Skip to content

Commit

Permalink
fix ui per-pass descriptor set (#17663)
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e authored Sep 24, 2024
1 parent 684974d commit 5ea5825
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
17 changes: 17 additions & 0 deletions native/cocos/renderer/pipeline/custom/NativeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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()) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -1320,6 +1332,10 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
std::tuple<gfx::DescriptorSet*, gfx::DescriptorSet*>>
renderGraphDescriptorSet(scratch);

ccstd::pmr::unordered_map<
RenderGraph::vertex_descriptor, gfx::DescriptorSet*>
uiDescriptorSet(scratch);

ccstd::pmr::unordered_map<
RenderGraph::vertex_descriptor,
gfx::DescriptorSet*>
Expand All @@ -1340,6 +1356,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
&ppl,
perPassResourceIndex,
renderGraphDescriptorSet,
uiDescriptorSet,
profilerPerPassDescriptorSets,
perInstanceDescriptorSets,
programLibrary,
Expand Down
21 changes: 18 additions & 3 deletions native/cocos/renderer/pipeline/custom/NativeExecutorDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -512,6 +512,21 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> {
subpassLayoutID, ctx, leafNodeID);
if (perPassSet) {
get<0>(ctx.renderGraphDescriptorSet[leafNodeID]) = perPassSet;
parentPassLayoutID = subpassLayoutID;
}
}
if (holds<SceneTag>(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;
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct RenderGraphVisitorContext {
ccstd::pmr::unordered_map<
RenderGraph::vertex_descriptor,
std::tuple<gfx::DescriptorSet*, gfx::DescriptorSet*>>& renderGraphDescriptorSet;
ccstd::pmr::unordered_map<
RenderGraph::vertex_descriptor, gfx::DescriptorSet*>& uiDescriptorSet;
ccstd::pmr::unordered_map<
RenderGraph::vertex_descriptor,
gfx::DescriptorSet*>& profilerPerPassDescriptorSets;
Expand Down

0 comments on commit 5ea5825

Please sign in to comment.