Adjust interface extraction to account for split types

OpVariable handling needs to be split out; variables are clearly not
present in the type tree. Take care to apply the OpVariable's
decorations in the right place.

Bug: b/123779863

Change-Id: I2761a604683cf8b025f6b9ba1efa5383f53d7ed1
Reviewed-on: https://swiftshader-review.googlesource.com/c/24372
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 842eb3e..4093ea8 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -364,8 +364,6 @@
 		auto const &obj = getType(id);
 		switch (obj.definition.opcode())
 		{
-		case spv::OpVariable:
-			return PopulateInterfaceInner(iface, obj.definition.word(1), d);
 		case spv::OpTypePointer:
 			return PopulateInterfaceInner(iface, obj.definition.word(3), d);
 		case spv::OpTypeMatrix:
@@ -426,7 +424,16 @@
 	{
 		// Walk a variable definition and populate the interface from it.
 		Decorations d{};
-		PopulateInterfaceInner(iface, id, d);
+
+		auto const it = decorations.find(id);
+		if (it != decorations.end())
+		{
+			d.Apply(it->second);
+		}
+
+		auto def = getObject(id).definition;
+		assert(def.opcode() == spv::OpVariable);
+		PopulateInterfaceInner(iface, def.word(1), d);
 	}
 
 	void SpirvShader::Decorations::Apply(spv::Decoration decoration, uint32_t arg)
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 06123ab..9d3d843 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -229,6 +229,12 @@
 			return it->second;
 		}
 
+		Object const &getObject(uint32_t id) const {
+			auto it = defs.find(id);
+			assert(it != defs.end());
+			return it->second;
+		}
+
 		void ProcessExecutionMode(InsnIterator it);
 
 		uint32_t ComputeTypeSize(InsnIterator insn);