Skip to main content
gamedev.net
🔒 Locked

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

Started by relaxok 1 reply 1.7k views
Original Post
relaxok
relaxok
Note: I am in D3D11, >=4.0 shaders

I've been reading this page today:

http://msdn.microsof...8(v=vs.85).aspx

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:

SV_VertexID.jpg

Thanks.
Nik02
Nik02
What would the index be if the geometry was assembled from multiple streams?
Niko Suni
MJP
MJP
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.