Skip to content

Commit

Permalink
Simplify visitObject (cocos#17716)
Browse files Browse the repository at this point in the history
* remove unused headers

* simplify visitObject
  • Loading branch information
star-e authored Oct 15, 2024
1 parent 707b36f commit f833b8a
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 223 deletions.
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

0 comments on commit f833b8a

Please sign in to comment.