Why does this HLSL pixel shader not compile?
I'm working on a ray tracing pixel shader and came across a weird error. I wrote the following code solely to generate the error, it's pointless but I can't figure out what's wrong with it.
float4 main(/*Any input*/) : SV_TARGET
{
uint uints[2];
float4 light[2];
uints[0] = 0;
uints[1] = 0;
uint c = 1;
[loop] while (c > 0) {
if (uints[c] == 0)
light[c - 1] = 0.0f;
else
light[c - 1] = 0.0f;
c--;
break;
}
return light[0];
}
When compiled with shader model 5_0 (with and without optimizations) I get the following error:
error MSB6006: "fxc.exe" exited with code -1073741819
Doing seemingly meaningless things to the code, like removing c--;
, gets rid of the error. Can anyone figure out what this weird error comes from?
In my case it compiles if I remove the [loop]
tag.
// Compiling pixel shader
ComPtr<ID3DBlob> pixelBlob = nullptr;
ComPtr<ID3DBlob> pixelErrorBlob = nullptr;
result = D3DCompile(pixelShaderByteCode.c_str(),
pixelShaderByteCode.length(),
nullptr,
nullptr,
nullptr,
"main", "ps_5_0",
compileFlags, 0,
pixelBlob.GetAddressOf(),
pixelErrorBlob.GetAddressOf());
float4 main(PixelInput input) : SV_TARGET
{
uint uints[2];
float4 light[2];
uints[0] = 0;
uints[1] = 0;
uint c = 1;
while (c > 0) {
if (uints[c] == 0)
light[c - 1] = 0.0f;
else
light[c - 1] = 0.0f;
c--;
break;
}
return light[0];
}