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 backend writes matNxM<f64> construction expressions incorrectly. #4681

Closed
jimblandy opened this issue Nov 14, 2023 · 0 comments · Fixed by #4684
Closed

WGSL backend writes matNxM<f64> construction expressions incorrectly. #4681

jimblandy opened this issue Nov 14, 2023 · 0 comments · Fixed by #4684
Labels
area: naga back-end Outputs of naga shader conversion lang: WGSL WebGPU Shading Language naga Shader Translator type: bug Something isn't working

Comments

@jimblandy
Copy link
Member

The Naga WGSL backend writes incorrect WGSL for Compose expressions building matrices whose elements are f64 values.

To reproduce:

$ cat mat4.frag
#version 450

void main() {
    dvec4 a = dvec4(1.0);
    dvec4 b = dvec4(2.0);
    dmat4 m = dmat4(a, b, a, b);
}
$ cargo run -p naga-cli -- mat4.frag mat4.wgsl
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `/home/jimb/rust/wgpu/target/debug/naga mat4.frag mat4.wgsl`
$ cat mat4.wgsl 
fn main_1() {
    var a: vec4<f64>;
    var b: vec4<f64>;
    var m: mat4x4<f32>;

    a = vec4(f64(1.0));
    b = vec4(f64(2.0));
    let _e8 = a;
    let _e9 = b;
    let _e10 = a;
    let _e11 = b;
    m = mat4x4<f32>(vec4<f64>(_e8.x, _e8.y, _e8.z, _e8.w), vec4<f64>(_e9.x, _e9.y, _e9.z, _e9.w), vec4<f64>(_e10.x, _e10.y, _e10.z, _e10.w), vec4<f64>(_e11.x, _e11.y, _e11.z, _e11.w));
    return;
}

@fragment 
fn main() {
    main_1();
    return;
}
$ 

Note that the construction expression tries to build a mat4x4<f32>. The IR's types arena is:

    types: {
        [1]: Type {
            name: None,
            inner: Vector {
                size: Quad,
                kind: Float,
                width: 8,
            },
        },
        [2]: Type {
            name: None,
            inner: Matrix {
                columns: Quad,
                rows: Quad,
                width: 8,
            },
        },
    },

There is no mat4x4<f32> type in that arena for the Naga Compose expression to refer to, so the WGSL backend must be writing incorrect code for that expression.

@jimblandy jimblandy added type: bug Something isn't working area: naga back-end Outputs of naga shader conversion naga Shader Translator lang: WGSL WebGPU Shading Language labels Nov 14, 2023
jimblandy added a commit to jimblandy/wgpu that referenced this issue Nov 14, 2023
When generating WGSL for an `Expression::Compose` constructing a
matrix, consult `TypeInner::Matrix::width` when writing the
type name in the construction expression, rather than just always
writing `matNxM<f32>`.

Fixes gfx-rs#4681.
jimblandy added a commit to jimblandy/wgpu that referenced this issue Nov 14, 2023
When generating WGSL for an `Expression::Compose` constructing a
matrix, consult `TypeInner::Matrix::width` when writing the
type name in the construction expression, rather than just always
writing `matNxM<f32>`.

Fixes gfx-rs#4681.
jimblandy added a commit to jimblandy/wgpu that referenced this issue Nov 15, 2023
When generating WGSL for an `Expression::Compose` constructing a
matrix, consult `TypeInner::Matrix::width` when writing the
type name in the construction expression, rather than just always
writing `matNxM<f32>`.

Fixes gfx-rs#4681.
jimblandy added a commit that referenced this issue Nov 15, 2023
When generating WGSL for an `Expression::Compose` constructing a
matrix, consult `TypeInner::Matrix::width` when writing the
type name in the construction expression, rather than just always
writing `matNxM<f32>`.

Fixes #4681.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion lang: WGSL WebGPU Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant