mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-01 04:10:58 +00:00
Fix offset calculation with declaring nested buffers in format string
* When calculating the size for a struct member we need to properly recurse
This commit is contained in:
@@ -772,12 +772,33 @@ uint32_t BufferFormatter::GetVarSize(const ShaderConstant &var)
|
||||
size = var.type.descriptor.matrixByteStride * var.type.descriptor.columns;
|
||||
}
|
||||
|
||||
if(!var.type.members.empty())
|
||||
size = GetStructVarSize(var.type.members);
|
||||
|
||||
if(var.type.descriptor.elements > 1)
|
||||
size *= var.type.descriptor.elements;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
uint32_t BufferFormatter::GetStructVarSize(const rdcarray<ShaderConstant> &members)
|
||||
{
|
||||
uint32_t lastMemberStart = 0;
|
||||
|
||||
const ShaderConstant *lastChild = &members.back();
|
||||
|
||||
lastMemberStart += lastChild->byteOffset;
|
||||
while(!lastChild->type.members.isEmpty())
|
||||
{
|
||||
lastMemberStart += (qMax(lastChild->type.descriptor.elements, 1U) - 1) *
|
||||
lastChild->type.descriptor.arrayByteStride;
|
||||
lastChild = &lastChild->type.members.back();
|
||||
lastMemberStart += lastChild->byteOffset;
|
||||
}
|
||||
|
||||
return lastMemberStart + GetVarSize(*lastChild);
|
||||
}
|
||||
|
||||
QString BufferFormatter::DeclarePaddingBytes(uint32_t bytes)
|
||||
{
|
||||
if(bytes == 0)
|
||||
@@ -922,20 +943,7 @@ QString BufferFormatter::DeclareStruct(QList<QString> &declaredStructs, const QS
|
||||
|
||||
if(requiredByteStride > 0)
|
||||
{
|
||||
uint32_t lastMemberStart = 0;
|
||||
|
||||
const ShaderConstant *lastChild = &members.back();
|
||||
|
||||
lastMemberStart += lastChild->byteOffset;
|
||||
while(!lastChild->type.members.isEmpty())
|
||||
{
|
||||
lastMemberStart += (qMax(lastChild->type.descriptor.elements, 1U) - 1) *
|
||||
lastChild->type.descriptor.arrayByteStride;
|
||||
lastChild = &lastChild->type.members.back();
|
||||
lastMemberStart += lastChild->byteOffset;
|
||||
}
|
||||
|
||||
const uint32_t structEnd = lastMemberStart + GetVarSize(*lastChild);
|
||||
const uint32_t structEnd = GetStructVarSize(members);
|
||||
|
||||
if(requiredByteStride > structEnd)
|
||||
ret += lit(" ") + DeclarePaddingBytes(requiredByteStride - structEnd);
|
||||
|
||||
@@ -101,6 +101,9 @@ public:
|
||||
|
||||
static QString DeclareStruct(const QString &name, const rdcarray<ShaderConstant> &members,
|
||||
uint32_t requiredByteStride);
|
||||
|
||||
static uint32_t GetStructVarSize(const rdcarray<ShaderConstant> &members);
|
||||
|
||||
static QString DeclarePaddingBytes(uint32_t bytes);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user