From 8fc9b862143991d28ad930e5dd00a3c28a92a018 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 19 Apr 2023 15:03:19 +0000 Subject: [PATCH] CMake: Add TINT_EXTERNAL_BENCHMARK_CORPUS_DIR If specified, CMake will glob all the .wgsl files in this directory, and add these to the list of benchmarks to run. Change-Id: I75b2754a6561dcd931c42bd47649c4f625e1c581 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127980 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Dan Sinclair --- CMakeLists.txt | 4 ++++ src/tint/CMakeLists.txt | 23 +++++++++++++++++++++++ src/tint/bench/benchmark.h | 12 +++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d44a64846..c6cee43a83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,8 @@ option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON) option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF) option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF) +set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.") + option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF) option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF) option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF) @@ -306,6 +308,8 @@ message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}") message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}") message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}") message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}") +message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}") + if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "") message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}") diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 8ac5b1504c..7b595fdf3f 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -1494,4 +1494,27 @@ if(TINT_BUILD_BENCHMARKS) tint_core_compile_options(tint-benchmark) target_link_libraries(tint-benchmark PRIVATE benchmark::benchmark libtint) + + if (TINT_EXTERNAL_BENCHMARK_CORPUS_DIR) + # Glob all the files at TINT_EXTERNAL_BENCHMARK_CORPUS_DIR, and create a header + # that lists these with the TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAMS() macro + set(TINT_BENCHMARK_GEN_DIR "${DAWN_BUILD_GEN_DIR}/src/tint/benchmark/") + set(TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER "${TINT_BENCHMARK_GEN_DIR}/external_wgsl_programs.h") + message("Globbing ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}...") + file(GLOB_RECURSE + TINT_EXTERNAL_BENCHMARK_FILES + RELATIVE "${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}" + "${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}/**.wgsl") + list(TRANSFORM TINT_EXTERNAL_BENCHMARK_FILES REPLACE + "(.+)" + " BENCHMARK_CAPTURE\(FUNC, \"\\1\", \"${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}/\\1\")") + list(JOIN TINT_EXTERNAL_BENCHMARK_FILES "; \\\n" TINT_EXTERNAL_BENCHMARK_FILES) + file(CONFIGURE + OUTPUT "${TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER}" + CONTENT "#define TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAMS(FUNC) \\ +${TINT_EXTERNAL_BENCHMARK_FILES};") + # Define TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER to the generated header path + target_compile_definitions(tint-benchmark PRIVATE + "TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER=\"${TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER}\"") + endif() endif(TINT_BUILD_BENCHMARKS) diff --git a/src/tint/bench/benchmark.h b/src/tint/bench/benchmark.h index 680158544d..adb28b8861 100644 --- a/src/tint/bench/benchmark.h +++ b/src/tint/bench/benchmark.h @@ -51,6 +51,15 @@ std::variant LoadInputFile(std::string name); /// @returns either the loaded Program or an Error std::variant LoadProgram(std::string name); +// If TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER is defined, include that to +// declare the TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAMS() macro, which appends +// external programs to the TINT_BENCHMARK_WGSL_PROGRAMS() list. +#ifdef TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER +#include TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAM_HEADER +#else +#define TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAMS(x) +#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); @@ -69,7 +78,8 @@ std::variant LoadProgram(std::string name); TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-fragment.wgsl"); \ TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-vertex.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"); \ + TINT_BENCHMARK_EXTERNAL_WGSL_PROGRAMS(FUNC) } // namespace tint::bench