DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
Internal compiler error on nested switch statement when targeting SM 6.6
Hi, I have encountered an internal compiler error when using nested switch statements. The compiler gives me the following error:
Internal compiler error: access violation. Attempted to read from address 0xFFFFFFFFFFFFFFE8
Here is a minimal shader that reproduces the issue:
static const int kAttribute1 = 0;
static const int kAttribute2 = 1;
struct PackInfo
{
bool m_fPackAttr1_0;
bool m_fPackAttr1_1;
bool m_fPackAttr1_2;
bool m_fPackAttr2_0;
bool m_fPackAttr2_1;
bool m_fPackAttr2_2;
};
bool IsPacked(int attr, int layer, PackInfo pckinf)
{
switch (attr)
{
case kAttribute1:
switch (layer)
{
case 0:
return pckinf.m_fPackAttr1_0;
case 1:
return pckinf.m_fPackAttr1_1;
case 2:
return pckinf.m_fPackAttr1_2;
default:
return false;
}
case kAttribute2:
switch (layer)
{
case 0:
return pckinf.m_fPackAttr2_0;
case 1:
return pckinf.m_fPackAttr2_1;
case 2:
return pckinf.m_fPackAttr2_2;
default:
return false;
}
default:
return false;
}
}
int GetChannelCount(int attr)
{
switch (attr)
{
case kAttribute1: return 2;
case kAttribute2: return 1;
default:
return 1;
}
}
float ExtractPackedValue(int attr, int layer, float4 packed, PackInfo pckinf)
{
int packIndex = 0;
for (int i = 0; i < attr; i++)
{
if (IsPacked(i, layer, pckinf))
packIndex += GetChannelCount(i);
}
return packed[packIndex];
}
RWBuffer<float> out_buf;
StructuredBuffer<PackInfo> pckinf_buf;
[numthreads(8,8,1)]
void main()
{
PackInfo pckinf = pckinf_buf[0];
float4 packedA = float4(0,0,0,0);
out_buf[0] = ExtractPackedValue(kAttribute2, 1, packedA, pckinf);
}
When compiling with /Tcs_6_6. Targeting a lower shader model, I don't get this issue. I hope this is enough information to look into this.
I should probably add that this issue was encountered using the July 2022 release of DXC.
Thanks for the report @mcbouterse!
We'll look into this. In the meantime, you can work around this issue by using the -disable-lifetime-markers
flag