Fix error in mat4x2(scalar) construction.
I recently discovered a very long-standing bug in the GLSL reference
compiler (circa 2002) that has managed to propagate to Mesa, glslang,
SwiftShader, and several GPU drivers. I'm trying to patch it where I
can.
A description of the issue is here:
https://github.com/KhronosGroup/glslang/issues/2645
Change-Id: I5c4985bcb05eadfc6559cf08929d9ef77c24096d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/54428
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Tested-by: John Stiles <johnstiles@google.com>
diff --git a/src/OpenGL/compiler/parseConst.cpp b/src/OpenGL/compiler/parseConst.cpp
index 26af408..bfec15a 100644
--- a/src/OpenGL/compiler/parseConst.cpp
+++ b/src/OpenGL/compiler/parseConst.cpp
@@ -199,19 +199,26 @@
}
} else { // for matrix constructors
int count = 0;
- int element = index;
- for(size_t i = index; i < totalSize; i++) {
- if (i >= instanceSize)
- return;
- if (element - i == 0 || (i - element) % (matrixRows + 1) == 0 )
- leftUnionArray[i].cast(basicType, rightUnionArray[0]);
- else
- leftUnionArray[i].setFConst(0.0f);
-
- (index)++;
-
- if (node->getType().getObjectSize() > 1)
+ if (node->getType().getObjectSize() == 1) {
+ // Synthesize a diagonal matrix from the provided scalar.
+ int matrixCols = node->getType().getNominalSize();
+ for (int c = 0; c < matrixCols; ++c) {
+ for (int r = 0; r < matrixRows; ++r) {
+ if (r == c)
+ leftUnionArray[index].cast(basicType, rightUnionArray[0]);
+ else
+ leftUnionArray[index].setFConst(0.0);
+ (index)++;
+ }
+ }
+ } else {
+ // Construct a matrix from the provided components.
+ for (size_t i = index; i < totalSize; i++) {
+ if (i >= instanceSize)
+ return;
+ leftUnionArray[i].cast(basicType, rightUnionArray[count]);
count++;
+ }
}
}
}