d3d12: graphics pipelines get a stable identity, logged as id= on the pipeline-compile and pipeline-use lines (RT-GRAPHICS-PREBUILD-STUDY) #2437

Open
github-bot wants to merge 3 commits from github-bot/gh-2437 into main AGit
Owner

@⁠MoonEyes on GitHub · 2026-11-27 06:59 UTC · original
MoonEyes:feat/graphics-pipeline-identity → main · +381 −80 · 6 files · 3 commits · open

What this is

Claim: RT-GRAPHICS-PREBUILD-STUDY, first step (the study only; no prebuild yet).

Depends on: none.

A graphics pipeline has no name that is the same in two runs. key= on the pipeline-compile lines is the
description the PC runtime matches a CachedPSO against, and it cannot serve:

  • it hashes the root signature, which the title builds in each run (its content, or its address for an object that
    is not ours);
  • ID3D12Device2::CreatePipelineState (the stream path, mesh pipelines) never sets it, so in one local run 279 of
    598 draw-time graphics builds were logged with key=-;
  • it has no MS or AS stage, so two mesh pipelines that differ only in the mesh shader share it where it is set.

Without a stable name a run cannot record which pipelines it drew, and a prebuild cannot resume.

What it adds

graphics_identity() (runtime/shims/d3d12_graphics_identity.h): a SHA-256 of what defines the description and
nothing of the run. It takes the decoded state blocks (blend, sample mask, rasterizer, depth and stencil, stream
output), the checksum and size of each stage's DXBC container (VS, PS, DS, HS, GS, and MS and AS), the render
target and depth formats, the sample count, and the input layout, strip cut and topology type (left out for a mesh
pipeline, which D3D12 ignores them for), plus the back face's stencil masks and the depth bounds test of a stream.
The root signature, addresses and the device are not in it. It is a pure function, with no device and no GPU.

PipelineState::create_graphics computes it. Every graphics creation path goes through it (the library
CreateGraphicsPipelineState, slot 57, and the stream CreatePipelineState, mesh included), so both paths set it.
pipeline-compile-begin, pipeline-compile and pipeline-use (draw) print id=<64 hex>; variant= is on them
(on pipeline-use too, now). A compute pipeline prints id=-. docs/d3d12_vulkan.md describes the field.

pipeline_key now takes its state from the same key_graphics_state function and hashes the same bytes
(checked against the previous function on a sample description).

How it relates to #2220 and #2260

#2220 (mine, open) records the order of first pipeline requests under order_key: GetCachedBlob's key with the
MS hash folded in. #2260 reads that log at startup. Both say the limit themselves: a root signature the runtime does
not know is hashed by its address, so that key can change between runs and the pipeline is then not found.

id= overlaps with order_key on purpose and differs in three points: the root signature is not in it at all (so
that limit does not apply), an AS stage is in it, and so are the back face's stencil masks and the depth bounds
test of a stream. It is not a cache key and replaces nothing here. This pull request does not touch the order log;
whether the log should later name pipelines by id instead is a question for #2220 and #2260, not decided here.

What it does not change

  • The driver's pipeline-cache key, GetCachedBlob, key=, the CachedPSO check: unchanged.
  • What is built, when, or how. It is observation only; the cost is one SHA-256 over about a kilobyte per graphics
    creation.
  • Compute pipelines.

Test

graphics_identity_test (CPU only, synthetic DXBC headers with invented checksums):

  • two descriptions built the same way, the same bytecode at another address, and another root signature or
    address, flags or cached blob: same identity;
  • another blend factor, write mask, sample mask, cull mode, depth bias, depth function, stencil operation,
    render target or depth format, sample count, topology, strip cut, input element, or another checksum or size of
    any stage: different identity;
  • mesh: another MS checksum, an AS, the back face's masks, the depth bounds test: different; the input layout and
    topology a description carries: ignored.

On main it does not build (no d3d12_graphics_identity.h). With the MS stage left out of the identity (what
key= does) it fails 2 checks; with the root signature put in, it fails 2 other checks. It passes with the change.
Ran with ctest next to pso_stream, native_pso_blend, native_pso_depth, native_pso_fallback,
d3d12_pso_validation, d3d12_pipeline_workers (both) and d3d12_stub_pipelines: all pass. gta6rt builds.
python -I scripts/check_no_game_data.py on the changed files: clean. No game data in the test, the code or this
text.

GPUs tested: none; this was not run on a GPU and the game was not run. The log lines were not read from a run.

Next

Not in this pull request: a graphics prebuild outside the game (gta6rt --precompile-graphics: a resumable list
of the pipelines a run drew, then a build of them through the same create_graphics and build the title uses).
This identity is the key such a list needs.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

