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 <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2023-04-19 15:03:19 +00:00 committed by Dawn LUCI CQ
parent 5f4847c23e
commit 8fc9b86214
3 changed files with 38 additions and 1 deletions

View File

@ -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}")

View File

@ -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)

View File

@ -51,6 +51,15 @@ std::variant<Source::File, Error> LoadInputFile(std::string name);
/// @returns either the loaded Program or an Error
std::variant<ProgramAndFile, Error> 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<ProgramAndFile, Error> 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