Top Description Fields Constructors Methods
org.lwjgl.opengl

public Class NVShaderBufferLoad

extends Object
Class Inheritance
Imports
java.nio.*, org.lwjgl.system.*

Native bindings to the NV_shader_buffer_load extension.

At a very coarse level, GL has evolved in a way that allows applications to replace many of the original state machine variables with blocks of user-defined data. For example, the current vertex state has been augmented by vertex buffer objects, fixed-function shading state and parameters have been replaced by shaders/programs and constant buffers, etc. Applications switch between coarse sets of state by binding objects to the context or to other container objects (e.g. vertex array objects) instead of manipulating state variables of the context. In terms of the number of GL commands required to draw an object, modern applications are orders of magnitude more efficient than legacy applications, but this explosion of objects bound to other objects has led to a new bottleneck - pointer chasing and CPU L2 cache misses in the driver, and general L2 cache pollution.

This extension provides a mechanism to read from a flat, 64-bit GPU address space from programs/shaders, to query GPU addresses of buffer objects at the API level, and to bind buffer objects to the context in such a way that they can be accessed via their GPU addresses in any shader stage.

The intent is that applications can avoid re-binding buffer objects or updating constants between each Draw call and instead simply use a VertexAttrib (or TexCoord, or InstanceID, or...) to "point" to the new object's state. In this way, one of the cheapest "state" updates (from the CPU's point of view) can be used to effect a significant state change in the shader similarly to how a pointer change may on the CPU. At the same time, this relieves the limits on how many buffer objects can be accessed at once by shaders, and allows these buffer object accesses to be exposed as C-style pointer dereferences in the shading language.

As a very simple example, imagine packing a group of similar objects' constants into a single buffer object and pointing your program at object <i> by setting glVertexAttribI1iEXT(attrLoc, i); and using a shader as such:


struct MyObjectType {
    mat4x4 modelView;
    vec4 materialPropertyX;
    // etc.
};
uniform MyObjectType *allObjects;
in int objectID; // bound to attrLoc

...

mat4x4 thisObjectsMatrix = allObjects[objectID].modelView;
// do transform, shading, etc.

This is beneficial in much the same way that texture arrays allow choosing between similar, but independent, texture maps with a single coordinate identifying which slice of the texture to use. It also resembles instancing, where a lightweight change (incrementing the instance ID) can be used to generate a different and interesting result, but with additional flexibility over instancing because the values are app-controlled and not a single incrementing counter.

Dependent pointer fetches are allowed, so more complex scene graph structures can be built into buffer objects providing significant new flexibility in the use of shaders. Another simple example, showing something you can't do with existing functionality, is to do dependent fetches into many buffer objects:


GenBuffers(N, dataBuffers);
GenBuffers(1, &pointerBuffer);

GLuint64EXT gpuAddrs[N];
for (i = 0; i < N; ++i) {
    BindBuffer(target, dataBuffers[i]);
    BufferData(target, size[i], myData[i], STATIC_DRAW);

    // get the address of this buffer and make it resident.
    GetBufferParameterui64vNV(target, BUFFER_GPU_ADDRESS,
                              gpuaddrs[i]);
    MakeBufferResidentNV(target, READ_ONLY);
}

GLuint64EXT pointerBufferAddr;
BindBuffer(target, pointerBuffer);
BufferData(target, sizeof(GLuint64EXT)*N, gpuAddrs, STATIC_DRAW);
GetBufferParameterui64vNV(target, BUFFER_GPU_ADDRESS,
                          &pointerBufferAddr);
MakeBufferResidentNV(target, READ_ONLY);

// now in the shader, we can use a double indirection
vec4 **ptrToBuffers = pointerBufferAddr;
vec4 *ptrToBufferI = ptrToBuffers[i];

This allows simultaneous access to more buffers than EXT_bindable_uniform (MAX_VERTEX_BINDABLE_UNIFORMS_EXT, etc.) and each can be larger than MAX_BINDABLE_UNIFORM_SIZE_EXT.

Field Summary

Modifier and TypeField and Description
public static final int
GL_BUFFER_GPU_ADDRESS_NV

Accepted by the pname parameter of GetBufferParameterui64vNV, GetNamedBufferParameterui64vNV.

public static final int
GL_GPU_ADDRESS_NV

Returned by the type parameter of GetActiveUniform.

public static final int
GL_MAX_SHADER_BUFFER_ADDRESS_NV

Accepted by the value parameter of GetIntegerui64vNV.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static long
glGetBufferParameterui64NV(int target, int pname)

public static void
glGetBufferParameterui64vNV(int target, int pname, LongBuffer params)

public static void
glGetBufferParameterui64vNV(int target, int pname, long[] params)

Array version of: GetBufferParameterui64vNV

public static long
glGetIntegerui64NV(int value)

public static void
glGetIntegerui64vNV(int value, LongBuffer result)

public static void
glGetIntegerui64vNV(int value, long[] result)

Array version of: GetIntegerui64vNV

public static long
glGetNamedBufferParameterui64NV(int buffer, int pname)

public static void
glGetNamedBufferParameterui64vNV(int buffer, int pname, LongBuffer params)

public static void
glGetNamedBufferParameterui64vNV(int buffer, int pname, long[] params)

Array version of: GetNamedBufferParameterui64vNV

public static long
glGetUniformui64NV(int program, int location)

public static void
glGetUniformui64vNV(int program, int location, LongBuffer params)

public static void
glGetUniformui64vNV(int program, int location, long[] params)

Array version of: GetUniformui64vNV

public static native boolean
public static native boolean
public static native void
public static native void
glMakeBufferResidentNV(int target, int access)

public static native void
public static native void
glMakeNamedBufferResidentNV(int buffer, int access)

public static native void
glProgramUniformui64NV(int program, int location, long value)

public static void
glProgramUniformui64vNV(int program, int location, LongBuffer value)

public static void
glProgramUniformui64vNV(int program, int location, long[] value)

Array version of: ProgramUniformui64vNV

public static native void
glUniformui64NV(int location, long value)

public static void
glUniformui64vNV(int location, LongBuffer value)

public static void
glUniformui64vNV(int location, long[] value)

Array version of: Uniformui64vNV

public static native void
nglGetBufferParameterui64vNV(int target, int pname, long params)

public static native void
nglGetIntegerui64vNV(int value, long result)

public static native void
nglGetNamedBufferParameterui64vNV(int buffer, int pname, long params)

public static native void
nglGetUniformui64vNV(int program, int location, long params)

public static native void
nglProgramUniformui64vNV(int program, int location, int count, long value)

public static native void
nglUniformui64vNV(int location, int count, long value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GL_BUFFER_GPU_ADDRESS_NVback to summary
public static final int GL_BUFFER_GPU_ADDRESS_NV

Accepted by the pname parameter of GetBufferParameterui64vNV, GetNamedBufferParameterui64vNV.

GL_GPU_ADDRESS_NVback to summary
public static final int GL_GPU_ADDRESS_NV

Returned by the type parameter of GetActiveUniform.

GL_MAX_SHADER_BUFFER_ADDRESS_NVback to summary
public static final int GL_MAX_SHADER_BUFFER_ADDRESS_NV

Accepted by the value parameter of GetIntegerui64vNV.

Constructor Detail

NVShaderBufferLoadback to summary
protected NVShaderBufferLoad()

Method Detail

glGetBufferParameterui64NVback to summary
public static long glGetBufferParameterui64NV(int target, int pname)
Annotations
@NativeType:void
glGetBufferParameterui64vNVback to summary
public static void glGetBufferParameterui64vNV(int target, int pname, LongBuffer params)
glGetBufferParameterui64vNVback to summary
public static void glGetBufferParameterui64vNV(int target, int pname, long[] params)

Array version of: GetBufferParameterui64vNV

glGetIntegerui64NVback to summary
public static long glGetIntegerui64NV(int value)
Annotations
@NativeType:void
glGetIntegerui64vNVback to summary
public static void glGetIntegerui64vNV(int value, LongBuffer result)
glGetIntegerui64vNVback to summary
public static void glGetIntegerui64vNV(int value, long[] result)

Array version of: GetIntegerui64vNV

glGetNamedBufferParameterui64NVback to summary
public static long glGetNamedBufferParameterui64NV(int buffer, int pname)
Annotations
@NativeType:void
glGetNamedBufferParameterui64vNVback to summary
public static void glGetNamedBufferParameterui64vNV(int buffer, int pname, LongBuffer params)
glGetNamedBufferParameterui64vNVback to summary
public static void glGetNamedBufferParameterui64vNV(int buffer, int pname, long[] params)

Array version of: GetNamedBufferParameterui64vNV

glGetUniformui64NVback to summary
public static long glGetUniformui64NV(int program, int location)
Annotations
@NativeType:void
glGetUniformui64vNVback to summary
public static void glGetUniformui64vNV(int program, int location, LongBuffer params)
glGetUniformui64vNVback to summary
public static void glGetUniformui64vNV(int program, int location, long[] params)

Array version of: GetUniformui64vNV

glIsBufferResidentNVback to summary
public static native boolean glIsBufferResidentNV(int target)
Annotations
@NativeType:GLboolean
glIsNamedBufferResidentNVback to summary
public static native boolean glIsNamedBufferResidentNV(int buffer)
Annotations
@NativeType:GLboolean
glMakeBufferNonResidentNVback to summary
public static native void glMakeBufferNonResidentNV(int target)
glMakeBufferResidentNVback to summary
public static native void glMakeBufferResidentNV(int target, int access)
glMakeNamedBufferNonResidentNVback to summary
public static native void glMakeNamedBufferNonResidentNV(int buffer)
glMakeNamedBufferResidentNVback to summary
public static native void glMakeNamedBufferResidentNV(int buffer, int access)
glProgramUniformui64NVback to summary
public static native void glProgramUniformui64NV(int program, int location, long value)
glProgramUniformui64vNVback to summary
public static void glProgramUniformui64vNV(int program, int location, LongBuffer value)
glProgramUniformui64vNVback to summary
public static void glProgramUniformui64vNV(int program, int location, long[] value)

Array version of: ProgramUniformui64vNV

glUniformui64NVback to summary
public static native void glUniformui64NV(int location, long value)
glUniformui64vNVback to summary
public static void glUniformui64vNV(int location, LongBuffer value)
glUniformui64vNVback to summary
public static void glUniformui64vNV(int location, long[] value)

Array version of: Uniformui64vNV

nglGetBufferParameterui64vNVback to summary
public static native void nglGetBufferParameterui64vNV(int target, int pname, long params)
nglGetIntegerui64vNVback to summary
public static native void nglGetIntegerui64vNV(int value, long result)
nglGetNamedBufferParameterui64vNVback to summary
public static native void nglGetNamedBufferParameterui64vNV(int buffer, int pname, long params)
nglGetUniformui64vNVback to summary
public static native void nglGetUniformui64vNV(int program, int location, long params)
nglProgramUniformui64vNVback to summary
public static native void nglProgramUniformui64vNV(int program, int location, int count, long value)
nglUniformui64vNVback to summary
public static native void nglUniformui64vNV(int location, int count, long value)