**@⁠MoonEyes** on GitHub · 2026-11-27 06:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2437) `MoonEyes:feat/graphics-pipeline-identity` → `main` · +381 −80 · 6 files · 3 commits · open ## What this is Claim: RT-GRAPHICS-PREBUILD-STUDY, first step (the study only; no prebuild yet). Depends on: none. A graphics pipeline has no name that is the same in two runs. `key=` on the `pipeline-compile` lines is the description the PC runtime matches a `CachedPSO` against, and it cannot serve: - it hashes the root signature, which the title builds in each run (its content, or its address for an object that is not ours); - `ID3D12Device2::CreatePipelineState` (the stream path, mesh pipelines) never sets it, so in one local run 279 of 598 draw-time graphics builds were logged with `key=-`; - it has no MS or AS stage, so two mesh pipelines that differ only in the mesh shader share it where it is set. Without a stable name a run cannot record which pipelines it drew, and a prebuild cannot resume. ## What it adds `graphics_identity()` (`runtime/shims/d3d12_graphics_identity.h`): a SHA-256 of what defines the description and nothing of the run. It takes the decoded state blocks (blend, sample mask, rasterizer, depth and stencil, stream output), the checksum and size of each stage's DXBC container (VS, PS, DS, HS, GS, and MS and AS), the render target and depth formats, the sample count, and the input layout, strip cut and topology type (left out for a mesh pipeline, which D3D12 ignores them for), plus the back face's stencil masks and the depth bounds test of a stream. The root signature, addresses and the device are not in it. It is a pure function, with no device and no GPU. `PipelineState::create_graphics` computes it. Every graphics creation path goes through it (the library `CreateGraphicsPipelineState`, slot 57, and the stream `CreatePipelineState`, mesh included), so both paths set it. `pipeline-compile-begin`, `pipeline-compile` and `pipeline-use` (draw) print `id=<64 hex>`; `variant=` is on them (on `pipeline-use` too, now). A compute pipeline prints `id=-`. `docs/d3d12_vulkan.md` describes the field. `pipeline_key` now takes its state from the same `key_graphics_state` function and hashes the same bytes (checked against the previous function on a sample description). ## How it relates to #2220 and #2260 #2220 (mine, open) records the order of first pipeline requests under `order_key`: `GetCachedBlob`'s key with the MS hash folded in. #2260 reads that log at startup. Both say the limit themselves: a root signature the runtime does not know is hashed by its address, so that key can change between runs and the pipeline is then not found. `id=` overlaps with `order_key` on purpose and differs in three points: the root signature is not in it at all (so that limit does not apply), an AS stage is in it, and so are the back face's stencil masks and the depth bounds test of a stream. It is not a cache key and replaces nothing here. This pull request does not touch the order log; whether the log should later name pipelines by `id` instead is a question for #2220 and #2260, not decided here. ## What it does not change - The driver's pipeline-cache key, `GetCachedBlob`, `key=`, the `CachedPSO` check: unchanged. - What is built, when, or how. It is observation only; the cost is one SHA-256 over about a kilobyte per graphics creation. - Compute pipelines. ## Test `graphics_identity_test` (CPU only, synthetic DXBC headers with invented checksums): - two descriptions built the same way, the same bytecode at another address, and another root signature or address, flags or cached blob: same identity; - another blend factor, write mask, sample mask, cull mode, depth bias, depth function, stencil operation, render target or depth format, sample count, topology, strip cut, input element, or another checksum or size of any stage: different identity; - mesh: another MS checksum, an AS, the back face's masks, the depth bounds test: different; the input layout and topology a description carries: ignored. On `main` it does not build (no `d3d12_graphics_identity.h`). With the MS stage left out of the identity (what `key=` does) it fails 2 checks; with the root signature put in, it fails 2 other checks. It passes with the change. Ran with ctest next to `pso_stream`, `native_pso_blend`, `native_pso_depth`, `native_pso_fallback`, `d3d12_pso_validation`, `d3d12_pipeline_workers` (both) and `d3d12_stub_pipelines`: all pass. `gta6rt` builds. `python -I scripts/check_no_game_data.py` on the changed files: clean. No game data in the test, the code or this text. GPUs tested: none; this was not run on a GPU and the game was not run. The log lines were not read from a run. ## Next Not in this pull request: a graphics prebuild outside the game (`gta6rt --precompile-graphics`: a resumable list of the pipelines a run drew, then a build of them through the same `create_graphics` and `build` the title uses). This identity is the key such a list needs. AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The key= of those lines is the description the PC runtime matches a CachedPSO
against. It names the root signature, which differs from run to run, and it is
never set on the pipeline state stream path (mesh pipelines), so in one local
run 279 of 598 draw-time builds were logged with key=-. It also has no MS or AS
stage. Nothing named a graphics description the same way twice.

graphics_identity() hashes what defines the description and nothing of the
run: the decoded state blocks, the checksum and size of every stage's DXBC
container (MS and AS included), the formats, the sample count, and the input
layout, strip cut and topology type (left out for a mesh pipeline, as D3D12
reads it), plus the back face's stencil masks and the depth bounds test of a
stream. The root signature, addresses and the device are not in it.
PipelineState::create_graphics computes it, which every graphics creation path
goes through, and the pipeline-compile-begin, pipeline-compile and pipeline-use
lines print it as id= (with variant=). pipeline_key and the driver's cache key
are unchanged: pipeline_key now takes its state from the same
key_graphics_state function and hashes the same bytes.

