Question

What's the equivalent in OpenCL to GLSL's uniform variables?

Where are uniform variables located in the GPU memory in OpenCL terms? When are they passed from the host to the GPU?

I understand that the answer may depend on the specific OpenGL implementation, but I wonder if there are some rules or a reasonable assumptions about this.

Was it helpful?

Solution

In GLSL the uniforms are accessible from every shader stage and instance in a read only manner. So it shows the behavior of the corresponding OpenCl global memory. Considering the constness of these values (that you can't modify them inside the shaders) it equals especially the __constant memory of OpenCL.

More information can be found here: http://www.opengl.org/wiki/Uniform_(GLSL) and here: http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/constant.html

I would prefer the __constant memory solution, because of optimization possibilities. Some OpenCL drivers may flush these __constant values directly down to the fast local or private memory, if there is enough space left from your kernel memory occupancy. When this is not done also the memory controller for the global memory (which contains the __constant memory) is able to work faster on the __constant part, because there can't be an update request from the kernel code.

The uniforms in OpenGL are transferred directly when calling glUniformXX.

Consider that you are also able to create uniform buffer objects. The access in this case is controlled by uniform buffer binding points. This is quiet similar to the texture handling in OpenGL. More information about UBO usage can be found here: http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/3490-2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top