Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
glsl-in: Fix matrix multiplication check
Browse files Browse the repository at this point in the history
The previous check compared rows to rows and columns to columns but
multiplication of matrices only needs the columns of the left matrix to
be equal to the rows of the right matrix.
  • Loading branch information
JCapucho committed May 27, 2022
1 parent f035854 commit dd06d27
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/front/glsl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,13 @@ impl Context {
width: right_width,
},
) => {
let additive_check =
left_columns != right_columns || left_rows != right_rows;
let multiplicative_check = left_columns != right_rows;

// Check that the two arguments have the same dimensions
if left_columns != right_columns
|| left_rows != right_rows
if (multiplicative_check && op == BinaryOperator::Multiply)
|| (additive_check && op != BinaryOperator::Multiply)
|| left_width != right_width
{
parser.errors.push(Error {
Expand Down
4 changes: 4 additions & 0 deletions tests/in/glsl/expressions.frag
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ void ternary(bool a) {
uint nested = a ? (a ? (a ? 2u : 3) : 4u) : 5;
}

void testMatrixMultiplication(mat4x3 a, mat4x4 b) {
mat4x3 c = a * b;
}

out vec4 o_color;
void main() {
privatePointer(global);
Expand Down
13 changes: 13 additions & 0 deletions tests/out/wgsl/expressions-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ fn ternary(a_20: bool) {
return;
}

fn testMatrixMultiplication(a_22: mat4x3<f32>, b_18: mat4x4<f32>) {
var a_23: mat4x3<f32>;
var b_19: mat4x4<f32>;
var c_2: mat4x3<f32>;

a_23 = a_22;
b_19 = b_18;
let _e5 = a_23;
let _e6 = b_19;
c_2 = (_e5 * _e6);
return;
}

fn main_1() {
var local_5: f32;

Expand Down

0 comments on commit dd06d27

Please sign in to comment.