mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-07 13:45:51 +00:00
transform: Minor changes to cleanup Dawn usage.
Move transform::Transform::Output to transform::Output. There's no need for this to be an nested class, it stutters, and it also prevents Dawn from forward declaring it. Add move assignment operator to DataMap. Change-Id: Ibe1af03abc1a872790d20ee6ec8cf18a511ea0b4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47772 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
fd7251bb02
commit
856a3688f7
@ -34,8 +34,7 @@ BindingRemapper::Remappings::~Remappings() = default;
|
|||||||
BindingRemapper::BindingRemapper() = default;
|
BindingRemapper::BindingRemapper() = default;
|
||||||
BindingRemapper::~BindingRemapper() = default;
|
BindingRemapper::~BindingRemapper() = default;
|
||||||
|
|
||||||
Transform::Output BindingRemapper::Run(const Program* in,
|
Output BindingRemapper::Run(const Program* in, const DataMap& datamap) {
|
||||||
const DataMap& datamap) {
|
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
auto* remappings = datamap.Get<Remappings>();
|
auto* remappings = datamap.Get<Remappings>();
|
||||||
if (!remappings) {
|
if (!remappings) {
|
||||||
|
@ -26,7 +26,7 @@ namespace transform {
|
|||||||
BoundArrayAccessors::BoundArrayAccessors() = default;
|
BoundArrayAccessors::BoundArrayAccessors() = default;
|
||||||
BoundArrayAccessors::~BoundArrayAccessors() = default;
|
BoundArrayAccessors::~BoundArrayAccessors() = default;
|
||||||
|
|
||||||
Transform::Output BoundArrayAccessors::Run(const Program* in, const DataMap&) {
|
Output BoundArrayAccessors::Run(const Program* in, const DataMap&) {
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
CloneContext ctx(&out, in);
|
CloneContext ctx(&out, in);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ CalculateArrayLength::BufferSizeIntrinsic::Clone(CloneContext* ctx) const {
|
|||||||
CalculateArrayLength::CalculateArrayLength() = default;
|
CalculateArrayLength::CalculateArrayLength() = default;
|
||||||
CalculateArrayLength::~CalculateArrayLength() = default;
|
CalculateArrayLength::~CalculateArrayLength() = default;
|
||||||
|
|
||||||
Transform::Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
|
Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
CloneContext ctx(&out, in);
|
CloneContext ctx(&out, in);
|
||||||
|
|
||||||
|
@ -58,8 +58,7 @@ bool StructMemberComparator(const ast::StructMember* a,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
|
Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
|
||||||
const DataMap&) {
|
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
CloneContext ctx(&out, in);
|
CloneContext ctx(&out, in);
|
||||||
|
|
||||||
|
@ -609,8 +609,7 @@ DecomposeStorageAccess::Intrinsic* DecomposeStorageAccess::Intrinsic::Clone(
|
|||||||
DecomposeStorageAccess::DecomposeStorageAccess() = default;
|
DecomposeStorageAccess::DecomposeStorageAccess() = default;
|
||||||
DecomposeStorageAccess::~DecomposeStorageAccess() = default;
|
DecomposeStorageAccess::~DecomposeStorageAccess() = default;
|
||||||
|
|
||||||
Transform::Output DecomposeStorageAccess::Run(const Program* in,
|
Output DecomposeStorageAccess::Run(const Program* in, const DataMap&) {
|
||||||
const DataMap&) {
|
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
CloneContext ctx(&out, in);
|
CloneContext ctx(&out, in);
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace transform {
|
|||||||
EmitVertexPointSize::EmitVertexPointSize() = default;
|
EmitVertexPointSize::EmitVertexPointSize() = default;
|
||||||
EmitVertexPointSize::~EmitVertexPointSize() = default;
|
EmitVertexPointSize::~EmitVertexPointSize() = default;
|
||||||
|
|
||||||
Transform::Output EmitVertexPointSize::Run(const Program* in, const DataMap&) {
|
Output EmitVertexPointSize::Run(const Program* in, const DataMap&) {
|
||||||
if (!in->AST().Functions().HasStage(ast::PipelineStage::kVertex)) {
|
if (!in->AST().Functions().HasStage(ast::PipelineStage::kVertex)) {
|
||||||
// If the module doesn't have any vertex stages, then there's nothing to do.
|
// If the module doesn't have any vertex stages, then there's nothing to do.
|
||||||
return Output(Program(in->Clone()));
|
return Output(Program(in->Clone()));
|
||||||
|
@ -60,8 +60,7 @@ FirstIndexOffset::FirstIndexOffset(uint32_t binding, uint32_t group)
|
|||||||
|
|
||||||
FirstIndexOffset::~FirstIndexOffset() = default;
|
FirstIndexOffset::~FirstIndexOffset() = default;
|
||||||
|
|
||||||
Transform::Output FirstIndexOffset::Run(const Program* in,
|
Output FirstIndexOffset::Run(const Program* in, const DataMap& data) {
|
||||||
const DataMap& data) {
|
|
||||||
// Get the uniform buffer binding point
|
// Get the uniform buffer binding point
|
||||||
uint32_t ub_binding = binding_;
|
uint32_t ub_binding = binding_;
|
||||||
uint32_t ub_group = group_;
|
uint32_t ub_group = group_;
|
||||||
|
@ -33,7 +33,7 @@ namespace transform {
|
|||||||
Hlsl::Hlsl() = default;
|
Hlsl::Hlsl() = default;
|
||||||
Hlsl::~Hlsl() = default;
|
Hlsl::~Hlsl() = default;
|
||||||
|
|
||||||
Transform::Output Hlsl::Run(const Program* in, const DataMap& data) {
|
Output Hlsl::Run(const Program* in, const DataMap& data) {
|
||||||
Manager manager;
|
Manager manager;
|
||||||
manager.Add<CanonicalizeEntryPointIO>();
|
manager.Add<CanonicalizeEntryPointIO>();
|
||||||
manager.Add<DecomposeStorageAccess>();
|
manager.Add<DecomposeStorageAccess>();
|
||||||
|
@ -20,7 +20,7 @@ namespace transform {
|
|||||||
Manager::Manager() = default;
|
Manager::Manager() = default;
|
||||||
Manager::~Manager() = default;
|
Manager::~Manager() = default;
|
||||||
|
|
||||||
Transform::Output Manager::Run(const Program* program, const DataMap& data) {
|
Output Manager::Run(const Program* program, const DataMap& data) {
|
||||||
Output out;
|
Output out;
|
||||||
if (!transforms_.empty()) {
|
if (!transforms_.empty()) {
|
||||||
for (auto& transform : transforms_) {
|
for (auto& transform : transforms_) {
|
||||||
|
@ -25,7 +25,7 @@ namespace transform {
|
|||||||
Msl::Msl() = default;
|
Msl::Msl() = default;
|
||||||
Msl::~Msl() = default;
|
Msl::~Msl() = default;
|
||||||
|
|
||||||
Transform::Output Msl::Run(const Program* in, const DataMap& data) {
|
Output Msl::Run(const Program* in, const DataMap& data) {
|
||||||
Manager manager;
|
Manager manager;
|
||||||
manager.Add<CanonicalizeEntryPointIO>();
|
manager.Add<CanonicalizeEntryPointIO>();
|
||||||
auto out = manager.Run(in, data);
|
auto out = manager.Run(in, data);
|
||||||
|
@ -846,7 +846,7 @@ Renamer::Renamer(const Config& config) : cfg_(config) {}
|
|||||||
|
|
||||||
Renamer::~Renamer() = default;
|
Renamer::~Renamer() = default;
|
||||||
|
|
||||||
Transform::Output Renamer::Run(const Program* in, const DataMap&) {
|
Output Renamer::Run(const Program* in, const DataMap&) {
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
CloneContext ctx(&out, in);
|
CloneContext ctx(&out, in);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace transform {
|
|||||||
Spirv::Spirv() = default;
|
Spirv::Spirv() = default;
|
||||||
Spirv::~Spirv() = default;
|
Spirv::~Spirv() = default;
|
||||||
|
|
||||||
Transform::Output Spirv::Run(const Program* in, const DataMap&) {
|
Output Spirv::Run(const Program* in, const DataMap&) {
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
CloneContext ctx(&out, in);
|
CloneContext ctx(&out, in);
|
||||||
HandleEntryPointIOTypes(ctx);
|
HandleEntryPointIOTypes(ctx);
|
||||||
|
@ -38,8 +38,7 @@ class TransformTestBase : public BASE {
|
|||||||
/// @param transforms the list of transforms to apply
|
/// @param transforms the list of transforms to apply
|
||||||
/// @param data the optional DataMap to pass to Transform::Run()
|
/// @param data the optional DataMap to pass to Transform::Run()
|
||||||
/// @return the transformed output
|
/// @return the transformed output
|
||||||
Transform::Output Run(
|
Output Run(std::string in,
|
||||||
std::string in,
|
|
||||||
std::vector<std::unique_ptr<transform::Transform>> transforms,
|
std::vector<std::unique_ptr<transform::Transform>> transforms,
|
||||||
const DataMap& data = {}) {
|
const DataMap& data = {}) {
|
||||||
auto file = std::make_unique<Source::File>("test", in);
|
auto file = std::make_unique<Source::File>("test", in);
|
||||||
@ -49,7 +48,7 @@ class TransformTestBase : public BASE {
|
|||||||
files_.emplace_back(std::move(file));
|
files_.emplace_back(std::move(file));
|
||||||
|
|
||||||
if (!program.IsValid()) {
|
if (!program.IsValid()) {
|
||||||
return Transform::Output(std::move(program));
|
return Output(std::move(program));
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager manager;
|
Manager manager;
|
||||||
@ -65,7 +64,7 @@ class TransformTestBase : public BASE {
|
|||||||
/// @param in the input WGSL source
|
/// @param in the input WGSL source
|
||||||
/// @param data the optional DataMap to pass to Transform::Run()
|
/// @param data the optional DataMap to pass to Transform::Run()
|
||||||
/// @return the transformed output
|
/// @return the transformed output
|
||||||
Transform::Output Run(std::string in,
|
Output Run(std::string in,
|
||||||
std::unique_ptr<transform::Transform> transform,
|
std::unique_ptr<transform::Transform> transform,
|
||||||
const DataMap& data = {}) {
|
const DataMap& data = {}) {
|
||||||
std::vector<std::unique_ptr<transform::Transform>> transforms;
|
std::vector<std::unique_ptr<transform::Transform>> transforms;
|
||||||
@ -79,14 +78,14 @@ class TransformTestBase : public BASE {
|
|||||||
/// @param data the optional DataMap to pass to Transform::Run()
|
/// @param data the optional DataMap to pass to Transform::Run()
|
||||||
/// @return the transformed output
|
/// @return the transformed output
|
||||||
template <typename TRANSFORM>
|
template <typename TRANSFORM>
|
||||||
Transform::Output Run(std::string in, const DataMap& data = {}) {
|
Output Run(std::string in, const DataMap& data = {}) {
|
||||||
return Run(std::move(in), std::make_unique<TRANSFORM>(), data);
|
return Run(std::move(in), std::make_unique<TRANSFORM>(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param output the output of the transform
|
/// @param output the output of the transform
|
||||||
/// @returns the output program as a WGSL string, or an error string if the
|
/// @returns the output program as a WGSL string, or an error string if the
|
||||||
/// program is not valid.
|
/// program is not valid.
|
||||||
std::string str(const Transform::Output& output) {
|
std::string str(const Output& output) {
|
||||||
diag::Formatter::Style style;
|
diag::Formatter::Style style;
|
||||||
style.print_newline_at_end = false;
|
style.print_newline_at_end = false;
|
||||||
|
|
||||||
|
@ -31,9 +31,10 @@ Data& Data::operator=(const Data&) = default;
|
|||||||
DataMap::DataMap() = default;
|
DataMap::DataMap() = default;
|
||||||
DataMap::DataMap(DataMap&&) = default;
|
DataMap::DataMap(DataMap&&) = default;
|
||||||
DataMap::~DataMap() = default;
|
DataMap::~DataMap() = default;
|
||||||
|
DataMap& DataMap::operator=(DataMap&&) = default;
|
||||||
|
|
||||||
Transform::Output::Output() = default;
|
Output::Output() = default;
|
||||||
Transform::Output::Output(Program&& p) : program(std::move(p)) {}
|
Output::Output(Program&& p) : program(std::move(p)) {}
|
||||||
Transform::Transform() = default;
|
Transform::Transform() = default;
|
||||||
Transform::~Transform() = default;
|
Transform::~Transform() = default;
|
||||||
|
|
||||||
|
@ -62,6 +62,11 @@ class DataMap {
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~DataMap();
|
~DataMap();
|
||||||
|
|
||||||
|
/// Move assignment operator
|
||||||
|
/// @param rhs the DataMap to move into this DataMap
|
||||||
|
/// @return this DataMap
|
||||||
|
DataMap& operator=(DataMap&& rhs);
|
||||||
|
|
||||||
/// Adds the data into DataMap keyed by the ClassID of type T.
|
/// Adds the data into DataMap keyed by the ClassID of type T.
|
||||||
/// @param data the data to add to the DataMap
|
/// @param data the data to add to the DataMap
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -114,14 +119,6 @@ class DataMap {
|
|||||||
std::unordered_map<const TypeInfo*, std::unique_ptr<Data>> map_;
|
std::unordered_map<const TypeInfo*, std::unique_ptr<Data>> map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Interface for Program transforms
|
|
||||||
class Transform {
|
|
||||||
public:
|
|
||||||
/// Constructor
|
|
||||||
Transform();
|
|
||||||
/// Destructor
|
|
||||||
virtual ~Transform();
|
|
||||||
|
|
||||||
/// The return type of Run()
|
/// The return type of Run()
|
||||||
class Output {
|
class Output {
|
||||||
public:
|
public:
|
||||||
@ -147,6 +144,17 @@ class Transform {
|
|||||||
DataMap data;
|
DataMap data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Interface for Program transforms
|
||||||
|
class Transform {
|
||||||
|
public:
|
||||||
|
/// [DEPRECATED]: Use transform::Output
|
||||||
|
using Output = transform::Output;
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
Transform();
|
||||||
|
/// Destructor
|
||||||
|
virtual ~Transform();
|
||||||
|
|
||||||
/// Runs the transform on `program`, returning the transformation result.
|
/// Runs the transform on `program`, returning the transformation result.
|
||||||
/// @param program the source program to transform
|
/// @param program the source program to transform
|
||||||
/// @param data optional extra transform-specific input data
|
/// @param data optional extra transform-specific input data
|
||||||
|
@ -390,7 +390,7 @@ VertexPulling::VertexPulling(const Config& config) : cfg_(config) {}
|
|||||||
|
|
||||||
VertexPulling::~VertexPulling() = default;
|
VertexPulling::~VertexPulling() = default;
|
||||||
|
|
||||||
Transform::Output VertexPulling::Run(const Program* in, const DataMap& data) {
|
Output VertexPulling::Run(const Program* in, const DataMap& data) {
|
||||||
ProgramBuilder out;
|
ProgramBuilder out;
|
||||||
|
|
||||||
auto cfg = cfg_;
|
auto cfg = cfg_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user