Recursive calls inside the shader

If inside a vertex shader (or geometry shader) had the ability to make calls at the same vertex shader, would create new mesh tessellation algorithms such as terrain visualization using quads, or selective refinement, without using the CPU.

Virtual sample (G_POINTS to vertex shaders and Geometry shader construct triangles)

layout( recalls=4 ) out; // allocate data to make 0 or 4 recalls
uniform usamplerBuffer mapVertexData;
uniform mat4 PMatrix,MVMatrix;

int computeErrorVisibitlity(usamplerBuffer map,int idVertex)
// return the computed value from PMatrix, MVMatrix or other

for (int k=0;k<4;k++) {
if (computeErrorVisibility(mapVertexData,gl_VertexID+k)) {
// construct attributes & other values
glRecall_VertexID[k] = (gl_VertexID+k)*4; //or another computed value
glRecall(); //don’t return or wait values (need for paralelism)
} else {
gl_Position = PMatrix * MVMatrix * getVertex(mapVertexData,gl_VertexID+k);

Interesting idea. I don’t see any fundamental problem with it.
The GPUs are massively parallel and the single toughest thing for them to deal with efficiently is control divergence.
But if all threads follow the same recursion tree everything should be fine.

Only some form of call stack would be needed to save/restore a subset of the registers.
It will probably impose some recursion depth limits, but still it would allow for interesting algorithms that are currently not easy or possible on GPU.

I would imagine that GPU-accelerated ray tracing would benefit a great deal if recursion was possible, even if control divergence is not allowed,
even though right now i don’t have any concrete idea how exactly :slight_smile: