Jump to content

  • Log In with Google      Sign In   
  • Create Account


Per-instance data in (non-vertex) shaders


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

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

#1 Husbjörn   Members   -  Reputation: 230

Like
0Likes
Like

Posted 22 June 2014 - 04:18 PM

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.



Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 4901

Like
3Likes
Like

Posted 22 June 2014 - 07:23 PM

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...



#3 MJP   Moderators   -  Reputation: 10799

Like
1Likes
Like

Posted 22 June 2014 - 09:20 PM

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. 



#4 Husbjörn   Members   -  Reputation: 230

Like
0Likes
Like

Posted 24 June 2014 - 11:54 AM

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, 24 June 2014 - 11:55 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS