From 76109561f4e392fd0da97a2d4b936b35c83e821a Mon Sep 17 00:00:00 2001 From: Jan Trencansky Date: Thu, 26 Nov 2026 12:36:34 -0500 Subject: [PATCH] d3d12: --precompile-pipelines builds the skip-listed programs unless --skip-listed LEONIDA_SKIP_COMPUTE is a play-time setting: the game drops the listed programs' dispatches. The precompile also refused to build them, one "not built (LEONIDA_SKIP_COMPUTE)" line each and no override. Players run it with the game's environment (docs/running.md), so their skip list kept those programs out of the journal for good, and a later run without the list compiled them in the game. - precompile_compute_pipelines builds every compute entry; with the list set it says how many entries it names. --skip-listed leaves them out on purpose, one line each. - The last line counts the whole run: built (compiled, from a cache), journaled already, being built by another process, failed; left out: of those the list names, not buildable, filtered out (--filter, the size bounds and now --limit too). - BuildHost::unbuildable no longer checks the list. The compile server checks it itself, as before: the game that starts it drops those dispatches. Docs: running.md, linux_proton.md and d3d12_vulkan.md no longer give compile time as the reason for the skip list. The 89-167 s per program came from wave64-emulated packs; with a native wave64 pack on an RX 7900 XTX (RADV, Mesa 26.3.1, Wine) all 721 library programs of 2 MiB or more built, 360 of them in 170 s on 32 threads, 2.5-32 s each, the largest (13 MiB) in 28.5 s alone, at a peak of 14 GiB of RAM. Two world runs on that card with all of them journaled and no skip list took them all from the journal and got no further than runs with the list (a stop with the GPU idle at 404 s; an idle-queue device loss at about 214 s, which also happens with the list set). Their output is not checked, so the docs keep the skip list and LEONIDA_RT_AS=off as the setting of our longest runs. Test: precompile_skip_list (test/check_precompile_skip_list.cmake) precompiles two synthetic compute modules, one of them listed, three times: with the list set both are built; with --skip-listed only the other one is, and the listed one is named; a second run into the first journal finds both journaled. It fails on main. Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_vulkan.md | 21 ++- docs/linux_proton.md | 17 ++- docs/running.md | 28 +++- runtime/CMakeLists.txt | 12 ++ runtime/shims/d3d12_precompile.h | 6 + runtime/shims/d3d12_vulkan_device.cpp | 53 ++++++-- runtime/src/main.cpp | 9 +- runtime/test/check_precompile_skip_list.cmake | 123 ++++++++++++++++++ 8 files changed, 238 insertions(+), 31 deletions(-) create mode 100644 runtime/test/check_precompile_skip_list.cmake diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 7abd1e0649..e5efa6ed0c 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2641,8 +2641,9 @@ Pipeline creation: `pipelineCreationCacheControl` feature unless `LEONIDA_PIPELINE_COMPILE=cache-only` asks for it. A cache-only create (`cache-only`) is left as it is. `LEONIDA_SKIP_COMPUTE=[,...]` (`all`: every compute program) never builds the matching - compute programs and drops their dispatches, direct and indirect; the first dropped dispatch of each is logged. - It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix. + compute programs at play and drops their dispatches, direct and indirect; the first dropped dispatch of each is + logged. It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix. + `--precompile-pipelines` (below) builds them anyway unless it is given `--skip-listed`. `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` also schedules a snapshot after a successful pipeline build, at most once per 120 seconds. It starts on the compile worker when queued builds have drained and the device has no active builds. The driver fills a mapped staging @@ -2681,7 +2682,8 @@ Pipeline creation: folders can share one; the file names and the driver's checks keep a pipeline from one build from being taken for another's. `gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--all] [--smallest-first] [--limit N] - [--min-bytes N] [--max-bytes N] [--filter PART]... [--list]` fills the journal ahead of play, with no game: it + [--min-bytes N] [--max-bytes N] [--filter PART]... [--skip-listed] [--list]` fills the journal ahead of play, with + no game: it creates the Vulkan device as `--run` does (so the same environment gives the same journal names and driver keys: LEONIDA_SHADERS, LEONIDA_PIPELINE_CACHE_DIR, and LEONIDA_DEVICE_FAULT/LEONIDA_AFTERMATH, whose diagnostics config makes other pipelines) and builds every compute entry of the library through the dispatch path @@ -2691,6 +2693,19 @@ Pipeline creation: 4 threads: modules of 3.6-5.8 MB took 46-145 s each, 12 in 312 s, about 3.5 GB of host memory each while in the driver (14.5 GB peak for four). Graphics pipelines are not covered: they are built at a title's draw from its PSO description and the bound formats, and take milliseconds. + `LEONIDA_SKIP_COMPUTE` does not narrow the build: it is a play-time setting, players run the pre-compile with the + game's environment, and a program left out here would stay out of the journal after the list is shortened. The run + says how many entries the list names and builds them; `--skip-listed` leaves them out on purpose. The last line + counts what was built (compiled, or found in a cache), what was journaled already or being built by another + process, what failed, and what was left out and why: by `--skip-listed`, not buildable on this device (no SPIR-V, + set-0 bindings without a bindless set, workgroup memory over the limit), or filtered out (`--filter`, the size + bounds, `--limit`). The 89-167 s per program behind the skip list of the large `library/` programs came from + wave64-emulated packs. Measured with a native wave64 pack on an RX 7900 XTX (RADV, Mesa 26.3.1, Wine): all 721 + programs of 2 MiB or more built, 360 of them in 170 s on 32 threads, 2.5-32 s each, the largest (13 MiB) in 28.5 s + alone, at a peak of 14 GiB of RAM for the process. With all of them in the journal and no skip list, two world runs + took them all from the journal (none built in the game) and ended as runs with the skip list do, in an idle-queue + device loss or a stop with the GPU idle ([running.md](running.md#settings-every-platform-needs)); whether their + output is correct is not measured. `LEONIDA_COMPILE_HELPER=1` (`shims/d3d12_compile_helper.h`) keeps first-ever compiles out of the title's process: the driver's locks, which a long `vkCreateComputePipelines` holds and a `vkQueueSubmit` of the same process waits for, are per process. A compute build of `LEONIDA_COMPILE_HELPER_MIN_BYTES` or more (128 KiB) with no journal file diff --git a/docs/linux_proton.md b/docs/linux_proton.md index b981c2ef2f..42487ed496 100644 --- a/docs/linux_proton.md +++ b/docs/linux_proton.md @@ -198,6 +198,8 @@ they were found. with the environment of the game run (`LEONIDA_SHADERS`, `LEONIDA_PIPELINE_CACHE_DIR`, `LEONIDA_DEVICE_FAULT`; `--precompile-pipelines` in [d3d12_vulkan.md](d3d12_vulkan.md)). It built 3,693 compute pipelines; the next boot took 1,900 of them from the journal in 0.1 s of driver time, and the menus ran at 30 frames/s instead of under one. + That run left out the programs `LEONIDA_SKIP_COMPUTE` named, which kept them out of the journal; the pre-compile + now builds them too unless it is given `--skip-listed`. The `pipeline_cache.bin` that `make_game.py`'s pipelines stage writes with `vk_pipeline_check` gave no hits: 0 of 5,526 journal pipeline keys were in its 29,861 objects (9 shader binaries were identical, so the machine code matched and the keys did not). Each of three differences is enough for a miss on RADV: @@ -212,10 +214,17 @@ they were found. hashes the whole set layout and the stage flags. Graphics would miss anyway: the checker pairs each stage with a stub and fixed state, and RADV hashes the full graphics state. 4. **Leave out the ray-tracing programs.** 724 library compute programs have 2 MiB of SPIR-V or more (676 of them - ray-tracing resolve) and take 89-167 s each in the driver. `LEONIDA_RT_AS=off` drops acceleration-structure builds - and copies, and `LEONIDA_SKIP_COMPUTE=,,...` with those programs' `lib_cs_NNNNN` names (picked by - module size from `library/index.json`) never builds or dispatches them. The picture then lacks whatever those - passes draw. + ray-tracing resolve). The 89-167 s each in the driver were measured with wave64-emulated packs; with the native + pack of step 2 they build in seconds, so compile time is not the reason any more. Measured afterwards on the same + machine (RX 7900 XTX, RADV, Mesa 26.3.1, Wine): all 721 such programs of that pack built, 360 of them in 170 s on 32 + threads, 2.5-32 s each, the largest (13 MiB) in 28.5 s alone, at a peak of 14 GiB of RAM. Two world runs with all + of them in the journal and no skip list (one run per build) took them all from the journal and got no further + than runs with the skip list: one stopped submitting after 404 s with the GPU idle, the other lost the device + about 214 s in with every queue idle, a loss that also happens with the skip list set + ([running.md](running.md#settings-every-platform-needs)). Whether their output is correct is not measured, so the + longest runs still leave them out. `LEONIDA_RT_AS=off` drops acceleration-structure builds and copies, and + `LEONIDA_SKIP_COMPUTE=,,...` with those programs' `lib_cs_NNNNN` names (picked by module size from + `library/index.json`) drops their dispatches at play. The picture then lacks whatever those passes draw. 5. **Keep the title's hang watchdog kicked.** The title exits on purpose (a write to address 0) when its main loop has not reported for 30 s, which a world load under the runtime exceeds. `LEONIDA_TITLE_WATCHDOG=0` defuses it only together with `LEONIDA_TITLE_WATCHDOG_KICK=,` (hex; `runtime/src/main.cpp`); the two values are diff --git a/docs/running.md b/docs/running.md index 3b7e61f64c..77887d23d3 100644 --- a/docs/running.md +++ b/docs/running.md @@ -22,10 +22,21 @@ Paths are placeholders: `` is the repository, `` the folder wit - **The GPU timeout.** World frames take seconds each. The OS's GPU timeout must be longer, or the driver resets the GPU: amdgpu's `lockup_timeout` on Linux, `TdrDelay` on Windows (sections below). - **Large ray-tracing programs.** 724 library compute programs have 2 MiB of SPIR-V or more (676 of them ray-tracing - resolve) and take 89-167 s each in the driver ([reported by others](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7184700506); - the count of 724 also measured by us). `LEONIDA_RT_AS=off` drops acceleration-structure builds and - `LEONIDA_SKIP_COMPUTE=,,...` with those programs' names (picked by module size from - `/shaders/spirv/library/index.json`) never builds or dispatches them. The picture then lacks what they draw. + resolve). With wave64 emulation they took 89-167 s each in the driver ([reported by others](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7184700506); + the count of 724 also measured by us). With a native wave64 pack compile time is no reason to leave them out: on an + RX 7900 XTX (RADV, Mesa 26.3.1, Wine) all 721 such programs of that pack built, 360 of them in 170 s on 32 threads, + 2.5-32 s each, the largest (13 MiB) in 28.5 s alone, at a peak of 14 GiB of RAM (measured by us). The pipeline + pre-compile builds them with the rest. Dispatched at play (measured by us, one run per condition: RX 7900 XTX 24 GB, + `LEONIDA_RT_AS=off`, no skip list, all 721 in the journal), they all came from the journal (2,700 compute + pipelines from it against 1,900 with the skip list set; none built in the game) and the load reached the world. + One run (a local build of `main` with four then-open pull requests) stopped submitting after 404 s with the GPU idle + and no GPU fault; the other (`main` `bd6ba97ab`) lost the device about 214 s in, after a read page fault, with + every queue idle in the dispatch markers. The same idle-queue device loss also happens with the skip list set, so + it is not shown to come from these programs, and running them got no further than the skip list's best runs + (about 11 minutes, ending on a title breakpoint). Whether their output is correct is not measured. Our longest + runs used `LEONIDA_SKIP_COMPUTE=,,...` with those programs' names (picked by module size from + `/shaders/spirv/library/index.json`), which drops their dispatches at play, and `LEONIDA_RT_AS=off`, which + drops acceleration-structure builds. The picture then lacks what they draw. ## Linux, Wine, AMD RX 7900 XTX (RADV) @@ -39,6 +50,8 @@ reasons behind each step: [linux_proton.md](linux_proton.md#amd-on-linux-what-go - **Pipeline pre-compile:** `wine /gta6rt.exe --precompile-pipelines --threads 16` with the run's `LEONIDA_SHADERS`, `LEONIDA_PIPELINE_CACHE_DIR` and `LEONIDA_DEVICE_FAULT`, before the first run. It built 3,693 compute pipelines. Not `make_game.py --stages pipelines`: its cache never matches the runtime's driver keys. + The pre-compile builds the programs `LEONIDA_SKIP_COMPUTE` names too (`--skip-listed` leaves them out) and ends + with one line that counts what it built, what was journaled already and what it left out. - **Driver and OS:** `amdgpu.lockup_timeout=30000,60000,10000,10000` on the kernel command line (the default is 2000 ms; reboot needed). - **Environment:** @@ -52,7 +65,7 @@ reasons behind each step: [linux_proton.md](linux_proton.md#amd-on-linux-what-go | `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` | session cache snapshots during the boot | | `LEONIDA_ASYNC_PIPELINES=0` | draws wait for their pipeline instead of being skipped | | `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_COMPUTE_WARMUP_MAX_BYTES=8388608` | warm-up limits, as in the NVIDIA report below | - | `LEONIDA_RT_AS=off`, `LEONIDA_SKIP_COMPUTE=` | the large ray-tracing programs ([above](#settings-every-platform-needs)) | + | `LEONIDA_RT_AS=off`, `LEONIDA_SKIP_COMPUTE=` | the large ray-tracing programs, left out at play as in our longest runs ([above](#settings-every-platform-needs)) | | `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_TITLE_WATCHDOG_KICK=,` | the title's hang watchdog ([above](#settings-every-platform-needs)) | | `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_FRAME_PACING=1`, `LEONIDA_PRESENT_NO_TEAR=1` | taken over from the NVIDIA report below; their effect on AMD was not measured one by one | | `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_GEOMETRY_MB=6144` | room for the title's buffers in the world | @@ -96,7 +109,10 @@ Reported by others: [#1608, comment 7184700506](https://github.com/ubiquitariani `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_HOST_IMAGE_COPY=0`, `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_FRAME_PACING=1`, `LEONIDA_PRESENT_NO_TEAR=1`. The report gives the reason for the skip list only: without it the world start waits - hours on the ray-tracing programs; with asynchronous pipelines instead the screen stayed black. + hours on the ray-tracing programs; with asynchronous pipelines instead the screen stayed black. Those compile times + are the report's pack; a native wave64 pack builds them in seconds each ([above](#settings-every-platform-needs)). + Where they still take minutes, `gta6rt --precompile-pipelines --big-threads N` bounds how many build at once (each + held about 3.5 GB of host memory on an RTX 4070 Ti) and `--skip-listed` leaves the listed ones out. - **Command:** TBD. - **What to expect:** the opening night street from about 650 s, at 0.1-0.2 frames/s, no device loss through 934 s. The black stretch before it is graphics pipelines of 1-2.6 MB SPIR-V compiling one at a time, 5-10 s each. diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index ddf3681a28..c685c46d64 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -4363,6 +4363,18 @@ if(TARGET Vulkan::Headers) target_link_libraries(gta6rt PRIVATE gta6rt_d3d12_com user32) # user32: the PresentX window target_compile_definitions(gta6rt PRIVATE LEONIDA_VULKAN_DEVICE) + # gta6rt --precompile-pipelines builds the programs LEONIDA_SKIP_COMPUTE names unless --skip-listed is given, + # and its last line counts both (shims/d3d12_precompile.h). Two synthetic compute modules, three runs. + if(TARGET gta6rt_compute_journal_shader) + add_dependencies(gta6rt gta6rt_indirect_count_shader gta6rt_compute_journal_shader) + add_test(NAME precompile_skip_list COMMAND ${CMAKE_COMMAND} + "-DGTA6RT=$" "-DRUNNER=${CMAKE_CROSSCOMPILING_EMULATOR}" + "-DSPV_A=${_indirect_count_spv}" "-DSPV_B=${_journal_second_spv}" + "-DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/precompile_skip_list" + -P "${CMAKE_CURRENT_SOURCE_DIR}/test/check_precompile_skip_list.cmake") + set_tests_properties(precompile_skip_list PROPERTIES TIMEOUT 240 SKIP_REGULAR_EXPRESSION "SKIP: ") + endif() + # A stand-in title that imports d3d12_xs.dll!D3D12XboxCreateDevice and runs a clear and a readback on the # device it gets, mapped and run by `gta6rt --run` with LEONIDA_D3D12=vulkan: the loader, the game thread, the # proxies and the Vulkan device in one process. check_tiny_frame.py reads the verdict, the binding and the diff --git a/runtime/shims/d3d12_precompile.h b/runtime/shims/d3d12_precompile.h index 447c4db4e0..ca96bb764a 100644 --- a/runtime/shims/d3d12_precompile.h +++ b/runtime/shims/d3d12_precompile.h @@ -8,6 +8,11 @@ // (src/pipeline_cache_journal.h) under the name the game looks it up by, and in the driver's own disk cache, which // NVIDIA keys by the executable's name. Entries whose journal file is there are skipped, so a run can be stopped at // any time and started again. +// +// LEONIDA_SKIP_COMPUTE (the play-time list of compute programs whose dispatches are dropped) does not narrow the +// build: a player runs this with the game's environment, and a program kept out of the journal here would stay out +// after the list is shortened. --skip-listed leaves the listed entries out on purpose. The last line counts what was +// built, what was journaled already and what was left out, and why. #pragma once #include @@ -25,6 +30,7 @@ struct PrecompileOptions { std::size_t limit = 0; // at most this many entries (0: all) std::size_t min_bytes = 0, max_bytes = 0; // SPIR-V size bounds (0: none) std::vector filters; // only entries whose name contains one of these + bool skip_listed = false; // --skip-listed: leave out the entries LEONIDA_SKIP_COMPUTE names bool dry_run = false; // --list: print the plan, build nothing bool via_helper = false; // --via-helper: as a title does with LEONIDA_COMPILE_HELPER=1 (a test) }; diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 16b814589e..dad52c11dc 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -1698,6 +1698,7 @@ bool merge_session_pipeline_cache(const leonida::VulkanDeviceFunctions& vk, VkDe // never built and every dispatch of theirs is dropped ("all" or "*": every compute program). For getting past a // program that hangs the GPU, such as a translated loop that never ends on the input it is given here, while the // program or its input is being fixed. What the program would have written keeps its previous contents. +// gta6rt --precompile-pipelines builds the listed programs anyway unless it is given --skip-listed. bool skip_compute(const std::string& name) { static const std::vector parts = [] { std::vector out; @@ -22309,10 +22310,10 @@ class BuildHost { DeviceState& state() { return *device_; } const leonida::ShaderLibrary* library() const { return library_; } - // Why create_compute would refuse the entry, or null. + // Why create_compute could not build the entry on this device, or null. LEONIDA_SKIP_COMPUTE is not a reason here: + // it drops a program's dispatches at play, and each caller decides whether it also keeps the program unbuilt. const char* unbuildable(const leonida::ShaderEntry& entry, std::size_t bytes) const { if (!bytes) return "no .spv"; - if (skip_compute(entry.name)) return "LEONIDA_SKIP_COMPUTE"; if (entry.binding_count && !with_set0_) return "set-0 bindings and no bindless set"; if (entry.lds_bytes && max_shared_ && entry.lds_bytes > max_shared_) return "workgroup memory over the limit"; return nullptr; @@ -22344,13 +22345,15 @@ int precompile_compute_pipelines(const PrecompileOptions& options) { if (!host.open()) return 1; const leonida::ShaderLibrary* library = host.library(); - // What to build: every compute entry the runtime could create a pipeline for. + // What to build: every compute entry the runtime could create a pipeline for. LEONIDA_SKIP_COMPUTE is a setting + // for play (the game drops the listed programs' dispatches); the journal is kept for every program unless + // --skip-listed asks to leave them out too, so a later run without the list finds them built. struct Job { const leonida::ShaderEntry* entry; std::size_t bytes; }; std::vector jobs; - std::size_t not_buildable = 0, filtered = 0; + std::size_t not_buildable = 0, filtered = 0, listed = 0, listed_left_out = 0; for (const leonida::ShaderEntry* entry : library->stage_entries("cs")) { if (!options.filters.empty() && std::none_of(options.filters.begin(), options.filters.end(), @@ -22363,6 +22366,15 @@ int precompile_compute_pipelines(const PrecompileOptions& options) { ++filtered; continue; } + if (skip_compute(entry->name)) { + ++listed; + if (options.skip_listed) { + ++listed_left_out; + std::fprintf(stderr, "[precompile] %s: not built (LEONIDA_SKIP_COMPUTE, --skip-listed)\n", + entry->name.c_str()); + continue; + } + } if (const char* why = host.unbuildable(*entry, bytes)) { ++not_buildable; std::fprintf(stderr, "[precompile] %s: not built (%s)\n", entry->name.c_str(), why); @@ -22373,14 +22385,22 @@ int precompile_compute_pipelines(const PrecompileOptions& options) { std::stable_sort(jobs.begin(), jobs.end(), [&](const Job& a, const Job& b) { return options.smallest_first ? a.bytes < b.bytes : a.bytes > b.bytes; }); - if (options.limit && jobs.size() > options.limit) jobs.resize(options.limit); + if (options.limit && jobs.size() > options.limit) { + filtered += jobs.size() - options.limit; + jobs.resize(options.limit); + } std::uint64_t total_bytes = 0; for (const Job& job : jobs) total_bytes += job.bytes; const unsigned threads = (std::max)(1u, options.threads); const unsigned big_threads = options.big_threads ? (std::min)(options.big_threads, threads) : threads; - std::fprintf(stderr, "[precompile] %zu compute entries to build (%.1f MB of SPIR-V; %zu filtered out, %zu not " - "buildable), %s first, %u thread(s), at most %u on modules over %zu bytes; journal %ls\n", - jobs.size(), double(total_bytes) / 1e6, filtered, not_buildable, + if (listed && !options.skip_listed) + std::fprintf(stderr, "[precompile] LEONIDA_SKIP_COMPUTE names %zu of the entries: built anyway, since the list " + "drops their dispatches at play only (--skip-listed leaves them out of this run)\n", + listed); + std::fprintf(stderr, "[precompile] %zu compute entries to build (%.1f MB of SPIR-V; %zu filtered out, %zu left " + "out by --skip-listed, %zu not buildable), %s first, %u thread(s), at most %u on modules over " + "%zu bytes; journal %ls\n", + jobs.size(), double(total_bytes) / 1e6, filtered, listed_left_out, not_buildable, options.smallest_first ? "smallest" : "largest", threads, big_threads, options.big_bytes, pipeline_journal_dir().c_str()); if (options.dry_run) { @@ -22390,7 +22410,7 @@ int precompile_compute_pipelines(const PrecompileOptions& options) { std::atomic next{0}; std::mutex progress_mutex; - std::size_t done = 0, compiled = 0, skipped = 0, hits = 0, failed = 0; + std::size_t done = 0, compiled = 0, skipped = 0, hits = 0, failed = 0, journaled = 0, elsewhere = 0; std::uint64_t done_bytes = 0; std::mutex big_mutex; std::condition_variable big_free; @@ -22429,8 +22449,8 @@ int precompile_compute_pipelines(const PrecompileOptions& options) { ++done; done_bytes += job.bytes; const char* what = "failed"; - if (build.skipped) ++skipped, what = "journaled already"; - else if (build.busy) ++skipped, what = "being built by another process"; + if (build.skipped) ++skipped, ++journaled, what = "journaled already"; + else if (build.busy) ++skipped, ++elsewhere, what = "being built by another process"; else if (build.result != VK_SUCCESS || (!build.pipeline && !build.skipped)) ++failed; else if (build.journal_hit || build.from_shared) ++hits, what = "found in a cache"; else ++compiled, what = build.journaled ? "compiled and journaled" : "compiled (not journaled)"; @@ -22447,8 +22467,12 @@ int precompile_compute_pipelines(const PrecompileOptions& options) { std::vector pool; for (unsigned t = 0; t < threads; ++t) pool.emplace_back(worker); for (std::thread& t : pool) t.join(); - std::fprintf(stderr, "[precompile] done: %zu compiled, %zu from a cache, %zu journaled already, %zu failed, %zu " - "not buildable, in %.0f s\n", compiled, hits, skipped, failed, not_buildable, + // One line for the whole run: what was built, what was there already, and what was left out and why. + std::fprintf(stderr, "[precompile] done: %zu built (%zu compiled, %zu from a cache), %zu journaled already, %zu " + "being built by another process, %zu failed; left out: %zu of %zu listed in " + "LEONIDA_SKIP_COMPUTE%s, %zu not buildable, %zu filtered out; in %.0f s\n", + compiled + hits, compiled, hits, journaled, elsewhere, failed, listed_left_out, listed, + options.skip_listed ? " (--skip-listed)" : "", not_buildable, filtered, std::chrono::duration(Clock::now() - began).count()); return failed ? 2 : 0; } @@ -22567,6 +22591,7 @@ int compile_server(const CompileServerOptions& options) { const leonida::ShaderEntry* entry = it == by_name.end() ? nullptr : it->second; const std::size_t bytes = entry ? library->spirv_bytes(*entry) : 0; if (!entry) failure = "no compute entry of that name in this library"; + else if (skip_compute(entry->name)) failure = "LEONIDA_SKIP_COMPUTE"; // the game drops its dispatches else if (const char* why = host.unbuildable(*entry, bytes)) failure = why; // LOCAL FIX (compile helper: the journal name was checked after the build): the name is hashed from the // module and this device's environment, which costs no driver call. A request from a game whose environment @@ -22691,7 +22716,7 @@ int compile_server(const CompileServerOptions& options) { return; } const leonida::ShaderEntry& entry = *fill_order[i]; - if (host.unbuildable(entry, fill_bytes[i])) continue; + if (skip_compute(entry.name) || host.unbuildable(entry, fill_bytes[i])) continue; std::error_code stat; const auto spv = library->spirv_file(entry); const long long mtime = static_cast(std::filesystem::last_write_time(spv, stat).time_since_epoch().count()); diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 21551e9489..6f70390995 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -10,11 +10,11 @@ // The same mapping, then each loaded DLL's TLS callbacks and DllMain(DLL_PROCESS_ATTACH) are run. // // gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--big-bytes N] [--all] [--smallest-first] -// [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--list] +// [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--skip-listed] [--list] // No game: creates the Vulkan device as --run does and builds every compute pipeline of the shader library // (LEONIDA_SHADERS) into the pipeline journal and the driver's cache, so a title's first dispatch of a large one -// does not stall it. Resumable: entries already journaled are skipped (--all: built anyway). See -// shims/d3d12_precompile.h. +// does not stall it. Resumable: entries already journaled are skipped (--all: built anyway). Programs named by +// LEONIDA_SKIP_COMPUTE are built too unless --skip-listed is given. See shims/d3d12_precompile.h. // // gta6rt --run [--game-dir DIR] [--overlay DIR] [--trace-d3d12] [--trace FILE] [-- game arguments...] // The same, then the EXE's own TLS callbacks and its entry point, on a game thread. The game's argv and @@ -262,7 +262,7 @@ int usage() { " gta6rt --init [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" " gta6rt --first-run-ui [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" " gta6rt --run [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n" - " gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--big-bytes N] [--all] [--smallest-first] [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--list] [--via-helper]\n" + " gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--big-bytes N] [--all] [--smallest-first] [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--skip-listed] [--list] [--via-helper]\n" " gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS]\n"); return 2; } @@ -290,6 +290,7 @@ int precompile_main(int argc, wchar_t** argv) { else if (a == L"--max-bytes") ok = number(i, options.max_bytes); else if (a == L"--all") options.rebuild = true; else if (a == L"--smallest-first") options.smallest_first = true; + else if (a == L"--skip-listed") options.skip_listed = true; else if (a == L"--list") options.dry_run = true; else if (a == L"--via-helper") options.via_helper = true; else if (a == L"--filter" && i + 1 < argc) { diff --git a/runtime/test/check_precompile_skip_list.cmake b/runtime/test/check_precompile_skip_list.cmake new file mode 100644 index 0000000000..5945db7615 --- /dev/null +++ b/runtime/test/check_precompile_skip_list.cmake @@ -0,0 +1,123 @@ +# gta6rt --precompile-pipelines and LEONIDA_SKIP_COMPUTE (shims/d3d12_precompile.h): the play-time skip list does not +# keep programs out of the pipeline journal; --skip-listed does, and the closing line counts both. +# cmake -DGTA6RT= [-DRUNNER=] -DSPV_A= -DSPV_B= +# -DTEST_DIR= -P check_precompile_skip_list.cmake +# A library of two synthetic compute entries, one of them named by LEONIDA_SKIP_COMPUTE, is precompiled three times: +# 1. into an empty journal with the list set and no flag: both entries are built; +# 2. into another empty journal with --skip-listed: only the unlisted one is, and the listed one is reported; +# 3. into the first journal again: both are journaled already, nothing is built. +# The verdicts are read from the output and the journal folders, since under Wine an exit status alone can look fine. +cmake_minimum_required(VERSION 3.24) + +foreach(var GTA6RT SPV_A SPV_B TEST_DIR) + if(NOT DEFINED ${var} OR "${${var}}" STREQUAL "") + message(FATAL_ERROR "check_precompile_skip_list.cmake: -D${var}=... is required") + endif() +endforeach() + +file(REMOVE_RECURSE "${TEST_DIR}") +file(MAKE_DIRECTORY "${TEST_DIR}/shaders") +# Two different modules: entries with the same module and layout share one journal file. +file(COPY_FILE "${SPV_A}" "${TEST_DIR}/shaders/precompile_kept.spv") +file(COPY_FILE "${SPV_B}" "${TEST_DIR}/shaders/precompile_listed.spv") +# The runtime's library takes an entry only with a program hash; these two name no real program. +set(meta "\"stage\":\"cs\",\"bindings\":[],\"push_constant_bytes\":144,\"local_size\":[1,1,1],\"wave64\":false") +string(REPEAT "a" 64 hash_kept) +string(REPEAT "b" 64 hash_listed) +file(WRITE "${TEST_DIR}/shaders/index.json" + "{\"precompile_kept\":{\"fssm_sha256\":\"${hash_kept}\",${meta}}," + "\"precompile_listed\":{\"fssm_sha256\":\"${hash_listed}\",${meta}}}\n") + +# Only what this test sets: a journal setting or helper from the caller's environment would change the counts. +foreach(var LEONIDA_PIPELINE_JOURNAL LEONIDA_PIPELINE_CACHE_BYTES LEONIDA_PIPELINE_JOURNAL_BYTES + LEONIDA_PIPELINE_JOURNAL_SEED_DIR LEONIDA_COMPILE_HELPER LEONIDA_LAZY_COMPUTE) + unset(ENV{${var}}) +endforeach() +file(TO_NATIVE_PATH "${TEST_DIR}/shaders" shaders) +set(ENV{LEONIDA_SHADERS} "${shaders}") +set(ENV{LEONIDA_SKIP_COMPUTE} "precompile_listed") + +set(failures "") +set(all_output "") +# Runs the precompile with the journal in and the extra arguments; sets `out` and `code` in the caller. +function(precompile label cache) + file(TO_NATIVE_PATH "${TEST_DIR}/${cache}" cache_dir) + set(ENV{LEONIDA_PIPELINE_CACHE_DIR} "${cache_dir}") + execute_process(COMMAND ${RUNNER} "${GTA6RT}" --precompile-pipelines --threads 1 ${ARGN} + WORKING_DIRECTORY "${TEST_DIR}" + TIMEOUT 90 + RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE output) + string(REPLACE "\r\n" "\n" output "\n${output}\n") + set(out "${output}" PARENT_SCOPE) + set(code "${result}" PARENT_SCOPE) + set(all_output "${all_output}--- ${label} (exit ${result}) ---${output}" PARENT_SCOPE) +endfunction() +# Functions, not macros: a macro would substitute the patterns' text and undo their backslash escapes. +function(expect label pattern) + if(NOT out MATCHES "${pattern}") + set(failures "${failures}${label}: no match for '${pattern}'\n" PARENT_SCOPE) + endif() +endfunction() +function(expect_not label pattern) + if(out MATCHES "${pattern}") + set(failures "${failures}${label}: unexpected match for '${pattern}'\n" PARENT_SCOPE) + endif() +endfunction() +function(expect_exit label want) + if(NOT "${code}" STREQUAL "${want}") + set(failures "${failures}${label}: exit ${code}, not ${want}\n" PARENT_SCOPE) + endif() +endfunction() +function(journal_files cache var) + file(GLOB files "${TEST_DIR}/${cache}/pipeline_cache.d/cs-*.bin") + list(LENGTH files count) + set(${var} ${count} PARENT_SCOPE) +endfunction() + +# 1. The list is set, no flag: both entries are built and nothing is reported as left out by the list. +precompile("list set, no flag" cache_all) +if(code STREQUAL "1" AND out MATCHES "the Vulkan device could not be created|the runtime builds no compute pipeline") + message("SKIP: no Vulkan device for the precompile here${all_output}") + return() +endif() +expect_exit("list set, no flag" 0) +expect("list set, no flag" "\n\\[precompile\\] LEONIDA_SKIP_COMPUTE names 1 of the entries: built anyway") +expect("list set, no flag" "\n\\[precompile\\] 2 compute entries to build ") +expect_not("list set, no flag" "precompile_listed: not built") +expect("list set, no flag" "\n\\[precompile\\] done: 2 built \\([0-9]+ compiled, [0-9]+ from a cache\\), 0 journaled already, 0 being built by another process, 0 failed; left out: 0 of 1 listed in LEONIDA_SKIP_COMPUTE, 0 not buildable, 0 filtered out; in [0-9]+ s\n") +# A driver that returns no cache data leaves no journal file; then step 3 has nothing to find. +set(journaled TRUE) +if(out MATCHES "compiled \\(not journaled\\)") + set(journaled FALSE) + message("note: the driver gave no cache data, so the journal-file checks are left out") +else() + journal_files(cache_all count) + if(NOT count EQUAL 2) + string(APPEND failures "list set, no flag: ${count} journal files, not 2\n") + endif() +endif() + +# 2. --skip-listed: the listed entry is left out and named, the other one is built. +precompile("--skip-listed" cache_listed --skip-listed) +expect_exit("--skip-listed" 0) +expect("--skip-listed" "\n\\[precompile\\] precompile_listed: not built \\(LEONIDA_SKIP_COMPUTE, --skip-listed\\)\n") +expect("--skip-listed" "\n\\[precompile\\] 1 compute entries to build \\([^)]*, 1 left out by --skip-listed, 0 not buildable\\)") +expect("--skip-listed" "\n\\[precompile\\] done: 1 built \\([0-9]+ compiled, [0-9]+ from a cache\\), 0 journaled already, 0 being built by another process, 0 failed; left out: 1 of 1 listed in LEONIDA_SKIP_COMPUTE \\(--skip-listed\\), 0 not buildable, 0 filtered out; in [0-9]+ s\n") +if(journaled) + journal_files(cache_listed count) + if(NOT count EQUAL 1) + string(APPEND failures "--skip-listed: ${count} journal files, not 1\n") + endif() +endif() + +# 3. The first journal again: both entries are there, nothing is built. +if(journaled) + precompile("again" cache_all) + expect_exit("again" 0) + expect("again" "\n\\[precompile\\] done: 0 built \\(0 compiled, 0 from a cache\\), 2 journaled already, 0 being built by another process, 0 failed; left out: 0 of 1 listed in LEONIDA_SKIP_COMPUTE, 0 not buildable, 0 filtered out; in [0-9]+ s\n") +endif() + +if(failures) + message(FATAL_ERROR "gta6rt --precompile-pipelines and LEONIDA_SKIP_COMPUTE:\n${failures}${all_output}") +endif() +message("precompile and LEONIDA_SKIP_COMPUTE: built regardless of the list, left out with --skip-listed${all_output}")