Add minimal support for integer constants

This is just enough support to be able to handle array sizes, etc.

Bug: b/120799499

Change-Id: I790d6accabe55efab9fd5e0c23c93b5d10b72e36
Reviewed-on: https://swiftshader-review.googlesource.com/c/23448
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 641ac81..0fa1279 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -160,6 +160,21 @@
 				break;
 			}
 
+			case spv::OpConstant:
+			case spv::OpConstantComposite:
+			case spv::OpConstantFalse:
+			case spv::OpConstantTrue:
+			case spv::OpConstantNull:
+			{
+				auto typeId = insn.word(1);
+				auto resultId = insn.word(2);
+				auto &object = defs[resultId];
+				object.kind = Object::Kind::Constant;
+				object.definition = insn;
+				object.sizeInComponents = defs[typeId].sizeInComponents;
+				break;
+			}
+
 			default:
 				break;    // This is OK, these passes are intentionally partial
 			}
@@ -409,4 +424,18 @@
 		Block |= src.Block;
 		BufferBlock |= src.BufferBlock;
 	}
+
+	uint32_t SpirvShader::GetConstantInt(uint32_t id)
+	{
+		// Slightly hackish access to constants very early in translation.
+		// General consumption of constants by other instructions should
+		// probably be just lowered to Reactor.
+
+		// TODO: not encountered yet since we only use this for array sizes etc,
+		// but is possible to construct integer constant 0 via OpConstantNull.
+		auto insn = defs[id].definition;
+		assert(insn.opcode() == spv::OpConstant);
+		assert(defs[insn.word(1)].definition.opcode() == spv::OpTypeInt);
+		return insn.word(3);
+	}
 }
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 4d5e453..3e1e31b 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -109,6 +109,7 @@
 				Unknown,        /* for paranoia -- if we get left with an object in this state, the module was broken */
 				Type,
 				Variable,
+				Constant,
 				Value,
 			} kind = Kind::Unknown;
 		};
@@ -218,6 +219,8 @@
 		int PopulateInterfaceInner(std::vector<InterfaceComponent> *iface, uint32_t id, Decorations d);
 
 		void PopulateInterface(std::vector<InterfaceComponent> *iface, uint32_t id);
+
+		uint32_t GetConstantInt(uint32_t id);
 	};
 }