Class CLBuffer

java.lang.Object
foundry.veil.api.opencl.CLBuffer
All Implemented Interfaces:
CLMemObject, AutoCloseable, org.lwjgl.system.NativeResource

public class CLBuffer extends Object implements CLMemObject

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 Details

    • kernel

      protected final CLKernel kernel
    • environment

      protected final CLEnvironment environment
    • pointer

      protected long pointer
  • Method Details

    • write

      public void write(long offset, ByteBuffer data) throws CLException
      Writes the specified data into this buffer.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The buffer with data to write
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, ByteBuffer, PointerBuffer, PointerBuffer)
    • write

      public void write(long offset, ShortBuffer data) throws CLException
      Writes the specified data into this buffer.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, ShortBuffer, PointerBuffer, PointerBuffer)
    • write

      public void write(long offset, IntBuffer data) throws CLException
      Writes the specified data into this buffer.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, IntBuffer, PointerBuffer, PointerBuffer)
    • write

      public void write(long offset, FloatBuffer data) throws CLException
      Writes the specified data into this buffer.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, FloatBuffer, PointerBuffer, PointerBuffer)
    • write

      public void write(long offset, DoubleBuffer data) throws CLException
      Writes the specified data into this buffer.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, DoubleBuffer, PointerBuffer, PointerBuffer)
    • read

      public void read(long offset, ByteBuffer store) throws CLException
      Reads the data from this buffer into the specified store.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, ByteBuffer, PointerBuffer, PointerBuffer)
    • read

      public void read(long offset, ShortBuffer store) throws CLException
      Reads the data from this buffer into the specified store.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, ShortBuffer, PointerBuffer, PointerBuffer)
    • read

      public void read(long offset, IntBuffer store) throws CLException
      Reads the data from this buffer into the specified store.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, IntBuffer, PointerBuffer, PointerBuffer)
    • read

      public void read(long offset, FloatBuffer store) throws CLException
      Reads the data from this buffer into the specified store.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, FloatBuffer, PointerBuffer, PointerBuffer)
    • read

      public void read(long offset, DoubleBuffer store) throws CLException
      Reads the data from this buffer into the specified store.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, DoubleBuffer, PointerBuffer, PointerBuffer)
    • writeAsync

      public void writeAsync(long offset, ByteBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of write(long, ByteBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The buffer with data to write
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, ByteBuffer, PointerBuffer, PointerBuffer)
    • writeAsync

      public void writeAsync(long offset, ShortBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of write(long, ShortBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, short[], PointerBuffer, PointerBuffer)
    • writeAsync

      public void writeAsync(long offset, IntBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of write(long, IntBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, int[], PointerBuffer, PointerBuffer)
    • writeAsync

      public void writeAsync(long offset, FloatBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of write(long, FloatBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, float[], PointerBuffer, PointerBuffer)
    • writeAsync

      public void writeAsync(long offset, DoubleBuffer data, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of write(long, DoubleBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start writing data to
      data - The data to write
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to upload data
      See Also:
      • CL10.clEnqueueWriteBuffer(long, long, boolean, long, double[], PointerBuffer, PointerBuffer)
    • readAsync

      public void readAsync(long offset, ByteBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of read(long, ByteBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, ByteBuffer, PointerBuffer, PointerBuffer)
    • readAsync

      public void readAsync(long offset, ShortBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of read(long, ShortBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, ShortBuffer, PointerBuffer, PointerBuffer)
    • readAsync

      public void readAsync(long offset, IntBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of read(long, IntBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, IntBuffer, PointerBuffer, PointerBuffer)
    • readAsync

      public void readAsync(long offset, FloatBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of read(long, FloatBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, FloatBuffer, PointerBuffer, PointerBuffer)
    • readAsync

      public void readAsync(long offset, DoubleBuffer store, @Nullable @Nullable Runnable onComplete) throws CLException
      Asynchronous implementation of read(long, DoubleBuffer). The specified callback will be fired when the operation completes.
      Parameters:
      offset - The offset into this buffer to start reading data from
      store - The buffer to store into
      onComplete - The callback for when the operation completes or null
      Throws:
      CLException - If any error occurs while trying to download data
      See Also:
      • CL10.clEnqueueReadBuffer(long, long, boolean, long, DoubleBuffer, PointerBuffer, PointerBuffer)
    • pointer

      public long pointer()
      Specified by:
      pointer in interface CLMemObject
      Returns:
      The pointer to this object
    • free

      public void free()
      Specified by:
      free in interface org.lwjgl.system.NativeResource