From 01d9c6698b4c0c65c928372cac8f1bbf355aad71 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 1 Mar 2022 13:21:30 +0000 Subject: [PATCH] Add flags for format-intepreted packed types --- qrenderdoc/Code/BufferFormatter.cpp | 64 +++++++++--------------- renderdoc/api/replay/renderdoc_tostr.inl | 4 ++ renderdoc/api/replay/replay_enums.h | 20 ++++++++ 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/qrenderdoc/Code/BufferFormatter.cpp b/qrenderdoc/Code/BufferFormatter.cpp index 31edbc499..d2be110df 100644 --- a/qrenderdoc/Code/BufferFormatter.cpp +++ b/qrenderdoc/Code/BufferFormatter.cpp @@ -36,8 +36,7 @@ struct StructFormatData GraphicsAPI BufferFormatter::m_API; -static bool MatchBaseTypeDeclaration(QString basetype, ShaderConstant &el, const bool isUnsigned, - CompType &interpretCompType, ResourceFormatType &interpretType) +static bool MatchBaseTypeDeclaration(QString basetype, const bool isUnsigned, ShaderConstant &el) { if(basetype == lit("bool")) { @@ -103,41 +102,40 @@ static bool MatchBaseTypeDeclaration(QString basetype, ShaderConstant &el, const else if(basetype == lit("unormh")) { el.type.descriptor.type = VarType::UShort; - interpretCompType = CompType::UNorm; + el.type.descriptor.flags |= ShaderVariableFlags::UNorm; } else if(basetype == lit("unormb")) { el.type.descriptor.type = VarType::UByte; - interpretCompType = CompType::UNorm; + el.type.descriptor.flags |= ShaderVariableFlags::UNorm; } else if(basetype == lit("snormh")) { el.type.descriptor.type = VarType::SShort; - interpretCompType = CompType::SNorm; + el.type.descriptor.flags |= ShaderVariableFlags::SNorm; } else if(basetype == lit("snormb")) { el.type.descriptor.type = VarType::SByte; - interpretCompType = CompType::SNorm; + el.type.descriptor.flags |= ShaderVariableFlags::SNorm; } else if(basetype == lit("uintten")) { el.type.descriptor.type = VarType::UInt; - interpretType = ResourceFormatType::R10G10B10A2; + el.type.descriptor.flags |= ShaderVariableFlags::R10G10B10A2; el.type.descriptor.columns = 4; } else if(basetype == lit("unormten")) { el.type.descriptor.type = VarType::UInt; - interpretCompType = CompType::UNorm; - interpretType = ResourceFormatType::R10G10B10A2; + el.type.descriptor.flags |= ShaderVariableFlags::R10G10B10A2; + el.type.descriptor.flags |= ShaderVariableFlags::UNorm; el.type.descriptor.columns = 4; } else if(basetype == lit("floateleven")) { el.type.descriptor.type = VarType::Float; - interpretCompType = CompType::Float; - interpretType = ResourceFormatType::R11G11B10; + el.type.descriptor.flags |= ShaderVariableFlags::R11G11B10; el.type.descriptor.columns = 3; } else @@ -322,10 +320,8 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u } ShaderConstant tmp; - CompType dummyCompType; - ResourceFormatType dummyType; - bool matched = MatchBaseTypeDeclaration(baseType, tmp, true, dummyCompType, dummyType); + bool matched = MatchBaseTypeDeclaration(baseType, true, tmp); if(!matched) { @@ -342,8 +338,6 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u } ShaderConstant el; - ResourceFormatType interpretType = ResourceFormatType::Regular; - CompType interpretCompType = CompType::Typeless; if(cur->structDef.type.descriptor.type == VarType::Enum) { @@ -582,8 +576,7 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u if(el.type.descriptor.rows == 1) el.type.descriptor.flags |= ShaderVariableFlags::RowMajorMatrix; - bool matched = - MatchBaseTypeDeclaration(basetype, el, isUnsigned, interpretCompType, interpretType); + bool matched = MatchBaseTypeDeclaration(basetype, isUnsigned, el); if(!matched) { @@ -610,7 +603,9 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u success = false; break; } - if(interpretType != ResourceFormatType::Regular || interpretCompType != CompType::Typeless) + if(el.type.descriptor.flags & + (ShaderVariableFlags::R10G10B10A2 | ShaderVariableFlags::R11G11B10 | + ShaderVariableFlags::UNorm | ShaderVariableFlags::SNorm)) { errors = tr("Bitfield packing not allowed on interpreted/packed formats on line: %1\n").arg(line); @@ -631,8 +626,6 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u el.type.descriptor.flags |= ShaderVariableFlags::HexDisplay; } - SetInterpretedResourceFormat(el, interpretType, interpretCompType); - ResourceFormat fmt = GetInterpretedResourceFormat(el); // normally the array stride is the size of an element @@ -825,8 +818,6 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u el.type.descriptor.arrayByteStride = el.type.descriptor.matrixByteStride = el.type.descriptor.columns * VarTypeByteSize(el.type.descriptor.type); - SetInterpretedResourceFormat(el, ResourceFormatType::Regular, CompType::Typeless); - root.structDef.type.members.push_back(el); } @@ -1320,29 +1311,22 @@ QString BufferFormatter::DeclareStruct(const QString &name, const rdcarray 2, - "ShaderConstant::defaultValue has changed, check packing"); - - // packing must match GetInterpretedResourceFormat below - elem.defaultValue = (uint64_t(interpretType) << 8) | (uint64_t(interpretCompType) << 0); -} - ResourceFormat GetInterpretedResourceFormat(const ShaderConstant &elem) { - // packing must match SetInterpretedResourceFormat above - ResourceFormatType interpretType = ResourceFormatType((elem.defaultValue >> 8) & 0xff); - CompType interpretCompType = CompType((elem.defaultValue >> 0) & 0xff); - ResourceFormat format; - format.type = interpretType; + format.type = ResourceFormatType::Regular; + + if(elem.type.descriptor.flags & ShaderVariableFlags::R10G10B10A2) + format.type = ResourceFormatType::R10G10B10A2; + else if(elem.type.descriptor.flags & ShaderVariableFlags::R11G11B10) + format.type = ResourceFormatType::R11G11B10; format.compType = VarTypeCompType(elem.type.descriptor.type); - if(interpretCompType != CompType::Typeless) - format.compType = interpretCompType; + if(elem.type.descriptor.flags & ShaderVariableFlags::UNorm) + format.compType = CompType::UNorm; + else if(elem.type.descriptor.flags & ShaderVariableFlags::SNorm) + format.compType = CompType::SNorm; format.compByteWidth = VarTypeByteSize(elem.type.descriptor.type); diff --git a/renderdoc/api/replay/renderdoc_tostr.inl b/renderdoc/api/replay/renderdoc_tostr.inl index 86310ffe6..c05b30c98 100644 --- a/renderdoc/api/replay/renderdoc_tostr.inl +++ b/renderdoc/api/replay/renderdoc_tostr.inl @@ -1120,6 +1120,10 @@ rdcstr DoStringise(const ShaderVariableFlags &el) STRINGISE_BITFIELD_CLASS_BIT(RowMajorMatrix); STRINGISE_BITFIELD_CLASS_BIT(HexDisplay); STRINGISE_BITFIELD_CLASS_BIT(RGBDisplay); + STRINGISE_BITFIELD_CLASS_BIT(R11G11B10); + STRINGISE_BITFIELD_CLASS_BIT(R10G10B10A2); + STRINGISE_BITFIELD_CLASS_BIT(UNorm); + STRINGISE_BITFIELD_CLASS_BIT(SNorm); } END_BITFIELD_STRINGISE(); } diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index 9414c354e..a47a89219 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -4291,6 +4291,22 @@ displayed .. data:: RGBDisplay This value should be interpreted as an RGB colour for display where possible. + +.. data:: R11G11B10 + + This value should be decoded from a 32-bit integer in R11G11B10 packing format. + +.. data:: R10G10B10A2 + + This value should be decoded from a 32-bit integer in R10G10B10A2 packing format. + +.. data:: UNorm + + This value should be treated as unsigned normalised floating point values when interpreting. + +.. data:: SNorm + + This value should be treated as signed normalised floating point values when interpreting. )"); enum class ShaderVariableFlags : uint32_t { @@ -4298,6 +4314,10 @@ enum class ShaderVariableFlags : uint32_t RowMajorMatrix = 0x0001, HexDisplay = 0x0002, RGBDisplay = 0x0004, + R11G11B10 = 0x0008, + R10G10B10A2 = 0x0010, + UNorm = 0x0020, + SNorm = 0x0040, }; BITMASK_OPERATORS(ShaderVariableFlags);