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

WGSL Let vs Var and Expected Error messages. #1454

Closed
genusistimelord opened this issue Oct 7, 2021 · 2 comments
Closed

WGSL Let vs Var and Expected Error messages. #1454

genusistimelord opened this issue Oct 7, 2021 · 2 comments
Labels
area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language

Comments

@genusistimelord
Copy link

// Fragment shader
[[stage(fragment)]]
fn main(in: VertexOutput,) -> [[location(0)]] vec4<f32> {
    let coords = vec3<i32>(i32(in.tex_coords.x), i32(in.tex_coords.y), i32(in.tex_coords.z));
    let object_color = textureLoad(tex, coords.xy, coords.z, 0);
    let color =  hueShift(object_color.rgb, f32(in.col.r));
    let ldchange = in.col.g / 1000000000u;
    let ldoffset = f32((in.col.g % 900000000u) / 1000000u) / 100.0;

    if (ldchange > 0u) {
        let color = color + vec3<f32>(ldoffset, ldoffset, ldoffset);
    } else {
        let color = color - vec3<f32>(ldoffset, ldoffset, ldoffset);
    }

    let color = color * (f32(in.col.b) / 100.0);
    let alpha = object_color.a * (f32(in.col.a)/ 100.0);
    return vec4<f32>(object_color.rgb, alpha);
}

So in the Above Code Example the Color that is first created I was attempting to Reset it within the if statement and then outside of the if statement. This Should either A: output code that var's Color or B: possibly throw a Error mentioning that you can not remake let with the same name Or have a Warning that says we detected you where Attempting to Reuse Color and should instead is var in lets place and remove let from the rest.

This issue was found as it failed to run on someone else's PC due to the Error message

[2021-10-07T13:24:55Z ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
In Device::create_render_pipeline
note: label = Sprite render pipeline
Internal error in VERTEX shader: D3DCompile error (0x80004005): C:\Users\Stefano\Desktop\reee\render_demo\Shader(76,26-31): error X3004: undeclared identifier 'color1'

But would run perfectly fine on other computers.

@kvark kvark added area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language labels Oct 7, 2021
@kvark
Copy link
Member

kvark commented Oct 7, 2021

Thank you for filing!
WGSL frontend shouldn't allow shadowing local variable names.

@jimblandy
Copy link
Member

These declarations will have no effect:

    if (ldchange > 0u) {
        let color = color + vec3<f32>(ldoffset, ldoffset, ldoffset);
    } else {
        let color = color - vec3<f32>(ldoffset, ldoffset, ldoffset);
    }

The author seems to expect this to change the value of color observed later, but that's not what this code does. It declares two independent variables color, each local to their branch of the if, which then immediately go out of scope without being used. The entire if has no effect.

This declaration ought to elicit an error from Naga:

    let color = color * (f32(in.col.b) / 100.0);

because it is a redeclaration of the color defined earlier:

    let color =  hueShift(object_color.rgb, f32(in.col.r));

Naga fails to report this. That bug is already covered by #1044, so I'm going to close this issue as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language
Projects
None yet
Development

No branches or pull requests

3 participants