Skip to content

Commit

Permalink
fix render window bug
Browse files Browse the repository at this point in the history
# Conflicts:
#	native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp
  • Loading branch information
star-e committed Oct 24, 2023
1 parent e9b7fd3 commit 8695b27
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 26 additions & 9 deletions native/cocos/renderer/pipeline/custom/NativePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<gfx::Framebuffer>(renderWindow->getFramebuffer())),
std::forward_as_tuple(sc),
resourceGraph);
}

Expand Down Expand Up @@ -528,22 +530,37 @@ void NativePipeline::updateRenderWindow(const ccstd::string &name, scene::Render
visitObject(
resID, resourceGraph,
[&](IntrusivePtr<gfx::Framebuffer> &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*/) {});
}
Expand Down
25 changes: 21 additions & 4 deletions native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -216,12 +220,14 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
std::ignore = texture;
},
[&](const IntrusivePtr<gfx::Framebuffer>& 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;
Expand Down Expand Up @@ -348,12 +354,23 @@ gfx::Texture* ResourceGraph::getTexture(vertex_descriptor resID) {
texture = tex.get();
},
[&](const IntrusivePtr<gfx::Framebuffer>& 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
Expand Down

0 comments on commit 8695b27

Please sign in to comment.