startup: cache translated graphics pipelines #1634

Closed
lambirou wants to merge 3 commits from upstream-pr/1641 into main
lambirou commented 2026-11-24 15:34:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T15:34:43Z.


Problem

The translated startup draw path creates a desktop graphics PSO on every run and keeps only an in-process map. A cold run pays the driver's pipeline compile again, and the existing X2W_SHADER_CACHE covers translated shader bytecode but not the driver's pipeline blobs.

XCL's public CachedPSO work (xcl shaders --precompile --pipelines) shows the shape, but this implementation is independent and uses the desktop ID3D12PipelineLibrary API.

Change

  • Add src/startup_stubs/graphics_pipeline_cache.h: an optional ID3D12PipelineLibrary cache under X2W_SHADER_CACHE\pso_<adapter>.lib.
  • Key each library entry by the translation revision, target formats, DSV, the title's blend/depth state and the translated VS/PS bytes, plus an adapter/driver identity. Blend and depth are hashed field by field, so ABI padding cannot change the cache name. The file has a versioned header and checksum.
  • Locate the adapter through ID3D12Device::GetAdapterLuid and IDXGIFactory4::EnumAdapterByLuid; hash vendor, device, subsystem, revision and the UMD version. The LUID is not hashed because it can change across boots, but it is a fallback when no DXGI adapter is found.
  • Wire pipeline_for to try LoadGraphicsPipeline first and fall back to CreateGraphicsPipelineState on a miss, corrupt/truncated blob, driver/adapter mismatch or missing ID3D12PipelineLibrary. A cache failure never fails a draw.
  • Coalesce persistence: a successful store marks the library dirty. Flush() at the end of each presented frame, outside draw_lock, serializes it once; destruction is the fallback. A version/adapter mismatch drops the old file and starts an empty library.
  • Add a source-built WARP test covering cold store, warm hit in a fresh library, corrupt blob, disabled interface and concurrent cache calls. The key control mutates every blend/depth field (22 blend, 14 depth) and requires a different hash, while a padding-only change keeps it identical. The test also prints the adapter identity, compares a cold-created and a warm-loaded pixel, and reports an eight-PSO batch. Register startup_pso_cache and document the behavior.

Safety note: ID3D12Device1::CreatePipelineLibrary does not copy the input blob; it keeps the pointer for the library's lifetime. The helper retains the file buffer until DropLibrary/Shutdown. Any future change must preserve that ownership rule.

Review response

  • The key now includes the translated VS and PS bytes through Translation::code_key, so a translator output change cannot reuse an old driver pipeline under the same name. The key schema is bumped to 3.
  • Persistence has an explicit safe point: queue_present calls flush_pipeline_cache() outside draw_lock. A frame with new stores writes the library once; the destructor remains a fallback.
  • The adapter identity is no longer the constant seed. On WARP the test prints adapter identity 3d82a583644e40a1; the value is derived from the device LUID's DXGI adapter and its UMD version. If no adapter is found, the LUID itself is hashed.
  • StorePipeline returning E_INVALIDARG is counted as a duplicate, not a new store, and no longer marks the library dirty.
  • Target formats now go through the same FNV update as the other fields instead of the key * 131 mix.
  • The device-free control now pins translated_code_key and pipeline_key: two translations with the same title key but different VS/PS bytes must produce different pipeline names.
  • The cache pointer is now a shared_ptr protected by a mutex, so a present-thread Flush() keeps the old cache alive if the draw thread replaces it after a device change.
  • The WARP batch of eight distinct trivial PSOs reported about 2.9 ms uncached, 2.5 ms cached cold (1.4 ms flush) and 0.9 ms warm in the last run. Timings vary; the batch is diagnostic and does not establish a title speedup.
  • The cached and uncached pipelines both render 0xff4080ff and their readbacks match.

Verification

. .\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev --target startup_pso_cache_check d3d12_xs_shim
ctest --preset dev --no-tests=error -R '^startup_pso_cache$' -V
python -B tests/docs_links_check.py
git diff --check

Result: startup_pso_cache ok (library WARP); 1/1 passed. The batch line is PSO batch 8: uncached 2.87 ms, cached cold 2.52 ms (flush 1.35 ms), warm 0.88 ms. The padding control passes, the 36 semantic mutations pass, the adapter identity is not the seed, and the cold and warm pixels both read ff4080ff. Five repeated CTest runs passed. docs_links_check.py checked 18 Markdown files and 393 links; git diff --check is clean.

Rebased onto origin/main (05092b6e); head 591f556e. Windows checks pass on this head.

Not tested

  • A physical GPU. The test is WARP only; the driver/library path is the remaining hardware variable.
  • A retail title workload. The eight-PSO WARP batch is diagnostic; the cache is opt-in through X2W_SHADER_CACHE and is not claimed as a speedup at title scale.
  • ID3D12PipelineLibrary on older drivers; an unsupported interface disables the cache and uses the direct path.
  • An abrupt process exit before the next present. The destructor fallback may not run, so that run's new library entries are not persisted.

