Skip to content

failed to legalize SPIR-V: Variable cannot be replaced: invalid index on embedded loop #8832

Description

@MichelVachon

Description
A shader does not compile with "-fspv-flatten-resource-arrays" with a mixture of for loops and ifs

Note: the shader compiles when the if() condition is moved inside the inner loop.

Steps to Reproduce
Compile the following shader

RWTexture2D HZBDstTextures[16];
[numthreads(8, 8, 1)]
void main(uint3 groupId : SV_GroupID)
{
[unroll]
for (uint srcTextureID = 0; srcTextureID < 16; srcTextureID++)
{
[branch]
if (srcTextureID == groupId.z)
{
[unroll]
for (uint mipOffset = 1; mipOffset < 4; mipOffset++)
{
const uint dstTextureID = srcTextureID + mipOffset;
HZBDstTextures[dstTextureID][uint2(0, 0)] = 2.2f;
}
}
}
}

With the following command line:
dxc.exe" /T cs_6_0 -spirv -fspv-flatten-resource-arrays

Actual Behavior
The following error message is reported:
fatal error: failed to legalize SPIR-V: Variable cannot be replaced: invalid index
%87 = OpAccessChain %_ptr_UniformConstant_type_2d_image %HZBDstTextures %85
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Environment

  • DXC version dxcompiler.dll: 1.10(5373-c4d8f4f9)(1.10.2605.37) - 1.10.2605.37 (c4d8f4f)
  • Host Operating System Windows 11 Enterprise 24H2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triagespirvWork related to SPIR-V

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions