From 5ea58256f85792b131ee56b3b771190ecd4cbd84 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Tue, 24 Sep 2024 09:40:34 +0800 Subject: [PATCH] fix ui per-pass descriptor set (#17663) --- .../pipeline/custom/NativeExecutor.cpp | 17 +++++++++++++++ .../custom/NativeExecutorDescriptor.cpp | 21 ++++++++++++++++--- .../custom/NativeExecutorRenderGraph.h | 2 ++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index df4f4e8069a..d99e91df292 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -412,6 +412,15 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { get<0>(iter->second)); } } + void tryBindUIOverwritePerPassDescriptorSet(RenderGraph::vertex_descriptor sceneID) const { + auto iter = ctx.uiDescriptorSet.find(sceneID); + if (iter != ctx.uiDescriptorSet.end()) { + CC_EXPECTS(iter->second); + ctx.cmdBuff->bindDescriptorSet( + static_cast(pipeline::SetIndex::GLOBAL), + iter->second); + } + } void begin(const RasterPass& pass, RenderGraph::vertex_descriptor vertID) const { const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID); if (!renderData.custom.empty()) { @@ -692,6 +701,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { if (queueData.passLayoutID != LayoutGraphData::null_vertex()) { const auto phaseLayoutID = locate(queueData.passLayoutID, "default", ctx.lg); if (phaseLayoutID != LayoutGraphData::null_vertex()) { + tryBindUIOverwritePerPassDescriptorSet(sceneID); submitUICommands(ctx.currentPass, phaseLayoutID, camera, ctx.cmdBuff); } } else { @@ -704,6 +714,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { CC_ENSURES(passLayoutID != LayoutGraphData::null_vertex()); const auto phaseLayoutID = locate(passLayoutID, "default", ctx.lg); if (phaseLayoutID != LayoutGraphData::null_vertex()) { + tryBindUIOverwritePerPassDescriptorSet(sceneID); submitUICommands(ctx.currentPass, phaseLayoutID, camera, ctx.cmdBuff); } } else { // Subpass @@ -721,6 +732,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { CC_ENSURES(subpassLayoutID != LayoutGraphData::null_vertex()); const auto phaseLayoutID = locate(subpassLayoutID, "default", ctx.lg); if (phaseLayoutID != LayoutGraphData::null_vertex()) { + tryBindUIOverwritePerPassDescriptorSet(sceneID); submitUICommands(ctx.currentPass, phaseLayoutID, camera, ctx.cmdBuff); } } @@ -1320,6 +1332,10 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) { std::tuple> renderGraphDescriptorSet(scratch); + ccstd::pmr::unordered_map< + RenderGraph::vertex_descriptor, gfx::DescriptorSet*> + uiDescriptorSet(scratch); + ccstd::pmr::unordered_map< RenderGraph::vertex_descriptor, gfx::DescriptorSet*> @@ -1340,6 +1356,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) { &ppl, perPassResourceIndex, renderGraphDescriptorSet, + uiDescriptorSet, profilerPerPassDescriptorSets, perInstanceDescriptorSets, programLibrary, diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutorDescriptor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutorDescriptor.cpp index e7825d37228..76cb194fe85 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutorDescriptor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutorDescriptor.cpp @@ -79,7 +79,7 @@ void updateCpuUniformBuffer( CC_EXPECTS(sizeof(Mat4) == typeSize); const Mat4 id{}; for (uint32_t i = 0; i != value.count; ++i) { - memcpy(buffer.data() + offset + i * typeSize, id.m, typeSize); + memcpy(buffer.data() + offset + (i * typeSize), id.m, typeSize); } } } @@ -418,7 +418,6 @@ gfx::DescriptorSet* updatePerPassDescriptorSet( CC_ENSURES(prevBuffer); newSet->bindBuffer(bindID, prevBuffer); } - auto name = lg.valueNames[d.descriptorID.value]; bindID += d.count; } break; @@ -486,7 +485,7 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> { const auto queueID = parent(leafNodeID, ctx.g); const auto passOrSubpassID = parent(queueID, ctx.g); const auto passID = parent(passOrSubpassID, ctx.g); - + LayoutGraphData::vertex_descriptor parentPassLayoutID = LayoutGraphData::null_vertex(); if (passID == RenderGraph::null_vertex()) { const auto& passLayoutName = get(RenderGraph::LayoutTag{}, ctx.g, passOrSubpassID); const auto passLayoutID = locate( @@ -495,6 +494,7 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> { passLayoutID, ctx, leafNodeID); if (perPassSet) { get<0>(ctx.renderGraphDescriptorSet[leafNodeID]) = perPassSet; + parentPassLayoutID = passLayoutID; } } else { const auto subpassID = passOrSubpassID; @@ -512,6 +512,21 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> { subpassLayoutID, ctx, leafNodeID); if (perPassSet) { get<0>(ctx.renderGraphDescriptorSet[leafNodeID]) = perPassSet; + parentPassLayoutID = subpassLayoutID; + } + } + if (holds(leafNodeID, ctx.g)) { + const auto& sceneData = get(SceneTag{}, leafNodeID, ctx.g); + if (any(sceneData.flags & SceneFlags::UI)) { + const auto passLayoutID = locate(LayoutGraphData::null_vertex(), "default", ctx.lg); + CC_EXPECTS(passLayoutID != LayoutGraphData::null_vertex()); + if (passLayoutID != parentPassLayoutID) { + auto* perPassSet = updateCameraUniformBufferAndDescriptorSet( + passLayoutID, ctx, leafNodeID); + if (perPassSet) { + ctx.uiDescriptorSet[leafNodeID] = perPassSet; + } + } } } } diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutorRenderGraph.h b/native/cocos/renderer/pipeline/custom/NativeExecutorRenderGraph.h index d9cc17e0b0b..da083bfd540 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutorRenderGraph.h +++ b/native/cocos/renderer/pipeline/custom/NativeExecutorRenderGraph.h @@ -63,6 +63,8 @@ struct RenderGraphVisitorContext { ccstd::pmr::unordered_map< RenderGraph::vertex_descriptor, std::tuple>& renderGraphDescriptorSet; + ccstd::pmr::unordered_map< + RenderGraph::vertex_descriptor, gfx::DescriptorSet*>& uiDescriptorSet; ccstd::pmr::unordered_map< RenderGraph::vertex_descriptor, gfx::DescriptorSet*>& profilerPerPassDescriptorSets;