--- OpenCL/OpenCL.pm 2012/05/01 16:37:23 1.66 +++ OpenCL/OpenCL.pm 2012/05/01 22:04:56 1.67 @@ -560,8 +560,8 @@ @OpenCL::UserEvent::ISA = OpenCL::Event::; - @OpenCL::MappedBuffer = - @OpenCL::MappedImage = OpenCL::Mapped::; + @OpenCL::MappedBuffer::ISA = + @OpenCL::MappedImage::ISA = OpenCL::Mapped::; } =head2 THE OpenCL PACKAGE @@ -1979,6 +1979,10 @@ When the object is destroyed it will enqueue an implicit unmap operation on the queue that was used to create it. +Keep in mind that you I to unmap (or destroy) mapped objects before +OpenCL sees the changes, even if some implementations don't need this +sometimes. + Example, replace the first two floats in the mapped buffer by 1 and 2. my $mapped = $queue->map_buffer ($buf, ... @@ -1991,6 +1995,11 @@ =over 4 +=item $ev = $mapped->unmap ($wait_events...) + +Unmaps the mapped memory object, using the queue originally used to create +it, quite similarly to C<< $queue->unmap ($mapped, ...) >>. + =item $bool = $mapped->mapped Returns whether the object is still mapped - true before an C is @@ -2015,22 +2024,46 @@ Returns the raw memory address of the mapped area - same as C<$mapped+0>. -=back +=item $mapped->set ($offset, $data) -=head2 THE OpenCL::MappedBuffer CLASS +Replaces the data at the given C<$offset> in the memory area by the new +C<$data>. This method is safer but slower than direct manipulation of +C<$$mapped> with substr. -This is a subclass of OpenCL::Mapped, representing mapped buffers. +=item $data = $mapped->get ($offset, $length) -=over 4 +Returns (without copying) a scalar representing the data at the given +C<$offset> and C<$length> in the mapped memory area. This is the same as +the following substr, except much slower: + + $data = substr $$mapped, $offset, $length + +#TODO: really? + +=cut + +sub get { + substr ${$_[0]}, $_[1], $_[2] +} =back +=head2 THE OpenCL::MappedBuffer CLASS + +This is a subclass of OpenCL::Mapped, representing mapped buffers. + =head2 THE OpenCL::MappedImage CLASS This is a subclass of OpenCL::Mapped, representing mapped images. =over 4 +=item $bytes = $mapped->row_pitch + +=item $bytes = $mapped->slice_pitch + +Return the row or slice pitch of the image that has been mapped. + =back