Skip to content

Commit 5ea5825

Browse files
authored
fix ui per-pass descriptor set (#17663)
1 parent 684974d commit 5ea5825

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

native/cocos/renderer/pipeline/custom/NativeExecutor.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
412412
get<0>(iter->second));
413413
}
414414
}
415+
void tryBindUIOverwritePerPassDescriptorSet(RenderGraph::vertex_descriptor sceneID) const {
416+
auto iter = ctx.uiDescriptorSet.find(sceneID);
417+
if (iter != ctx.uiDescriptorSet.end()) {
418+
CC_EXPECTS(iter->second);
419+
ctx.cmdBuff->bindDescriptorSet(
420+
static_cast<uint32_t>(pipeline::SetIndex::GLOBAL),
421+
iter->second);
422+
}
423+
}
415424
void begin(const RasterPass& pass, RenderGraph::vertex_descriptor vertID) const {
416425
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
417426
if (!renderData.custom.empty()) {
@@ -692,6 +701,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
692701
if (queueData.passLayoutID != LayoutGraphData::null_vertex()) {
693702
const auto phaseLayoutID = locate(queueData.passLayoutID, "default", ctx.lg);
694703
if (phaseLayoutID != LayoutGraphData::null_vertex()) {
704+
tryBindUIOverwritePerPassDescriptorSet(sceneID);
695705
submitUICommands(ctx.currentPass, phaseLayoutID, camera, ctx.cmdBuff);
696706
}
697707
} else {
@@ -704,6 +714,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
704714
CC_ENSURES(passLayoutID != LayoutGraphData::null_vertex());
705715
const auto phaseLayoutID = locate(passLayoutID, "default", ctx.lg);
706716
if (phaseLayoutID != LayoutGraphData::null_vertex()) {
717+
tryBindUIOverwritePerPassDescriptorSet(sceneID);
707718
submitUICommands(ctx.currentPass, phaseLayoutID, camera, ctx.cmdBuff);
708719
}
709720
} else { // Subpass
@@ -721,6 +732,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
721732
CC_ENSURES(subpassLayoutID != LayoutGraphData::null_vertex());
722733
const auto phaseLayoutID = locate(subpassLayoutID, "default", ctx.lg);
723734
if (phaseLayoutID != LayoutGraphData::null_vertex()) {
735+
tryBindUIOverwritePerPassDescriptorSet(sceneID);
724736
submitUICommands(ctx.currentPass, phaseLayoutID, camera, ctx.cmdBuff);
725737
}
726738
}
@@ -1320,6 +1332,10 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
13201332
std::tuple<gfx::DescriptorSet*, gfx::DescriptorSet*>>
13211333
renderGraphDescriptorSet(scratch);
13221334

1335+
ccstd::pmr::unordered_map<
1336+
RenderGraph::vertex_descriptor, gfx::DescriptorSet*>
1337+
uiDescriptorSet(scratch);
1338+
13231339
ccstd::pmr::unordered_map<
13241340
RenderGraph::vertex_descriptor,
13251341
gfx::DescriptorSet*>
@@ -1340,6 +1356,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
13401356
&ppl,
13411357
perPassResourceIndex,
13421358
renderGraphDescriptorSet,
1359+
uiDescriptorSet,
13431360
profilerPerPassDescriptorSets,
13441361
perInstanceDescriptorSets,
13451362
programLibrary,

native/cocos/renderer/pipeline/custom/NativeExecutorDescriptor.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void updateCpuUniformBuffer(
7979
CC_EXPECTS(sizeof(Mat4) == typeSize);
8080
const Mat4 id{};
8181
for (uint32_t i = 0; i != value.count; ++i) {
82-
memcpy(buffer.data() + offset + i * typeSize, id.m, typeSize);
82+
memcpy(buffer.data() + offset + (i * typeSize), id.m, typeSize);
8383
}
8484
}
8585
}
@@ -418,7 +418,6 @@ gfx::DescriptorSet* updatePerPassDescriptorSet(
418418
CC_ENSURES(prevBuffer);
419419
newSet->bindBuffer(bindID, prevBuffer);
420420
}
421-
auto name = lg.valueNames[d.descriptorID.value];
422421
bindID += d.count;
423422
}
424423
break;
@@ -486,7 +485,7 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> {
486485
const auto queueID = parent(leafNodeID, ctx.g);
487486
const auto passOrSubpassID = parent(queueID, ctx.g);
488487
const auto passID = parent(passOrSubpassID, ctx.g);
489-
488+
LayoutGraphData::vertex_descriptor parentPassLayoutID = LayoutGraphData::null_vertex();
490489
if (passID == RenderGraph::null_vertex()) {
491490
const auto& passLayoutName = get(RenderGraph::LayoutTag{}, ctx.g, passOrSubpassID);
492491
const auto passLayoutID = locate(
@@ -495,6 +494,7 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> {
495494
passLayoutID, ctx, leafNodeID);
496495
if (perPassSet) {
497496
get<0>(ctx.renderGraphDescriptorSet[leafNodeID]) = perPassSet;
497+
parentPassLayoutID = passLayoutID;
498498
}
499499
} else {
500500
const auto subpassID = passOrSubpassID;
@@ -512,6 +512,21 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> {
512512
subpassLayoutID, ctx, leafNodeID);
513513
if (perPassSet) {
514514
get<0>(ctx.renderGraphDescriptorSet[leafNodeID]) = perPassSet;
515+
parentPassLayoutID = subpassLayoutID;
516+
}
517+
}
518+
if (holds<SceneTag>(leafNodeID, ctx.g)) {
519+
const auto& sceneData = get(SceneTag{}, leafNodeID, ctx.g);
520+
if (any(sceneData.flags & SceneFlags::UI)) {
521+
const auto passLayoutID = locate(LayoutGraphData::null_vertex(), "default", ctx.lg);
522+
CC_EXPECTS(passLayoutID != LayoutGraphData::null_vertex());
523+
if (passLayoutID != parentPassLayoutID) {
524+
auto* perPassSet = updateCameraUniformBufferAndDescriptorSet(
525+
passLayoutID, ctx, leafNodeID);
526+
if (perPassSet) {
527+
ctx.uiDescriptorSet[leafNodeID] = perPassSet;
528+
}
529+
}
515530
}
516531
}
517532
}

native/cocos/renderer/pipeline/custom/NativeExecutorRenderGraph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct RenderGraphVisitorContext {
6363
ccstd::pmr::unordered_map<
6464
RenderGraph::vertex_descriptor,
6565
std::tuple<gfx::DescriptorSet*, gfx::DescriptorSet*>>& renderGraphDescriptorSet;
66+
ccstd::pmr::unordered_map<
67+
RenderGraph::vertex_descriptor, gfx::DescriptorSet*>& uiDescriptorSet;
6668
ccstd::pmr::unordered_map<
6769
RenderGraph::vertex_descriptor,
6870
gfx::DescriptorSet*>& profilerPerPassDescriptorSets;

0 commit comments

Comments
 (0)