[transform] Add transforms to the sample app.

This CL extends the sample app to allow running the bound array accessor
transform.

Bug: tint:206
Change-Id: I226a947a2e0a9e0945aa044b2847b4fd62b7c277
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29122
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-09-30 00:05:23 +00:00 committed by Commit Bot service account
parent af780816ca
commit 70b4c3baad
2 changed files with 47 additions and 0 deletions

View File

@ -21,6 +21,8 @@
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
#include "src/context.h" #include "src/context.h"
#include "src/reader/reader.h" #include "src/reader/reader.h"
#include "src/transform/bound_array_accessors_transform.h"
#include "src/transform/manager.h"
#include "src/transform/vertex_pulling_transform.h" #include "src/transform/vertex_pulling_transform.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/type_manager.h" #include "src/type_manager.h"

View File

@ -16,6 +16,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -50,6 +51,8 @@ struct Options {
bool emit_single_entry_point = false; bool emit_single_entry_point = false;
tint::ast::PipelineStage stage; tint::ast::PipelineStage stage;
std::string ep_name; std::string ep_name;
std::vector<std::string> transforms;
}; };
const char kUsage[] = R"(Usage: tint [options] <input-file> const char kUsage[] = R"(Usage: tint [options] <input-file>
@ -67,6 +70,9 @@ const char kUsage[] = R"(Usage: tint [options] <input-file>
-ep <compute|fragment|vertex> <name> -- Output single entry point -ep <compute|fragment|vertex> <name> -- Output single entry point
--output-file <name> -- Output file name. Use "-" for standard output --output-file <name> -- Output file name. Use "-" for standard output
-o <name> -- Output file name. Use "-" for standard output -o <name> -- Output file name. Use "-" for standard output
--transform <name list> -- Runs transformers, name list is comma separated
Available transforms:
bound_array_accessors
--parse-only -- Stop after parsing the input --parse-only -- Stop after parsing the input
--dump-ast -- Dump the generated AST to stdout --dump-ast -- Dump the generated AST to stdout
-h -- This help text)"; -h -- This help text)";
@ -156,6 +162,18 @@ tint::ast::PipelineStage convert_to_pipeline_stage(const std::string& name) {
return tint::ast::PipelineStage::kNone; return tint::ast::PipelineStage::kNone;
} }
std::vector<std::string> split_transform_names(std::string list) {
std::vector<std::string> res;
std::stringstream str(list);
while (str.good()) {
std::string substr;
getline(str, substr, ',');
res.push_back(substr);
}
return res;
}
bool ParseArgs(const std::vector<std::string>& args, Options* opts) { bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
for (size_t i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
const std::string& arg = args[i]; const std::string& arg = args[i];
@ -197,6 +215,13 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
} else if (arg == "-h" || arg == "--help") { } else if (arg == "-h" || arg == "--help") {
opts->show_help = true; opts->show_help = true;
} else if (arg == "--transform") {
++i;
if (i >= args.size()) {
std::cerr << "Missing value for " << arg << std::endl;
return false;
}
opts->transforms = split_transform_names(args[i]);
} else if (arg == "--parse-only") { } else if (arg == "--parse-only") {
opts->parse_only = true; opts->parse_only = true;
} else if (arg == "--dump-ast") { } else if (arg == "--dump-ast") {
@ -474,6 +499,26 @@ int main(int argc, const char** argv) {
return 1; return 1;
} }
tint::transform::Manager transform_manager;
for (const auto& name : options.transforms) {
// TODO(dsinclair): The vertex pulling transform requires setup code to
// be run that needs user input. Should we find a way to support that here
// maybe through a provided file?
if (name == "bound_array_accessors") {
transform_manager.append(
std::make_unique<tint::transform::BoundArrayAccessorsTransform>(
&ctx, &mod));
} else {
std::cerr << "Unknown transform name: " << name << std::endl;
return 1;
}
}
if (!transform_manager.Run()) {
std::cerr << "Transformer: " << transform_manager.error() << std::endl;
return 1;
}
std::unique_ptr<tint::writer::Writer> writer; std::unique_ptr<tint::writer::Writer> writer;
#if TINT_BUILD_SPV_WRITER #if TINT_BUILD_SPV_WRITER