Pipeline/SpirvShader: Process OpString instructions

Strings are used for debug instructions.

Bug: b/145351270
Change-Id: I6bc711c6c8b320bef6e5abbe9c4bda189fdafc0b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39884
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 0ee4bd4..a4ef814 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -433,10 +433,13 @@
 			case spv::OpLine:
 			case spv::OpNoLine:
 			case spv::OpModuleProcessed:
-			case spv::OpString:
 				// No semantic impact
 				break;
 
+			case spv::OpString:
+				strings.emplace(insn.word(1), insn.string(2));
+				break;
+
 			case spv::OpFunctionParameter:
 				// These should have all been removed by preprocessing passes. If we see them here,
 				// our assumptions are wrong and we will probably generate wrong code.
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 45265de..d74fb14 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -377,6 +377,9 @@
 		Type::ID result;          // return type.
 	};
 
+	using String = std::string;
+	using StringID = SpirvID<std::string>;
+
 	struct TypeOrObject
 	{};  // Dummy struct to represent a Type or Object.
 
@@ -728,6 +731,7 @@
 	HandleMap<Type> types;
 	HandleMap<Object> defs;
 	HandleMap<Function> functions;
+	std::unordered_map<StringID, String> strings;
 	Function::ID entryPoint;
 
 	const bool robustBufferAccess = true;
@@ -1006,6 +1010,13 @@
 		return it->second;
 	}
 
+	String const &getString(StringID id) const
+	{
+		auto it = strings.find(id);
+		ASSERT_MSG(it != strings.end(), "Unknown string %d", id.value());
+		return it->second;
+	}
+
 	// Returns a SIMD::Pointer to the underlying data for the given pointer
 	// object.
 	// Handles objects of the following kinds: