Add transform to strip entry points from a module

Remove the Generator::GenerateEntryPoint() APIs as they were mostly
unimplemented and not used by anything except the Tint sample app,
which now uses the new transform.

Change-Id: I1ccb303d6c3aa15e622c193d33b753e22bf39a95
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price
2021-04-28 15:33:03 +00:00
committed by Commit Bot service account
parent f5f311e264
commit 0949bdf68f
20 changed files with 577 additions and 258 deletions

View File

@@ -59,7 +59,6 @@ struct Options {
Format format = Format::kNone;
bool emit_single_entry_point = false;
tint::ast::PipelineStage stage;
std::string ep_name;
std::vector<std::string> transforms;
@@ -77,7 +76,7 @@ const char kUsage[] = R"(Usage: tint [options] <input-file>
.metal -> msl
.hlsl -> hlsl
If none matches, then default to SPIR-V assembly.
-ep <compute|fragment|vertex> <name> -- Output single entry point
-ep <name> -- Output single entry point
--output-file <name> -- Output file name. Use "-" for standard output
-o <name> -- Output file name. Use "-" for standard output
--transform <name list> -- Runs transforms, name list is comma separated
@@ -185,19 +184,6 @@ Format infer_format(const std::string& filename) {
return Format::kNone;
}
tint::ast::PipelineStage convert_to_pipeline_stage(const std::string& name) {
if (name == "compute") {
return tint::ast::PipelineStage::kCompute;
}
if (name == "fragment") {
return tint::ast::PipelineStage::kFragment;
}
if (name == "vertex") {
return tint::ast::PipelineStage::kVertex;
}
return tint::ast::PipelineStage::kNone;
}
std::vector<std::string> split_transform_names(std::string list) {
std::vector<std::string> res;
@@ -373,17 +359,10 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
return false;
}
} else if (arg == "-ep") {
if (i + 2 >= args.size()) {
std::cerr << "Missing values for -ep" << std::endl;
if (i + 1 >= args.size()) {
std::cerr << "Missing value for -ep" << std::endl;
return false;
}
i++;
opts->stage = convert_to_pipeline_stage(args[i]);
if (opts->stage == tint::ast::PipelineStage::kNone) {
std::cerr << "Invalid pipeline stage: " << args[i] << std::endl;
return false;
}
i++;
opts->ep_name = args[i];
opts->emit_single_entry_point = true;
@@ -697,6 +676,13 @@ int main(int argc, const char** argv) {
}
}
if (options.emit_single_entry_point) {
transform_manager.append(
std::make_unique<tint::transform::SingleEntryPoint>());
transform_inputs.Add<tint::transform::SingleEntryPoint::Config>(
options.ep_name);
}
switch (options.format) {
#if TINT_BUILD_SPV_WRITER
case Format::kSpirv:
@@ -801,16 +787,9 @@ int main(int argc, const char** argv) {
return 1;
}
if (options.emit_single_entry_point) {
if (!writer->GenerateEntryPoint(options.stage, options.ep_name)) {
std::cerr << "Failed to generate: " << writer->error() << std::endl;
return 1;
}
} else {
if (!writer->Generate()) {
std::cerr << "Failed to generate: " << writer->error() << std::endl;
return 1;
}
if (!writer->Generate()) {
std::cerr << "Failed to generate: " << writer->error() << std::endl;
return 1;
}
#if TINT_BUILD_SPV_WRITER