Class CLKernel

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

public class CLKernel extends Object implements org.lwjgl.system.NativeResource
Manages the OpenCL kernel object. Buffers can be created with createBuffer(int, long) and createBufferUnsafe(int, long)
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Acquires the data referenced by this object from OpenGL to allow OpenCL to safely modify it.
    createBuffer(int flags, long size)
    Creates a new CL memory buffer.
    createBufferFromGL(int flags, int buffer)
    Creates a new CL memory buffer that reflects the data in an OpenGL buffer.
    @Nullable CLBuffer
    createBufferFromGLUnsafe(int flags, int buffer)
    Creates a new CL memory buffer that reflects the data in an OpenGL buffer.
    @Nullable CLBuffer
    createBufferUnsafe(int flags, long size)
    Creates a new CL memory buffer.
    void
    execute(int[] globalWorkSizes, int[] localWorkSizes)
    Executes this kernel in n dimensions.
    void
    execute(int globalWorkSize, int localWorkSize)
    Executes this kernel in 1 dimension.
    void
    execute(int globalWorkSizeX, int localWorkSizeX, int globalWorkSizeY, int localWorkSizeY)
    Executes this kernel in 2 dimensions.
    void
    execute(int globalWorkSizeX, int localWorkSizeX, int globalWorkSizeY, int localWorkSizeY, int globalWorkSizeZ, int localWorkSizeZ)
    Executes this kernel in 3 dimensions.
    void
     
     
    long
     
    int
     
    net.minecraft.resources.ResourceLocation
     
    void
    Releases the data referenced by this object from OpenCL to allow OpenGL to safely modify it again.
    void
    setByte(int index, byte value)
    Sets a single byte parameter.
    void
    setDouble(int index, double value)
    Sets a single double parameter.
    void
    setFloat(int index, float value)
    Sets a single float parameter.
    void
    setInt(int index, int value)
    Sets a single int parameter.
    void
    setLong(int index, long value)
    Sets a single long parameter.
    void
    setPointers(int index, long... value)
    Sets an array of pointers to the specified parameter.
    void
    setPointers(int index, CLMemObject... value)
    Sets an array of memory object pointers to the specified parameter.
    void
    setShort(int index, short value)
    Sets a single short parameter.
    void
    setVector2f(int index, float x, float y)
    Sets a single float2 parameter.
    void
    setVector2f(int index, org.joml.Vector2fc value)
    Sets a single float2 parameter.
    void
    setVector3f(int index, org.joml.Vector3fc value)
    Sets a single float4 parameter.
    void
    setVector4f(int index, float x, float y, float z, float w)
    Sets a single float4 parameter.
    void
    setVector4f(int index, org.joml.Vector4fc value)
    Sets a single float4 parameter.

    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
  • Method Details

    • execute

      public void execute(int globalWorkSize, int localWorkSize) throws CLException
      Executes this kernel in 1 dimension. globalWorkSize must be evenly divisible by localWorkSize
      Parameters:
      globalWorkSize - The size of the global work group
      localWorkSize - The size of each local work group
      Throws:
      CLException - If any error occurs while executing the kernel
      See Also:
    • execute

      public void execute(int globalWorkSizeX, int localWorkSizeX, int globalWorkSizeY, int localWorkSizeY) throws CLException
      Executes this kernel in 2 dimensions. globalWorkSize must be evenly divisible by localWorkSize
      Parameters:
      globalWorkSizeX - The size of the global work group in the X
      localWorkSizeX - The size of each local work group in the X
      globalWorkSizeY - The size of the global work group in the Y
      localWorkSizeY - The size of each local work group in the Y
      Throws:
      CLException - If any error occurs while executing the kernel
      See Also:
    • execute

      public void execute(int globalWorkSizeX, int localWorkSizeX, int globalWorkSizeY, int localWorkSizeY, int globalWorkSizeZ, int localWorkSizeZ) throws CLException
      Executes this kernel in 3 dimensions. globalWorkSize must be evenly divisible by localWorkSize
      Parameters:
      globalWorkSizeX - The size of the global work group in the X
      localWorkSizeX - The size of each local work group in the X
      globalWorkSizeY - The size of the global work group in the Y
      localWorkSizeY - The size of each local work group in the Y
      globalWorkSizeZ - The size of the global work group in the Z
      localWorkSizeZ - The size of each local work group in the Z
      Throws:
      CLException - If any error occurs while executing the kernel
      See Also:
    • execute

      public void execute(int[] globalWorkSizes, int[] localWorkSizes) throws CLException, IllegalArgumentException
      Executes this kernel in n dimensions. globalWorkSize must be evenly divisible by localWorkSize
      Parameters:
      globalWorkSizes - The size of each global work group
      localWorkSizes - The size of each local work group
      Throws:
      CLException - If any error occurs while executing the kernel
      IllegalArgumentException - If the length of globalWorkSizes and localWorkSizes are not equal
      See Also:
    • acquireFromGL

      public void acquireFromGL(CLMemObject... objects) throws CLException
      Acquires the data referenced by this object from OpenGL to allow OpenCL to safely modify it.
      Parameters:
      objects - The objects to acquire from OpenGL
      Throws:
      CLException - If any error occurs while trying to sync data
    • releaseToGL

      public void releaseToGL(CLMemObject... objects) throws CLException
      Releases the data referenced by this object from OpenCL to allow OpenGL to safely modify it again.
      Parameters:
      objects - The objects to acquire from OpenGL
      Throws:
      CLException - If any error occurs while trying to sync data
    • createBufferUnsafe

      @Nullable public @Nullable CLBuffer createBufferUnsafe(int flags, long size)
      Creates a new CL memory buffer. Any errors are consumed and printed to console.
      Parameters:
      flags - a bit-field that is used to specify allocation and usage information such as the memory area that should be used to allocate the buffer object and how it will be used. If value specified for flags is 0, the default is used which is MEM_READ_WRITE. One of:
      All possible OpenCL memory buffer flags
      MEM_READ_WRITE MEM_WRITE_ONLY MEM_READ_ONLY MEM_USE_HOST_PTR MEM_ALLOC_HOST_PTR
      MEM_COPY_HOST_PTR MEM_HOST_WRITE_ONLY MEM_HOST_READ_ONLY MEM_HOST_NO_ACCESS
      size - The size of the buffer in bytes
      Returns:
      A data buffer that can be used with setPointers(int, long...) or setPointers(int, CLMemObject...) or null if an error occurred
      See Also:
      • CL10.clCreateBuffer(long, long, long, IntBuffer)
    • createBuffer

      public CLBuffer createBuffer(int flags, long size) throws CLException
      Creates a new CL memory buffer.
      Parameters:
      flags - a bit-field that is used to specify allocation and usage information such as the memory area that should be used to allocate the buffer object and how it will be used. If value specified for flags is 0, the default is used which is MEM_READ_WRITE. One of:
      OpenCL memory buffer flags
      MEM_READ_WRITE MEM_WRITE_ONLY MEM_READ_ONLY MEM_USE_HOST_PTR MEM_ALLOC_HOST_PTR
      MEM_COPY_HOST_PTR MEM_HOST_WRITE_ONLY MEM_HOST_READ_ONLY MEM_HOST_NO_ACCESS
      size - The size of the buffer in bytes
      Returns:
      A data buffer that can be used with setPointers(int, long...) or setPointers(int, CLMemObject...)
      Throws:
      CLException - If there is any problem creating the buffer
      See Also:
      • CL10.clCreateBuffer(long, long, long, IntBuffer)
    • createBufferFromGLUnsafe

      @Nullable public @Nullable CLBuffer createBufferFromGLUnsafe(int flags, int buffer)
      Creates a new CL memory buffer that reflects the data in an OpenGL buffer. Any errors are consumed and printed to console.
      Parameters:
      flags - a bit-field that is used to specify allocation and usage information such as the memory area that should be used to allocate the buffer object and how it will be used. If value specified for flags is 0, the default is used which is MEM_READ_WRITE. One of:
      OpenCL memory buffer flags
      MEM_READ_WRITE MEM_WRITE_ONLY MEM_READ_ONLY
      buffer - The OpenGL buffer to attach to
      Returns:
      A data buffer that can be used with setPointers(int, long...) or setPointers(int, CLMemObject...) or null if an error occurred
      See Also:
      • CL10GL.clCreateFromGLBuffer(long, long, int, IntBuffer)
    • createBufferFromGL

      public CLBuffer createBufferFromGL(int flags, int buffer) throws CLException
      Creates a new CL memory buffer that reflects the data in an OpenGL buffer.
      Parameters:
      flags - a bit-field that is used to specify allocation and usage information such as the memory area that should be used to allocate the buffer object and how it will be used. If value specified for flags is 0, the default is used which is MEM_READ_WRITE. One of:
      OpenCL memory buffer flags
      MEM_READ_WRITE MEM_WRITE_ONLY MEM_READ_ONLY
      buffer - The OpenGL buffer to attach to
      Returns:
      A data buffer that can be used with setPointers(int, long...) or setPointers(int, CLMemObject...)
      Throws:
      CLException - If there is any problem creating the buffer
      See Also:
      • CL10GL.clCreateFromGLBuffer(long, long, int, IntBuffer)
    • setByte

      public void setByte(int index, byte value) throws CLException
      Sets a single byte parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setShort

      public void setShort(int index, short value) throws CLException
      Sets a single short parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setInt

      public void setInt(int index, int value) throws CLException
      Sets a single int parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setLong

      public void setLong(int index, long value) throws CLException
      Sets a single long parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setFloat

      public void setFloat(int index, float value) throws CLException
      Sets a single float parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setVector2f

      public void setVector2f(int index, org.joml.Vector2fc value) throws CLException
      Sets a single float2 parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setVector2f

      public void setVector2f(int index, float x, float y) throws CLException
      Sets a single float2 parameter.
      Parameters:
      index - The index to set the parameter for
      x - The X value of the parameter
      y - The Y value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setVector3f

      public void setVector3f(int index, org.joml.Vector3fc value) throws CLException
      Sets a single float4 parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setVector4f

      public void setVector4f(int index, org.joml.Vector4fc value) throws CLException
      Sets a single float4 parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setVector4f

      public void setVector4f(int index, float x, float y, float z, float w) throws CLException
      Sets a single float4 parameter.
      Parameters:
      index - The index to set the parameter for
      x - The X value of the parameter
      y - The Y value of the parameter
      z - The Z value of the parameter
      w - The W value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setDouble

      public void setDouble(int index, double value) throws CLException
      Sets a single double parameter.
      Parameters:
      index - The index to set the parameter for
      value - The value of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setPointers

      public void setPointers(int index, long... value) throws CLException
      Sets an array of pointers to the specified parameter.
      Parameters:
      index - The index to set the parameter for
      value - The values of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • setPointers

      public void setPointers(int index, CLMemObject... value) throws CLException
      Sets an array of memory object pointers to the specified parameter.
      Parameters:
      index - The index to set the parameter for
      value - The values of the parameter
      Throws:
      CLException - If there is any problem setting the kernel argument
    • getEnvironment

      public CLEnvironment getEnvironment()
      Returns:
      The environment this kernel is in
    • getProgram

      public net.minecraft.resources.ResourceLocation getProgram()
      Returns:
      The name of the program this kernel is created from
    • getHandle

      public long getHandle()
      Returns:
      The pointer to the kernel object
    • getMaxWorkGroupSize

      public int getMaxWorkGroupSize()
      Returns:
      The maximum size a work group can be
    • free

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