From 3c65545c828f65c6ac99c651198fb3527562a0d0 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 6 Nov 2020 16:00:33 +0000 Subject: [PATCH] Add helpers for accessing 'special' properties in pointer/image vars --- .../driver/shaders/spirv/spirv_debug.cpp | 8 +++---- renderdoc/driver/shaders/spirv/spirv_debug.h | 15 ++---------- .../shaders/spirv/spirv_debug_setup.cpp | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index c93e6f710..2e32bfe42 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -660,7 +660,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray // get the pointer base offset (should be zero for any binding but could be non-zero for a // buffer_device_address pointer) - uint64_t offset = structPointer.value.u64v[BufferPointerByteOffsetVariableSlot]; + uint64_t offset = debugger.GetPointerByteOffset(structPointer); // add the offset of the member const DataType &pointerType = debugger.GetTypeForId(len.structure); @@ -2299,8 +2299,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray sampler.type == VarType::Sampler); // at setup time we stored the texture type for easy access here - DebugAPIWrapper::TextureType texType = - (DebugAPIWrapper::TextureType)img.value.u64v[TextureTypeVariableSlot]; + DebugAPIWrapper::TextureType texType = debugger.GetTextureType(img); // should not be sampling or fetching from subpass textures RDCASSERT((texType & DebugAPIWrapper::Subpass_Texture) == 0); @@ -2352,8 +2351,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray ShaderVariable result; result.type = resultType.scalar().Type(); - DebugAPIWrapper::TextureType texType = - (DebugAPIWrapper::TextureType)img.value.u64v[TextureTypeVariableSlot]; + DebugAPIWrapper::TextureType texType = debugger.GetTextureType(img); if(texType & DebugAPIWrapper::Subpass_Texture) { diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index cad2c67bd..c2e7bf2ff 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -102,19 +102,6 @@ public: uint32_t component) = 0; }; -// this could be cleaner if ShaderVariable wasn't a very public struct, but it's not worth it so -// we just reserve value slots that we know won't be used in opaque variables -static const uint32_t PointerVariableSlot = 0; -static const uint32_t Scalar0VariableSlot = 1; -static const uint32_t Scalar1VariableSlot = 2; -static const uint32_t BaseIdVariableSlot = 3; -static const uint32_t MajorStrideVariableSlot = 4; -static const uint32_t ArrayVariableSlot = 8; -static const uint32_t TextureTypeVariableSlot = 9; -static const uint32_t BufferPointerByteOffsetVariableSlot = 9; -static const uint32_t BufferPointerTypeIdVariableSlot = 10; -static const uint32_t SSBOVariableSlot = 11; - typedef ShaderVariable (*ExtInstImpl)(ThreadState &, uint32_t, const rdcarray &); struct ExtInstDispatcher @@ -280,6 +267,8 @@ public: ShaderVariable ReadFromPointer(const ShaderVariable &v) const; ShaderVariable GetPointerValue(const ShaderVariable &v) const; + uint64_t GetPointerByteOffset(const ShaderVariable &ptr) const; + DebugAPIWrapper::TextureType GetTextureType(const ShaderVariable &img) const; ShaderVariable MakePointerVariable(Id id, const ShaderVariable *v, uint32_t scalar0 = ~0U, uint32_t scalar1 = ~0U) const; Id GetPointerBaseId(const ShaderVariable &v) const; diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index 08fb101af..8e4f29a80 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -27,6 +27,19 @@ #include "spirv_op_helpers.h" #include "spirv_reflect.h" +// this could be cleaner if ShaderVariable wasn't a very public struct, but it's not worth it so +// we just reserve value slots that we know won't be used in opaque variables +static const uint32_t PointerVariableSlot = 0; +static const uint32_t Scalar0VariableSlot = 1; +static const uint32_t Scalar1VariableSlot = 2; +static const uint32_t BaseIdVariableSlot = 3; +static const uint32_t MajorStrideVariableSlot = 4; +static const uint32_t ArrayVariableSlot = 8; +static const uint32_t TextureTypeVariableSlot = 9; +static const uint32_t BufferPointerByteOffsetVariableSlot = 9; +static const uint32_t BufferPointerTypeIdVariableSlot = 10; +static const uint32_t SSBOVariableSlot = 11; + static ShaderVariable *pointerIfMutable(const ShaderVariable &var) { return NULL; @@ -1402,6 +1415,16 @@ ShaderVariable Debugger::MakeCompositePointer(const ShaderVariable &base, Id id, return ret; } +uint64_t Debugger::GetPointerByteOffset(const ShaderVariable &ptr) const +{ + return ptr.value.u64v[BufferPointerByteOffsetVariableSlot]; +} + +DebugAPIWrapper::TextureType Debugger::GetTextureType(const ShaderVariable &img) const +{ + return (DebugAPIWrapper::TextureType)img.value.u64v[TextureTypeVariableSlot]; +} + ShaderVariable Debugger::GetPointerValue(const ShaderVariable &ptr) const { // opaque pointers display as their inner value