Package com.jme3.opencl
Class Buffer
java.lang.Object
com.jme3.opencl.AbstractOpenCLObject
com.jme3.opencl.Buffer
- All Implemented Interfaces:
- OpenCLObject
- Direct Known Subclasses:
- LwjglBuffer
Wrapper for an OpenCL buffer object.
 A buffer object stores a one-dimensional collection of elements. Elements of a buffer object can
 be a scalar data type (such as an int, float), vector data type, or a user-defined structure.
 
Buffers are created by the
All access methods (read/write/copy/map) are available in both synchronized/blocking versions and in async/non-blocking versions. The later ones always return an
Buffers are created by the
Context.
 All access methods (read/write/copy/map) are available in both synchronized/blocking versions and in async/non-blocking versions. The later ones always return an
Event object
 and have the prefix -Async in their name.- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classResult of an async mapping operation, contains the event and the target byte buffer.Nested classes/interfaces inherited from interface com.jme3.opencl.OpenCLObjectOpenCLObject.ObjectReleaser
- 
Field SummaryFields inherited from class com.jme3.opencl.AbstractOpenCLObjectreleaser
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionabstract EventAcquires this buffer object for using.voidAcquires this buffer object for using.voidcopyTo(CommandQueue queue, Buffer dest) Alternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long), setssizetothis.getSize().voidcopyTo(CommandQueue queue, Buffer dest, long size) Alternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long), setssrcOffsetanddestOffsetto zero.abstract voidcopyTo(CommandQueue queue, Buffer dest, long size, long srcOffset, long destOffset) Performs a blocking copy operation from this buffer to the specified buffer.copyToAsync(CommandQueue queue, Buffer dest) Alternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long), setssizetothis.getSize().copyToAsync(CommandQueue queue, Buffer dest, long size) Alternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long), setssrcOffsetanddestOffsetto zero.abstract EventcopyToAsync(CommandQueue queue, Buffer dest, long size, long srcOffset, long destOffset) Performs an async/non-blocking copy operation from this buffer to the specified buffer.abstract EventcopyToImageAsync(CommandQueue queue, Image dest, long srcOffset, long[] destOrigin, long[] destRegion) Copies this buffer to the specified image.abstract EventfillAsync(CommandQueue queue, ByteBuffer pattern, long size, long offset) Enqueues a fill operation.abstract MemoryAccessabstract longgetSize()abstract ByteBuffermap(CommandQueue queue, long size, long offset, MappingAccess access) Maps this buffer directly into host memory.map(CommandQueue queue, long size, MappingAccess access) Alternative version ofmap(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess), setsoffsetto zero.map(CommandQueue queue, MappingAccess access) Alternative version ofmap(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess), setssizetogetSize().abstract Buffer.AsyncMappingmapAsync(CommandQueue queue, long size, long offset, MappingAccess access) Maps this buffer asynchronously into host memory.mapAsync(CommandQueue queue, long size, MappingAccess access) Alternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess), setsoffsetto zero.mapAsync(CommandQueue queue, MappingAccess access) Alternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess), setssizetogetSize().voidread(CommandQueue queue, ByteBuffer dest) Alternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize().voidread(CommandQueue queue, ByteBuffer dest, long size) Alternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.abstract voidread(CommandQueue queue, ByteBuffer dest, long size, long offset) Performs a blocking read of the buffer.readAsync(CommandQueue queue, ByteBuffer dest) Alternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize()readAsync(CommandQueue queue, ByteBuffer dest, long size) Alternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.abstract EventreadAsync(CommandQueue queue, ByteBuffer dest, long size, long offset) Performs an async/non-blocking read of the buffer.register()Registers this object for automatic releasing on garbage collection.abstract EventReleases a shared buffer object.voidReleases a shared buffer object.toString()abstract voidunmap(CommandQueue queue, ByteBuffer ptr) Unmaps a previously mapped memory.voidwrite(CommandQueue queue, ByteBuffer src) Alternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize().voidwrite(CommandQueue queue, ByteBuffer src, long size) Alternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.abstract voidwrite(CommandQueue queue, ByteBuffer src, long size, long offset) Performs a blocking write to the buffer.writeAsync(CommandQueue queue, ByteBuffer src) Alternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize().writeAsync(CommandQueue queue, ByteBuffer src, long size) Alternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.abstract EventwriteAsync(CommandQueue queue, ByteBuffer src, long size, long offset) Performs an async/non-blocking write to the buffer.Methods inherited from class com.jme3.opencl.AbstractOpenCLObjectfinalize, getReleaser, release
- 
Constructor Details- 
Buffer
 
- 
- 
Method Details- 
registerDescription copied from interface:OpenCLObjectRegisters this object for automatic releasing on garbage collection. By default, OpenCLObjects are not registered in theOpenCLObjectManager, you have to release it manually by callingOpenCLObject.release(). Without registering or releasing, a memory leak might occur.
 Returnsthisto allow calls likeBuffer buffer = clContext.createBuffer(1024).register();.- Specified by:
- registerin interface- OpenCLObject
- Overrides:
- registerin class- AbstractOpenCLObject
- Returns:
- this
 
- 
getSizepublic abstract long getSize()- Returns:
- the size of the buffer in bytes.
- See Also:
 
- 
getMemoryAccessFlags- Returns:
- the memory access flags set on creation.
- See Also:
 
- 
readPerforms a blocking read of the buffer. The target buffer must have at leastsizebytes remaining. This method may set the limit to the last byte read.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the size in bytes being read
- offset- the offset in bytes in the buffer to read from
 
- 
readAlternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the number of bytes to read
 
- 
readAlternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize().- Parameters:
- queue- the command queue
- dest- the target buffer
 
- 
readAsyncPerforms an async/non-blocking read of the buffer. The target buffer must have at leastsizebytes remaining. This method may set the limit to the last byte read.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the size in bytes being read
- offset- the offset in bytes in the buffer to read from
- Returns:
- the event indicating when the memory has been fully read into the provided buffer
 
- 
readAsyncAlternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the number of bytes to read
- Returns:
- an Event to indicate completion
 
- 
readAsyncAlternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize()- Parameters:
- queue- the command queue
- dest- the target buffer
- Returns:
- an Event to indicate completion
 
- 
writePerforms a blocking write to the buffer. The target buffer must have at leastsizebytes remaining. This method may set the limit to the last byte that will be written.- Parameters:
- queue- the command queue
- src- the source buffer, its data is written to this buffer
- size- the size in bytes to write
- offset- the offset into the target buffer
 
- 
writeAlternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.- Parameters:
- queue- the command queue
- src- the source buffer, its data is written to this buffer
- size- the number of bytes to write
 
- 
writeAlternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize().- Parameters:
- queue- the command queue
- src- the source buffer, its data is written to this buffer
 
- 
writeAsyncPerforms an async/non-blocking write to the buffer. The target buffer must have at leastsizebytes remaining. This method may set the limit to the last byte that will be written.- Parameters:
- queue- the command queue
- src- the source buffer, its data is written to this buffer
- size- the size in bytes to write
- offset- the offset into the target buffer
- Returns:
- an Event to indicate completion
 
- 
writeAsyncAlternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long), setsoffsetto zero.- Parameters:
- queue- the command queue
- src- the source buffer, its data is written to this buffer
- size- the number of bytes to write
- Returns:
- an Event to indicate completion
 
- 
writeAsyncAlternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long), setssizetogetSize().- Parameters:
- queue- the command queue
- src- the source buffer, its data is written to this buffer
- Returns:
- an Event to indicate completion
 
- 
copyTopublic abstract void copyTo(CommandQueue queue, Buffer dest, long size, long srcOffset, long destOffset) Performs a blocking copy operation from this buffer to the specified buffer.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the size in bytes to copy
- srcOffset- offset in bytes into this buffer
- destOffset- offset in bytes into the target buffer
 
- 
copyToAlternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long), setssrcOffsetanddestOffsetto zero.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the number of bytes to copy
 
- 
copyToAlternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long), setssizetothis.getSize().- Parameters:
- queue- the command queue
- dest- the target buffer
 
- 
copyToAsyncpublic abstract Event copyToAsync(CommandQueue queue, Buffer dest, long size, long srcOffset, long destOffset) Performs an async/non-blocking copy operation from this buffer to the specified buffer.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the size in bytes to copy
- srcOffset- offset in bytes into this buffer
- destOffset- offset in bytes into the target buffer
- Returns:
- the event object indicating when the copy operation is finished
 
- 
copyToAsyncAlternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long), setssrcOffsetanddestOffsetto zero.- Parameters:
- queue- the command queue
- dest- the target buffer
- size- the number of bytes to copy
- Returns:
- an Event to indicate completion
 
- 
copyToAsyncAlternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long), setssizetothis.getSize().- Parameters:
- queue- the command queue
- dest- the target buffer
- Returns:
- an Event to indicate completion
 
- 
mapMaps this buffer directly into host memory. This might be the fastest method to access the contents of the buffer since the OpenCL implementation directly provides the memory.
 Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer).- Parameters:
- queue- the command queue
- size- the size in bytes to map
- offset- the offset into this buffer
- access- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE
- Returns:
- the byte buffer directly reflecting the buffer contents
 
- 
mapAlternative version ofmap(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess), setsoffsetto zero. Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer).- Parameters:
- queue- the command queue
- size- the number of bytes to map
- access- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE
- Returns:
- the byte buffer directly reflecting the buffer contents
 
- 
mapAlternative version ofmap(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess), setssizetogetSize(). Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer).- Parameters:
- queue- the command queue
- access- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE
- Returns:
- the byte buffer directly reflecting the buffer contents
 
- 
unmapUnmaps a previously mapped memory. This releases the native resources and for WRITE_ONLY or READ_WRITE access, the memory content is sent back to the GPU.- Parameters:
- queue- the command queue
- ptr- the buffer that was previously mapped
 
- 
mapAsyncpublic abstract Buffer.AsyncMapping mapAsync(CommandQueue queue, long size, long offset, MappingAccess access) Maps this buffer asynchronously into host memory. This might be the fastest method to access the contents of the buffer since the OpenCL implementation directly provides the memory.
 Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer).- Parameters:
- queue- the command queue
- size- the size in bytes to map
- offset- the offset into this buffer
- access- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE
- Returns:
- the byte buffer directly reflecting the buffer contents and the event indicating when the buffer contents are available
 
- 
mapAsyncAlternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess), setsoffsetto zero. Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer).- Parameters:
- queue- the command queue
- size- the size in bytes to map
- access- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE
- Returns:
- the byte buffer directly reflecting the buffer contents and the event indicating when the buffer contents are available
 
- 
mapAsyncAlternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess), setssizetogetSize(). Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer).- Parameters:
- queue- the command queue
- access- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE
- Returns:
- the byte buffer directly reflecting the buffer contents and the event indicating when the buffer contents are available
 
- 
fillAsyncEnqueues a fill operation. This method can be used to initialize or clear a buffer with a certain value.- Parameters:
- queue- the command queue
- pattern- the buffer containing the filling pattern. The remaining bytes specify the pattern length
- size- the size in bytes to fill, must be a multiple of the pattern length
- offset- the offset in bytes into the buffer, must be a multiple of the pattern length
- Returns:
- an event indicating when this operation is finished
 
- 
copyToImageAsyncpublic abstract Event copyToImageAsync(CommandQueue queue, Image dest, long srcOffset, long[] destOrigin, long[] destRegion) Copies this buffer to the specified image. Note that no format conversion is done.
 For detailed description of the origin and region parameter, see the documentation of theImageclass.- Parameters:
- queue- the command queue
- dest- the target image
- srcOffset- the offset in bytes into this buffer
- destOrigin- the origin of the copied area
- destRegion- the size of the copied area
- Returns:
- the event object
 
- 
acquireBufferForSharingAsyncAcquires this buffer object for using. Only call this method if this buffer represents a shared object from OpenGL, created with e.g.Context.bindVertexBuffer(com.jme3.scene.VertexBuffer, com.jme3.opencl.MemoryAccess). This method must be called before the buffer is used. After the work is done, the buffer must be released by callingreleaseBufferForSharingAsync(com.jme3.opencl.CommandQueue)so that OpenGL can use the VertexBuffer again.- Parameters:
- queue- the command queue
- Returns:
- the event object
 
- 
acquireBufferForSharingNoEventAcquires this buffer object for using. Only call this method if this buffer represents a shared object from OpenGL, created with e.g.Context.bindVertexBuffer(com.jme3.scene.VertexBuffer, com.jme3.opencl.MemoryAccess). This method must be called before the buffer is used. After the work is done, the buffer must be released by callingreleaseBufferForSharingAsync(com.jme3.opencl.CommandQueue)so that OpenGL can use the VertexBuffer again. The generated event object is directly released. This brings a performance improvement when the resource is e.g. directly used by a kernel afterwards on the same queue (this implicitly waits for this action). If you need the event, useacquireBufferForSharingAsync(com.jme3.opencl.CommandQueue)instead.- Parameters:
- queue- the command queue
 
- 
releaseBufferForSharingAsyncReleases a shared buffer object. Call this method after the buffer object was acquired byacquireBufferForSharingAsync(com.jme3.opencl.CommandQueue)to hand the control back to OpenGL.- Parameters:
- queue- the command queue
- Returns:
- the event object
 
- 
releaseBufferForSharingNoEventReleases a shared buffer object. Call this method after the buffer object was acquired byacquireBufferForSharingAsync(com.jme3.opencl.CommandQueue)to hand the control back to OpenGL. The generated event object is directly released, resulting in performance improvements.- Parameters:
- queue- the command queue
 
- 
toString
 
-