microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] Descriptor bindings assigned before dead code elimination
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Hi,
I am running into an issue where the binding numbers that are being assigned are not quite what I expect.
If you have a shader with 2 unused Cbuffers, then a CBuffer that is used you will end up with Set 0, Binding 2. I would expect it to be Set 0, Binding 0.
(I am using the shift functionality to move the textures and samplers so that buffer start at 0)
In the resulting Spirv I can see that the two unused Cbuffers have been eliminated but the binding index doesn't reflect that.
Texture2D g_texture2D;
sampler g_sampler;
cbuffer a //unused
{
float4x4 g_a;
};
cbuffer b //unused
{
float4x4 g_b;
};
cbuffer c //used
{
float4x4 g_localToClip;
float4 g_randomOffset;
float4 g_colorAdd;
};
float4 mainPS( float3 vTexCoord : TEXCOORD, float4 vColor : COLOR ) : SV_Target
{
return (g_texture2D.Sample( g_sampler, vTexCoord.xy ) * vColor) + g_colorAdd;
}
Expected: c [Set: 0, Binding: 0]
Actual: c [Set: 0, Binding: 2]
Is it possible to get this kind of behaviour?
Thanks!
Nick
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the shader example with SPIR-V output and the stated resource-shift settings. Inspect where descriptor bindings are assigned relative to dead code elimination. Done means the surviving c constant buffer receives Set 0, Binding 0 rather than retaining Binding 2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100