Skip to content

d3d12: depth bounds and back-face stencil masks in a stream's pipeline keys (RT-STATE-PIPELINE-KEY-DS2) - #2477

Open
Tyrannys wants to merge 3 commits into
ProjectLeonida:mainfrom
Tyrannys:claude/pipeline-key-ds2
Open

Tyrannys wants to merge 3 commits into
ProjectLeonida:mainfrom
Tyrannys:claude/pipeline-key-ds2

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-STATE-PIPELINE-KEY-DS2 (#1608 (comment)), item 5 of @kevincommits' RT-STATE-AUDIT-PIPELINE finding (#2464 Part B, #1608 (comment)). Thanks to kevincommits for finding it.

What and why

A pipeline state stream (ID3D12Device2::CreatePipelineState) can carry state that the plain D3D12_GRAPHICS_PIPELINE_STATE_DESC cannot hold: DEPTH_STENCIL1/DEPTH_STENCIL2's DepthBoundsTestEnable, and DEPTH_STENCIL2's per-face stencil masks. parse_pipeline_stream keeps them beside the description (PipelineStream::depth_bounds, back_masks/back_stencil), and create_graphics builds from them. But the keys were made from the description alone:

So two streams that differ only in the depth-bounds flag, or only in the back face's stencil masks, got the same key, and the order log and prewarm plan mixed the two pipelines up.

stream_graphics_key(stream) (runtime/shims/d3d12_vulkan_device.cpp) is now the graphics key of a stream. It folds in the depth-bounds flag, and the back face's masks when they differ from the front face's (without DEPTH_STENCIL2 the back face takes the front's, so equal masks build the same pipeline). Both the console-stream cache key and order_key use it. A stream with neither keeps exactly the key it had, which is also the key CreateGraphicsPipelineState gives the same description.

Old order logs: every key stays the same except for streams with depth bounds on, or with back-face masks unlike the front's. In an older pipeline_order.log such a pipeline is named by the plain key. That entry now simply finds nothing: the prewarm plan skips it and the pipeline is built on first use, as without a plan. Nothing misreads the log, and the next run's log has the new key. docs/d3d12_vulkan.md says so where the key is described.

Not in this PR: the other items of the finding (6: DEPTH_STENCIL2/RASTERIZER1/2 in derived-PSO overlays; 7: depth bounds without a DSV), and the plain CreatePipelineState path, which sets an order key but no cache key. That last one is unchanged here.

Tested

  • New d3d12_pipeline_stream_key (runtime/test/d3d12_pipeline_stream_key_test.cpp, through rt::d3d12::pipeline_stream_keys_for_test, parse only, no device). Synthetic streams: depth bounds on vs off; back-face masks unlike the front's (read or write) vs equal; and both at once. Each gets a cache and order key of its own. Off, or equal masks, gives the plain DEPTH_STENCIL stream's key. With the fold taken out (keys as on main) it fails with 7 failures; with it, it passes.
  • pipeline_order, pipeline_prewarm, replay_pipeline_order_hook: pass. tests/test_ci_registration.py: pass. Full runtime build (RelWithDebInfo, MSVC): clean.

GPUs tested: n/a (the new test only parses streams; the other tests are CPU-only). Build host: profile M (NVIDIA GeForce RTX 4070 SUPER, 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. (No translator change.)

🤖 Generated with Claude Code

Tyrannys and others added 2 commits November 27, 2026 10:08
…e keys

A pipeline state stream carries DEPTH_STENCIL1/2's depth-bounds flag and
DEPTH_STENCIL2's back-face stencil masks beside the graphics description, and
create_graphics builds from them, but the console-stream cache key and
order_key (pipeline_order.log, the prewarm plan) hashed the description
alone. Two streams that differ only there shared a key.

stream_graphics_key folds them in where they change the pipeline (back masks
only when unlike the front's); a stream without them keeps its old key, so
older order logs only miss the changed entries. New
d3d12_pipeline_stream_key test.

RT-STATE-PIPELINE-KEY-DS2, item 5 of kevincommits' RT-STATE-AUDIT-PIPELINE
finding.

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

Copy link
Copy Markdown
Contributor

Independent Linux/Wine + NVIDIA check at head 06adf9b7b (merged cleanly onto origin/main c0201a806 alongside #2480, #2478, #2476, #2474).

  • Environment: Linux 7.2.15, wine-11.22, clang-cl + xwin cross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Ryzen 7 5800X, 32 GB RAM. No game files.
  • CTest: d3d12_pipeline_stream_key passed (4.43 s) under Wine.

AI-assisted.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Tested for #2464 as Aslanek asked: unit tests and a game run on my machine; CI ignored for now as asked.

RUN pr2477-court | 2026-11-27 | MoonEyes | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        main ec91d695c + PR #2477 (head 06adf9b7b), merged locally without conflict, nothing pushed | shaders: main's own translation
MACHINE:     RTX 4060 8 GB, desktop, only GPU, display attached | NVIDIA 610.88 | Windows 11 Pro 26300 | Ryzen 5 3600 | 32 GB | Windows GPU timeout at the default (2 s)
RECIPE:      short recipe: docs/running.md Windows NVIDIA recipe, pipeline cache warm, 330 s cap, scripted button presses from 60 s | build RelWithDebInfo, only the PR's targets built
TESTS:
  - d3d12_pipeline_stream_key_test (new, ctest d3d12_pipeline_stream_key): pass on the PR | fails on main: does not compile on main (it uses a new test hook that main lacks)
  - d3d12_title_va_test (14 ctest variants, touched by the PR): 14/14 pass on the PR | fails on main: no (14/14 also pass on main with the PR's test file, so this test does not discriminate)
GAME:        session=1 at 125 s | world entered at 175 s | last window >= 1 img/s ends at 251 s | 0 frames after world entry + 240 s | end: stopped by my local stall guard at 251 s (no new frame line for 180 s), not by the cap | device loss: no (no fault report) | private RAM max 17169 MB
COMPARED TO: w77 (main ec91d695c, same short recipe): session=1 at 145 s, world at 195 s, last window >= 1 img/s at 293 s, private RAM max 16043 MB, ended by the time limit (337 s)
             w79 (main, same short recipe): world at 200 s, last window >= 1 img/s at 286 s, private RAM max 16583 MB, ended by the time limit (350 s)
             one run each (n=1); on main the spread of world entry on this recipe is about 165 to 200 s, so no conclusion on timings
VERDICT:     new test passes and cannot compile on main; title_va test does not discriminate; game reached the world, stopped by the stall guard, no device loss; inconclusive for the game (n=1)

Reading (marked):

  • MEASURED: the display stops after the world is entered (76 s after world entry for the last window >= 1 img/s here; 98 s on w77, 86 s on w79). Present on main too, not caused by this PR (finding Coordinating who works on what (continued from #14) #1608 (comment)).
  • MEASURED: the run was ended by my local stall guard, not by a crash or a device loss. A stall guard end is not comparable with the time-limit end of the main runs; compare the last-window figure, not the end time. I do not attribute the stop to this PR.
  • The game logs of this run were deleted by a disk cleanup before this write-up; the figures above were extracted before that and cannot be re-checked from the logs now.

Limits: one machine, one run for the PR, one run for each main witness.

AI-assisted (Claude Code, Claude Opus 5.5)

@timbot103

Copy link
Copy Markdown
Contributor

Reviewed at head 06adf9b7b on Windows 11 (MSVC 2022 19.44).

Verification

  • Built d3d12_pipeline_stream_key_test and gta6rt.
  • d3d12_pipeline_stream_key_test: passed.

Finding (Request changes)

  • Public Device::CreatePipelineState never assigns cache_key_ (d3d12_vulkan_device.cpp:17953-17966 vs. 15714-15723; cached_pso.h:59-72):
    The hash payload construction itself (d3d12_vulkan_device.cpp:10914-10935) cleanly distinguishes depth-bounds enable and back-face stencil masks while keeping plain graphics keys unchanged. However, Device::CreatePipelineState (17955-17966) sets order_key when logging/prewarming is active and calls create_graphics(...), but never calls pipeline->set_cache_key(...) (only prepare_console_stream does). As a result, PSOs created through the public ID3D12Device2::CreatePipelineState stream API still emit an empty cache_key_ (64 identical zero bytes in GetCachedBlob) regardless of depth-bounds or back-face stencil mask differences; d3d12_pipeline_stream_key_test calls the hashing helper directly so it didn't catch the missing call site. Assigning cache_key_ in Device::CreatePipelineState (and adding a test through CreatePipelineState -> GetCachedBlob) closes this gap.

AI-assisted review + local MSVC verification.

timbot103's review of ProjectLeonida#2477: the public stream path made its PSO without
set_cache_key, so GetCachedBlob gave an empty key for every stream PSO
(the stream key test calls the key helper directly and did not see it).
CreatePipelineState now sets the same key prepare_console_stream sets:
pipeline_key for a compute stream, stream_graphics_key (with the depth
bounds flag and back-face stencil masks) for a graphics or mesh one.

d3d12_compute_test: a compute PSO made through CreatePipelineState gives
the same GetCachedBlob bytes as the one CreateComputePipelineState makes
from the same root signature and CS, and that blob is accepted back as
CachedPSO. It fails without the fix.

AI-assisted (Claude Code).

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

Copy link
Copy Markdown
Contributor Author

@timbot103 thanks, you were right: the public ID3D12Device2::CreatePipelineState never called set_cache_key, so every PSO from a stream had an empty key in GetCachedBlob. Fixed in 19186132a.

  • Fix: CreatePipelineState now sets the same key that prepare_console_stream sets:
    • a compute stream gets pipeline_key(stream.compute);
    • a graphics or mesh stream gets stream_graphics_key(stream), which includes the depth-bounds flag and the back-face stencil masks.
  • Test: d3d12_compute_test makes a compute PSO through CreatePipelineState (root signature + CS stream). Its GetCachedBlob bytes must equal those of the PSO CreateComputePipelineState makes from the same root signature and CS, and the blob must be accepted back as CachedPSO. The test goes through the real device on the GPU.
  • Results on profile M (RTX 4070 SUPER, NVIDIA 621.01, Windows 11, MSVC RelWithDebInfo):
    • With the new line removed, d3d12_compute fails.
    • With the fix it passes, 3 of 3 runs.
    • ctest -R "d3d12_pipeline|d3d12_title_va|cached_pso|d3d12_compute" passes 9/9.
    • gta6rt builds.
  • Not covered: a graphics stream through the public API. That needs a real VS on the device. Graphics streams use the same stream_graphics_key that d3d12_pipeline_stream_key_test checks directly.

No game files used. AI-assisted (Claude Code).

whoalin1 added a commit to whoalin1/leonida-continued that referenced this pull request Nov 28, 2026
…k oracle (TEST-545)

tests/semantic/test_valu_div_fixup.py compared a hand-written Python model of the
fixup against itself and never imported tools/rdna2spirv.py, so it passed whatever
the translator did, and its rules had drifted from native RDNA2 (gfx1036) on six
points (NaN priority, the sign of 0/0 and inf/inf, inf(S2), the copysign of the
pass-through, NaN(S0), and the exponent-difference cutoff).

It now translates hand-written listings and asserts what the translator emits: the
pure-integer lowering's op order and classification constants, NaN(S2) above
NaN(S1) read off the dataflow, one word per measured rule through
spirv_mini_interp, and the EXEC-masked and null-destination cases. The f16 model
is gone rather than ported: the translator has no v_div_fixup_f16 lowering yet
(ProjectLeonida#2477 adds it with its own translator tests).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

@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 and verified at head 19186132a (Windows 11, MSVC 19.44, Ninja Release, LEONIDA_VK_VALIDATION=1).

Verification

  • Built d3d12_pipeline_stream_key_test, d3d12_compute_test, and gta6rt.
  • ctest -R "^(d3d12_pipeline_stream_key|d3d12_compute)$" (LEONIDA_VK_VALIDATION=1): 2/2 passed (0 validation errors).
  • python -I scripts/check_no_game_data.py: clean.

Review notes

  • stream_graphics_key preserves exact key compatibility when neither depth bounds nor differing back-face stencil masks are present, and folds both fields cleanly into both cache (GetCachedBlob) and pipeline_order.log keys when active.
  • ID3D12Device2::CreatePipelineState now sets the same cache key as prepare_console_stream and the description paths, and the new d3d12_compute_test round-trip verifies byte-identical GetCachedBlob output accepted back via CachedPSO.

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.

5 participants