rate up
1
rate down
Indexing in DirextX12
I've seen Dynamic Indexing using HLSL 5.1 on Microsofts website and was wondering if anyone knew if there are performance differences between dynamic indexing and previous indexing methods (static?) when using DirectX 12? Thought I would ask before spending time trying to make tests. Thanks
Chosen Answer
rate up
1
rate down
Dynamic indexing provides flexibility at the cost of an added level of indirection. So all other things aside, if you were to access a texture from a texture array dynamically compared to accessing the same texture from the same array statically, accessing that texture statically would perform better because the shader would be compiled to access that texture directly when compiled, compared to the indirection of dynamic indexing, where the shader would have to index into the array to get the texture. There is also the issue where if not every element (pixel, vertex) in a draw call will use the same index when dynamically indexing, which would also hurt performance. I'll mention that below. Although just accessing the texture statically vs dynamically theoretically has a clear performance winner, in practice you might find that the way you have written your shader performs better when dynamically indexing into the array. For example, you might have to branch when using precompiled (static) indexing: float4 finalcolor = float4(0.0f, 0.0f, 0.0f, 1.0f); if(matidx == 0) { finalcolor = texarray[0].Sample(sampler, texcoords); } else if(matidx == 1) { finalcolor = texarray[1].Sample(sampler, texcoords); } ... But with dynamic indexing you can do without the branching: float4 finalcolor = texarray[matidx].Sample(sampler, texcoords); Different GPU's do things differently, so i can't tell you how much better or worse either a precompiled index or dynamic index would perform, but since dynamic indexing does indeed add a level of indirection, it seems obvious it will generally perform a little slower. You can also imagine if the dynamic index is going to be changing a lot in a single draw call it will perform worse as well. The reason is because the GPU will group elements (pixels, vertices, geometry) and run that group through the same shader code. If the code between any of those elements change, it will need to address that, probably by separating them from the group and running their specific shader code. I don't know exactly how it addresses this, but hopefully you get the idea. Ideally you want all elements (vertices, pixels) to run through the exact same shader code. That will give you the best performance, which is why dynamic branching is bad (when one element takes one branch and the next element takes the next branch). If all the elements go through the same branch (if statement), then the branching doesn't hurt performance since all the elements are running the same code Hope that answers your question!
Comments
Thank you for the explanation.
on Oct 27 `16
sobe118
Sign in to answer!