SpirvShader: Add type field to GenericValue

It's quite common to want the object and the type. Fix up these cases.

Avoids a second Object lookup.

Change-Id: Ied1ae0c8d264cfe6c6ff3603d0d096bf9f657b84
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28468
Presubmit-Ready: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index e6662e5..8f14316 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -2192,7 +2192,7 @@
 		auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
 		auto lhs = GenericValue(this, routine, insn.word(3));
 		auto rhs = GenericValue(this, routine, insn.word(4));
-		auto rhsType = getType(getObject(insn.word(4)).type);
+		auto rhsType = getType(rhs.type);
 
 		for (auto i = 0u; i < type.sizeInComponents; i++)
 		{
@@ -2214,7 +2214,7 @@
 		auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
 		auto lhs = GenericValue(this, routine, insn.word(3));
 		auto rhs = GenericValue(this, routine, insn.word(4));
-		auto lhsType = getType(getObject(insn.word(3)).type);
+		auto lhsType = getType(lhs.type);
 
 		for (auto i = 0u; i < type.sizeInComponents; i++)
 		{
@@ -3003,7 +3003,7 @@
 		auto falseBlockId = Block::ID(block.branchInstruction.word(3));
 
 		auto cond = GenericValue(this, state->routine, condId);
-		ASSERT_MSG(getType(getObject(condId).type).sizeInComponents == 1, "Condition must be a Boolean type scalar");
+		ASSERT_MSG(getType(cond.type).sizeInComponents == 1, "Condition must be a Boolean type scalar");
 
 		// TODO: Optimize for case where all lanes take same path.
 
@@ -3021,7 +3021,7 @@
 		auto selId = Object::ID(block.branchInstruction.word(1));
 
 		auto sel = GenericValue(this, state->routine, selId);
-		ASSERT_MSG(getType(getObject(selId).type).sizeInComponents == 1, "Selector must be a scalar");
+		ASSERT_MSG(getType(sel.type).sizeInComponents == 1, "Selector must be a scalar");
 
 		auto numCases = (block.branchInstruction.wordCount() - 3) / 2;
 
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 7831401..c3104c0 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -766,7 +766,8 @@
 	public:
 		GenericValue(SpirvShader const *shader, SpirvRoutine const *routine, SpirvShader::Object::ID objId) :
 				obj(shader->getObject(objId)),
-				intermediate(obj.kind == SpirvShader::Object::Kind::Intermediate ? &routine->getIntermediate(objId) : nullptr) {}
+				intermediate(obj.kind == SpirvShader::Object::Kind::Intermediate ? &routine->getIntermediate(objId) : nullptr),
+				type(obj.type) {}
 
 		RValue<SIMD::Float> Float(uint32_t i) const
 		{
@@ -787,6 +788,8 @@
 		{
 			return As<SIMD::UInt>(Float(i));
 		}
+
+		SpirvShader::Type::ID const type;
 	};
 
 }