r/GraphicsProgramming • • Jun 03 '23

Question How do arguments to entry point functions work?

When you have a shader with an entry point that takes some arguments, how does that input get assigned? For example: PS_INPUT VS_Main( uint vertexId : SV_VertexID )- where does vertexid come from? Does the semantic SV_VertexID make it run on every vertex in the vertex buffer? How does the index buffer play into it?

Thanks!

0 Upvotes

3 comments sorted by

1

u/wm_lex_dev Jun 03 '23 edited Jun 03 '23

The vertex shader will automatically run once for every vertex. The semantic : SV_VertexID tells the GPU that this is the variable that is supposed to represent the current vertex's ID.

If you don't use that ID, you can just omit the variable and nothing will change.

IIRC, with indexed rendering the vertex shader runs once for each index, which means the same vertex can get processed more than once, with a different ID each time.

I say "ID", but a better term might be "index" except for the fact that "index" is an incredibly overloaded term. The first vertex has the ID 0, the second one has the ID 1, etc.

EDIT: Reworded my comment

1

u/hanotak Jun 03 '23

Thanks!

1

u/DolphinsAreOk Jun 03 '23

Its the Input Assembers job to do this, searching for this might help.