Observation only. graphics_identity_test checks synthetic descriptions: equal
descriptions share an identity, a changed state, shader, format or mesh stage
changes it, a changed root signature or address does not.

AI-assisted: yes (Claude Code)

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The test now pins the bytes key_graphics_state feeds the cache key (computed
with the code of main before the function was shared) and the identity of the
reference description: swapping two hashed fields used to pass every check.
The docs and the header say that a root signature key can differ between runs
rather than that it does, that an AS never reaches an identity (such a
pipeline is refused first), and that a console stream prepared at bind time
builds without the back-face stencil masks and the depth bounds test, so the
same stream gets another id there.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 07:06:32 +00:00
Author
Owner

@⁠timbot103 on GitHub · 2026-11-27 10:41 UTC · original

Independently checked head 830d50203 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 build of graphics_identity_test and d3d12_m2_textured_test with zero new warnings in the PR-modified files.
  • graphics_identity_test: all passed.
  • d3d12_m2_textured_test with LEONIDA_VK_VALIDATION=1:
    • NVIDIA GeForce RTX 5080 (driver 616.64): 4096/4096 pixels matched (error 0), 0 validation errors.
    • AMD Radeon(TM) Graphics (driver 25.10.30.02): 4096/4096 pixels matched (error 0), 0 validation errors.

Code review notes:

  • Field-by-field serialization through KeyBuilder avoids struct padding leaks, float bit-patterns use memcpy, null stream-output SemanticName entries hash safely, mesh pipelines skip ignored IA/topology fields, frozen cache-key tests pin the on-disk key, and id= placement after key= keeps scripts/check_compute_journal_overlay.py matching cleanly.
  • One determinism suggestion (non-blocking for cache key): key_graphics_state currently hashes some fields that D3D12 ignores depending on enable flags — specifically BlendState.RenderTarget[1..7] when IndependentBlendEnable == FALSE, RTVFormats[i >= NumRenderTargets], LogicOp when LogicOpEnable == FALSE, and stencil masks/ops when StencilEnable == FALSE. If a title leaves ignored fields uninitialized on the stack, the same pipeline could produce different id= values across runs. Since key_graphics_state must stay frozen for pipeline_key, normalizing a local copy of the desc inside graphics_identity only (zeroing ignored fields before hashing) plus a test with garbage in ignored fields would make cross-run id= matching airtight.

Overall looks clean and well-scoped. AI-assisted.

**@⁠timbot103** on GitHub · 2026-11-27 10:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2437#issuecomment-7216181665) Independently checked head `830d50203` 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 build of `graphics_identity_test` and `d3d12_m2_textured_test` with zero new warnings in the PR-modified files. - `graphics_identity_test`: **all passed**. - `d3d12_m2_textured_test` with `LEONIDA_VK_VALIDATION=1`: - **NVIDIA GeForce RTX 5080** (driver `616.64`): **4096/4096 pixels matched (error 0)**, 0 validation errors. - **AMD Radeon(TM) Graphics** (driver `25.10.30.02`): **4096/4096 pixels matched (error 0)**, 0 validation errors. **Code review notes:** - Field-by-field serialization through `KeyBuilder` avoids struct padding leaks, float bit-patterns use `memcpy`, null stream-output `SemanticName` entries hash safely, mesh pipelines skip ignored IA/topology fields, frozen cache-key tests pin the on-disk key, and `id=` placement after `key=` keeps `scripts/check_compute_journal_overlay.py` matching cleanly. - **One determinism suggestion (non-blocking for cache key):** `key_graphics_state` currently hashes some fields that D3D12 ignores depending on enable flags — specifically `BlendState.RenderTarget[1..7]` when `IndependentBlendEnable == FALSE`, `RTVFormats[i >= NumRenderTargets]`, `LogicOp` when `LogicOpEnable == FALSE`, and stencil masks/ops when `StencilEnable == FALSE`. If a title leaves ignored fields uninitialized on the stack, the same pipeline could produce different `id=` values across runs. Since `key_graphics_state` must stay frozen for `pipeline_key`, normalizing a local copy of the desc inside `graphics_identity` only (zeroing ignored fields before hashing) plus a test with garbage in ignored fields would make cross-run `id=` matching airtight. Overall looks clean and well-scoped. AI-assisted.
This pull request has changes conflicting with the target branch.
  • runtime/shims/d3d12_vulkan_device.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2437/head:github-bot/gh-2437'
git switch 'github-bot/gh-2437'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2437'
git switch 'github-bot/gh-2437'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2437'
git switch 'github-bot/gh-2437'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2437'
git switch 'main'
git merge --squash 'github-bot/gh-2437'
git switch 'main'
git merge --ff-only 'github-bot/gh-2437'
git switch 'main'
git merge 'github-bot/gh-2437'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.