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

@Maticcm

Maticcm commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Independent check of the public graphics ID3D12Device2::CreatePipelineState path at 19186132a49487fefdc4788317a2b103fca3ca09, against parent 06adf9b7b9b432a0d64f8442833f17e7e9f060c8. RTX 3080 desktop (10 GiB), driver 630.20, native Windows 11 build 26340, MSVC 19.50.35717 RelWithDebInfo and Vulkan SDK 1.4.363.1, Khronos validation enabled.

The unmodified d3d12_compute, d3d12_mesh, and d3d12_pipeline_stream_key CTests passed at both revisions. For a separate shared control I reused the synthetic VS and PS in d3d12_mesh_test and created three graphics PSOs through the public stream API. Two streams were identical, and a third differed only by an explicit zero sample mask. I read all three via GetCachedBlob.

  • Parent: identical streams matched, but the changed stream also returned identical bytes, failing the distinct-blob assertion.
  • Exact head: identical streams matched, and the changed mask returned a different 104-byte blob. The rest of the mesh fixture passed, with zero Vulkan validation errors.

This exercises the public graphics path with a sample-mask difference. The existing stream-key test covers depth bounds and back-face masks directly. Synthetic shaders only. AI-assisted (Codex).

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Windows 11 + RTX 3090 Verification (19186132a4 merged with main c8bf0e7b65) — PASS

  • Environment: Windows 11 (10.0.26200), MSVC 19.44.35207 (/O2 /MD /EHsc /std:c++20 /W4 /permissive- /utf-8), NVIDIA GeForce RTX 3090 (610.88) + VK_LAYER_KHRONOS_validation 1.4.363.1 (LEONIDA_VK_VALIDATION=1).
  • Merge, Docs & CTest Gates: Clean git merge-tree onto main (c8bf0e7b65) (0 conflicts); check_no_game_data.py, test_docs_env_vars.py (5/5), test_docs_table_rows.py (2/2), test_docs_encoding.py (1/1), test_ctest_registration.py (7/7), and test_ci_registration.py (18/18) all OK; 0 new /W4 warnings.
  • Red -> Green:
    • Red (#2477 d3d12_compute_test.cpp linked against main gta6rt_d3d12_com): fails with rc=1 (from_stream->GetCachedBlob / CachedPSO round-trip fails because main's public ID3D12Device2::CreatePipelineState left cache_key_ empty).
    • Green (19186132a4 + main c8bf0e7b65):
      1. d3d12_pipeline_stream_key_test.exe: rc=0 (depth bounds: on and off get different cache and order keys; off keeps the plain key, back-face stencil masks: masks unlike the front's get keys of their own; equal ones keep the plain key, depth bounds with back-face masks: a key unlike either alone, d3d12_pipeline_stream_key_test: all passed).
      2. d3d12_compute_test.exe on NVIDIA GeForce RTX 3090: rc=0, 0 VUID- validation errors (verifying byte-identical GetCachedBlob between CreateComputePipelineState and ID3D12Device2::CreatePipelineState plus CachedPSO acceptance).

AI-assisted.

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

Static audit of head 1918613. I ran no builds, tests, or GPU workloads. I traced the depth-stencil parser, the cache and prewarm keys, and Vulkan state emission. The new parser test is registered under the Windows test guard, which also covers Linux-hosted Windows cross-builds.

  • [MAJOR] runtime/shims/d3d12_vulkan_device.cpp:11741 — With LEONIDA_PIPELINE_COMPILE=on-demand, a console graphics stream gets a key for its depth bounds and separate stencil masks. First bind and prewarm both resolve it through a call that drops those fields. This disables depth bounds, skips the capability check, and gives both faces the front masks. Please forward both fields as the public stream path does and cover deferred resolution.
  • [MINOR] runtime/shims/d3d12_vulkan_device.cpp:17960 — A public graphics stream accepts a CACHED_PSO blob from an otherwise identical stream with a different back-face read mask. The parsed blob never reaches check_cached_pso. Please check it against the stream key and exercise matching and mismatched blobs through CreatePipelineState.
  • [MINOR] docs/d3d12_vulkan.md:2804 — An old order entry for a bounds-enabled stream can still prewarm an otherwise identical bounds-off PSO because that PSO retains the old key. Please clarify which PSO can still match the entry.

AI-assisted.

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Verified by OreoFR — READY

  • Base: main c8bf0e7 + this PR (head 1918613) merged with --no-ff
  • Red (main + only this PR's tests): d3d12_compute fails on main with the PR's new block (slot 67 call 2 failed with 0x80070057: the empty key of the public stream gives a different blob). d3d12_pipeline_stream_key_test does not compile on main, because pipeline_stream_keys_for_test is a hook the PR adds.
  • Green (merge): d3d12_compute and d3d12_pipeline_stream_key pass; ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p5 = main + d3d12: depth bounds and back-face stencil masks in a stream's pipeline keys (RT-STATE-PIPELINE-KEY-DS2) #2477 + rdna2spirv: a VALU data read of a lane-mask operand yields the wave's mask word #1397 (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 unchanged vs main (25 DLLs, 655 functions, no WS2_32)
  • Diff read: no issue (streams without the extra state keep their old keys).
  • 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.

8 participants