640void NormalPass::renderPrep(QSSGRenderer &renderer, QSSGLayerRenderData &data)
642 using namespace RenderHelpers;
644 QSSG_ASSERT(!data.renderedCameras.isEmpty(),
return);
645 QSSGRenderCamera *camera = data.renderedCameras[0];
647 const auto &rhiCtx = renderer.contextInterface()->rhiContext();
648 QRhi *rhi = rhiCtx->rhi();
650 const auto &layerPrepResult = data.layerPrepResult;
657 ps = data.getPipelineState();
660 adjustOriginForOffscreenRender(ps, data);
661 const auto cleanup = qScopeGuard([&data] { endOffscreenRender(data); });
663 sortedOpaqueObjects = data.getSortedOpaqueRenderableObjects(*camera);
667 QSSGShaderFeatures shaderFeatures = data.getShaderFeatures();
668 shaderFeatures.set(QSSGShaderFeatures::Feature::NormalPass,
true);
670 normalTexture = data.getRenderResult(QSSGRenderResult::Key::NormalTexture);
671 QSSGRhiResourceRegistry ®istry = QSSGRhiContextPrivate::get(rhiCtx.get())->resourceRegistry();
673 const QSize size = layerPrepResult.textureDimensions();
674 bool needsBuild =
false;
676 if (!normalTexture->texture) {
677 QRhiTexture::Format format = QRhiTexture::RGBA16F;
678 if (!rhi->isTextureFormatSupported(format)) {
679 qWarning(
"No float formats, not great");
680 format = QRhiTexture::RGBA8;
682 normalTexture->texture = rhiCtx->rhi()->newTexture(format, size, 1, QRhiTexture::RenderTarget);
684 normalTexture->texture->setName(QByteArrayLiteral(
"Normal texture"));
685 }
else if (normalTexture->texture->pixelSize() != size) {
687 registry.retire(normalTexture->texture);
688 normalTexture->texture->setPixelSize(size);
692 if (!normalTexture->depthStencil) {
693 normalTexture->depthStencil = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, size);
695 }
else if (normalTexture->depthStencil->pixelSize() != size) {
696 registry.retire(normalTexture->depthStencil);
697 normalTexture->depthStencil->setPixelSize(size);
702 if (!normalTexture->texture->create()) {
703 qWarning(
"Failed to build normal texture (size %dx%d, format %d)",
704 size.width(), size.height(),
int(normalTexture->texture->format()));
705 normalTexture->reset(®istry);
709 if (!normalTexture->depthStencil->create()) {
710 qWarning(
"Failed to build depth-stencil buffer for normal texture (size %dx%d)",
711 size.width(), size.height());
712 normalTexture->reset(®istry);
716 normalTexture->resetRenderTarget();
718 QRhiTextureRenderTargetDescription rtDesc;
719 QRhiColorAttachment colorAttachment(normalTexture->texture);
720 rtDesc.setColorAttachments({ colorAttachment });
721 rtDesc.setDepthStencilBuffer(normalTexture->depthStencil);
723 normalTexture->rt = rhi->newTextureRenderTarget(rtDesc);
724 normalTexture->rt->setName(QByteArrayLiteral(
"Normal texture RT"));
725 normalTexture->rpDesc = normalTexture->rt->newCompatibleRenderPassDescriptor();
726 normalTexture->rt->setRenderPassDescriptor(normalTexture->rpDesc);
727 if (!normalTexture->rt->create()) {
728 qWarning(
"Failed to build render target for normal texture");
729 normalTexture->reset(®istry);
734 rhiPrepareNormalPass(rhiCtx.get(),
this, ps, normalTexture->rpDesc, data, sortedOpaqueObjects);
1239 const auto &ctx = *renderer.contextInterface();
1240 const auto &rhiCtx = ctx.rhiContext();
1241 QSSG_ASSERT(rhiCtx->rhi()->isRecordingFrame(),
return);
1242 QSSG_ASSERT(!data.renderedCameras.isEmpty(),
return);
1243 QSSG_ASSERT(data.renderedCameras.count() == data.layer.viewCount,
return);
1244 layer = &data.layer;
1249 rpDesc = rhiCtx->mainRenderPassDescriptor();
1250 ps = data.getPipelineState();
1251 ps.samples = rhiCtx->mainPassSampleCount();
1252 ps.viewCount = data.layer.viewCount;
1253 ps.polygonMode = QRhiGraphicsPipeline::Fill;
1258 QRhi *rhi = rhiCtx->rhi();
1259 QSSGRenderSkyMaterial &skyMaterial = *layer->skyMaterial;
1260 const int viewCount = data.layer.viewCount;
1262 const QSSGRenderLayer::TonemapMode tonemapMode =
1263 skipTonemapping && (layer->tonemapMode != QSSGRenderLayer::TonemapMode::Custom)
1264 ? QSSGRenderLayer::TonemapMode::None
1265 : layer->tonemapMode;
1266 QSSGShaderFeatures tonemapFeatures;
1267 quint32 tonemapKey = 0;
1268 skyMaterialTonemapFeatures(tonemapMode, tonemapFeatures, tonemapKey);
1270 pipeline = skyMaterial.ensureBackgroundPipeline(ctx, tonemapFeatures, tonemapKey, viewCount);
1278 const QMatrix3x3 o = layer->lightProbeSettings.probeOrientation;
1279 const QMatrix4x4 orientation(o(0, 0), o(0, 1), o(0, 2), 0.0f,
1280 o(1, 0), o(1, 1), o(1, 2), 0.0f,
1281 o(2, 0), o(2, 1), o(2, 2), 0.0f,
1282 0.0f, 0.0f, 0.0f, 1.0f);
1283 QVarLengthArray<QMatrix4x4, 2> inverseProjections;
1284 QVarLengthArray<QMatrix4x4, 2> viewRotations;
1285 for (
int v = 0; v < viewCount; ++v) {
1286 const QSSGRenderCamera &camera = *data.renderedCameras[v];
1287 inverseProjections.append(camera.projection.inverted());
1288 QMatrix4x4 cameraRotation = data.getGlobalTransform(camera);
1289 cameraRotation.setColumn(3, QVector4D(0.0f, 0.0f, 0.0f, 1.0f));
1290 viewRotations.append(orientation * cameraRotation);
1292 const float adjustY = rhi->isYUpInNDC() ? 1.0f : -1.0f;
1293 const float exposure = layer->lightProbeSettings.probeExposure;
1295 QRhiResourceUpdateBatch *rub = rhi->nextResourceUpdateBatch();
1296 skyMaterial.updateBackgroundUniforms(ctx,
this, inverseProjections, viewRotations, adjustY, exposure, rub);
1297 rhiCtx->commandBuffer()->resourceUpdate(rub);
1299 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx.get());
1300 backgroundSrb = rhiCtxD->srb(skyMaterial.backgroundBindings);
1302 switch (skyMaterial.skyboxMode) {
1303 case QSSGRenderSkyMaterial::SkyboxMode::ScreenSpaceHalf:
1306 case QSSGRenderSkyMaterial::SkyboxMode::ScreenSpaceQuarter:
1309 case QSSGRenderSkyMaterial::SkyboxMode::ScreenSpaceFull:
1310 case QSSGRenderSkyMaterial::SkyboxMode::Cubemap:
1315 renderer.rhiQuadRenderer()->prepareQuad(rhiCtx.get(),
nullptr);
1320 const std::array<
float, 4> vp = ps.viewport.viewport();
1321 const QSize fullSize(
int(vp.at(2)),
int(vp.at(3)));
1322 const QSize targetSize = (fullSize / qreal(
scaleDivisor)).expandedTo(QSize(1, 1));
1323 const bool multiView = viewCount >= 2;
1324 const int wantArraySize = multiView ? viewCount : 0;
1326 offscreenTexture = data.getRenderResult(QSSGRenderResult::Key::SkyMaterialBackgroundTexture);
1327 QSSGRhiRenderableTexture *tex = offscreenTexture;
1328 QSSGRhiResourceRegistry *registry = &QSSGRhiContextPrivate::get(rhiCtx.get())->resourceRegistry();
1329 if (!tex->texture || tex->texture->pixelSize() != targetSize || tex->texture->arraySize() != wantArraySize) {
1330 tex->reset(registry);
1331 tex->texture = multiView ? rhi->newTextureArray(QRhiTexture::RGBA16F, viewCount, targetSize, 1, QRhiTexture::RenderTarget)
1332 : rhi->newTexture(QRhiTexture::RGBA16F, targetSize, 1, QRhiTexture::RenderTarget);
1333 if (!tex->texture->create()) {
1334 qWarning(
"Failed to build SkyMaterial screen-space background texture");
1335 tex->reset(registry);
1336 offscreenTexture =
nullptr;
1339 QRhiColorAttachment att(tex->texture);
1340 att.setMultiViewCount(viewCount);
1341 QRhiTextureRenderTargetDescription desc;
1342 desc.setColorAttachments({ att });
1343 tex->rt = rhi->newTextureRenderTarget(desc);
1344 tex->rt->setName(QByteArrayLiteral(
"SkyMaterial screen-space background"));
1345 tex->rpDesc = tex->rt->newCompatibleRenderPassDescriptor();
1346 tex->rt->setRenderPassDescriptor(tex->rpDesc);
1347 if (!tex->rt->create()) {
1348 qWarning(
"Failed to build SkyMaterial screen-space background render target");
1349 tex->reset(registry);
1350 offscreenTexture =
nullptr;
1355 QSSGRhiGraphicsPipelineState offscreenPs;
1356 offscreenPs.viewport = QRhiViewport(0, 0,
float(targetSize.width()),
float(targetSize.height()));
1357 offscreenPs.samples = 1;
1358 offscreenPs.viewCount = viewCount;
1359 offscreenPs.polygonMode = QRhiGraphicsPipeline::Fill;
1360 QSSGRhiGraphicsPipelineStatePrivate::setShaderPipeline(offscreenPs, pipeline.get());
1361 renderer.rhiQuadRenderer()->recordRenderQuadPass(rhiCtx.get(), &offscreenPs, backgroundSrb,
1362 offscreenTexture->rt, QSSGRhiQuadRenderer::RenderBehind);
1735 auto *ctx = renderer.contextInterface();
1736 const auto &rhiCtx = ctx->rhiContext();
1737 auto *rhi = rhiCtx->rhi();
1739 QSSG_ASSERT(!data.renderedCameras.isEmpty() && data.renderedCameraData.has_value() ,
return);
1740 QSSGRenderCamera *camera = data.renderedCameras[0];
1742 ps = data.getPipelineState();
1743 ps.samples = rhiCtx->mainPassSampleCount();
1744 ps.viewCount = rhiCtx->mainPassViewCount();
1746 adjustOriginForOffscreenRender(ps, data);
1749 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled,
true);
1750 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled,
false);
1752 shaderFeatures = data.getShaderFeatures();
1753 sortedTransparentObjects = data.getSortedTransparentRenderableObjects(*camera);
1755 if (method == QSSGRenderLayer::OITMethod::WeightedBlended) {
1757 ps.colorAttachmentCount = 2;
1759 rhiAccumTexture = data.getRenderResult(QSSGRenderResult::Key::AccumTexture);
1760 rhiRevealageTexture = data.getRenderResult(QSSGRenderResult::Key::RevealageTexture);
1762 rhiDepthTexture = data.getRenderResult(QSSGRenderResult::Key::DepthTextureMS);
1764 rhiDepthTexture = data.getRenderResult(QSSGRenderResult::Key::DepthTexture);
1765 if (!rhiDepthTexture->isValid())
1767 if (!oitRenderContext->oitRenderTarget || oitRenderContext->oitRenderTarget->pixelSize() != data.layerPrepResult.textureDimensions()
1768 || rhiDepthTexture->texture != oitRenderContext->oitRenderTarget->description().depthTexture()
1769 || ps.samples != oitRenderContext->oitRenderTarget->sampleCount()) {
1773 delete rhiAccumTexture->texture;
1774 delete rhiRevealageTexture->texture;
1777 rhiAccumTexture->texture =
nullptr;
1778 rhiRevealageTexture->texture =
nullptr;
1780 const QRhiTexture::Flags textureFlags = QRhiTexture::RenderTarget;
1781 if (ps.viewCount >= 2) {
1782 rhiAccumTexture->texture = rhi->newTextureArray(QRhiTexture::RGBA16F, ps.viewCount, data.layerPrepResult.textureDimensions(), ps.samples, textureFlags);
1783 rhiRevealageTexture->texture = rhi->newTextureArray(QRhiTexture::R16F, ps.viewCount, data.layerPrepResult.textureDimensions(), ps.samples, textureFlags);
1785 rhiAccumTexture->texture = rhi->newTexture(QRhiTexture::RGBA16F, data.layerPrepResult.textureDimensions(), ps.samples, textureFlags);
1786 rhiRevealageTexture->texture = rhi->newTexture(QRhiTexture::R16F, data.layerPrepResult.textureDimensions(), ps.samples, textureFlags);
1788 rhiAccumTexture->texture->create();
1789 rhiRevealageTexture->texture->create();
1791 QRhiTextureRenderTargetDescription desc;
1792 QRhiColorAttachment accumAttachment(rhiAccumTexture->texture);
1793 QRhiColorAttachment revealageAttachment(rhiRevealageTexture->texture);
1794 if (ps.viewCount >= 2) {
1795 accumAttachment.setMultiViewCount(ps.viewCount);
1796 revealageAttachment.setMultiViewCount(ps.viewCount);
1798 desc.setColorAttachments({{accumAttachment}, {revealageAttachment}});
1799 desc.setDepthTexture(rhiDepthTexture->texture);
1802 oitRenderContext->oitRenderTarget = rhi->newTextureRenderTarget(desc, QRhiTextureRenderTarget::PreserveDepthStencilContents);
1810 renderTarget = oitRenderContext->oitRenderTarget;
1812 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx.get());
1813 const auto &shaderCache = renderer.contextInterface()->shaderCache();
1814 clearPipeline = shaderCache->getBuiltInRhiShaders().getRhiClearMRTShader(ps.viewCount);
1816 QSSGRhiShaderResourceBindingList bindings;
1817 QVector4D clearData[2];
1818 clearData[0] = QVector4D(0.0, 0.0, 0.0, 0.0);
1819 clearData[1] = QVector4D(1.0, 1.0, 1.0, 1.0);
1821 QSSGRhiDrawCallData &dcd(rhiCtxD->drawCallData({
this, clearPipeline.get(),
nullptr,
nullptr, 0 }));
1822 QRhiBuffer *&ubuf = dcd.ubuf;
1823 const int ubufSize =
sizeof(clearData);
1825 ubuf = rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, ubufSize);
1829 QRhiResourceUpdateBatch *rub = rhi->nextResourceUpdateBatch();
1830 rub->updateDynamicBuffer(ubuf, 0, ubufSize, &clearData);
1831 renderer.rhiQuadRenderer()->prepareQuad(rhiCtx.get(), rub);
1833 bindings.addUniformBuffer(0, QRhiShaderResourceBinding::FragmentStage, ubuf);
1835 clearSrb = rhiCtxD->srb(bindings);
1837 ps.targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
1838 ps.targetBlend[0].srcColor = QRhiGraphicsPipeline::One;
1839 ps.targetBlend[0].dstAlpha = QRhiGraphicsPipeline::One;
1840 ps.targetBlend[0].dstColor = QRhiGraphicsPipeline::One;
1841 ps.targetBlend[1].srcAlpha = QRhiGraphicsPipeline::Zero;
1842 ps.targetBlend[1].srcColor = QRhiGraphicsPipeline::Zero;
1843 ps.targetBlend[1].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
1844 ps.targetBlend[1].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
1846 TransparentPass::prep(*ctx, data,
this, ps, shaderFeatures, oitRenderContext->renderPassDescriptor, sortedTransparentObjects,
true);
1847 }
else if (method == QSSGRenderLayer::OITMethod::LinkedList) {
1855 rhiDepthTexture = data.getRenderResult(QSSGRenderResult::Key::DepthTextureMS);
1857 rhiDepthTexture = data.getRenderResult(QSSGRenderResult::Key::DepthTexture);
1858 if (!rhiDepthTexture->isValid())
1863 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled,
true);
1864 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled,
false);
1865 ps.targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
1866 ps.targetBlend[0].srcColor = QRhiGraphicsPipeline::SrcAlpha;
1867 ps.targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
1868 ps.targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
1870 shaderFeatures = data.getShaderFeatures();
1871 sortedTransparentObjects = data.getSortedTransparentRenderableObjects(*camera);
1873#ifdef QSSG_OIT_USE_BUFFERS
1874 rhiABuffer = oitRenderContext->aBuffer;
1875 rhiAuxBuffer = oitRenderContext->auxBuffer;
1876 rhiCounterBuffer = oitRenderContext->counterBuffer;
1878 rhiABufferImage = data.getRenderResult(QSSGRenderResult::Key::ABufferImage);
1879 rhiAuxiliaryImage = data.getRenderResult(QSSGRenderResult::Key::AuxiliaryImage);
1880 rhiCounterImage = data.getRenderResult(QSSGRenderResult::Key::CounterImage);
1882 QSize dim = data.layerPrepResult.textureDimensions();
1884 if (oitRenderContext->oitRenderTarget ==
nullptr || oitRenderContext->oitRenderTarget->pixelSize() != dim
1885 || rhiDepthTexture->texture != oitRenderContext->oitRenderTarget->description().depthTexture()
1886 || ps.samples != oitRenderContext->oitRenderTarget->sampleCount()) {
1895 const QRhiTexture::Flags textureFlags = QRhiTexture::RenderTarget;
1896 if (ps.viewCount >= 2)
1903 colorAttachment.setMultiViewCount(ps.viewCount);
1904 QRhiTextureRenderTargetDescription desc;
1905 desc.setColorAttachments({ colorAttachment });
1906 desc.setDepthTexture(rhiDepthTexture->texture);
1907 oitRenderContext->oitRenderTarget = rhi->newTextureRenderTarget(desc, QRhiTextureRenderTarget::PreserveDepthStencilContents);
1913 renderTarget = oitRenderContext->oitRenderTarget;
1915 dim.setWidth(dim.width() * ps.samples);
1916 dim.setHeight(dim.height() * ps.viewCount);
1917#ifdef QSSG_OIT_USE_BUFFERS
1918 if (!rhiAuxBuffer || rhiAuxBuffer->size() != (dim.width() * dim.height() * 4u) || currentNodeCount == 0 || linkedListRequiresResize(dim))
1920 if (!rhiAuxiliaryImage->texture || rhiAuxiliaryImage->texture->pixelSize() != dim || currentNodeCount == 0 || linkedListRequiresResize(dim))
1923 quint32 extraNodeCount = 0;
1924#ifdef QSSG_OIT_USE_BUFFERS
1925 if (rhiAuxBuffer && rhiAuxBuffer->size() != (dim.width() * dim.height() * 4u)) {
1926 if (rhiAuxBuffer->size() < (dim.width() * dim.height() * 4u))
1927 extraNodeCount = ensureFreeNodes((dim.width() * dim.height() * 4u) - rhiAuxBuffer->size(), 32u * 1024u);
1928 delete rhiAuxBuffer;
1929 rhiAuxBuffer =
nullptr;
1932 if (rhiABufferImage->texture) {
1933 const auto s = rhiAuxiliaryImage->texture->pixelSize();
1934 if (s.width() * s.height() < dim.width() * dim.height())
1935 extraNodeCount = ensureFreeNodes(dim.width() * dim.height() - s.width() * s.height(), 32u * 1024u);
1936 delete rhiABufferImage->texture;
1937 rhiABufferImage->texture =
nullptr;
1938 delete rhiAuxiliaryImage->texture;
1939 rhiAuxiliaryImage->texture =
nullptr;
1943 if (reportedNodeCount) {
1945 currentNodeCount = ensureFreeNodes(reportedNodeCount + extraNodeCount, dim.width() * dim.height() / 2);
1947 quint32 size = RenderHelpers::rhiCalculateABufferSize(data.layerPrepResult.textureDimensions(), 4 * ps.samples * ps.viewCount);
1948 currentNodeCount = ensureFreeNodes(size * size, 32u * 1024u);
1950 data.layer.oitNodeCount = currentNodeCount;
1952#ifdef QSSG_OIT_USE_BUFFERS
1953 if (rhiABuffer && currentNodeCount * 16 != rhiABuffer->size()) {
1955 rhiABuffer =
nullptr;
1958 rhiABuffer = rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, currentNodeCount * 16);
1959 rhiABuffer->create();
1961 if (!rhiAuxBuffer) {
1962 rhiAuxBuffer = rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, dim.width() * dim.height() * 4);
1963 rhiAuxBuffer->create();
1965 if (!rhiCounterBuffer) {
1966 rhiCounterBuffer = rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 4);
1967 rhiCounterBuffer->create();
1968 oitRenderContext->counterBuffer = rhiCounterBuffer;
1970 oitRenderContext->aBuffer = rhiABuffer;
1971 oitRenderContext->auxBuffer = rhiAuxBuffer;
1973 quint32 sizeWithLayers = RenderHelpers::rhiCalculateABufferSize(currentNodeCount);
1974 const QRhiTexture::Flags textureFlags = QRhiTexture::UsedWithLoadStore;
1975 rhiABufferImage->texture = rhi->newTexture(QRhiTexture::RGBA32UI, QSize(sizeWithLayers, sizeWithLayers), 1, textureFlags);
1976 rhiABufferImage->texture->create();
1977 rhiAuxiliaryImage->texture = rhi->newTexture(QRhiTexture::R32UI, dim, 1, textureFlags);
1978 rhiAuxiliaryImage->texture->create();
1979 if (!rhiCounterImage->texture) {
1980 rhiCounterImage->texture = rhi->newTexture(QRhiTexture::R32UI, QSize(1, 1), 1, textureFlags | QRhiTexture::UsedAsTransferSource);
1981 rhiCounterImage->texture->create();
1983 readbackImage = rhi->newTexture(QRhiTexture::R32UI, QSize(1, 1), 1, QRhiTexture::UsedAsTransferSource);
1989 QRhiResourceUpdateBatch *rub = rhiCtx->rhi()->nextResourceUpdateBatch();
1991 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx.get());
1992 const auto &shaderCache = renderer.contextInterface()->shaderCache();
1993#ifdef QSSG_OIT_USE_BUFFERS
1994 clearPipeline = shaderCache->getBuiltInRhiShaders().getRhiClearBufferShader(ps.viewCount);
1996 clearPipeline = shaderCache->getBuiltInRhiShaders().getRhiClearImageShader(ps.viewCount);
1998 QSSGRhiShaderResourceBindingList bindings;
1999 quint32 clearImageData[10] = {0};
2001 QSSGRhiDrawCallData &dcd(rhiCtxD->drawCallData({
this, clearPipeline.get(),
nullptr,
nullptr, 0 }));
2002 QRhiBuffer *&ubuf = dcd.ubuf;
2003 const int ubufSize =
sizeof(clearImageData);
2005 ubuf = rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, ubufSize);
2009 clearImageData[4] = data.layerPrepResult.textureDimensions().width();
2010 clearImageData[5] = data.layerPrepResult.textureDimensions().height();
2011 clearImageData[6] = ps.samples;
2012 clearImageData[7] = 0;
2013 const QPoint origin = currentViewportOrigin(data);
2014 clearImageData[8] = quint32(origin.x());
2015 clearImageData[9] = quint32(origin.y());
2017 rub->updateDynamicBuffer(ubuf, 0, ubufSize, clearImageData);
2019#ifdef QSSG_OIT_USE_BUFFERS
2020 rub->uploadStaticBuffer(rhiCounterBuffer, 0, 4, &zero);
2022 rub->uploadTexture(rhiCounterImage->texture, {{0, 0, {&zero, 4}}});
2025 bindings.addUniformBuffer(0, QRhiShaderResourceBinding::FragmentStage, ubuf);
2026#ifdef QSSG_OIT_USE_BUFFERS
2027 bindings.addStorageBufferLoadStore(1, QRhiShaderResourceBinding::FragmentStage, rhiAuxBuffer);
2029 bindings.addImageLoadStore(1, QRhiShaderResourceBinding::FragmentStage, rhiAuxiliaryImage->texture, 0);
2032 clearSrb = rhiCtxD->srb(bindings);
2034 renderer.rhiQuadRenderer()->prepareQuad(rhiCtx.get(), rub);
2036 TransparentPass::prep(*ctx, data,
this, ps, shaderFeatures, oitRenderContext->renderPassDescriptor, sortedTransparentObjects,
true);
2042 auto *ctx = renderer.contextInterface();
2043 const auto &rhiCtx = ctx->rhiContext();
2044 QSSG_ASSERT(rhiCtx->rhi()->isRecordingFrame(),
return);
2045 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
2046 if (Q_UNLIKELY(!renderTarget))
return;
2048 if (method == QSSGRenderLayer::OITMethod::WeightedBlended) {
2049 QRhiShaderResourceBindings *srb = clearSrb;
2051 cb->beginPass(renderTarget, Qt::black, {});
2052 QSSGRHICTX_STAT(rhiCtx, beginRenderPass(renderTarget));
2053 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled,
false);
2054 QSSGRhiGraphicsPipelineStatePrivate::setShaderPipeline(ps, clearPipeline.get());
2055 renderer.rhiQuadRenderer()->recordRenderQuad(rhiCtx.get(), &ps, srb, renderTarget->renderPassDescriptor(), {});
2056 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled,
true);
2058 cb->debugMarkBegin(QByteArrayLiteral(
"Quick3D render order-independent alpha"));
2059 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderPass);
2060 Q_TRACE(QSSG_renderPass_entry, QStringLiteral(
"Quick3D render order-independent alpha"));
2061 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled,
true);
2062 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled,
false);
2063 TransparentPass::render(*ctx, ps, sortedTransparentObjects);
2065 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderPass, 0, QByteArrayLiteral(
"transparent_order_independent_pass"));
2066 Q_TRACE(QSSG_renderPass_exit);
2068 QSSGRHICTX_STAT(rhiCtx, endRenderPass());
2070 }
else if (method == QSSGRenderLayer::OITMethod::LinkedList) {
2071 QRhiShaderResourceBindings *srb = clearSrb;
2073 cb->beginPass(renderTarget, Qt::transparent, {},
nullptr, rhiCtx->commonPassFlags());
2074 QSSGRHICTX_STAT(rhiCtx, beginRenderPass(renderTarget));
2075 cb->debugMarkBegin(QByteArrayLiteral(
"Quick3D render alpha"));
2076 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderPass);
2077 Q_TRACE(QSSG_renderPass_entry, QStringLiteral(
"Quick3D render alpha"));
2079 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled,
true);
2080 QSSGRhiGraphicsPipelineStatePrivate::setShaderPipeline(ps, clearPipeline.get());
2081 renderer.rhiQuadRenderer()->recordRenderQuad(rhiCtx.get(), &ps, srb, renderTarget->renderPassDescriptor(), {});
2083 TransparentPass::render(*ctx, ps, sortedTransparentObjects);
2086 QRhiResourceUpdateBatch *rub = rhiCtx->rhi()->nextResourceUpdateBatch();
2087 QRhiReadbackResult *result =
nullptr;
2090 result->pixelSize = {};
2092 result->format = QRhiTexture::UnknownFormat;
2094 result =
new QRhiReadbackResult();
2097 const auto completedFunc = [
this, oitrt, result](){
2099 const quint32 *d =
reinterpret_cast<
const quint32 *>(result->data.constData());
2100 quint32 nodeCount = *d;
2102 this->reportedNodeCount = ensureFreeNodes(nodeCount, 32u * 1024u);
2103 oitrt->completedResults.append(result);
2104 QSSG_ASSERT(oitrt->pendingResult == result,
return;);
2105 oitrt->pendingResult =
nullptr;
2108 result->completed = completedFunc;
2109#ifdef QSSG_OIT_USE_BUFFERS
2110 rub->readBackBuffer(rhiCounterBuffer, 0, 4, result);
2113 QRhiReadbackDescription rbdesc;
2115 rub->readBackTexture(rbdesc, result);
2121 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderPass, 0, QByteArrayLiteral(
"transparent_order_independent_pass"));
2122 Q_TRACE(QSSG_renderPass_exit);
2123 QSSGRHICTX_STAT(rhiCtx, endRenderPass());
2145 QSSG_ASSERT(!data.renderedCameras.isEmpty(),
return);
2147 const auto &rhiCtx = renderer.contextInterface()->rhiContext();
2148 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx.get());
2149 QSSG_ASSERT(rhiCtx->rhi()->isRecordingFrame(),
return);
2150 const auto &shaderCache = renderer.contextInterface()->shaderCache();
2152 ps = data.getPipelineState();
2153 ps.samples = rhiCtx->mainPassSampleCount();
2154 ps.viewCount = rhiCtx->mainPassViewCount();
2156 if (method == QSSGRenderLayer::OITMethod::WeightedBlended) {
2157 rhiAccumTexture = data.getRenderResult(QSSGRenderResult::Key::AccumTexture);
2158 rhiRevealageTexture = data.getRenderResult(QSSGRenderResult::Key::RevealageTexture);
2159 compositeShaderPipeline = shaderCache->getBuiltInRhiShaders().getRhiOitCompositeShader(method, ps.samples > 1 ?
true :
false, ps.viewCount);
2160 QSSGRhiShaderResourceBindingList bindings;
2162 QRhiSampler *sampler = rhiCtx->sampler({ QRhiSampler::Nearest,
2163 QRhiSampler::Nearest,
2165 QRhiSampler::ClampToEdge,
2166 QRhiSampler::ClampToEdge,
2167 QRhiSampler::ClampToEdge });
2168 bindings.addTexture(1, QRhiShaderResourceBinding::FragmentStage, rhiAccumTexture->texture, sampler);
2169 bindings.addTexture(2, QRhiShaderResourceBinding::FragmentStage, rhiRevealageTexture->texture, sampler);
2171 compositeSrb = rhiCtxD->srb(bindings);
2172 }
else if (method == QSSGRenderLayer::OITMethod::LinkedList) {
2173#ifdef QSSG_OIT_USE_BUFFERS
2174 rhiABuffer = data.getOitRenderContext().aBuffer;
2175 rhiAuxBuffer = data.getOitRenderContext().auxBuffer;
2176 compositeShaderPipeline = shaderCache->getBuiltInRhiShaders().getRhiOitCompositeShader(method, ps.samples > 1 ?
true :
false, ps.viewCount,
true);
2178 rhiABufferImage = data.getRenderResult(QSSGRenderResult::Key::ABufferImage);
2179 rhiAuxiliaryImage = data.getRenderResult(QSSGRenderResult::Key::AuxiliaryImage);
2180 compositeShaderPipeline = shaderCache->getBuiltInRhiShaders().getRhiOitCompositeShader(method, ps.samples > 1 ?
true :
false, ps.viewCount);
2184 QSSGRhiDrawCallData &dcd(rhiCtxD->drawCallData({
this, compositeShaderPipeline.get(),
nullptr,
nullptr, 0 }));
2185 QRhiBuffer *&ubuf = dcd.ubuf;
2186 const int ubufSize = 6 *
sizeof(quint32);
2188 ubuf = rhiCtx->rhi()->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, ubufSize);
2191#ifdef QSSG_OIT_USE_BUFFERS
2192 const quint32 values[6] = { 0,
2193 quint32(data.layer.oitNodeCount),
2194 quint32(ps.samples),
2196 quint32(data.layerPrepResult.textureDimensions().width()),
2197 quint32(data.layerPrepResult.textureDimensions().height())
2200 const quint32 sizeWithLayers = rhiABufferImage->texture->pixelSize().width();
2201 const quint32 values[6] = { sizeWithLayers,
2202 sizeWithLayers * sizeWithLayers,
2203 quint32(ps.samples),
2205 quint32(data.layerPrepResult.textureDimensions().width()),
2206 quint32(data.layerPrepResult.textureDimensions().height())
2209 QRhiResourceUpdateBatch *rub = rhiCtx->rhi()->nextResourceUpdateBatch();
2210 rub->updateDynamicBuffer(ubuf, 0, ubufSize, values);
2211 renderer.rhiQuadRenderer()->prepareQuad(rhiCtx.get(), rub);
2213 QSSGRhiShaderResourceBindingList bindings;
2215 bindings.addUniformBuffer(0, QRhiShaderResourceBinding::FragmentStage, ubuf);
2216#ifdef QSSG_OIT_USE_BUFFERS
2217 bindings.addStorageBufferLoad(1, QRhiShaderResourceBinding::FragmentStage, rhiABuffer);
2218 bindings.addStorageBufferLoad(2, QRhiShaderResourceBinding::FragmentStage, rhiAuxBuffer);
2220 bindings.addImageLoad(1, QRhiShaderResourceBinding::FragmentStage, rhiABufferImage->texture, 0);
2221 bindings.addImageLoad(2, QRhiShaderResourceBinding::FragmentStage, rhiAuxiliaryImage->texture, 0);
2223 QRhiSampler *overflowSampler = rhiCtx->sampler({ QRhiSampler::Nearest,
2224 QRhiSampler::Nearest,
2226 QRhiSampler::ClampToEdge,
2227 QRhiSampler::ClampToEdge,
2228 QRhiSampler::ClampToEdge });
2229 bindings.addTexture(3, QRhiShaderResourceBinding::FragmentStage,
rhiOverflowTexture, overflowSampler);
2231 compositeSrb = rhiCtxD->srb(bindings);
2384 QSSGRenderUserPass *passNode,
2385 QSSGRhiRenderableTextureV2Ptr renderableTexture,
2389 const bool isTopLevelPass = (parentUserPassData ==
nullptr);
2391 QSSGRenderCamera *camera = data.renderedCameras[0];
2392 const auto &rhiCtx = renderer.contextInterface()->rhiContext();
2394 const QSize targetSize = data.layerPrepResult.textureDimensions();
2396 static const auto needsRebuild = [](QRhiTexture *texture,
const QSize &size, QRhiTexture::Format format) {
2397 return !texture || texture->pixelSize() != size || texture->format() != format;
2400 qCDebug(lcUserRenderPass,
"renderPrep in UserRenderPass");
2402 const QSSGResourceId currentPassId = QSSGRenderGraphObjectUtils::getResourceId(*passNode);
2403 if (visitedPasses.find(currentPassId) != visitedPasses.end()) {
2404 qWarning(
"UserRenderPass: Circular dependency detected in SubRenderPass chain. Ignoring pass.");
2409 if (visitedPasses.size() >= MAX_SUBPASS_DEPTH) {
2410 qWarning(
"UserRenderPass: Maximum SubRenderPass nesting depth (%zu) exceeded. Ignoring pass.", MAX_SUBPASS_DEPTH);
2414 visitedPasses.insert(currentPassId);
2418 currentPassData.clearColor = passNode->clearColor;
2419 currentPassData.depthStencilClearValue = passNode->depthStencilClearValue;
2421 renderableTexture = currentPassData.renderableTexture = data.requestUserRenderPassManager()->getOrCreateRenderableTexture(*passNode);
2423 currentPassData.renderableTexture = renderableTexture;
2425 QSSGRenderableObjectList &renderables = currentPassData.renderables;
2426 QSSGRhiGraphicsPipelineState &ps = currentPassData.ps;
2427 const auto &renderTarget = currentPassData.renderableTexture;
2430 ps = data.getPipelineState();
2431 const auto origin = data.m_currentOrigin;
2432 adjustOriginForOffscreenRender(ps, data);
2433 const auto cleanup = qScopeGuard([&data, origin] { data.m_currentOrigin = origin; });
2435 bool renderablesFiltered =
false;
2437 bool needsDepthStencilRenderBuffer =
false;
2438 QSSGAllocateTexturePtr depthTextureAllocCommand;
2440 QVarLengthArray<QSSGColorAttachment *, 16> colorAttachments;
2441 QVarLengthArray<QSSGResourceId, 4> subPassIds;
2444 for (
const QSSGCommand *theCommand : std::as_const(passNode->commands)) {
2447 qCDebug(lcUserRenderPass) <<
"Exec. command: >" << theCommand->typeAsString() <<
"--" << theCommand->debugString();
2449 switch (theCommand->m_type) {
2450 case CommandType::ColorAttachment:
2452 const QSSGColorAttachment *colorAttachCmd =
static_cast<
const QSSGColorAttachment *>(theCommand);
2453 colorAttachments.push_back(
const_cast<QSSGColorAttachment *>(colorAttachCmd));
2456 case CommandType::DepthTextureAttachment:
2458 QSSG_ASSERT(depthTextureAllocCommand ==
nullptr,
break);
2459 const QSSGDepthTextureAttachment *depthAttachCmd =
static_cast<
const QSSGDepthTextureAttachment *>(theCommand);
2460 needsDepthStencilRenderBuffer =
false;
2461 depthTextureAllocCommand = depthAttachCmd->m_textureCmd;
2464 case CommandType::AddShaderDefine:
2466 const auto *defineCmd =
static_cast<
const QSSGAddShaderDefine *>(theCommand);
2467 const auto &defineName = defineCmd->m_name;
2468 if (defineName.size() > 0) {
2469 QByteArray value = QByteArray::number(defineCmd->m_value);
2470 currentPassData.shaderDefines.push_back({ defineName, value });
2474 case CommandType::RenderablesFilter:
2476 auto filterCommand =
static_cast<
const QSSGRenderablesFilterCommand *>(theCommand);
2480 enum RenderableType : quint8 {
2486 if (filterCommand->renderableTypes & RenderableType::Opaque)
2487 renderables = data.getSortedOpaqueRenderableObjects(*camera, 0, filterCommand->layerMask);
2488 if (filterCommand->renderableTypes & RenderableType::Transparent)
2489 renderables += data.getSortedTransparentRenderableObjects(*camera, 0, filterCommand->layerMask);
2493 renderablesFiltered =
true;
2497 case CommandType::PipelineStateOverride:
2499 auto pipelineCommand =
static_cast<
const QSSGPipelineStateOverrideCommand *>(theCommand);
2500 if (pipelineCommand->m_depthTestEnabled)
2501 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled, *pipelineCommand->m_depthTestEnabled);
2502 if (pipelineCommand->m_depthWriteEnabled)
2503 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled, *pipelineCommand->m_depthWriteEnabled);
2504 if (pipelineCommand->m_blendEnabled)
2505 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled, *pipelineCommand->m_blendEnabled);
2506 if (pipelineCommand->m_usesStencilReference)
2507 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::UsesStencilRef, *pipelineCommand->m_usesStencilReference);
2508 if (pipelineCommand->m_usesScissor)
2509 ps.flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::UsesScissor, *pipelineCommand->m_usesScissor);
2510 if (pipelineCommand->m_depthFunction)
2511 ps.depthFunc = *pipelineCommand->m_depthFunction;
2512 if (pipelineCommand->m_cullMode) {
2513 ps.cullMode = *pipelineCommand->m_cullMode;
2514 ps.userSetCullMode =
true;
2516 if (pipelineCommand->m_polygonMode)
2517 ps.polygonMode = *pipelineCommand->m_polygonMode;
2518 if (pipelineCommand->m_stencilOpFrontState)
2519 ps.stencilOpFrontState = *pipelineCommand->m_stencilOpFrontState;
2520 if (pipelineCommand->m_stencilWriteMask)
2521 ps.stencilWriteMask = *pipelineCommand->m_stencilWriteMask;
2522 if (pipelineCommand->m_stencilReference)
2523 ps.stencilRef = *pipelineCommand->m_stencilReference;
2524 if (pipelineCommand->m_viewport)
2525 ps.viewport = *pipelineCommand->m_viewport;
2526 if (pipelineCommand->m_scissor)
2527 ps.scissor = *pipelineCommand->m_scissor;
2528 if (pipelineCommand->m_targetBlend0)
2529 ps.targetBlend[0] = *pipelineCommand->m_targetBlend0;
2530 if (pipelineCommand->m_targetBlend1)
2531 ps.targetBlend[1] = *pipelineCommand->m_targetBlend1;
2532 if (pipelineCommand->m_targetBlend2)
2533 ps.targetBlend[2] = *pipelineCommand->m_targetBlend2;
2534 if (pipelineCommand->m_targetBlend3)
2535 ps.targetBlend[3] = *pipelineCommand->m_targetBlend3;
2536 if (pipelineCommand->m_targetBlend4)
2537 ps.targetBlend[4] = *pipelineCommand->m_targetBlend4;
2538 if (pipelineCommand->m_targetBlend5)
2539 ps.targetBlend[5] = *pipelineCommand->m_targetBlend5;
2540 if (pipelineCommand->m_targetBlend6)
2541 ps.targetBlend[6] = *pipelineCommand->m_targetBlend6;
2542 if (pipelineCommand->m_targetBlend7)
2543 ps.targetBlend[7] = *pipelineCommand->m_targetBlend7;
2546 case CommandType::DepthStencilAttachment:
2548 QSSG_ASSERT(depthTextureAllocCommand ==
nullptr,
break);
2549 needsDepthStencilRenderBuffer =
true;
2551 case CommandType::SubRenderPass:
2553 auto subPassCommand =
static_cast<
const QSSGSubRenderPass *>(theCommand);
2554 if (subPassCommand && subPassCommand->m_userPassId != QSSGResourceId::Invalid)
2555 subPassIds.append(subPassCommand->m_userPassId);
2559 qWarning() <<
"Effect command" << theCommand->typeAsString() <<
"not implemented";
2564 if (colorAttachments.size() > 4) {
2565 colorAttachments.resize(4);
2566 qWarning() <<
"UserRenderPass supports up to 4 color attachments only.";
2571 if (isTopLevelPass) {
2573 bool needsBuild = !renderTarget->isValid();
2575 const qsizetype oldAttachmentCount = renderTarget->colorAttachmentCount();
2578 const qsizetype wantedAttachmentCount = qMax<qsizetype>(colorAttachments.size(), 1);
2580 if (oldAttachmentCount != wantedAttachmentCount)
2587 if (renderTarget->getRenderTarget() && renderTarget->getRenderTarget()->flags() != passNode->renderTargetFlags)
2594 for (
int i = 0; i != oldAttachmentCount; ++i) {
2595 QRhiTexture::Format expectedFormat = QRhiTexture::RGBA8;
2596 if (i < colorAttachments.size()) {
2597 const auto &colorAttachment = colorAttachments.at(i);
2598 QSSG_ASSERT(colorAttachment !=
nullptr,
continue);
2599 expectedFormat = QSSGBufferManager::toRhiFormat(colorAttachment->format());
2601 const auto &texture = renderTarget->getColorTexture(i);
2602 needsBuild = needsBuild || needsRebuild(texture.texture(), targetSize, expectedFormat);
2606 if (needsDepthStencilRenderBuffer != (renderTarget->getDepthStencil() !=
nullptr))
2610 if (depthTextureAllocCommand) {
2611 const auto format = QSSGBufferManager::toRhiFormat(depthTextureAllocCommand->format());
2612 const auto &depthTexture = renderTarget->getDepthTexture();
2613 needsBuild = !depthTexture.isValid() || needsRebuild(depthTexture.texture(), targetSize, format);
2615 if (renderTarget->getDepthTexture().isValid())
2621 const auto &rt = renderTarget->getRenderTarget();
2622 if (rt && rt->flags() != passNode->renderTargetFlags)
2628 renderTarget->reset(&QSSGRhiContextPrivate::get(rhiCtx.get())->resourceRegistry());
2630 QRhiTextureRenderTargetDescription rtDesc;
2633 const qsizetype colorAttachmentCount = wantedAttachmentCount;
2635 bool createSucceeded =
true;
2636 bool colorAllocatorsNeedsUpdate =
false;
2640 QVarLengthArray<QRhiTexture *, 4> textures;
2641 for (qsizetype i = 0; i < colorAttachmentCount && createSucceeded ; ++i) {
2642 if (i >= colorAttachments.size()) {
2644 auto *tex = rhiCtx->rhi()->newTexture(QRhiTexture::RGBA8, targetSize, ps.samples, QRhiTexture::RenderTarget);
2645 tex->setName(QByteArrayLiteral(
"Default color attachment"));
2646 createSucceeded = createSucceeded && tex->create();
2647 textures.push_back(tex);
2650 const auto &colorAttCmd = colorAttachments.at(i);
2651 const auto &name = colorAttCmd->m_name;
2652 const auto format = QSSGBufferManager::toRhiFormat(colorAttCmd->format());
2653 const auto &allocateTexCmd = colorAttCmd->m_textureCmd;
2654 const auto &existingTexture = allocateTexCmd->texture();
2655 if (existingTexture.isValid() && !needsRebuild(existingTexture.texture(), targetSize, format)) {
2658 textures.push_back(existingTexture.texture());
2660 auto *tex = rhiCtx->rhi()->newTexture(format, targetSize, ps.samples, QRhiTexture::RenderTarget);
2662 createSucceeded = createSucceeded && tex->create();
2663 textures.push_back(tex);
2667 colorAllocatorsNeedsUpdate =
true;
2671 rtDesc.setColorAttachments(textures.cbegin(), textures.cend());
2674 if (needsDepthStencilRenderBuffer) {
2675 auto renderBuffer = rhiCtx->rhi()->newRenderBuffer(QRhiRenderBuffer::DepthStencil, targetSize, ps.samples);
2676 if (renderBuffer->create())
2677 rtDesc.setDepthStencilBuffer(renderBuffer);
2678 }
else if (depthTextureAllocCommand) {
2679 const auto format = QSSGBufferManager::toRhiFormat(depthTextureAllocCommand->format());
2680 const auto &existingDepthTexture = depthTextureAllocCommand->texture();
2681 if (existingDepthTexture.isValid() && !needsRebuild(existingDepthTexture.texture(), targetSize, format)) {
2682 rtDesc.setDepthTexture(existingDepthTexture.texture());
2685 QRhiTexture *depthTex = rhiCtx->rhi()->newTexture(format, targetSize, ps.samples, QRhiTexture::RenderTarget);
2686 if (depthTex->create())
2687 rtDesc.setDepthTexture(depthTex);
2691 if (createSucceeded) {
2693 renderTarget->setDescription(*rhiCtx,
std::move(rtDesc), passNode->renderTargetFlags);
2698 if (colorAllocatorsNeedsUpdate) {
2699 for (qsizetype i = 0; i < colorAttachments.size(); ++i) {
2700 const auto &colorAttCmd = colorAttachments.at(i);
2701 const auto &allocateTexCmd = colorAttCmd->m_textureCmd;
2702 allocateTexCmd->setTexture(renderTarget->getColorTexture(i));
2706 if (depthTextureAllocCommand)
2707 depthTextureAllocCommand->setTexture(renderTarget->getDepthTexture());
2710 renderTarget->resetRenderTarget();
2711 qWarning() <<
"Failed to create textures for UserRenderPass";
2717 Q_ASSERT(renderTarget->isValid());
2719 ps.colorAttachmentCount =
int(renderTarget->colorAttachmentCount());
2722 for (
const auto &subPassId : std::as_const(subPassIds)) {
2723 QSSGRenderUserPass *userPassNode = QSSGRenderGraphObjectUtils::getResource<QSSGRenderUserPass>(subPassId);
2724 QSSG_ASSERT(userPassNode && userPassNode->type == QSSGRenderGraphObject::Type::RenderPass,
continue);
2725 prepareSubPass(renderer, data, userPassNode, currentPassData.renderableTexture, ¤tPassData, key);
2728 if (passNode->passMode == QSSGRenderUserPass::PassModes::UserPass) {
2730 if (!renderablesFiltered && renderables.isEmpty())
2731 renderables = data.getSortedOpaqueRenderableObjects(*camera);
2733 if (passNode->materialMode == QSSGRenderUserPass::MaterialModes::AugmentMaterial) {
2737 QSSG_ASSERT(shaderAugmentation.outputs.size() == 0, shaderAugmentation.outputs.clear());
2738 shaderAugmentation.defines =
std::move(currentPassData.shaderDefines);
2740 for (
int i = 0, end = colorAttachments.size(); i < end; ++i) {
2741 const auto &colorAttCmd = colorAttachments.at(i);
2742 const auto &name = colorAttCmd->m_name;
2743 if (name.size() > 0)
2744 shaderAugmentation.outputs.push_back(name);
2746 shaderAugmentation.outputs.push_back(getDefaultOutputName(size_t(i)));
2749 QSSGShaderFeatures shaderFeatures = data.getShaderFeatures();
2750 shaderFeatures.disableTonemapping();
2752 currentPassData.index = RenderHelpers::rhiPrepareAugmentedUserPass(&(*rhiCtx), key, ps, renderTarget->getRenderPassDescriptor().get(), shaderAugmentation, data, renderables, shaderFeatures);
2753 }
else if (passNode->materialMode == QSSGRenderUserPass::MaterialModes::OverrideMaterial) {
2755 QSSGShaderFeatures shaderFeatures = data.getShaderFeatures();
2756 shaderFeatures.disableTonemapping();
2758 currentPassData.index = RenderHelpers::rhiPrepareOverrideMaterialUserPass(&(*rhiCtx), key, ps, renderTarget->getRenderPassDescriptor().get(), passNode->overrideMaterial, data, renderables, shaderFeatures);
2762 QSSGShaderFeatures shaderFeatures = data.getShaderFeatures();
2763 shaderFeatures.disableTonemapping();
2764 currentPassData.index = RenderHelpers::rhiPrepareOriginalMaterialUserPass(&(*rhiCtx), key, ps, renderTarget->getRenderPassDescriptor().get(), data, renderables, shaderFeatures);
2767 userPassData.push_back(currentPassData);
2769 parentUserPassData->subPassData.push_back(currentPassData);
2772 if (passNode->passMode == QSSGRenderUserPass::PassModes::SkyboxPass) {
2773 if (rhiCtx->rhi()->isFeatureSupported(QRhi::TexelFetch)) {
2774 if (data.layer.background == QSSGRenderLayer::Background::SkyBoxCubeMap && data.layer.skyBoxCubeMap) {
2775 if (!currentPassData.skyboxCubeMapPass)
2778 currentPassData.skyboxCubeMapPass->skipTonemapping =
true;
2779 currentPassData.skyboxCubeMapPass->renderPrep(renderer, data);
2780 currentPassData.skyboxCubeMapPass->ps.samples = ps.samples;
2781 currentPassData.skyboxCubeMapPass->rpDesc = renderTarget->getRenderPassDescriptor().get();
2783 currentPassData.skyboxPass =
std::nullopt;
2784 }
else if ((data.layer.background == QSSGRenderLayer::Background::SkyBox && data.layer.lightProbe)
2785 || (data.layer.background == QSSGRenderLayer::Background::SkyMaterial && data.layer.skyMaterial)) {
2786 if (!currentPassData.skyboxPass)
2789 currentPassData.skyboxPass->skipTonemapping =
true;
2790 currentPassData.skyboxPass->renderPrep(renderer, data);
2791 currentPassData.skyboxPass->ps.samples = ps.samples;
2792 currentPassData.skyboxPass->rpDesc = renderTarget->getRenderPassDescriptor().get();
2794 currentPassData.skyboxCubeMapPass =
std::nullopt;
2797 userPassData.push_back(currentPassData);
2799 parentUserPassData->subPassData.push_back(currentPassData);
2801 }
else if (passNode->passMode == QSSGRenderUserPass::PassModes::Item2DPass) {
2802 if (!currentPassData.item2DPass)
2804 const bool hasItem2Ds = (data.item2DsView.size() > 0);
2807 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(renderer.contextInterface()->rhiContext().get());
2808 QRhiRenderTarget *prevRenderTarget = rhiCtx->renderTarget();
2809 rhiCtxD->setRenderTarget(renderTarget->getRenderTarget().get());
2810 currentPassData.item2DPass->renderPrep(renderer, data);
2812 rhiCtxD->setRenderTarget(prevRenderTarget);
2814 userPassData.push_back(currentPassData);
2816 parentUserPassData->subPassData.push_back(currentPassData);