From 31593f437341a395cece7176af2b0b91bb7ab2d3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 23 Apr 2020 15:16:42 +0100 Subject: [PATCH] Support SPIR-V 1.4 pointer comparison opcodes --- .../driver/shaders/spirv/spirv_debug.cpp | 23 +++++++++++++++++++ renderdoc/driver/shaders/spirv/spirv_debug.h | 1 + .../shaders/spirv/spirv_debug_setup.cpp | 10 ++++++++ 3 files changed, 34 insertions(+) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index ace6e321f..3eb9ba9c4 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -553,6 +553,29 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray break; } + case Op::PtrEqual: + case Op::PtrNotEqual: + { + OpPtrEqual equal(it); + + ShaderVariable a = GetSrc(equal.operand1); + ShaderVariable b = GetSrc(equal.operand2); + + bool isEqual = debugger.ArePointersAndEqual(a, b); + + ShaderVariable var; + var.rows = var.columns = 1; + // TODO we should add a bool type + var.type = VarType::UInt; + + if(opdata.op == Op::PtrEqual) + var.value.uv[0] = isEqual ? 1 : 0; + else + var.value.uv[0] = isEqual ? 0 : 1; + + SetDst(equal.result, var); + break; + } ////////////////////////////////////////////////////////////////////////////// // diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 02eb0dfbf..e5df419ba 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -257,6 +257,7 @@ public: uint32_t scalar1 = ~0U) const; Id GetPointerBaseId(const ShaderVariable &v) const; bool IsOpaquePointer(const ShaderVariable &v) const; + bool ArePointersAndEqual(const ShaderVariable &a, const ShaderVariable &b) const; void WriteThroughPointer(const ShaderVariable &ptr, const ShaderVariable &val); ShaderVariable MakeCompositePointer(const ShaderVariable &base, Id id, rdcarray &indices); diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index 8064ded04..d1c0e554f 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -1248,6 +1248,16 @@ bool Debugger::IsOpaquePointer(const ShaderVariable &ptr) const return inner->type == VarType::ReadOnlyResource || inner->type == VarType::ReadWriteResource; } +bool Debugger::ArePointersAndEqual(const ShaderVariable &a, const ShaderVariable &b) const +{ + // we can do a pointer comparison by checking the values, since we store all pointer-related + // data in there + if(a.type == VarType::GPUPointer && b.type == VarType::GPUPointer) + return memcmp(&a.value, &b.value, sizeof(ShaderValue)) == 0; + + return false; +} + void Debugger::WriteThroughPointer(const ShaderVariable &ptr, const ShaderVariable &val) { ShaderVariable *storage = (ShaderVariable *)(uintptr_t)ptr.value.u64v[0];