DrawProceduralIndirect & Graphics Buffer Index

So I’ve been using DrawProceduralIndirect to draw meshes with Structured buffers, I understand a fair amount about the SRP and shaders. I’ve messed around with the Graphics Buffer, but cannot for the life of me find any documentation or post about how to use it to pass index data into a shader.

I have noticed that SV_VERTEXID within the shader doesn’t seem to be used when using:
public void DrawProceduralIndirect(GraphicsBuffer indexBuffer, Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs);

I’ve done allot of googling about this question and could only find past Posts which either pointed to the lack luster documentation of the API or just said its in the works:

So a fairly simple question, how does one get the index passed in by the IndexBuffer within the vertex pass?

Thanks.

Hey, try SV_IndexID

Cheers, thats exactly what I was looking for.

1 Like

Just cooked up a real quick test, however Im getting an invalid Input Semantic:
invalid vs_4_0 input semantic 'SV_INDEXID'

Is there something else that needs to be enabled?

Test Shader:

Shader "Unlit/Test"
{
    SubShader
    {
        Pass
        {
            HLSLPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            StructuredBuffer<float3> _Verts;

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

            v2f vert (uint index : SV_INDEXID)
            {
                v2f o;
                o.vertex = float4(_Verts[index], 0);
                return o;
            }

            float3 frag (v2f i) : SV_Target
            {
                return 1;
            }
          
            ENDHLSL
        }
    }
}

I just checked the hlsl docs and I’ve given you bad advice: SV_Index doesn’t exist, and I misread your initial question, SV_VertexID is indeed what you want.

I’m surprised you found that SV_VertexID wasn’t valid with that API… it should always be valid. Maybe your ComputeBuffer args were incorrect and you only passed one vertex per instance?

No worries, I figured it out earlier out in the day. Indeed the Args Computer buffer had the wrong stride, so it was missing the last argument. I was fairly suprised there were no exceptions being kicked off from within Unity, but I found out that the Args Buffer was wrong by doing a capture via Render Doc, DirectX was spitting out some errors about it.

So I can confirm SV_VertexID should of being working and it is indeed now working. Sorry for wasting time, but it was a fun rabbit hole to jump down.

The Graphics Buffer is really intresting, cant wait to see what more it can do in the future.

2 Likes