From ab64cf2ec05980d72cb2bad45e629d10ebbefdc1 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 23 Oct 2017 10:37:07 -0700 Subject: Fix output for matrix multiple in GLSL code (#228) When Slang sees a matrix multiplication `M * v` in GLSL code it should (obviously) output GLSL code that also does `M * v`, but there was a bug introduced where the type-checker manages to resolve the operation and recognize it as a matrix-vector multiply, and then the code-generation logic says "oh, I'm generating output for GLSL, and that is reversed from HLSL/Slang, so I'd better reverse these operands!" and outputs `v * M`... which isn't what we want. I've fixed the problem in an expedient way, by having the front-end resolve the operation to what it believes is an intrinsic multiply operation, rather than a matrix-vector operation. If we ever support cross compilation *from* GLSL (unlikely), we've need to fix this up so that we have both real matrix-vector multiplies and "reversed" multiplies where the operands folow the GLSL convention). I've added two tests here to confirm the fix. The one under `tests/bugs` catches the actual issue described above, and confirms the fix. The other one under `tests/cross-compile` is just to make sure that we *do* properly reverse the operands to a matrix-vector product when converting from Slang to GLSL. --- tests/bugs/matrix-mult.glsl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/bugs/matrix-mult.glsl (limited to 'tests/bugs') diff --git a/tests/bugs/matrix-mult.glsl b/tests/bugs/matrix-mult.glsl new file mode 100644 index 000000000..b427dee14 --- /dev/null +++ b/tests/bugs/matrix-mult.glsl @@ -0,0 +1,28 @@ +//TEST:COMPARE_GLSL:-profile glsl_fragment_450 -no-checking +// matrix-mult.glsl +#version 450 + +// Confirm that we don't exchange the operands +// to a matrix-vector multiply when we recognize +// one in "raw" GLSL code. + +#ifdef __SLANG__ +__import empty; +#endif + +layout(binding = 0) +uniform C +{ + mat4x4 m; +}; + +layout(location = 0) +in vec4 v; + +layout(location = 0) +out vec4 r; + +void main() +{ + r = m * v; +} -- cgit v1.2.3