From 60e530de880ca83315072acbfb5ef3455381498e Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 14 Nov 2017 18:08:34 +0000 Subject: [PATCH] Split out utility function to group together resource usage events --- qrenderdoc/Code/QRDUtils.cpp | 65 ++++++++++++++++++++++++++++ qrenderdoc/Code/QRDUtils.h | 4 ++ qrenderdoc/Windows/TextureViewer.cpp | 64 ++------------------------- 3 files changed, 73 insertions(+), 60 deletions(-) diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 8b5a36ba3..31069b482 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -293,6 +293,71 @@ QString GetComponentString(byte mask) return ret; } +void CombineUsageEvents(ICaptureContext &ctx, const rdcarray &usage, + std::function callback) +{ + uint32_t start = 0; + uint32_t end = 0; + ResourceUsage us = ResourceUsage::IndexBuffer; + + for(const EventUsage u : usage) + { + if(start == 0) + { + start = end = u.eventID; + us = u.usage; + continue; + } + + const DrawcallDescription *draw = ctx.GetDrawcall(u.eventID); + + bool distinct = false; + + // if the usage is different from the last, add a new entry, + // or if the previous draw link is broken. + if(u.usage != us || draw == NULL || draw->previous == 0) + { + distinct = true; + } + else + { + // otherwise search back through real draws, to see if the + // last event was where we were - otherwise it's a new + // distinct set of drawcalls and should have a separate + // entry in the context menu + const DrawcallDescription *prev = ctx.GetDrawcall(draw->previous); + + while(prev != NULL && prev->eventID > end) + { + if(!(prev->flags & (DrawFlags::Dispatch | DrawFlags::Drawcall | DrawFlags::CmdList))) + { + prev = ctx.GetDrawcall(prev->previous); + } + else + { + distinct = true; + break; + } + + if(prev == NULL) + distinct = true; + } + } + + if(distinct) + { + callback(start, end, us); + start = end = u.eventID; + us = u.usage; + } + + end = u.eventID; + } + + if(start != 0) + callback(start, end, us); +} + 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 938a616ef..314e3aa1a 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -98,6 +98,10 @@ QString TypeString(const SigParameter &sig); QString D3DSemanticString(const SigParameter &sig); QString GetComponentString(byte mask); +void CombineUsageEvents( + ICaptureContext &ctx, const rdcarray &usage, + std::function callback); + struct Formatter { static void setParams(const PersistantConfig &config); diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index d9726e10d..fecae4a8d 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -1845,66 +1845,10 @@ void TextureViewer::OpenResourceContextMenu(ResourceId id, const rdcarrayprevious == 0) - { - distinct = true; - } - else - { - // otherwise search back through real draws, to see if the - // last event was where we were - otherwise it's a new - // distinct set of drawcalls and should have a separate - // entry in the context menu - const DrawcallDescription *prev = m_Ctx.GetDrawcall(curDraw->previous); - - while(prev != NULL && prev->eventID > end) - { - if(!(prev->flags & (DrawFlags::Dispatch | DrawFlags::Drawcall | DrawFlags::CmdList))) - { - prev = m_Ctx.GetDrawcall(prev->previous); - } - else - { - distinct = true; - break; - } - - if(prev == NULL) - distinct = true; - } - } - - if(distinct) - { - AddResourceUsageEntry(contextMenu, start, end, us); - start = end = u.eventID; - us = u.usage; - } - - end = u.eventID; - } - - if(start != 0) - AddResourceUsageEntry(contextMenu, start, end, us); + CombineUsageEvents(m_Ctx, usage, + [this, &contextMenu](uint32_t start, uint32_t end, ResourceUsage use) { + AddResourceUsageEntry(contextMenu, start, end, use); + }); RDDialog::show(&contextMenu, QCursor::pos()); }