Package foundry.veil.api.opencl
Class CLKernel
java.lang.Object
foundry.veil.api.opencl.CLKernel
- All Implemented Interfaces:
AutoCloseable
,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 TypeMethodDescriptionvoid
acquireFromGL
(CLMemObject... objects) 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
free()
long
int
net.minecraft.resources.ResourceLocation
void
releaseToGL
(CLMemObject... objects) 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
Executes this kernel in 1 dimension.globalWorkSize
must be evenly divisible bylocalWorkSize
- Parameters:
globalWorkSize
- The size of the global work grouplocalWorkSize
- 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 bylocalWorkSize
- Parameters:
globalWorkSizeX
- The size of the global work group in the XlocalWorkSizeX
- The size of each local work group in the XglobalWorkSizeY
- The size of the global work group in the YlocalWorkSizeY
- 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 bylocalWorkSize
- Parameters:
globalWorkSizeX
- The size of the global work group in the XlocalWorkSizeX
- The size of each local work group in the XglobalWorkSizeY
- The size of the global work group in the YlocalWorkSizeY
- The size of each local work group in the YglobalWorkSizeZ
- The size of the global work group in the ZlocalWorkSizeZ
- 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 bylocalWorkSize
- Parameters:
globalWorkSizes
- The size of each global work grouplocalWorkSizes
- The size of each local work group- Throws:
CLException
- If any error occurs while executing the kernelIllegalArgumentException
- If the length ofglobalWorkSizes
andlocalWorkSizes
are not equal- See Also:
-
acquireFromGL
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
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
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 isMEM_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...)
orsetPointers(int, CLMemObject...)
ornull
if an error occurred - See Also:
-
createBuffer
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 isMEM_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...)
orsetPointers(int, CLMemObject...)
- Throws:
CLException
- If there is any problem creating the buffer- See Also:
-
createBufferFromGLUnsafe
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 isMEM_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...)
orsetPointers(int, CLMemObject...)
ornull
if an error occurred - See Also:
-
createBufferFromGL
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 isMEM_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...)
orsetPointers(int, CLMemObject...)
- Throws:
CLException
- If there is any problem creating the buffer- See Also:
-
setByte
Sets a single byte parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setShort
Sets a single short parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setInt
Sets a single int parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setLong
Sets a single long parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setFloat
Sets a single float parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setVector2f
Sets a single float2 parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setVector2f
Sets a single float2 parameter.- Parameters:
index
- The index to set the parameter forx
- The X value of the parametery
- The Y value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setVector3f
Sets a single float4 parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setVector4f
Sets a single float4 parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setVector4f
Sets a single float4 parameter.- Parameters:
index
- The index to set the parameter forx
- The X value of the parametery
- The Y value of the parameterz
- The Z value of the parameterw
- The W value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setDouble
Sets a single double parameter.- Parameters:
index
- The index to set the parameter forvalue
- The value of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setPointers
Sets an array of pointers to the specified parameter.- Parameters:
index
- The index to set the parameter forvalue
- The values of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
setPointers
Sets an array of memory object pointers to the specified parameter.- Parameters:
index
- The index to set the parameter forvalue
- The values of the parameter- Throws:
CLException
- If there is any problem setting the kernel argument
-
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 interfaceorg.lwjgl.system.NativeResource
-