From 38b13e562bfbe950a1803787890b0f6229309a12 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 24 Aug 2023 12:45:37 +0200 Subject: [PATCH] Reduce swapchain dependencies in QBackingStoreDefaultCompositor Instead of passing around the QRhiSwapChain, pass the objects queried from it. There is no point in tying the helper code to a swapchain when all that can function with other (texture-based) render targets as well. Change-Id: I0b14853f537c2d641eb67815c10edfe72e958fdf Reviewed-by: Andy Nichols --- .../painting/qbackingstoredefaultcompositor.cpp | 14 +++++++------- .../painting/qbackingstoredefaultcompositor_p.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/painting/qbackingstoredefaultcompositor.cpp b/src/gui/painting/qbackingstoredefaultcompositor.cpp index cd984ae0e9..d5973d66af 100644 --- a/src/gui/painting/qbackingstoredefaultcompositor.cpp +++ b/src/gui/painting/qbackingstoredefaultcompositor.cpp @@ -280,7 +280,7 @@ enum class PipelineBlend { static QRhiGraphicsPipeline *createGraphicsPipeline(QRhi *rhi, QRhiShaderResourceBindings *srb, - QRhiSwapChain *swapchain, + QRhiRenderPassDescriptor *rpDesc, PipelineBlend blend) { QRhiGraphicsPipeline *ps = rhi->newGraphicsPipeline(); @@ -324,7 +324,7 @@ static QRhiGraphicsPipeline *createGraphicsPipeline(QRhi *rhi, }); ps->setVertexInputLayout(inputLayout); ps->setShaderResourceBindings(srb); - ps->setRenderPassDescriptor(swapchain->renderPassDescriptor()); + ps->setRenderPassDescriptor(rpDesc); if (!ps->create()) { qWarning("QBackingStoreDefaultCompositor: Failed to build graphics pipeline"); @@ -407,7 +407,7 @@ void QBackingStoreDefaultCompositor::updateUniforms(PerQuadData *d, QRhiResource resourceUpdates->updateDynamicBuffer(d->ubuf, 116, 4, &textureSwizzle); } -void QBackingStoreDefaultCompositor::ensureResources(QRhiSwapChain *swapchain, QRhiResourceUpdateBatch *resourceUpdates) +void QBackingStoreDefaultCompositor::ensureResources(QRhiResourceUpdateBatch *resourceUpdates, QRhiRenderPassDescriptor *rpDesc) { static const float vertexData[] = { -1, -1, 0, 0, 0, @@ -438,11 +438,11 @@ void QBackingStoreDefaultCompositor::ensureResources(QRhiSwapChain *swapchain, Q QRhiShaderResourceBindings *srb = m_widgetQuadData.srb; // just for the layout if (!m_psNoBlend) - m_psNoBlend = createGraphicsPipeline(m_rhi, srb, swapchain, PipelineBlend::None); + m_psNoBlend = createGraphicsPipeline(m_rhi, srb, rpDesc, PipelineBlend::None); if (!m_psBlend) - m_psBlend = createGraphicsPipeline(m_rhi, srb, swapchain, PipelineBlend::Alpha); + m_psBlend = createGraphicsPipeline(m_rhi, srb, rpDesc, PipelineBlend::Alpha); if (!m_psPremulBlend) - m_psPremulBlend = createGraphicsPipeline(m_rhi, srb, swapchain, PipelineBlend::PremulAlpha); + m_psPremulBlend = createGraphicsPipeline(m_rhi, srb, rpDesc, PipelineBlend::PremulAlpha); } QPlatformBackingStore::FlushResult QBackingStoreDefaultCompositor::flush(QPlatformBackingStore *backingStore, @@ -511,7 +511,7 @@ QPlatformBackingStore::FlushResult QBackingStoreDefaultCompositor::flush(QPlatfo if (!gotTextureFromGraphicsBuffer) toTexture(backingStore, rhi, resourceUpdates, scaledRegion(region, sourceDevicePixelRatio, offset), &flags); - ensureResources(swapchain, resourceUpdates); + ensureResources(resourceUpdates, swapchain->renderPassDescriptor()); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN const UpdateUniformOption uniformOption = (flags & QPlatformBackingStore::TextureSwizzle) != 0? NeedsRedBlueSwap : NoOption; diff --git a/src/gui/painting/qbackingstoredefaultcompositor_p.h b/src/gui/painting/qbackingstoredefaultcompositor_p.h index 839fa61c73..0e68ac090c 100644 --- a/src/gui/painting/qbackingstoredefaultcompositor_p.h +++ b/src/gui/painting/qbackingstoredefaultcompositor_p.h @@ -50,7 +50,7 @@ private: NeedsAlphaRotate = 0x02, }; - void ensureResources(QRhiSwapChain *swapchain, QRhiResourceUpdateBatch *resourceUpdates); + void ensureResources(QRhiResourceUpdateBatch *resourceUpdates, QRhiRenderPassDescriptor *rpDesc); QRhiTexture *toTexture(const QImage &image, QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates,