Jump to content
  • Advertisement
Sign in to follow this  

Any way to get which index is being computed in a vertex shader?

This topic is 2788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Note: I am in D3D11, >=4.0 shaders

I've been reading this page today:


It all seems very useful, however it's not quite what I need.

SV_VertexID refers to the actual value of the index in the index buffer you're iterating through, with say, DrawIndexed.

However, there doesn't seem to be a way to get the plain old 'which index am i on?' So when you're for example debugging in PIX and see a DrawIndexed call of 192k indices, there's no way inside the vertex shader to know if you're computing index 0 or 192k or 5 or 99, etc.

Does anybody know any way this is possible in HLSL? I'm kind of stunned it doesn't exist. There are many patterns where the value of the index could help you calculate something that would otherwise waste vertex format space.

Just to be super clear, I'm talking about getting the value of VTX rather than IDX in the below scenario:



Share this post

Link to post
Share on other sites
The problem with indexed draw calls is that the vertex shader won't execute per-index, it will try to run once per vertex and then share the results for identical index values using the post-transform vertex cache. In order for the index value to be useful for you in the shader, the runtime would either have to transparently disable the post-transform cache (which would hurt performance) or somehow expose it through the API.

Typically if you want to do some operation for each expanded vertex in an indexed list, then you need to use a geometry shader.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!