Jump to content



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

  • You cannot reply to this topic
2 replies to this topic

#1 relaxok   Members   -  Reputation: 104

Like
0Likes
Like

Posted 25 February 2012 - 08:17 PM

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:

Posted Image

Thanks.

Ad:

#2 Nik02   Members   -  Reputation: 1299

Like
0Likes
Like

Posted 26 February 2012 - 04:49 AM

What would the index be if the geometry was assembled from multiple streams?
Niko Suni
Software developer

#3 MJP   Moderators   -  Reputation: 2128

Like
1Likes
Like

Posted 26 February 2012 - 02:35 PM

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.






We are working on generating results for this topic
PARTNERS