Avoid emitting nonsquare scale matrix entries where there is no main diagonal element
As mentioned in the patch itself, this is fairly benign, but still junk that a later pass has to be able to eliminate. Is easier to just not produce it in the first place.
Bug: b/116263076
Change-Id: I199672bb9b53eb4ee9d4a8e3a23fc2ce42f0dec6
Reviewed-on: https://swiftshader-review.googlesource.com/20770
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/OpenGL/compiler/OutputASM.cpp b/src/OpenGL/compiler/OutputASM.cpp
index 3fe64fa..a2714de 100644
--- a/src/OpenGL/compiler/OutputASM.cpp
+++ b/src/OpenGL/compiler/OutputASM.cpp
@@ -1569,9 +1569,19 @@
for(int i = 0; i < outCols; i++)
{
emit(sw::Shader::OPCODE_MOV, result, i, &zero);
- Instruction *mov = emitCast(result, i, arg0, 0);
- mov->dst.mask = 1 << i;
- ASSERT(mov->src[0].swizzle == 0x00);
+ if (i < outRows)
+ {
+ // Insert the scalar value on the main diagonal.
+ // For non-square matrices, Avoid emitting in
+ // a column which doesn't /have/ a main diagonal
+ // element, even though it would be fairly benign --
+ // it's not necessarily trivial for downstream
+ // passes to see that this is redundant and strip it
+ // out.
+ Instruction *mov = emitCast(result, i, arg0, 0);
+ mov->dst.mask = 1 << i;
+ ASSERT(mov->src[0].swizzle == 0x00);
+ }
}
}
else if(arg0->isMatrix())