slang icon indicating copy to clipboard operation
slang copied to clipboard

[CTS] constant-folding not working for the switch-case labels

Open jkwak-work opened this issue 4 months ago • 0 comments

Problem description One of recent changes (PR #5341) caused a regression. The expression in a switch-case label is no longer folded at the compile-time. It caused CTS failures and four tests are disabled by PR #8

Repro The following shader should compile without error,

#version 310 es
layout(location = 0) in highp vec4 a_position;
layout(location = 1) in highp vec4 a_coords;

layout(location = 0) out mediump vec4 v_color;
layout (std140, set=0, binding=0) uniform buffer0 { highp int ui_two; };

void main (void)
{
    gl_Position = a_position;
    highp vec4 coords = a_coords;
    mediump vec3 res = vec3(0.0);

    const int t = 2;
    switch (ui_two)
    {
        case int(0.0): res = coords.xyz; break;
        case 2-1:      res = coords.wzy; break;
        case 3&(1<<1): res = coords.yzw; break;
        case t+1:      res = coords.zyx; break;
    }

    v_color = vec4(res, 1.0);
}

Currently it prints the following error message.

$ slangc.exe test.slang.vert
test.slang.vert(17): error 39999: expression does not evaluate to a compile-time constant
        case int(0.0):  res = coords.xyz;   break;

Goal Fix the regression and re-enable the disabled CTS tests.

jkwak-work avatar Oct 22 '24 15:10 jkwak-work