Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous warning about 0 iteration loops with specialization constants in GLSL compatibility mode #5949

Closed
juliusikkala opened this issue Dec 28, 2024 · 1 comment · Fixed by #5953

Comments

@juliusikkala
Copy link
Contributor

When the loop length is dependent on a specialization constant that is initialized to zero, slangc reports that the "loop runs for 0 iterations and will be removed. It shouldn't, since the value of the specialization constant isn't actually known at compile time. Luckily, even with -O2, it doesn't actually appear to get removed, judging from -target glsl output still emitting the loop anyway. So it's probably just the diagnostics.

Source for replicating:

// test.comp
#version 460
layout(constant_id = 0) const uint A = 0;
layout(local_size_x = 1) in;

layout(binding = 0) buffer output_buffer
{
    float output[];
};

void main()
{
    for(uint i = 0; i < A; ++i)
    {
        output[i] = i;
    }
}

(The output buffer is only there to prevent the compiler from optimizing the loop away, it is not particularly necessary to replicate this bug.)

Output:

test.comp(13): warning 30505: the loop runs for 0 iterations and will be removed.
    for(uint i = 0; i < A; ++i)
    ^~~
@juliusikkala
Copy link
Contributor Author

It appears that this is incredibly easy to work around; just not using the const keyword with the specialization constant is enough. Since basically all GLSL shaders with specialization constants use the const keyword, I'll submit a PR to fix this anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant