ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.pm
(Generate patch)

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.83 by root, Sat May 5 15:11:19 2012 UTC vs.
Revision 1.88 by root, Tue Oct 22 17:25:38 2013 UTC

232 # find and use the first opencl device that let's us get a shared opengl context 232 # find and use the first opencl device that let's us get a shared opengl context
233 my $platform; 233 my $platform;
234 my $dev; 234 my $dev;
235 my $ctx; 235 my $ctx;
236 236
237 sub get_context {
237 for (OpenCL::platforms) { 238 for (OpenCL::platforms) {
238 $platform = $_; 239 $platform = $_;
239 for ($platform->devices) { 240 for ($platform->devices) {
240 $dev = $_; 241 $dev = $_;
241 $ctx = $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) 242 $ctx = eval { $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) }
242 and last; 243 and return;
244 }
243 } 245 }
246
247 die "cannot find suitable OpenCL device\n";
244 } 248 }
245 249
246 $ctx 250 get_context;
247 or die "cannot find suitable OpenCL device\n";
248 251
249 my $queue = $ctx->queue ($dev); 252 my $queue = $ctx->queue ($dev);
250 253
251 # now attach an opencl image2d object to the opengl texture 254 # now attach an opencl image2d object to the opengl texture
252 my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid); 255 my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid);
399=head2 CONSTANTS 402=head2 CONSTANTS
400 403
401All C<CL_xxx> constants that this module supports are always available 404All C<CL_xxx> constants that this module supports are always available
402in the C<OpenCL> namespace as C<OpenCL::xxx> (i.e. without the C<CL_> 405in the C<OpenCL> namespace as C<OpenCL::xxx> (i.e. without the C<CL_>
403prefix). Constants which are not defined in the header files used during 406prefix). Constants which are not defined in the header files used during
404compilation, or otherwise are not available, will have the value C<-1>. 407compilation, or otherwise are not available, will have the value C<0> (in
408some cases, this will make them indistinguishable from real constants,
409sorry).
405 410
406The latest version of this module knows and exports the constants 411The latest version of this module knows and exports the constants
407listed in L<http://cvs.schmorp.de/OpenCL/constiv.h>. 412listed in L<http://cvs.schmorp.de/OpenCL/constiv.h>.
408 413
409=head2 OPENCL 1.1 VS. OPENCL 1.2 414=head2 OPENCL 1.1 VS. OPENCL 1.2
595use Async::Interrupt (); 600use Async::Interrupt ();
596 601
597our $POLL_FUNC; # set by XS 602our $POLL_FUNC; # set by XS
598 603
599BEGIN { 604BEGIN {
600 our $VERSION = '0.99'; 605 our $VERSION = '1.01';
601 606
602 require XSLoader; 607 require XSLoader;
603 XSLoader::load (__PACKAGE__, $VERSION); 608 XSLoader::load (__PACKAGE__, $VERSION);
604 609
605 @OpenCL::Platform::ISA = 610 @OpenCL::Platform::ISA =
1218OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, 1223OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR,
1219OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. 1224OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS.
1220 1225
1221L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> 1226L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html>
1222 1227
1228A somewhat informative thread on the flags is:
1229
1230L<http://www.khronos.org/message_boards/viewtopic.php?f=28&t=2440>
1231
1223=item $buf = $ctx->buffer_sv ($flags, $data) 1232=item $buf = $ctx->buffer_sv ($flags, $data)
1224 1233
1225Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and 1234Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
1226initialise it with the given data values. 1235initialise it with the given data values.
1227 1236
1620it. You are not necessarily meant to do it this way, this example just 1629it. You are not necessarily meant to do it this way, this example just
1621shows you the accessors to use :) 1630shows you the accessors to use :)
1622 1631
1623 my $mapped = $queue->map_image ($image, 1, OpenCL::MAP_WRITE); 1632 my $mapped = $queue->map_image ($image, 1, OpenCL::MAP_WRITE);
1624 1633
1625 $mapped->set ($_ * $mapped->row_pitch, pack "C", 5) 1634 $mapped->write ($_ * $mapped->row_pitch, pack "C", 5)
1626 for 0..$image->height; 1635 for 0 .. $mapped->height - 1;
1627 1636
1628 $mapped->unmap;. 1637 $mapped->unmap;.
1629 $mapped->wait; # only needed for out of order queues normally 1638 $mapped->wait; # only needed for out of order queues normally
1630 1639
1631=item $ev = $queue->unmap ($mapped, $wait_events...) 1640=item $ev = $queue->unmap ($mapped, $wait_events...)
2343 2352
2344This is a subclass of OpenCL::Mapped, representing mapped images. 2353This is a subclass of OpenCL::Mapped, representing mapped images.
2345 2354
2346=over 4 2355=over 4
2347 2356
2357=item $pixels = $mapped->width
2358
2359=item $pixels = $mapped->height
2360
2361=item $pixels = $mapped->depth
2362
2363Return the width/height/depth of the mapped image region, in pixels.
2364
2348=item $bytes = $mapped->row_pitch 2365=item $bytes = $mapped->row_pitch
2349 2366
2350=item $bytes = $mapped->slice_pitch 2367=item $bytes = $mapped->slice_pitch
2351 2368
2352Return the row or slice pitch of the image that has been mapped. 2369Return the row or slice pitch of the image that has been mapped.
2353 2370
2371=item $bytes = $mapped->element_size
2372
2373Return the size of a single pixel.
2374
2375=item $data = $mapped->get_row ($count, $x=0, $y=0, $z=0)
2376
2377Return C<$count> pixels from the given coordinates. The pixel data must
2378be completely contained within a single row.
2379
2380If C<$count> is C<undef>, then all the remaining pixels in that row are
2381returned.
2382
2383=item $mapped->set_row ($data, $x=0, $y=0, $z=0)
2384
2385Write the given pixel data at the given coordinate. The pixel data must
2386be completely contained within a single row.
2387
2354=back 2388=back
2355
2356 2389
2357=cut 2390=cut
2358 2391
23591; 23921;
2360 2393

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines