… | |
… | |
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 | |
401 | All C<CL_xxx> constants that this module supports are always available |
404 | All C<CL_xxx> constants that this module supports are always available |
402 | in the C<OpenCL> namespace as C<OpenCL::xxx> (i.e. without the C<CL_> |
405 | in the C<OpenCL> namespace as C<OpenCL::xxx> (i.e. without the C<CL_> |
403 | prefix). Constants which are not defined in the header files used during |
406 | prefix). Constants which are not defined in the header files used during |
404 | compilation, or otherwise are not available, will have the value C<-1>. |
407 | compilation, or otherwise are not available, will have the value C<0> (in |
|
|
408 | some cases, this will make them indistinguishable from real constants, |
|
|
409 | sorry). |
405 | |
410 | |
406 | The latest version of this module knows and exports the constants |
411 | The latest version of this module knows and exports the constants |
407 | listed in L<http://cvs.schmorp.de/OpenCL/constiv.h>. |
412 | listed 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 |
… | |
… | |
595 | use Async::Interrupt (); |
600 | use Async::Interrupt (); |
596 | |
601 | |
597 | our $POLL_FUNC; # set by XS |
602 | our $POLL_FUNC; # set by XS |
598 | |
603 | |
599 | BEGIN { |
604 | BEGIN { |
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 = |
… | |
… | |
1218 | OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, |
1223 | OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, |
1219 | OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. |
1224 | OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. |
1220 | |
1225 | |
1221 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
1226 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
1222 | |
1227 | |
|
|
1228 | A somewhat informative thread on the flags is: |
|
|
1229 | |
|
|
1230 | L<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 | |
1225 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
1234 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
1226 | initialise it with the given data values. |
1235 | initialise it with the given data values. |
1227 | |
1236 | |