summaryrefslogtreecommitdiffstats
path: root/src/render/framegraph/framegraphvisitor.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-05-18 15:36:01 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-07-03 08:54:23 +0000
commitd8d24fb4a5c0839ec4ac92063cc919606821cb9f (patch)
treeed4908350c559e8b991635e45f1dc797d41e37fa /src/render/framegraph/framegraphvisitor.cpp
parentb246d17fb3e45848ddbfd581d7cb87b9575f7e86 (diff)
Use more instances of MaterialParameter when necessary
Change-Id: I08f98b77d9a0e7f74a1093748e7b32e27e1f88c5 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/framegraph/framegraphvisitor.cpp')
-rw-r--r--src/render/framegraph/framegraphvisitor.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/render/framegraph/framegraphvisitor.cpp b/src/render/framegraph/framegraphvisitor.cpp
index c43a32e3f..6b331d4ad 100644
--- a/src/render/framegraph/framegraphvisitor.cpp
+++ b/src/render/framegraph/framegraphvisitor.cpp
@@ -133,7 +133,6 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
// Note: do it only if OpenGL 4.3+ available
auto computeEntityFilterer = Render::FilterEntityByComponentJobPtr<Render::ComputeCommand, Render::Material>::create();
- auto materialGatherer = Render::MaterialParameterGathererJobPtr::create();
auto frustumCulling = Render::FrustumCullingJobPtr::create();
// Init what we can here
@@ -141,12 +140,25 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
filterEntityByLayer->setManager(entityManager);
renderableEntityFilterer->setManager(entityManager);
computeEntityFilterer->setManager(entityManager);
- materialGatherer->setNodeManagers(m_renderer->nodeManagers());
- materialGatherer->setRenderer(m_renderer);
frustumCulling->setRoot(m_renderer->sceneRoot());
renderViewCommandBuilder->setIndex(currentRenderViewIndex);
renderViewCommandBuilder->setRenderer(m_renderer);
+ // Since Material gathering is an heavy task, we split it
+ QVector<Render::MaterialParameterGathererJobPtr> materialGatherers;
+ { // Scoped to avoid copy in lambdas
+ const QVector<HMaterial> materialHandles = m_renderer->nodeManagers()->materialManager()->activeHandles();
+ const int materialGathererCount = std::max(materialHandles.size() / 8, 1);
+ materialGatherers.reserve(materialGathererCount);
+ for (auto i = 0; i < materialGathererCount; ++i) {
+ auto materialGatherer = Render::MaterialParameterGathererJobPtr::create();
+ materialGatherer->setNodeManagers(m_renderer->nodeManagers());
+ materialGatherer->setRenderer(m_renderer);
+ materialGatherer->setHandles(materialHandles.mid(i * 8, 8));
+ materialGatherers.push_back(materialGatherer);
+ }
+ }
+
// Copy shared ptr -> this is called once the FrameGraphBranch was used to fill initial data in the RenderView
auto syncRenderViewInitialization = [=] () {
RenderView *rv = renderViewJob->renderView();
@@ -156,8 +168,10 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
filterEntityByLayer->setLayers(rv->layerFilter());
// Material Parameter building
- materialGatherer->setRenderPassFilter(const_cast<RenderPassFilter *>(rv->renderPassFilter()));
- materialGatherer->setTechniqueFilter(const_cast<TechniqueFilter *>(rv->techniqueFilter()));
+ for (const auto materialGatherer : qAsConst(materialGatherers)) {
+ materialGatherer->setRenderPassFilter(const_cast<RenderPassFilter *>(rv->renderPassFilter()));
+ materialGatherer->setTechniqueFilter(const_cast<TechniqueFilter *>(rv->techniqueFilter()));
+ }
// Frustum culling
frustumCulling->setViewProjection(rv->viewProjectionMatrix());
@@ -201,8 +215,12 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
rv->setComputables(std::move(computableEntities));
}
+ // Reduction
+ QHash<Qt3DCore::QNodeId, QVector<RenderPassParameterData>> params;
+ for (const auto materialGatherer : qAsConst(materialGatherers))
+ params.unite(materialGatherer->materialToPassAndParameter());
// Set all required data on the RenderView for final processing
- rv->setMaterialParameterTable(std::move(materialGatherer->materialToPassAndParameter()));
+ rv->setMaterialParameterTable(std::move(params));
}
renderViewCommandBuilder->setRenderView(renderViewJob->renderView());
};
@@ -214,11 +232,13 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
syncRenderViewInitializationJob->addDependency(renderViewJob);
filterEntityByLayer->addDependency(syncRenderViewInitializationJob);
- materialGatherer->addDependency(syncRenderViewInitializationJob);
frustumCulling->addDependency(syncRenderViewInitializationJob);
syncRenderViewCommandBuildingJob->addDependency(syncRenderViewInitializationJob);
- syncRenderViewCommandBuildingJob->addDependency(materialGatherer);
+ for (const auto materialGatherer : qAsConst(materialGatherers)) {
+ materialGatherer->addDependency(syncRenderViewInitializationJob);
+ syncRenderViewCommandBuildingJob->addDependency(materialGatherer);
+ }
syncRenderViewCommandBuildingJob->addDependency(renderableEntityFilterer);
syncRenderViewCommandBuildingJob->addDependency(computeEntityFilterer);
syncRenderViewCommandBuildingJob->addDependency(filterEntityByLayer);
@@ -233,8 +253,9 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
m_jobs->push_back(syncRenderViewInitializationJob);
m_jobs->push_back(syncRenderViewCommandBuildingJob);
m_jobs->push_back(renderViewCommandBuilder);
- m_jobs->push_back(materialGatherer);
m_jobs->push_back(frustumCulling);
+ for (const auto materialGatherer : qAsConst(materialGatherers))
+ m_jobs->push_back(materialGatherer);
}
}