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:
Ben Clayton 2021-04-16 08:35:24 +00:00 committed by Commit Bot service account
parent fd7251bb02
commit 856a3688f7
16 changed files with 58 additions and 54 deletions

View File

@ -34,8 +34,7 @@ BindingRemapper::Remappings::~Remappings() = default;
BindingRemapper::BindingRemapper() = default;
BindingRemapper::~BindingRemapper() = default;
Transform::Output BindingRemapper::Run(const Program* in,
const DataMap& datamap) {
Output BindingRemapper::Run(const Program* in, const DataMap& datamap) {
ProgramBuilder out;
auto* remappings = datamap.Get<Remappings>();
if (!remappings) {

View File

@ -26,7 +26,7 @@ namespace transform {
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;
CloneContext ctx(&out, in);

View File

@ -68,7 +68,7 @@ CalculateArrayLength::BufferSizeIntrinsic::Clone(CloneContext* ctx) const {
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;
CloneContext ctx(&out, in);

View File

@ -58,8 +58,7 @@ bool StructMemberComparator(const ast::StructMember* a,
} // namespace
Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
const DataMap&) {
Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
ProgramBuilder out;
CloneContext ctx(&out, in);

View File

@ -609,8 +609,7 @@ DecomposeStorageAccess::Intrinsic* DecomposeStorageAccess::Intrinsic::Clone(
DecomposeStorageAccess::DecomposeStorageAccess() = default;
DecomposeStorageAccess::~DecomposeStorageAccess() = default;
Transform::Output DecomposeStorageAccess::Run(const Program* in,
const DataMap&) {
Output DecomposeStorageAccess::Run(const Program* in, const DataMap&) {
ProgramBuilder out;
CloneContext ctx(&out, in);

View File

@ -25,7 +25,7 @@ namespace transform {
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 the module doesn't have any vertex stages, then there's nothing to do.
return Output(Program(in->Clone()));

View File

@ -60,8 +60,7 @@ FirstIndexOffset::FirstIndexOffset(uint32_t binding, uint32_t group)
FirstIndexOffset::~FirstIndexOffset() = default;
Transform::Output FirstIndexOffset::Run(const Program* in,
const DataMap& data) {
Output FirstIndexOffset::Run(const Program* in, const DataMap& data) {
// Get the uniform buffer binding point
uint32_t ub_binding = binding_;
uint32_t ub_group = group_;

View File

@ -33,7 +33,7 @@ namespace transform {
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.Add<CanonicalizeEntryPointIO>();
manager.Add<DecomposeStorageAccess>();

View File

@ -20,7 +20,7 @@ namespace transform {
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;
if (!transforms_.empty()) {
for (auto& transform : transforms_) {

View File

@ -25,7 +25,7 @@ namespace transform {
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.Add<CanonicalizeEntryPointIO>();
auto out = manager.Run(in, data);

View File

@ -846,7 +846,7 @@ Renamer::Renamer(const Config& config) : cfg_(config) {}
Renamer::~Renamer() = default;
Transform::Output Renamer::Run(const Program* in, const DataMap&) {
Output Renamer::Run(const Program* in, const DataMap&) {
ProgramBuilder out;
CloneContext ctx(&out, in);

View File

@ -31,7 +31,7 @@ namespace transform {
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;
CloneContext ctx(&out, in);
HandleEntryPointIOTypes(ctx);

View File

@ -38,10 +38,9 @@ class TransformTestBase : public BASE {
/// @param transforms the list of transforms to apply
/// @param data the optional DataMap to pass to Transform::Run()
/// @return the transformed output
Transform::Output Run(
std::string in,
std::vector<std::unique_ptr<transform::Transform>> transforms,
const DataMap& data = {}) {
Output Run(std::string in,
std::vector<std::unique_ptr<transform::Transform>> transforms,
const DataMap& data = {}) {
auto file = std::make_unique<Source::File>("test", in);
auto program = reader::wgsl::Parse(file.get());
@ -49,7 +48,7 @@ class TransformTestBase : public BASE {
files_.emplace_back(std::move(file));
if (!program.IsValid()) {
return Transform::Output(std::move(program));
return Output(std::move(program));
}
Manager manager;
@ -65,9 +64,9 @@ class TransformTestBase : public BASE {
/// @param in the input WGSL source
/// @param data the optional DataMap to pass to Transform::Run()
/// @return the transformed output
Transform::Output Run(std::string in,
std::unique_ptr<transform::Transform> transform,
const DataMap& data = {}) {
Output Run(std::string in,
std::unique_ptr<transform::Transform> transform,
const DataMap& data = {}) {
std::vector<std::unique_ptr<transform::Transform>> transforms;
transforms.emplace_back(std::move(transform));
return Run(std::move(in), std::move(transforms), data);
@ -79,14 +78,14 @@ class TransformTestBase : public BASE {
/// @param data the optional DataMap to pass to Transform::Run()
/// @return the transformed output
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);
}
/// @param output the output of the transform
/// @returns the output program as a WGSL string, or an error string if the
/// program is not valid.
std::string str(const Transform::Output& output) {
std::string str(const Output& output) {
diag::Formatter::Style style;
style.print_newline_at_end = false;

View File

@ -31,9 +31,10 @@ Data& Data::operator=(const Data&) = default;
DataMap::DataMap() = default;
DataMap::DataMap(DataMap&&) = default;
DataMap::~DataMap() = default;
DataMap& DataMap::operator=(DataMap&&) = default;
Transform::Output::Output() = default;
Transform::Output::Output(Program&& p) : program(std::move(p)) {}
Output::Output() = default;
Output::Output(Program&& p) : program(std::move(p)) {}
Transform::Transform() = default;
Transform::~Transform() = default;

View File

@ -62,6 +62,11 @@ class DataMap {
/// Destructor
~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.
/// @param data the data to add to the DataMap
template <typename T>
@ -114,39 +119,42 @@ class DataMap {
std::unordered_map<const TypeInfo*, std::unique_ptr<Data>> map_;
};
/// The return type of Run()
class Output {
public:
/// Constructor
Output();
/// Constructor
/// @param program the program to move into this Output
explicit Output(Program&& program);
/// Constructor
/// @param program_ the program to move into this Output
/// @param data_ a variadic list of additional data unique_ptrs produced by
/// the transform
template <typename... DATA>
Output(Program&& program_, DATA... data_)
: program(std::move(program_)), data(std::forward<DATA>(data_)...) {}
/// The transformed program. May be empty on error.
Program program;
/// Extra output generated by the transforms.
DataMap data;
};
/// Interface for Program transforms
class Transform {
public:
/// [DEPRECATED]: Use transform::Output
using Output = transform::Output;
/// Constructor
Transform();
/// Destructor
virtual ~Transform();
/// The return type of Run()
class Output {
public:
/// Constructor
Output();
/// Constructor
/// @param program the program to move into this Output
explicit Output(Program&& program);
/// Constructor
/// @param program_ the program to move into this Output
/// @param data_ a variadic list of additional data unique_ptrs produced by
/// the transform
template <typename... DATA>
Output(Program&& program_, DATA... data_)
: program(std::move(program_)), data(std::forward<DATA>(data_)...) {}
/// The transformed program. May be empty on error.
Program program;
/// Extra output generated by the transforms.
DataMap data;
};
/// Runs the transform on `program`, returning the transformation result.
/// @param program the source program to transform
/// @param data optional extra transform-specific input data

View File

@ -390,7 +390,7 @@ VertexPulling::VertexPulling(const Config& config) : cfg_(config) {}
VertexPulling::~VertexPulling() = default;
Transform::Output VertexPulling::Run(const Program* in, const DataMap& data) {
Output VertexPulling::Run(const Program* in, const DataMap& data) {
ProgramBuilder out;
auto cfg = cfg_;