From 267798b2409a9be5f8b4e1696bc1afe45a2d1192 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 24 Apr 2020 17:01:40 +0100 Subject: [PATCH] Add boolean vartype --- qrenderdoc/Code/BufferFormatter.cpp | 26 +++++++++---------- qrenderdoc/Code/QRDUtils.h | 1 + qrenderdoc/Windows/ShaderViewer.cpp | 7 ++++- renderdoc/api/replay/renderdoc_tostr.inl | 7 ++++- renderdoc/api/replay/replay_enums.h | 7 ++++- renderdoc/driver/gl/gl_common.h | 3 +++ renderdoc/driver/gl/gl_replay.cpp | 2 ++ renderdoc/driver/gl/glx_dispatch_table.h | 2 ++ .../driver/shaders/dxbc/dxbc_reflect.cpp | 2 +- renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp | 2 +- .../driver/shaders/spirv/spirv_debug.cpp | 14 +++++----- .../shaders/spirv/spirv_disassemble.cpp | 3 +++ .../driver/shaders/spirv/spirv_processor.cpp | 2 ++ .../driver/shaders/spirv/spirv_processor.h | 2 +- renderdoc/driver/vulkan/vk_common.h | 3 +++ 15 files changed, 56 insertions(+), 27 deletions(-) diff --git a/qrenderdoc/Code/BufferFormatter.cpp b/qrenderdoc/Code/BufferFormatter.cpp index f099b6b5f..7a6c01bbc 100644 --- a/qrenderdoc/Code/BufferFormatter.cpp +++ b/qrenderdoc/Code/BufferFormatter.cpp @@ -272,7 +272,7 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u if(basetype == lit("bool")) { - el.type.descriptor.type = VarType::UInt; + el.type.descriptor.type = VarType::Bool; } else if(basetype == lit("byte")) { @@ -849,18 +849,9 @@ QString BufferFormatter::DeclareStruct(QList &declaredStructs, const QS } uint32_t size = lastChild->type.descriptor.rows * lastChild->type.descriptor.columns; - if(lastChild->type.descriptor.type == VarType::Double || - lastChild->type.descriptor.type == VarType::ULong || - lastChild->type.descriptor.type == VarType::SLong) - size *= 8; - else if(lastChild->type.descriptor.type == VarType::Float || - lastChild->type.descriptor.type == VarType::UInt || - lastChild->type.descriptor.type == VarType::SInt) - size *= 4; - else if(lastChild->type.descriptor.type == VarType::Half || - lastChild->type.descriptor.type == VarType::UShort || - lastChild->type.descriptor.type == VarType::SShort) - size *= 2; + uint32_t typeSize = VarTypeByteSize(lastChild->type.descriptor.type); + if(typeSize > 1) + size *= typeSize; if(lastChild->type.descriptor.elements > 1) size *= lastChild->type.descriptor.elements; @@ -911,6 +902,7 @@ ResourceFormat GetInterpretedResourceFormat(const ShaderConstant &elem) case VarType::SShort: case VarType::SLong: case VarType::SByte: format.compType = CompType::SInt; break; + case VarType::Bool: case VarType::UInt: case VarType::UShort: case VarType::ULong: @@ -991,6 +983,8 @@ static void FillShaderVarData(ShaderVariable &var, const ShaderConstant &elem, c var.value.u64v[dst] = o.toULongLong(); else if(var.type == VarType::SLong) var.value.s64v[dst] = o.toLongLong(); + else if(var.type == VarType::Bool) + var.value.uv[dst] = o.toBool() ? 1 : 0; else if(var.type == VarType::UInt || var.type == VarType::UShort || var.type == VarType::UByte) var.value.uv[dst] = o.toUInt(); else if(var.type == VarType::SInt || var.type == VarType::SShort || var.type == VarType::SByte) @@ -1596,6 +1590,12 @@ QString RowString(const ShaderVariable &v, uint32_t row, VarType type) return RowValuesToString((int)v.columns, v.displayAsHex, v.value.uv[row * v.columns + 0], v.value.uv[row * v.columns + 1], v.value.uv[row * v.columns + 2], v.value.uv[row * v.columns + 3]); + else if(type == VarType::Bool) + return RowValuesToString((int)v.columns, v.displayAsHex, + v.value.uv[row * v.columns + 0] ? true : false, + v.value.uv[row * v.columns + 1] ? true : false, + v.value.uv[row * v.columns + 2] ? true : false, + v.value.uv[row * v.columns + 3] ? true : false); else return RowValuesToString((int)v.columns, v.displayAsHex, v.value.fv[row * v.columns + 0], v.value.fv[row * v.columns + 1], v.value.fv[row * v.columns + 2], diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index 0e1847cf3..01aad8947 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -235,6 +235,7 @@ struct Formatter { return QFormatStr("%1").arg(u, hex ? 2 : 0, hex ? 16 : 10, QLatin1Char('0')).toUpper(); } + static QString Format(bool b, bool hex = false) { return b ? lit("true") : lit("false"); } static QString HexFormat(uint32_t u, uint32_t byteSize) { if(byteSize == 1) diff --git a/qrenderdoc/Windows/ShaderViewer.cpp b/qrenderdoc/Windows/ShaderViewer.cpp index c16435f3b..ca433d7e9 100644 --- a/qrenderdoc/Windows/ShaderViewer.cpp +++ b/qrenderdoc/Windows/ShaderViewer.cpp @@ -2748,7 +2748,8 @@ void ShaderViewer::updateWatchVariables() var.type == VarType::UShort || var.type == VarType::UByte) regcast = QLatin1Char('u'); else if(var.type == VarType::SLong || var.type == VarType::SInt || - var.type == VarType::SShort || var.type == VarType::SByte) + var.type == VarType::SShort || var.type == VarType::SByte || + var.type == VarType::Bool) regcast = QLatin1Char('i'); else if(var.type == VarType::Unknown) regcast = ui->intView->isChecked() ? QLatin1Char('i') : QLatin1Char('f'); @@ -2858,6 +2859,8 @@ RDTreeWidgetItem *ShaderViewer::makeSourceVariableNode(const SourceVariableMappi typeName = lit("float"); else if(l.type == VarType::Double) typeName = lit("double"); + else if(l.type == VarType::Bool) + typeName = lit("bool"); QList children; @@ -3024,6 +3027,8 @@ RDTreeWidgetItem *ShaderViewer::makeSourceVariableNode(const SourceVariableMappi value += Formatter::Format(reg->value.uv[r.component]); else if(l.type == VarType::SInt) value += Formatter::Format(reg->value.iv[r.component]); + else if(l.type == VarType::Bool) + value += Formatter::Format(reg->value.uv[r.component] ? true : false); else if(l.type == VarType::Float) value += Formatter::Format(reg->value.fv[r.component]); else if(l.type == VarType::Double) diff --git a/renderdoc/api/replay/renderdoc_tostr.inl b/renderdoc/api/replay/renderdoc_tostr.inl index f70feb0c3..102052347 100644 --- a/renderdoc/api/replay/renderdoc_tostr.inl +++ b/renderdoc/api/replay/renderdoc_tostr.inl @@ -832,8 +832,13 @@ rdcstr DoStringise(const VarType &el) STRINGISE_ENUM_CLASS_NAMED(ULong, "ulong"); STRINGISE_ENUM_CLASS_NAMED(SByte, "byte"); STRINGISE_ENUM_CLASS_NAMED(UByte, "ubyte"); - STRINGISE_ENUM_CLASS_NAMED(Unknown, "unknown"); + STRINGISE_ENUM_CLASS_NAMED(Bool, "bool"); STRINGISE_ENUM_CLASS_NAMED(GPUPointer, "pointer"); + STRINGISE_ENUM_CLASS_NAMED(ConstantBlock, "cbuffer"); + STRINGISE_ENUM_CLASS_NAMED(ReadOnlyResource, "resource"); + STRINGISE_ENUM_CLASS_NAMED(ReadWriteResource, "rwresource"); + STRINGISE_ENUM_CLASS_NAMED(Sampler, "sampler"); + STRINGISE_ENUM_CLASS_NAMED(Unknown, "unknown"); } END_ENUM_STRINGISE(); } diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index 4acd30e8e..8375d2940 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -195,6 +195,10 @@ DOCUMENT(R"(Represents the base type of a shader variable in debugging or consta An unsigned 8-bit integer value. +.. data:: Bool + + A boolean value. + .. data:: GPUPointer A 64-bit pointer into GPU-addressable memory. Variables with this type are stored with opaque @@ -237,6 +241,7 @@ enum class VarType : uint8_t ULong, SByte, UByte, + Bool, GPUPointer, ConstantBlock, ReadOnlyResource, @@ -260,7 +265,7 @@ constexpr uint32_t VarTypeByteSize(VarType type) // clang-format off return (type == VarType::UByte || type == VarType::SByte) ? 1 : (type == VarType::Half || type == VarType::UShort || type == VarType::SShort) ? 2 - : (type == VarType::Float || type == VarType::UInt || type == VarType::SInt ) ? 4 + : (type == VarType::Float || type == VarType::UInt || type == VarType::SInt || type == VarType::Bool) ? 4 : (type == VarType::Double || type == VarType::ULong || type == VarType::SLong ) ? 8 : 0; // clang-format on diff --git a/renderdoc/driver/gl/gl_common.h b/renderdoc/driver/gl/gl_common.h index 0fd54852d..932d060a0 100644 --- a/renderdoc/driver/gl/gl_common.h +++ b/renderdoc/driver/gl/gl_common.h @@ -260,6 +260,9 @@ struct GLWindowingData #error "Unknown platform" #endif +#undef None +#undef Bool + struct GLPlatform { // simple wrapper for OS functions to make/delete a context diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index b7d9af0f8..2d2a9e3bf 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -2083,6 +2083,7 @@ void GLReplay::OpenGLFillCBufferVariables(ResourceId shader, GLuint prog, bool b case VarType::SInt: GL.glGetUniformiv(prog, location, (int32_t *)uniformData.data()); break; + case VarType::Bool: case VarType::UInt: GL.glGetUniformuiv(prog, location, (uint32_t *)uniformData.data()); break; @@ -2133,6 +2134,7 @@ void GLReplay::OpenGLFillCBufferVariables(ResourceId shader, GLuint prog, bool b case VarType::SInt: GL.glGetUniformiv(prog, location + a, (int32_t *)uniformData.data()); break; + case VarType::Bool: case VarType::UInt: GL.glGetUniformuiv(prog, location + a, (uint32_t *)uniformData.data()); break; diff --git a/renderdoc/driver/gl/glx_dispatch_table.h b/renderdoc/driver/gl/glx_dispatch_table.h index fc3f65a04..a55a2d125 100644 --- a/renderdoc/driver/gl/glx_dispatch_table.h +++ b/renderdoc/driver/gl/glx_dispatch_table.h @@ -26,6 +26,8 @@ #include "gl_common.h" +#define Bool int + // glX functions typedef GLXContext (*PFN_glXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); diff --git a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp index abc53306f..4425b3479 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp @@ -39,7 +39,7 @@ static ShaderVariableType MakeShaderVariableType(DXBC::CBufferVariableType type) case DXBC::VARTYPE_MIN12INT: case DXBC::VARTYPE_MIN16INT: case DXBC::VARTYPE_INT: ret.descriptor.type = VarType::SInt; break; - case DXBC::VARTYPE_BOOL: + case DXBC::VARTYPE_BOOL: ret.descriptor.type = VarType::Bool; break; case DXBC::VARTYPE_MIN16UINT: case DXBC::VARTYPE_UINT: ret.descriptor.type = VarType::UInt; break; case DXBC::VARTYPE_DOUBLE: ret.descriptor.type = VarType::Double; break; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp b/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp index 3d85ab882..f5060a044 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp @@ -206,7 +206,7 @@ SPDBChunk::SPDBChunk(void *chunk) typeInfo[T_LONG] = {"int32_t", VarType::SInt, 4, 1, 0, 0, LF_NUMERIC, {}}; typeInfo[T_SHORT] = {"int16_t", VarType::SInt, 2, 1, 0, 0, LF_NUMERIC, {}}; typeInfo[T_CHAR] = {"char", VarType::SInt, 1, 1, 0, 0, LF_NUMERIC, {}}; - typeInfo[T_BOOL32FF] = {"bool", VarType::UInt, 4, 1, 0, 0, LF_NUMERIC, {}}; + typeInfo[T_BOOL32FF] = {"bool", VarType::Bool, 4, 1, 0, 0, LF_NUMERIC, {}}; typeInfo[T_UINT4] = {"uint32_t", VarType::UInt, 4, 1, 0, 0, LF_NUMERIC, {}}; typeInfo[T_UINT2] = {"uint16_t", VarType::UInt, 2, 1, 0, 0, LF_NUMERIC, {}}; typeInfo[T_UINT1] = {"uint8_t", VarType::UInt, 1, 1, 0, 0, LF_NUMERIC, {}}; diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index 2110ad093..9154bd8c7 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -565,8 +565,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray ShaderVariable var; var.rows = var.columns = 1; - // TODO we should add a bool type - var.type = VarType::UInt; + var.type = VarType::Bool; if(opdata.op == Op::PtrEqual) var.value.uv[0] = isEqual ? 1 : 0; @@ -1295,8 +1294,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray var.value.uv[c] = (var.value.fv[c] > b.value.fv[c]) ? 0 : 1; } - // TODO we should add a bool type - var.type = VarType::UInt; + var.type = VarType::Bool; SetDst(comp.result, var); break; @@ -1310,6 +1308,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray for(uint8_t c = 0; c < var.columns; c++) var.value.uv[c] = 1U - var.value.uv[c]; + var.type = VarType::Bool; + SetDst(negate.result, var); break; } @@ -1342,8 +1342,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray for(uint8_t c = 0; c < var.columns; c++) var.value.uv[c] = isnan(var.value.fv[c]) ? 1 : 0; - // TODO we should add a bool type - var.type = VarType::UInt; + var.type = VarType::Bool; SetDst(is.result, var); break; @@ -1357,8 +1356,7 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray for(uint8_t c = 0; c < var.columns; c++) var.value.uv[c] = isinf(var.value.fv[c]) ? 1 : 0; - // TODO we should add a bool type - var.type = VarType::UInt; + var.type = VarType::Bool; SetDst(is.result, var); break; diff --git a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp index daff03ecf..9df32f569 100644 --- a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp @@ -412,6 +412,7 @@ rdcstr Reflector::Disassemble(const rdcstr &entryPoint, case VarType::SInt: case VarType::SShort: case VarType::SByte: ret += ToStr(value.i.x); break; + case VarType::Bool: ret += value.u.x ? "true" : "false"; break; case VarType::UInt: case VarType::UShort: case VarType::UByte: ret += ToStr(value.u.x); break; @@ -1571,6 +1572,7 @@ rdcstr Reflector::StringiseConstant(rdcspv::Id id) const case VarType::SInt: case VarType::SShort: case VarType::SByte: return ToStr(value.value.i.x); + case VarType::Bool: return value.value.u.x ? "true" : "false"; case VarType::UInt: case VarType::UShort: case VarType::UByte: return ToStr(value.value.u.x); @@ -1601,6 +1603,7 @@ rdcstr Reflector::StringiseConstant(rdcspv::Id id) const case VarType::UShort: case VarType::UByte: ret += ToStr(value.value.uv[i]); break; case VarType::SLong: ret += ToStr(value.value.s64v[i]); break; + case VarType::Bool: return value.value.u.x ? "true" : "false"; case VarType::Unknown: case VarType::GPUPointer: case VarType::ConstantBlock: diff --git a/renderdoc/driver/shaders/spirv/spirv_processor.cpp b/renderdoc/driver/shaders/spirv/spirv_processor.cpp index b9f16e001..1b2936be8 100644 --- a/renderdoc/driver/shaders/spirv/spirv_processor.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_processor.cpp @@ -522,6 +522,7 @@ void Processor::RegisterOp(Iter it) ShaderVariable v("true", 1, 0, 0, 0); v.columns = 1; + v.type = VarType::Bool; constants[decoded.result] = {decoded.resultType, decoded.result, v, {}, opdata.op}; if(opdata.op == Op::SpecConstantTrue) @@ -533,6 +534,7 @@ void Processor::RegisterOp(Iter it) ShaderVariable v("true", 0, 0, 0, 0); v.columns = 1; + v.type = VarType::Bool; constants[decoded.result] = {decoded.resultType, decoded.result, v, {}, opdata.op}; if(opdata.op == Op::SpecConstantFalse) diff --git a/renderdoc/driver/shaders/spirv/spirv_processor.h b/renderdoc/driver/shaders/spirv/spirv_processor.h index d4d8eec76..ce4aa7ca4 100644 --- a/renderdoc/driver/shaders/spirv/spirv_processor.h +++ b/renderdoc/driver/shaders/spirv/spirv_processor.h @@ -86,7 +86,7 @@ struct Scalar } else if(type == Op::TypeBool) { - return VarType::UInt; + return VarType::Bool; } return VarType::Unknown; diff --git a/renderdoc/driver/vulkan/vk_common.h b/renderdoc/driver/vulkan/vk_common.h index 0c2cefd3f..34f04b536 100644 --- a/renderdoc/driver/vulkan/vk_common.h +++ b/renderdoc/driver/vulkan/vk_common.h @@ -62,6 +62,9 @@ #include "serialise/serialiser.h" #include "vk_dispatchtables.h" +#undef Bool +#undef None + // enable this to cause every internal QueueSubmit to immediately call DeviceWaitIdle(), and to only // submit one command buffer at once to narrow down the cause of device lost errors #define SINGLE_FLUSH_VALIDATE OPTION_OFF