Skip to content

Constexpr propagation checks do not work as expected. #6370

@mifreundorfer

Description

@mifreundorfer

Tested with v2025.5.1, compiling the following code:

Texture2D<float4> input;
RWTexture2D<float4> output;

float3 LoadSourceColor(uint2 pixelPos, int2 offset) {
    return input.Load(int3(pixelPos, 0), offset).rgb;
}

[shader("compute")]
void Test(uint3 thread_index : SV_DispatchThreadID) {
    float4 result = 0;

    [unroll]
    for (int i = 0; i < 3 * 3 - 1; i++) {
        //result.rgb += input.Load(int3(thread_index.xy, 0), int2( i % 3, i / 3 )).rgb;
        result.rgb += LoadSourceColor(thread_index.xy, int2( i % 3, i / 3 )).rgb;
    }

    output[thread_index.xy] = result;
}
  • Slang fails to unroll the loop when a function is called inside the loop. Inlining the load correctly unrolls the loop.
  • When the loop fails to unroll, invalid SPIR-V is generated for OpImageFetch with ConstOffset instead of Offset, using a non constant value.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions