Skip to content

d3d12: stamp compute journal files with the writing build and device-create config; precompile re-checks other writers' files (RT-PIPELINE-JOURNAL-BUILD-ID) - #2511

Open
Tyrannys wants to merge 2 commits into
ProjectLeonida:mainfrom
Tyrannys:rt-pipeline-journal-build-id
Open

Tyrannys wants to merge 2 commits into
ProjectLeonida:mainfrom
Tyrannys:rt-pipeline-journal-build-id

Conversation

@Tyrannys

@Tyrannys Tyrannys commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-PIPELINE-JOURNAL-BUILD-ID (#1608 (comment))

What and why

From @enlight3d's finding in #1608 (#1608 (comment)). Thanks for the measurements.

On NVIDIA 621.40, a compute journal file in pipeline_cache.d was measured giving cache hits mostly to the gta6rt build that wrote it. The runtime checks only the blob header (vendor, device, pipeline-cache UUID). gta6rt --precompile-pipelines skipped any file whose header matched as "journaled already". So after a rebuild it could report a complete journal that the new binary got few hits from.

What our code gives the driver. Nothing in it changes from one build to the next:

  • VkApplicationInfo has only the name gta6rt and API 1.3, with no application or engine version.
  • The compute create info has no specialization data.
  • The journal key already hashes the SPIR-V, the entry point, the create and stage flags, the subgroup request, the push range and the bindless layout. Two builds of the same source give the same file names, which is why the precompiler took the files as done.

So there was no per-build input to make stable.

Measured here. A standalone Vulkan program, RTX 4070 SUPER, driver 621.01:

  • A VkPipelineCache blob written by one executable gave a cache hit (creation feedback APPLICATION_PIPELINE_CACHE_HIT, 3-75 ms instead of 2.6-22 s) to all of these:
    • a byte-identical copy under another name;
    • an executable rebuilt with a different string in it;
    • one of those with robustBufferAccess or shaderInt64 enabled on the device.
  • The blobs were 0.7 MiB and 2 MiB.
  • NVIDIA's own disk cache (%LOCALAPPDATA%\NVIDIA\GLCache) did key on the executable. A renamed byte-identical copy got a file of its own there and compiled again (4.7 s) when given an empty VkPipelineCache.

So this driver did not show the effect. What the driver keys on in enlight3d's case is still open. Their same-binary drop (all compute pipelines from the journal at 20:16, 22 at 21:45) also points at something besides the binary.

Device-create config (second commit). A boot A/B on the same RTX 4070 SUPER (621.01), counts only:

  • journal precompiled without LEONIDA_DEVICE_FAULT, boot with LEONIDA_DEVICE_FAULT=1: 10 compiled, 0 from the journal;
  • the setting matching both ways: 0 compiled, 10 from the journal.

The NVIDIA diagnostics config (=1, or LEONIDA_AFTERMATH=1) already names its pipelines apart (since #2098), so such a boot simply had no file for those pipelines, and nothing said why.

Change. Whatever the cause, the precompiler should not count a file as done without knowing the driver takes it for this binary.

  • Stamp (pipeline_cache_journal.h). Each journal file now starts with 16 bytes:

    • LPJ1 and the stamp's size;
    • a 64-bit hash of the contents of the gta6rt executable that wrote it (file_build, computed once per process).

    read_entry_file removes the stamp before the blob goes to the driver. check_entry/entry_usable read the stamp and blob header. The new entry_current is true only for a file this build wrote. A file without a stamp (an older runtime) is read as before and counts as from another build. An older runtime reading a new file sees a header it does not know and rebuilds that file.

  • Precompile (d3d12_vulkan_device.cpp). With skip_journaled, only entry_current files are skipped. A file from another build is built against, as at a dispatch:

    • a hit takes milliseconds, and the file is written again with this build's stamp (restamp_hits), so the next run skips it;
    • a miss compiles and rewrites the file.

    After the existing done: line (unchanged, so the existing check_precompile_skip_list patterns still match), a second line follows when there were any: N journal file(s) from another gta6rt build or without a build stamp: H still found by the driver (now stamped as this build's), C compiled again.

  • Runtime. The journal's "so far" line also gives from another build: N, M of them found. A boot after a rebuild then shows directly whether that driver still takes another build's files. The runtime does not restamp, so files from another build keep counting until the precompiler runs.

  • LEONIDA_PIPELINE_JOURNAL_BUILD=<hex> replaces the executable's hash. It is for tests: a second build without a second binary.

  • docs/d3d12_vulkan.md and docs/running.md describe the stamp and say to run the precompiler again after a rebuild.

  • Device-create config in the stamp (second commit). The stamp grows to 24 bytes: the build, then device_create_config of the VkDeviceCreateInfo (new src/vulkan_device_config.h): the enabled extensions in any order, pEnabledFeatures, and each pNext structure by type, with the contents of the core 1.1/1.2/1.3 feature structures, robustness2, device fault and the diagnostics config (features and create info with its flags). entry_current needs both to match. A file this build wrote under another config (for example LEONIDA_DEVICE_FAULT=2, which adds fault info and checkpoints but keeps the names) is built against again and restamped on a hit, and counted apart from other builds: [precompile] N journal file(s) from this build under another device config (...): H still found by the driver (now stamped with this config), C compiled again, and from another device config: N, M of them found in the runtime's line.

  • The other diagnostics setting. Each build also names the file under the other diagnostics config setting. When the pipeline has no file but that one exists, it is reported once at boot (<entry> has a journal file only for a device without NVIDIA's diagnostics config ...; run gta6rt --precompile-pipelines with this boot's setting), counted in the runtime's line (only under the other diagnostics config setting: N), and in a closing line of the precompiler (N entries had a journal file only for a device without NVIDIA's diagnostics config: built for this setting).

Unchanged: the compile helper's readiness checks and the compile server's idle fill still use entry_usable (any build). The helper is the same executable as the game, so its files carry the game's stamp.

Overlap: #2198 (--precompile-pipelines --verify), #2179 and #2228 (journal rewrite and stale-file probe), #2307 (pipeline_cache_journal.h guards) and #2392 (make_game pipelines via the runtime) touch the same files on other lines. #2179 matters here: on a seeded miss, NVIDIA returned the seeded data without the new pipeline, so a rewrite could keep a file that misses. With this change, such a file also gets this build's stamp. #2179 fixes the rewrite itself.

Tested

Windows 11, MSVC (VS 18), RelWithDebInfo, on main 34e33d3. Short GPU runs only.

  • pipeline_cache_journal_test (CPU) gains test_stamp:

    • stamp round trip;
    • a stamped file reads back as the blob alone, with its build;
    • entry_current only for the writing build, never for build 0;
    • an unstamped file is usable and counts as from another build;
    • a stamp followed by a short or foreign blob is refused, and the read limit counts the stamp;
    • a seed file's stamp comes with its data;
    • file_build is the same for a copy under another name, differs for a one-byte change and for one byte fewer, and is 0 for a missing or empty file.
  • check_precompile_skip_list.cmake (gta6rt, real device, two small synthetic modules) gains three checks:

    • each file starts with the stamp;
    • as another build (LEONIDA_PIPELINE_JOURNAL_BUILD), both files are built again, not counted as journaled already: 2 found in a cache, 0 compiled, and the new line reports 2 from another build;
    • that build's next run counts both as journaled already.

    With main's skip check (entry_usable) restored in this branch, the "another build" step fails on both of its patterns: the files are counted as journaled already and no other-build line is printed.

  • Second commit:

    • new vulkan_device_config_test (CPU): the same create info gives the same value; extension order does not matter, an added extension does; core and chained feature bits (including the last member of the 1.2 and 1.3 structures) count; LEONIDA_DEVICE_FAULT=1 and =2 (through the runtime's DeviceFaultFeatures) differ from a plain device and from each other; Aftermath's extra flags count; =1 on a device without the config equals =2; never 0.
    • pipeline_cache_journal_test: the config in the stamp, other_config apart from other_build (an unstamped file counts only as another build), entry_current false for another config, a seed file's config.
    • check_precompile_skip_list.cmake gains steps 6-9, run here (fault info, checkpoints and the diagnostics config are all on this device): with LEONIDA_DEVICE_FAULT=2, both files are reported from another device config (2 still found by the driver), then journaled already on the next run; with LEONIDA_DEVICE_FAULT=1, both are built (no file under the diagnostics names), the new line reports 2 with a file only without the config, the journal holds 4 files, and the next run counts 2 journaled already. Each step falls back to a note on a device without those extensions.
    • Negative control: with the config check taken out of entry_current, step 6 fails on both of its patterns.
  • ctest -R "^(pipeline_cache_journal|pipeline_cache_store|pipeline_cache_file|pipeline_cache_seed|compile_helper|d3d12_compute_journal|precompile_skip_list|vulkan_device_config|vulkan_device_fault)$": 9/9 pass.

  • scripts/check_no_game_data.py: clean.

Not tested: NVIDIA 621.40 (enlight3d's driver), AMD or Intel, and a game boot with this branch (the A/B counts above are from a boot of main). A boot after this lands, with a journal from the previous build, would show in the runtime's line how many of that build's files the driver still takes. Files written by the first commit's 16-byte stamp (never merged) read as unstamped.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

… re-checks other builds' files

A compute journal file (pipeline_cache.d/cs-*.bin) was taken by gta6rt --precompile-pipelines as
journaled already whenever its blob header named this device and driver. enlight3d measured on
NVIDIA 621.40 that a rebuilt runtime got few hits from the files another build wrote, so after a
rebuild the precompiler could report a complete journal that did not help.

Each journal file now starts with a 16-byte stamp ("LPJ1", its size, a 64-bit hash of the gta6rt
executable that wrote it) before the VkPipelineCache blob; the stamp is removed before the blob
reaches the driver. Files without a stamp are read as before.

- The precompiler skips only files this build wrote (entry_current). A file from another build is
  built against: a hit takes milliseconds and the file is stamped as this build's, a miss compiles
  and rewrites it. A line after the summary counts them.
- The runtime's journal line counts files from another build and how many of them still hit.
- LEONIDA_PIPELINE_JOURNAL_BUILD=<hex> stands in for the executable's hash (tests).

pipeline_cache_journal_test gains test_stamp; check_precompile_skip_list checks the stamp and a run
as another build. Docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…other diagnostics setting

On NVIDIA 621.01 (RTX 4070 SUPER), a compute journal precompiled without
LEONIDA_DEVICE_FAULT and booted with it gave 0 of 10 pipelines from the
journal (10 compiled); with the setting matching both ways, 10 of 10.

- The journal stamp grows to 24 bytes: the writing binary's build plus a
  hash of the VkDeviceCreateInfo (src/vulkan_device_config.h: enabled
  extensions in any order, core and chained feature bits, the device fault
  and NVIDIA diagnostics config structures with their flags). Only a file
  this build wrote under this config is "journaled already" for
  --precompile-pipelines; a file from another config is built against again
  and restamped on a hit, like a file from another build.
- The diagnostics config already names its pipelines apart, so a boot with it
  finds no file for a journal precompiled without it. Such a pipeline (no
  file, one under the other setting) is now counted: once at boot with a hint
  to precompile with the boot's setting, in the journal's running line, and
  in a closing line of the precompiler.
- Tests: vulkan_device_config_test (CPU); pipeline_cache_journal_test covers
  the config in the stamp; check_precompile_skip_list runs
  LEONIDA_DEVICE_FAULT=2 and =1 against the journal when the device has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys Tyrannys changed the title d3d12: stamp compute journal files with the writing build; precompile re-checks other builds' files (RT-PIPELINE-JOURNAL-BUILD-ID) d3d12: stamp compute journal files with the writing build and device-create config; precompile re-checks other writers' files (RT-PIPELINE-JOURNAL-BUILD-ID) Nov 28, 2026
@timbot103

Copy link
Copy Markdown
Contributor

Independently checked head 4a497c8f1 on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK 1.4.363.0, WSL llvm-mc 21.1.8, no game files.

Local build & dual-GPU verification:

  • Clean MSVC build of pipeline_cache_journal_test, vulkan_device_config_test, and d3d12_m4_compute_test (zero warnings in PR files).
  • pipeline_cache_journal_test: PASS (pipeline_cache_journal_test: ok).
  • vulkan_device_config_test: PASS (vulkan_device_config: ok).
  • d3d12_m4_compute_test (LEONIDA_VK_VALIDATION=1): 1924/1924 words matched (error 0) on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02), 0 validation errors.

Code review notes:

  • The 24-byte LPJ1 stamp (magic + size validation, unstamped files still readable as another build, header mismatch clearing data, check_entry bounds checks, one-time static content hash for file_build) is clean and backwards-compatible going forward.
  • vulkan_device_config.h properly sorts/deduplicates enabled extensions, hashes pEnabledFeatures (VkBool32 fields) and listed pNext structs from past pNext to the last member without reading trailing padding, and caps chain traversal at 256 links.
  • Two minor notes:
    1. Worth one line in docs/running.md noting that an older runtime binary reading a newly stamped file will treat it as a header mismatch (harmless cache miss, no crash).
    2. VkPhysicalDeviceVulkan14Features (if present in pNext) is currently hashed by sType only, and the hash depends on pNext chain order (at worst a harmless rebuild).

Overall looks clean and solid. AI-assisted.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4a497c8f1 and tested both CPU unit tests and live Vulkan compute journal / precompile paths.

Code audit:

  • runtime/src/vulkan_device_config.h: cleanly hashes sorted/deduplicated device extensions, pEnabledFeatures, and the pNext chain (using exact member ranges without reading trailing padding; bounded chain traversal; non-zero result).
  • runtime/src/pipeline_cache_journal.h: 24-byte LPJ1 stamp (magic, stamp_bytes, executable file_build, device_create_config) is backward compatible with unstamped files, check_entry reads only stamp + cache header for fast precompile scans, and entry_current properly gates precompile skips.
  • runtime/shims/d3d12_vulkan_device.cpp: restamping on hits from another build/config skips immutable seed files, updates journal_bytes atomically, and surfaces the other_diagnostics hint cleanly.

Verification (Windows 11, MSVC 19.44, Ninja Release, LEONIDA_VK_VALIDATION=1):

  • Built pipeline_cache_journal_test, vulkan_device_config_test, d3d12_m4_compute_test, and gta6rt.
  • ctest -R '^(pipeline_cache_journal|vulkan_device_config|d3d12_m4_compute|precompile_skip_list)$': 4/4 passed.
  • python -I scripts/check_no_game_data.py: passed.

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341, VK_LAYER_KHRONOS_validation 1.4.363).

AI-assisted (Antigravity, Gemini).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants