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.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Result of an async mapping operation, contains the event and the target byte buffer.Nested classes/interfaces inherited from interface com.jme3.opencl.OpenCLObject
OpenCLObject.ObjectReleaser
-
Field Summary
Fields inherited from class com.jme3.opencl.AbstractOpenCLObject
releaser
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Event
Acquires this buffer object for using.void
Acquires this buffer object for using.void
copyTo
(CommandQueue queue, Buffer dest) Alternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long)
, setssize
tothis.getSize()
.void
copyTo
(CommandQueue queue, Buffer dest, long size) Alternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long)
, setssrcOffset
anddestOffset
to zero.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.copyToAsync
(CommandQueue queue, Buffer dest) Alternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long)
, setssize
tothis.getSize()
.copyToAsync
(CommandQueue queue, Buffer dest, long size) Alternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long)
, setssrcOffset
anddestOffset
to zero.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.abstract Event
copyToImageAsync
(CommandQueue queue, Image dest, long srcOffset, long[] destOrigin, long[] destRegion) Copies this buffer to the specified image.abstract Event
fillAsync
(CommandQueue queue, ByteBuffer pattern, long size, long offset) Enqueues a fill operation.abstract MemoryAccess
abstract long
getSize()
abstract ByteBuffer
map
(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)
, setsoffset
to zero.map
(CommandQueue queue, MappingAccess access) Alternative version ofmap(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess)
, setssize
togetSize()
.abstract Buffer.AsyncMapping
mapAsync
(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)
, setsoffset
to zero.mapAsync
(CommandQueue queue, MappingAccess access) Alternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess)
, setssize
togetSize()
.void
read
(CommandQueue queue, ByteBuffer dest) Alternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long)
, setssize
togetSize()
.void
read
(CommandQueue queue, ByteBuffer dest, long size) Alternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.abstract void
read
(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)
, setssize
togetSize()
readAsync
(CommandQueue queue, ByteBuffer dest, long size) Alternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.abstract Event
readAsync
(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 Event
Releases a shared buffer object.void
Releases a shared buffer object.toString()
abstract void
unmap
(CommandQueue queue, ByteBuffer ptr) Unmaps a previously mapped memory.void
write
(CommandQueue queue, ByteBuffer src) Alternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long)
, setssize
togetSize()
.void
write
(CommandQueue queue, ByteBuffer src, long size) Alternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.abstract void
write
(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)
, setssize
togetSize()
.writeAsync
(CommandQueue queue, ByteBuffer src, long size) Alternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.abstract Event
writeAsync
(CommandQueue queue, ByteBuffer src, long size, long offset) Performs an async/non-blocking write to the buffer.Methods inherited from class com.jme3.opencl.AbstractOpenCLObject
finalize, getReleaser, release
-
Constructor Details
-
Buffer
-
-
Method Details
-
register
Description copied from interface:OpenCLObject
Registers 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.
Returnsthis
to allow calls likeBuffer buffer = clContext.createBuffer(1024).register();
.- Specified by:
register
in interfaceOpenCLObject
- Overrides:
register
in classAbstractOpenCLObject
- Returns:
this
-
getSize
public abstract long getSize()- Returns:
- the size of the buffer in bytes.
- See Also:
-
getMemoryAccessFlags
- Returns:
- the memory access flags set on creation.
- See Also:
-
read
Performs a blocking read of the buffer. The target buffer must have at leastsize
bytes remaining. This method may set the limit to the last byte read.- Parameters:
queue
- the command queuedest
- the target buffersize
- the size in bytes being readoffset
- the offset in bytes in the buffer to read from
-
read
Alternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.- Parameters:
queue
- the command queuedest
- the target buffersize
- the number of bytes to read
-
read
Alternative version ofread(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long)
, setssize
togetSize()
.- Parameters:
queue
- the command queuedest
- the target buffer
-
readAsync
Performs an async/non-blocking read of the buffer. The target buffer must have at leastsize
bytes remaining. This method may set the limit to the last byte read.- Parameters:
queue
- the command queuedest
- the target buffersize
- the size in bytes being readoffset
- 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
-
readAsync
Alternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.- Parameters:
queue
- the command queuedest
- the target buffersize
- the number of bytes to read- Returns:
- an Event to indicate completion
-
readAsync
Alternative version ofreadAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long)
, setssize
togetSize()
- Parameters:
queue
- the command queuedest
- the target buffer- Returns:
- an Event to indicate completion
-
write
Performs a blocking write to the buffer. The target buffer must have at leastsize
bytes remaining. This method may set the limit to the last byte that will be written.- Parameters:
queue
- the command queuesrc
- the source buffer, its data is written to this buffersize
- the size in bytes to writeoffset
- the offset into the target buffer
-
write
Alternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.- Parameters:
queue
- the command queuesrc
- the source buffer, its data is written to this buffersize
- the number of bytes to write
-
write
Alternative version ofwrite(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long)
, setssize
togetSize()
.- Parameters:
queue
- the command queuesrc
- the source buffer, its data is written to this buffer
-
writeAsync
Performs an async/non-blocking write to the buffer. The target buffer must have at leastsize
bytes remaining. This method may set the limit to the last byte that will be written.- Parameters:
queue
- the command queuesrc
- the source buffer, its data is written to this buffersize
- the size in bytes to writeoffset
- the offset into the target buffer- Returns:
- an Event to indicate completion
-
writeAsync
Alternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long, long)
, setsoffset
to zero.- Parameters:
queue
- the command queuesrc
- the source buffer, its data is written to this buffersize
- the number of bytes to write- Returns:
- an Event to indicate completion
-
writeAsync
Alternative version ofwriteAsync(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer, long)
, setssize
togetSize()
.- Parameters:
queue
- the command queuesrc
- the source buffer, its data is written to this buffer- Returns:
- an Event to indicate completion
-
copyTo
public 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 queuedest
- the target buffersize
- the size in bytes to copysrcOffset
- offset in bytes into this bufferdestOffset
- offset in bytes into the target buffer
-
copyTo
Alternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long)
, setssrcOffset
anddestOffset
to zero.- Parameters:
queue
- the command queuedest
- the target buffersize
- the number of bytes to copy
-
copyTo
Alternative version ofcopyTo(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long)
, setssize
tothis.getSize()
.- Parameters:
queue
- the command queuedest
- the target buffer
-
copyToAsync
public 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 queuedest
- the target buffersize
- the size in bytes to copysrcOffset
- offset in bytes into this bufferdestOffset
- offset in bytes into the target buffer- Returns:
- the event object indicating when the copy operation is finished
-
copyToAsync
Alternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long, long, long)
, setssrcOffset
anddestOffset
to zero.- Parameters:
queue
- the command queuedest
- the target buffersize
- the number of bytes to copy- Returns:
- an Event to indicate completion
-
copyToAsync
Alternative version ofcopyToAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Buffer, long)
, setssize
tothis.getSize()
.- Parameters:
queue
- the command queuedest
- the target buffer- Returns:
- an Event to indicate completion
-
map
Maps 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 queuesize
- the size in bytes to mapoffset
- the offset into this bufferaccess
- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE- Returns:
- the byte buffer directly reflecting the buffer contents
-
map
Alternative version ofmap(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess)
, setsoffset
to zero. Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer)
.- Parameters:
queue
- the command queuesize
- the number of bytes to mapaccess
- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE- Returns:
- the byte buffer directly reflecting the buffer contents
-
map
Alternative version ofmap(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess)
, setssize
togetSize()
. Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer)
.- Parameters:
queue
- the command queueaccess
- specifies the possible access to the memory: READ_ONLY, WRITE_ONLY, READ_WRITE- Returns:
- the byte buffer directly reflecting the buffer contents
-
unmap
Unmaps 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 queueptr
- the buffer that was previously mapped
-
mapAsync
public 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 queuesize
- the size in bytes to mapoffset
- the offset into this bufferaccess
- 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
-
mapAsync
Alternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess)
, setsoffset
to zero. Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer)
.- Parameters:
queue
- the command queuesize
- the size in bytes to mapaccess
- 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
-
mapAsync
Alternative version ofmapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess)
, setssize
togetSize()
. Important: The mapped memory MUST be released by callingunmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer)
.- Parameters:
queue
- the command queueaccess
- 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
-
fillAsync
Enqueues a fill operation. This method can be used to initialize or clear a buffer with a certain value.- Parameters:
queue
- the command queuepattern
- the buffer containing the filling pattern. The remaining bytes specify the pattern lengthsize
- the size in bytes to fill, must be a multiple of the pattern lengthoffset
- the offset in bytes into the buffer, must be a multiple of the pattern length- Returns:
- an event indicating when this operation is finished
-
copyToImageAsync
public 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 theImage
class.- Parameters:
queue
- the command queuedest
- the target imagesrcOffset
- the offset in bytes into this bufferdestOrigin
- the origin of the copied areadestRegion
- the size of the copied area- Returns:
- the event object
-
acquireBufferForSharingAsync
Acquires 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
-
acquireBufferForSharingNoEvent
Acquires 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
-
releaseBufferForSharingAsync
Releases 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
-
releaseBufferForSharingNoEvent
Releases 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
-