SpirvShaderDebugger: Add flag for printing opcodes as they're executed
The `PRINT_EACH_EXECUTED_INSTRUCTION` preprocessor flag complements the existing `PRINT_EACH_PROCESSED_INSTRUCTION` flag to print each instruction before they are executed.
This is exceptionally helpful when debugging the debugger.
Bug: b/148401179
Change-Id: If35728f115d664c1dba63e625eefccac9d3140ce
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42249
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/SpirvShaderDebugger.cpp b/src/Pipeline/SpirvShaderDebugger.cpp
index d744859..41913d9 100644
--- a/src/Pipeline/SpirvShaderDebugger.cpp
+++ b/src/Pipeline/SpirvShaderDebugger.cpp
@@ -16,6 +16,8 @@
// If enabled, each instruction will be printed before processing.
#define PRINT_EACH_PROCESSED_INSTRUCTION 0
+// If enabled, each instruction will be printed before executing.
+#define PRINT_EACH_EXECUTED_INSTRUCTION 0
#ifdef ENABLE_VK_DEBUGGER
@@ -1452,16 +1454,31 @@
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());
+ {
+ 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
+# if PRINT_EACH_EXECUTED_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);
+ rr::Print("{0}\n", instruction);
+ }
+# endif // PRINT_EACH_EXECUTED_INSTRUCTION
+
if(extensionsImported.count(Extension::OpenCLDebugInfo100) == 0)
{
// We're emitting debugger logic for SPIR-V.