Skip to content

Commit efed2b6

Browse files
authored
fix profiler rendering (#18737)
1 parent a4c3789 commit efed2b6

File tree

3 files changed

+54
-50
lines changed

3 files changed

+54
-50
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ void submitUICommands(
286286
void submitProfilerCommands(
287287
RenderGraphVisitorContext& ctx,
288288
RenderGraph::vertex_descriptor sceneId) {
289+
CC_EXPECTS(!ctx.passShowStatistics.empty());
290+
if (!ctx.passShowStatistics.back()) {
291+
// profiler is disabled
292+
return;
293+
}
294+
289295
const auto* profiler = ctx.ppl->getProfiler();
290296
if (!profiler || !profiler->isEnabled()) {
291297
return;
@@ -452,6 +458,10 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
452458

453459
// PerPass DescriptorSet
454460
tryBindPassDescriptorSet(vertID);
461+
462+
// Statistics
463+
CC_EXPECTS(ctx.passShowStatistics.empty());
464+
ctx.passShowStatistics.emplace_back(pass.showStatistics);
455465
}
456466
void begin(const RasterSubpass& subpass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static)
457467
#if CC_DEBUG
@@ -474,7 +484,10 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
474484
}
475485
tryBindPassDescriptorSet(vertID);
476486
ctx.subpassIndex = subpass.subpassID;
477-
// noop
487+
488+
// Statistics
489+
CC_EXPECTS(ctx.passShowStatistics.size() == 1);
490+
ctx.passShowStatistics.emplace_back(subpass.showStatistics);
478491
}
479492
void begin(const ComputeSubpass& subpass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static)
480493
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
@@ -843,6 +856,10 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
843856
ctx.currentPass = nullptr;
844857
ctx.viewportStack.pop_back();
845858
CC_ENSURES(ctx.viewportStack.empty());
859+
860+
// Statistics
861+
ctx.passShowStatistics.pop_back();
862+
CC_ENSURES(ctx.passShowStatistics.empty());
846863
}
847864
void end(const RasterSubpass& subpass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static)
848865
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
@@ -858,7 +875,8 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
858875
std::ignore = subpass;
859876
std::ignore = vertID;
860877
ctx.subpassIndex = 0;
861-
// noop
878+
ctx.passShowStatistics.pop_back();
879+
CC_ENSURES(ctx.passShowStatistics.size() == 1);
862880
}
863881
void end(const ComputeSubpass& subpass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static)
864882
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
@@ -1388,7 +1406,9 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
13881406
RenderGraphVisitor visitor{{}, ctx};
13891407
auto colors = rg.colors(scratch);
13901408
for (const auto vertID : ctx.g.sortedVertices) {
1391-
if (holds<RasterPassTag>(vertID, ctx.g) || holds<ComputeTag>(vertID, ctx.g) || holds<CopyTag>(vertID, ctx.g)) {
1409+
if (holds<RasterPassTag>(vertID, ctx.g) ||
1410+
holds<ComputeTag>(vertID, ctx.g) ||
1411+
holds<CopyTag>(vertID, ctx.g)) {
13921412
boost::depth_first_visit(fg, vertID, visitor, get(colors, ctx.g));
13931413
}
13941414
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "LayoutGraphTypes.h"
2828
#include "NativePipelineTypes.h"
2929
#include "RenderGraphTypes.h"
30+
#include <boost/container/static_vector.hpp>
3031

3132
namespace cc {
3233

@@ -64,6 +65,7 @@ struct RenderGraphVisitorContext {
6465
gfx::RenderPass* currentPass = nullptr;
6566
uint32_t subpassIndex = 0;
6667
RenderGraph::vertex_descriptor currentInFlightPassID = RenderGraph::null_vertex();
68+
boost::container::static_vector<bool, 2> passShowStatistics;
6769
};
6870

6971
} // namespace render

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

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,58 +1069,40 @@ void NativeRenderQueueBuilder::addDraw2D(const scene::Camera *camera) {
10691069

10701070
void NativeRenderQueueBuilder::addProfiler(const scene::Camera *camera) {
10711071
CC_EXPECTS(camera);
1072-
bool showStatistics = false;
10731072
const auto passOrSubpassId = parent(nodeID, *renderGraph);
1074-
{
1075-
CC_EXPECTS(passOrSubpassId != RenderGraph::null_vertex());
1076-
const auto passOrNullId = parent(passOrSubpassId, *renderGraph);
1077-
1078-
const auto passId = passOrNullId == RenderGraph::null_vertex()
1079-
? passOrSubpassId
1080-
: passOrNullId;
1081-
1082-
CC_ENSURES(passId != RenderGraph::null_vertex() &&
1083-
holds<RasterPassTag>(passId, *renderGraph));
1084-
1085-
const auto &pass = get(RasterPassTag{}, passId, *renderGraph);
1086-
1087-
showStatistics = pass.showStatistics;
1088-
}
10891073

1090-
if (showStatistics) {
1091-
const auto passLayoutId = locate(
1092-
LayoutGraphData::null_vertex(), "default", *layoutGraph);
1093-
const auto phaseLayoutId = locate(
1094-
passLayoutId, "default", *layoutGraph);
1074+
const auto passLayoutId = locate(
1075+
LayoutGraphData::null_vertex(), "default", *layoutGraph);
1076+
const auto phaseLayoutId = locate(
1077+
passLayoutId, "default", *layoutGraph);
10951078

1096-
const auto queueId = addVertex2(
1097-
QueueTag{},
1098-
std::forward_as_tuple("Profiler Queue"),
1099-
std::forward_as_tuple("default"),
1100-
std::forward_as_tuple(),
1101-
std::forward_as_tuple(),
1102-
std::forward_as_tuple(QueueHint::BLEND, phaseLayoutId, passLayoutId),
1103-
*renderGraph,
1104-
passOrSubpassId);
1079+
const auto queueId = addVertex2(
1080+
QueueTag{},
1081+
std::forward_as_tuple("Profiler Queue"),
1082+
std::forward_as_tuple("default"),
1083+
std::forward_as_tuple(),
1084+
std::forward_as_tuple(),
1085+
std::forward_as_tuple(QueueHint::BLEND, phaseLayoutId, passLayoutId),
1086+
*renderGraph,
1087+
passOrSubpassId);
11051088

1106-
const auto sceneId = addVertex2(
1107-
BlitTag{},
1108-
std::forward_as_tuple("Profiler"),
1109-
std::forward_as_tuple(),
1110-
std::forward_as_tuple(),
1111-
std::forward_as_tuple(),
1112-
std::forward_as_tuple(
1113-
IntrusivePtr<Material>{},
1114-
RenderGraph::null_vertex(),
1115-
SceneFlags::NONE,
1116-
nullptr,
1117-
BlitType::DRAW_PROFILE),
1118-
*renderGraph,
1119-
queueId);
1089+
const auto sceneId = addVertex2(
1090+
BlitTag{},
1091+
std::forward_as_tuple("Profiler"),
1092+
std::forward_as_tuple(),
1093+
std::forward_as_tuple(),
1094+
std::forward_as_tuple(),
1095+
std::forward_as_tuple(
1096+
IntrusivePtr<Material>{},
1097+
RenderGraph::null_vertex(),
1098+
SceneFlags::NONE,
1099+
nullptr,
1100+
BlitType::DRAW_PROFILE),
1101+
*renderGraph,
1102+
queueId);
11201103

1121-
auto &data = get(RenderGraph::DataTag{}, *renderGraph, sceneId);
1122-
setMat4Impl(data, *layoutGraph, "cc_matProj", camera->getMatProj());
1123-
}
1104+
auto &data = get(RenderGraph::DataTag{}, *renderGraph, sceneId);
1105+
setMat4Impl(data, *layoutGraph, "cc_matProj", camera->getMatProj());
11241106
}
11251107

11261108
void NativeRenderQueueBuilder::clearRenderTarget(const ccstd::string &name, const gfx::Color &color) {

0 commit comments

Comments
 (0)