Skip to content

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

Open
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-pipeline-journal-build-id
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-pipeline-journal-build-id

Conversation

@Tyrannys

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.

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.

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.

  • ctest -R "^(pipeline_cache_journal|pipeline_cache_store|pipeline_cache_file|pipeline_cache_seed|compile_helper|d3d12_compute_journal|precompile_skip_list)$": 7/7 pass (with pipeline_cache_file and pipeline_cache_seed).

  • scripts/check_no_game_data.py: clean.

Not tested: NVIDIA 621.40 (enlight3d's driver), AMD or Intel, and a game boot. 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.

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

1 participant