Skip to content

[hlsl-out] Stores of vec2-based matrix inside struct tries to access raw matrix directly #4423

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

Open
Tracked by #2719
cwfitzgerald opened this issue Dec 27, 2022 · 3 comments · May be fixed by #7438
Open
Tracked by #2719

[hlsl-out] Stores of vec2-based matrix inside struct tries to access raw matrix directly #4423

cwfitzgerald opened this issue Dec 27, 2022 · 3 comments · May be fixed by #7438
Assignees
Labels
area: naga back-end Outputs of naga shader conversion lang: HLSL D3D Shading Language naga Shader Translator type: bug Something isn't working

Comments

@cwfitzgerald
Copy link
Member

WGSL

struct Ah {
    inner: mat2x2<f32>,
};
@group(0) @binding(0)
var<storage, write> ah: Ah;

@compute @workgroup_size(1)
fn cs_main() {
    ah = Ah(mat2x2<f32>(vec2<f32>(0.0), vec2<f32>(1.0)));
}

HLSL

struct Ah {
    float2 inner_0; float2 inner_1;
};

RWByteAddressBuffer ah : register(u0);

Ah ConstructAh(float2x2 arg0) {
    Ah ret = (Ah)0;
    ret.inner_0 = arg0[0];
    ret.inner_1 = arg0[1];
    return ret;
}

[numthreads(1, 1, 1)]
void cs_main()
{
    {
        Ah _value2 = ConstructAh(float2x2((0.0).xx, (1.0).xx));
        {
            // ERROR: Inner doesn't exist
            float2x2 _value3 = _value2.inner;
            ah.Store2(0+0, asuint(_value3[0]));
            ah.Store2(0+8, asuint(_value3[1]));
        }
    }
    return;
}
@cwfitzgerald cwfitzgerald added kind: bug area: naga back-end Outputs of naga shader conversion lang: HLSL D3D Shading Language labels Dec 27, 2022
@ErichDonGubler
Copy link
Member

Firefox bug tracking this: https://bugzilla.mozilla.org/show_bug.cgi?id=1859304

@jimblandy
Copy link
Member

Since this causes HLSL compilation errors, it should be pretty easy to spot when we start running into it on the CTS. (If the symptom was just corrupted data, that would be harder to debug.)

In that light, Mozilla is going to wait until we run into this in our CTS runs to prioritize it.

Once that happens, this looks like a good first bug: easily reproduced, the HLSL backend isn't lovely but it's manageable, snapshot testing should suffice.

@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@cwfitzgerald cwfitzgerald added naga Shader Translator type: bug Something isn't working and removed kind: bug labels Oct 25, 2023
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Nov 3, 2023
@andyleiserson andyleiserson self-assigned this Mar 21, 2025
@andyleiserson andyleiserson moved this to In Progress in WebGPU for Firefox Mar 21, 2025
@andyleiserson
Copy link
Contributor

A couple additional failures:

@group(0) @binding(0)
var<uniform> u_m2x2: mat2x2<f32>;

fn access_m2x2() {
    let l_u_c_c = u_m2x2;
}

Generated HLSL fails with:

hlsl_mat_uniform_load.hlsl:26:29: error: type 'const __mat2x2' does not provide a subscript operator
    float2 l_u_c_c = u_m2x2_[0];
                     ~~~~~~~^~

And:

struct StructWithMat2x2 {
    m: mat2x2<f32>,
}

struct StructWithArrayOfStructOfMat2x2 {
    a: array<StructWithMat2x2, 4>,
}

@group(0) @binding(0)
var<storage, read_write> s_sasm2x2: StructWithArrayOfStructOfMat2x2;

fn access_sasm2x2() {
    var idx = 1;
    idx--;

    let l_s_s = s_sasm2x2;
    s_sasm2x2 = l_s_s;
}

Panics at the wildcard match in write_value_type:

write_value_type Struct { members: [StructMember { name: Some("m"), ty: [0], binding: None, offset: 0 }], span: 16 }

andyleiserson added a commit to andyleiserson/wgpu that referenced this issue Mar 26, 2025
@andyleiserson andyleiserson linked a pull request Mar 26, 2025 that will close this issue
6 tasks
andyleiserson added a commit to andyleiserson/wgpu that referenced this issue Mar 26, 2025
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: HLSL D3D Shading Language naga Shader Translator type: bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

5 participants