From f3ab5c3b9ba1e91cb7fddd0e92a9cbd6c4bdccfd Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 10 Feb 2021 09:29:24 +0100 Subject: [PATCH] WIP: Attempt at improving batch overlap detection The current approach invalidates all batches between two render orders that change. So if you have a scene with an animating alpha batch at the beginning and end, then all alpha batches will be reuploaded every frame. --- .../scenegraph/coreapi/qsgbatchrenderer.cpp | 28 +++++++++++++------ .../scenegraph/coreapi/qsgbatchrenderer_p.h | 3 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index c34327bb41..9f89bec4c6 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -978,8 +978,6 @@ Renderer::Renderer(QSGDefaultRenderContext *ctx) , m_tmpOpaqueElements(16) , m_rebuild(FullRebuild) , m_zRange(0) - , m_renderOrderRebuildLower(-1) - , m_renderOrderRebuildUpper(-1) , m_currentMaterial(nullptr) , m_currentShader(nullptr) , m_currentStencilValue(0) @@ -1791,10 +1789,21 @@ void Renderer::invalidateBatchAndOverlappingRenderOrders(Batch *batch) Q_ASSERT(batch); Q_ASSERT(batch->first); - if (m_renderOrderRebuildLower < 0 || batch->first->order < m_renderOrderRebuildLower) + /*if (m_renderOrderRebuildLower < 0 || batch->first->order < m_renderOrderRebuildLower) m_renderOrderRebuildLower = batch->first->order; if (m_renderOrderRebuildUpper < 0 || batch->lastOrderInBatch > m_renderOrderRebuildUpper) - m_renderOrderRebuildUpper = batch->lastOrderInBatch; + m_renderOrderRebuildUpper = batch->lastOrderInBatch;*/ + + int start = batch->first->order; + int end = batch->lastOrderInBatch; + if (m_renderOrderRebuildRanges.size() < batch->lastOrderInBatch + 1) { + int start = std::min(start, m_renderOrderRebuildRanges.size()); + m_renderOrderRebuildRanges.resize(batch->lastOrderInBatch + 1); + } + + for (int i = start; i <= end; ++i) + m_renderOrderRebuildRanges[i] = (i >= batch->first->order && i <= batch->lastOrderInBatch); + batch->invalidate(); @@ -1803,8 +1812,12 @@ void Renderer::invalidateBatchAndOverlappingRenderOrders(Batch *batch) if (b->first) { int bf = b->first->order; int bl = b->lastOrderInBatch; - if (bl > m_renderOrderRebuildLower && bf < m_renderOrderRebuildUpper) - b->invalidate(); + for (int j = bf; j <= bl; ++j) { + if (j < m_renderOrderRebuildRanges.size() && m_renderOrderRebuildRanges.at(j)) { + b->invalidate(); + break; + } + } } } @@ -4346,8 +4359,7 @@ void Renderer::render() } m_rebuild = 0; - m_renderOrderRebuildLower = -1; - m_renderOrderRebuildUpper = -1; + m_renderOrderRebuildRanges.fill(false); if (m_visualizer->mode() != Visualizer::VisualizeNothing) m_visualizer->visualize(); diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 172d7c0e7f..08b906c313 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -871,8 +871,7 @@ private: uint m_rebuild; qreal m_zRange; - int m_renderOrderRebuildLower; - int m_renderOrderRebuildUpper; + QVector m_renderOrderRebuildRanges; GLuint m_bufferStrategy; int m_batchNodeThreshold; -- 2.21.0.windows.1