Move src/benchmark to src/bench

The current directory and namespace collides quite spectacularly with
the google benchmark include directory and namespace.
This becomes very hard to work around when there's a .cc file in src/
that wants to include "benchmark/benchmark.h", as MSVC appears to
resolve this to the relative path, while GCC and Clang resolve to the
compiler specified include directory.

Bug: tint:1383
Change-Id: Icc8891718d1d8a1b55c2ac4b2bb1487e8d09e629
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/78740
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-01-31 19:49:00 +00:00 committed by Tint LUCI CQ
parent 3e80ae68ee
commit f67b6373a6
9 changed files with 44 additions and 44 deletions

View File

@ -1160,7 +1160,7 @@ if(TINT_BUILD_BENCHMARKS)
endif() endif()
set(TINT_BENCHMARK_SRC set(TINT_BENCHMARK_SRC
"benchmark/benchmark.cc" "bench/benchmark.cc"
"reader/wgsl/parser_bench.cc" "reader/wgsl/parser_bench.cc"
) )

View File

@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
#include <filesystem> #include <filesystem>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
#include <vector> #include <vector>
namespace tint::benchmark { namespace tint::bench {
namespace { namespace {
std::filesystem::path kInputFileDir; std::filesystem::path kInputFileDir;
@ -96,8 +96,8 @@ std::variant<tint::Source::File, Error> LoadInputFile(std::string name) {
} }
std::variant<ProgramAndFile, Error> LoadProgram(std::string name) { std::variant<ProgramAndFile, Error> LoadProgram(std::string name) {
auto res = benchmark::LoadInputFile(name); auto res = bench::LoadInputFile(name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
return *err; return *err;
} }
auto& file = std::get<Source::File>(res); auto& file = std::get<Source::File>(res);
@ -108,16 +108,16 @@ std::variant<ProgramAndFile, Error> LoadProgram(std::string name) {
return ProgramAndFile{std::move(program), std::move(file)}; return ProgramAndFile{std::move(program), std::move(file)};
} }
} // namespace tint::benchmark } // namespace tint::bench
int main(int argc, char** argv) { int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv); benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) { if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1; return 1;
} }
if (!tint::benchmark::FindBenchmarkInputDir()) { if (!tint::bench::FindBenchmarkInputDir()) {
std::cerr << "failed to locate benchmark input files" << std::endl; std::cerr << "failed to locate benchmark input files" << std::endl;
return 1; return 1;
} }
::benchmark::RunSpecifiedBenchmarks(); benchmark::RunSpecifiedBenchmarks();
} }

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_BENCHMARK_BENCHMARK_H_ #ifndef SRC_BENCH_BENCHMARK_H_
#define SRC_BENCHMARK_BENCHMARK_H_ #define SRC_BENCH_BENCHMARK_H_
#include <memory> #include <memory>
#include <string> #include <string>
@ -23,7 +23,7 @@
#include "src/utils/concat.h" #include "src/utils/concat.h"
#include "tint/tint.h" #include "tint/tint.h"
namespace tint::benchmark { namespace tint::bench {
/// Error indicates an operation did not complete successfully. /// Error indicates an operation did not complete successfully.
struct Error { struct Error {
@ -71,6 +71,6 @@ std::variant<ProgramAndFile, Error> LoadProgram(std::string name);
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-fragment.wgsl"); \ TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-vertex.wgsl"); TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-vertex.wgsl");
} // namespace tint::benchmark } // namespace tint::bench
#endif // SRC_BENCHMARK_BENCHMARK_H_ #endif // SRC_BENCH_BENCHMARK_H_

View File

@ -14,14 +14,14 @@
#include <string> #include <string>
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
namespace tint::reader::wgsl { namespace tint::reader::wgsl {
namespace { namespace {
void ParseWGSL(::benchmark::State& state, std::string input_name) { void ParseWGSL(benchmark::State& state, std::string input_name) {
auto res = benchmark::LoadInputFile(input_name); auto res = bench::LoadInputFile(input_name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
state.SkipWithError(err->msg.c_str()); state.SkipWithError(err->msg.c_str());
return; return;
} }

View File

@ -15,18 +15,18 @@
#include <string> #include <string>
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
namespace tint::writer::glsl { namespace tint::writer::glsl {
namespace { namespace {
void GenerateGLSL(::benchmark::State& state, std::string input_name) { void GenerateGLSL(benchmark::State& state, std::string input_name) {
auto res = benchmark::LoadProgram(input_name); auto res = bench::LoadProgram(input_name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
state.SkipWithError(err->msg.c_str()); state.SkipWithError(err->msg.c_str());
return; return;
} }
auto& program = std::get<benchmark::ProgramAndFile>(res).program; auto& program = std::get<bench::ProgramAndFile>(res).program;
std::vector<std::string> entry_points; std::vector<std::string> entry_points;
for (auto& fn : program.AST().Functions()) { for (auto& fn : program.AST().Functions()) {
if (fn->IsEntryPoint()) { if (fn->IsEntryPoint()) {

View File

@ -14,18 +14,18 @@
#include <string> #include <string>
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
namespace tint::writer::hlsl { namespace tint::writer::hlsl {
namespace { namespace {
void GenerateHLSL(::benchmark::State& state, std::string input_name) { void GenerateHLSL(benchmark::State& state, std::string input_name) {
auto res = benchmark::LoadProgram(input_name); auto res = bench::LoadProgram(input_name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
state.SkipWithError(err->msg.c_str()); state.SkipWithError(err->msg.c_str());
return; return;
} }
auto& program = std::get<benchmark::ProgramAndFile>(res).program; auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) { for (auto _ : state) {
auto res = Generate(&program, {}); auto res = Generate(&program, {});
if (!res.error.empty()) { if (!res.error.empty()) {

View File

@ -14,18 +14,18 @@
#include <string> #include <string>
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
namespace tint::writer::msl { namespace tint::writer::msl {
namespace { namespace {
void GenerateMSL(::benchmark::State& state, std::string input_name) { void GenerateMSL(benchmark::State& state, std::string input_name) {
auto res = benchmark::LoadProgram(input_name); auto res = bench::LoadProgram(input_name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
state.SkipWithError(err->msg.c_str()); state.SkipWithError(err->msg.c_str());
return; return;
} }
auto& program = std::get<benchmark::ProgramAndFile>(res).program; auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) { for (auto _ : state) {
auto res = Generate(&program, {}); auto res = Generate(&program, {});
if (!res.error.empty()) { if (!res.error.empty()) {

View File

@ -14,18 +14,18 @@
#include <string> #include <string>
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
namespace tint::writer::spirv { namespace tint::writer::spirv {
namespace { namespace {
void GenerateSPIRV(::benchmark::State& state, std::string input_name) { void GenerateSPIRV(benchmark::State& state, std::string input_name) {
auto res = benchmark::LoadProgram(input_name); auto res = bench::LoadProgram(input_name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
state.SkipWithError(err->msg.c_str()); state.SkipWithError(err->msg.c_str());
return; return;
} }
auto& program = std::get<benchmark::ProgramAndFile>(res).program; auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) { for (auto _ : state) {
auto res = Generate(&program, {}); auto res = Generate(&program, {});
if (!res.error.empty()) { if (!res.error.empty()) {

View File

@ -14,18 +14,18 @@
#include <string> #include <string>
#include "src/benchmark/benchmark.h" #include "src/bench/benchmark.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
void GenerateWGSL(::benchmark::State& state, std::string input_name) { void GenerateWGSL(benchmark::State& state, std::string input_name) {
auto res = benchmark::LoadProgram(input_name); auto res = bench::LoadProgram(input_name);
if (auto err = std::get_if<benchmark::Error>(&res)) { if (auto err = std::get_if<bench::Error>(&res)) {
state.SkipWithError(err->msg.c_str()); state.SkipWithError(err->msg.c_str());
return; return;
} }
auto& program = std::get<benchmark::ProgramAndFile>(res).program; auto& program = std::get<bench::ProgramAndFile>(res).program;
for (auto _ : state) { for (auto _ : state) {
auto res = Generate(&program, {}); auto res = Generate(&program, {});
if (!res.error.empty()) { if (!res.error.empty()) {