[tint][build] Generate benchmarks for GN and Bazel
These were not emitted, or were emitted incorrectly.
Aside from fuzzers, CMake, GN and Bazel now all generate the same executable, library, test and benchmark targets.
Change-Id: I88c115d4fb974755fc7c476694f4ef79d6e18e49
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/150860
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index fef2890..b8e3c10 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -32,7 +32,7 @@
"src/tint/api",
]
if (tint_build_unittests) {
- deps += [ "src/tint/cmd/test" ]
+ deps += [ "src/tint/cmd/test:test_cmd" ]
}
if (dawn_standalone) {
deps += [
diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel
index 36422e3..21d9817 100644
--- a/WORKSPACE.bazel
+++ b/WORKSPACE.bazel
@@ -28,6 +28,11 @@
)
local_repository(
+ name = "benchmark",
+ path = "third_party/google_benchmark/src",
+)
+
+local_repository(
name = "gtest",
path = "third_party/googletest",
)
diff --git a/docs/tint/gen.md b/docs/tint/gen.md
index c566275..7c7a48a 100644
--- a/docs/tint/gen.md
+++ b/docs/tint/gen.md
@@ -31,19 +31,23 @@
production code.
* `bench_cmd` are benchmark executables.
-The build generator uses a file naming convention to classify each source file to a single target kind:
+The build generator uses a file naming convention based on the file name before the extension to classify each source file to a single target kind.
-* Source files with a `_test` suffix before the file extension are classed as
- `test` library targets. Example: `parser_test.cc`.
-* Source files with a `_bench` suffix before the file extension are classed as
- `bench` library targets. Example: `writer_bench.cc`.
-* Source files with the name `main.cc` are classed as executable targets.
- These typically exist under `src/tint/cmd`. Example: `cmd/tint/main.cc`.
-* Source files with the name `main_test.cc` are classed as test executable targets.
- These typically exist under `src/tint/cmd`. Example: `cmd/test/main_test.cc`.
-* Source files with the name `main_bench.cc` are classed as benchmark executable targets.
- These typically exist under `src/tint/cmd`. Example: `cmd/benchmark/main_bench.cc`.
-* All other files are considered `lib` targets. Example: `parser.cc`.
+* Source files named `test` or with a `_test` suffix are classed as `test` library targets. \
+ Example: `parser_test.cc`.
+* Source files named `bench` or with a `_bench` suffix are classed as `bench` library targets. \
+ Example: `writer_bench.cc`.
+* Source files with the name `main` are classed as executable targets.
+ These typically exist under `src/tint/cmd`. \
+ Example: `cmd/tint/main.cc`.
+* Source files with the name `main_test` are classed as test executable targets.
+ These typically exist under `src/tint/cmd`. \
+ Example: `cmd/test/main_test.cc`.
+* Source files with the name `main_bench` are classed as benchmark executable targets.
+ These typically exist under `src/tint/cmd`. \
+ Example: `cmd/benchmark/main_bench.cc`.
+* All other files are considered `lib` targets. \
+ Example: `parser.cc`.
Each source directory can have at most one `lib`, `test`, `test_main`, `bench`, `bench_main` or `cmd`
target.
diff --git a/scripts/tint_overrides_with_defaults.gni b/scripts/tint_overrides_with_defaults.gni
index 7e2a646..df509f1 100644
--- a/scripts/tint_overrides_with_defaults.gni
+++ b/scripts/tint_overrides_with_defaults.gni
@@ -86,6 +86,11 @@
if (!defined(tint_build_unittests)) {
tint_build_unittests = true
}
+
+ # Build benchmarks
+ if (!defined(tint_build_benchmarks)) {
+ tint_build_benchmarks = true
+ }
}
declare_args() {
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index d6570a1..2daaf3e 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -194,6 +194,16 @@
}
}
+if (tint_build_benchmarks) {
+ group("google_benchmark") {
+ testonly = true
+ public_deps = [
+ "//third_party/google_benchmark",
+ "//third_party/google_benchmark:benchmark_main",
+ ]
+ }
+}
+
group("abseil") {
# When build_with_chromium=true we need to include "//third_party/abseil-cpp:absl" while
# it's beneficial to be more specific with standalone Dawn, especially when it comes to
@@ -215,6 +225,6 @@
if (tint_build_unittests) {
group("tint_unittests") {
testonly = true
- public_deps = [ "${tint_src_dir}/cmd/test" ]
+ public_deps = [ "${tint_src_dir}/cmd/test:test_cmd" ]
}
}
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index b839535..aa88e1a 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -175,13 +175,6 @@
function(tint_bench_compile_options TARGET)
tint_core_compile_options(${TARGET})
- set_target_properties(${TARGET} PROPERTIES FOLDER "Benchmarks")
- target_link_libraries(${TARGET} PRIVATE benchmark::benchmark)
- if(TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER)
- target_compile_definitions(${TARGET} PRIVATE
- "TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER=\"${TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER}\""
- )
- endif()
endfunction()
function(tint_fuzz_compile_options TARGET)
@@ -456,6 +449,14 @@
target_link_libraries(${TARGET} PRIVATE
glslang-default-resource-limits
)
+ elseif(${DEPENDENCY} STREQUAL "google-benchmark")
+ set_target_properties(${TARGET} PROPERTIES FOLDER "Benchmarks")
+ target_link_libraries(${TARGET} PRIVATE benchmark::benchmark)
+ if(TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER)
+ target_compile_definitions(${TARGET} PRIVATE
+ "TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER=\"${TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER}\""
+ )
+ endif()
elseif(${DEPENDENCY} STREQUAL "gtest")
target_include_directories(${TARGET} PRIVATE ${gmock_SOURCE_DIR}/include)
target_link_libraries(${TARGET} PRIVATE gmock)
diff --git a/src/tint/cmd/bench/BUILD.bazel b/src/tint/cmd/bench/BUILD.bazel
index 62a4335..19f7f9b 100644
--- a/src/tint/cmd/bench/BUILD.bazel
+++ b/src/tint/cmd/bench/BUILD.bazel
@@ -25,59 +25,24 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
- "benchmark.cc",
- ],
- hdrs = [
+ "bench.cc",
"bench.h",
],
deps = [
- "//src/tint/lang/core",
- "//src/tint/lang/core/constant",
- "//src/tint/lang/core/type",
- "//src/tint/lang/wgsl",
- "//src/tint/lang/wgsl/ast",
- "//src/tint/lang/wgsl/program",
- "//src/tint/lang/wgsl/sem",
- "//src/tint/utils/containers",
- "//src/tint/utils/diagnostic",
- "//src/tint/utils/ice",
- "//src/tint/utils/id",
- "//src/tint/utils/macros",
- "//src/tint/utils/math",
- "//src/tint/utils/memory",
- "//src/tint/utils/result",
- "//src/tint/utils/rtti",
- "//src/tint/utils/symbol",
- "//src/tint/utils/text",
- "//src/tint/utils/traits",
- ],
- copts = COPTS,
- visibility = ["//visibility:public"],
-)
-cc_binary(
- name = "bench_cmd",
- srcs = [
- "main_bench.cc",
- ],
- deps = [
"//src/tint/api/common",
- "//src/tint/cmd/bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/ir",
"//src/tint/lang/core/type",
- "//src/tint/lang/core:bench",
"//src/tint/lang/spirv/reader/common",
"//src/tint/lang/wgsl",
"//src/tint/lang/wgsl/ast",
"//src/tint/lang/wgsl/program",
"//src/tint/lang/wgsl/reader",
- "//src/tint/lang/wgsl/reader:bench",
"//src/tint/lang/wgsl/sem",
"//src/tint/lang/wgsl/writer",
- "//src/tint/lang/wgsl/writer:bench",
- "//src/tint/lang/wgsl:bench",
"//src/tint/utils/containers",
"//src/tint/utils/diagnostic",
"//src/tint/utils/ice",
@@ -88,10 +53,51 @@
"//src/tint/utils/reflection",
"//src/tint/utils/result",
"//src/tint/utils/rtti",
+ "//src/tint/utils/symbol",
+ "//src/tint/utils/text",
+ "//src/tint/utils/traits",
+ "@benchmark",
+ ] + select({
+ ":tint_build_spv_reader": [
+ "//src/tint/lang/spirv/reader",
+ ],
+ "//conditions:default": [],
+ }),
+ copts = COPTS,
+ visibility = ["//visibility:public"],
+)
+cc_binary(
+ name = "bench_cmd",
+ srcs = [
+ "main_bench.cc",
+ ],
+ deps = [
+ "//src/tint/cmd/bench:bench",
+ "//src/tint/lang/core",
+ "//src/tint/lang/core/constant",
+ "//src/tint/lang/core/type",
+ "//src/tint/lang/core:bench",
+ "//src/tint/lang/wgsl",
+ "//src/tint/lang/wgsl/ast",
+ "//src/tint/lang/wgsl/program",
+ "//src/tint/lang/wgsl/reader:bench",
+ "//src/tint/lang/wgsl/sem",
+ "//src/tint/lang/wgsl/writer:bench",
+ "//src/tint/lang/wgsl:bench",
+ "//src/tint/utils/containers",
+ "//src/tint/utils/diagnostic",
+ "//src/tint/utils/ice",
+ "//src/tint/utils/id",
+ "//src/tint/utils/macros",
+ "//src/tint/utils/math",
+ "//src/tint/utils/memory",
+ "//src/tint/utils/result",
+ "//src/tint/utils/rtti",
"//src/tint/utils/rtti:bench",
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
] + select({
":tint_build_glsl_writer": [
"//src/tint/lang/glsl/writer:bench",
@@ -108,11 +114,6 @@
],
"//conditions:default": [],
}) + select({
- ":tint_build_spv_reader": [
- "//src/tint/lang/spirv/reader",
- ],
- "//conditions:default": [],
- }) + select({
":tint_build_spv_writer": [
"//src/tint/lang/spirv/writer:bench",
],
diff --git a/src/tint/cmd/bench/BUILD.cmake b/src/tint/cmd/bench/BUILD.cmake
index a6da553..f832dcc 100644
--- a/src/tint/cmd/bench/BUILD.cmake
+++ b/src/tint/cmd/bench/BUILD.cmake
@@ -22,37 +22,6 @@
################################################################################
################################################################################
-# Target: tint_cmd_bench
-# Kind: lib
-################################################################################
-tint_add_target(tint_cmd_bench lib
- cmd/bench/bench.h
- cmd/bench/benchmark.cc
-)
-
-tint_target_add_dependencies(tint_cmd_bench lib
- tint_lang_core
- tint_lang_core_constant
- tint_lang_core_type
- tint_lang_wgsl
- tint_lang_wgsl_ast
- tint_lang_wgsl_program
- tint_lang_wgsl_sem
- tint_utils_containers
- tint_utils_diagnostic
- tint_utils_ice
- tint_utils_id
- tint_utils_macros
- tint_utils_math
- tint_utils_memory
- tint_utils_result
- tint_utils_rtti
- tint_utils_symbol
- tint_utils_text
- tint_utils_traits
-)
-
-################################################################################
# Target: tint_cmd_bench_bench_cmd
# Kind: bench_cmd
################################################################################
@@ -61,21 +30,16 @@
)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
- tint_api_common
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
- tint_lang_core_ir
tint_lang_core_type
tint_lang_core_bench
- tint_lang_spirv_reader_common
tint_lang_wgsl
tint_lang_wgsl_ast
tint_lang_wgsl_program
- tint_lang_wgsl_reader
tint_lang_wgsl_reader_bench
tint_lang_wgsl_sem
- tint_lang_wgsl_writer
tint_lang_wgsl_writer_bench
tint_lang_wgsl_bench
tint_utils_containers
@@ -85,7 +49,6 @@
tint_utils_macros
tint_utils_math
tint_utils_memory
- tint_utils_reflection
tint_utils_result
tint_utils_rtti
tint_utils_rtti_bench
@@ -94,6 +57,10 @@
tint_utils_traits
)
+tint_target_add_external_dependencies(tint_cmd_bench_bench_cmd bench_cmd
+ "google-benchmark"
+)
+
if(TINT_BUILD_GLSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_glsl_writer_bench
@@ -112,12 +79,6 @@
)
endif(TINT_BUILD_MSL_WRITER)
-if(TINT_BUILD_SPV_READER)
- tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
- tint_lang_spirv_reader
- )
-endif(TINT_BUILD_SPV_READER)
-
if(TINT_BUILD_SPV_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_spirv_writer_bench
@@ -125,3 +86,50 @@
endif(TINT_BUILD_SPV_WRITER)
tint_target_set_output_name(tint_cmd_bench_bench_cmd bench_cmd "tint_benchmark")
+
+################################################################################
+# Target: tint_cmd_bench_bench
+# Kind: bench
+################################################################################
+tint_add_target(tint_cmd_bench_bench bench
+ cmd/bench/bench.cc
+ cmd/bench/bench.h
+)
+
+tint_target_add_dependencies(tint_cmd_bench_bench bench
+ tint_api_common
+ tint_lang_core
+ tint_lang_core_constant
+ tint_lang_core_ir
+ tint_lang_core_type
+ tint_lang_spirv_reader_common
+ tint_lang_wgsl
+ tint_lang_wgsl_ast
+ tint_lang_wgsl_program
+ tint_lang_wgsl_reader
+ tint_lang_wgsl_sem
+ tint_lang_wgsl_writer
+ tint_utils_containers
+ tint_utils_diagnostic
+ tint_utils_ice
+ tint_utils_id
+ tint_utils_macros
+ tint_utils_math
+ tint_utils_memory
+ tint_utils_reflection
+ tint_utils_result
+ tint_utils_rtti
+ tint_utils_symbol
+ tint_utils_text
+ tint_utils_traits
+)
+
+tint_target_add_external_dependencies(tint_cmd_bench_bench bench
+ "google-benchmark"
+)
+
+if(TINT_BUILD_SPV_READER)
+ tint_target_add_dependencies(tint_cmd_bench_bench bench
+ tint_lang_spirv_reader
+ )
+endif(TINT_BUILD_SPV_READER)
diff --git a/src/tint/cmd/bench/BUILD.gn b/src/tint/cmd/bench/BUILD.gn
index e17e2de..e47181c 100644
--- a/src/tint/cmd/bench/BUILD.gn
+++ b/src/tint/cmd/bench/BUILD.gn
@@ -25,30 +25,98 @@
import("${tint_src_dir}/tint.gni")
-libtint_source_set("bench") {
- sources = [
- "bench.h",
- "benchmark.cc",
- ]
- deps = [
- "${tint_src_dir}/lang/core",
- "${tint_src_dir}/lang/core/constant",
- "${tint_src_dir}/lang/core/type",
- "${tint_src_dir}/lang/wgsl",
- "${tint_src_dir}/lang/wgsl/ast",
- "${tint_src_dir}/lang/wgsl/program",
- "${tint_src_dir}/lang/wgsl/sem",
- "${tint_src_dir}/utils/containers",
- "${tint_src_dir}/utils/diagnostic",
- "${tint_src_dir}/utils/ice",
- "${tint_src_dir}/utils/id",
- "${tint_src_dir}/utils/macros",
- "${tint_src_dir}/utils/math",
- "${tint_src_dir}/utils/memory",
- "${tint_src_dir}/utils/result",
- "${tint_src_dir}/utils/rtti",
- "${tint_src_dir}/utils/symbol",
- "${tint_src_dir}/utils/text",
- "${tint_src_dir}/utils/traits",
- ]
+if (tint_build_unittests || tint_build_benchmarks) {
+ import("//testing/test.gni")
+}
+if (tint_build_benchmarks) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [
+ "bench.cc",
+ "bench.h",
+ ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${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/spirv/reader/common",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/reader",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/lang/wgsl/writer",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_spv_reader) {
+ deps += [ "${tint_src_dir}/lang/spirv/reader" ]
+ }
+ }
+}
+if (tint_build_benchmarks) {
+ test("bench_cmd") {
+ testonly = true
+ output_name = "tint_benchmark"
+ sources = [ "main_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core:bench",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl:bench",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/reader:bench",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/lang/wgsl/writer:bench",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/rtti:bench",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_glsl_writer) {
+ deps += [ "${tint_src_dir}/lang/glsl/writer:bench" ]
+ }
+
+ if (tint_build_hlsl_writer) {
+ deps += [ "${tint_src_dir}/lang/hlsl/writer:bench" ]
+ }
+
+ if (tint_build_msl_writer) {
+ deps += [ "${tint_src_dir}/lang/msl/writer:bench" ]
+ }
+
+ if (tint_build_spv_writer) {
+ deps += [ "${tint_src_dir}/lang/spirv/writer:bench" ]
+ }
+ }
}
diff --git a/src/tint/cmd/bench/bench.cc b/src/tint/cmd/bench/bench.cc
new file mode 100644
index 0000000..f9cb65e
--- /dev/null
+++ b/src/tint/cmd/bench/bench.cc
@@ -0,0 +1,142 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <filesystem>
+#include <iostream>
+#include <utility>
+#include <vector>
+
+#include "src/tint/cmd/bench/bench.h"
+#include "src/tint/lang/spirv/reader/reader.h"
+#include "src/tint/lang/wgsl/reader/reader.h"
+#include "src/tint/lang/wgsl/writer/writer.h"
+#include "src/tint/utils/text/string.h"
+#include "src/tint/utils/text/string_stream.h"
+
+namespace tint::bench {
+namespace {
+
+std::filesystem::path kInputFileDir;
+
+/// Copies the content from the file named `input_file` to `buffer`,
+/// assuming each element in the file is of type `T`. If any error occurs,
+/// writes error messages to the standard error stream and returns false.
+/// Assumes the size of a `T` object is divisible by its required alignment.
+/// @returns true if we successfully read the file.
+template <typename T>
+Result<std::vector<T>> ReadFile(const std::string& input_file) {
+ FILE* file = nullptr;
+#if defined(_MSC_VER)
+ fopen_s(&file, input_file.c_str(), "rb");
+#else
+ file = fopen(input_file.c_str(), "rb");
+#endif
+ if (!file) {
+ return Failure{"Failed to open " + input_file};
+ }
+
+ fseek(file, 0, SEEK_END);
+ const auto file_size = static_cast<size_t>(ftell(file));
+ if (0 != (file_size % sizeof(T))) {
+ StringStream err;
+ err << "File " << input_file
+ << " does not contain an integral number of objects: " << file_size
+ << " bytes in the file, require " << sizeof(T) << " bytes per object";
+ fclose(file);
+ return Failure{err.str()};
+ }
+ fseek(file, 0, SEEK_SET);
+
+ std::vector<T> buffer;
+ buffer.resize(file_size / sizeof(T));
+
+ size_t bytes_read = fread(buffer.data(), 1, file_size, file);
+ fclose(file);
+ if (bytes_read != file_size) {
+ return Failure{"Failed to read " + input_file};
+ }
+
+ return buffer;
+}
+
+bool FindBenchmarkInputDir() {
+ // Attempt to find the benchmark input files by searching up from the current
+ // working directory.
+ auto path = std::filesystem::current_path();
+ while (std::filesystem::is_directory(path)) {
+ auto test = path / "test" / "tint" / "benchmark";
+ if (std::filesystem::is_directory(test)) {
+ kInputFileDir = test;
+ return true;
+ }
+ auto parent = path.parent_path();
+ if (path == parent) {
+ break;
+ }
+ path = parent;
+ }
+ return false;
+}
+
+} // namespace
+
+bool Initialize() {
+ if (!FindBenchmarkInputDir()) {
+ std::cerr << "failed to locate benchmark input files" << std::endl;
+ return false;
+ }
+ return true;
+}
+
+Result<Source::File> LoadInputFile(std::string name) {
+ auto path = std::filesystem::path(name).is_absolute() ? name : (kInputFileDir / name).string();
+ if (tint::HasSuffix(path, ".wgsl")) {
+ auto data = ReadFile<uint8_t>(path);
+ if (!data) {
+ return data.Failure();
+ }
+ return tint::Source::File(path, std::string(data->begin(), data->end()));
+ }
+ if (tint::HasSuffix(path, ".spv")) {
+ auto spirv = ReadFile<uint32_t>(path);
+ if (spirv) {
+ auto program = tint::spirv::reader::Read(spirv.Get(), {});
+ if (!program.IsValid()) {
+ return Failure{program.Diagnostics()};
+ }
+ auto result = tint::wgsl::writer::Generate(program, {});
+ if (!result) {
+ return result.Failure();
+ }
+ return tint::Source::File(path, result->wgsl);
+ }
+ return spirv.Failure();
+ }
+ return Failure{"unsupported file extension: '" + name + "'"};
+}
+
+Result<ProgramAndFile> LoadProgram(std::string name) {
+ auto res = bench::LoadInputFile(name);
+ if (!res) {
+ return res.Failure();
+ }
+ auto file = std::make_unique<Source::File>(res.Get());
+ auto program = wgsl::reader::Parse(file.get());
+ if (!program.IsValid()) {
+ return Failure{program.Diagnostics()};
+ }
+ return ProgramAndFile{std::move(program), std::move(file)};
+}
+
+} // namespace tint::bench
diff --git a/src/tint/cmd/bench/bench.h b/src/tint/cmd/bench/bench.h
index e813c4a..fc15e20 100644
--- a/src/tint/cmd/bench/bench.h
+++ b/src/tint/cmd/bench/bench.h
@@ -21,16 +21,12 @@
#include "benchmark/benchmark.h"
#include "src/tint/lang/wgsl/program/program.h"
+#include "src/tint/utils/macros/compiler.h"
#include "src/tint/utils/macros/concat.h"
+#include "src/tint/utils/result/result.h"
namespace tint::bench {
-/// Error indicates an operation did not complete successfully.
-struct Error {
- /// The error message.
- std::string msg;
-};
-
/// ProgramAndFile holds a Program and a Source::File.
struct ProgramAndFile {
/// The tint program parsed from file.
@@ -39,18 +35,23 @@
std::unique_ptr<Source::File> file;
};
+/// Initializes the internal state for benchmarking.
+/// Must be called once by the benchmark executable entry point.
+/// @returns true on success, false of failure
+bool Initialize();
+
/// LoadInputFile attempts to load a benchmark input file with the given file
/// name. Accepts files with the .wgsl and .spv extension.
/// SPIR-V files are automatically converted to WGSL.
/// @param name the file name
-/// @returns either the loaded Source::File or an Error
-std::variant<Source::File, Error> LoadInputFile(std::string name);
+/// @returns the loaded Source::File
+Result<Source::File> LoadInputFile(std::string name);
/// LoadInputFile attempts to load a benchmark input program with the given file
/// name.
/// @param name the file name
-/// @returns either the loaded Program or an Error
-std::variant<ProgramAndFile, Error> LoadProgram(std::string name);
+/// @returns the loaded Program
+Result<ProgramAndFile> LoadProgram(std::string name);
// If TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER is defined, include that to
// declare the TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAMS() and TINT_BENCHMARK_EXTERNAL_SPV_PROGRAMS()
@@ -64,7 +65,7 @@
#endif
/// Declares a benchmark with the given function and WGSL file name
-#define TINT_BENCHMARK_WGSL_PROGRAM(FUNC, WGSL_NAME) BENCHMARK_CAPTURE(FUNC, WGSL_NAME, WGSL_NAME);
+#define TINT_BENCHMARK_WGSL_PROGRAM(FUNC, WGSL_NAME) BENCHMARK_CAPTURE(FUNC, WGSL_NAME, WGSL_NAME)
/// Declares a set of benchmarks for the given function using a list of WGSL files.
#define TINT_BENCHMARK_WGSL_PROGRAMS(FUNC) \
@@ -83,7 +84,8 @@
/// Declares a set of benchmarks for the given function using a list of WGSL and SPIR-V files.
#define TINT_BENCHMARK_PROGRAMS(FUNC) \
TINT_BENCHMARK_WGSL_PROGRAMS(FUNC) \
- TINT_BENCHMARK_SPV_PROGRAMS(FUNC)
+ TINT_BENCHMARK_SPV_PROGRAMS(FUNC) \
+ TINT_REQUIRE_SEMICOLON
} // namespace tint::bench
diff --git a/src/tint/cmd/bench/benchmark.cc b/src/tint/cmd/bench/benchmark.cc
deleted file mode 100644
index ad8658b..0000000
--- a/src/tint/cmd/bench/benchmark.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2023 The Tint Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
-#endif
-
-// A placeholder symbol used to emit a symbol for this lib target.
-int tint_cmd_bench_symbol = 1;
diff --git a/src/tint/cmd/bench/main_bench.cc b/src/tint/cmd/bench/main_bench.cc
index e04dc38..99d6c48 100644
--- a/src/tint/cmd/bench/main_bench.cc
+++ b/src/tint/cmd/bench/main_bench.cc
@@ -12,134 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include <filesystem>
-#include <iostream>
-#include <utility>
-#include <vector>
-
#include "src/tint/cmd/bench/bench.h"
-#include "src/tint/lang/spirv/reader/reader.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-#include "src/tint/utils/text/string.h"
-#include "src/tint/utils/text/string_stream.h"
-
-namespace tint::bench {
-namespace {
-
-std::filesystem::path kInputFileDir;
-
-/// Copies the content from the file named `input_file` to `buffer`,
-/// assuming each element in the file is of type `T`. If any error occurs,
-/// writes error messages to the standard error stream and returns false.
-/// Assumes the size of a `T` object is divisible by its required alignment.
-/// @returns true if we successfully read the file.
-template <typename T>
-std::variant<std::vector<T>, Error> ReadFile(const std::string& input_file) {
- FILE* file = nullptr;
-#if defined(_MSC_VER)
- fopen_s(&file, input_file.c_str(), "rb");
-#else
- file = fopen(input_file.c_str(), "rb");
-#endif
- if (!file) {
- return Error{"Failed to open " + input_file};
- }
-
- fseek(file, 0, SEEK_END);
- const auto file_size = static_cast<size_t>(ftell(file));
- if (0 != (file_size % sizeof(T))) {
- StringStream err;
- err << "File " << input_file
- << " does not contain an integral number of objects: " << file_size
- << " bytes in the file, require " << sizeof(T) << " bytes per object";
- fclose(file);
- return Error{err.str()};
- }
- fseek(file, 0, SEEK_SET);
-
- std::vector<T> buffer;
- buffer.resize(file_size / sizeof(T));
-
- size_t bytes_read = fread(buffer.data(), 1, file_size, file);
- fclose(file);
- if (bytes_read != file_size) {
- return Error{"Failed to read " + input_file};
- }
-
- return buffer;
-}
-
-bool FindBenchmarkInputDir() {
- // Attempt to find the benchmark input files by searching up from the current
- // working directory.
- auto path = std::filesystem::current_path();
- while (std::filesystem::is_directory(path)) {
- auto test = path / "test" / "tint" / "benchmark";
- if (std::filesystem::is_directory(test)) {
- kInputFileDir = test;
- return true;
- }
- auto parent = path.parent_path();
- if (path == parent) {
- break;
- }
- path = parent;
- }
- return false;
-}
-
-} // namespace
-
-std::variant<tint::Source::File, Error> LoadInputFile(std::string name) {
- auto path = std::filesystem::path(name).is_absolute() ? name : (kInputFileDir / name).string();
- if (tint::HasSuffix(path, ".wgsl")) {
- auto data = ReadFile<uint8_t>(path);
- if (auto* buf = std::get_if<std::vector<uint8_t>>(&data)) {
- return tint::Source::File(path, std::string(buf->begin(), buf->end()));
- }
- return std::get<Error>(data);
- }
- if (tint::HasSuffix(path, ".spv")) {
- auto spirv = ReadFile<uint32_t>(path);
- if (auto* buf = std::get_if<std::vector<uint32_t>>(&spirv)) {
- auto program = tint::spirv::reader::Read(*buf, {});
- if (!program.IsValid()) {
- return Error{program.Diagnostics().str()};
- }
- auto result = tint::wgsl::writer::Generate(program, {});
- if (!result) {
- return Error{result.Failure().reason.str()};
- }
- return tint::Source::File(path, result->wgsl);
- }
- return std::get<Error>(spirv);
- }
- return Error{"unsupported file extension: '" + name + "'"};
-}
-
-std::variant<ProgramAndFile, Error> LoadProgram(std::string name) {
- auto res = bench::LoadInputFile(name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- return *err;
- }
- auto file = std::make_unique<Source::File>(std::move(std::get<Source::File>(res)));
- auto program = wgsl::reader::Parse(file.get());
- if (program.Diagnostics().contains_errors()) {
- return Error{program.Diagnostics().str()};
- }
- return ProgramAndFile{std::move(program), std::move(file)};
-}
-
-} // namespace tint::bench
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
- if (!tint::bench::FindBenchmarkInputDir()) {
- std::cerr << "failed to locate benchmark input files" << std::endl;
+ if (!tint::bench::Initialize()) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
diff --git a/src/tint/cmd/common/BUILD.gn b/src/tint/cmd/common/BUILD.gn
index 5bca6c4..85d8874 100644
--- a/src/tint/cmd/common/BUILD.gn
+++ b/src/tint/cmd/common/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/cmd/test/BUILD.gn b/src/tint/cmd/test/BUILD.gn
index 5461cfb..469cd7e 100644
--- a/src/tint/cmd/test/BUILD.gn
+++ b/src/tint/cmd/test/BUILD.gn
@@ -25,11 +25,12 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_unittests) {
- test("test") {
+ test("test_cmd") {
+ testonly = true
output_name = "tint_unittests"
sources = [ "main_test.cc" ]
deps = [
@@ -116,7 +117,6 @@
"${tint_src_dir}/lang/spirv/writer/raise:unittests",
]
}
- testonly = true
configs += [ "${tint_src_dir}:tint_unittests_config" ]
if (build_with_chromium) {
diff --git a/src/tint/externals.json b/src/tint/externals.json
index 649a650..6cdd1b2 100644
--- a/src/tint/externals.json
+++ b/src/tint/externals.json
@@ -8,6 +8,11 @@
"absl/**"
],
},
+ "google-benchmark": {
+ "IncludePatterns": [
+ "benchmark/benchmark.h"
+ ]
+ },
"metal": {
"IncludePatterns": [
"Metal/Metal.h"
diff --git a/src/tint/lang/core/BUILD.bazel b/src/tint/lang/core/BUILD.bazel
index 8b4f3e9..f3b42a9 100644
--- a/src/tint/lang/core/BUILD.bazel
+++ b/src/tint/lang/core/BUILD.bazel
@@ -116,6 +116,7 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"access_bench.cc",
"address_space_bench.cc",
@@ -129,6 +130,7 @@
deps = [
"//src/tint/lang/core",
"//src/tint/utils/traits",
+ "@benchmark",
],
copts = COPTS,
visibility = ["//visibility:public"],
diff --git a/src/tint/lang/core/BUILD.cmake b/src/tint/lang/core/BUILD.cmake
index ec43104..3bc86ee 100644
--- a/src/tint/lang/core/BUILD.cmake
+++ b/src/tint/lang/core/BUILD.cmake
@@ -138,3 +138,7 @@
tint_lang_core
tint_utils_traits
)
+
+tint_target_add_external_dependencies(tint_lang_core_bench bench
+ "google-benchmark"
+)
diff --git a/src/tint/lang/core/BUILD.gn b/src/tint/lang/core/BUILD.gn
index 78c9e73..c4ae92e 100644
--- a/src/tint/lang/core/BUILD.gn
+++ b/src/tint/lang/core/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
@@ -114,3 +114,23 @@
]
}
}
+if (tint_build_benchmarks) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [
+ "access_bench.cc",
+ "address_space_bench.cc",
+ "attribute_bench.cc",
+ "builtin_type_bench.cc",
+ "builtin_value_bench.cc",
+ "interpolation_sampling_bench.cc",
+ "interpolation_type_bench.cc",
+ "texel_format_bench.cc",
+ ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/utils/traits",
+ ]
+ }
+}
diff --git a/src/tint/lang/core/constant/BUILD.gn b/src/tint/lang/core/constant/BUILD.gn
index 2f15285..e96fcd5 100644
--- a/src/tint/lang/core/constant/BUILD.gn
+++ b/src/tint/lang/core/constant/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/core/intrinsic/BUILD.gn b/src/tint/lang/core/intrinsic/BUILD.gn
index 2ee3356..679b2d5 100644
--- a/src/tint/lang/core/intrinsic/BUILD.gn
+++ b/src/tint/lang/core/intrinsic/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/core/ir/BUILD.gn b/src/tint/lang/core/ir/BUILD.gn
index ff12f1e..a092238 100644
--- a/src/tint/lang/core/ir/BUILD.gn
+++ b/src/tint/lang/core/ir/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/core/ir/transform/BUILD.gn b/src/tint/lang/core/ir/transform/BUILD.gn
index f6ce734..d6442c7 100644
--- a/src/tint/lang/core/ir/transform/BUILD.gn
+++ b/src/tint/lang/core/ir/transform/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/core/type/BUILD.gn b/src/tint/lang/core/type/BUILD.gn
index c80abf5..db47a50 100644
--- a/src/tint/lang/core/type/BUILD.gn
+++ b/src/tint/lang/core/type/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/glsl/writer/BUILD.bazel b/src/tint/lang/glsl/writer/BUILD.bazel
index a0e6bb2..19020bd 100644
--- a/src/tint/lang/glsl/writer/BUILD.bazel
+++ b/src/tint/lang/glsl/writer/BUILD.bazel
@@ -70,13 +70,14 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"writer_bench.cc",
],
deps = [
"//src/tint/api/common",
"//src/tint/api/options",
- "//src/tint/cmd/bench",
+ "//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/type",
@@ -97,6 +98,7 @@
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
] + select({
":tint_build_glsl_writer": [
"//src/tint/lang/glsl/writer",
diff --git a/src/tint/lang/glsl/writer/BUILD.cmake b/src/tint/lang/glsl/writer/BUILD.cmake
index 232ff0d..0afac03 100644
--- a/src/tint/lang/glsl/writer/BUILD.cmake
+++ b/src/tint/lang/glsl/writer/BUILD.cmake
@@ -86,7 +86,7 @@
tint_target_add_dependencies(tint_lang_glsl_writer_bench bench
tint_api_common
tint_api_options
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_type
@@ -109,6 +109,10 @@
tint_utils_traits
)
+tint_target_add_external_dependencies(tint_lang_glsl_writer_bench bench
+ "google-benchmark"
+)
+
if(TINT_BUILD_GLSL_WRITER)
tint_target_add_dependencies(tint_lang_glsl_writer_bench bench
tint_lang_glsl_writer
diff --git a/src/tint/lang/glsl/writer/BUILD.gn b/src/tint/lang/glsl/writer/BUILD.gn
index 96574b1..15b8ed7 100644
--- a/src/tint/lang/glsl/writer/BUILD.gn
+++ b/src/tint/lang/glsl/writer/BUILD.gn
@@ -24,6 +24,10 @@
import("../../../../../scripts/tint_overrides_with_defaults.gni")
import("${tint_src_dir}/tint.gni")
+
+if (tint_build_unittests || tint_build_benchmarks) {
+ import("//testing/test.gni")
+}
if (tint_build_glsl_writer) {
libtint_source_set("writer") {
sources = [
@@ -67,3 +71,44 @@
}
}
}
+if (tint_build_benchmarks) {
+ if (tint_build_glsl_writer) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "writer_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/api/common",
+ "${tint_src_dir}/api/options",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_glsl_writer) {
+ deps += [
+ "${tint_src_dir}/lang/glsl/writer",
+ "${tint_src_dir}/lang/glsl/writer/common",
+ ]
+ }
+ }
+ }
+}
diff --git a/src/tint/lang/glsl/writer/ast_printer/BUILD.gn b/src/tint/lang/glsl/writer/ast_printer/BUILD.gn
index fc1c41e..2890c90 100644
--- a/src/tint/lang/glsl/writer/ast_printer/BUILD.gn
+++ b/src/tint/lang/glsl/writer/ast_printer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_glsl_writer) {
diff --git a/src/tint/lang/glsl/writer/ast_raise/BUILD.gn b/src/tint/lang/glsl/writer/ast_raise/BUILD.gn
index 7b7a0e0..c004912 100644
--- a/src/tint/lang/glsl/writer/ast_raise/BUILD.gn
+++ b/src/tint/lang/glsl/writer/ast_raise/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_glsl_writer) {
diff --git a/src/tint/lang/glsl/writer/writer_bench.cc b/src/tint/lang/glsl/writer/writer_bench.cc
index de9d3e6..904b4dc 100644
--- a/src/tint/lang/glsl/writer/writer_bench.cc
+++ b/src/tint/lang/glsl/writer/writer_bench.cc
@@ -24,11 +24,11 @@
void GenerateGLSL(benchmark::State& state, std::string input_name) {
auto res = bench::LoadProgram(input_name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- state.SkipWithError(err->msg.c_str());
+ if (!res) {
+ state.SkipWithError(res.Failure().reason.str());
return;
}
- auto& program = std::get<bench::ProgramAndFile>(res).program;
+ auto& program = res->program;
std::vector<std::string> entry_points;
for (auto& fn : program.AST().Functions()) {
if (fn->IsEntryPoint()) {
@@ -38,9 +38,9 @@
for (auto _ : state) {
for (auto& ep : entry_points) {
- auto res = Generate(program, {}, ep);
- if (!res) {
- state.SkipWithError(res.Failure().reason.str());
+ auto gen_res = Generate(program, {}, ep);
+ if (!gen_res) {
+ state.SkipWithError(gen_res.Failure().reason.str());
}
}
}
diff --git a/src/tint/lang/hlsl/writer/BUILD.bazel b/src/tint/lang/hlsl/writer/BUILD.bazel
index 323d038..58d4602 100644
--- a/src/tint/lang/hlsl/writer/BUILD.bazel
+++ b/src/tint/lang/hlsl/writer/BUILD.bazel
@@ -71,13 +71,14 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"writer_bench.cc",
],
deps = [
"//src/tint/api/common",
"//src/tint/api/options",
- "//src/tint/cmd/bench",
+ "//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/type",
@@ -99,6 +100,7 @@
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
] + select({
":tint_build_hlsl_writer": [
"//src/tint/lang/hlsl/writer",
diff --git a/src/tint/lang/hlsl/writer/BUILD.cmake b/src/tint/lang/hlsl/writer/BUILD.cmake
index 887529b..3565fce 100644
--- a/src/tint/lang/hlsl/writer/BUILD.cmake
+++ b/src/tint/lang/hlsl/writer/BUILD.cmake
@@ -87,7 +87,7 @@
tint_target_add_dependencies(tint_lang_hlsl_writer_bench bench
tint_api_common
tint_api_options
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_type
@@ -111,6 +111,10 @@
tint_utils_traits
)
+tint_target_add_external_dependencies(tint_lang_hlsl_writer_bench bench
+ "google-benchmark"
+)
+
if(TINT_BUILD_HLSL_WRITER)
tint_target_add_dependencies(tint_lang_hlsl_writer_bench bench
tint_lang_hlsl_writer
diff --git a/src/tint/lang/hlsl/writer/BUILD.gn b/src/tint/lang/hlsl/writer/BUILD.gn
index b270131..dbc5d31 100644
--- a/src/tint/lang/hlsl/writer/BUILD.gn
+++ b/src/tint/lang/hlsl/writer/BUILD.gn
@@ -24,6 +24,10 @@
import("../../../../../scripts/tint_overrides_with_defaults.gni")
import("${tint_src_dir}/tint.gni")
+
+if (tint_build_unittests || tint_build_benchmarks) {
+ import("//testing/test.gni")
+}
if (tint_build_hlsl_writer) {
libtint_source_set("writer") {
sources = [
@@ -68,3 +72,42 @@
}
}
}
+if (tint_build_benchmarks) {
+ if (tint_build_hlsl_writer) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "writer_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/api/common",
+ "${tint_src_dir}/api/options",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/hlsl/writer/common",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_hlsl_writer) {
+ deps += [ "${tint_src_dir}/lang/hlsl/writer" ]
+ }
+ }
+ }
+}
diff --git a/src/tint/lang/hlsl/writer/ast_printer/BUILD.gn b/src/tint/lang/hlsl/writer/ast_printer/BUILD.gn
index 017911b..619d72a 100644
--- a/src/tint/lang/hlsl/writer/ast_printer/BUILD.gn
+++ b/src/tint/lang/hlsl/writer/ast_printer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_hlsl_writer) {
diff --git a/src/tint/lang/hlsl/writer/ast_raise/BUILD.gn b/src/tint/lang/hlsl/writer/ast_raise/BUILD.gn
index 24b8ca4..cbbf8c7 100644
--- a/src/tint/lang/hlsl/writer/ast_raise/BUILD.gn
+++ b/src/tint/lang/hlsl/writer/ast_raise/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_hlsl_writer) {
diff --git a/src/tint/lang/hlsl/writer/writer_bench.cc b/src/tint/lang/hlsl/writer/writer_bench.cc
index 00c5d39..727e696f 100644
--- a/src/tint/lang/hlsl/writer/writer_bench.cc
+++ b/src/tint/lang/hlsl/writer/writer_bench.cc
@@ -22,15 +22,14 @@
void GenerateHLSL(benchmark::State& state, std::string input_name) {
auto res = bench::LoadProgram(input_name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- state.SkipWithError(err->msg.c_str());
+ if (!res) {
+ state.SkipWithError(res.Failure().reason.str());
return;
}
- auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) {
- auto res = Generate(program, {});
- if (!res) {
- state.SkipWithError(res.Failure().reason.str());
+ auto gen_res = Generate(res->program, {});
+ if (!gen_res) {
+ state.SkipWithError(gen_res.Failure().reason.str());
}
}
}
diff --git a/src/tint/lang/msl/writer/BUILD.bazel b/src/tint/lang/msl/writer/BUILD.bazel
index 4348b90..8b34a6c 100644
--- a/src/tint/lang/msl/writer/BUILD.bazel
+++ b/src/tint/lang/msl/writer/BUILD.bazel
@@ -74,13 +74,14 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"writer_bench.cc",
],
deps = [
"//src/tint/api/common",
"//src/tint/api/options",
- "//src/tint/cmd/bench",
+ "//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/type",
@@ -101,6 +102,7 @@
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
] + select({
":tint_build_msl_writer": [
"//src/tint/lang/msl/writer",
diff --git a/src/tint/lang/msl/writer/BUILD.cmake b/src/tint/lang/msl/writer/BUILD.cmake
index d3291bc..6bcfd2f 100644
--- a/src/tint/lang/msl/writer/BUILD.cmake
+++ b/src/tint/lang/msl/writer/BUILD.cmake
@@ -92,7 +92,7 @@
tint_target_add_dependencies(tint_lang_msl_writer_bench bench
tint_api_common
tint_api_options
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_type
@@ -115,6 +115,10 @@
tint_utils_traits
)
+tint_target_add_external_dependencies(tint_lang_msl_writer_bench bench
+ "google-benchmark"
+)
+
if(TINT_BUILD_MSL_WRITER)
tint_target_add_dependencies(tint_lang_msl_writer_bench bench
tint_lang_msl_writer
diff --git a/src/tint/lang/msl/writer/BUILD.gn b/src/tint/lang/msl/writer/BUILD.gn
index 9f13b86..553a1cc 100644
--- a/src/tint/lang/msl/writer/BUILD.gn
+++ b/src/tint/lang/msl/writer/BUILD.gn
@@ -24,6 +24,10 @@
import("../../../../../scripts/tint_overrides_with_defaults.gni")
import("${tint_src_dir}/tint.gni")
+
+if (tint_build_unittests || tint_build_benchmarks) {
+ import("//testing/test.gni")
+}
if (tint_build_msl_writer) {
libtint_source_set("writer") {
sources = [
@@ -71,3 +75,44 @@
}
}
}
+if (tint_build_benchmarks) {
+ if (tint_build_msl_writer) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "writer_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/api/common",
+ "${tint_src_dir}/api/options",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_msl_writer) {
+ deps += [
+ "${tint_src_dir}/lang/msl/writer",
+ "${tint_src_dir}/lang/msl/writer/common",
+ ]
+ }
+ }
+ }
+}
diff --git a/src/tint/lang/msl/writer/ast_printer/BUILD.gn b/src/tint/lang/msl/writer/ast_printer/BUILD.gn
index 072b550..229ad23 100644
--- a/src/tint/lang/msl/writer/ast_printer/BUILD.gn
+++ b/src/tint/lang/msl/writer/ast_printer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_msl_writer) {
diff --git a/src/tint/lang/msl/writer/ast_raise/BUILD.gn b/src/tint/lang/msl/writer/ast_raise/BUILD.gn
index cf231b6..05d773f 100644
--- a/src/tint/lang/msl/writer/ast_raise/BUILD.gn
+++ b/src/tint/lang/msl/writer/ast_raise/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_msl_writer) {
diff --git a/src/tint/lang/msl/writer/common/BUILD.gn b/src/tint/lang/msl/writer/common/BUILD.gn
index 8e834d8..30e2d4f 100644
--- a/src/tint/lang/msl/writer/common/BUILD.gn
+++ b/src/tint/lang/msl/writer/common/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_msl_writer) {
diff --git a/src/tint/lang/msl/writer/printer/BUILD.gn b/src/tint/lang/msl/writer/printer/BUILD.gn
index cf2af5a..9f75e9a 100644
--- a/src/tint/lang/msl/writer/printer/BUILD.gn
+++ b/src/tint/lang/msl/writer/printer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_msl_writer) {
diff --git a/src/tint/lang/msl/writer/writer_bench.cc b/src/tint/lang/msl/writer/writer_bench.cc
index aa04473..712d272 100644
--- a/src/tint/lang/msl/writer/writer_bench.cc
+++ b/src/tint/lang/msl/writer/writer_bench.cc
@@ -24,11 +24,11 @@
void GenerateMSL(benchmark::State& state, std::string input_name) {
auto res = bench::LoadProgram(input_name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- state.SkipWithError(err->msg.c_str());
+ if (!res) {
+ state.SkipWithError(res.Failure().reason.str());
return;
}
- auto& program = std::get<bench::ProgramAndFile>(res).program;
+ auto& program = res->program;
tint::msl::writer::Options gen_options = {};
gen_options.array_length_from_uniform.ubo_binding = tint::BindingPoint{0, 30};
@@ -61,9 +61,9 @@
}
}
for (auto _ : state) {
- auto res = Generate(program, gen_options);
- if (!res) {
- state.SkipWithError(res.Failure().reason.str());
+ auto gen_res = Generate(program, gen_options);
+ if (!gen_res) {
+ state.SkipWithError(gen_res.Failure().reason.str());
}
}
}
diff --git a/src/tint/lang/spirv/ir/BUILD.gn b/src/tint/lang/spirv/ir/BUILD.gn
index 2a81280..52aff36 100644
--- a/src/tint/lang/spirv/ir/BUILD.gn
+++ b/src/tint/lang/spirv/ir/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/spirv/reader/ast_lower/BUILD.gn b/src/tint/lang/spirv/reader/ast_lower/BUILD.gn
index 12924c2..a24ca3e 100644
--- a/src/tint/lang/spirv/reader/ast_lower/BUILD.gn
+++ b/src/tint/lang/spirv/reader/ast_lower/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_reader) {
diff --git a/src/tint/lang/spirv/reader/ast_parser/BUILD.gn b/src/tint/lang/spirv/reader/ast_parser/BUILD.gn
index 163e8be..7f54ccf 100644
--- a/src/tint/lang/spirv/reader/ast_parser/BUILD.gn
+++ b/src/tint/lang/spirv/reader/ast_parser/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_reader) {
@@ -88,6 +88,7 @@
"${tint_spirv_headers_dir}:spv_headers",
"${tint_spirv_tools_dir}:spvtools",
"${tint_spirv_tools_dir}:spvtools_opt",
+ "${tint_spirv_tools_dir}:spvtools_val",
]
}
public_configs = [ "${tint_spirv_tools_dir}/:spvtools_internal_config" ]
@@ -172,6 +173,7 @@
"${tint_spirv_tools_dir}:spvtools_headers",
"${tint_spirv_tools_dir}:spvtools_opt",
"${tint_spirv_tools_dir}:spvtools_val",
+ "${tint_spirv_tools_dir}:spvtools_val",
]
}
public_configs = [ "${tint_spirv_tools_dir}/:spvtools_internal_config" ]
diff --git a/src/tint/lang/spirv/writer/BUILD.bazel b/src/tint/lang/spirv/writer/BUILD.bazel
index f8d6a11..7c2a7b7 100644
--- a/src/tint/lang/spirv/writer/BUILD.bazel
+++ b/src/tint/lang/spirv/writer/BUILD.bazel
@@ -149,13 +149,14 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"writer_bench.cc",
],
deps = [
"//src/tint/api/common",
"//src/tint/api/options",
- "//src/tint/cmd/bench",
+ "//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/type",
@@ -176,6 +177,7 @@
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
] + select({
":tint_build_spv_writer": [
"//src/tint/lang/spirv/writer",
diff --git a/src/tint/lang/spirv/writer/BUILD.cmake b/src/tint/lang/spirv/writer/BUILD.cmake
index 0910cfb..953b266 100644
--- a/src/tint/lang/spirv/writer/BUILD.cmake
+++ b/src/tint/lang/spirv/writer/BUILD.cmake
@@ -176,7 +176,7 @@
tint_target_add_dependencies(tint_lang_spirv_writer_bench bench
tint_api_common
tint_api_options
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_type
@@ -199,6 +199,10 @@
tint_utils_traits
)
+tint_target_add_external_dependencies(tint_lang_spirv_writer_bench bench
+ "google-benchmark"
+)
+
if(TINT_BUILD_SPV_WRITER)
tint_target_add_dependencies(tint_lang_spirv_writer_bench bench
tint_lang_spirv_writer
diff --git a/src/tint/lang/spirv/writer/BUILD.gn b/src/tint/lang/spirv/writer/BUILD.gn
index 38d4260..0501f18 100644
--- a/src/tint/lang/spirv/writer/BUILD.gn
+++ b/src/tint/lang/spirv/writer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_writer) {
@@ -153,3 +153,44 @@
}
}
}
+if (tint_build_benchmarks) {
+ if (tint_build_spv_writer) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "writer_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/api/common",
+ "${tint_src_dir}/api/options",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_spv_writer) {
+ deps += [
+ "${tint_src_dir}/lang/spirv/writer",
+ "${tint_src_dir}/lang/spirv/writer/common",
+ ]
+ }
+ }
+ }
+}
diff --git a/src/tint/lang/spirv/writer/ast_printer/BUILD.gn b/src/tint/lang/spirv/writer/ast_printer/BUILD.gn
index 4344f94..577508d 100644
--- a/src/tint/lang/spirv/writer/ast_printer/BUILD.gn
+++ b/src/tint/lang/spirv/writer/ast_printer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_writer) {
diff --git a/src/tint/lang/spirv/writer/ast_raise/BUILD.gn b/src/tint/lang/spirv/writer/ast_raise/BUILD.gn
index 5ab53d5..4eb4fe1 100644
--- a/src/tint/lang/spirv/writer/ast_raise/BUILD.gn
+++ b/src/tint/lang/spirv/writer/ast_raise/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_writer) {
diff --git a/src/tint/lang/spirv/writer/common/BUILD.gn b/src/tint/lang/spirv/writer/common/BUILD.gn
index 5c12785..98f7ec6 100644
--- a/src/tint/lang/spirv/writer/common/BUILD.gn
+++ b/src/tint/lang/spirv/writer/common/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_writer) {
diff --git a/src/tint/lang/spirv/writer/raise/BUILD.gn b/src/tint/lang/spirv/writer/raise/BUILD.gn
index 6d187d6..7cd648d 100644
--- a/src/tint/lang/spirv/writer/raise/BUILD.gn
+++ b/src/tint/lang/spirv/writer/raise/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
if (tint_build_spv_writer) {
diff --git a/src/tint/lang/spirv/writer/writer_bench.cc b/src/tint/lang/spirv/writer/writer_bench.cc
index adef3df..c5bccce 100644
--- a/src/tint/lang/spirv/writer/writer_bench.cc
+++ b/src/tint/lang/spirv/writer/writer_bench.cc
@@ -22,15 +22,14 @@
void RunBenchmark(benchmark::State& state, std::string input_name, Options options) {
auto res = bench::LoadProgram(input_name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- state.SkipWithError(err->msg.c_str());
+ if (!res) {
+ state.SkipWithError(res.Failure().reason.str());
return;
}
- auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) {
- auto res = Generate(program, options);
- if (!res) {
- state.SkipWithError(res.Failure().reason.str());
+ auto gen_res = Generate(res->program, options);
+ if (!gen_res) {
+ state.SkipWithError(gen_res.Failure().reason.str());
}
}
}
diff --git a/src/tint/lang/wgsl/BUILD.bazel b/src/tint/lang/wgsl/BUILD.bazel
index 83e4df2..20c24b6 100644
--- a/src/tint/lang/wgsl/BUILD.bazel
+++ b/src/tint/lang/wgsl/BUILD.bazel
@@ -102,6 +102,7 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"diagnostic_rule_bench.cc",
"diagnostic_severity_bench.cc",
@@ -118,6 +119,7 @@
"//src/tint/utils/rtti",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
],
copts = COPTS,
visibility = ["//visibility:public"],
diff --git a/src/tint/lang/wgsl/BUILD.cmake b/src/tint/lang/wgsl/BUILD.cmake
index c72aa5e..4b8db03 100644
--- a/src/tint/lang/wgsl/BUILD.cmake
+++ b/src/tint/lang/wgsl/BUILD.cmake
@@ -134,3 +134,7 @@
tint_utils_text
tint_utils_traits
)
+
+tint_target_add_external_dependencies(tint_lang_wgsl_bench bench
+ "google-benchmark"
+)
diff --git a/src/tint/lang/wgsl/BUILD.gn b/src/tint/lang/wgsl/BUILD.gn
index 4ddc480..7b55c18 100644
--- a/src/tint/lang/wgsl/BUILD.gn
+++ b/src/tint/lang/wgsl/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
@@ -99,3 +99,26 @@
}
}
}
+if (tint_build_benchmarks) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [
+ "diagnostic_rule_bench.cc",
+ "diagnostic_severity_bench.cc",
+ "extension_bench.cc",
+ ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+ }
+}
diff --git a/src/tint/lang/wgsl/ast/BUILD.gn b/src/tint/lang/wgsl/ast/BUILD.gn
index 2cc22fe..2de24e1 100644
--- a/src/tint/lang/wgsl/ast/BUILD.gn
+++ b/src/tint/lang/wgsl/ast/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/ast/transform/BUILD.gn b/src/tint/lang/wgsl/ast/transform/BUILD.gn
index 958683e..9286bd0 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.gn
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/helpers/BUILD.gn b/src/tint/lang/wgsl/helpers/BUILD.gn
index 3ce0df4..d0ff37c 100644
--- a/src/tint/lang/wgsl/helpers/BUILD.gn
+++ b/src/tint/lang/wgsl/helpers/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/inspector/BUILD.gn b/src/tint/lang/wgsl/inspector/BUILD.gn
index 566230b..1256404 100644
--- a/src/tint/lang/wgsl/inspector/BUILD.gn
+++ b/src/tint/lang/wgsl/inspector/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/program/BUILD.gn b/src/tint/lang/wgsl/program/BUILD.gn
index ea3bd1b..4ebef42 100644
--- a/src/tint/lang/wgsl/program/BUILD.gn
+++ b/src/tint/lang/wgsl/program/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/reader/BUILD.bazel b/src/tint/lang/wgsl/reader/BUILD.bazel
index 116874d..e47e37f 100644
--- a/src/tint/lang/wgsl/reader/BUILD.bazel
+++ b/src/tint/lang/wgsl/reader/BUILD.bazel
@@ -64,12 +64,13 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"reader_bench.cc",
],
deps = [
"//src/tint/api/common",
- "//src/tint/cmd/bench",
+ "//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/ir",
@@ -92,6 +93,7 @@
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
],
copts = COPTS,
visibility = ["//visibility:public"],
diff --git a/src/tint/lang/wgsl/reader/BUILD.cmake b/src/tint/lang/wgsl/reader/BUILD.cmake
index 2d94eb5..163a125 100644
--- a/src/tint/lang/wgsl/reader/BUILD.cmake
+++ b/src/tint/lang/wgsl/reader/BUILD.cmake
@@ -73,7 +73,7 @@
tint_target_add_dependencies(tint_lang_wgsl_reader_bench bench
tint_api_common
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_ir
@@ -97,3 +97,7 @@
tint_utils_text
tint_utils_traits
)
+
+tint_target_add_external_dependencies(tint_lang_wgsl_reader_bench bench
+ "google-benchmark"
+)
diff --git a/src/tint/lang/wgsl/reader/BUILD.gn b/src/tint/lang/wgsl/reader/BUILD.gn
index 7962250..f4808f9 100644
--- a/src/tint/lang/wgsl/reader/BUILD.gn
+++ b/src/tint/lang/wgsl/reader/BUILD.gn
@@ -25,6 +25,10 @@
import("${tint_src_dir}/tint.gni")
+if (tint_build_unittests || tint_build_benchmarks) {
+ import("//testing/test.gni")
+}
+
libtint_source_set("reader") {
sources = [
"reader.cc",
@@ -59,3 +63,36 @@
"${tint_src_dir}/utils/traits",
]
}
+if (tint_build_benchmarks) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "reader_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/api/common",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${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/program",
+ "${tint_src_dir}/lang/wgsl/reader",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+ }
+}
diff --git a/src/tint/lang/wgsl/reader/lower/BUILD.gn b/src/tint/lang/wgsl/reader/lower/BUILD.gn
index 674130d..490ba6f 100644
--- a/src/tint/lang/wgsl/reader/lower/BUILD.gn
+++ b/src/tint/lang/wgsl/reader/lower/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/reader/parser/BUILD.gn b/src/tint/lang/wgsl/reader/parser/BUILD.gn
index f765960..77cc04c 100644
--- a/src/tint/lang/wgsl/reader/parser/BUILD.gn
+++ b/src/tint/lang/wgsl/reader/parser/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/reader/program_to_ir/BUILD.gn b/src/tint/lang/wgsl/reader/program_to_ir/BUILD.gn
index 87f764b..f8b67b3 100644
--- a/src/tint/lang/wgsl/reader/program_to_ir/BUILD.gn
+++ b/src/tint/lang/wgsl/reader/program_to_ir/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/reader/reader_bench.cc b/src/tint/lang/wgsl/reader/reader_bench.cc
index b5f736a..be3898c 100644
--- a/src/tint/lang/wgsl/reader/reader_bench.cc
+++ b/src/tint/lang/wgsl/reader/reader_bench.cc
@@ -22,15 +22,14 @@
void ParseWGSL(benchmark::State& state, std::string input_name) {
auto res = bench::LoadInputFile(input_name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- state.SkipWithError(err->msg.c_str());
+ if (!res) {
+ state.SkipWithError(res.Failure().reason.str());
return;
}
- auto& file = std::get<Source::File>(res);
for (auto _ : state) {
- auto res = Parse(&file);
- if (res.Diagnostics().contains_errors()) {
- state.SkipWithError(res.Diagnostics().str().c_str());
+ auto program = Parse(&res.Get());
+ if (program.Diagnostics().contains_errors()) {
+ state.SkipWithError(program.Diagnostics().str());
}
}
}
diff --git a/src/tint/lang/wgsl/resolver/BUILD.gn b/src/tint/lang/wgsl/resolver/BUILD.gn
index c10075f..ba04bbb 100644
--- a/src/tint/lang/wgsl/resolver/BUILD.gn
+++ b/src/tint/lang/wgsl/resolver/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/sem/BUILD.gn b/src/tint/lang/wgsl/sem/BUILD.gn
index 2e87dae..82cda60 100644
--- a/src/tint/lang/wgsl/sem/BUILD.gn
+++ b/src/tint/lang/wgsl/sem/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/writer/BUILD.bazel b/src/tint/lang/wgsl/writer/BUILD.bazel
index 36cadd8..7d24c91 100644
--- a/src/tint/lang/wgsl/writer/BUILD.bazel
+++ b/src/tint/lang/wgsl/writer/BUILD.bazel
@@ -69,11 +69,12 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"writer_bench.cc",
],
deps = [
- "//src/tint/cmd/bench",
+ "//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/type",
@@ -95,6 +96,7 @@
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
+ "@benchmark",
],
copts = COPTS,
visibility = ["//visibility:public"],
diff --git a/src/tint/lang/wgsl/writer/BUILD.cmake b/src/tint/lang/wgsl/writer/BUILD.cmake
index c9893f6..bfb510a 100644
--- a/src/tint/lang/wgsl/writer/BUILD.cmake
+++ b/src/tint/lang/wgsl/writer/BUILD.cmake
@@ -78,7 +78,7 @@
)
tint_target_add_dependencies(tint_lang_wgsl_writer_bench bench
- tint_cmd_bench
+ tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_type
@@ -101,3 +101,7 @@
tint_utils_text
tint_utils_traits
)
+
+tint_target_add_external_dependencies(tint_lang_wgsl_writer_bench bench
+ "google-benchmark"
+)
diff --git a/src/tint/lang/wgsl/writer/BUILD.gn b/src/tint/lang/wgsl/writer/BUILD.gn
index 21b27a4..85772cd 100644
--- a/src/tint/lang/wgsl/writer/BUILD.gn
+++ b/src/tint/lang/wgsl/writer/BUILD.gn
@@ -25,6 +25,10 @@
import("${tint_src_dir}/tint.gni")
+if (tint_build_unittests || tint_build_benchmarks) {
+ import("//testing/test.gni")
+}
+
libtint_source_set("writer") {
sources = [
"options.cc",
@@ -64,3 +68,34 @@
"${tint_src_dir}/utils/traits",
]
}
+if (tint_build_benchmarks) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "writer_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/cmd/bench:bench",
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/lang/wgsl/writer",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+ }
+}
diff --git a/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn b/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn
index dcdec55..d50257d 100644
--- a/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn
+++ b/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/writer/ir_to_program/BUILD.gn b/src/tint/lang/wgsl/writer/ir_to_program/BUILD.gn
index c823bb4..70419b6 100644
--- a/src/tint/lang/wgsl/writer/ir_to_program/BUILD.gn
+++ b/src/tint/lang/wgsl/writer/ir_to_program/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/writer/raise/BUILD.gn b/src/tint/lang/wgsl/writer/raise/BUILD.gn
index 7dc51e0..6df44ac 100644
--- a/src/tint/lang/wgsl/writer/raise/BUILD.gn
+++ b/src/tint/lang/wgsl/writer/raise/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/lang/wgsl/writer/writer_bench.cc b/src/tint/lang/wgsl/writer/writer_bench.cc
index 05f349a..3a4157d 100644
--- a/src/tint/lang/wgsl/writer/writer_bench.cc
+++ b/src/tint/lang/wgsl/writer/writer_bench.cc
@@ -22,15 +22,14 @@
void GenerateWGSL(benchmark::State& state, std::string input_name) {
auto res = bench::LoadProgram(input_name);
- if (auto err = std::get_if<bench::Error>(&res)) {
- state.SkipWithError(err->msg.c_str());
+ if (!res) {
+ state.SkipWithError(res.Failure().reason.str());
return;
}
- auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) {
- auto res = Generate(program, {});
- if (!res) {
- state.SkipWithError(res.Failure().reason.str());
+ auto gen_res = Generate(res->program, {});
+ if (!gen_res) {
+ state.SkipWithError(gen_res.Failure().reason.str());
}
}
}
diff --git a/src/tint/utils/cli/BUILD.gn b/src/tint/utils/cli/BUILD.gn
index 2306667..d3cf2d6 100644
--- a/src/tint/utils/cli/BUILD.gn
+++ b/src/tint/utils/cli/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/command/BUILD.gn b/src/tint/utils/command/BUILD.gn
index c9b9d86..ae5d105 100644
--- a/src/tint/utils/command/BUILD.gn
+++ b/src/tint/utils/command/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/containers/BUILD.gn b/src/tint/utils/containers/BUILD.gn
index b7cbe13b..ade9da6 100644
--- a/src/tint/utils/containers/BUILD.gn
+++ b/src/tint/utils/containers/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/diagnostic/BUILD.gn b/src/tint/utils/diagnostic/BUILD.gn
index 90735ad..f78673c 100644
--- a/src/tint/utils/diagnostic/BUILD.gn
+++ b/src/tint/utils/diagnostic/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/file/BUILD.gn b/src/tint/utils/file/BUILD.gn
index cfca680..338d014 100644
--- a/src/tint/utils/file/BUILD.gn
+++ b/src/tint/utils/file/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/ice/BUILD.gn b/src/tint/utils/ice/BUILD.gn
index d151d2f..bd1c9b4 100644
--- a/src/tint/utils/ice/BUILD.gn
+++ b/src/tint/utils/ice/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/macros/BUILD.gn b/src/tint/utils/macros/BUILD.gn
index 7b85feb..00a8f8b 100644
--- a/src/tint/utils/macros/BUILD.gn
+++ b/src/tint/utils/macros/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/math/BUILD.gn b/src/tint/utils/math/BUILD.gn
index 2498c65..6f1ec11 100644
--- a/src/tint/utils/math/BUILD.gn
+++ b/src/tint/utils/math/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/memory/BUILD.gn b/src/tint/utils/memory/BUILD.gn
index 36728c7..9bacaf7 100644
--- a/src/tint/utils/memory/BUILD.gn
+++ b/src/tint/utils/memory/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/reflection/BUILD.gn b/src/tint/utils/reflection/BUILD.gn
index 86c94c2..944c46a 100644
--- a/src/tint/utils/reflection/BUILD.gn
+++ b/src/tint/utils/reflection/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/result/BUILD.gn b/src/tint/utils/result/BUILD.gn
index f607347..79e9d94 100644
--- a/src/tint/utils/result/BUILD.gn
+++ b/src/tint/utils/result/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/rtti/BUILD.bazel b/src/tint/utils/rtti/BUILD.bazel
index e724929..893a78a 100644
--- a/src/tint/utils/rtti/BUILD.bazel
+++ b/src/tint/utils/rtti/BUILD.bazel
@@ -61,6 +61,7 @@
)
cc_library(
name = "bench",
+ alwayslink = True,
srcs = [
"switch_bench.cc",
],
@@ -70,6 +71,7 @@
"//src/tint/utils/memory",
"//src/tint/utils/rtti",
"//src/tint/utils/traits",
+ "@benchmark",
],
copts = COPTS,
visibility = ["//visibility:public"],
diff --git a/src/tint/utils/rtti/BUILD.cmake b/src/tint/utils/rtti/BUILD.cmake
index 9b256ff..c06aae6 100644
--- a/src/tint/utils/rtti/BUILD.cmake
+++ b/src/tint/utils/rtti/BUILD.cmake
@@ -74,3 +74,7 @@
tint_utils_rtti
tint_utils_traits
)
+
+tint_target_add_external_dependencies(tint_utils_rtti_bench bench
+ "google-benchmark"
+)
diff --git a/src/tint/utils/rtti/BUILD.gn b/src/tint/utils/rtti/BUILD.gn
index cd23285..41a2b54 100644
--- a/src/tint/utils/rtti/BUILD.gn
+++ b/src/tint/utils/rtti/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
@@ -59,3 +59,17 @@
]
}
}
+if (tint_build_benchmarks) {
+ tint_unittests_source_set("bench") {
+ testonly = true
+ sources = [ "switch_bench.cc" ]
+ deps = [
+ "${tint_src_dir}:google_benchmark",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/traits",
+ ]
+ }
+}
diff --git a/src/tint/utils/strconv/BUILD.gn b/src/tint/utils/strconv/BUILD.gn
index e386dcb..95987c5 100644
--- a/src/tint/utils/strconv/BUILD.gn
+++ b/src/tint/utils/strconv/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/symbol/BUILD.gn b/src/tint/utils/symbol/BUILD.gn
index 4eec052c..aba2da4 100644
--- a/src/tint/utils/symbol/BUILD.gn
+++ b/src/tint/utils/symbol/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/text/BUILD.gn b/src/tint/utils/text/BUILD.gn
index 6c0b1a1..b92ba7a 100644
--- a/src/tint/utils/text/BUILD.gn
+++ b/src/tint/utils/text/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/src/tint/utils/traits/BUILD.gn b/src/tint/utils/traits/BUILD.gn
index 215b58e..f5e0cc6 100644
--- a/src/tint/utils/traits/BUILD.gn
+++ b/src/tint/utils/traits/BUILD.gn
@@ -25,7 +25,7 @@
import("${tint_src_dir}/tint.gni")
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
diff --git a/tools/src/cmd/gen/build/BUILD.bazel.tmpl b/tools/src/cmd/gen/build/BUILD.bazel.tmpl
index 1c7be33..1ad11c4 100644
--- a/tools/src/cmd/gen/build/BUILD.bazel.tmpl
+++ b/tools/src/cmd/gen/build/BUILD.bazel.tmpl
@@ -43,6 +43,7 @@
{{- else if $.Kind.IsBench -}}
cc_library(
name = "bench",
+ alwayslink = True,
{{- else if $.Kind.IsCmd -}}
cc_binary(
name = "cmd",
@@ -143,6 +144,7 @@
{{- else if eq $.Name "glslang-res-limits" -}}{{/* unsupported */}}
{{- else if eq $.Name "glslang" -}}{{/* unsupported */}}
{{- else if eq $.Name "gmock" -}}"@gtest",
+{{- else if eq $.Name "google-benchmark" -}}"@benchmark",
{{- else if eq $.Name "gtest" -}}"@gtest",
{{- else if eq $.Name "metal" -}}{{/* unsupported */}}
{{- else if eq $.Name "spirv-headers" -}}"@spirv_headers//:spirv_cpp11_headers", "@spirv_headers//:spirv_c_headers",
diff --git a/tools/src/cmd/gen/build/BUILD.gn.tmpl b/tools/src/cmd/gen/build/BUILD.gn.tmpl
index 229ad4f..f409b8a 100644
--- a/tools/src/cmd/gen/build/BUILD.gn.tmpl
+++ b/tools/src/cmd/gen/build/BUILD.gn.tmpl
@@ -3,9 +3,12 @@
import("${tint_src_dir}/tint.gni")
-{{- if or ($.Project.Target $ "test") ($.Project.Target $ "test_cmd")}}
+{{- if or ($.Project.Target $ "test")
+ ($.Project.Target $ "test_cmd")
+ ($.Project.Target $ "bench")
+ ($.Project.Target $ "bench_cmd") }}
{{/* newline */}}
-if (tint_build_unittests) {
+if (tint_build_unittests || tint_build_benchmarks) {
import("//testing/test.gni")
}
{{- end}}
@@ -14,6 +17,8 @@
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "cmd")}}
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "test")}}
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "test_cmd")}}
+{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "bench")}}
+{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "bench_cmd")}}
{{- /*
@@ -37,6 +42,8 @@
{{- if $.Kind.IsTestOrTestCmd}}
if (tint_build_unittests) {
+{{- else if $.Kind.IsBenchOrBenchCmd}}
+if (tint_build_benchmarks) {
{{- end}}
{{- /* Target condition */}}
@@ -51,8 +58,15 @@
{{- else if $.Kind.IsTest -}}
tint_unittests_source_set("unittests") {
testonly = true
+{{- else if $.Kind.IsBench -}}
+tint_unittests_source_set("bench") {
+ testonly = true
{{- else if $.Kind.IsTestCmd -}}
-test("{{$.Directory.Name}}") {
+test("test_cmd") {
+ testonly = true
+{{- else if $.Kind.IsBenchCmd -}}
+test("bench_cmd") {
+ testonly = true
{{- else }}{{Error $.Kind}}
{{- end }}
{{- if $.OutputName }}
@@ -105,7 +119,6 @@
{{- end}}
{{- if $.Kind.IsTestCmd }}
- testonly = true
configs += [ "${tint_src_dir}:tint_unittests_config" ]
if (build_with_chromium) {
@@ -117,8 +130,8 @@
{{- /* Target condition */}}
{{- if $.Condition}}}{{end}}
-{{- /* if(tint_build_unittests) */}}
-{{- if $.Kind.IsTestOrTestCmd}}}{{end}}
+{{- /* if(tint_build_unittests) or if(tint_build_benchmarks) */}}
+{{- if or $.Kind.IsTestOrTestCmd $.Kind.IsBenchOrBenchCmd}}}{{end}}
{{- end}}
@@ -146,10 +159,11 @@
{{- if eq $.Name "abseil" -}}"${tint_src_dir}:abseil",
{{- else if eq $.Name "glslang-res-limits" -}}"${tint_glslang_dir}:glslang_default_resource_limits_sources",
{{- else if eq $.Name "glslang" -}}"${tint_glslang_dir}:glslang_lib_sources",
+{{- else if eq $.Name "google-benchmark" -}}"${tint_src_dir}:google_benchmark",
{{- else if eq $.Name "gtest" -}}"${tint_src_dir}:gmock_and_gtest",
{{- else if eq $.Name "metal" -}}"${tint_src_dir}:metal",
{{- else if eq $.Name "spirv-headers" -}}"${tint_spirv_headers_dir}:spv_headers",
-{{- else if eq $.Name "spirv-opt-internal" -}}"${tint_spirv_tools_dir}:spvtools", "${tint_spirv_tools_dir}:spvtools_opt",
+{{- else if eq $.Name "spirv-opt-internal" -}}"${tint_spirv_tools_dir}:spvtools", "${tint_spirv_tools_dir}:spvtools_opt", "${tint_spirv_tools_dir}:spvtools_val",
{{- else if eq $.Name "spirv-tools" -}}"${tint_spirv_tools_dir}:spvtools_headers", "${tint_spirv_tools_dir}:spvtools_val",
{{- else if eq $.Name "thread" -}}"${tint_src_dir}:thread",
{{- else if eq $.Name "winsock" -}}"${tint_src_dir}:winsock",
diff --git a/tools/src/cmd/gen/build/build.go b/tools/src/cmd/gen/build/build.go
index 500a995..d044663 100644
--- a/tools/src/cmd/gen/build/build.go
+++ b/tools/src/cmd/gen/build/build.go
@@ -403,8 +403,9 @@
return fmt.Errorf(`%v:%v includes non-existent file '%v'`, file.Path(), include.Line, path)
}
- if file.Target.Kind == targetLib && includeFile.Target.Kind != targetLib {
- return fmt.Errorf(`%v:%v lib target must not include %v target`, file.Path(), include.Line, includeFile.Target.Kind)
+ if !isValidDependency(file.Target.Kind, includeFile.Target.Kind) {
+ return fmt.Errorf(`%v:%v %v target must not include %v target`,
+ file.Path(), include.Line, file.Target.Kind, includeFile.Target.Kind)
}
addInternalDependency(includeFile.Target)
diff --git a/tools/src/cmd/gen/build/target_kind.go b/tools/src/cmd/gen/build/target_kind.go
index b9ddc19..7f83f46 100644
--- a/tools/src/cmd/gen/build/target_kind.go
+++ b/tools/src/cmd/gen/build/target_kind.go
@@ -14,7 +14,9 @@
package build
-import "strings"
+import (
+ "strings"
+)
// TargetKind is an enumerator of target kinds
type TargetKind string
@@ -57,6 +59,9 @@
// IsTestOrTestCmd returns true if the TargetKind is 'test' or 'test_cmd'
func (k TargetKind) IsTestOrTestCmd() bool { return k.IsTest() || k.IsTestCmd() }
+// IsBenchOrBenchCmd returns true if the TargetKind is 'bench' or 'bench_cmd'
+func (k TargetKind) IsBenchOrBenchCmd() bool { return k.IsBench() || k.IsBenchCmd() }
+
// All the target kinds
var AllTargetKinds = []TargetKind{
targetLib,
@@ -69,21 +74,43 @@
// targetKindFromFilename returns the target kind my pattern matching the filename
func targetKindFromFilename(filename string) TargetKind {
+ noExt, ext := filename, ""
+ if i := strings.LastIndex(filename, "."); i >= 0 {
+ noExt = filename[:i]
+ ext = filename[i+1:]
+ }
+
+ if ext != "cc" && ext != "mm" && ext != "h" {
+ return targetInvalid
+ }
+
switch {
case filename == "main_test.cc":
return targetTestCmd
case filename == "main_bench.cc":
return targetBenchCmd
- case strings.HasSuffix(filename, "_test.cc"), strings.HasSuffix(filename, "_test.h"):
+ case strings.HasSuffix(noExt, "_test"):
return targetTest
- case strings.HasSuffix(filename, "_bench.cc"), strings.HasSuffix(filename, "_bench.h"):
+ case noExt == "bench" || strings.HasSuffix(noExt, "_bench"):
return targetBench
- case filename == "main.cc":
+ case noExt == "main" || strings.HasSuffix(noExt, "_main"):
return targetCmd
- case strings.HasSuffix(filename, ".cc"),
- strings.HasSuffix(filename, ".mm"),
- strings.HasSuffix(filename, ".h"):
+ default:
return targetLib
}
- return targetInvalid
+}
+
+// isValidDependency returns true iff its valid for a target of kind 'from' to
+// depend on a target with kind 'to'.
+func isValidDependency(from, to TargetKind) bool {
+ switch from {
+ case targetLib, targetCmd:
+ return to == targetLib
+ case targetTest, targetTestCmd:
+ return to == targetLib || to == targetTest
+ case targetBench, targetBenchCmd:
+ return to == targetLib || to == targetBench
+ default:
+ return false
+ }
}