18/06/2012 GL_AMD_query_buffer_object released

One aspect where I think the OpenGL specification lack of completeness is the interoperability between the fixed-function parts and the programmable function parts of the OpenGL pipeline.

GL_AMD_query_buffer_object leverages one aspect of this issue allowing an application to reuse in a shader the result of a query object by storing it into a buffer, instead of having to read it on the CPU side and then submitting it back to the GPU through a uniform variable or uniform buffer. This is ensuring a synchronization-less rendering.

Anther use case of this extension is when an application is making a large number of queries. Instead of quering each individual result, an application can collect these results into a buffer object and then read all the content of this buffer to obtain the results on the application-side doing a single GPU-CPU round-trip.

This extension offers us the luxury of four examples, the following example is a copy of the first one.

Example 1: Using occlusion query result in shader:
  • // --- Application side ---
  • // Create a buffer object for the query result
  • glGenBuffers(1, &queryBuffer);
  • glBindBuffer(GL_QUERY_BUFFER_AMD, queryBuffer);
  • glBufferData(GL_QUERY_BUFFER_AMD, sizeof(GLuint), NULL, GL_DYNAMIC_COPY);
  • // Perform occlusion query
  • glBeginQuery(GL_SAMPLES_PASSED, queryId)
  • ...
  • glEndQuery(GL_SAMPLES_PASSED);
  • // Get query results to buffer object
  • glBindBuffer(GL_QUERY_BUFFER_AMD, queryBuffer);
  • glGetQueryObjectuiv(queryId, GL_QUERY_RESULT, BUFFER_OFFSET(0));
  • // Bind query result buffer as uniform buffer
  • glBindBufferBase(GL_UNIFORM_BUFFER, 0, queryBuffer);
  • ...
  • // --- Shader ---
  • ...
  • uniform queryResult {
  • uint samplesPassed;
  • }
  • void main() {
  • ...
  • if (samplesPassed > threshold) {
  • // Complex processing
  • ...
  • } else {
  • // Simplified processing
  • ...
  • }
  • }
GLM 0.9.3.4 released >
< May 2012 OpenGL drivers status
Copyright Christophe Riccio 2002-2016 all rights reserved
Designed for Chrome 9, Firefox 4, Opera 11 and Safari 5