From c8ac7e4a76264f106daf114871a3cd2f89520864 Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:17:25 -0600 Subject: [PATCH 1/3] runtime: -DLEONIDA_VULKAN_HEADERS_FETCH=ON uses the pinned Vulkan-Headers even when others are installed (CMAKE-VULKAN-HEADERS-PIN) find_package(Vulkan) and the find_path(Vulkan_INCLUDE_DIR) fallback ran before the fetch branch, so any Vulkan headers on the machine (an SDK, conda-forge's vulkan-headers, /usr/include) defined Vulkan::Headers first and the pinned Khronos Vulkan-Headers 6802bb47 (vulkan-sdk-1.4.363.0) were never used, even with the flag on. Against conda-forge's Vulkan 1.3 headers that cost a Radeon 780M three GPU tests (225/248 passed instead of 228/248). The fetch, or a FETCHCONTENT_SOURCE_DIR_VULKANHEADERS copy, now runs first. FindVulkan still runs afterwards for glslangValidator and leaves the existing Vulkan::Headers alone. The pinned commit is one variable the URL uses. Every configure with headers prints one "-- Vulkan headers:" line with the include directory, VK_HEADER_VERSION and whether they are the pin (runtime/cmake/vulkan_headers_report.cmake); docs/testing.md and docs/gpu_test_results.md ask a GPU record to build with the pin and quote it. tests/test_cmake_vulkan_headers_pin.py configures runtime/ with a fake SDK on VULKAN_SDK and a fake local copy of the pin (no network) and checks the include directories Vulkan::Headers carries; it fails on main. Co-Authored-By: Claude Opus 5.5 --- docs/gpu_test_results.md | 6 + docs/testing.md | 13 ++ runtime/CMakeLists.txt | 51 +++-- runtime/README.md | 3 +- runtime/cmake/vulkan_headers_report.cmake | 50 +++++ tests/test_cmake_vulkan_headers_pin.py | 224 ++++++++++++++++++++++ 6 files changed, 331 insertions(+), 16 deletions(-) create mode 100644 runtime/cmake/vulkan_headers_report.cmake create mode 100644 tests/test_cmake_vulkan_headers_pin.py diff --git a/docs/gpu_test_results.md b/docs/gpu_test_results.md index c1503a06c1..8c26c82070 100644 --- a/docs/gpu_test_results.md +++ b/docs/gpu_test_results.md @@ -4,6 +4,12 @@ This page keeps a local record of GPU test runs. The project's public tracker is [#166](https://github.com/ItsNotRexed/Leonida/issues/166) (one comment per GPU and driver); post counts and pass/fail lines there, never game shaders, logs or private paths. +Name the Vulkan headers a run was built against: configure with `-DLEONIDA_VULKAN_HEADERS_FETCH=ON`, which uses the +repository's pinned Khronos Vulkan-Headers whatever else is installed, and quote the configure's `-- Vulkan headers:` +line in the entry. Other headers can change the counts ([testing.md](testing.md#build-the-test-programs)). Until +`CMAKE-VULKAN-HEADERS-PIN` the flag lost to any Vulkan headers already on the machine, so an older entry whose setup +names it may have been built against those instead. + | GPU | Driver, OS | Commit | build.py | check.py | run_gpu_tests.py | Failed | Entry | |---|---|---|---|---|---|---|---| | AMD Radeon RX 9070 GRE (RDNA4, GFX1201), subgroup 32..64 | RADV, Mesa 26.3.1-arch3.5, Vulkan 1.4.363, CachyOS | `05961f0` | 264/264 translated and valid | 203/206 pass, 3 skipped | 218/235 passed, 16 skipped (native and emulated) | `ms_wave_info_s3`, flaky (see below) | [local note](../gpu-test-results/RX9070GRE.txt) | diff --git a/docs/testing.md b/docs/testing.md index 149e44476d..8a92e1709e 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -93,6 +93,19 @@ cmake --build runtime/build/linux --parallel On macOS, add `-DVulkan_INCLUDE_DIR=/opt/homebrew/include` to the first command. +For a result you will post, add `-DLEONIDA_VULKAN_HEADERS_FETCH=ON` to the first command. It builds against the +repository's pinned Khronos Vulkan-Headers (downloaded once at configure time and hash-checked; +`-DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS=` uses a local copy instead), even when `VULKAN_SDK`, +`Vulkan_INCLUDE_DIR` or installed headers name others, so two records of the same GPU compare. The headers decide +what the test programs can ask the driver for: built against conda-forge's Vulkan 1.3 headers instead of the pin, a +Radeon 780M skipped `ps_texoff`, `ps_texoff_forms` and `ps_texoff_implicit` (225/248 passed instead of 228/248, +[#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122653687)). Every configure names the +headers it uses in one line; quote it in the record: + +```text +-- Vulkan headers: /_deps/vulkanheaders-src/include (VK_HEADER_VERSION 363), the pin: Khronos Vulkan-Headers 6802bb4733b63ed5efd3adb308a6c885ef180ea1, hash-checked +``` + The test programs and `scripts/run_gpu_tests.py` should come from the same commit. Some checks tolerate an older binary (`unpinned_subgroup_skip`), but mixing them can report false failures in the compute tests: 28 `cs_*` failures on both an RTX 5070 Ti Laptop and a Radeon 610M with the `426023a` script and `48ad23f` binaries, where diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 64e346f40a..640959ff40 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1368,11 +1368,40 @@ if(BUILD_TESTING) endif() # GPU test and pipeline tools load Vulkan at run time, so only the Vulkan headers are needed at build time. -# Nothing is downloaded unless asked: set VULKAN_SDK, install the Vulkan headers, pass -# -DLEONIDA_VULKAN_HEADERS_FETCH=ON to download the pinned Khronos Vulkan-Headers release once at configure time -# (hash-checked), or pass -DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS= to use a local copy without downloading. -option(LEONIDA_VULKAN_HEADERS_FETCH "Download the pinned Khronos Vulkan-Headers release if no Vulkan headers are found" OFF) +# Nothing is downloaded unless asked. -DLEONIDA_VULKAN_HEADERS_FETCH=ON downloads the pinned Khronos Vulkan-Headers +# release once at configure time (hash-checked), and -DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS= uses a local +# copy of it without downloading. Either one wins over any other Vulkan headers on the machine (VULKAN_SDK, +# Vulkan_INCLUDE_DIR, conda-forge's vulkan-headers, /usr/include), so GPU test results built with it compare across +# machines. Without them the headers come from VULKAN_SDK, Vulkan_INCLUDE_DIR or an install. The configure names the +# headers it uses in a "Vulkan headers:" line (cmake/vulkan_headers_report.cmake). +option(LEONIDA_VULKAN_HEADERS_FETCH "Build against the pinned Khronos Vulkan-Headers release (downloaded once), even when other Vulkan headers are installed" OFF) option(LEONIDA_REQUIRE_VULKAN "Fail the configure instead of warning when no Vulkan headers are found" OFF) +# The pinned Khronos Vulkan-Headers commit, which the "Vulkan headers:" line names. +set(LEONIDA_VULKAN_HEADERS_PIN 6802bb4733b63ed5efd3adb308a6c885ef180ea1) +set(leonida_vulkan_headers_origin FOUND) +if(LEONIDA_VULKAN_HEADERS_FETCH OR FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) + # Before find_package(Vulkan): it would define Vulkan::Headers from whatever headers it finds first, and the pin + # would never be used. FindVulkan leaves an existing Vulkan::Headers alone. + include(FetchContent) + FetchContent_Declare(VulkanHeaders + # vulkan-sdk-1.4.363.0 (same commit pinned in .github/workflows/runtime.yml) + URL https://github.com/KhronosGroup/Vulkan-Headers/archive/${LEONIDA_VULKAN_HEADERS_PIN}.tar.gz + URL_HASH SHA256=9044fbb356160e43201dc2094acb44c8a906722a63a35f48fc0f051579db9bb6 + DOWNLOAD_EXTRACT_TIMESTAMP TRUE) + set(VULKAN_HEADERS_ENABLE_TESTS OFF CACHE BOOL "" FORCE) + set(VULKAN_HEADERS_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) + set(VULKAN_HEADERS_ENABLE_MODULE OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(VulkanHeaders) + if(NOT TARGET Vulkan::Headers) + message(FATAL_ERROR "The Vulkan-Headers project in ${vulkanheaders_SOURCE_DIR} defines no Vulkan::Headers target") + endif() + if(FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) + set(leonida_vulkan_headers_origin SOURCE_DIR) + else() + set(leonida_vulkan_headers_origin PIN) + endif() +endif() +# Also finds glslangValidator (Vulkan_GLSLANG_VALIDATOR_EXECUTABLE), which the shader-building tests below use. find_package(Vulkan QUIET) if(NOT TARGET Vulkan::Headers) find_path(Vulkan_INCLUDE_DIR @@ -1384,20 +1413,12 @@ if(NOT TARGET Vulkan::Headers) set_target_properties(Vulkan::Headers PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIR}" ) - elseif(LEONIDA_VULKAN_HEADERS_FETCH OR FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) - include(FetchContent) - FetchContent_Declare(VulkanHeaders - # vulkan-sdk-1.4.363.0 (same commit pinned in .github/workflows/runtime.yml) - URL https://github.com/KhronosGroup/Vulkan-Headers/archive/6802bb4733b63ed5efd3adb308a6c885ef180ea1.tar.gz - URL_HASH SHA256=9044fbb356160e43201dc2094acb44c8a906722a63a35f48fc0f051579db9bb6 - DOWNLOAD_EXTRACT_TIMESTAMP TRUE) - set(VULKAN_HEADERS_ENABLE_TESTS OFF CACHE BOOL "" FORCE) - set(VULKAN_HEADERS_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) - set(VULKAN_HEADERS_ENABLE_MODULE OFF CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(VulkanHeaders) endif() endif() if(TARGET Vulkan::Headers) + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/vulkan_headers_report.cmake") + get_target_property(leonida_vk_include_dirs Vulkan::Headers INTERFACE_INCLUDE_DIRECTORIES) + leonida_vulkan_headers_report("${leonida_vk_include_dirs}" ${leonida_vulkan_headers_origin}) foreach(tool vk_harness vk_ps_sweep vk_texture_test vk_sampler_test vk_compute_test vk_store_test vk_pipeline_check vk_command_replay_test vk_bindless_test vk_image_fuzz vk_descriptor_bench depth24_convert_test vk_predicate_capture_test vk_predicated_copy_test vk_xdxr_build_test vk_queue_test vk_sandbox) diff --git a/runtime/README.md b/runtime/README.md index 61794a2c2d..795cbedc3a 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -267,7 +267,8 @@ ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure On Windows the build configures the CPU tests that do not need a GPU or game files, including the root-signature forwarding test (`root_sig_test`) and the clear-command test. The Vulkan tools and D3D12-over-Vulkan COM targets are built when Vulkan headers are found (via `VULKAN_SDK`, an installed -SDK, or `-DLEONIDA_VULKAN_HEADERS_FETCH=ON` to download the pinned Khronos Vulkan-Headers release): +SDK, or `-DLEONIDA_VULKAN_HEADERS_FETCH=ON` to download the pinned Khronos Vulkan-Headers release, which then wins +over any installed headers; the configure's `-- Vulkan headers:` line names the ones in use): - `vk_harness` — hand-written RDNA2 shader programs on a real Vulkan device. - `vk_texture_test`, `vk_compute_test`, `vk_store_test` — texture, LDS/compute, and buffer-store paths. diff --git a/runtime/cmake/vulkan_headers_report.cmake b/runtime/cmake/vulkan_headers_report.cmake new file mode 100644 index 0000000000..2129ca636f --- /dev/null +++ b/runtime/cmake/vulkan_headers_report.cmake @@ -0,0 +1,50 @@ +# Names the Vulkan headers a configure builds against, in one STATUS line a GPU test record can quote: +# -- Vulkan headers: (VK_HEADER_VERSION ), +# The headers decide what the GPU test tools can ask the driver for, so two records of the same GPU and driver differ +# when their headers do: rebuilt against conda-forge's Vulkan 1.3 headers instead of the pin, run_gpu_tests.py on a +# Radeon 780M skipped ps_texoff, ps_texoff_forms and ps_texoff_implicit (225/248 passed instead of 228/248). +# Kept in its own file so tests/test_cmake_vulkan_headers_pin.py can run it with `cmake -P`. + +# include_dirs: the INTERFACE_INCLUDE_DIRECTORIES of Vulkan::Headers. Generator expressions such as +# $ (FetchContent's target) are unwrapped. origin: PIN (the hash-checked download of +# LEONIDA_VULKAN_HEADERS_PIN), SOURCE_DIR (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) or FOUND (anything else). +function(leonida_vulkan_headers_report include_dirs origin) + set(dir "") + set(header "") + foreach(d IN LISTS include_dirs) + string(REGEX REPLACE "^\\$$" "\\1" d "${d}") + if(NOT d OR d MATCHES "^\\$<") + continue() + endif() + foreach(name vulkan_core.h vulkan.h) + if(EXISTS "${d}/vulkan/${name}") + set(dir "${d}") + set(header "${d}/vulkan/${name}") + break() + endif() + endforeach() + if(dir) + break() + endif() + endforeach() + set(version "unknown") + if(header) + file(STRINGS "${header}" line REGEX "^#define VK_HEADER_VERSION [0-9]+" LIMIT_COUNT 1) + if(line MATCHES "VK_HEADER_VERSION ([0-9]+)") + set(version "${CMAKE_MATCH_1}") + endif() + else() + set(dir "${include_dirs}") + endif() + if(origin STREQUAL "PIN") + set(what "the pin: Khronos Vulkan-Headers ${LEONIDA_VULKAN_HEADERS_PIN}, hash-checked") + elseif(origin STREQUAL "SOURCE_DIR") + set(what "from FETCHCONTENT_SOURCE_DIR_VULKANHEADERS: a local copy used in place of the pin, not checked " + "against it") + else() + set(what "found on this machine, not the pin (-DLEONIDA_VULKAN_HEADERS_FETCH=ON builds against the pinned " + "Khronos Vulkan-Headers)") + endif() + string(CONCAT what ${what}) + message(STATUS "Vulkan headers: ${dir} (VK_HEADER_VERSION ${version}), ${what}") +endfunction() diff --git a/tests/test_cmake_vulkan_headers_pin.py b/tests/test_cmake_vulkan_headers_pin.py new file mode 100644 index 0000000000..0cde32099b --- /dev/null +++ b/tests/test_cmake_vulkan_headers_pin.py @@ -0,0 +1,224 @@ +"""-DLEONIDA_VULKAN_HEADERS_FETCH=ON (or a FETCHCONTENT_SOURCE_DIR_VULKANHEADERS copy) must win over other headers. + +runtime/CMakeLists.txt used to run find_package(Vulkan) and find_path(Vulkan_INCLUDE_DIR) before the fetch, so any +Vulkan headers on the machine (an SDK, conda-forge's vulkan-headers, /usr/include) defined Vulkan::Headers first and +the pinned Khronos Vulkan-Headers were never used, even with the flag on. That changes GPU results: against +conda-forge's Vulkan 1.3 headers run_gpu_tests.py on a Radeon 780M skipped ps_texoff, ps_texoff_forms and +ps_texoff_implicit (225/248 passed instead of 228/248 with the pin). The configure now also names its headers in a +"Vulkan headers:" line (runtime/cmake/vulkan_headers_report.cmake) that a GPU record can quote. + +The configure cases run CMake on runtime/ with hand-written stand-ins for an installed SDK (VULKAN_SDK) and for the +pinned release (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS), so nothing is downloaded and no real Vulkan headers are +needed. They need cmake and a C++ compiler and are skipped without them; the cmake -P cases need cmake only. +""" +import os +import re +import shutil +import subprocess +import tempfile +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +RUNTIME = ROOT / "runtime" +MODULE = RUNTIME / "cmake" / "vulkan_headers_report.cmake" +CMAKE_LISTS = RUNTIME / "CMakeLists.txt" +CMAKE = shutil.which("cmake") + +SDK_VERSION = 231 # conda-forge's vulkan-headers next to llvm-tools +PIN_VERSION = 363 # vulkan-sdk-1.4.363.0 + +# Runs at the end of the top-level directory (cmake_language DEFER) and writes the include directories of the +# Vulkan::Headers target the tools link, which is what the compiler gets, independent of the "Vulkan headers:" line. +HOOK = """\ +function(leonida_test_dump_vulkan_headers) + if(TARGET Vulkan::Headers) + get_target_property(dirs Vulkan::Headers INTERFACE_INCLUDE_DIRECTORIES) + else() + set(dirs NONE) + endif() + file(WRITE "${CMAKE_BINARY_DIR}/leonida_test_vulkan_headers.txt" "${dirs}") +endfunction() +cmake_language(DEFER CALL leonida_test_dump_vulkan_headers) +""" + +# A stand-in for the Khronos Vulkan-Headers project: the same target names and include directory layout. +FAKE_PROJECT = """\ +cmake_minimum_required(VERSION 3.24) +project(Vulkan-Headers LANGUAGES NONE) +add_library(Vulkan-Headers INTERFACE) +add_library(Vulkan::Headers ALIAS Vulkan-Headers) +target_include_directories(Vulkan-Headers INTERFACE "$") +""" + + +def write(path, text): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text, encoding="utf-8", newline="\n") + + +def write_headers(include, version): + """vulkan/vulkan.h and vulkan/vulkan_core.h under include; version None writes no VK_HEADER_VERSION line.""" + line = f"#define VK_HEADER_VERSION {version}\n" if version is not None else "" + write(include / "vulkan" / "vulkan_core.h", f"#ifndef VULKAN_CORE_H_\n#define VULKAN_CORE_H_ 1\n{line}#endif\n") + write(include / "vulkan" / "vulkan.h", '#include "vulkan_core.h"\n') + + +def same_dir(a, b): + return os.path.normcase(os.path.realpath(a)) == os.path.normcase(os.path.realpath(b)) + + +def included(text): + """The directories of an INTERFACE_INCLUDE_DIRECTORIES value, with $ unwrapped.""" + dirs = [] + for d in text.split(";"): + m = re.fullmatch(r"\$", d) + if m: + d = m.group(1) + if d and not d.startswith("$<"): + dirs.append(d) + return dirs + + +def headers_line(output): + lines = [ln for ln in output.splitlines() if "Vulkan headers:" in ln] + return lines[-1] if lines else "" + + +def run_module(dirs, origin): + with tempfile.TemporaryDirectory() as tmp: + script = Path(tmp) / "driver.cmake" + write(script, f'include("{MODULE.as_posix()}")\n' + 'set(LEONIDA_VULKAN_HEADERS_PIN 0123456789abcdef0123456789abcdef01234567)\n' + f'leonida_vulkan_headers_report("{dirs}" {origin})\n') + return subprocess.run([CMAKE, "-P", str(script)], capture_output=True, text=True, timeout=60) + + +@unittest.skipUnless(CMAKE, "cmake not on PATH") +class ReportLineTest(unittest.TestCase): + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.include = Path(tmp.name) / "include" + + def test_found_headers_are_named_and_not_called_the_pin(self): + write_headers(self.include, SDK_VERSION) + r = run_module(self.include.as_posix(), "FOUND") + self.assertEqual(r.returncode, 0, r.stderr) + line = headers_line(r.stdout) + self.assertIn(f"Vulkan headers: {self.include.as_posix()} (VK_HEADER_VERSION {SDK_VERSION})", line) + self.assertIn("not the pin", line) + self.assertIn("-DLEONIDA_VULKAN_HEADERS_FETCH=ON", line) + + def test_pin_names_the_commit(self): + write_headers(self.include, PIN_VERSION) + r = run_module(f"$", "PIN") + self.assertEqual(r.returncode, 0, r.stderr) + line = headers_line(r.stdout) + self.assertIn(f"Vulkan headers: {self.include.as_posix()} (VK_HEADER_VERSION {PIN_VERSION})", line) + self.assertIn("the pin: Khronos Vulkan-Headers 0123456789abcdef0123456789abcdef01234567", line) + + def test_source_dir_copy_is_not_vouched_for(self): + write_headers(self.include, PIN_VERSION) + r = run_module(self.include.as_posix(), "SOURCE_DIR") + self.assertEqual(r.returncode, 0, r.stderr) + line = headers_line(r.stdout) + self.assertIn("FETCHCONTENT_SOURCE_DIR_VULKANHEADERS", line) + self.assertIn("not checked against it", line) + + def test_header_without_a_version_says_unknown(self): + write_headers(self.include, None) + r = run_module(self.include.as_posix(), "FOUND") + self.assertEqual(r.returncode, 0, r.stderr) + self.assertIn("(VK_HEADER_VERSION unknown)", headers_line(r.stdout)) + + +@unittest.skipUnless(CMAKE, "cmake not on PATH") +class ConfigureTest(unittest.TestCase): + """Configures runtime/ with a fake installed SDK on VULKAN_SDK and a fake copy of the pinned release.""" + + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + base = Path(tmp.name).resolve() + self.sdk_include = base / "sdk" / "include" + write_headers(self.sdk_include, SDK_VERSION) + self.pin_source = base / "vulkan-headers" + self.pin_include = self.pin_source / "include" + write_headers(self.pin_include, PIN_VERSION) + write(self.pin_source / "CMakeLists.txt", FAKE_PROJECT) + self.hook = base / "hook.cmake" + write(self.hook, HOOK) + self.base = base + self.env = dict(os.environ, VULKAN_SDK=str(base / "sdk")) + + def configure(self, build, *args): + cmd = [CMAKE, "-S", str(RUNTIME), "-B", str(build), f"-DCMAKE_PROJECT_gta6rt_INCLUDE={self.hook.as_posix()}", + "-DBUILD_TESTING=OFF", "-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF", *args] + r = subprocess.run(cmd, capture_output=True, text=True, timeout=600, env=self.env) + out = r.stdout + r.stderr + if r.returncode and "CMAKE_CXX_COMPILER" in out and not (build / "leonida_test_vulkan_headers.txt").exists(): + self.skipTest("no working C++ compiler for CMake") + self.assertEqual(r.returncode, 0, out[-4000:]) + dirs = included((build / "leonida_test_vulkan_headers.txt").read_text(encoding="utf-8")) + return dirs, headers_line(out) + + def assert_uses(self, dirs, include): + self.assertTrue(any(same_dir(d, include) for d in dirs), f"Vulkan::Headers includes {dirs}, not {include}") + + def assert_pin(self, dirs, line): + self.assert_uses(dirs, self.pin_include) + self.assertFalse(any(same_dir(d, self.sdk_include) for d in dirs), dirs) + self.assertIn(f"(VK_HEADER_VERSION {PIN_VERSION})", line) + self.assertIn("FETCHCONTENT_SOURCE_DIR_VULKANHEADERS", line) + + def test_fetch_wins_over_installed_headers(self): + dirs, line = self.configure(self.base / "build", "-DLEONIDA_VULKAN_HEADERS_FETCH=ON", + f"-DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS={self.pin_source.as_posix()}") + self.assert_pin(dirs, line) + + def test_turning_fetch_on_in_a_build_that_found_headers(self): + build = self.base / "build" + # The installed SDK is visible: without the fetch it is used (and Vulkan_INCLUDE_DIR is cached). + dirs, line = self.configure(build) + self.assert_uses(dirs, self.sdk_include) + self.assertIn(f"(VK_HEADER_VERSION {SDK_VERSION}), found on this machine, not the pin", line) + # The same build folder with the fetch turned on: the pin, not the cached lookup. + dirs, line = self.configure(build, "-DLEONIDA_VULKAN_HEADERS_FETCH=ON", + f"-DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS={self.pin_source.as_posix()}") + self.assert_pin(dirs, line) + # And off again: back to the installed headers. + dirs, line = self.configure(build, "-DLEONIDA_VULKAN_HEADERS_FETCH=OFF", + "-UFETCHCONTENT_SOURCE_DIR_VULKANHEADERS") + self.assert_uses(dirs, self.sdk_include) + self.assertIn("not the pin", line) + + +class CMakeListsTest(unittest.TestCase): + def setUp(self): + self.text = CMAKE_LISTS.read_text(encoding="utf-8") + + def test_fetch_comes_before_find_package(self): + fetch = re.search(r"^if\(LEONIDA_VULKAN_HEADERS_FETCH OR FETCHCONTENT_SOURCE_DIR_VULKANHEADERS\)$", self.text, + re.M) + self.assertIsNotNone(fetch, "the top-level fetch branch is missing from runtime/CMakeLists.txt") + self.assertLess(fetch.start(), self.text.index("\nfind_package(Vulkan QUIET)\n")) + + def test_headers_line_is_printed_with_the_tools(self): + m = re.search(r"^if\(TARGET Vulkan::Headers\)\n(.*?)^ foreach\(tool ", self.text, re.S | re.M) + self.assertIsNotNone(m, "if(TARGET Vulkan::Headers) ... foreach(tool ...) not found") + self.assertIn("vulkan_headers_report.cmake", m.group(1)) + self.assertIn("leonida_vulkan_headers_report(", m.group(1)) + + def test_pin_matches_the_ci_checkout(self): + m = re.search(r"^set\(LEONIDA_VULKAN_HEADERS_PIN ([0-9a-f]{40})\)$", self.text, re.M) + self.assertIsNotNone(m, "set(LEONIDA_VULKAN_HEADERS_PIN ) not found") + self.assertIn("Vulkan-Headers/archive/${LEONIDA_VULKAN_HEADERS_PIN}.tar.gz", self.text) + ci = (ROOT / ".github" / "workflows" / "runtime.yml").read_text(encoding="utf-8") + refs = re.findall(r"^\s*ref: ([0-9a-f]{40}) # vulkan-sdk-", ci, re.M) + self.assertTrue(refs, "no Vulkan-Headers checkout in runtime.yml") + self.assertEqual(set(refs), {m.group(1)}) + + +if __name__ == "__main__": + unittest.main() From aea4da4ca3c3890499ed30b7c3bdbb402c0afe2d Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:18:35 -0600 Subject: [PATCH 2/3] runtime: the Vulkan-Headers pin can't be replaced by an installed package (CMAKE-VULKAN-HEADERS-PIN) With -DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS, FetchContent_MakeAvailable(VulkanHeaders) tried find_package(VulkanHeaders) first: an installed VulkanHeadersConfig.cmake (VK_HEADER_VERSION 111) became Vulkan::Headers, nothing was downloaded, and the "Vulkan headers:" line still called it the pin. - The declaration carries OVERRIDE_FIND_PACKAGE, so FetchContent never tries find_package() in place of the pin, and a later find_package(VulkanHeaders) gets the pin. - After FetchContent_MakeAvailable, leonida_vulkan_headers_check fails the configure unless Vulkan::Headers is the copy FetchContent populated, which catches a dependency provider or an earlier FetchContent_Declare(VulkanHeaders). For the pin, the copy must also be VK_HEADER_VERSION LEONIDA_VULKAN_HEADERS_PIN_VERSION (363), which catches a stale copy kept by FETCHCONTENT_FULLY_DISCONNECTED=ON. - tests/test_cmake_vulkan_headers_pin.py: offline configures for ALWAYS mode with an installed package (pre-seeded FETCHCONTENT_BASE_DIR, FULLY_DISCONNECTED), a dependency provider and a stale copy, cmake -P cases for the check, and the pin version against runtime.yml. Reported by Dezmonius on #491. Co-Authored-By: Claude Opus 5.5 --- docs/testing.md | 8 +- runtime/CMakeLists.txt | 22 ++- runtime/cmake/vulkan_headers_report.cmake | 58 ++++++- tests/test_cmake_vulkan_headers_pin.py | 180 ++++++++++++++++++++-- 4 files changed, 239 insertions(+), 29 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 8a92e1709e..97130b5fb9 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -96,9 +96,11 @@ On macOS, add `-DVulkan_INCLUDE_DIR=/opt/homebrew/include` to the first command. For a result you will post, add `-DLEONIDA_VULKAN_HEADERS_FETCH=ON` to the first command. It builds against the repository's pinned Khronos Vulkan-Headers (downloaded once at configure time and hash-checked; `-DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS=` uses a local copy instead), even when `VULKAN_SDK`, -`Vulkan_INCLUDE_DIR` or installed headers name others, so two records of the same GPU compare. The headers decide -what the test programs can ask the driver for: built against conda-forge's Vulkan 1.3 headers instead of the pin, a -Radeon 780M skipped `ps_texoff`, `ps_texoff_forms` and `ps_texoff_implicit` (225/248 passed instead of 228/248, +`Vulkan_INCLUDE_DIR` or installed headers name others, so two records of the same GPU compare. When something else +would supply other headers in place of the pin (a dependency provider, or a stale download kept by +`FETCHCONTENT_FULLY_DISCONNECTED`), the configure fails instead. The headers decide what the test programs can ask the +driver for: built against conda-forge's Vulkan 1.3 headers instead of the pin, a Radeon 780M skipped `ps_texoff`, +`ps_texoff_forms` and `ps_texoff_implicit` (225/248 passed instead of 228/248, [#14](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122653687)). Every configure names the headers it uses in one line; quote it in the record: diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 640959ff40..c16e3b8b8d 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1376,30 +1376,41 @@ endif() # headers it uses in a "Vulkan headers:" line (cmake/vulkan_headers_report.cmake). option(LEONIDA_VULKAN_HEADERS_FETCH "Build against the pinned Khronos Vulkan-Headers release (downloaded once), even when other Vulkan headers are installed" OFF) option(LEONIDA_REQUIRE_VULKAN "Fail the configure instead of warning when no Vulkan headers are found" OFF) -# The pinned Khronos Vulkan-Headers commit, which the "Vulkan headers:" line names. +# The pinned Khronos Vulkan-Headers commit, which the "Vulkan headers:" line names, and its VK_HEADER_VERSION. set(LEONIDA_VULKAN_HEADERS_PIN 6802bb4733b63ed5efd3adb308a6c885ef180ea1) +set(LEONIDA_VULKAN_HEADERS_PIN_VERSION 363) +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/vulkan_headers_report.cmake") set(leonida_vulkan_headers_origin FOUND) if(LEONIDA_VULKAN_HEADERS_FETCH OR FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) # Before find_package(Vulkan): it would define Vulkan::Headers from whatever headers it finds first, and the pin # would never be used. FindVulkan leaves an existing Vulkan::Headers alone. include(FetchContent) + # OVERRIDE_FIND_PACKAGE: FetchContent_MakeAvailable never tries find_package(VulkanHeaders) in place of the pin, even + # with -DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS, and a later find_package(VulkanHeaders) gets the pin. FetchContent_Declare(VulkanHeaders # vulkan-sdk-1.4.363.0 (same commit pinned in .github/workflows/runtime.yml) URL https://github.com/KhronosGroup/Vulkan-Headers/archive/${LEONIDA_VULKAN_HEADERS_PIN}.tar.gz URL_HASH SHA256=9044fbb356160e43201dc2094acb44c8a906722a63a35f48fc0f051579db9bb6 - DOWNLOAD_EXTRACT_TIMESTAMP TRUE) + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + OVERRIDE_FIND_PACKAGE) set(VULKAN_HEADERS_ENABLE_TESTS OFF CACHE BOOL "" FORCE) set(VULKAN_HEADERS_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) set(VULKAN_HEADERS_ENABLE_MODULE OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(VulkanHeaders) - if(NOT TARGET Vulkan::Headers) - message(FATAL_ERROR "The Vulkan-Headers project in ${vulkanheaders_SOURCE_DIR} defines no Vulkan::Headers target") - endif() + FetchContent_GetProperties(VulkanHeaders) if(FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) set(leonida_vulkan_headers_origin SOURCE_DIR) else() set(leonida_vulkan_headers_origin PIN) endif() + # A dependency provider or an earlier FetchContent_Declare(VulkanHeaders) can still answer FetchContent_MakeAvailable + # with other headers; fail rather than build against them and call them the pin. + set(leonida_vk_include_dirs "") + if(TARGET Vulkan::Headers) + get_target_property(leonida_vk_include_dirs Vulkan::Headers INTERFACE_INCLUDE_DIRECTORIES) + endif() + leonida_vulkan_headers_check("${leonida_vk_include_dirs}" "${vulkanheaders_SOURCE_DIR}" + ${leonida_vulkan_headers_origin}) endif() # Also finds glslangValidator (Vulkan_GLSLANG_VALIDATOR_EXECUTABLE), which the shader-building tests below use. find_package(Vulkan QUIET) @@ -1416,7 +1427,6 @@ if(NOT TARGET Vulkan::Headers) endif() endif() if(TARGET Vulkan::Headers) - include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/vulkan_headers_report.cmake") get_target_property(leonida_vk_include_dirs Vulkan::Headers INTERFACE_INCLUDE_DIRECTORIES) leonida_vulkan_headers_report("${leonida_vk_include_dirs}" ${leonida_vulkan_headers_origin}) foreach(tool vk_harness vk_ps_sweep vk_texture_test vk_sampler_test vk_compute_test vk_store_test vk_pipeline_check vk_command_replay_test diff --git a/runtime/cmake/vulkan_headers_report.cmake b/runtime/cmake/vulkan_headers_report.cmake index 2129ca636f..0e8588f423 100644 --- a/runtime/cmake/vulkan_headers_report.cmake +++ b/runtime/cmake/vulkan_headers_report.cmake @@ -5,10 +5,10 @@ # Radeon 780M skipped ps_texoff, ps_texoff_forms and ps_texoff_implicit (225/248 passed instead of 228/248). # Kept in its own file so tests/test_cmake_vulkan_headers_pin.py can run it with `cmake -P`. -# include_dirs: the INTERFACE_INCLUDE_DIRECTORIES of Vulkan::Headers. Generator expressions such as -# $ (FetchContent's target) are unwrapped. origin: PIN (the hash-checked download of -# LEONIDA_VULKAN_HEADERS_PIN), SOURCE_DIR (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) or FOUND (anything else). -function(leonida_vulkan_headers_report include_dirs origin) +# Sets dir_var to the first of include_dirs (the INTERFACE_INCLUDE_DIRECTORIES of Vulkan::Headers) that holds +# vulkan/vulkan_core.h or vulkan/vulkan.h, or to "" when none does, and version_var to its VK_HEADER_VERSION, or to +# "unknown". Generator expressions such as $ (FetchContent's target) are unwrapped. +function(leonida_vulkan_headers_find include_dirs dir_var version_var) set(dir "") set(header "") foreach(d IN LISTS include_dirs) @@ -33,7 +33,16 @@ function(leonida_vulkan_headers_report include_dirs origin) if(line MATCHES "VK_HEADER_VERSION ([0-9]+)") set(version "${CMAKE_MATCH_1}") endif() - else() + endif() + set(${dir_var} "${dir}" PARENT_SCOPE) + set(${version_var} "${version}" PARENT_SCOPE) +endfunction() + +# include_dirs: the INTERFACE_INCLUDE_DIRECTORIES of Vulkan::Headers. origin: PIN (the hash-checked download of +# LEONIDA_VULKAN_HEADERS_PIN), SOURCE_DIR (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) or FOUND (anything else). +function(leonida_vulkan_headers_report include_dirs origin) + leonida_vulkan_headers_find("${include_dirs}" dir version) + if(NOT dir) set(dir "${include_dirs}") endif() if(origin STREQUAL "PIN") @@ -48,3 +57,42 @@ function(leonida_vulkan_headers_report include_dirs origin) string(CONCAT what ${what}) message(STATUS "Vulkan headers: ${dir} (VK_HEADER_VERSION ${version}), ${what}") endfunction() + +# Fails the configure unless Vulkan::Headers (include_dirs) is the Vulkan-Headers copy FetchContent populated in +# source_dir (empty when it populated none). FetchContent_MakeAvailable(VulkanHeaders) can return other headers +# without populating anything: a dependency provider can answer it, and so can find_package() when an earlier +# FetchContent_Declare(VulkanHeaders) asked for that or when FETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS applies (an +# installed VulkanHeadersConfig.cmake with VK_HEADER_VERSION 111 was named as the pin that way). origin PIN also needs +# the pinned version, LEONIDA_VULKAN_HEADERS_PIN_VERSION, which a build folder populated before the pin changed and +# configured with FETCHCONTENT_FULLY_DISCONNECTED=ON does not have. +function(leonida_vulkan_headers_check include_dirs source_dir origin) + leonida_vulkan_headers_find("${include_dirs}" dir version) + set(same FALSE) + if(dir AND source_dir) + file(REAL_PATH "${dir}" used) + file(REAL_PATH "${source_dir}/include" wanted) + if(used STREQUAL wanted) + set(same TRUE) + endif() + endif() + if(NOT same) + if(source_dir) + set(wanted "${source_dir}/include") + else() + set(wanted "a folder FetchContent populated (it populated none)") + endif() + message(FATAL_ERROR + "-DLEONIDA_VULKAN_HEADERS_FETCH=ON or FETCHCONTENT_SOURCE_DIR_VULKANHEADERS asks for the Vulkan headers in " + "${wanted}, but Vulkan::Headers includes \"${include_dirs}\". Something other than that download answered " + "FetchContent_MakeAvailable(VulkanHeaders): a dependency provider (CMAKE_PROJECT_TOP_LEVEL_INCLUDES) or an " + "earlier FetchContent_Declare(VulkanHeaders). Remove it, or configure without either of the two to build " + "against the installed headers.") + endif() + if(origin STREQUAL "PIN" AND NOT version STREQUAL "${LEONIDA_VULKAN_HEADERS_PIN_VERSION}") + message(FATAL_ERROR + "${dir} has VK_HEADER_VERSION ${version}, but the pinned Khronos Vulkan-Headers ${LEONIDA_VULKAN_HEADERS_PIN} " + "are version ${LEONIDA_VULKAN_HEADERS_PIN_VERSION}, so ${source_dir} is not the pin. A dependency provider may " + "have populated it, or the build folder was populated before the pin changed and FETCHCONTENT_FULLY_DISCONNECTED " + "is ON, which keeps the old copy: configure once with -DFETCHCONTENT_FULLY_DISCONNECTED=OFF to download the pin.") + endif() +endfunction() diff --git a/tests/test_cmake_vulkan_headers_pin.py b/tests/test_cmake_vulkan_headers_pin.py index 0cde32099b..d632248acb 100644 --- a/tests/test_cmake_vulkan_headers_pin.py +++ b/tests/test_cmake_vulkan_headers_pin.py @@ -7,9 +7,17 @@ ps_texoff_implicit (225/248 passed instead of 228/248 with the pin). The configure now also names its headers in a "Vulkan headers:" line (runtime/cmake/vulkan_headers_report.cmake) that a GPU record can quote. -The configure cases run CMake on runtime/ with hand-written stand-ins for an installed SDK (VULKAN_SDK) and for the -pinned release (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS), so nothing is downloaded and no real Vulkan headers are -needed. They need cmake and a C++ compiler and are skipped without them; the cmake -P cases need cmake only. +FetchContent_MakeAvailable(VulkanHeaders) can also hand back other headers without populating the pin: with +-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS it tried find_package(VulkanHeaders) first, and an installed +VulkanHeadersConfig.cmake with VK_HEADER_VERSION 111 was used and named as the pin. The declaration now carries +OVERRIDE_FIND_PACKAGE, and the configure fails when a dependency provider or another declaration still supplies +other headers, or when the populated copy is not the pinned version. + +The configure cases run CMake on runtime/ with hand-written stand-ins for an installed SDK (VULKAN_SDK), an installed +Vulkan-Headers package (VulkanHeaders_DIR) and the pinned release (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS, or a copy +already in FETCHCONTENT_BASE_DIR with FETCHCONTENT_FULLY_DISCONNECTED=ON), so nothing is downloaded and no real Vulkan +headers are needed. They need cmake and a C++ compiler and are skipped without them; the cmake -P cases need cmake +only. """ import os import re @@ -26,7 +34,11 @@ CMAKE = shutil.which("cmake") SDK_VERSION = 231 # conda-forge's vulkan-headers next to llvm-tools -PIN_VERSION = 363 # vulkan-sdk-1.4.363.0 +PACKAGE_VERSION = 111 # an installed Vulkan-Headers package found through VulkanHeaders_DIR +# The VK_HEADER_VERSION of the pin (363 for vulkan-sdk-1.4.363.0), which a stand-in for the pin must have. +_PIN_VERSION = re.search(r"^set\(LEONIDA_VULKAN_HEADERS_PIN_VERSION ([0-9]+)\)$", + CMAKE_LISTS.read_text(encoding="utf-8"), re.M) +PIN_VERSION = int(_PIN_VERSION.group(1)) if _PIN_VERSION else None # Runs at the end of the top-level directory (cmake_language DEFER) and writes the include directories of the # Vulkan::Headers target the tools link, which is what the compiler gets, independent of the "Vulkan headers:" line. @@ -51,6 +63,31 @@ target_include_directories(Vulkan-Headers INTERFACE "$") """ +# A stand-in for an installed Khronos Vulkan-Headers package: the same config file and target names. +FAKE_PACKAGE = """\ +if(NOT TARGET Vulkan::Headers) + add_library(Vulkan::Headers INTERFACE IMPORTED) + set_target_properties(Vulkan::Headers PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/include") +endif() +""" + +# A dependency provider (CMAKE_PROJECT_TOP_LEVEL_INCLUDES) that answers FetchContent_MakeAvailable(VulkanHeaders) with +# the installed package's headers, as a package manager's provider would. +PROVIDER = """\ +function(leonida_test_provider method name) + if(name STREQUAL "VulkanHeaders") + if(NOT TARGET Vulkan::Headers) + add_library(Vulkan::Headers INTERFACE IMPORTED GLOBAL) + set_target_properties(Vulkan::Headers PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@INCLUDE@") + endif() + FetchContent_SetPopulated(${name}) + endif() +endfunction() +cmake_language(SET_DEPENDENCY_PROVIDER leonida_test_provider SUPPORTED_METHODS FETCHCONTENT_MAKEAVAILABLE_SERIAL) +""" + +CHECK_FAILED = "Something other than that download answered" + def write(path, text): path.parent.mkdir(parents=True, exist_ok=True) @@ -85,15 +122,24 @@ def headers_line(output): return lines[-1] if lines else "" -def run_module(dirs, origin): +def run_module(call): with tempfile.TemporaryDirectory() as tmp: script = Path(tmp) / "driver.cmake" write(script, f'include("{MODULE.as_posix()}")\n' 'set(LEONIDA_VULKAN_HEADERS_PIN 0123456789abcdef0123456789abcdef01234567)\n' - f'leonida_vulkan_headers_report("{dirs}" {origin})\n') + f'set(LEONIDA_VULKAN_HEADERS_PIN_VERSION {PIN_VERSION})\n' + f'{call}\n') return subprocess.run([CMAKE, "-P", str(script)], capture_output=True, text=True, timeout=60) +def run_report(dirs, origin): + return run_module(f'leonida_vulkan_headers_report("{dirs}" {origin})') + + +def run_check(dirs, source_dir, origin): + return run_module(f'leonida_vulkan_headers_check("{dirs}" "{source_dir}" {origin})') + + @unittest.skipUnless(CMAKE, "cmake not on PATH") class ReportLineTest(unittest.TestCase): def setUp(self): @@ -103,7 +149,7 @@ def setUp(self): def test_found_headers_are_named_and_not_called_the_pin(self): write_headers(self.include, SDK_VERSION) - r = run_module(self.include.as_posix(), "FOUND") + r = run_report(self.include.as_posix(), "FOUND") self.assertEqual(r.returncode, 0, r.stderr) line = headers_line(r.stdout) self.assertIn(f"Vulkan headers: {self.include.as_posix()} (VK_HEADER_VERSION {SDK_VERSION})", line) @@ -112,7 +158,7 @@ def test_found_headers_are_named_and_not_called_the_pin(self): def test_pin_names_the_commit(self): write_headers(self.include, PIN_VERSION) - r = run_module(f"$", "PIN") + r = run_report(f"$", "PIN") self.assertEqual(r.returncode, 0, r.stderr) line = headers_line(r.stdout) self.assertIn(f"Vulkan headers: {self.include.as_posix()} (VK_HEADER_VERSION {PIN_VERSION})", line) @@ -120,7 +166,7 @@ def test_pin_names_the_commit(self): def test_source_dir_copy_is_not_vouched_for(self): write_headers(self.include, PIN_VERSION) - r = run_module(self.include.as_posix(), "SOURCE_DIR") + r = run_report(self.include.as_posix(), "SOURCE_DIR") self.assertEqual(r.returncode, 0, r.stderr) line = headers_line(r.stdout) self.assertIn("FETCHCONTENT_SOURCE_DIR_VULKANHEADERS", line) @@ -128,11 +174,52 @@ def test_source_dir_copy_is_not_vouched_for(self): def test_header_without_a_version_says_unknown(self): write_headers(self.include, None) - r = run_module(self.include.as_posix(), "FOUND") + r = run_report(self.include.as_posix(), "FOUND") self.assertEqual(r.returncode, 0, r.stderr) self.assertIn("(VK_HEADER_VERSION unknown)", headers_line(r.stdout)) +@unittest.skipUnless(CMAKE, "cmake not on PATH") +class CheckTest(unittest.TestCase): + """leonida_vulkan_headers_check: Vulkan::Headers must be the copy FetchContent populated, and the pin's version.""" + + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + base = Path(tmp.name) + self.source = base / "vulkan-headers" + self.package = base / "package" + write_headers(self.package / "include", PACKAGE_VERSION) + + def test_the_populated_copy_passes(self): + write_headers(self.source / "include", PIN_VERSION) + r = run_check(f"$", self.source.as_posix(), "PIN") + self.assertEqual(r.returncode, 0, r.stderr) + + def test_other_headers_fail(self): + write_headers(self.source / "include", PIN_VERSION) + r = run_check((self.package / "include").as_posix(), self.source.as_posix(), "PIN") + self.assertNotEqual(r.returncode, 0) + self.assertIn(CHECK_FAILED, " ".join(r.stderr.split())) + + def test_nothing_populated_fails(self): + # find_package() or a provider answered FetchContent_MakeAvailable: vulkanheaders_SOURCE_DIR is empty. + r = run_check((self.package / "include").as_posix(), "", "PIN") + self.assertNotEqual(r.returncode, 0) + self.assertIn("it populated none", " ".join(r.stderr.split())) + + def test_another_version_is_not_the_pin(self): + write_headers(self.source / "include", PIN_VERSION - 1) + r = run_check((self.source / "include").as_posix(), self.source.as_posix(), "PIN") + self.assertNotEqual(r.returncode, 0) + self.assertIn(f"has VK_HEADER_VERSION {PIN_VERSION - 1}", " ".join(r.stderr.split())) + + def test_a_source_dir_copy_may_be_another_version(self): + write_headers(self.source / "include", PIN_VERSION - 1) + r = run_check((self.source / "include").as_posix(), self.source.as_posix(), "SOURCE_DIR") + self.assertEqual(r.returncode, 0, r.stderr) + + @unittest.skipUnless(CMAKE, "cmake not on PATH") class ConfigureTest(unittest.TestCase): """Configures runtime/ with a fake installed SDK on VULKAN_SDK and a fake copy of the pinned release.""" @@ -147,19 +234,27 @@ def setUp(self): self.pin_include = self.pin_source / "include" write_headers(self.pin_include, PIN_VERSION) write(self.pin_source / "CMakeLists.txt", FAKE_PROJECT) + self.package = base / "package" + self.package_include = self.package / "include" + write_headers(self.package_include, PACKAGE_VERSION) + write(self.package / "VulkanHeadersConfig.cmake", FAKE_PACKAGE) self.hook = base / "hook.cmake" write(self.hook, HOOK) self.base = base self.env = dict(os.environ, VULKAN_SDK=str(base / "sdk")) - def configure(self, build, *args): + def run_configure(self, build, *args): cmd = [CMAKE, "-S", str(RUNTIME), "-B", str(build), f"-DCMAKE_PROJECT_gta6rt_INCLUDE={self.hook.as_posix()}", "-DBUILD_TESTING=OFF", "-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF", *args] r = subprocess.run(cmd, capture_output=True, text=True, timeout=600, env=self.env) out = r.stdout + r.stderr if r.returncode and "CMAKE_CXX_COMPILER" in out and not (build / "leonida_test_vulkan_headers.txt").exists(): self.skipTest("no working C++ compiler for CMake") - self.assertEqual(r.returncode, 0, out[-4000:]) + return r.returncode, out + + def configure(self, build, *args): + returncode, out = self.run_configure(build, *args) + self.assertEqual(returncode, 0, out[-4000:]) dirs = included((build / "leonida_test_vulkan_headers.txt").read_text(encoding="utf-8")) return dirs, headers_line(out) @@ -177,6 +272,42 @@ def test_fetch_wins_over_installed_headers(self): f"-DFETCHCONTENT_SOURCE_DIR_VULKANHEADERS={self.pin_source.as_posix()}") self.assert_pin(dirs, line) + def seeded_base_dir(self, version): + """A FETCHCONTENT_BASE_DIR that already holds a downloaded copy, for FETCHCONTENT_FULLY_DISCONNECTED=ON.""" + deps = self.base / "deps" + write_headers(deps / "vulkanheaders-src" / "include", version) + write(deps / "vulkanheaders-src" / "CMakeLists.txt", FAKE_PROJECT) + return deps + + def test_always_mode_does_not_swap_in_an_installed_package(self): + # FETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS used to make FetchContent_MakeAvailable take the installed + # VulkanHeadersConfig.cmake and populate nothing, and the line still said "the pin". + deps = self.seeded_base_dir(PIN_VERSION) + dirs, line = self.configure(self.base / "build", "-DLEONIDA_VULKAN_HEADERS_FETCH=ON", + "-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS", + f"-DVulkanHeaders_DIR={self.package.as_posix()}", + f"-DFETCHCONTENT_BASE_DIR={deps.as_posix()}", "-DFETCHCONTENT_FULLY_DISCONNECTED=ON") + self.assert_uses(dirs, deps / "vulkanheaders-src" / "include") + self.assertFalse(any(same_dir(d, self.package_include) for d in dirs), dirs) + self.assertIn(f"(VK_HEADER_VERSION {PIN_VERSION}), the pin: Khronos Vulkan-Headers ", line) + + def test_a_dependency_provider_cannot_stand_in_for_the_pin(self): + provider = self.base / "provider.cmake" + write(provider, PROVIDER.replace("@INCLUDE@", self.package_include.as_posix())) + returncode, out = self.run_configure(self.base / "build", "-DLEONIDA_VULKAN_HEADERS_FETCH=ON", + f"-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={provider.as_posix()}") + self.assertNotEqual(returncode, 0, headers_line(out)) + self.assertIn(CHECK_FAILED, " ".join(out.split())) + + def test_a_stale_download_is_not_called_the_pin(self): + # A build folder populated before the pin changed keeps that copy while FETCHCONTENT_FULLY_DISCONNECTED is ON. + deps = self.seeded_base_dir(PIN_VERSION - 1) + returncode, out = self.run_configure(self.base / "build", "-DLEONIDA_VULKAN_HEADERS_FETCH=ON", + f"-DFETCHCONTENT_BASE_DIR={deps.as_posix()}", + "-DFETCHCONTENT_FULLY_DISCONNECTED=ON") + self.assertNotEqual(returncode, 0, headers_line(out)) + self.assertIn(f"has VK_HEADER_VERSION {PIN_VERSION - 1}", " ".join(out.split())) + def test_turning_fetch_on_in_a_build_that_found_headers(self): build = self.base / "build" # The installed SDK is visible: without the fetch it is used (and Vulkan_INCLUDE_DIR is cached). @@ -204,20 +335,39 @@ def test_fetch_comes_before_find_package(self): self.assertIsNotNone(fetch, "the top-level fetch branch is missing from runtime/CMakeLists.txt") self.assertLess(fetch.start(), self.text.index("\nfind_package(Vulkan QUIET)\n")) + def fetch_branch(self): + m = re.search(r"^if\(LEONIDA_VULKAN_HEADERS_FETCH OR FETCHCONTENT_SOURCE_DIR_VULKANHEADERS\)\n(.*?)^endif\(\)$", + self.text, re.S | re.M) + self.assertIsNotNone(m, "the top-level fetch branch is missing from runtime/CMakeLists.txt") + return m + def test_headers_line_is_printed_with_the_tools(self): m = re.search(r"^if\(TARGET Vulkan::Headers\)\n(.*?)^ foreach\(tool ", self.text, re.S | re.M) self.assertIsNotNone(m, "if(TARGET Vulkan::Headers) ... foreach(tool ...) not found") - self.assertIn("vulkan_headers_report.cmake", m.group(1)) self.assertIn("leonida_vulkan_headers_report(", m.group(1)) + self.assertLess(self.text.index("/cmake/vulkan_headers_report.cmake\")"), self.fetch_branch().start()) + + def test_the_fetch_is_checked(self): + branch = self.fetch_branch().group(1) + declare = re.search(r"^ FetchContent_Declare\(VulkanHeaders\n(.*?)^ FetchContent_MakeAvailable\(VulkanHeaders\)$", + branch, re.S | re.M) + self.assertIsNotNone(declare, "FetchContent_Declare(VulkanHeaders ...) not found in the fetch branch") + code = "\n".join(ln for ln in declare.group(1).splitlines() if not ln.lstrip().startswith("#")) + self.assertIn("OVERRIDE_FIND_PACKAGE", code) + self.assertLess(branch.index("FetchContent_MakeAvailable(VulkanHeaders)"), + branch.index("leonida_vulkan_headers_check(")) def test_pin_matches_the_ci_checkout(self): m = re.search(r"^set\(LEONIDA_VULKAN_HEADERS_PIN ([0-9a-f]{40})\)$", self.text, re.M) self.assertIsNotNone(m, "set(LEONIDA_VULKAN_HEADERS_PIN ) not found") self.assertIn("Vulkan-Headers/archive/${LEONIDA_VULKAN_HEADERS_PIN}.tar.gz", self.text) ci = (ROOT / ".github" / "workflows" / "runtime.yml").read_text(encoding="utf-8") - refs = re.findall(r"^\s*ref: ([0-9a-f]{40}) # vulkan-sdk-", ci, re.M) + refs = re.findall(r"^\s*ref: ([0-9a-f]{40}) # vulkan-sdk-[0-9]+\.[0-9]+\.([0-9]+)\.[0-9]+$", ci, re.M) self.assertTrue(refs, "no Vulkan-Headers checkout in runtime.yml") - self.assertEqual(set(refs), {m.group(1)}) + self.assertEqual({commit for commit, _ in refs}, {m.group(1)}) + # The SDK version's third number is the VK_HEADER_VERSION the configure checks the download against. + self.assertIsNotNone(PIN_VERSION, "set(LEONIDA_VULKAN_HEADERS_PIN_VERSION ) not found") + self.assertEqual({int(version) for _, version in refs}, {PIN_VERSION}) if __name__ == "__main__": From b7c9afd76ac7a2119568824d0e48262282155376 Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:15:23 -0600 Subject: [PATCH 3/3] runtime: a disconnected configure no longer calls the cached Vulkan-Headers "hash-checked" (CMAKE-VULKAN-HEADERS-PIN) With FETCHCONTENT_FULLY_DISCONNECTED=ON, FetchContent reuses the copy already in FETCHCONTENT_BASE_DIR and checks no archive, but the "Vulkan headers:" line still said "hash-checked". The path and version checks confirm what was selected, not that this configure checked an archive. - A new origin, PIN_CACHED, is used when FETCHCONTENT_FULLY_DISCONNECTED is on and no FETCHCONTENT_SOURCE_DIR_VULKANHEADERS is given. The line reads "the pinned version, cached source: Khronos Vulkan-Headers ; archive not checked in this configure (FETCHCONTENT_FULLY_DISCONNECTED=ON)". leonida_vulkan_headers_check still requires LEONIDA_VULKAN_HEADERS_PIN_VERSION for it. - Each branch of the report builds its text with string(CONCAT) on quoted pieces, so the ";" survives. - tests/test_cmake_vulkan_headers_pin.py: the disconnected-mode configure test asserts the wording and that "hash-checked" is gone, a cmake -P case checks the wording, and the version check runs for both pin origins (19 tests). Reported by titoreinaldo on #491. Co-Authored-By: Claude Opus 5.5 --- runtime/CMakeLists.txt | 3 +++ runtime/cmake/vulkan_headers_report.cmake | 26 ++++++++++++++--------- tests/test_cmake_vulkan_headers_pin.py | 24 +++++++++++++++++---- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index c16e3b8b8d..652c0c25fb 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1400,6 +1400,9 @@ if(LEONIDA_VULKAN_HEADERS_FETCH OR FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) FetchContent_GetProperties(VulkanHeaders) if(FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) set(leonida_vulkan_headers_origin SOURCE_DIR) + elseif(FETCHCONTENT_FULLY_DISCONNECTED) + # FetchContent reuses what is already in FETCHCONTENT_BASE_DIR and checks no archive. + set(leonida_vulkan_headers_origin PIN_CACHED) else() set(leonida_vulkan_headers_origin PIN) endif() diff --git a/runtime/cmake/vulkan_headers_report.cmake b/runtime/cmake/vulkan_headers_report.cmake index 0e8588f423..aa30ea637f 100644 --- a/runtime/cmake/vulkan_headers_report.cmake +++ b/runtime/cmake/vulkan_headers_report.cmake @@ -39,22 +39,27 @@ function(leonida_vulkan_headers_find include_dirs dir_var version_var) endfunction() # include_dirs: the INTERFACE_INCLUDE_DIRECTORIES of Vulkan::Headers. origin: PIN (the hash-checked download of -# LEONIDA_VULKAN_HEADERS_PIN), SOURCE_DIR (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) or FOUND (anything else). +# LEONIDA_VULKAN_HEADERS_PIN), PIN_CACHED (a copy already in FETCHCONTENT_BASE_DIR, which +# FETCHCONTENT_FULLY_DISCONNECTED=ON uses without downloading or checking an archive; leonida_vulkan_headers_check +# has confirmed only its version), SOURCE_DIR (FETCHCONTENT_SOURCE_DIR_VULKANHEADERS) or FOUND (anything else). function(leonida_vulkan_headers_report include_dirs origin) leonida_vulkan_headers_find("${include_dirs}" dir version) if(NOT dir) set(dir "${include_dirs}") endif() + # string(CONCAT) on quoted pieces keeps a ";" in the text, which a list would split on. if(origin STREQUAL "PIN") set(what "the pin: Khronos Vulkan-Headers ${LEONIDA_VULKAN_HEADERS_PIN}, hash-checked") + elseif(origin STREQUAL "PIN_CACHED") + string(CONCAT what "the pinned version, cached source: Khronos Vulkan-Headers ${LEONIDA_VULKAN_HEADERS_PIN}; " + "archive not checked in this configure (FETCHCONTENT_FULLY_DISCONNECTED=ON)") elseif(origin STREQUAL "SOURCE_DIR") - set(what "from FETCHCONTENT_SOURCE_DIR_VULKANHEADERS: a local copy used in place of the pin, not checked " - "against it") + string(CONCAT what "from FETCHCONTENT_SOURCE_DIR_VULKANHEADERS: a local copy used in place of the pin, not " + "checked against it") else() - set(what "found on this machine, not the pin (-DLEONIDA_VULKAN_HEADERS_FETCH=ON builds against the pinned " - "Khronos Vulkan-Headers)") + string(CONCAT what "found on this machine, not the pin (-DLEONIDA_VULKAN_HEADERS_FETCH=ON builds against the " + "pinned Khronos Vulkan-Headers)") endif() - string(CONCAT what ${what}) message(STATUS "Vulkan headers: ${dir} (VK_HEADER_VERSION ${version}), ${what}") endfunction() @@ -62,9 +67,9 @@ endfunction() # source_dir (empty when it populated none). FetchContent_MakeAvailable(VulkanHeaders) can return other headers # without populating anything: a dependency provider can answer it, and so can find_package() when an earlier # FetchContent_Declare(VulkanHeaders) asked for that or when FETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS applies (an -# installed VulkanHeadersConfig.cmake with VK_HEADER_VERSION 111 was named as the pin that way). origin PIN also needs -# the pinned version, LEONIDA_VULKAN_HEADERS_PIN_VERSION, which a build folder populated before the pin changed and -# configured with FETCHCONTENT_FULLY_DISCONNECTED=ON does not have. +# installed VulkanHeadersConfig.cmake with VK_HEADER_VERSION 111 was named as the pin that way). origin PIN or +# PIN_CACHED also needs the pinned version, LEONIDA_VULKAN_HEADERS_PIN_VERSION, which a build folder populated before +# the pin changed and configured with FETCHCONTENT_FULLY_DISCONNECTED=ON does not have. function(leonida_vulkan_headers_check include_dirs source_dir origin) leonida_vulkan_headers_find("${include_dirs}" dir version) set(same FALSE) @@ -88,7 +93,8 @@ function(leonida_vulkan_headers_check include_dirs source_dir origin) "earlier FetchContent_Declare(VulkanHeaders). Remove it, or configure without either of the two to build " "against the installed headers.") endif() - if(origin STREQUAL "PIN" AND NOT version STREQUAL "${LEONIDA_VULKAN_HEADERS_PIN_VERSION}") + if((origin STREQUAL "PIN" OR origin STREQUAL "PIN_CACHED") AND + NOT version STREQUAL "${LEONIDA_VULKAN_HEADERS_PIN_VERSION}") message(FATAL_ERROR "${dir} has VK_HEADER_VERSION ${version}, but the pinned Khronos Vulkan-Headers ${LEONIDA_VULKAN_HEADERS_PIN} " "are version ${LEONIDA_VULKAN_HEADERS_PIN_VERSION}, so ${source_dir} is not the pin. A dependency provider may " diff --git a/tests/test_cmake_vulkan_headers_pin.py b/tests/test_cmake_vulkan_headers_pin.py index d632248acb..afa183ee65 100644 --- a/tests/test_cmake_vulkan_headers_pin.py +++ b/tests/test_cmake_vulkan_headers_pin.py @@ -164,6 +164,16 @@ def test_pin_names_the_commit(self): self.assertIn(f"Vulkan headers: {self.include.as_posix()} (VK_HEADER_VERSION {PIN_VERSION})", line) self.assertIn("the pin: Khronos Vulkan-Headers 0123456789abcdef0123456789abcdef01234567", line) + def test_a_cached_pin_does_not_claim_a_hash_check(self): + # FETCHCONTENT_FULLY_DISCONNECTED=ON: the copy in FETCHCONTENT_BASE_DIR is used and no archive is checked. + write_headers(self.include, PIN_VERSION) + r = run_report(f"$", "PIN_CACHED") + self.assertEqual(r.returncode, 0, r.stderr) + line = headers_line(r.stdout) + self.assertIn(f"(VK_HEADER_VERSION {PIN_VERSION}), the pinned version, cached source: Khronos Vulkan-Headers " + "0123456789abcdef0123456789abcdef01234567; archive not checked in this configure", line) + self.assertNotIn("hash-checked", line) + def test_source_dir_copy_is_not_vouched_for(self): write_headers(self.include, PIN_VERSION) r = run_report(self.include.as_posix(), "SOURCE_DIR") @@ -210,9 +220,11 @@ def test_nothing_populated_fails(self): def test_another_version_is_not_the_pin(self): write_headers(self.source / "include", PIN_VERSION - 1) - r = run_check((self.source / "include").as_posix(), self.source.as_posix(), "PIN") - self.assertNotEqual(r.returncode, 0) - self.assertIn(f"has VK_HEADER_VERSION {PIN_VERSION - 1}", " ".join(r.stderr.split())) + for origin in ("PIN", "PIN_CACHED"): + with self.subTest(origin=origin): + r = run_check((self.source / "include").as_posix(), self.source.as_posix(), origin) + self.assertNotEqual(r.returncode, 0) + self.assertIn(f"has VK_HEADER_VERSION {PIN_VERSION - 1}", " ".join(r.stderr.split())) def test_a_source_dir_copy_may_be_another_version(self): write_headers(self.source / "include", PIN_VERSION - 1) @@ -289,7 +301,11 @@ def test_always_mode_does_not_swap_in_an_installed_package(self): f"-DFETCHCONTENT_BASE_DIR={deps.as_posix()}", "-DFETCHCONTENT_FULLY_DISCONNECTED=ON") self.assert_uses(dirs, deps / "vulkanheaders-src" / "include") self.assertFalse(any(same_dir(d, self.package_include) for d in dirs), dirs) - self.assertIn(f"(VK_HEADER_VERSION {PIN_VERSION}), the pin: Khronos Vulkan-Headers ", line) + # The preseeded copy is the pinned version, but no archive was checked in this configure. + self.assertIn(f"(VK_HEADER_VERSION {PIN_VERSION}), the pinned version, cached source: Khronos Vulkan-Headers ", + line) + self.assertIn("archive not checked in this configure (FETCHCONTENT_FULLY_DISCONNECTED=ON)", line) + self.assertNotIn("hash-checked", line) def test_a_dependency_provider_cannot_stand_in_for_the_pin(self): provider = self.base / "provider.cmake"