Jump to content
  • Advertisement
Sign in to follow this  
Husbj

Per-instance data in (non-vertex) shaders

This topic is 1488 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

So I've been using per-instance input slots for providing world and world-view-projection matrices to my vertex shaders for instanced meshes. This works just fine and I've been passing them along through the output of the vertex shader for some small tests when needed. However as shaders get more complex it cannot be the best way to copy such per-instance data for each vertex just to make it available to other shader stages. I know I could set up a constant buffer that contains arrays indexable by the instance id that is a smaller overhead to pass along throughout the shader pipeline, but is there any other way to achieve this? I'd rather not use the cbuffer array approach since the amount of instances in any given frame may vary.

Share this post


Link to post
Share on other sites
Advertisement

You could do more or less the same thing as the constant buffer approach, but instead use an SRV to hold the data.  That allows you to have a variable sized resource that has a much larger potential size than a CB, and you can still access the data in a simple way.  You will have to test it out to see if there is a performance delta for your particular situation though, since you will be trading device memory accesses for interpolants.  It may or may not be a good trade off...

Share this post


Link to post
Share on other sites

Like Jason mentioned if you have your instance data in a buffer or texture (StructuredBuffer is probably the easiest to work with) then you can fetch the data in any stage as long as you pass the InstanceID downward from the vertex shader. 

Share this post


Link to post
Share on other sites

Ah, that's clever, didn't know there were separate buffer resources in addition to having to rebuild and sample a texture.

Thanks!

Edited by Husbjörn

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!