[fuzz] Add default path for Mesa Vulkan driver Adds support in the fuzzers to look for the Mesa driver in a pre-defined location, the same directory as the binary. This mirrors how dxc is found, with there being a CLI flag to override this value as needed. This is done so that ClusterFuzz targets don't require command line flags to run with the Mesa driver, since flags to the binary are not supported. This retains the ability when running locally to supply a flag to override the value. The build rules for Mesa are also changed to add a post build script that will copy the results to the route of the build directory, and rewrite the config JSON file. Since this behaviour is desired for both the tint_wgsl_fuzzer and tint_ir_fuzzer, a new common code location target is added for the fuzzers. Existing duplicated code is not migrated to use this location yet. Future CLs will do that. Various bits of documentation are updated to reference this new output layout. Bug: 506912899 Change-Id: I0f11f407dd12781b41ab6b1b84893c3c5a95f7f7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/305916 Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ryan Harrison <rharrison@chromium.org> Auto-Submit: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/docs/tint/coverage-info.md b/docs/tint/coverage-info.md index a7aa4d0..862f23a 100644 --- a/docs/tint/coverage-info.md +++ b/docs/tint/coverage-info.md
@@ -97,11 +97,11 @@ -b out/gn-coverage \ -o coverage_report \ --format html \ - -a out/gn-coverage/gen/third_party/mesa/install/lib/x86_64-linux-gnu/libvulkan_lvp.so \ + -a out/gn-coverage/libvulkan_lvp.so \ --path-equivalence=/third_party/mesa,$(pwd)/third_party/mesa \ - --path-equivalence=$(pwd)/out/gn-coverage/src,$(pwd)/out/gn-coverage/gen/third_party/mesa/mesa_setup/src \ + --path-equivalence=$(pwd)/out/gn-coverage/src,$(pwd)/out/gn-coverage/gen/third_party/mesa/mesa_build_setup/src \ -i '\/usr\/.*' \ - -c 'out/gn-coverage/tint_ir_fuzzer -max_total_time=30 --vk_icd=./out/gn-coverage/gen/third_party/mesa/install/share/vulkan/icd.d/lvp_icd.x86_64.json' + -c 'out/gn-coverage/tint_ir_fuzzer -max_total_time=30' ``` * `-a`: Adds the dynamically loaded driver as object source to the
diff --git a/src/dawn/node/README.md b/src/dawn/node/README.md index 4314e7c..77a495b 100644 --- a/src/dawn/node/README.md +++ b/src/dawn/node/README.md
@@ -137,10 +137,10 @@ VK_ICD_FILENAMES=<swiftshader-cmake-build>/Linux/vk_swiftshader_icd.json ./tools/run run-cts --bin=<path-build-dir> [WebGPU CTS query] ``` -To test against Lavapipe (mesa's software implementation of Vulkan), similarly to SwiftShader, prefix `./tools/run run-cts` with `VK_ICD_FILENAMES=<lavapipe-install-dir>/share/vulkan/icd.d/lvp_icd.x86_64.json`. For example: +To test against Lavapipe (mesa's software implementation of Vulkan), similarly to SwiftShader, prefix `./tools/run run-cts` with `VK_ICD_FILENAMES=<path-to-lvp_icd.json>`. If using the version built by Dawn, this will be `lvp_icd.json` in the root of the build directory. For example: ```sh -VK_ICD_FILENAMES=<lavapipe-install-dir>/share/vulkan/icd.d/lvp_icd.x86_64.json ./tools/run run-cts --bin=<path-build-dir> [WebGPU CTS query] +VK_ICD_FILENAMES=<path-build-dir>/lvp_icd.json ./tools/run run-cts --bin=<path-build-dir> [WebGPU CTS query] ``` The `--flag` parameter must be passed in multiple times, once for each flag begin set. Here are some common arguments: @@ -316,6 +316,22 @@ ### Building Lavapipe (LLVM Vulkan) +#### Building as part of Dawn + +Dawn can automatically build and configure Lavapipe as part of its build process. + +1. **GN Build:** + * Ensure `checkout_mesa = True` is set in your `.gclient` file's `custom_vars` section, and run `gclient sync`. + * Add `tint_build_mesa = true` to your `args.gn`. + * Build with `ninja`. +2. **CMake Build:** + * Add `-DTINT_BUILD_MESA=ON` to your CMake configuration command. + * Build with `ninja` or `make`. + +The build system will automatically copy `libvulkan_lvp.so` (or platform equivalent) and `lvp_icd.json` to the root of your build directory. + +#### Building manually + ### System requirements - Python 3.6 or newer
diff --git a/src/tint/cmd/fuzz/BUILD.cmake b/src/tint/cmd/fuzz/BUILD.cmake index 65ca459..4041b38 100644 --- a/src/tint/cmd/fuzz/BUILD.cmake +++ b/src/tint/cmd/fuzz/BUILD.cmake
@@ -34,5 +34,6 @@ # Do not modify this file directly ################################################################################ +include(cmd/fuzz/common/BUILD.cmake) include(cmd/fuzz/ir/BUILD.cmake) include(cmd/fuzz/wgsl/BUILD.cmake)
diff --git a/src/tint/cmd/fuzz/common/BUILD.bazel b/src/tint/cmd/fuzz/common/BUILD.bazel new file mode 100644 index 0000000..92a4836 --- /dev/null +++ b/src/tint/cmd/fuzz/common/BUILD.bazel
@@ -0,0 +1,54 @@ +# Copyright 2026 The Dawn & Tint Authors +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# File generated by 'tools/src/cmd/gen' using the template: +# tools/src/cmd/gen/build/BUILD.bazel.tmpl +# +# To regenerate run: './tools/run gen' +# +# Do not modify this file directly +################################################################################ + +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("//src/tint:flags.bzl", "COPTS") +load("@bazel_skylib//lib:selects.bzl", "selects") +cc_library( + name = "common", + srcs = [ + "helper.cc", + ], + hdrs = [ + "helper.h", + ], + deps = [ + "//src/tint/utils/command", + ], + copts = COPTS, + visibility = ["//visibility:public"], +) +
diff --git a/src/tint/cmd/fuzz/common/BUILD.cmake b/src/tint/cmd/fuzz/common/BUILD.cmake new file mode 100644 index 0000000..4f0660d --- /dev/null +++ b/src/tint/cmd/fuzz/common/BUILD.cmake
@@ -0,0 +1,48 @@ +# Copyright 2026 The Dawn & Tint Authors +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# File generated by 'tools/src/cmd/gen' using the template: +# tools/src/cmd/gen/build/BUILD.cmake.tmpl +# +# To regenerate run: './tools/run gen' +# +# Do not modify this file directly +################################################################################ + +################################################################################ +# Target: tint_cmd_fuzz_common +# Kind: lib +################################################################################ +tint_add_target(tint_cmd_fuzz_common lib + cmd/fuzz/common/helper.cc + cmd/fuzz/common/helper.h +) + +tint_target_add_dependencies(tint_cmd_fuzz_common lib + tint_utils_command +)
diff --git a/src/tint/cmd/fuzz/common/BUILD.gn b/src/tint/cmd/fuzz/common/BUILD.gn new file mode 100644 index 0000000..fc55e13 --- /dev/null +++ b/src/tint/cmd/fuzz/common/BUILD.gn
@@ -0,0 +1,48 @@ +# Copyright 2026 The Dawn & Tint Authors +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# File generated by 'tools/src/cmd/gen' using the template: +# tools/src/cmd/gen/build/BUILD.gn.tmpl +# +# To regenerate run: './tools/run gen' +# +# Do not modify this file directly +################################################################################ + +import("../../../../../scripts/dawn_overrides_with_defaults.gni") +import("../../../../../scripts/tint_overrides_with_defaults.gni") + +import("${tint_src_dir}/tint.gni") + +libtint_source_set("common") { + sources = [ + "helper.cc", + "helper.h", + ] + deps = [ "${tint_src_dir}/utils/command" ] +}
diff --git a/src/tint/cmd/fuzz/common/helper.cc b/src/tint/cmd/fuzz/common/helper.cc new file mode 100644 index 0000000..482958a --- /dev/null +++ b/src/tint/cmd/fuzz/common/helper.cc
@@ -0,0 +1,79 @@ +// Copyright 2026 The Dawn & Tint Authors +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "src/tint/cmd/fuzz/common/helper.h" + +#include <filesystem> +#include <iostream> + +#if TINT_BUILD_FUZZER_VULKAN_SUPPORT +#include "src/tint/utils/command/command.h" +#endif + +namespace tint::fuzz::common { + +std::string ReplaceAll(std::string str, std::string_view substr, std::string_view replacement) { + size_t pos = 0; + while ((pos = str.find(substr, pos)) != std::string_view::npos) { + str.replace(pos, substr.length(), replacement); + pos += replacement.length(); + } + return str; +} + +std::string GetDefaultVkICDPath([[maybe_unused]] char*** argv) { + std::string default_vk_icd_path = ""; +#if TINT_BUILD_FUZZER_VULKAN_SUPPORT + // Assume the Vulkan ICD JSON is in the same directory as this executable + std::string exe_path = (*argv)[0]; + exe_path = ReplaceAll(exe_path, "\\", "/"); + auto pos = exe_path.rfind('/'); + if (pos != std::string::npos) { + default_vk_icd_path = exe_path.substr(0, pos) + "/lvp_icd.json"; + } else { + // argv[0] doesn't contain path to exe, try relative to cwd + default_vk_icd_path = "lvp_icd.json"; + } + + if (!std::filesystem::exists(default_vk_icd_path)) { + default_vk_icd_path = ""; + } +#endif + return default_vk_icd_path; +} + +void PrintVkICDPathFound([[maybe_unused]] const std::string& vk_icd_path) { +#if TINT_BUILD_FUZZER_VULKAN_SUPPORT + if (!vk_icd_path.empty()) { + std::cout << "Vulkan ICD JSON found: " << vk_icd_path << "\n"; + } else { + std::cout << "Vulkan ICD JSON not found\n"; + } +#endif +} + +} // namespace tint::fuzz::common
diff --git a/src/tint/cmd/fuzz/common/helper.h b/src/tint/cmd/fuzz/common/helper.h new file mode 100644 index 0000000..814954b --- /dev/null +++ b/src/tint/cmd/fuzz/common/helper.h
@@ -0,0 +1,53 @@ +// Copyright 2026 The Dawn & Tint Authors +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef SRC_TINT_CMD_FUZZ_COMMON_HELPER_H_ +#define SRC_TINT_CMD_FUZZ_COMMON_HELPER_H_ + +#include <string> +#include <string_view> + +namespace tint::fuzz::common { + +/// ReplaceAll replaces all occurrences of @p substr with @p replacement in @p str +/// @param str the string to perform the replacement on +/// @param substr the substring to replace +/// @param replacement the replacement string +/// @returns the string with all occurrences of @p substr replaced with @p replacement +std::string ReplaceAll(std::string str, std::string_view substr, std::string_view replacement); + +/// @returns the default Vulkan ICD path for the current executable +/// @param argv the command line arguments +std::string GetDefaultVkICDPath(char*** argv); + +/// Prints the Vulkan ICD path if it is not empty +/// @param vk_icd_path the path to the Vulkan ICD +void PrintVkICDPathFound(const std::string& vk_icd_path); + +} // namespace tint::fuzz::common + +#endif // SRC_TINT_CMD_FUZZ_COMMON_HELPER_H_
diff --git a/src/tint/cmd/fuzz/ir/BUILD.cfg b/src/tint/cmd/fuzz/ir/BUILD.cfg index adbfbe7..40401c9 100644 --- a/src/tint/cmd/fuzz/ir/BUILD.cfg +++ b/src/tint/cmd/fuzz/ir/BUILD.cfg
@@ -8,6 +8,7 @@ /* Depend on all the fuzz targets to pull them all together. */ "Internal": [ "**:fuzz", + "cmd/fuzz/common", "cmd/fuzz/ir/helpers", "utils/protos/ir_fuzz:proto" ],
diff --git a/src/tint/cmd/fuzz/ir/BUILD.cmake b/src/tint/cmd/fuzz/ir/BUILD.cmake index 4cca2b9..1e49aa0 100644 --- a/src/tint/cmd/fuzz/ir/BUILD.cmake +++ b/src/tint/cmd/fuzz/ir/BUILD.cmake
@@ -50,6 +50,7 @@ tint_target_add_dependencies(tint_cmd_fuzz_ir_fuzz_cmd fuzz_cmd tint_api_common + tint_cmd_fuzz_common tint_cmd_fuzz_ir_helpers tint_cmd_fuzz_ir_fuzz tint_lang_core
diff --git a/src/tint/cmd/fuzz/ir/BUILD.gn b/src/tint/cmd/fuzz/ir/BUILD.gn index 8123bb2..c174671 100644 --- a/src/tint/cmd/fuzz/ir/BUILD.gn +++ b/src/tint/cmd/fuzz/ir/BUILD.gn
@@ -85,6 +85,7 @@ "${dawn_root}/src/utils", "${tint_lpm_dir}:libprotobuf-mutator", "${tint_src_dir}/api/common", + "${tint_src_dir}/cmd/fuzz/common", "${tint_src_dir}/cmd/fuzz/ir:fuzz", "${tint_src_dir}/cmd/fuzz/ir/helpers", "${tint_src_dir}/lang/core",
diff --git a/src/tint/cmd/fuzz/ir/main_fuzz.cc b/src/tint/cmd/fuzz/ir/main_fuzz.cc index d971b12..9f6a5f8 100644 --- a/src/tint/cmd/fuzz/ir/main_fuzz.cc +++ b/src/tint/cmd/fuzz/ir/main_fuzz.cc
@@ -33,6 +33,7 @@ #include <cstddef> #include <span> +#include "src/tint/cmd/fuzz/common/helper.h" #include "src/tint/cmd/fuzz/ir/fuzz.h" #include "src/tint/lang/core/ir/module.h" #include "src/tint/lang/core/ir/validator.h" @@ -143,7 +144,8 @@ options.run_concurrently = opt_concurrent.value.value_or(false); options.verbose = opt_verbose.value.value_or(false); #if TINT_BUILD_FUZZER_VULKAN_SUPPORT - options.vk_icd = opt_vk_icd.value.value_or(""); + options.vk_icd = opt_vk_icd.value.value_or(tint::fuzz::common::GetDefaultVkICDPath(argv)); + tint::fuzz::common::PrintVkICDPathFound(options.vk_icd); #endif options.dump_ir_when_validating = opt_dump_ir.value.value_or(false);
diff --git a/src/tint/cmd/fuzz/wgsl/BUILD.cfg b/src/tint/cmd/fuzz/wgsl/BUILD.cfg index b17eada..e641863 100644 --- a/src/tint/cmd/fuzz/wgsl/BUILD.cfg +++ b/src/tint/cmd/fuzz/wgsl/BUILD.cfg
@@ -5,7 +5,10 @@ "OutputName": "tint_wgsl_fuzzer", "AdditionalDependencies": { /* Depend on all the fuzz targets to pull them all together. */ - "Internal": [ "**:fuzz" ], + "Internal": [ + "**:fuzz", + "cmd/fuzz/common" + ], "External": [ "dxcompiler-for-fuzzer", "mesa"
diff --git a/src/tint/cmd/fuzz/wgsl/BUILD.cmake b/src/tint/cmd/fuzz/wgsl/BUILD.cmake index c1ac828..5384371 100644 --- a/src/tint/cmd/fuzz/wgsl/BUILD.cmake +++ b/src/tint/cmd/fuzz/wgsl/BUILD.cmake
@@ -46,6 +46,7 @@ tint_target_add_dependencies(tint_cmd_fuzz_wgsl_fuzz_cmd fuzz_cmd tint_api_common + tint_cmd_fuzz_common tint_cmd_fuzz_ir_fuzz tint_lang_core tint_lang_core_constant
diff --git a/src/tint/cmd/fuzz/wgsl/BUILD.gn b/src/tint/cmd/fuzz/wgsl/BUILD.gn index e300b88..e12bd55 100644 --- a/src/tint/cmd/fuzz/wgsl/BUILD.gn +++ b/src/tint/cmd/fuzz/wgsl/BUILD.gn
@@ -87,6 +87,7 @@ deps = [ "${dawn_root}/src/utils", "${tint_src_dir}/api/common", + "${tint_src_dir}/cmd/fuzz/common", "${tint_src_dir}/cmd/fuzz/ir:fuzz", "${tint_src_dir}/lang/core", "${tint_src_dir}/lang/core/constant",
diff --git a/src/tint/cmd/fuzz/wgsl/main_fuzz.cc b/src/tint/cmd/fuzz/wgsl/main_fuzz.cc index 121ad7a..def1931 100644 --- a/src/tint/cmd/fuzz/wgsl/main_fuzz.cc +++ b/src/tint/cmd/fuzz/wgsl/main_fuzz.cc
@@ -35,6 +35,7 @@ #include <span> #include <string> +#include "src/tint/cmd/fuzz/common/helper.h" #include "src/tint/cmd/fuzz/wgsl/fuzz.h" #include "src/tint/utils/command/cli.h" #include "src/tint/utils/command/command.h" @@ -49,23 +50,12 @@ tint::fuzz::wgsl::Options options; -[[nodiscard]] inline std::string ReplaceAll(std::string str, - std::string_view substr, - std::string_view replacement) { - size_t pos = 0; - while ((pos = str.find(substr, pos)) != std::string_view::npos) { - str.replace(pos, substr.length(), replacement); - pos += replacement.length(); - } - return str; -} - std::string get_default_dxc_path(char*** argv) { std::string default_dxc_path = ""; #if TINT_BUILD_HLSL_WRITER // Assume the DXC library is in the same directory as this executable std::string exe_path = (*argv)[0]; - exe_path = ReplaceAll(exe_path, "\\", "/"); + exe_path = tint::fuzz::common::ReplaceAll(exe_path, "\\", "/"); auto pos = exe_path.rfind('/'); if (pos != std::string::npos) { default_dxc_path = exe_path.substr(0, pos) + '/' + tint::hlsl::validate::kDxcDLLName; @@ -161,12 +151,15 @@ options.verbose = opt_verbose.value.value_or(false); options.dxc = opt_dxc.value.value_or(get_default_dxc_path(argv)); #if TINT_BUILD_FUZZER_VULKAN_SUPPORT - options.vk_icd = opt_vk_icd.value.value_or(""); + options.vk_icd = opt_vk_icd.value.value_or(tint::fuzz::common::GetDefaultVkICDPath(argv)); #endif options.dump = opt_dump.value.value_or(false); options.dump_ir_when_validating = opt_dump_ir.value.value_or(false); print_dxc_path_found(options.dxc); +#if TINT_BUILD_FUZZER_VULKAN_SUPPORT + tint::fuzz::common::PrintVkICDPathFound(options.vk_icd); +#endif #if DAWN_ASAN_ENABLED() && !defined(NDEBUG) // TODO(crbug.com/352402877): Avoid DXC timeouts on asan + debug fuzzer builds std::cout << "DXC validation disabled in asan + debug builds"
diff --git a/third_party/mesa/BUILD.gn b/third_party/mesa/BUILD.gn index 6ec0fdc..1bb0beb 100644 --- a/third_party/mesa/BUILD.gn +++ b/third_party/mesa/BUILD.gn
@@ -29,8 +29,22 @@ import("${mesa_meson_dir}/meson_target.gni") -meson_target("mesa") { +meson_target("mesa_build") { source_dir = "src" options = mesa_options outputs = [ "${target_gen_dir}/install" ] } + +action("copy_mesa_vulkan_icd") { + script = "copy_mesa_driver.py" + deps = [ ":mesa_build" ] + args = [ + rebase_path("${target_gen_dir}/install", root_build_dir), + rebase_path(root_out_dir, root_build_dir), + ] + outputs = [ "${root_out_dir}/lvp_icd.json" ] +} + +group("mesa") { + public_deps = [ ":copy_mesa_vulkan_icd" ] +}
diff --git a/third_party/mesa/CMakeLists.txt b/third_party/mesa/CMakeLists.txt index 788aaad..dbd81e6 100644 --- a/third_party/mesa/CMakeLists.txt +++ b/third_party/mesa/CMakeLists.txt
@@ -32,7 +32,15 @@ "-Dvulkan-drivers=swrast" ) -meson_target("mesa" +meson_target("mesa_build" SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" OPTIONS ${MESA_OPTIONS} ) + +add_custom_target("mesa" ALL + COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/copy_mesa_driver.py" + "${CMAKE_CURRENT_BINARY_DIR}/install" + "${CMAKE_BINARY_DIR}" + DEPENDS "mesa_build" + COMMENT "Copying Mesa Vulkan ICD and driver to root build directory" +)
diff --git a/third_party/mesa/copy_mesa_driver.py b/third_party/mesa/copy_mesa_driver.py new file mode 100644 index 0000000..50562d2 --- /dev/null +++ b/third_party/mesa/copy_mesa_driver.py
@@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + +# Copyright 2026 The Dawn & Tint Authors +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import glob +import json +import os +import shutil +import sys + + +def main(): + if len(sys.argv) != 3: + print("Usage: copy_mesa_driver.py <mesa_install_dir> <output_dir>") + sys.exit(1) + + install_dir = sys.argv[1] + out_dir = sys.argv[2] + + # Find the ICD JSON + json_pattern = os.path.join(install_dir, '**', 'lvp_icd.*.json') + json_files = glob.glob(json_pattern, recursive=True) + if not json_files: + print(f"Could not find lvp_icd.*.json in {install_dir}") + sys.exit(1) + + # Find the shared library + # Linux: libvulkan_lvp.so, Windows: vulkan_lvp.dll, Mac: libvulkan_lvp.dylib + so_pattern = os.path.join(install_dir, '**', '*vulkan_lvp*') + so_files = [ + f for f in glob.glob(so_pattern, recursive=True) + if os.path.isfile(f) and f.endswith(('.so', '.dll', '.dylib')) + ] + if not so_files: + print(f"Could not find vulkan_lvp shared library in {install_dir}") + sys.exit(1) + + so_file = so_files[0] + so_name = os.path.basename(so_file) + + # Copy shared library + shutil.copy2(so_file, os.path.join(out_dir, so_name)) + + # Read and update JSON + with open(json_files[0], 'r') as f: + icd_data = json.load(f) + + # Update library_path to be relative to the JSON manifest + icd_data['ICD']['library_path'] = f"./{so_name}" + + # Write updated JSON + out_json = os.path.join(out_dir, "lvp_icd.json") + with open(out_json, 'w') as f: + json.dump(icd_data, f, indent=4) + + +if __name__ == '__main__': + main()