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

Simplify visitObject #17716

Merged
merged 2 commits into from
Oct 15, 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
1 change: 0 additions & 1 deletion native/cocos/renderer/pipeline/custom/CustomTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
// clang-format off
#pragma once
#include "cocos/base/std/container/string.h"
#include "cocos/renderer/pipeline/custom/CustomFwd.h"
#include "cocos/renderer/pipeline/custom/RenderGraphTypes.h"

Expand Down
92 changes: 48 additions & 44 deletions native/cocos/renderer/pipeline/custom/LayoutGraphGraphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,32 +739,34 @@ tag(LayoutGraph::vertex_descriptor u, const LayoutGraph& g) noexcept {
g._vertices[u].handle);
}

inline LayoutGraph::VertexValue
value(LayoutGraph::vertex_descriptor u, LayoutGraph& g) noexcept {
template <class... Ts>
auto visitObject(LayoutGraph::vertex_descriptor v, const LayoutGraph&g, Ts&&... args) {
using vertex_descriptor = LayoutGraph::vertex_descriptor;
return ccstd::visit(
overload(
[&](const impl::ValueHandle<RenderStageTag, vertex_descriptor>& h) {
return LayoutGraph::VertexValue{&g.stages[h.value]};
},
[&](const impl::ValueHandle<RenderPhaseTag, vertex_descriptor>& h) {
return LayoutGraph::VertexValue{&g.phases[h.value]};
}),
g._vertices[u].handle);
auto visitor = Overloaded{ std::forward<Ts>(args)... };
const auto& var = g._vertices[v].handle;
switch (var.index()) {
case 0:
return visitor(g.stages[ccstd::get<impl::ValueHandle<RenderStageTag, vertex_descriptor>>(var).value]);
case 1:
return visitor(g.phases[ccstd::get<impl::ValueHandle<RenderPhaseTag, vertex_descriptor>>(var).value]);
default:
std::terminate();
}
}

inline LayoutGraph::VertexConstValue
value(LayoutGraph::vertex_descriptor u, const LayoutGraph& g) noexcept {
template <class... Ts>
auto visitObject(LayoutGraph::vertex_descriptor v, LayoutGraph&g, Ts&&... args) {
using vertex_descriptor = LayoutGraph::vertex_descriptor;
return ccstd::visit(
overload(
[&](const impl::ValueHandle<RenderStageTag, vertex_descriptor>& h) {
return LayoutGraph::VertexConstValue{&g.stages[h.value]};
},
[&](const impl::ValueHandle<RenderPhaseTag, vertex_descriptor>& h) {
return LayoutGraph::VertexConstValue{&g.phases[h.value]};
}),
g._vertices[u].handle);
auto visitor = Overloaded{ std::forward<Ts>(args)... };
auto& var = g._vertices[v].handle;
switch (var.index()) {
case 0:
return visitor(g.stages[ccstd::get<impl::ValueHandle<RenderStageTag, vertex_descriptor>>(var).value]);
case 1:
return visitor(g.phases[ccstd::get<impl::ValueHandle<RenderPhaseTag, vertex_descriptor>>(var).value]);
default:
std::terminate();
}
}

template <class Tag>
Expand Down Expand Up @@ -1439,32 +1441,34 @@ tag(LayoutGraphData::vertex_descriptor u, const LayoutGraphData& g) noexcept {
g._vertices[u].handle);
}

inline LayoutGraphData::VertexValue
value(LayoutGraphData::vertex_descriptor u, LayoutGraphData& g) noexcept {
template <class... Ts>
auto visitObject(LayoutGraphData::vertex_descriptor v, const LayoutGraphData&g, Ts&&... args) {
using vertex_descriptor = LayoutGraphData::vertex_descriptor;
return ccstd::visit(
overload(
[&](const impl::ValueHandle<RenderStageTag, vertex_descriptor>& h) {
return LayoutGraphData::VertexValue{&g.stages[h.value]};
},
[&](const impl::ValueHandle<RenderPhaseTag, vertex_descriptor>& h) {
return LayoutGraphData::VertexValue{&g.phases[h.value]};
}),
g._vertices[u].handle);
auto visitor = Overloaded{ std::forward<Ts>(args)... };
const auto& var = g._vertices[v].handle;
switch (var.index()) {
case 0:
return visitor(g.stages[ccstd::get<impl::ValueHandle<RenderStageTag, vertex_descriptor>>(var).value]);
case 1:
return visitor(g.phases[ccstd::get<impl::ValueHandle<RenderPhaseTag, vertex_descriptor>>(var).value]);
default:
std::terminate();
}
}

inline LayoutGraphData::VertexConstValue
value(LayoutGraphData::vertex_descriptor u, const LayoutGraphData& g) noexcept {
template <class... Ts>
auto visitObject(LayoutGraphData::vertex_descriptor v, LayoutGraphData&g, Ts&&... args) {
using vertex_descriptor = LayoutGraphData::vertex_descriptor;
return ccstd::visit(
overload(
[&](const impl::ValueHandle<RenderStageTag, vertex_descriptor>& h) {
return LayoutGraphData::VertexConstValue{&g.stages[h.value]};
},
[&](const impl::ValueHandle<RenderPhaseTag, vertex_descriptor>& h) {
return LayoutGraphData::VertexConstValue{&g.phases[h.value]};
}),
g._vertices[u].handle);
auto visitor = Overloaded{ std::forward<Ts>(args)... };
auto& var = g._vertices[v].handle;
switch (var.index()) {
case 0:
return visitor(g.stages[ccstd::get<impl::ValueHandle<RenderStageTag, vertex_descriptor>>(var).value]);
case 1:
return visitor(g.phases[ccstd::get<impl::ValueHandle<RenderPhaseTag, vertex_descriptor>>(var).value]);
default:
std::terminate();
}
}

template <class Tag>
Expand Down
Loading
Loading