From d0720fe7872a52e8f033dff40b77d89fe08b3449 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 21 Mar 2022 13:03:48 +0000 Subject: [PATCH] Allow a [[pad]] annotation to specify padding elements * These elements are consumed but not shown, so the offsets of subsequent elements still act as if they're there. This may be more convenient than specifying a manual offset on the next element or a struct size. --- qrenderdoc/Code/BufferFormatter.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/Code/BufferFormatter.cpp b/qrenderdoc/Code/BufferFormatter.cpp index 39c24cc48..1b74e0bd7 100644 --- a/qrenderdoc/Code/BufferFormatter.cpp +++ b/qrenderdoc/Code/BufferFormatter.cpp @@ -792,6 +792,8 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u QRegularExpressionMatch structMatch = structUseRegex.match(line); + bool isPadding = false; + if(structMatch.hasMatch() && structelems.contains(structMatch.captured(1))) { StructFormatData &structContext = structelems[structMatch.captured(1)]; @@ -807,6 +809,10 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u { specifiedOffset = annot.param.toUInt(); } + else if(annot.name == lit("pad") || annot.name == lit("padding")) + { + isPadding = true; + } else { errors = tr("Unrecognised annotation on variable: %1\n").arg(annot.name); @@ -864,7 +870,9 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u el.type.descriptor.elements = arrayCount; cur->offset += 8; - cur->structDef.type.members.push_back(el); + + if(!isPadding) + cur->structDef.type.members.push_back(el); continue; } @@ -946,7 +954,8 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u el.byteOffset = cur->offset; el.type.descriptor.elements = arrayCount; - cur->structDef.type.members.push_back(el); + if(!isPadding) + cur->structDef.type.members.push_back(el); // advance by the struct including any trailing padding cur->offset += el.type.descriptor.elements * el.type.descriptor.arrayByteStride; @@ -1268,6 +1277,10 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u cur->offset = specifiedOffset; } + else if(annot.name == lit("pad") || annot.name == lit("padding")) + { + isPadding = true; + } else { errors = tr("Unrecognised annotation on variable: %1\n").arg(annot.name); @@ -1455,7 +1468,8 @@ ShaderConstant BufferFormatter::ParseFormatString(const QString &formatString, u el.byteOffset = cur->offset; - cur->structDef.type.members.push_back(el); + if(!isPadding) + cur->structDef.type.members.push_back(el); // if we're bitfield packing don't advance offset, otherwise advance to the end of this element if(bitfieldCurPos == ~0U)