Reference: ivall/xcl@930e8b4 (xcl shaders --precompile --pipelines, #744), observed 2026-11-24. Public specification used: Microsoft ID3D12PipelineLibrary and D3D12_CACHED_PIPELINE_STATE. Independent implementation: the files above. No XCL code or tables are included.

Licence

MIT, as the rest of the repository. The cache uses only the public Microsoft D3D12 API and contains no XCL code, tables, game files or third-party binaries.

AI use: implementation and first verification were drafted by a Codex subagent; the orchestrator reviewed the diff, rebased it, reran the build/CTest and five direct test runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5475272188 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T15:34:43Z. --- ## Problem The translated startup draw path creates a desktop graphics PSO on every run and keeps only an in-process map. A cold run pays the driver's pipeline compile again, and the existing `X2W_SHADER_CACHE` covers translated shader bytecode but not the driver's pipeline blobs. XCL's public `CachedPSO` work (`xcl shaders --precompile --pipelines`) shows the shape, but this implementation is independent and uses the desktop `ID3D12PipelineLibrary` API. ## Change - Add `src/startup_stubs/graphics_pipeline_cache.h`: an optional `ID3D12PipelineLibrary` cache under `X2W_SHADER_CACHE\pso_<adapter>.lib`. - Key each library entry by the translation revision, target formats, DSV, the title's blend/depth state and the translated VS/PS bytes, plus an adapter/driver identity. Blend and depth are hashed field by field, so ABI padding cannot change the cache name. The file has a versioned header and checksum. - Locate the adapter through `ID3D12Device::GetAdapterLuid` and `IDXGIFactory4::EnumAdapterByLuid`; hash vendor, device, subsystem, revision and the UMD version. The LUID is not hashed because it can change across boots, but it is a fallback when no DXGI adapter is found. - Wire `pipeline_for` to try `LoadGraphicsPipeline` first and fall back to `CreateGraphicsPipelineState` on a miss, corrupt/truncated blob, driver/adapter mismatch or missing `ID3D12PipelineLibrary`. A cache failure never fails a draw. - Coalesce persistence: a successful store marks the library dirty. `Flush()` at the end of each presented frame, outside `draw_lock`, serializes it once; destruction is the fallback. A version/adapter mismatch drops the old file and starts an empty library. - Add a source-built WARP test covering cold store, warm hit in a fresh library, corrupt blob, disabled interface and concurrent cache calls. The key control mutates every blend/depth field (22 blend, 14 depth) and requires a different hash, while a padding-only change keeps it identical. The test also prints the adapter identity, compares a cold-created and a warm-loaded pixel, and reports an eight-PSO batch. Register `startup_pso_cache` and document the behavior. **Safety note:** `ID3D12Device1::CreatePipelineLibrary` does not copy the input blob; it keeps the pointer for the library's lifetime. The helper retains the file buffer until `DropLibrary`/`Shutdown`. Any future change must preserve that ownership rule. ## Review response - The key now includes the translated VS and PS bytes through `Translation::code_key`, so a translator output change cannot reuse an old driver pipeline under the same name. The key schema is bumped to 3. - Persistence has an explicit safe point: `queue_present` calls `flush_pipeline_cache()` outside `draw_lock`. A frame with new stores writes the library once; the destructor remains a fallback. - The adapter identity is no longer the constant seed. On WARP the test prints `adapter identity 3d82a583644e40a1`; the value is derived from the device LUID's DXGI adapter and its UMD version. If no adapter is found, the LUID itself is hashed. - `StorePipeline` returning `E_INVALIDARG` is counted as a duplicate, not a new store, and no longer marks the library dirty. - Target formats now go through the same FNV update as the other fields instead of the `key * 131` mix. - The device-free control now pins `translated_code_key` and `pipeline_key`: two translations with the same title key but different VS/PS bytes must produce different pipeline names. - The cache pointer is now a `shared_ptr` protected by a mutex, so a present-thread `Flush()` keeps the old cache alive if the draw thread replaces it after a device change. - The WARP batch of eight distinct trivial PSOs reported about 2.9 ms uncached, 2.5 ms cached cold (1.4 ms flush) and 0.9 ms warm in the last run. Timings vary; the batch is diagnostic and does not establish a title speedup. - The cached and uncached pipelines both render `0xff4080ff` and their readbacks match. ## Verification ```powershell . .\tools\dev.ps1 cmake --preset dev cmake --build --preset dev --target startup_pso_cache_check d3d12_xs_shim ctest --preset dev --no-tests=error -R '^startup_pso_cache$' -V python -B tests/docs_links_check.py git diff --check ``` Result: `startup_pso_cache ok (library WARP)`; 1/1 passed. The batch line is `PSO batch 8: uncached 2.87 ms, cached cold 2.52 ms (flush 1.35 ms), warm 0.88 ms`. The padding control passes, the 36 semantic mutations pass, the adapter identity is not the seed, and the cold and warm pixels both read `ff4080ff`. Five repeated CTest runs passed. `docs_links_check.py` checked 18 Markdown files and 393 links; `git diff --check` is clean. Rebased onto `origin/main` (`05092b6e`); head `591f556e`. Windows checks pass on this head. ## Not tested - A physical GPU. The test is WARP only; the driver/library path is the remaining hardware variable. - A retail title workload. The eight-PSO WARP batch is diagnostic; the cache is opt-in through `X2W_SHADER_CACHE` and is not claimed as a speedup at title scale. - `ID3D12PipelineLibrary` on older drivers; an unsupported interface disables the cache and uses the direct path. - An abrupt process exit before the next present. The destructor fallback may not run, so that run's new library entries are not persisted. Reference: `ivall/xcl@930e8b4` (`xcl shaders --precompile --pipelines`, #744), observed 2026-11-24. Public specification used: Microsoft `ID3D12PipelineLibrary` and `D3D12_CACHED_PIPELINE_STATE`. Independent implementation: the files above. No XCL code or tables are included. ## Licence MIT, as the rest of the repository. The cache uses only the public Microsoft D3D12 API and contains no XCL code, tables, game files or third-party binaries. AI use: implementation and first verification were drafted by a Codex subagent; the orchestrator reviewed the diff, rebased it, reran the build/CTest and five direct test runs.
tedin7 commented 2026-11-24 15:47:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:47:41Z.

Review: COMMENTED


Reviewed 46a0816df2a957bc23c9fac36fb79fe36cc3f68e:

  • Implementation & safety:
    • src/startup_stubs/graphics_pipeline_cache.h: OpenLibrary retains blob_ for the lifetime of ID3D12PipelineLibrary and DropLibrary releases library_ before freeing blob_, respecting the CreatePipelineLibrary pointer-lifetime contract. Header validation checks magic ("XSP1"), version, header size, adapter/driver identity (vendor, device, subsys, revision, UMD version), bounded payload size (<= 256 MiB), and FNV-1a checksum; any mismatch or D3D12_ERROR_DRIVER_VERSION_MISMATCH / D3D12_ERROR_ADAPTER_NOT_FOUND drops the file and falls back cleanly to CreateGraphicsPipelineState.
    • src/startup_stubs/d3d12_draw.inl: pipeline_for folds tr.key (including translator revision), target_count, target_formats[], dsv_format, has_blend/blend, and has_depth_stencil/depth_stencil into the lookup key, and resets pipeline_cache_for if the ID3D12Device* changes.
    • tests/startup_pso_cache_check.cpp: covers cold store + file creation, warm hit in a fresh GraphicsPipelineCache instance, truncated/corrupt blob recovery, disabled-library fallback, and 4-thread concurrent creation/lookup on WARP.
  • Minor note: pipeline_cache_for in src/startup_stubs/d3d12_draw.inl uses unsynchronized function-local static variables (cache, owner), though pipeline_for itself already accesses bound.pipelines without locking (single-threaded draw path); GraphicsPipelineCache itself is SRWLOCK-synchronized.
  • Linux repo hygiene (executed locally):
    • python3 tests/docs_links_check.py — passed (Checked 16 Markdown files and 348 links.)
    • python3 tests/bidi_controls_check.py — passed (Checked 1267 tracked source, script and build/CI files: no bidirectional controls.)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) (executed locally):
    • Debug (cmake --build --preset dev --target startup_pso_cache_check d3d12_xs_shim -- -j 6 + ctest --preset dev -R '^startup_pso_cache$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed.
    • Release /O2 (cmake --build --preset release --target startup_pso_cache_check d3d12_xs_shim -- -j 6 + ctest --preset release -R '^startup_pso_cache$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042570333 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#pullrequestreview-6042570333). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:47:41Z. **Review:** COMMENTED --- Reviewed `46a0816df2a957bc23c9fac36fb79fe36cc3f68e`: - **Implementation & safety**: - `src/startup_stubs/graphics_pipeline_cache.h`: `OpenLibrary` retains `blob_` for the lifetime of `ID3D12PipelineLibrary` and `DropLibrary` releases `library_` before freeing `blob_`, respecting the `CreatePipelineLibrary` pointer-lifetime contract. Header validation checks magic (`"XSP1"`), version, header size, adapter/driver identity (vendor, device, subsys, revision, UMD version), bounded payload size (`<= 256 MiB`), and FNV-1a checksum; any mismatch or `D3D12_ERROR_DRIVER_VERSION_MISMATCH` / `D3D12_ERROR_ADAPTER_NOT_FOUND` drops the file and falls back cleanly to `CreateGraphicsPipelineState`. - `src/startup_stubs/d3d12_draw.inl`: `pipeline_for` folds `tr.key` (including translator revision), `target_count`, `target_formats[]`, `dsv_format`, `has_blend`/`blend`, and `has_depth_stencil`/`depth_stencil` into the lookup key, and resets `pipeline_cache_for` if the `ID3D12Device*` changes. - `tests/startup_pso_cache_check.cpp`: covers cold store + file creation, warm hit in a fresh `GraphicsPipelineCache` instance, truncated/corrupt blob recovery, disabled-library fallback, and 4-thread concurrent creation/lookup on WARP. - **Minor note**: `pipeline_cache_for` in `src/startup_stubs/d3d12_draw.inl` uses unsynchronized function-local `static` variables (`cache`, `owner`), though `pipeline_for` itself already accesses `bound.pipelines` without locking (single-threaded draw path); `GraphicsPipelineCache` itself is `SRWLOCK`-synchronized. - **Linux repo hygiene** (executed locally): - `python3 tests/docs_links_check.py` — passed (`Checked 16 Markdown files and 348 links.`) - `python3 tests/bidi_controls_check.py` — passed (`Checked 1267 tracked source, script and build/CI files: no bidirectional controls.`) - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)** (executed locally): - Debug (`cmake --build --preset dev --target startup_pso_cache_check d3d12_xs_shim -- -j 6` + `ctest --preset dev -R '^startup_pso_cache$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed**. - Release `/O2` (`cmake --build --preset release --target startup_pso_cache_check d3d12_xs_shim -- -j 6` + `ctest --preset release -R '^startup_pso_cache$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed**. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 17:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T16:26:46Z.


The cache helper covers warm lookup and fallback. In the production path, a cold miss currently serializes and flushes the entire pipeline library while draw_lock is held. Please measure cold-path serialization separately from warm hits on a source-built batch of several distinct PSOs, and include a cached/uncached pixel comparison. If the cold overhead is significant, coalesce persistence or keep disk persistence opt-in while gathering that comparison.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7137677576 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7137677576). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T16:26:46Z. --- The cache helper covers warm lookup and fallback. In the production path, a cold miss currently serializes and flushes the entire pipeline library while draw_lock is held. Please measure cold-path serialization separately from warm hits on a source-built batch of several distinct PSOs, and include a cached/uncached pixel comparison. If the cold overhead is significant, coalesce persistence or keep disk persistence opt-in while gathering that comparison.
tedin7 commented 2026-11-24 17:18:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:18:13Z.

Review: COMMENTED


Re-review at head_sha: 9998541ce47e192cab5fda6862ebc9f309147ca2 (previously reviewed at 46a0816d).

Findings

P2 (test gap): the new key-hash control cannot detect a field being left out of the key (tests/startup_pso_cache_check.cpp, hash_padding_ignored)

  • What changed since the last review: the pipeline key no longer hashes the raw D3D12_BLEND_DESC / D3D12_DEPTH_STENCIL_DESC bytes (ABI padding could be uninitialized and give different cache names across runs). hash_blend_key and hash_depth_stencil_key now hash the semantic fields one by one, the key schema goes from 1 to 2, and a padding control was added. That design is right, and today the functions do cover every field of both structs (I counted against d3d12.h: 2 + 10 x 8 blend fields, and 6 + 4 + 4 depth/stencil fields).
  • The gap: the only semantic differences the control exercises are RenderTarget[0].SrcBlend and FrontFace.StencilFunc. Hand-written hashing like this is exactly where a field gets dropped later, and then two different blend or depth states map to the same cached pipeline, i.e. a wrong pipeline is reused silently.
  • Reproduced (Linux, MinGW-w64 + Wine, see limits): extracted hash_padding_ignored and the two static_asserts into a small program that includes the unchanged graphics_pipeline_cache.h. Unmodified: PASS. With return hash_stencil_ops_key(depth.BackFace, key); replaced by return key;: still PASS. With the RenderTargetWriteMask line removed from hash_blend_key: still PASS. Expected: FAIL for both.
  • Suggested fix: change one field at a time from a base value and require the key to change. I wrote that locally (base blend/depth desc, 36 single-field changes: both blend flags, all 10 per-target fields on targets 0 and 7, all 6 depth fields, all 4 ops fields on front and back). On the PR's code: 36 cases, 0 unchanged. With BackFace dropped: 4 unchanged, fails. With the write mask dropped: 2 unchanged, fails. Keep the padding half of the existing control as it is.

Other changes in the new commit, no issue

  • The blend and depth keys now go through hash_blend_key / hash_depth_stencil_key (using declarations in d3d12_draw.inl), the has_blend / has_depth_stencil bits are still folded in, and the schema byte is bumped so old key names are not reused.
  • The two static_asserts document the padding the control relies on. They hold for the MinGW-w64 layout I built with; I did not check the MSVC layout, but the same ABI padding is what the PR text describes.
  • git merge-tree against current main (bc65bb1b) reports no conflicts (tree a0fc9b67).

Verified

Limits: Linux x86-64 only. startup_pso_cache_check needs a D3D12 device (WARP), so I did not run the whole test or the pipeline-library parts (cold store, warm hit, corrupt blob, concurrency). I only ran the device-free hash control, cross-built with x86_64-w64-mingw32-g++ -std=c++17 -O1 -static and run under Wine, not MSVC.

  • Unmodified: hash_padding_ignored: PASS.
  • Mutation (raw bytes): in hash_blend_key, the per-field hashing of BlendEnable replaced by hashing the whole target struct (padding included): hash_padding_ignored: FAIL. So the padding half of the control works.
  • Mutations that escape: BackFace dropped, and RenderTargetWriteMask dropped, as above.
  • All edits were made in the PR worktree and reverted with git checkout -- .; git status --short clean.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044028072 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#pullrequestreview-6044028072). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:18:13Z. **Review:** COMMENTED --- Re-review at `head_sha`: `9998541ce47e192cab5fda6862ebc9f309147ca2` (previously reviewed at `46a0816d`). ### Findings **P2 (test gap): the new key-hash control cannot detect a field being left out of the key** (`tests/startup_pso_cache_check.cpp`, `hash_padding_ignored`) - What changed since the last review: the pipeline key no longer hashes the raw `D3D12_BLEND_DESC` / `D3D12_DEPTH_STENCIL_DESC` bytes (ABI padding could be uninitialized and give different cache names across runs). `hash_blend_key` and `hash_depth_stencil_key` now hash the semantic fields one by one, the key schema goes from 1 to 2, and a padding control was added. That design is right, and today the functions do cover every field of both structs (I counted against `d3d12.h`: 2 + 10 x 8 blend fields, and 6 + 4 + 4 depth/stencil fields). - The gap: the only semantic differences the control exercises are `RenderTarget[0].SrcBlend` and `FrontFace.StencilFunc`. Hand-written hashing like this is exactly where a field gets dropped later, and then two different blend or depth states map to the same cached pipeline, i.e. a wrong pipeline is reused silently. - Reproduced (Linux, MinGW-w64 + Wine, see limits): extracted `hash_padding_ignored` and the two `static_assert`s into a small program that includes the unchanged `graphics_pipeline_cache.h`. Unmodified: PASS. With `return hash_stencil_ops_key(depth.BackFace, key);` replaced by `return key;`: still PASS. With the `RenderTargetWriteMask` line removed from `hash_blend_key`: still PASS. Expected: FAIL for both. - Suggested fix: change one field at a time from a base value and require the key to change. I wrote that locally (base blend/depth desc, 36 single-field changes: both blend flags, all 10 per-target fields on targets 0 and 7, all 6 depth fields, all 4 ops fields on front and back). On the PR's code: 36 cases, 0 unchanged. With BackFace dropped: 4 unchanged, fails. With the write mask dropped: 2 unchanged, fails. Keep the padding half of the existing control as it is. ### Other changes in the new commit, no issue - The blend and depth keys now go through `hash_blend_key` / `hash_depth_stencil_key` (`using` declarations in `d3d12_draw.inl`), the `has_blend` / `has_depth_stencil` bits are still folded in, and the schema byte is bumped so old key names are not reused. - The two `static_assert`s document the padding the control relies on. They hold for the MinGW-w64 layout I built with; I did not check the MSVC layout, but the same ABI padding is what the PR text describes. - `git merge-tree` against current `main` (`bc65bb1b`) reports no conflicts (tree `a0fc9b67`). ### Verified Limits: Linux x86-64 only. `startup_pso_cache_check` needs a D3D12 device (WARP), so I did not run the whole test or the pipeline-library parts (cold store, warm hit, corrupt blob, concurrency). I only ran the device-free hash control, cross-built with `x86_64-w64-mingw32-g++ -std=c++17 -O1 -static` and run under Wine, not MSVC. - Unmodified: `hash_padding_ignored: PASS`. - **Mutation (raw bytes):** in `hash_blend_key`, the per-field hashing of `BlendEnable` replaced by hashing the whole `target` struct (padding included): `hash_padding_ignored: FAIL`. So the padding half of the control works. - **Mutations that escape:** BackFace dropped, and `RenderTargetWriteMask` dropped, as above. - All edits were made in the PR worktree and reverted with `git checkout -- .`; `git status --short` clean. AI-assisted; commands listed were executed locally.
lambirou commented 2026-11-24 19:01:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T18:45:36Z.


@R0Y00 Ready for maintainer review.

Rebased onto origin/main (578d1e1c); head 9998541c; Windows checks pass.

The WARP test passes cold, warm, corrupt, disabled and concurrent cases. The key now hashes blend/depth fields rather than raw structures, so ABI padding cannot change the cache name. Physical-GPU and warm-vs-cold load-time measurements remain untested. No game data.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141112243 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7141112243). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T18:45:36Z. --- @R0Y00 Ready for maintainer review. Rebased onto `origin/main` (`578d1e1c`); head `9998541c`; Windows checks pass. The WARP test passes cold, warm, corrupt, disabled and concurrent cases. The key now hashes blend/depth fields rather than raw structures, so ABI padding cannot change the cache name. Physical-GPU and warm-vs-cold load-time measurements remain untested. No game data.
tedin7 commented 2026-11-24 19:22:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:22:13Z.

Review: COMMENTED


Review at a71f8fc5f6a8aa83d6d3faf618d3a451a7579878 (comment only, not an approval).

What I checked

  • Read the full diff against origin/main (d3d12_draw.inl, graphics_pipeline_cache.h, the test, CMake, docs).
  • Cache key: translation key (title shader words + root signature blob + a revision string), output formats, DSV format, blend and depth-stencil. Blend and depth are hashed field by field, so ABI padding cannot change the name.
  • COM lifetime: the library is released before the blob it was created from, the cache holds a device reference, and a failed load or create returns a usable pipeline.

Commands run on this branch (Linux)

  • x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only on graphics_pipeline_cache.h: compiles.
  • A small program (mingw build, run under wine) calls hash_blend_key and hash_depth_stencil_key: 12 checks pass. Padding bytes set to 0xAA versus 0 give the same key. Flipping AlphaToCoverage, IndependentBlend, RT7 LogicOp, RT3 write mask, RT0 BlendOpAlpha, RT1 DestBlendAlpha, DepthFunc, StencilWriteMask, BackFace func or FrontFace depth-fail op each changes it.
  • Two real mutations of the header, each caught by that program (then restored): dropping LogicOp from the blend hash, and dropping BackFace from the depth hash.
  • Not run: startup_pso_cache_check and anything D3D12. The Windows runner (x2w_pipe.py win2025) was blocked by a local command guard in this session, so there is no Windows result from me. I did not run the WARP test.

P2: the key does not cover the translated bytecode

d3d12_draw.inl:436-446. tr.key is a hash of the title's shader words and root signature plus the string x2w-startup-shader-4 (d3d12_draw.inl:201). The desktop VS and PS (tr.vs, tr.ps, line 451) come from gfx2hlsl.py and DXC, and are not in the key. If the translator output changes and nobody bumps that string, the library can hold a pipeline built from the old bytecode under the same name. I could not confirm whether LoadGraphicsPipeline rejects a description whose shaders differ; the documentation I know does not promise it. Hashing tr.vs and tr.ps bytes into the key is cheap and removes the dependency on a manual bump.

P2: the library is persisted only at process shutdown

Flush() (graphics_pipeline_cache.h:208) is called only from the test. In the product the only write is PersistLibrary() from Shutdown(), reached by the destructor of the function-static unique_ptr (d3d12_draw.inl:415). That runs at process or DLL teardown, where D3D12 may already be unloaded, and not at all if the title ends the process abruptly. In both cases the cache file never appears and the feature does nothing, while the doc says stores are coalesced and flushed. Suggest an explicit flush at a safe point (device release or a frame or time threshold).

Related: the cache holds a device reference from a static (graphics_pipeline_cache.h:178), so the device outlives the title's own release until teardown.

P2: adapter and driver identity is probably the constant seed

graphics_pipeline_cache.h:85. adapter_identity queries IDXGIDevice on an ID3D12Device. As far as I know a D3D12 device does not implement IDXGIDevice, so the query fails and the hash stays at the seed x2w-pso-cache-v1 for every GPU and driver. Safety still holds, because CreatePipelineLibrary rejects a foreign blob and the code deletes it and starts empty. But the docs and comments promise vendor, device, revision and UMD identity in the file name and header. I could not run this here; please confirm on the Windows node, for example by printing the identity for WARP and a hardware adapter. If it is constant, use GetAdapterLuid plus EnumAdapterByLuid, or the DXGI_ADAPTER_DESC of the adapter the device was made on.

P3

  • graphics_pipeline_cache.h:279: StorePipeline returning E_INVALIDARG (name already stored) is counted as a successful store and marks the library dirty. It should be counted separately; a same-name duplicate with a different pipeline would otherwise be silent.
  • d3d12_draw.inl:413-427: pipeline_cache_for resets the static cache when the device pointer changes, with no lock. This is fine if draws are single-threaded, as bound.pipelines already assumes, but the cache has its own SRW lock, which suggests concurrent use is expected.
  • d3d12_draw.inl:438-441: the key mixes key * 131 + format with FNV; a 64-bit hash with no desc comparison of its own relies on the library's own validation on a collision.

Verdict

No functional break found in the paths I could read or run, and the field-by-field hashing is right. I would fix the two P2 points (bytecode in the key, and when the library is written) before merge, and confirm the third on Windows.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045833038 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#pullrequestreview-6045833038). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:22:13Z. **Review:** COMMENTED --- Review at `a71f8fc5f6a8aa83d6d3faf618d3a451a7579878` (comment only, not an approval). ## What I checked - Read the full diff against `origin/main` (`d3d12_draw.inl`, `graphics_pipeline_cache.h`, the test, CMake, docs). - Cache key: translation key (title shader words + root signature blob + a revision string), output formats, DSV format, blend and depth-stencil. Blend and depth are hashed field by field, so ABI padding cannot change the name. - COM lifetime: the library is released before the blob it was created from, the cache holds a device reference, and a failed load or create returns a usable pipeline. ## Commands run on this branch (Linux) - `x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only` on `graphics_pipeline_cache.h`: compiles. - A small program (mingw build, run under wine) calls `hash_blend_key` and `hash_depth_stencil_key`: 12 checks pass. Padding bytes set to 0xAA versus 0 give the same key. Flipping AlphaToCoverage, IndependentBlend, RT7 LogicOp, RT3 write mask, RT0 BlendOpAlpha, RT1 DestBlendAlpha, DepthFunc, StencilWriteMask, BackFace func or FrontFace depth-fail op each changes it. - Two real mutations of the header, each caught by that program (then restored): dropping `LogicOp` from the blend hash, and dropping `BackFace` from the depth hash. - Not run: `startup_pso_cache_check` and anything D3D12. The Windows runner (`x2w_pipe.py win2025`) was blocked by a local command guard in this session, so there is no Windows result from me. I did not run the WARP test. ## P2: the key does not cover the translated bytecode `d3d12_draw.inl:436-446`. `tr.key` is a hash of the title's shader words and root signature plus the string `x2w-startup-shader-4` (`d3d12_draw.inl:201`). The desktop VS and PS (`tr.vs`, `tr.ps`, line 451) come from `gfx2hlsl.py` and DXC, and are not in the key. If the translator output changes and nobody bumps that string, the library can hold a pipeline built from the old bytecode under the same name. I could not confirm whether `LoadGraphicsPipeline` rejects a description whose shaders differ; the documentation I know does not promise it. Hashing `tr.vs` and `tr.ps` bytes into the key is cheap and removes the dependency on a manual bump. ## P2: the library is persisted only at process shutdown `Flush()` (`graphics_pipeline_cache.h:208`) is called only from the test. In the product the only write is `PersistLibrary()` from `Shutdown()`, reached by the destructor of the function-static `unique_ptr` (`d3d12_draw.inl:415`). That runs at process or DLL teardown, where D3D12 may already be unloaded, and not at all if the title ends the process abruptly. In both cases the cache file never appears and the feature does nothing, while the doc says stores are coalesced and flushed. Suggest an explicit flush at a safe point (device release or a frame or time threshold). Related: the cache holds a device reference from a static (`graphics_pipeline_cache.h:178`), so the device outlives the title's own release until teardown. ## P2: adapter and driver identity is probably the constant seed `graphics_pipeline_cache.h:85`. `adapter_identity` queries `IDXGIDevice` on an `ID3D12Device`. As far as I know a D3D12 device does not implement `IDXGIDevice`, so the query fails and the hash stays at the seed `x2w-pso-cache-v1` for every GPU and driver. Safety still holds, because `CreatePipelineLibrary` rejects a foreign blob and the code deletes it and starts empty. But the docs and comments promise vendor, device, revision and UMD identity in the file name and header. I could not run this here; please confirm on the Windows node, for example by printing the identity for WARP and a hardware adapter. If it is constant, use `GetAdapterLuid` plus `EnumAdapterByLuid`, or the `DXGI_ADAPTER_DESC` of the adapter the device was made on. ## P3 - `graphics_pipeline_cache.h:279`: `StorePipeline` returning `E_INVALIDARG` (name already stored) is counted as a successful store and marks the library dirty. It should be counted separately; a same-name duplicate with a different pipeline would otherwise be silent. - `d3d12_draw.inl:413-427`: `pipeline_cache_for` resets the static cache when the device pointer changes, with no lock. This is fine if draws are single-threaded, as `bound.pipelines` already assumes, but the cache has its own SRW lock, which suggests concurrent use is expected. - `d3d12_draw.inl:438-441`: the key mixes `key * 131 + format` with FNV; a 64-bit hash with no desc comparison of its own relies on the library's own validation on a collision. ## Verdict No functional break found in the paths I could read or run, and the field-by-field hashing is right. I would fix the two P2 points (bytecode in the key, and when the library is written) before merge, and confirm the third on Windows. AI-assisted; commands listed were executed locally.
lambirou commented 2026-11-24 20:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T19:08:52Z.


Addressed the P2 and the owner's cold-path request on head a71f8fc5.

  • The key control now mutates each semantic field (22 blend, 14 depth). Removing RenderTargetWriteMask from the hash fails the test.
  • Persistence is coalesced: a successful store marks the library dirty, and Flush() or destruction serializes it once. The draw path no longer rewrites the whole library per PSO.
  • The WARP batch of 8 distinct trivial PSOs reports uncached / cached cold / flush / warm times. The last local run read 4.33 / 2.67 / 2.01 / 0.76 ms. This is diagnostic, not a title speedup claim.
  • A cold-created and a warm-loaded pipeline both render 0xff4080ff, and their readbacks match.

Windows checks pass on this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141667997 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7141667997). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T19:08:52Z. --- Addressed the P2 and the owner's cold-path request on head `a71f8fc5`. - The key control now mutates each semantic field (22 blend, 14 depth). Removing `RenderTargetWriteMask` from the hash fails the test. - Persistence is coalesced: a successful store marks the library dirty, and `Flush()` or destruction serializes it once. The draw path no longer rewrites the whole library per PSO. - The WARP batch of 8 distinct trivial PSOs reports uncached / cached cold / flush / warm times. The last local run read 4.33 / 2.67 / 2.01 / 0.76 ms. This is diagnostic, not a title speedup claim. - A cold-created and a warm-loaded pipeline both render `0xff4080ff`, and their readbacks match. Windows checks pass on this head.
lambirou commented 2026-11-24 21:01:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T20:45:16Z.


Addressed the P2 findings on head f9a88f54.

  • The key now includes the translated VS/PS bytes through Translation::code_key; schema 3.
  • Persistence has a safe point: queue_present calls flush_pipeline_cache() outside draw_lock; the destructor remains a fallback.
  • Adapter identity uses GetAdapterLuid and IDXGIFactory4::EnumAdapterByLuid. On WARP the test prints adapter identity 3d82a583644e40a1, not the constant seed. The LUID is only a fallback.
  • StorePipeline returning E_INVALIDARG is counted as a duplicate, not a new store.
  • Target formats now use the same FNV update as the other key fields.

The startup_pso_cache test passes 1/1, the 36 field mutations pass, and Windows checks pass on this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7144011308 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7144011308). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T20:45:16Z. --- Addressed the P2 findings on head `f9a88f54`. - The key now includes the translated VS/PS bytes through `Translation::code_key`; schema 3. - Persistence has a safe point: `queue_present` calls `flush_pipeline_cache()` outside `draw_lock`; the destructor remains a fallback. - Adapter identity uses `GetAdapterLuid` and `IDXGIFactory4::EnumAdapterByLuid`. On WARP the test prints `adapter identity 3d82a583644e40a1`, not the constant seed. The LUID is only a fallback. - `StorePipeline` returning `E_INVALIDARG` is counted as a duplicate, not a new store. - Target formats now use the same FNV update as the other key fields. The startup_pso_cache test passes 1/1, the 36 field mutations pass, and Windows checks pass on this head.
tedin7 commented 2026-11-24 21:31:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:31:25Z.

Review: COMMENTED


Re-review at head f9a88f54759e100fd6ec056cd7cf323011f3b183 (previous reviews at 46a0816d, 9998541c, a71f8fc5).

Verdict: no P1. The P2 about the shader bytecode missing from the key is fixed. One new P2 (thread safety of the cache pointer), one P3.

What changed since a71f8fc5 (PR-only diff compared)

  • d3d12_draw.inl: Translation::code_key = tr.key + FNV of the translated VS and PS bytes, used in pipeline_for (schema 3); target formats are hashed with fnv_bytes instead of key * 131 +. This closes the old gap where changed translator output kept the same cache name.
  • graphics_pipeline_cache.h: adapter located through GetAdapterLuid + IDXGIFactory4::EnumAdapterByLuid (LUID only as fallback hash, version string x2w-pso-cache-v2); E_INVALIDARG from StorePipeline is now counted as duplicates instead of a store.
  • flush_pipeline_cache() is called from queue_present (d3d12_xs_device.cpp:3318), so a cold batch is written once per presented frame.
  • Test: a check that the adapter identity differs from the constant seed. The per-field key controls from the earlier P2 are in place (tests/startup_pso_cache_check.cpp ~280-335, single-field changes on blend, depth and both stencil faces).

P2: unsynchronized cache/owner statics are now read from a second lock domain

d3d12_draw.inl:461-471 (pipeline_cache_for) and the new flush_pipeline_cache() right below it. The draw path reaches pipeline_cache_for under draw_lock; flush_pipeline_cache() is called from queue_present outside draw_lock (by design, per the comment). If the ID3D12Device* changes (owner != device), the draw thread does cache.reset(new ...) while the present thread may be inside cache->Flush() on the old object, which is a use-after-free window. The earlier review called the unlocked statics a minor note while only one lock domain touched them; adding a second caller outside the lock makes it a real, if narrow, race. Fix: take draw_lock (or a small dedicated lock) around the pointer read and swap, or keep the old cache alive until both paths are done with it.

P3

  • The new code_key wiring in pipeline_for has no test: startup_pso_cache_check exercises the cache helper only, so dropping the code_key line leaves every test green. A small control that two translations with different VS/PS bytes and the same tr.key give different pipeline names would pin the fix.

Commands run locally

  • git diff --check origin/main...HEAD: exit 0. docs_links_check.py: 18 files, 376 links. bidi_controls_check.py: 1337 files, clean.
  • x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only on graphics_pipeline_cache.h: compiles (only the #pragma once in main file warning).
  • Windows Server 2025 (Build 26100, MSVC 14.44 + D3D12 WARP) via the pipeline, ^startup_pso_cache$: Debug 1/1 and Release /O2 1/1 passed.

Mutations (mingw build run under wine, reverted with git checkout -- .)

A small harness built against the unchanged graphics_pipeline_cache.h changes one blend or depth field at a time and requires a different key: unmodified, 0 unchanged out of 12 cases.

Mutation of the header Result
remove LogicOp from hash_blend_key detected (RT7 LogicOp unchanged)
remove RenderTargetWriteMask from hash_blend_key detected
hash_depth_stencil_key returns before BackFace detected (2 cases unchanged)
Limit: these were detected by my harness, not by running the PR's own test with the mutation, since that test needs a D3D12 device and Windows. The PR test has matching single-field cases, but I did not run a mutated build of it on Windows.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047744157 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#pullrequestreview-6047744157). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:31:25Z. **Review:** COMMENTED --- Re-review at head `f9a88f54759e100fd6ec056cd7cf323011f3b183` (previous reviews at `46a0816d`, `9998541c`, `a71f8fc5`). **Verdict: no P1. The P2 about the shader bytecode missing from the key is fixed. One new P2 (thread safety of the cache pointer), one P3.** ### What changed since `a71f8fc5` (PR-only diff compared) - `d3d12_draw.inl`: `Translation::code_key` = `tr.key` + FNV of the translated VS and PS bytes, used in `pipeline_for` (schema 3); target formats are hashed with `fnv_bytes` instead of `key * 131 +`. This closes the old gap where changed translator output kept the same cache name. - `graphics_pipeline_cache.h`: adapter located through `GetAdapterLuid` + `IDXGIFactory4::EnumAdapterByLuid` (LUID only as fallback hash, version string `x2w-pso-cache-v2`); `E_INVALIDARG` from `StorePipeline` is now counted as `duplicates` instead of a store. - `flush_pipeline_cache()` is called from `queue_present` (`d3d12_xs_device.cpp:3318`), so a cold batch is written once per presented frame. - Test: a check that the adapter identity differs from the constant seed. The per-field key controls from the earlier P2 are in place (`tests/startup_pso_cache_check.cpp` ~280-335, single-field changes on blend, depth and both stencil faces). ### P2: unsynchronized `cache`/`owner` statics are now read from a second lock domain `d3d12_draw.inl:461-471` (`pipeline_cache_for`) and the new `flush_pipeline_cache()` right below it. The draw path reaches `pipeline_cache_for` under `draw_lock`; `flush_pipeline_cache()` is called from `queue_present` outside `draw_lock` (by design, per the comment). If the `ID3D12Device*` changes (`owner != device`), the draw thread does `cache.reset(new ...)` while the present thread may be inside `cache->Flush()` on the old object, which is a use-after-free window. The earlier review called the unlocked statics a minor note while only one lock domain touched them; adding a second caller outside the lock makes it a real, if narrow, race. Fix: take `draw_lock` (or a small dedicated lock) around the pointer read and swap, or keep the old cache alive until both paths are done with it. ### P3 - The new `code_key` wiring in `pipeline_for` has no test: `startup_pso_cache_check` exercises the cache helper only, so dropping the `code_key` line leaves every test green. A small control that two translations with different VS/PS bytes and the same `tr.key` give different pipeline names would pin the fix. ### Commands run locally - `git diff --check origin/main...HEAD`: exit 0. `docs_links_check.py`: 18 files, 376 links. `bidi_controls_check.py`: 1337 files, clean. - `x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only` on `graphics_pipeline_cache.h`: compiles (only the `#pragma once in main file` warning). - Windows Server 2025 (Build 26100, MSVC 14.44 + D3D12 WARP) via the pipeline, `^startup_pso_cache$`: Debug 1/1 and Release /O2 1/1 passed. ### Mutations (mingw build run under wine, reverted with `git checkout -- .`) A small harness built against the unchanged `graphics_pipeline_cache.h` changes one blend or depth field at a time and requires a different key: unmodified, 0 unchanged out of 12 cases. | Mutation of the header | Result | |---|---| | remove `LogicOp` from `hash_blend_key` | detected (RT7 LogicOp unchanged) | | remove `RenderTargetWriteMask` from `hash_blend_key` | detected | | `hash_depth_stencil_key` returns before `BackFace` | detected (2 cases unchanged) | Limit: these were detected by my harness, not by running the PR's own test with the mutation, since that test needs a D3D12 device and Windows. The PR test has matching single-field cases, but I did not run a mutated build of it on Windows. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:16:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:16:07Z.

Review: COMMENTED


Review of head 591f556e221baa64938f3221afde3ec46dd28e69 (comment only).

Scope: PSO library cache for translated pipelines (graphics_pipeline_cache.h, d3d12_draw.inl, present hook, new startup_pso_cache_check, docs, CMake).

Commands executed locally (Linux worktree of the PR head):

  • git diff --stat origin/main...HEAD -> 6 files, +1112/-7
  • python3 tests/docs_links_check.py -> Self-test passed; Checked 18 Markdown files and 393 links
  • python3 tests/bidi_controls_check.py -> no bidirectional controls in 1414 files
  • git diff --check origin/main...HEAD -> clean
  • gh pr checks 1641 -> Windows build+test pass (ctest: 100% tests passed out of 30), Linux Python checks pass, gfx1013 fixtures pass; /O2 job skipped

The new test and the cache code are Windows/D3D12 only, so the Linux tests touched are none. I did not run a Win2025 job and I did not run a mutation of the new logic. I read the code only. The Windows CI result above is the runtime evidence.

Findings: no P1, no P2.

What I checked and found sound:

  • Key: pipeline_key hashes code key (translation key + VS/PS bytes), target count and formats, DSV, blend/depth presence and the fields of both blocks one by one, so padding cannot change the name. Schema byte and adapter identity are mixed in. The old key ignored blend state and shader bytes; the new one fixes that.
  • Fallback: every load failure, store failure, null library or missing ID3D12Device1 ends in a direct CreateGraphicsPipelineState. A cache failure never fails a draw.
  • Blob: magic, version, header size, adapter, payload size and checksum are checked before CreatePipelineLibrary; the blob stays alive as long as the library; the write is atomic through a temp file.
  • Threading: shared_ptr keeps the old cache alive across a device change, and the cache holds its own device reference, so the owner pointer cannot be reused while it is set.

Nits (non blocking):

  1. graphics_pipeline_cache.h (GetOrCreateGraphicsPipeline): if LoadGraphicsPipeline returns E_INVALIDARG because the desc differs from the stored one (rasterizer, topology or input layout are not in the key), the later StorePipeline also returns E_INVALIDARG and is counted as a duplicate. The stale entry then stays forever and that PSO is rebuilt on every run. A comment, or a key that includes those fields, would make this explicit.
  2. Flush() serializes and writes the file while holding the cache lock, so a draw thread that creates a new PSO at that moment waits for the disk write. It is once per presented frame with new stores, so it is small, but worth knowing.
  3. A failed DeleteFileW/OpenEmptyLibrary after a driver mismatch is not logged; only the counter changes.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050683658 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#pullrequestreview-6050683658). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:16:07Z. **Review:** COMMENTED --- Review of head `591f556e221baa64938f3221afde3ec46dd28e69` (comment only). Scope: PSO library cache for translated pipelines (`graphics_pipeline_cache.h`, `d3d12_draw.inl`, present hook, new `startup_pso_cache_check`, docs, CMake). Commands executed locally (Linux worktree of the PR head): - `git diff --stat origin/main...HEAD` -> 6 files, +1112/-7 - `python3 tests/docs_links_check.py` -> Self-test passed; Checked 18 Markdown files and 393 links - `python3 tests/bidi_controls_check.py` -> no bidirectional controls in 1414 files - `git diff --check origin/main...HEAD` -> clean - `gh pr checks 1641` -> Windows build+test pass (ctest: 100% tests passed out of 30), Linux Python checks pass, gfx1013 fixtures pass; /O2 job skipped The new test and the cache code are Windows/D3D12 only, so the Linux tests touched are none. I did not run a Win2025 job and I did not run a mutation of the new logic. I read the code only. The Windows CI result above is the runtime evidence. Findings: no P1, no P2. What I checked and found sound: - Key: `pipeline_key` hashes code key (translation key + VS/PS bytes), target count and formats, DSV, blend/depth presence and the fields of both blocks one by one, so padding cannot change the name. Schema byte and adapter identity are mixed in. The old key ignored blend state and shader bytes; the new one fixes that. - Fallback: every load failure, store failure, null library or missing `ID3D12Device1` ends in a direct `CreateGraphicsPipelineState`. A cache failure never fails a draw. - Blob: magic, version, header size, adapter, payload size and checksum are checked before `CreatePipelineLibrary`; the blob stays alive as long as the library; the write is atomic through a temp file. - Threading: `shared_ptr` keeps the old cache alive across a device change, and the cache holds its own device reference, so the `owner` pointer cannot be reused while it is set. Nits (non blocking): 1. `graphics_pipeline_cache.h` (`GetOrCreateGraphicsPipeline`): if `LoadGraphicsPipeline` returns `E_INVALIDARG` because the desc differs from the stored one (rasterizer, topology or input layout are not in the key), the later `StorePipeline` also returns `E_INVALIDARG` and is counted as a duplicate. The stale entry then stays forever and that PSO is rebuilt on every run. A comment, or a key that includes those fields, would make this explicit. 2. `Flush()` serializes and writes the file while holding the cache lock, so a draw thread that creates a new PSO at that moment waits for the disk write. It is once per presented frame with new stores, so it is small, but worth knowing. 3. A failed `DeleteFileW`/`OpenEmptyLibrary` after a driver mismatch is not logged; only the counter changes. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 13:01:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:17Z.


@lambirou could you rebase this branch onto current main and force-push?

GitHub reports head 591f556e as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (cf97bee1):

  • src/startup_stubs/d3d12_draw.inl

Commands run locally:

git fetch origin main pull/1641/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1641 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162994757 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7162994757). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:53:17Z. --- @lambirou could you rebase this branch onto current `main` and force-push? GitHub reports head `591f556e` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`cf97bee1`): - `src/startup_stubs/d3d12_draw.inl` Commands run locally: ``` git fetch origin main pull/1641/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1641 --json mergeable # CONFLICTING ``` Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 16:05:02 +00:00
Leyukaka commented 2026-12-01 21:54:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T21:54:47Z.


@lambirou, the pipeline library cache in this PR still looks useful: as your description notes, cold runs still pay the driver pipeline compile again, and X2W_SHADER_CACHE only covers the translated bytecode.

Do you plan to reopen it after a rebase? If not, would you be fine with me carrying it forward on current main? I would keep your commits and authorship, resolve the d3d12_draw.inl conflict, rerun the WARP cold, warm, corrupt, disabled and concurrent cases, and link the new PR here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7326999094 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7326999094). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T21:54:47Z. --- @lambirou, the pipeline library cache in this PR still looks useful: as your description notes, cold runs still pay the driver pipeline compile again, and `X2W_SHADER_CACHE` only covers the translated bytecode. Do you plan to reopen it after a rebase? If not, would you be fine with me carrying it forward on current `main`? I would keep your commits and authorship, resolve the `d3d12_draw.inl` conflict, rerun the WARP cold, warm, corrupt, disabled and concurrent cases, and link the new PR here.
Leyukaka commented 2026-12-02 08:12:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T08:12:20Z.


@lambirou, thank you for this work. I carried it forward on current main in #3837, with your three commits and authorship kept and one commit on top for the rewritten pipeline_for. If you prefer to continue it yourself, tell me and I will close mine.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7339138471 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1641#issuecomment-7339138471). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T08:12:20Z. --- @lambirou, thank you for this work. I carried it forward on current `main` in #3837, with your three commits and authorship kept and one commit on top for the rewritten `pipeline_for`. If you prefer to continue it yourself, tell me and I will close mine.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1634
No description provided.