SpirvShaderDebugger: Add flag for printing opcodes
The `PRINT_EACH_PROCESSED_INSTRUCTION` preprocessor flag can control printing of each instruction before they are processed.
This is exceptionally helpful when debugging the debugger (or anything else to do with SpirvShader).
Bug: b/145351270
Change-Id: Iddfbedbfc86487d71f6980b2f3fb74f7f13e972f
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40093
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShaderDebugger.cpp b/src/Pipeline/SpirvShaderDebugger.cpp
index ab596f7..1342c21 100644
--- a/src/Pipeline/SpirvShaderDebugger.cpp
+++ b/src/Pipeline/SpirvShaderDebugger.cpp
@@ -14,6 +14,9 @@
#include "SpirvShader.hpp"
+// If enabled, each instruction will be printed before processing.
+#define PRINT_EACH_PROCESSED_INSTRUCTION 0
+
#ifdef ENABLE_VK_DEBUGGER
# include "Vulkan/Debug/Context.hpp"
@@ -598,6 +601,17 @@
void SpirvShader::dbgBeginEmitInstruction(InsnIterator insn, EmitState *state) const
{
+# if PRINT_EACH_PROCESSED_INSTRUCTION
+ auto instruction = spvtools::spvInstructionBinaryToText(
+ SPV_ENV_VULKAN_1_1,
+ insn.wordPointer(0),
+ insn.wordCount(),
+ insns.data(),
+ insns.size(),
+ SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
+ printf("%s\n", instruction.c_str());
+# endif // PRINT_EACH_PROCESSED_INSTRUCTION
+
auto dbg = impl.debugger;
if(!dbg) { return; }