Investigate HLSL shader debugging after bytecode patching
When the debugging information is embedded in shaders, PIX seems to be working, but does not show the structured buffer layout. At the same time it does show the layout of constant buffers. Reproduces with DXIL bytecode SM6.4. PIX Version: 2104.20
Reply from PIX:
There is something strange going on with HLSL source code in this trace.
The VS and PS shaders are both named "hlsl.hlsl". The PS declares Texture2D g_Textures[NUM_TEXTURES]; first, without previous textures, resulting in g_Textures being assigned to t0. However, if you look at the DXIL at global ID 16, g_Textures is assigned t1. This means that when the shader was compiled, some extra HLSL was included that had another single texture declaration. There is such an extra declaration in the VS version of hlsl.hlsl. However, the VS hlsl can't be simply included into the PS hlsl without a few conflicts of things.
I took a look at the engine code, and it seems like it does some magic with hlsl (such as cross-compiling to other target languages on other platforms), and there's a custom include handler that can be overridden. I theorize that when the original HLSL was compiled, the include handler somehow added in that extra texture reference, and when PIX compiles the code with its own include handler, that texture reference is missing. Without diving deep into how the engine compiled the original shader, which I think is out-of-scope for me, I conclude that this isn't an issue with PIX itself.
That said, I can duplicate the expected output image in PIX by editing in specific texture register assignments for the texture and material lookups like so: Texture2D g_Textures[NUM_TEXTURES] : register(t1); StructuredBuffer<MaterialAttribs> g_MaterialAttribs : register(t6); ...to restore the original texture registers, and then applying that HLSL edit with F6.