Package foundry.veil.api.opencl
Class CLBuffer
java.lang.Object
foundry.veil.api.opencl.CLBuffer
- All Implemented Interfaces:
CLMemObject
,AutoCloseable
,org.lwjgl.system.NativeResource
A generic data buffer that can be uploaded to/from OpenCL.
When using the buffer methods, the data should be provided as follows:
// Using MemoryStack is fast, but limits the amount of data that can be allocated try (MemoryStack stack = MemoryStack.stackPush()) { // position should be 0 so the data can all be read ByteBuffer data = stack.malloc(2); data.put(0, (byte) 4); data.put(1, (byte) 7); // rewind can be used if the position is mutated data.rewind(); // You get a buffer from a kernel CLBuffer buffer = ...; buffer.write(data); // data.pointer() is still going to be 0 after this call }
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CLEnvironment
protected final CLKernel
protected long
-
Method Summary
Modifier and TypeMethodDescriptionvoid
free()
long
pointer()
void
read
(long offset, ByteBuffer store) Reads the data from this buffer into the specified store.void
read
(long offset, DoubleBuffer store) Reads the data from this buffer into the specified store.void
read
(long offset, FloatBuffer store) Reads the data from this buffer into the specified store.void
Reads the data from this buffer into the specified store.void
read
(long offset, ShortBuffer store) Reads the data from this buffer into the specified store.void
readAsync
(long offset, ByteBuffer store, @Nullable Runnable onComplete) Asynchronous implementation ofread(long, ByteBuffer)
.void
readAsync
(long offset, DoubleBuffer store, @Nullable Runnable onComplete) Asynchronous implementation ofread(long, DoubleBuffer)
.void
readAsync
(long offset, FloatBuffer store, @Nullable Runnable onComplete) Asynchronous implementation ofread(long, FloatBuffer)
.void
Asynchronous implementation ofread(long, IntBuffer)
.void
readAsync
(long offset, ShortBuffer store, @Nullable Runnable onComplete) Asynchronous implementation ofread(long, ShortBuffer)
.void
write
(long offset, ByteBuffer data) Writes the specified data into this buffer.void
write
(long offset, DoubleBuffer data) Writes the specified data into this buffer.void
write
(long offset, FloatBuffer data) Writes the specified data into this buffer.void
Writes the specified data into this buffer.void
write
(long offset, ShortBuffer data) Writes the specified data into this buffer.void
writeAsync
(long offset, ByteBuffer data, @Nullable Runnable onComplete) Asynchronous implementation ofwrite(long, ByteBuffer)
.void
writeAsync
(long offset, DoubleBuffer data, @Nullable Runnable onComplete) Asynchronous implementation ofwrite(long, DoubleBuffer)
.void
writeAsync
(long offset, FloatBuffer data, @Nullable Runnable onComplete) Asynchronous implementation ofwrite(long, FloatBuffer)
.void
writeAsync
(long offset, IntBuffer data, @Nullable Runnable onComplete) Asynchronous implementation ofwrite(long, IntBuffer)
.void
writeAsync
(long offset, ShortBuffer data, @Nullable Runnable onComplete) Asynchronous implementation ofwrite(long, ShortBuffer)
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.lwjgl.system.NativeResource
close
-
Field Details
-
kernel
-
environment
-
pointer
protected long pointer
-
-
Method Details
-
write
Writes the specified data into this buffer.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The buffer with data to write- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
write
Writes the specified data into this buffer.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to write- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
write
Writes the specified data into this buffer.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to write- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
write
Writes the specified data into this buffer.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to write- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
write
Writes the specified data into this buffer.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to write- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
read
Reads the data from this buffer into the specified store.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store into- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
read
Reads the data from this buffer into the specified store.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store into- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
read
Reads the data from this buffer into the specified store.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store into- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
read
Reads the data from this buffer into the specified store.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store into- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
read
Reads the data from this buffer into the specified store.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store into- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
writeAsync
public void writeAsync(long offset, ByteBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofwrite(long, ByteBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The buffer with data to writeonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
writeAsync
public void writeAsync(long offset, ShortBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofwrite(long, ShortBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to writeonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
writeAsync
public void writeAsync(long offset, IntBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofwrite(long, IntBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to writeonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
writeAsync
public void writeAsync(long offset, FloatBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofwrite(long, FloatBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to writeonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
writeAsync
public void writeAsync(long offset, DoubleBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofwrite(long, DoubleBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start writing data todata
- The data to writeonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to upload data- See Also:
-
readAsync
public void readAsync(long offset, ByteBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofread(long, ByteBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store intoonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
readAsync
public void readAsync(long offset, ShortBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofread(long, ShortBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store intoonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
readAsync
public void readAsync(long offset, IntBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofread(long, IntBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store intoonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
readAsync
public void readAsync(long offset, FloatBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofread(long, FloatBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store intoonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
readAsync
public void readAsync(long offset, DoubleBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException Asynchronous implementation ofread(long, DoubleBuffer)
. The specified callback will be fired when the operation completes.- Parameters:
offset
- The offset into this buffer to start reading data fromstore
- The buffer to store intoonComplete
- The callback for when the operation completes ornull
- Throws:
CLException
- If any error occurs while trying to download data- See Also:
-
pointer
public long pointer()- Specified by:
pointer
in interfaceCLMemObject
- Returns:
- The pointer to this object
-
free
public void free()- Specified by:
free
in interfaceorg.lwjgl.system.NativeResource
-