From 5456aba9910014dab23f8036939bdb76c2374997 Mon Sep 17 00:00:00 2001 From: Zhou Zhenglong Date: Tue, 24 Oct 2023 17:03:20 +0800 Subject: [PATCH 1/2] fix render window bug # Conflicts: # native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp # native/cocos/renderer/pipeline/custom/NativePipeline.cpp --- .../pipeline/custom/NativePipeline.cpp | 35 ++++++++++++++----- .../pipeline/custom/NativeResourceGraph.cpp | 25 ++++++++++--- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index dfb1d5e91b1..43db5a99a39 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -127,14 +127,16 @@ uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format if (!renderWindow->getSwapchain()) { CC_ASSERT(renderWindow->getFramebuffer()->getColorTextures().size() == 1); CC_ASSERT(renderWindow->getFramebuffer()->getColorTextures().at(0)); + 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); } @@ -364,22 +366,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 20709a6f97f..442d8f34b27 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -29,6 +29,7 @@ #include "details/Range.h" #include "gfx-base/GFXDef-common.h" #include "pipeline/custom/RenderCommonFwd.h" +#include "cocos/scene/RenderWindow.h" namespace cc { @@ -172,6 +173,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(); @@ -217,12 +221,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; @@ -339,12 +345,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 From fafb9aa7ecddf09cbba4e6330638733fc494dc2d Mon Sep 17 00:00:00 2001 From: Zhou Zhenglong Date: Wed, 25 Oct 2023 15:10:11 +0800 Subject: [PATCH 2/2] fix v3.8.0 --- native/cocos/renderer/pipeline/custom/NativeExecutor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index c044f4204a3..e38f90dbf31 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -227,7 +227,12 @@ PersistentRenderPassAndFramebuffer createPersistentRenderPassAndFramebuffer( // data.framebuffer = fb; }, [&](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