public class ARBComputeShader
extends java.lang.Object
Recent graphics hardware has become extremely powerful and a strong desire to harness this power for work (both graphics and non-graphics) that does not fit the traditional graphics pipeline well has emerged. To address this, this extension adds a new single-stage program type known as a compute program. This program may contain one or more compute shaders which may be launched in a manner that is essentially stateless. This allows arbitrary workloads to be sent to the graphics hardware with minimal disturbance to the GL state machine.
In most respects, a compute program is identical to a traditional OpenGL program object, with similar status, uniforms, and other such properties. It has access to many of the same resources as fragment and other shader types, such as textures, image variables, atomic counters, and so on. However, it has no predefined inputs nor any fixed-function outputs. It cannot be part of a pipeline and its visible side effects are through its actions on images and atomic counters.
OpenCL is another solution for using graphics processors as generalized compute devices. This extension addresses a different need. For example, OpenCL is designed to be usable on a wide range of devices ranging from CPUs, GPUs, and DSPs through to FPGAs. While one could implement GL on these types of devices, the target here is clearly GPUs. Another difference is that OpenCL is more full featured and includes features such as multiple devices, asynchronous queues and strict IEEE semantics for floating point operations. This extension follows the semantics of OpenGL - implicitly synchronous, in-order operation with single-device, single queue logical architecture and somewhat more relaxed numerical precision requirements. Although not as feature rich, this extension offers several advantages for applications that can tolerate the omission of these features. Compute shaders are written in GLSL, for example and so code may be shared between compute and other shader types. Objects are created and owned by the same context as the rest of the GL, and therefore no interoperability API is required and objects may be freely used by both compute and graphics simultaneously without acquire-release semantics or object type translation.
Requires OpenGL 4.2. Promoted to core in OpenGL 4.3.
| Modifier and Type | Field and Description |
|---|---|
static int |
GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER
Accepted by the
pname parameter of GetActiveAtomicCounterBufferiv. |
static int |
GL_COMPUTE_SHADER
Accepted by the
type parameter of CreateShader and returned in the params parameter by GetShaderiv. |
static int |
GL_COMPUTE_SHADER_BIT
Accepted by the
stages parameter of UseProgramStages. |
static int |
GL_COMPUTE_WORK_GROUP_SIZE
Accepted by the
pname parameter of GetProgramiv. |
static int |
GL_DISPATCH_INDIRECT_BUFFER
Accepted by the
target parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, and GetBufferPointerv. |
static int |
GL_DISPATCH_INDIRECT_BUFFER_BINDING
Accepted by the
value parameter of GetIntegerv, GetBooleanv, GetInteger64v, GetFloatv, and GetDoublev. |
static int |
GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_ATOMIC_COUNTERS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_IMAGE_UNIFORMS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_SHARED_MEMORY_SIZE
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_UNIFORM_BLOCKS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_UNIFORM_COMPONENTS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_WORK_GROUP_COUNT
Accepted by the
pname parameter of GetIntegeri_v, GetBooleani_v, GetFloati_v, GetDoublei_v and GetInteger64i_v. |
static int |
GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS
Accepted by the
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v. |
static int |
GL_MAX_COMPUTE_WORK_GROUP_SIZE
Accepted by the
pname parameter of GetIntegeri_v, GetBooleani_v, GetFloati_v, GetDoublei_v and GetInteger64i_v. |
static int |
GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER
Accepted by the
pname parameter of GetActiveUniformBlockiv. |
| Modifier and Type | Method and Description |
|---|---|
static void |
glDispatchCompute(int num_groups_x,
int num_groups_y,
int num_groups_z)
Launches one or more compute work groups.
|
static void |
glDispatchComputeIndirect(long indirect)
Launches one or more compute work groups using parameters stored in a buffer.
|
public static final int GL_COMPUTE_SHADER
type parameter of CreateShader and returned in the params parameter by GetShaderiv.public static final int GL_MAX_COMPUTE_UNIFORM_BLOCKS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_IMAGE_UNIFORMS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_SHARED_MEMORY_SIZE
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_UNIFORM_COMPONENTS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_ATOMIC_COUNTERS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS
pname parameter of GetIntegerv, GetBooleanv, GetFloatv, GetDoublev and GetInteger64v.public static final int GL_MAX_COMPUTE_WORK_GROUP_COUNT
pname parameter of GetIntegeri_v, GetBooleani_v, GetFloati_v, GetDoublei_v and GetInteger64i_v.public static final int GL_MAX_COMPUTE_WORK_GROUP_SIZE
pname parameter of GetIntegeri_v, GetBooleani_v, GetFloati_v, GetDoublei_v and GetInteger64i_v.public static final int GL_COMPUTE_WORK_GROUP_SIZE
pname parameter of GetProgramiv.public static final int GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER
pname parameter of GetActiveUniformBlockiv.public static final int GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER
pname parameter of GetActiveAtomicCounterBufferiv.public static final int GL_DISPATCH_INDIRECT_BUFFER
target parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, and GetBufferPointerv.public static final int GL_DISPATCH_INDIRECT_BUFFER_BINDING
value parameter of GetIntegerv, GetBooleanv, GetInteger64v, GetFloatv, and GetDoublev.public static final int GL_COMPUTE_SHADER_BIT
stages parameter of UseProgramStages.public static void glDispatchCompute(int num_groups_x,
int num_groups_y,
int num_groups_z)
num_groups_x - the number of work groups to be launched in the X dimensionnum_groups_y - the number of work groups to be launched in the Y dimensionnum_groups_z - the number of work groups to be launched in the Z dimensionpublic static void glDispatchComputeIndirect(long indirect)
The parameters addressed by indirect are packed a structure, which takes the form (in C):
typedef struct {
uint num_groups_x;
uint num_groups_y;
uint num_groups_z;
} DispatchIndirectCommand;
A call to glDispatchComputeIndirect is equivalent, assuming no errors are generated, to:
cmd = (const DispatchIndirectCommand *)indirect;
glDispatchCompute(cmd->num_groups_x, cmd->num_groups_y, cmd->num_groups_z);indirect - the offset into the buffer object currently bound to the DISPATCH_INDIRECT_BUFFER buffer target at which the dispatch parameters are
stored.Copyright LWJGL. All Rights Reserved. License terms.