glslshaderpersistence

Persistent data in a shader - GLSL


Is it possible to have persistent data within the same shader? Something like a uniform, except that the shader itself can set it.

What I'm trying to do is embed a vertex in my vertex stream that will act as a "state change" and affect an operation on all vertices downstream. I.E. the vertex shader says "ah, I hit this vertex" and turns a boolean on or off... and later vertices can check that boolean. It doesn't need to work between shaders, it just needs to work during a single pump of vertices.

Is this possible? Using GLSL.


Solution

  • embed a vertex in my vertex stream that will act as a "state change" and affect an operation on all vertices downstream.

    That's not possible. Invocations of a particular shader stage execute in a largely undefined order with respect to other invocations within that stage (and drawing command). Regardless of the ability to read or write memory, you cannot ensure that "downstream" invocations will not have been executed before the "upstream" invocations wrote to that memory.

    If you want to do something like that, you will need to put them into separate drawing commands as well as issue appropriate memory barriers (to make such writes visible to later commands ) between such draws.