diff --git a/qrenderdoc/Code/BufferFormatter.cpp b/qrenderdoc/Code/BufferFormatter.cpp index ff7b0256c..18867e9a5 100644 --- a/qrenderdoc/Code/BufferFormatter.cpp +++ b/qrenderdoc/Code/BufferFormatter.cpp @@ -737,6 +737,35 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u else if(el.type.descriptor.type == VarType::SByte) el.type.descriptor.type = VarType::UByte; } + else if(annot == lit("[[bin]]") || annot == lit("[[binary]]")) + { + if(VarTypeCompType(el.type.descriptor.type) == CompType::Float) + { + errors = + tr("Binary display is not supported on floating point formats on line: %1\n").arg(line); + success = false; + break; + } + + if(el.type.descriptor.flags & + (ShaderVariableFlags::R10G10B10A2 | ShaderVariableFlags::R11G11B10)) + { + errors = tr("Binary display is not supported on packed formats on line: %1\n").arg(line); + success = false; + break; + } + + el.type.descriptor.flags |= ShaderVariableFlags::BinaryDisplay; + + if(el.type.descriptor.type == VarType::SLong) + el.type.descriptor.type = VarType::ULong; + else if(el.type.descriptor.type == VarType::SInt) + el.type.descriptor.type = VarType::UInt; + else if(el.type.descriptor.type == VarType::SShort) + el.type.descriptor.type = VarType::UShort; + else if(el.type.descriptor.type == VarType::SByte) + el.type.descriptor.type = VarType::UByte; + } else if(annot == lit("[[unorm]]")) { if(!(el.type.descriptor.flags & ShaderVariableFlags::R10G10B10A2)) @@ -2289,6 +2318,17 @@ QString TypeString(const ShaderVariable &v) else if(v.type == VarType::UByte) typeStr = lit("[[hex]] byte"); } + else if(v.flags & ShaderVariableFlags::BinaryDisplay) + { + if(v.type == VarType::ULong) + typeStr = lit("[[binary]] long"); + else if(v.type == VarType::UInt) + typeStr = lit("[[binary]] int"); + else if(v.type == VarType::UShort) + typeStr = lit("[[binary]] short"); + else if(v.type == VarType::UByte) + typeStr = lit("[[binary]] byte"); + } if(v.type == VarType::Unknown) return lit("Typeless"); @@ -2309,6 +2349,25 @@ static QString RowValuesToString(int cols, ShaderVariableFlags flags, el x, el y { const bool hex = bool(flags & ShaderVariableFlags::HexDisplay); + if(bool(flags & ShaderVariableFlags::BinaryDisplay)) + { + if(cols == 1) + return Formatter::BinFormat(x); + else if(cols == 2) + return QFormatStr("%1, %2").arg(Formatter::BinFormat(x)).arg(Formatter::BinFormat(y)); + else if(cols == 3) + return QFormatStr("%1, %2, %3") + .arg(Formatter::BinFormat(x)) + .arg(Formatter::BinFormat(y)) + .arg(Formatter::BinFormat(z)); + else + return QFormatStr("%1, %2, %3, %4") + .arg(Formatter::BinFormat(x)) + .arg(Formatter::BinFormat(y)) + .arg(Formatter::BinFormat(z)) + .arg(Formatter::BinFormat(w)); + } + if(cols == 1) return Formatter::Format(x, hex); else if(cols == 2) @@ -2450,6 +2509,17 @@ QString RowTypeString(const ShaderVariable &v) else if(v.type == VarType::UByte) typeStr = lit("[[hex]] byte"); } + else if(v.flags & ShaderVariableFlags::BinaryDisplay) + { + if(v.type == VarType::ULong) + typeStr = lit("[[binary]] long"); + else if(v.type == VarType::UInt) + typeStr = lit("[[binary]] int"); + else if(v.type == VarType::UShort) + typeStr = lit("[[binary]] short"); + else if(v.type == VarType::UByte) + typeStr = lit("[[binary]] byte"); + } if(v.columns == 1) return typeStr; diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index 5de874b74..805db09af 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -257,6 +257,22 @@ struct Formatter else return Format(u, true); } + static QString BinFormat(uint64_t u, uint32_t byteSize) + { + return QFormatStr("%1").arg(u, byteSize * 8, 2, QLatin1Char('0')).toUpper(); + } + static QString BinFormat(uint64_t u) { return BinFormat(u, 8); } + static QString BinFormat(uint32_t u) { return BinFormat(u, 4); } + static QString BinFormat(uint16_t u) { return BinFormat(u, 2); } + static QString BinFormat(uint8_t u) { return BinFormat(u, 1); } + static QString BinFormat(int64_t i) { return Format(i); } + static QString BinFormat(int32_t i) { return Format(i); } + static QString BinFormat(int16_t i) { return Format(i); } + static QString BinFormat(int8_t i) { return Format(i); } + static QString BinFormat(float f) { return Format(f); } + static QString BinFormat(rdhalf f) { return Format(f); } + static QString BinFormat(double d) { return Format(d); } + static QString BinFormat(bool b) { return b ? lit("true") : lit("false"); } static QString Format(int32_t i, bool hex = false) { return QString::number(i); } static QString Format(int64_t i, bool hex = false) { return QString::number(i); } static const QFont &PreferredFont() { return *m_Font; } diff --git a/qrenderdoc/Windows/BufferViewer.cpp b/qrenderdoc/Windows/BufferViewer.cpp index 5d7784463..976fba6a7 100644 --- a/qrenderdoc/Windows/BufferViewer.cpp +++ b/qrenderdoc/Windows/BufferViewer.cpp @@ -750,9 +750,12 @@ static QString interpretVariant(const QVariant &v, const ShaderConstant &el, } const bool hexDisplay = bool(el.type.descriptor.flags & ShaderVariableFlags::HexDisplay); + const bool binDisplay = bool(el.type.descriptor.flags & ShaderVariableFlags::BinaryDisplay); if(hexDisplay && prop.format.type == ResourceFormatType::Regular) ret = Formatter::HexFormat(u, prop.format.compByteWidth); + else if(binDisplay && prop.format.type == ResourceFormatType::Regular) + ret = Formatter::BinFormat(u, prop.format.compByteWidth); else ret = Formatter::Format(u, hexDisplay); } @@ -773,8 +776,13 @@ static QString interpretVariant(const QVariant &v, const ShaderConstant &el, } else if(vt == QMetaType::ULongLong) { - ret = Formatter::Format((uint64_t)v.toULongLong(), - bool(el.type.descriptor.flags & ShaderVariableFlags::HexDisplay)); + const bool hexDisplay = bool(el.type.descriptor.flags & ShaderVariableFlags::HexDisplay); + const bool binDisplay = bool(el.type.descriptor.flags & ShaderVariableFlags::BinaryDisplay); + + if(binDisplay) + ret = Formatter::BinFormat((uint64_t)v.toULongLong(), 8); + else + ret = Formatter::Format((uint64_t)v.toULongLong(), hexDisplay); } else if(vt == QMetaType::LongLong) { diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index a47a89219..6888d15ea 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -4288,6 +4288,10 @@ displayed This value should be displayed using hexadecimal where possible. +.. data:: BinaryDisplay + + This value should be displayed using binary where possible. + .. data:: RGBDisplay This value should be interpreted as an RGB colour for display where possible. @@ -4313,11 +4317,12 @@ enum class ShaderVariableFlags : uint32_t NoFlags = 0x0000, RowMajorMatrix = 0x0001, HexDisplay = 0x0002, - RGBDisplay = 0x0004, - R11G11B10 = 0x0008, - R10G10B10A2 = 0x0010, - UNorm = 0x0020, - SNorm = 0x0040, + BinaryDisplay = 0x0004, + RGBDisplay = 0x0008, + R11G11B10 = 0x0010, + R10G10B10A2 = 0x0020, + UNorm = 0x0040, + SNorm = 0x0080, }; BITMASK_OPERATORS(ShaderVariableFlags);