Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix native viewport #17871

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion native/cocos/renderer/pipeline/custom/NativeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
}
// scissor
gfx::Rect scissor{vp.left, vp.top, vp.width, vp.height};
// Do not across framebuffer boundary, otherwise vulkan will be device lost.
scissor.x = std::max(scissor.x, 0);
scissor.y = std::max(scissor.y, 0);
scissor.width = std::min(scissor.width, pass.width - scissor.x);
scissor.height = std::min(scissor.height, pass.height - scissor.y);

// render pass
{
Expand All @@ -455,6 +460,12 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
ctx.currentPass = data.renderPass.get();
}

// Set viewport
{
ctx.cmdBuff->setViewport(vp);
ctx.viewportStack.emplace_back(vp);
}

// PerPass DescriptorSet
tryBindPassDescriptorSet(vertID);
}
Expand All @@ -477,7 +488,6 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
if (subpass.subpassID) {
ctx.cmdBuff->nextSubpass();
}
// ctx.cmdBuff->setViewport(subpass);
tryBindPassDescriptorSet(vertID);
ctx.subpassIndex = subpass.subpassID;
// noop
Expand Down Expand Up @@ -663,8 +673,12 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
return;
}
}

if (queue.viewport.width != 0 && queue.viewport.height != 0) {
ctx.cmdBuff->setViewport(queue.viewport);
ctx.viewportStack.emplace_back(queue.viewport);
} else {
ctx.viewportStack.emplace_back();
}

tryBindQueueDescriptorSets(vertID);
Expand Down Expand Up @@ -807,6 +821,8 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
void begin(const gfx::Viewport& pass, RenderGraph::vertex_descriptor vertID) const {
}
void end(const RasterPass& pass, RenderGraph::vertex_descriptor vertID) const {
CC_EXPECTS(ctx.viewportStack.size() == 1);

const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
if (!renderData.custom.empty()) {
const auto& passes = ctx.ppl->custom.renderPasses;
Expand All @@ -822,6 +838,8 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
}
ctx.cmdBuff->endRenderPass();
ctx.currentPass = nullptr;
ctx.viewportStack.pop_back();
CC_ENSURES(ctx.viewportStack.empty());
}
void end(const RasterSubpass& subpass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static)
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
Expand Down Expand Up @@ -891,6 +909,20 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
return;
}
}

// Revert viewport
CC_EXPECTS(ctx.viewportStack.size() > 1);
if (ctx.viewportStack.back()) {
for (size_t i = ctx.viewportStack.size() - 1; i-- > 0;) {
const auto& vp = ctx.viewportStack[i];
if (vp) {
ctx.cmdBuff->setViewport(*vp);
break;
}
}
}
ctx.viewportStack.pop_back();

#if CC_DEBUG
ctx.cmdBuff->endMarker();
#endif
Expand Down Expand Up @@ -1346,6 +1378,9 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
gfx::DescriptorSet*>
perInstanceDescriptorSets(scratch);

ccstd::pmr::vector<ccstd::optional<gfx::Viewport>> viewportStack(scratch);
viewportStack.reserve(4);

// submit commands
RenderGraphVisitorContext ctx{
ppl.nativeContext,
Expand All @@ -1360,6 +1395,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
profilerPerPassDescriptorSets,
perInstanceDescriptorSets,
programLibrary,
viewportStack,
CustomRenderGraphContext{
custom.currentContext,
&rg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct RenderGraphVisitorContext {
RenderGraph::vertex_descriptor,
gfx::DescriptorSet*>& perInstanceDescriptorSets;
ProgramLibrary* programLib = nullptr;
ccstd::pmr::vector<ccstd::optional<gfx::Viewport>>& viewportStack;
CustomRenderGraphContext customContext;
boost::container::pmr::memory_resource* scratch = nullptr;
gfx::RenderPass* currentPass = nullptr;
Expand Down
Loading