summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-06-28 16:35:22 +0200
committerPaul Lemire <paul.lemire@kdab.com>2016-07-04 07:31:43 +0000
commit0b85e7ad6a962ad86b5c6a74ec20980e72ef9a57 (patch)
tree2db87d33bdffa98bc40ad4a663cbc21ba231dac4
parentfb6f909a27fa6b60907d4748311fa0f6b77478fe (diff)
ClearsBuffers: make the RenderViews store clearbuffers values
This then allows to only do value lookup at submission time rather than accessing the backend node. This will be a great help when submission and frame processing are later on parallelized. Change-Id: I0d34251d67f8329f486626642d7d2eccef9ddf18 Task-number: QTBUG-54423 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/render/backend/renderer.cpp17
-rw-r--r--src/render/backend/renderview.cpp16
-rw-r--r--src/render/backend/renderview_p.h17
-rw-r--r--src/render/framegraph/framegraphvisitor.cpp13
4 files changed, 46 insertions, 17 deletions
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index b062c93f2..64fa4ffc4 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -708,8 +708,10 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
// set color, depth, stencil clear values (only if needed)
auto clearBufferTypes = renderView->clearTypes();
- if (clearBufferTypes & QClearBuffers::ColorBuffer && renderView->globalClearColorBuffers() != nullptr)
- m_graphicsContext->clearColor(renderView->globalClearColorBuffers()->clearColorAsColor());
+ if (clearBufferTypes & QClearBuffers::ColorBuffer) {
+ const QVector4D vCol = renderView->globalClearColorBufferInfo().clearColor;
+ m_graphicsContext->clearColor(QColor::fromRgbF(vCol.x(), vCol.y(), vCol.z(), vCol.w()));
+ }
if (clearBufferTypes & QClearBuffers::DepthBuffer)
m_graphicsContext->clearDepthValue(renderView->clearDepthValue());
if (clearBufferTypes & QClearBuffers::StencilBuffer)
@@ -720,14 +722,9 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
// if there are ClearColors set for different draw buffers,
// clear each of these draw buffers individually now
- const QVector<const ClearBuffers*> clearDrawBuffers = renderView->specificClearColorBuffers();
- for (const ClearBuffers *clearBuffer : clearDrawBuffers) {
- if (!clearBuffer->bufferId().isNull()) {
- const RenderTargetOutput *buffer = m_nodesManager->attachmentManager()->lookupResource(clearBuffer->bufferId());
- const int drawBufferIndex = renderView->attachmentPack().getDrawBufferIndex(buffer->point());
- m_graphicsContext->clearBufferf(drawBufferIndex, clearBuffer->clearColor());
- }
- }
+ const QVector<ClearBufferInfo> clearDrawBuffers = renderView->specificClearColorBufferInfo();
+ for (const ClearBufferInfo &clearBuffer : clearDrawBuffers)
+ m_graphicsContext->clearBufferf(clearBuffer.drawBufferIndex, clearBuffer.clearColor);
// Set the Viewport
m_graphicsContext->setViewport(renderView->viewport(), renderView->surfaceSize() * renderView->devicePixelRatio());
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index b8c7f772a..0f74239b6 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -243,7 +243,6 @@ RenderView::RenderView()
, m_viewport(QRectF(0.0f, 0.0f, 1.0f, 1.0f))
, m_surface(nullptr)
, m_clearBuffer(QClearBuffers::None)
- , m_globalClearColorBuffer(nullptr)
, m_stateSet(nullptr)
, m_noDraw(false)
, m_compute(false)
@@ -361,11 +360,22 @@ void RenderView::addClearBuffers(const ClearBuffers *cb) {
// keep track of global ClearColor (if set) and collect all DrawBuffer-specific
// ClearColors
if (type & QClearBuffers::ColorBuffer) {
+ ClearBufferInfo clearBufferInfo;
+ clearBufferInfo.clearColor = cb->clearColor();
+
if (cb->clearsAllColorBuffers()) {
- m_globalClearColorBuffer = cb;
+ m_globalClearColorBuffer = clearBufferInfo;
m_clearBuffer |= QClearBuffers::ColorBuffer;
} else {
- m_specificClearColorBuffers.push_back(cb);
+ if (cb->bufferId()) {
+ const RenderTargetOutput *targetOutput = m_manager->attachmentManager()->lookupResource(cb->bufferId());
+ if (targetOutput) {
+ clearBufferInfo.attchmentPoint = targetOutput->point();
+ // Note: a job is later performed to find the drawIndex from the buffer attachment point
+ // using the AttachmentPack
+ m_specificClearColorBuffers.push_back(clearBufferInfo);
+ }
+ }
}
}
}
diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h
index 0596b28b1..0b01744e9 100644
--- a/src/render/backend/renderview_p.h
+++ b/src/render/backend/renderview_p.h
@@ -105,6 +105,13 @@ struct Q_AUTOTEST_EXPORT Plane
const float d;
};
+struct Q_AUTOTEST_EXPORT ClearBufferInfo
+{
+ int drawBufferIndex = 0;
+ QRenderTargetOutput::AttachmentPoint attchmentPoint = QRenderTargetOutput::Color0;
+ QVector4D clearColor;
+};
+
// This class is kind of analogous to RenderBin but I want to avoid trampling
// on that until we get this working
@@ -177,8 +184,10 @@ public:
// color ClearBuffers are collected, as there may be multiple
// color buffers to be cleared. we need to apply all these at rendering
void addClearBuffers(const ClearBuffers *cb);
- inline QVector<const ClearBuffers*> specificClearColorBuffers() const { return m_specificClearColorBuffers; }
- inline const ClearBuffers* globalClearColorBuffers() const { return m_globalClearColorBuffer; }
+ inline QVector<ClearBufferInfo> specificClearColorBufferInfo() const { return m_specificClearColorBuffers; }
+ inline QVector<ClearBufferInfo> &specificClearColorBufferInfo() { return m_specificClearColorBuffers; }
+ inline ClearBufferInfo globalClearColorBufferInfo() const { return m_globalClearColorBuffer; }
+
inline QClearBuffers::BufferTypeFlags clearTypes() const { return m_clearBuffer; }
inline float clearDepthValue() const { return m_clearDepthValue; }
inline int clearStencilValue() const { return m_clearStencilValue; }
@@ -249,8 +258,8 @@ private:
QClearBuffers::BufferTypeFlags m_clearBuffer;
float m_clearDepthValue;
int m_clearStencilValue;
- const ClearBuffers* m_globalClearColorBuffer; // global ClearColor
- QVector<const ClearBuffers*> m_specificClearColorBuffers; // different draw buffers with distinct colors
+ ClearBufferInfo m_globalClearColorBuffer; // global ClearColor
+ QVector<ClearBufferInfo> m_specificClearColorBuffers; // different draw buffers with distinct colors
RenderStateSet *m_stateSet;
bool m_noDraw:1;
bool m_compute:1;
diff --git a/src/render/framegraph/framegraphvisitor.cpp b/src/render/framegraph/framegraphvisitor.cpp
index 211ed0660..a27cca19f 100644
--- a/src/render/framegraph/framegraphvisitor.cpp
+++ b/src/render/framegraph/framegraphvisitor.cpp
@@ -319,10 +319,19 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
renderer->enqueueRenderView(rv, currentRenderViewIndex);
};
+ auto setClearBufferDrawIndex = [=] () {
+ RenderView *rv = renderViewJob->renderView();
+ QVector<ClearBufferInfo> &clearBuffersInfo = rv->specificClearColorBufferInfo();
+ const AttachmentPack &attachmentPack = rv->attachmentPack();
+ for (ClearBufferInfo &clearBufferInfo : clearBuffersInfo)
+ clearBufferInfo.drawBufferIndex = attachmentPack.getDrawBufferIndex(clearBufferInfo.attchmentPoint);
+ };
+
auto syncRenderViewCommandBuildingJob = GenericLambdaJobPtr<decltype(syncForRenderCommandBuilding)>::create(syncForRenderCommandBuilding);
auto syncRenderViewInitializationJob = GenericLambdaJobPtr<decltype(syncRenderViewInitialization)>::create(syncRenderViewInitialization);
auto syncRenderViewCommandBuildersJob = GenericLambdaJobPtr<decltype(syncRenderViewCommandBuilders)>::create(syncRenderViewCommandBuilders);
auto syncFrustumCullingJob = GenericLambdaJobPtr<decltype(syncFrustumCulling)>::create(syncFrustumCulling);
+ auto setClearBufferDrawIndexJob = GenericLambdaJobPtr<decltype(setClearBufferDrawIndex)>::create(setClearBufferDrawIndex);
// Set dependencies
syncFrustumCullingJob->addDependency(renderer->updateWorldTransformJob());
@@ -331,6 +340,8 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
frustumCulling->addDependency(renderer->expandBoundingVolumeJob());
frustumCulling->addDependency(syncFrustumCullingJob);
+ setClearBufferDrawIndexJob->addDependency(syncRenderViewInitializationJob);
+
syncRenderViewInitializationJob->addDependency(renderViewJob);
filterEntityByLayer->addDependency(syncRenderViewInitializationJob);
@@ -351,6 +362,7 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
syncRenderViewCommandBuildersJob->addDependency(renderViewCommandBuilder);
}
renderer->frameCleanupJob()->addDependency(syncRenderViewCommandBuildersJob);
+ renderer->frameCleanupJob()->addDependency(setClearBufferDrawIndexJob);
// Add jobs
m_jobs->push_back(renderViewJob);
@@ -363,6 +375,7 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
m_jobs->push_back(lightGatherer);
m_jobs->push_back(syncRenderViewCommandBuildersJob);
m_jobs->push_back(syncFrustumCullingJob);
+ m_jobs->push_back(setClearBufferDrawIndexJob);
for (const auto materialGatherer : qAsConst(materialGatherers))
m_jobs->push_back(materialGatherer);