mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 09:00:44 +00:00
Add flags for format-intepreted packed types
This commit is contained in:
@@ -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<Shade
|
||||
return DeclareStruct(declaredStructs, name, members, requiredByteStride, QString());
|
||||
}
|
||||
|
||||
void SetInterpretedResourceFormat(ShaderConstant &elem, ResourceFormatType interpretType,
|
||||
CompType interpretCompType)
|
||||
{
|
||||
static_assert(sizeof(elem.defaultValue) > 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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user