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

[glsl-in] lost statement of multi part loop-expression #6208

Open
Vipitis opened this issue Sep 3, 2024 · 0 comments
Open

[glsl-in] lost statement of multi part loop-expression #6208

Vipitis opened this issue Sep 3, 2024 · 0 comments
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working

Comments

@Vipitis
Copy link

Vipitis commented Sep 3, 2024

Description
If the third expression of a for loop (loop-expression according to the spec Chapter 6.3) contains multiple statements... naga just takes the last one and forgets the the first. I haven't looked at more than two statements.

this leads to infinite loops and potential crashes. Likely root cause to finding gfx-rs/wgpu-native#416, maybe related to #4558

Repro steps
I have two semantically equivalent code snippets in glsl

for (int i = 0; i < 50; i+=1, b+=0.01) {
        a -= 0.01;
    }
for (int i = 0; i < 50; b+=0.01, i+=1) {
        a -= 0.01;
    }

the third expression contains the usual incrementor, as well as a completely unrelated statement.

translating them to wgls using naga gives me the following output for this loop

loop {
        let _e22 = i;
        if !((_e22 < 50i)) {
            break;
        }
        {
            let _e29 = a;
            a = (_e29 - 0.01f);
        }
        continuing {
            let _e26 = b;
            b = (_e26 + 0.01f);
        }
    }
loop {
        let _e22 = i;
        if !((_e22 < 50i)) {
            break;
        }
        {
            let _e29 = a;
            a = (_e29 - 0.01f);
        }
        continuing {
            let _e26 = i;
            i = (_e26 + 1i);
        }
    }

the difference is which statement is part of the continuing block. The other statement is completely lost. It is dependant on the order.

Expected vs observed behavior
A reference for this being valid in a shadertoy. Perhaps the continuing block could just include both statements?

Platform
naga 22.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants