Sign in to follow this  

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

This topic is 2114 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:

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205118(v=vs.85).aspx"]http://msdn.microsof...8(v=vs.85).aspx[/url]

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:

[img]http://bh.polpo.org/SV_VertexID.jpg[/img]

Thanks.

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

This topic is 2114 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this