From b7873ef58825993f7b820ec78842d0e5bbd7a8a5 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Thu, 7 Nov 2019 08:26:57 +0100 Subject: QSortPolicy: add Uniform sorting mode We used to perform uniform minization between adjacent render commands all the time. Since this can yield to a higher CPU usages (but more efficient rendering submission), we now make this step optional. [ChangeLog] QSortPolicy add Uniform mode (to control whether uniform minization should be performed) Change-Id: I5c0e0dba22400a9884ee1d75426fd76b073fdcb5 Reviewed-by: Sean Harmer --- src/render/framegraph/qsortpolicy.cpp | 7 +++++-- src/render/framegraph/qsortpolicy.h | 1 + src/render/renderers/opengl/renderer/renderview.cpp | 8 ++++++++ tests/auto/render/renderviews/tst_renderviews.cpp | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/render/framegraph/qsortpolicy.cpp b/src/render/framegraph/qsortpolicy.cpp index a24dd5eae..5c04025b0 100644 --- a/src/render/framegraph/qsortpolicy.cpp +++ b/src/render/framegraph/qsortpolicy.cpp @@ -98,12 +98,14 @@ QSortPolicyPrivate::QSortPolicyPrivate() projection of the camera-to-object-center vector onto the camera's view vector. - \value Material sort the objects based on their material value + \value Material sort the objects based on their material (shader) value. \value FrontToBack sort the objects from front to back. The opposite of BackToFront. \value [since 5.14] Texture sort the objects to minimize texture changes. + + \value [since 5.15] Uniform sort the objects to minimize uniform changes. */ /*! @@ -123,10 +125,11 @@ QSortPolicyPrivate::QSortPolicyPrivate() order. More accurately, the sorting key is the z component of the projection of the camera-to-object-center vector onto the camera's view vector. - \li Material - sort the objects based on their material value + \li Material - sort the objects based on their material (shader) value. \li FrontToBack - sort the objects from front to back. The opposite of BackToFront. \li [since 5.14] Texture - sort the objects to minimize texture changes. + \li [since 5.15] Uniform - sort the objects to minimize uniform changes. \endlist */ diff --git a/src/render/framegraph/qsortpolicy.h b/src/render/framegraph/qsortpolicy.h index a302caa8b..f5ea988e8 100644 --- a/src/render/framegraph/qsortpolicy.h +++ b/src/render/framegraph/qsortpolicy.h @@ -62,6 +62,7 @@ public: Material = (1 << 2), FrontToBack = (1 << 3), Texture = (1 << 4), + Uniform = (1 << 5) }; Q_ENUM(SortType) // LCOV_EXCL_LINE diff --git a/src/render/renderers/opengl/renderer/renderview.cpp b/src/render/renderers/opengl/renderer/renderview.cpp index c00a92629..60ebc2193 100644 --- a/src/render/renderers/opengl/renderer/renderview.cpp +++ b/src/render/renderers/opengl/renderer/renderview.cpp @@ -467,6 +467,8 @@ int findSubRange(const QVector &commands, return advanceUntilNonAdjacent(commands, begin, end, AdjacentSubRangeFinder::adjacentSubRange); case QSortPolicy::Texture: return advanceUntilNonAdjacent(commands, begin, end, AdjacentSubRangeFinder::adjacentSubRange); + case QSortPolicy::Uniform: + return end; default: Q_UNREACHABLE(); return end; @@ -513,6 +515,8 @@ void sortCommandRange(QVector &commands, int begin, const int end case QSortPolicy::Texture: SubRangeSorter::sortSubRange(commands.begin() + begin, commands.begin() + end); break; + case QSortPolicy::Uniform: + break; default: Q_UNREACHABLE(); } @@ -536,6 +540,10 @@ void RenderView::sort() // For RenderCommand with the same shader // We compute the adjacent change cost + // Only perform uniform minimization if we explicitly asked for it + if (!m_data.m_sortingTypes.contains(QSortPolicy::Uniform)) + return; + // Minimize uniform changes int i = 0; const int commandSize = m_commands.size(); diff --git a/tests/auto/render/renderviews/tst_renderviews.cpp b/tests/auto/render/renderviews/tst_renderviews.cpp index 1558b68c9..086ff0220 100644 --- a/tests/auto/render/renderviews/tst_renderviews.cpp +++ b/tests/auto/render/renderviews/tst_renderviews.cpp @@ -253,6 +253,7 @@ private Q_SLOTS: // WHEN renderView.setCommands(rawCommands); + renderView.addSortType((QVector() << QSortPolicy::Uniform)); renderView.sort(); // THEN -- cgit v1.2.3