[glsl] Add benchmark for IR generator
Bug: 42251044
Change-Id: Iaeb43d6f0c286dc67f2c4a8f110b9477ff106612
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/210055
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/glsl/writer/BUILD.bazel b/src/tint/lang/glsl/writer/BUILD.bazel
index 01fe256..c29e49b 100644
--- a/src/tint/lang/glsl/writer/BUILD.bazel
+++ b/src/tint/lang/glsl/writer/BUILD.bazel
@@ -162,11 +162,14 @@
"//src/tint/api/common",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
+ "//src/tint/lang/core/ir",
"//src/tint/lang/core/type",
"//src/tint/lang/wgsl",
"//src/tint/lang/wgsl/ast",
"//src/tint/lang/wgsl/ast/transform",
+ "//src/tint/lang/wgsl/common",
"//src/tint/lang/wgsl/features",
+ "//src/tint/lang/wgsl/inspector",
"//src/tint/lang/wgsl/program",
"//src/tint/lang/wgsl/sem",
"//src/tint/utils/containers",
@@ -188,11 +191,13 @@
":tint_build_glsl_writer": [
"//src/tint/lang/glsl/writer",
"//src/tint/lang/glsl/writer/common",
+ "//src/tint/lang/glsl/writer/helpers",
],
"//conditions:default": [],
}) + select({
":tint_build_wgsl_reader": [
"//src/tint/cmd/bench:bench",
+ "//src/tint/lang/wgsl/reader",
],
"//conditions:default": [],
}),
diff --git a/src/tint/lang/glsl/writer/BUILD.cmake b/src/tint/lang/glsl/writer/BUILD.cmake
index 706cd98..3b5925e 100644
--- a/src/tint/lang/glsl/writer/BUILD.cmake
+++ b/src/tint/lang/glsl/writer/BUILD.cmake
@@ -181,11 +181,14 @@
tint_api_common
tint_lang_core
tint_lang_core_constant
+ tint_lang_core_ir
tint_lang_core_type
tint_lang_wgsl
tint_lang_wgsl_ast
tint_lang_wgsl_ast_transform
+ tint_lang_wgsl_common
tint_lang_wgsl_features
+ tint_lang_wgsl_inspector
tint_lang_wgsl_program
tint_lang_wgsl_sem
tint_utils_containers
@@ -212,12 +215,14 @@
tint_target_add_dependencies(tint_lang_glsl_writer_bench bench
tint_lang_glsl_writer
tint_lang_glsl_writer_common
+ tint_lang_glsl_writer_helpers
)
endif(TINT_BUILD_GLSL_WRITER)
if(TINT_BUILD_WGSL_READER)
tint_target_add_dependencies(tint_lang_glsl_writer_bench bench
tint_cmd_bench_bench
+ tint_lang_wgsl_reader
)
endif(TINT_BUILD_WGSL_READER)
diff --git a/src/tint/lang/glsl/writer/BUILD.gn b/src/tint/lang/glsl/writer/BUILD.gn
index 0a98298..fd304f2 100644
--- a/src/tint/lang/glsl/writer/BUILD.gn
+++ b/src/tint/lang/glsl/writer/BUILD.gn
@@ -160,11 +160,14 @@
"${tint_src_dir}/api/common",
"${tint_src_dir}/lang/core",
"${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/ir",
"${tint_src_dir}/lang/core/type",
"${tint_src_dir}/lang/wgsl",
"${tint_src_dir}/lang/wgsl/ast",
"${tint_src_dir}/lang/wgsl/ast/transform",
+ "${tint_src_dir}/lang/wgsl/common",
"${tint_src_dir}/lang/wgsl/features",
+ "${tint_src_dir}/lang/wgsl/inspector",
"${tint_src_dir}/lang/wgsl/program",
"${tint_src_dir}/lang/wgsl/sem",
"${tint_src_dir}/utils/containers",
@@ -186,11 +189,15 @@
deps += [
"${tint_src_dir}/lang/glsl/writer",
"${tint_src_dir}/lang/glsl/writer/common",
+ "${tint_src_dir}/lang/glsl/writer/helpers",
]
}
if (tint_build_wgsl_reader) {
- deps += [ "${tint_src_dir}/cmd/bench:bench" ]
+ deps += [
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/wgsl/reader",
+ ]
}
}
}
diff --git a/src/tint/lang/glsl/writer/writer_bench.cc b/src/tint/lang/glsl/writer/writer_bench.cc
index 2b54db8..f4418e4 100644
--- a/src/tint/lang/glsl/writer/writer_bench.cc
+++ b/src/tint/lang/glsl/writer/writer_bench.cc
@@ -28,13 +28,78 @@
#include <string>
#include "src/tint/cmd/bench/bench.h"
+#include "src/tint/lang/glsl/writer/helpers/generate_bindings.h"
#include "src/tint/lang/glsl/writer/writer.h"
#include "src/tint/lang/wgsl/ast/identifier.h"
#include "src/tint/lang/wgsl/ast/module.h"
+#include "src/tint/lang/wgsl/ast/transform/manager.h"
+#include "src/tint/lang/wgsl/ast/transform/single_entry_point.h"
+#include "src/tint/lang/wgsl/inspector/inspector.h"
+#include "src/tint/lang/wgsl/reader/reader.h"
namespace tint::glsl::writer {
namespace {
+void GenerateGLSL(benchmark::State& state, std::string input_name) {
+ auto res = bench::GetWgslProgram(input_name);
+ if (res != Success) {
+ state.SkipWithError(res.Failure().reason.Str());
+ return;
+ }
+
+ // Generate the input program and generator options for each entry point.
+ std::vector<Program> programs;
+ std::vector<Options> options;
+ std::vector<std::string> names;
+ tint::inspector::Inspector inspector(res->program);
+ for (auto ep : inspector.GetEntryPoints()) {
+ tint::glsl::writer::Options gen_options = {};
+ gen_options.bindings = tint::glsl::writer::GenerateBindings(res->program);
+ gen_options.bindings.texture_builtins_from_uniform.ubo_binding = {4u, 0u};
+
+ auto textureBuiltinsFromUniformData = inspector.GetTextureQueries(ep.name);
+ if (!textureBuiltinsFromUniformData.empty()) {
+ for (size_t i = 0; i < textureBuiltinsFromUniformData.size(); ++i) {
+ const auto& info = textureBuiltinsFromUniformData[i];
+
+ // This is the unmodified binding point from the WGSL shader.
+ tint::BindingPoint srcBindingPoint{info.group, info.binding};
+ gen_options.bindings.texture_builtins_from_uniform.ubo_bindingpoint_ordering
+ .emplace_back(srcBindingPoint);
+ }
+ }
+
+ // Run single entry point to strip the program down to a single entry point.
+ tint::ast::transform::Manager manager;
+ tint::ast::transform::DataMap inputs;
+ tint::ast::transform::DataMap outputs;
+ inputs.Add<tint::ast::transform::SingleEntryPoint::Config>(ep.name);
+ manager.Add<tint::ast::transform::SingleEntryPoint>();
+ auto program = manager.Run(res->program, inputs, outputs);
+
+ programs.push_back(std::move(program));
+ options.push_back(gen_options);
+ names.push_back(ep.name);
+ }
+
+ for (auto _ : state) {
+ for (uint32_t i = 0; i < programs.size(); i++) {
+ // Convert the AST program to an IR module.
+ auto ir = tint::wgsl::reader::ProgramToLoweredIR(programs[i]);
+ if (ir != Success) {
+ state.SkipWithError(ir.Failure().reason.Str());
+ return;
+ }
+
+ // Generate GLSL.
+ auto gen_res = Generate(ir.Get(), options[i], names[i]);
+ if (gen_res != Success) {
+ state.SkipWithError(gen_res.Failure().reason.Str());
+ }
+ }
+ }
+}
+
void GenerateGLSL_AST(benchmark::State& state, std::string input_name) {
auto res = bench::GetWgslProgram(input_name);
if (res != Success) {
@@ -59,6 +124,7 @@
}
}
+TINT_BENCHMARK_PROGRAMS(GenerateGLSL);
TINT_BENCHMARK_PROGRAMS(GenerateGLSL_AST);
} // namespace