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

[spv-out] Matrix + Matrix operations not implemented #1527

Closed
parasyte opened this issue Nov 12, 2021 · 3 comments · Fixed by #1820
Closed

[spv-out] Matrix + Matrix operations not implemented #1527

parasyte opened this issue Nov 12, 2021 · 3 comments · Fixed by #1820
Labels
area: back-end Outputs of shader conversion lang: SPIR-V Binary SPIR-V input and output

Comments

@parasyte
Copy link
Contributor

WGSL test case:

[[stage(vertex)]]
fn vertex() {
    let model = mat4x4<f32>(
        vec4<f32>(1.0, 0.0, 0.0, 0.0),
        vec4<f32>(0.0, 1.0, 0.0, 0.0),
        vec4<f32>(0.0, 0.0, 1.0, 0.0),
        vec4<f32>(0.0, 0.0, 0.0, 1.0),
    );

    let foo = model + model;
}

Panics at:

naga/src/back/spv/block.rs

Lines 321 to 328 in e69a70b

crate::BinaryOperator::Add => match *left_ty_inner {
crate::TypeInner::Scalar { kind, .. }
| crate::TypeInner::Vector { kind, .. } => match kind {
crate::ScalarKind::Float => spirv::Op::FAdd,
_ => spirv::Op::IAdd,
},
_ => unimplemented!(),
},

Workaround by decomposing the matrices into their column vectors and constructing a new matrix after adding the columns separately:

[[stage(vertex)]]
fn vertex() {
    let model = mat4x4<f32>(
        vec4<f32>(1.0, 0.0, 0.0, 0.0),
        vec4<f32>(0.0, 1.0, 0.0, 0.0),
        vec4<f32>(0.0, 0.0, 1.0, 0.0),
        vec4<f32>(0.0, 0.0, 0.0, 1.0),
    );

    let foo = mat4x4<f32>(
        model.x + model.x,
        model.y + model.y,
        model.z + model.z,
        model.w + model.w,
    );
}

I believe this is the transformation required for SpirV.

@kvark
Copy link
Member

kvark commented Nov 13, 2021

I don't think WGSL supports that today, see the spec - https://gpuweb.github.io/gpuweb/wgsl/#arithmetic-expr

@kvark kvark added the area: validation Validation of the IR label Nov 13, 2021
@parasyte
Copy link
Contributor Author

Looks like it does, though. In the “Matrix arithmetic” table.

@kvark
Copy link
Member

kvark commented Nov 15, 2021

Sorry, you are correct. I'm surprised it's in a separate section.

QuantumEntangledAndy added a commit to QuantumEntangledAndy/dotrix that referenced this issue Mar 18, 2022
@teoxoy teoxoy added lang: SPIR-V Binary SPIR-V input and output area: back-end Outputs of shader conversion and removed area: validation Validation of the IR labels Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end Outputs of shader conversion lang: SPIR-V Binary SPIR-V input and output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants