microsoft / microsoft/DirectXShaderCompiler
Problem with DXIL signing and switch case/enum use
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Hi! I'm having a bit of trouble with emitted shader code which is then passed to DXC and I think this case qualifies as a bug:
enum class QualityT { Low, Medium, High, };
struct MyStruct
{
float4 m_color;
uint4 m_shaderVariantKey[1];
};
ConstantBuffer<MyStruct> MyCB : register(b0);
::QualityT __GetQuality()
{
uint shaderKey = (MyCB.m_shaderVariantKey[0].w >> 0) & 3;
return (::QualityT) shaderKey;
}
float4 MainPS() :SV_Target0
{
static const int IntOption = 4;
switch ( __GetQuality() )
{
case QualityT::Low: return MyCB.m_color * float4 (IntOption, 0, 0, 0) ;
case QualityT::Medium: return MyCB.m_color * float4 (0, IntOption, 0, 0) ;
case QualityT::High: return MyCB.m_color * float4 (0, 0, IntOption, 0) ;
}
}
The code fails validation:
warning: DXIL.dll not found. Resulting DXIL will not be signed for use in release environments.
error: validation errors
at 0x24f9e5b2a10 inside block #0 of function MainPS Instructions must be of an allowed type
Validation failed.
Shader playground link: http://shader-playground.timjones.io/5a194437e2936994ce22465b0ffdea4b
The issue doesn't end here. Commenting out any one of the three switch cases results in a valid DXIL code (but it shouldn't, because there is no default case). Adding a new enumerator results in failed validation + correct error message (enum class QualityT { Low, Medium, High, Fake };).
Finally, adding a default case fixed the signing validation problem, although there are no enumerations that fall in the default case: http://shader-playground.timjones.io/43eb8687ee339c98c7d52bebaf766d56
Thanks,
Alex
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 provided HLSL example with DXC, using the linked Shader Playground cases as references. Compare validation with all three enum switch cases, with one case removed, and with a default case. Done means the original complete switch validates and signs without requiring an unreachable default case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100