diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index 381f11297..83219deaf 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -24,6 +24,7 @@ #include "spirv_debug.h" #include +#include #include "common/formatting.h" #include "spirv_op_helpers.h" @@ -63,7 +64,7 @@ ThreadState::ThreadState(uint32_t workgroupIdx, Debugger &debug, const GlobalSta { workgroupIndex = workgroupIdx; nextInstruction = 0; - done = false; + helperInvocation = false; } ThreadState::~ThreadState() @@ -75,7 +76,7 @@ ThreadState::~ThreadState() bool ThreadState::Finished() const { - return done || callstack.empty(); + return helperInvocation || callstack.empty(); } void ThreadState::FillCallstack(ShaderDebugState &state) @@ -1809,6 +1810,46 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray break; } + ////////////////////////////////////////////////////////////////////////////// + // + // Misc opcodes + // + ////////////////////////////////////////////////////////////////////////////// + + case Op::ReadClockKHR: + { + const DataType &resultType = debugger.GetType(opdata.resultType); + + ShaderVariable result; + + result.type = resultType.scalar().Type(); + result.rows = 1; + result.columns = RDCMAX(1U, resultType.vector().count); + + result.value.u64v[0] = global.clock; + + SetDst(state, opdata.result, result); + break; + } + case Op::IsHelperInvocationEXT: + { + ShaderVariable result; + + result.type = VarType::UInt; + result.rows = 1; + result.columns = 1; + + result.value.u.x = helperInvocation; + + SetDst(state, opdata.result, result); + break; + } + case Op::DemoteToHelperInvocationEXT: + { + helperInvocation = true; + break; + } + ////////////////////////////////////////////////////////////////////////////// // // Function flow control opcodes diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index ea3b25195..6908c80ea 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -115,6 +115,8 @@ public: rdcarray samplers; SparseIdMap extInsts; + + uint64_t clock; }; struct StackFrame @@ -195,7 +197,7 @@ struct ThreadState // index in the pixel quad uint32_t workgroupIndex; - bool done; + bool helperInvocation; const ShaderVariable &GetSrc(Id id) const; diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index eb780fb18..9c10329c2 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -339,6 +339,8 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader } } + global.clock = uint64_t(time(NULL)) << 32; + for(auto it = extSets.begin(); it != extSets.end(); it++) { Id id = it->first; @@ -638,7 +640,7 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader lane.outputs = active.outputs; lane.ids = active.ids; // mark as inactive/helper lane - lane.done = true; + lane.helperInvocation = true; } // now that the globals are allocated and their storage won't move, we can take pointers to them @@ -774,6 +776,8 @@ rdcarray Debugger::ContinueDebug() // do 100 in a chunk for(int cycleCounter = 0; cycleCounter < 100; cycleCounter++) { + global.clock++; + if(active.Finished()) break;