From bace05d926530e8a514adf2038cf8d049f44880f Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 14 Nov 2017 17:34:28 +0000 Subject: [PATCH] Split out code to populate RDTreeWidget with structured data --- qrenderdoc/Code/QRDUtils.cpp | 72 +++++++++++++++++++++++ qrenderdoc/Code/QRDUtils.h | 5 ++ qrenderdoc/Windows/APIInspector.cpp | 90 +---------------------------- qrenderdoc/Windows/APIInspector.h | 1 - 4 files changed, 79 insertions(+), 89 deletions(-) diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 31069b482..cb0c955c4 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -40,6 +40,7 @@ #include #include #include +#include "Widgets/Extended/RDTreeWidget.h" // normally this is in the renderdoc core library, but it's needed for the 'unknown enum' path, // so we implement it here using QString. It's inefficient, but this is a very uncommon path - @@ -358,6 +359,77 @@ void CombineUsageEvents(ICaptureContext &ctx, const rdcarray &usage, callback(start, end, us); } +void addStructuredObjects(RDTreeWidgetItem *parent, const StructuredObjectList &objs, + bool parentIsArray) +{ + for(const SDObject *obj : objs) + { + if(obj->type.flags & SDTypeFlags::Hidden) + continue; + + QVariant param; + + if(parentIsArray) + param = QFormatStr("[%1]").arg(parent->childCount()); + else + param = obj->name; + + RDTreeWidgetItem *item = new RDTreeWidgetItem({param, QString()}); + + // we don't identify via the type name as many types could be serialised as a ResourceId - + // e.g. ID3D11Resource* or ID3D11Buffer* which would be the actual typename. We want to preserve + // that for the best raw structured data representation instead of flattening those out to just + // "ResourceId", and we also don't want to store two types ('fake' and 'real'), so instead we + // check the custom string. + if((obj->type.flags & SDTypeFlags::HasCustomString) && + !strncmp(obj->data.str.c_str(), "ResourceId", 10)) + { + ResourceId id; + static_assert(sizeof(id) == sizeof(obj->data.basic.u), "ResourceId is no longer uint64_t!"); + memcpy(&id, &obj->data.basic.u, sizeof(id)); + + // TODO Get global name + param = ToQStr(id); + } + else if(obj->type.flags & SDTypeFlags::NullString) + { + param = lit("NULL"); + } + else if(obj->type.flags & SDTypeFlags::HasCustomString) + { + param = obj->data.str; + } + else + { + switch(obj->type.basetype) + { + case SDBasic::Chunk: + case SDBasic::Struct: + param = QFormatStr("%1()").arg(obj->type.name); + addStructuredObjects(item, obj->data.children, false); + break; + case SDBasic::Array: + param = QFormatStr("%1[]").arg(obj->type.name); + addStructuredObjects(item, obj->data.children, true); + break; + case SDBasic::Null: param = lit("NULL"); break; + case SDBasic::Buffer: param = lit("(%1 bytes)").arg(obj->type.byteSize); break; + case SDBasic::String: param = obj->data.str; break; + case SDBasic::Enum: + case SDBasic::UnsignedInteger: param = Formatter::Format(obj->data.basic.u); break; + case SDBasic::SignedInteger: param = Formatter::Format(obj->data.basic.i); break; + case SDBasic::Float: param = Formatter::Format(obj->data.basic.d); break; + case SDBasic::Boolean: param = (obj->data.basic.b ? lit("True") : lit("False")); break; + case SDBasic::Character: param = QString(QLatin1Char(obj->data.basic.c)); break; + } + } + + item->setText(1, param); + + parent->addChild(item); + } +} + bool SaveToJSON(QVariantMap &data, QIODevice &f, const char *magicIdentifier, uint32_t magicVersion) { // marker that this data is valid diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index 314e3aa1a..899431b81 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -102,6 +102,11 @@ void CombineUsageEvents( ICaptureContext &ctx, const rdcarray &usage, std::function callback); +class RDTreeWidgetItem; + +void addStructuredObjects(RDTreeWidgetItem *parent, const StructuredObjectList &objs, + bool parentIsArray); + struct Formatter { static void setParams(const PersistantConfig &config); diff --git a/qrenderdoc/Windows/APIInspector.cpp b/qrenderdoc/Windows/APIInspector.cpp index f350a81fa..d9aa7cf9f 100644 --- a/qrenderdoc/Windows/APIInspector.cpp +++ b/qrenderdoc/Windows/APIInspector.cpp @@ -33,7 +33,7 @@ APIInspector::APIInspector(ICaptureContext &ctx, QWidget *parent) ui->setupUi(this); ui->apiEvents->setColumns({lit("EID"), tr("Event")}); - ui->apiEvents->header()->resizeSection(0, 200); + ui->apiEvents->header()->resizeSection(0, 150); ui->splitter->setCollapsible(1, true); ui->splitter->setSizes({1, 0}); @@ -146,7 +146,7 @@ void APIInspector::fillAPIView() root->setText(1, chunk->name); - addObjects(root, chunk->data.children, false); + addStructuredObjects(root, chunk->data.children, false); } else { @@ -166,89 +166,3 @@ void APIInspector::fillAPIView() ui->apiEvents->setUpdatesEnabled(true); } - -void APIInspector::addObjects(RDTreeWidgetItem *parent, const StructuredObjectList &objs, - bool parentIsArray) -{ - for(const SDObject *obj : objs) - { - if(obj->type.flags & SDTypeFlags::Hidden) - continue; - - QString param; - - if(parentIsArray) - param = QFormatStr("[%1]").arg(parent->childCount()); - else - param = obj->name; - - RDTreeWidgetItem *item = new RDTreeWidgetItem({param, QString()}); - - param = QString(); - - // we don't identify via the type name as many types could be serialised as a ResourceId - - // e.g. ID3D11Resource* or ID3D11Buffer* which would be the actual typename. We want to preserve - // that for the best raw structured data representation instead of flattening those out to just - // "ResourceId", and we also don't want to store two types ('fake' and 'real'), so instead we - // check the custom string. - if((obj->type.flags & SDTypeFlags::HasCustomString) && - !strncmp(obj->data.str.c_str(), "ResourceId", 10)) - { - ResourceId id; - static_assert(sizeof(id) == sizeof(obj->data.basic.u), "ResourceId is no longer uint64_t!"); - memcpy(&id, &obj->data.basic.u, sizeof(id)); - // for resource IDs, try to locate the resource. - TextureDescription *tex = m_Ctx.GetTexture(id); - BufferDescription *buf = m_Ctx.GetBuffer(id); - - if(tex) - { - param += tex->name; - } - else if(buf) - { - param += buf->name; - } - else - { - param += lit("%1 %2").arg(obj->type.name).arg(obj->data.basic.u); - } - } - else if(obj->type.flags & SDTypeFlags::NullString) - { - param += lit("NULL"); - } - else if(obj->type.flags & SDTypeFlags::HasCustomString) - { - param += obj->data.str; - } - else - { - switch(obj->type.basetype) - { - case SDBasic::Chunk: - case SDBasic::Struct: - param += QFormatStr("%1()").arg(obj->type.name); - addObjects(item, obj->data.children, false); - break; - case SDBasic::Array: - param += QFormatStr("%1[]").arg(obj->type.name); - addObjects(item, obj->data.children, true); - break; - case SDBasic::Null: param += lit("NULL"); break; - case SDBasic::Buffer: param += lit("(%1 byte buffer)").arg(obj->type.byteSize); break; - case SDBasic::String: param += obj->data.str; break; - case SDBasic::Enum: - case SDBasic::UnsignedInteger: param += Formatter::Format(obj->data.basic.u); break; - case SDBasic::SignedInteger: param += Formatter::Format(obj->data.basic.i); break; - case SDBasic::Float: param += Formatter::Format(obj->data.basic.d); break; - case SDBasic::Boolean: param += (obj->data.basic.b ? tr("True") : tr("False")); break; - case SDBasic::Character: param += QLatin1Char(obj->data.basic.c); break; - } - } - - item->setText(1, param); - - parent->addChild(item); - } -} diff --git a/qrenderdoc/Windows/APIInspector.h b/qrenderdoc/Windows/APIInspector.h index 567535c86..6139a9811 100644 --- a/qrenderdoc/Windows/APIInspector.h +++ b/qrenderdoc/Windows/APIInspector.h @@ -59,5 +59,4 @@ private: void addCallstack(rdcarray calls); void fillAPIView(); - void addObjects(RDTreeWidgetItem *parent, const StructuredObjectList &objs, bool parentIsArray); };