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

@timbot103 timbot103 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.

I reviewed head 4a497c8f1 against the base code in a static audit. No builds, tests, or GPU runs were performed. I’d request changes before relying on the stamp to skip pipelines.

  • runtime/shims/d3d12_vulkan_device.cpp:11693 can make a stale entry current after a fast create with no valid feedback or after a reported miss that exports the old seeded bytes, as described in the PR. Please require a confirmed application-cache hit to promote the original bytes and materialize misses in an empty cache. The next precompile otherwise skips the file even if it still lacks the pipeline.
  • runtime/shims/d3d12_vulkan_device.cpp:11966 bypasses the entry lock when the stale file is readable. Two default precompile runs can both build and replace the same entry. Please hold the lock across the recheck and publish, and check currency again after acquiring it.
  • runtime/src/vulkan_device_config.h:78 ignores the contents of chained runtime features such as VkPhysicalDeviceShaderClockFeaturesKHR. The two clock bits can change while the extension list and chain types stay the same. Please hash the payloads of the feature structures the runtime emits.
  • runtime/src/pipeline_cache_journal.h:270 accepts a stamped file truncated to just the two headers. The write path at runtime/shims/d3d12_vulkan_device.cpp:11698 can also produce files 1–24 bytes above the reader’s cap. Please align the read and write bounds and record the expected payload length.
  • runtime/shims/d3d12_vulkan_device.cpp:23684 reports a hit as restamped even if publishing failed. Please count successful publishes using build.restamped and report failed attempts.
  • runtime/shims/d3d12_vulkan_device.cpp:11910 misses alternate diagnostics files written with LEONIDA_AFTERMATH_SHADER_ERRORS=1 when the current boot has Aftermath disabled. Please check the supported flag variants or look them up by the base pipeline key.

AI-assisted.

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Independently verified head 4a497c8f1bebda53091413442a76d31ff3411c97 merged cleanly onto origin/main (5825b02ff89bca1a2d1331d982818e3dbb74d597) on Windows 11 (10.0.26200), MSVC 19.44.35207 (RelWithDebInfo), NVIDIA GeForce RTX 3090 (driver 595.79, fault info + buffer markers/checkpoints + VK_NV_device_diagnostics_config all supported), with VK_LAYER_KHRONOS_validation 1.4.363.1 (LEONIDA_VK_VALIDATION=1). No game files used.

Red -> Green Verification

  • Red (entry_usable skip check restored in build_compute_pipeline):
    • ctest -C RelWithDebInfo -R "^precompile_skip_list$": FAILED (rc=8) on both another build (LEONIDA_PIPELINE_JOURNAL_BUILD) and device fault 2 (LEONIDA_DEVICE_FAULT=2) checks (2 journaled already instead of rebuilding/restamping and reporting the other-build / other-config lines).
  • Green (#2511 merged with origin/main 5825b02ff8, LEONIDA_VK_VALIDATION=1 on RTX 3090):
    • 9/9 CTests Passed (15.27 s, 0 Khronos validation errors):
      • pipeline_cache_file (0.58 s), pipeline_cache_store (0.06 s), pipeline_cache_journal (0.20 s), compile_helper (0.65 s), vulkan_device_fault (0.22 s), vulkan_device_config (0.05 s), d3d12_compute_journal (0.60 s), pipeline_cache_seed, and precompile_skip_list (10.77 s) — executing all 9 end-to-end steps on RTX 3090 including LEONIDA_PIPELINE_JOURNAL_BUILD restamping, LEONIDA_DEVICE_FAULT=2 other-config restamping, and LEONIDA_DEVICE_FAULT=1 NVIDIA diagnostics-config cross-setting detection (2 entries had a journal file only for a device without NVIDIA's diagnostics config: built for this setting -> 2 journaled already on repeat).
    • scripts/check_no_game_data.py & 18/18 doc/CTest checks (test_docs_encoding.py, test_docs_repo_paths.py, test_docs_env_vars.py, test_ctest_registration.py): Passed.

Important Cross-PR Interaction Catch with Open PR #2179 (RT-JOURNAL-SEEDED-REWRITE)

The PR body notes #2179 touches JournalCache on adjacent lines, and git merge-tree --write-tree between #2511 (4a497c8f1b) and #2179 (4212cf5ab3) auto-merges cleanly (rc=0) with zero text conflicts — however, combining them as-is silently disables #2179's restart_empty() on every LPJ1-stamped file:

  • #2511's read_entry_file sets entry.bytes = size to the on-disk file size (stamp_bytes (24) + blob_size, needed by JournalCache::publish() for replace_bytes(total, file_.bytes, file.size())) and erases the 24-byte LPJ1 stamp from entry.data before JournalCache::create() seeds vkCreatePipelineCache with file_.data.size() (file_.bytes - 24).
  • #2179's JournalCache::restart_empty() checks size != file_.bytes against vkGetPipelineCacheData(..., &size, nullptr). On an unchanged seeded miss from an LPJ1-stamped file, the driver returns size == file_.bytes - 24, so size != file_.bytes is always true and restart_empty() returns false.
  • 1-line coordination fix (flagged on #2179 as well): whichever PR lands second should store seeded_bytes_ = file_.data.size() in JournalCache::create() and compare size != seeded_bytes_ in JournalCache::restart_empty(), keeping file_.bytes as the on-disk stamped byte count for publish().

AI-assisted: yes

@lixonik

lixonik commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

CORRECTION to my earlier audit of 4a497c8f1: the hash records the type of every visited pNext structure, but it hashes member values only for the cases in add_struct. My earlier wording overstated the coverage.

On head 4a497c8f1bebda53091413442a76d31ff3411c97 merged with main c8bf0e7b65, two synthetic CPU controls confirmed the corresponding review findings:

  • With the extension set and pNext types held fixed, changing only VkPhysicalDeviceShaderClockFeaturesKHR::shaderSubgroupClock left device_create_config unchanged.
  • I wrote a stamped entry with a matching 32-byte Vulkan cache header and a 64-byte synthetic payload. After removing all 64 payload bytes, entry_current still returned true, so a precompile scan can skip that header-only file.

Windows 10, MSVC 19.29, Vulkan SDK headers 1.4.363.1, CPU only. These probes do not measure driver cache-hit behavior.

AI-assisted. Codex (GPT-6).

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Verified by OreoFR — NO RED (tests do not compile on main)

  • Base: main c8bf0e7 + this PR (head 4a497c8) merged with --no-ff
  • Red (main + only this PR's tests): no behavioural red. vulkan_device_config_test needs the new src/vulkan_device_config.h, and pipeline_cache_journal_test needs the new journal writer API (94 compile errors on main). precompile_skip_list launches gta6rt, so it is excluded here.
  • Green (merge): vulkan_device_config and pipeline_cache_journal pass; ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p6 = main + 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 (no shared files): 495 tests, new failures vs main: none (main alone: 494 tests, 5 failures: loader, xs_proxy_mock, xmem_no_write_watch, api_ref_state timeout, xbox_present; xbox_present fails in every package as on main)
  • gta6rt.exe links without the XMA decoder (LEONIDA_CARGO=OFF, LEONIDA_XMA2_DECODER_LIB empty), main + this PR alone; imports vs main: 2 more functions from msvcp140.dll (std::ios_base::bad, std::basic_istream::gcount, from the stamp reader), no new DLL, no WS2_32
  • Diff read: no issue. Checked: stamp read and strip, the entry_current and check_entry bounds, and the restamp path. Every journal reader goes through entry_usable or read_entry_file.
  • Other runs: Consistent with zmasi's and lixonik's runs.
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

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.

5 participants