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.
Crossbones+ - Reputation: 6334
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...
Jason Zink :: DirectX MVP
Direct3D 11 engine on CodePlex: Hieroglyph 3
Direct3D Books: Practical Rendering and Computation with Direct3D 11, Programming Vertex, Geometry, and Pixel Shaders
Articles: Dual-Paraboloid Mapping Article :: Parallax Occlusion Mapping Article (original):: Fast Silhouettes Article
Games: Lunar Rift
Moderators - Reputation: 17297
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.