Skip to content

D3D12-WARM-MASKED-TWINS: note masked twins in the pipeline book, so the precompile makes them - #2957

Draft
johnabrea wants to merge 1 commit into
ProjectLeonida:mainfrom
johnabrea:d3d12-warm-masked
Draft

johnabrea wants to merge 1 commit into
ProjectLeonida:mainfrom
johnabrea:d3d12-warm-masked

Conversation

@johnabrea

Copy link
Copy Markdown

Claimed in the coordination issue as: D3D12-WARM-MASKED-TWINS (#2570 (comment))

What and why

Since 65f372c ("gpu: honor coverage on the first masked draw"), the first draw under the console's sample mask builds its masked twin before the draw is recorded (make::masked_for), so the frame waits for that compile. This is correct for the picture. But the precompile never makes a twin:

  • the twin's key is noted as used (library::note_used), so it is in early-pipelines.txt;
  • known-pipelines.bin holds only the title's own pipelines (known::note is called from hand_out alone), so leonida warm --used has no entry for that key.

As a result, every twin is compiled in play, once per translation or driver change, and each one stalls the frame. On a fork that had merged 65f372c this showed up as constant hitching right after an update. Reverting the commit there removed the hitching.

This change:

  • host_pipeline_masked notes the twin in the book (known::note) when it is first created, under the twin's own key, the one the used list names.
  • In a book entry, a masked twin's pixel shader has 0x80 set on its stage number, followed by the mask's position row after the hash (u32::MAX for None). parse makes Shader::masked with that mask, so the warm translates and builds the same pipeline the draw would.
  • Entries are length-prefixed, so an older build reading a new file refuses only the twins' entries (STAGES.get misses); all other entries are unaffected. Old files read as before.

Not covered: a twin made for differing bound formats (make::variant) is noted as used under the variant's key, which the book does not hold. The plain pipelines' format variants have the same gap today.

Tested

  • New pipeline::known::tests::a_masked_twin_comes_back_masked: writes an entry with a masked pixel shader (position row Some(3) and None) and reads it back with the mask intact; an entry cut inside the position row is refused. On main this test does not build (put_shader is new), and main's parse refuses the 0x81 stage byte.
  • cargo test -p leonida-gpu --lib --locked: 644 passed, 1 failed (watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view, a file this PR does not touch). That test passed when run alone right after.
  • scripts/build-nvidia.ps1 (diag, with DLSS) builds.
  • Not yet run in game. It needs three steps: a run that notes the twins, a precompile, and then a run that checks no twin compiles in play. It stays a draft until that is done.

GPUs tested: NVIDIA GeForce RTX 5080, driver 621.40, Windows 11 Pro 26200 (unit tests only so far)

AI-assisted: yes. Claude Code with Claude Opus 5.5 wrote the change. Not yet reviewed by a separate reviewer agent; that will happen before this leaves draft.

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (check_no_game_data.py on the changed files).
  • A new translator rule is in the contract table of docs/design.md (n/a: no translator change).

🤖 Generated with Claude Code

…them (D3D12-WARM-MASKED-TWINS)

Since 65f372c the first draw under the console's sample mask builds its
masked twin (the pixel shader translated to discard the masked-out pixels)
before it is recorded, and the frame waits for that compile. The precompile
never made a twin: `known-pipelines.bin` held only the title's own pipelines,
so the twin's key, which the used list (`early-pipelines.txt`) does name, had
no entry for `leonida warm --used` to make. Every twin was compiled in play,
once per translation or driver, a stall each.

The twin is now noted in the book the first time a draw asks for it, under
its own key. In its entry the pixel shader's stage number carries 0x80 and the
mask's position row (u32::MAX for none) follows the hash; reading such an
entry makes the shader's masked twin again, so the warm translates and builds
the same pipeline the draw would. Entries are length-prefixed: an older build
reading a new file refuses only the twins' entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@merzleckeier

Copy link
Copy Markdown
Contributor

The recorded masked twin rebuilt in a fresh process on both adapters. I tested 699ff016 on 1fff69129 with Wine 11.22 / VKD3D-Proton 3.1.0, using RTX 4070 SUPER (620.73.4) and Radeon RADV (26.3.1).

A synthetic graphics pipeline exercised the production host_pipeline_masked path twice with identical bound and declared render-target formats. Both arms created the plain and masked D3D12 PSOs. Main wrote one book entry. With this PR the book contained the plain entry and one masked entry (stage 0x81, row 0), sharing the same two underlying shader containers.

I applied current #2654 (f4ae7b92) to both replay arms because Wine needs the empty-library fix to save early-pipelines.txt. Both arms then saved the same masked key in the early list. With #2654 alone a fresh process found no corresponding book entry. With this PR it selected one entry and the production known::make path built that masked PSO on both adapters.

Cross-reading the books also behaved as described. The new reader made the plain entry from the older book. The older reader made the plain entry from the new book and declined only the masked entry. The three stock book tests passed. The fixture substituted DXC-compiled HLSL at the shader-translation boundary. It did not issue a draw or measure game stalls.

MEASURED with synthetic inputs, OpenAI Codex and independent raw-log verification.

@andrew-ai

Copy link
Copy Markdown

Verified on-disk compatibility across an upgrade, rollback, and second upgrade on Windows. I built separate test executables from base 1fff69129 and head 699ff0167. Five separate processes shared one temporary cache. I used synthetic vertex and pixel containers with the production note, flush, record walkers and parser.

Base wrote one plain record. The PR appended two masked records interleaved with two ordinary ones. Base reopened the same files, skipped precisely the two masked entries, and decoded each following plain record. A separate base process then appended a sixth ordinary record. When the PR reopened the book it decoded all six IDs in order, including both masks (no position row and row 3 respectively) and the ordinary record appended after rollback. All five runs also checked the shader container bytes read from disk.

This verifies record compatibility and append behavior. Driver compilation and in-game frame times were outside this check. Coordination claim. AI-assisted with OpenAI Codex (GPT-6).

@matthieupl87-spec

Copy link
Copy Markdown

Retail run of the three steps from the description, at 699ff0167, diag build via build-nvidia.ps1. The build has one local commit outside this PR, in run.rs, unrelated to pipelines.

Rig: Ryzen 5 5600X (6 cores), 32 GB DDR4-3600, RTX 5070 Ti 16 GB, driver 621.40, Windows 11 Pro 26300. Series X profile, the title's own upscaler, 16:9, story save, the same cache folder throughout.

Steps:

  1. Run 1, about 14 min in the world.
  2. Restart: the launcher's warm --used ran before the window came up (about 2 min). warm-done.txt went from 18,906 to 19,864 lines.
  3. Run 2, about 18 min, roughly the same route.

From the logs (host pipeline library saved at each run's end; masked twins counted from the host mesh pipeline shaders=[…, pixel … masked] lines):

run 1 run 2
made= (compiled in play) 247 229
loaded= 3,522 3,804
started_early= 3,290 3,495
distinct masked twins seen 206 255
  • Of run 1's 206 twins, 189 came back in run 2. In run 2, started_early grew by 205 and loaded by 282, while made did not grow (229, including 66 twins never seen in run 1). This fits the twins being built by the precompile and loaded from the library, not compiled in play.
  • The host … pipeline shaders= line is logged for loaded and compiled pipelines alike, so I could not tell twin by twin which were loaded. A log line or counter for "masked twin compiled in play" would make this check direct.

Frame pacing (frame-time log, 5 s windows): frames over 1 s: 48 in run 1, 48 in run 2. Frames over 100 ms: 369 and 871 (run 2 was longer and went through busier places). Window-title fps: median 14 in both, p90 14 and 28. This machine is CPU-bound (GPU about 20–30 % busy), so the hitches are not mainly pipeline compiles here, and these numbers neither confirm nor rule out a pacing gain.

No crash in either run; both windows were closed normally.

AI-assisted (Claude Code). Numbers from my own runs; no logs or game data attached.

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