PDA

View Full Version : (GL 4.6) How to write parameter buffer from shaders?



Asylum
09-27-2017, 09:21 AM
Khronos recently released the OpenGL 4.6 spec which incorporates the ARB_indirect_parameters extension.
While it's rather obvious how to use the new functions (f.e. glMultiDrawElementsCount) it is not clear how one can fill the parameter buffer in a shader as glBindBufferBase doesn't accept the GL_PARAMETER_BUFFER enum (according to the spec.).

So my questions are:

how do I write this buffer from a shader
how do I write this buffer with transform feedback

Alfonse Reinheart
09-27-2017, 10:22 AM
Buffer objects are not typed. There is no such thing as a "parameter buffer," "vertex buffer," "pixel buffer," or anything. There are just buffer objects (https://www.khronos.org/opengl/wiki/Buffer_Object), and the various ways in which they can be used. Any buffer object can be used with any of the buffer object usages.

So if you have a buffer, you can write to it from a shader using any of the ways of doing so. Atomic counters, image load/store to buffer textures, SSBOs, etc. After that's done, bind it to the `GL_PARAMETER_BUFFER` bind point and render.

... that being said, I just realized something. The ARB neglected to add a `glMemoryBarrier` bit for parameter buffer usage. So you actually can't use image load/store or SSBOs to write, since there's no barrier to make those writes visible.

Asylum
09-28-2017, 01:53 AM
Thanks, that was my first thought too, I just wanted confirmation. The GL standard is a little confusing in this regard, with all its buffer bindings etc.
In Metal for example you really have just one general-purpose buffer concept, and you can use it for whatever you want to.

Dark Photon
09-28-2017, 06:29 AM
In Metal for example you really have just one general-purpose buffer concept, and you can use it for whatever you want to.
That's what you have in OpenGL too.

The difference is that instead of always passing in these buffer objects as parameters to functions that use them (e.g. glVertexAttribPointer), you sometimes bind them to context-provided buffer bind targets (https://www.khronos.org/opengl/wiki/Buffer_Object#General_use) first, and then those API calls read the buffer handles from there. The bind targets behave as implicit parameters to those functions.