diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index 7345252328e..bd7e0d873be 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -289,6 +289,8 @@ uint32_t addDepthStencilImpl( if (swapchain) { CC_EXPECTS(residency == ResourceResidency::BACKBUFFER); CC_EXPECTS(ppl.defaultFramebufferHasDepthStencil); + RenderSwapchain sc{swapchain, true}; + sc.texture = RenderSwapchain::getDepthStencilTexture(swapchain); resID = addVertex( SwapchainTag{}, std::forward_as_tuple(name.c_str()), @@ -296,7 +298,7 @@ uint32_t addDepthStencilImpl( std::forward_as_tuple(ResourceTraits{residency}), std::forward_as_tuple(), std::forward_as_tuple(samplerInfo), - std::forward_as_tuple(RenderSwapchain{swapchain, true}), + std::forward_as_tuple(sc), ppl.resourceGraph); } else { CC_EXPECTS(residency == ResourceResidency::MANAGED || residency == ResourceResidency::MEMORYLESS); @@ -378,6 +380,9 @@ uint32_t NativePipeline::addRenderWindow( sc.renderWindow = renderWindow; CC_ENSURES(!sc.isDepthStencil); + sc.texture = RenderSwapchain::getColorTexture(renderWindow); + CC_ENSURES(sc.texture); + CC_ENSURES(desc.format != gfx::Format::UNKNOWN); return addVertex( SwapchainTag{}, @@ -396,6 +401,10 @@ uint32_t NativePipeline::addRenderWindow( desc.format = renderWindow->getFramebuffer()->getColorTextures()[0]->getFormat(); CC_ENSURES(desc.format != gfx::Format::UNKNOWN); + RenderSwapchain sc{renderWindow->getSwapchain(), false}; + sc.texture = RenderSwapchain::getColorTexture(renderWindow->getSwapchain()); + CC_ENSURES(sc.texture); + return addVertex( SwapchainTag{}, std::forward_as_tuple(name.c_str()), @@ -403,7 +412,7 @@ uint32_t NativePipeline::addRenderWindow( std::forward_as_tuple(ResourceTraits{ResourceResidency::BACKBUFFER}), std::forward_as_tuple(), std::forward_as_tuple(), - std::forward_as_tuple(RenderSwapchain{renderWindow->getSwapchain(), false}), + std::forward_as_tuple(sc), resourceGraph); } diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index 46b93f19c34..b718dc7d4e0 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -36,6 +36,29 @@ namespace cc { namespace render { +gfx::Texture* RenderSwapchain::getColorTexture(gfx::Swapchain* swapchain) noexcept { + CC_EXPECTS(swapchain); + gfx::Texture* texture = swapchain->getColorTexture(); + CC_ENSURES(texture); + return texture; +} + +gfx::Texture* RenderSwapchain::getColorTexture(scene::RenderWindow* renderWindow) noexcept { + const auto& fb = renderWindow->getFramebuffer(); + CC_EXPECTS(fb); + CC_EXPECTS(fb->getColorTextures().size() == 1); + gfx::Texture* texture = fb->getColorTextures()[0]; + CC_ENSURES(texture); + return texture; +} + +gfx::Texture* RenderSwapchain::getDepthStencilTexture(gfx::Swapchain* swapchain) noexcept { + CC_EXPECTS(swapchain); + gfx::Texture* texture = swapchain->getDepthStencilTexture(); + CC_ENSURES(texture); + return texture; +} + ResourceGroup::~ResourceGroup() noexcept { for (const auto& buffer : instancingBuffers) { buffer->clear(); @@ -398,23 +421,7 @@ gfx::Texture* ResourceGraph::getTexture(vertex_descriptor resID) { return fb->getColorTextures()[0]; }, [](const RenderSwapchain& sc) -> gfx::Texture* { - gfx::Texture* texture1 = nullptr; - if (sc.swapchain) { - if (sc.isDepthStencil) { - texture1 = sc.swapchain->getDepthStencilTexture(); - } else { - texture1 = sc.swapchain->getColorTexture(); - } - } else { - CC_EXPECTS(sc.renderWindow); - CC_EXPECTS(!sc.isDepthStencil); - const auto& fb = sc.renderWindow->getFramebuffer(); - CC_EXPECTS(fb); - CC_EXPECTS(fb->getColorTextures().size() == 1); - CC_EXPECTS(fb->getColorTextures().at(0)); - texture1 = fb->getColorTextures()[0]; - } - return texture1; + return sc.texture; }, [](const FormatView& view) -> gfx::Texture* { // TODO(zhouzhenglong): add ImageView support diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h index 524b5ad0367..de261f316e8 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h @@ -192,12 +192,17 @@ struct RenderSwapchain { : swapchain(swapchainIn), isDepthStencil(isDepthStencilIn) {} + static gfx::Texture* getColorTexture(gfx::Swapchain* swapchain) noexcept; + static gfx::Texture* getColorTexture(scene::RenderWindow* renderWindow) noexcept; + static gfx::Texture* getDepthStencilTexture(gfx::Swapchain* swapchain) noexcept; + gfx::Swapchain* swapchain{nullptr}; scene::RenderWindow* renderWindow{nullptr}; uint32_t currentID{0}; uint32_t numBackBuffers{0}; uint32_t generation{0xFFFFFFFF}; bool isDepthStencil{false}; + gfx::Texture* texture{nullptr}; }; struct ResourceStates {