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/+/54428Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Tested-by: 's avatarJohn Stiles <johnstiles@google.com>
parent e0152f11
...@@ -199,19 +199,26 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -199,19 +199,26 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
} }
} else { // for matrix constructors } else { // for matrix constructors
int count = 0; int count = 0;
int element = index; if (node->getType().getObjectSize() == 1) {
for(size_t i = index; i < totalSize; i++) { // Synthesize a diagonal matrix from the provided scalar.
if (i >= instanceSize) int matrixCols = node->getType().getNominalSize();
return; for (int c = 0; c < matrixCols; ++c) {
if (element - i == 0 || (i - element) % (matrixRows + 1) == 0 ) for (int r = 0; r < matrixRows; ++r) {
leftUnionArray[i].cast(basicType, rightUnionArray[0]); if (r == c)
else leftUnionArray[index].cast(basicType, rightUnionArray[0]);
leftUnionArray[i].setFConst(0.0f); else
leftUnionArray[index].setFConst(0.0);
(index)++; (index)++;
}
if (node->getType().getObjectSize() > 1) }
} 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++; count++;
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment