Search code examples
shaderdirect3dhlslgeometry-shader

Geometry shader, MaxVertexCount cannot be known


I am currently working on a shader where the amount of vertices are not defined by the amount of triangles, my shader puts a cuber every X units.

This means that I cannot know in advance how many cubes it will create and I do not know many vertices it will take.

However you have to put a maxvertexcount[x]. What do I put in the x?

How do I work around this?

Note: I am a beginner at geometry shaders and know next to nothing about them.


Solution

  • You do know how many vertices it will take ("take" as in input) per-invocation.

    That is defined by the primitive topology; a triangle (strip), for instance takes 3 and triangle adjacency takes 6. MaxVertexCount absolutely has to be known, because there is an implementation limit to the number of vertices you can output per invocation.

    If you hit that limit on a single invocation, then you will have to force the GPU to invoke your Geometry Shader multiple times (Shader Model 5.0 feature). D3D refers to this process as "Geometry Shader Instancing" and gives uint InstanceID : SV_GSInstanceID to identify which duplicate invocation (instance) is executing.

    Your description of the problem is actually making this difficult to answer definitively, could you include some HLSL code to show what you are actually trying to do?