From 89526027d20274fab1dd2b924d0ffa7fc45362ea Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 17 Oct 2024 10:46:12 +0100 Subject: [PATCH] DXIL Debugger support for vector instructions ExtractElement InsertElement ShuffleVector --- renderdoc/driver/shaders/dxil/dxil_debug.cpp | 83 ++++++++++++++++++- .../driver/shaders/dxil/dxil_reflect.cpp | 3 - 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/renderdoc/driver/shaders/dxil/dxil_debug.cpp b/renderdoc/driver/shaders/dxil/dxil_debug.cpp index ff1cb9d100..b153b0a921 100644 --- a/renderdoc/driver/shaders/dxil/dxil_debug.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_debug.cpp @@ -3170,10 +3170,91 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper, break; } - case Operation::AddrSpaceCast: case Operation::ExtractElement: + { + RDCASSERTEQUAL(inst.args[0]->type->type, Type::TypeKind::Vector); + RDCASSERTEQUAL(retType->type, Type::TypeKind::Scalar); + RDCASSERTEQUAL(retType->scalarType, inst.args[0]->type->inner->scalarType); + ShaderVariable a; + RDCASSERT(GetShaderVariable(inst.args[0], opCode, dxOpCode, a)); + ShaderVariable b; + RDCASSERT(GetShaderVariable(inst.args[1], opCode, dxOpCode, b)); + const uint32_t idx = b.value.u32v[0]; + +#undef _IMPL +#define _IMPL(I, S, U) comp(result, 0) = comp(a, idx); + IMPL_FOR_INT_TYPES_FOR_TYPE(_IMPL, a.type); + +#undef _IMPL +#define _IMPL(T) comp(result, 0) = comp(a, idx); + + IMPL_FOR_FLOAT_TYPES_FOR_TYPE(_IMPL, a.type); + + break; + } case Operation::InsertElement: + { + RDCASSERTEQUAL(inst.args[0]->type->type, Type::TypeKind::Vector); + RDCASSERTEQUAL(retType->type, Type::TypeKind::Vector); + RDCASSERTEQUAL(retType->inner->scalarType, inst.args[0]->type->inner->scalarType); + RDCASSERTEQUAL(inst.args[1]->type->type, Type::TypeKind::Scalar); + RDCASSERTEQUAL(inst.args[1]->type->scalarType, inst.args[0]->type->inner->scalarType); + ShaderVariable a; + RDCASSERT(GetShaderVariable(inst.args[0], opCode, dxOpCode, a)); + ShaderVariable b; + RDCASSERT(GetShaderVariable(inst.args[1], opCode, dxOpCode, b)); + ShaderVariable c; + RDCASSERT(GetShaderVariable(inst.args[2], opCode, dxOpCode, c)); + const uint32_t idx = c.value.u32v[0]; + + result = a; + +#undef _IMPL +#define _IMPL(I, S, U) comp(result, idx) = comp(b, 0); + IMPL_FOR_INT_TYPES_FOR_TYPE(_IMPL, a.type); + +#undef _IMPL +#define _IMPL(T) comp(result, idx) = comp(b, 0); + + IMPL_FOR_FLOAT_TYPES_FOR_TYPE(_IMPL, b.type); + break; + } case Operation::ShuffleVector: + { + RDCASSERTEQUAL(inst.args[0]->type->type, Type::TypeKind::Vector); + RDCASSERTEQUAL(inst.args[1]->type->type, Type::TypeKind::Vector); + RDCASSERTEQUAL(retType->type, Type::TypeKind::Vector); + RDCASSERTEQUAL(retType->inner->scalarType, inst.args[0]->type->inner->scalarType); + RDCASSERTEQUAL(inst.args[1]->type->inner->scalarType, inst.args[0]->type->inner->scalarType); + RDCASSERTEQUAL(retType->elemCount, inst.args[2]->type->elemCount); + ShaderVariable a; + RDCASSERT(GetShaderVariable(inst.args[0], opCode, dxOpCode, a)); + ShaderVariable b; + bool bIsValid = GetShaderVariable(inst.args[1], opCode, dxOpCode, b); + ShaderVariable c; + RDCASSERT(GetShaderVariable(inst.args[2], opCode, dxOpCode, c)); + // TODO: mask entries might be undef meaning "don’t care" + const uint32_t aMax = inst.args[0]->type->elemCount; + for(uint32_t idx = 0; idx < retType->elemCount; idx++) + { + const uint32_t mask = c.value.u32v[idx]; + if(!bIsValid) + RDCASSERT(mask < aMax); + RDCASSERT(mask < retType->elemCount); + +#undef _IMPL +#define _IMPL(I, S, U) \ + comp(result, idx) = (mask < aMax) ? comp(a, mask) : comp(b, mask - aMax); + IMPL_FOR_INT_TYPES_FOR_TYPE(_IMPL, a.type); + +#undef _IMPL +#define _IMPL(T) comp(result, idx) = (mask < aMax) ? comp(a, mask) : comp(b, mask - aMax); + + IMPL_FOR_FLOAT_TYPES_FOR_TYPE(_IMPL, a.type); + } + break; + } + case Operation::AddrSpaceCast: case Operation::InsertValue: case Operation::Switch: case Operation::Fence: diff --git a/renderdoc/driver/shaders/dxil/dxil_reflect.cpp b/renderdoc/driver/shaders/dxil/dxil_reflect.cpp index 2ba71c86ac..e579e0ab04 100644 --- a/renderdoc/driver/shaders/dxil/dxil_reflect.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_reflect.cpp @@ -1769,9 +1769,6 @@ rdcstr Program::GetDebugStatus() switch(inst->op) { case Operation::AddrSpaceCast: - case Operation::ExtractElement: - case Operation::InsertElement: - case Operation::ShuffleVector: case Operation::InsertValue: case Operation::Switch: case Operation::Fence: