diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index 040539105b7..cc07948872f 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -57,6 +57,7 @@ #include "pipeline/custom/RenderCommonFwd.h" #include "pipeline/custom/RenderGraphTypes.h" #include "pipeline/custom/details/GslUtils.h" +#include "cocos/scene/RenderWindow.h" #ifndef BRANCH_CULLING #define BRANCH_CULLING 0 @@ -327,7 +328,12 @@ RenderingInfo FrameGraphDispatcher::getRenderPassAndFrameBuffer(RenderGraph::ver fbInfo.colorTextures.emplace_back(fb->getColorTextures().at(0)); }, [&](const RenderSwapchain &sc) { - fbInfo.colorTextures.emplace_back(sc.swapchain->getColorTexture()); + if (sc.swapchain) { + fbInfo.colorTextures.emplace_back(sc.swapchain->getColorTexture()); + } else { + CC_EXPECTS(sc.renderWindow); + fbInfo.colorTextures.emplace_back(sc.renderWindow->getFramebuffer()->getColorTextures().front()); + } }, [&](const FormatView &view) { // TODO(zhouzhenglong): add ImageView support diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index 004765b67e4..b54503e0601 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -190,14 +190,16 @@ uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format CC_ASSERT(renderWindow->getFramebuffer()->getColorTextures().size() == 1); CC_ASSERT(renderWindow->getFramebuffer()->getColorTextures().at(0)); desc.sampleCount = renderWindow->getFramebuffer()->getColorTextures().at(0)->getInfo().samples; + RenderSwapchain sc{}; + sc.renderWindow = renderWindow; return addVertex( - FramebufferTag{}, + SwapchainTag{}, std::forward_as_tuple(name.c_str()), std::forward_as_tuple(desc), std::forward_as_tuple(ResourceTraits{ResourceResidency::EXTERNAL}), std::forward_as_tuple(), std::forward_as_tuple(), - std::forward_as_tuple(IntrusivePtr(renderWindow->getFramebuffer())), + std::forward_as_tuple(sc), resourceGraph); } @@ -528,22 +530,37 @@ void NativePipeline::updateRenderWindow(const ccstd::string &name, scene::Render visitObject( resID, resourceGraph, [&](IntrusivePtr &fb) { + // deprecated + CC_EXPECTS(false); CC_EXPECTS(!renderWindow->getSwapchain()); desc.width = renderWindow->getWidth(); desc.height = renderWindow->getHeight(); fb = renderWindow->getFramebuffer(); }, [&](RenderSwapchain &sc) { - CC_EXPECTS(renderWindow->getSwapchain()); auto *newSwapchain = renderWindow->getSwapchain(); - if (sc.generation != newSwapchain->getGeneration()) { - resourceGraph.invalidatePersistentRenderPassAndFramebuffer( - sc.swapchain->getColorTexture()); + const auto& oldTexture = resourceGraph.getTexture(resID); + resourceGraph.invalidatePersistentRenderPassAndFramebuffer(oldTexture); + if (newSwapchain) { + desc.width = newSwapchain->getWidth(); + desc.height = newSwapchain->getHeight(); + + sc.renderWindow = nullptr; + sc.swapchain = renderWindow->getSwapchain(); sc.generation = newSwapchain->getGeneration(); + } else { + CC_EXPECTS(renderWindow->getFramebuffer()); + CC_EXPECTS(renderWindow->getFramebuffer()->getColorTextures().size() == 1); + CC_EXPECTS(renderWindow->getFramebuffer()->getColorTextures().front()); + + const auto& texture = renderWindow->getFramebuffer()->getColorTextures().front(); + desc.width = texture->getWidth(); + desc.height = texture->getHeight(); + + sc.renderWindow = renderWindow; + sc.swapchain = nullptr; + sc.generation = 0xFFFFFFFF; } - desc.width = renderWindow->getSwapchain()->getWidth(); - desc.height = renderWindow->getSwapchain()->getHeight(); - sc.swapchain = renderWindow->getSwapchain(); }, [](const auto & /*res*/) {}); } diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index 750616d549a..e8aa1c8880b 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -31,6 +31,7 @@ #include "details/Range.h" #include "gfx-base/GFXDef-common.h" #include "pipeline/custom/RenderCommonFwd.h" +#include "cocos/scene/RenderWindow.h" namespace cc { @@ -171,6 +172,9 @@ bool ManagedTexture::checkResource(const ResourceDesc& desc) const { void ResourceGraph::validateSwapchains() { bool swapchainInvalidated = false; for (auto& sc : swapchains) { + if (!sc.swapchain) { + continue; + } if (sc.generation != sc.swapchain->getGeneration()) { swapchainInvalidated = true; sc.generation = sc.swapchain->getGeneration(); @@ -216,12 +220,14 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { std::ignore = texture; }, [&](const IntrusivePtr& fb) { + // deprecated + CC_EXPECTS(false); CC_EXPECTS(fb); std::ignore = fb; }, - [&](const RenderSwapchain& queue) { - CC_EXPECTS(queue.swapchain); - std::ignore = queue; + [&](const RenderSwapchain& window) { + CC_EXPECTS(window.swapchain || window.renderWindow); + std::ignore = window; }, [&](const FormatView& view) { // NOLINT(misc-no-recursion) std::ignore = view; @@ -348,12 +354,23 @@ gfx::Texture* ResourceGraph::getTexture(vertex_descriptor resID) { texture = tex.get(); }, [&](const IntrusivePtr& fb) { + // deprecated + CC_EXPECTS(false); CC_EXPECTS(fb->getColorTextures().size() == 1); CC_EXPECTS(fb->getColorTextures().at(0)); texture = fb->getColorTextures()[0]; }, [&](const RenderSwapchain& sc) { - texture = sc.swapchain->getColorTexture(); + if (sc.swapchain) { + texture = sc.swapchain->getColorTexture(); + } else { + CC_EXPECTS(sc.renderWindow); + const auto& fb = sc.renderWindow->getFramebuffer(); + CC_EXPECTS(fb); + CC_EXPECTS(fb->getColorTextures().size() == 1); + CC_EXPECTS(fb->getColorTextures().at(0)); + texture = fb->getColorTextures()[0]; + } }, [&](const FormatView& view) { // TODO(zhouzhenglong): add ImageView support