shader: consume startup requests and publish runtime cache entries in compile_dxil #2955

Merged
consolelogkyo merged 1 commit from upstream-pr/2955 into cpp-migration 2026-11-26 23:23:45 +00:00
consolelogkyo commented 2026-11-26 23:12:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by consolelogkyo on 2026-11-26T23:12:53Z.


Summary

Make compile_dxil --requests consume revision-28 startup requests (including ASCII req_<key>.psin stream descriptions) and publish runtime-named stage binaries and <key>.txt manifests accepted directly by the startup runtime cache loaders:

  • Request keys & .psin stream descriptions (src/shader_compute_request.cpp, src/gfx1013_compute_native.cpp, src/gfx1013_direct_graphics.inl, src/guest_shader_container.h):
    • Parse ASCII req_<key>.psin (psin1 <16-hex-key> ena=0x<mask> addr=0x<mask>), reject malformed lines, duplicate/missing masks, embedded keys naming another pipeline, or contradictory (ena & ~addr) != 0 masks, and fold b"psin1" + struct.pack("<II", ena, addr) into the graphics FNV-1a key identically to tools/startup/gfx2hlsl.py:pipeline_key.
    • Honour both SPI_PS_INPUT_ADDR (entry VGPR layout) and SPI_PS_INPUT_ENA (loaded entry inputs) in raw graphics lowering, refusing reads of allocated-but-disabled pixel entry VGPRs and keying raw parameter/wave acceptance off verified enable_mask center inputs rather than a binary interpolant count.
    • Validate compute part framing before key comparison so tampered .c67 requests report "compute request key mismatch".
  • Runtime stage naming & atomic manifest publication (src/direct_compute_cache.cpp, tools/startup/compile_dxil.cpp):
    • Strip req_ from --requests output stems (<key>.vs.cso / <key>.ps.cso, <key>.gs.cso for gfx1013-container-rect, and <key>.cs.cso for compute).
    • Format x2w-manifest (1/2 for graphics, 2 + stage cs + group for compute) for stage bindings modelled by d3d12_draw.inl:load_translation and d3d12_compute_dispatch.inl:load_compute_translation, skipping manifest emission for unmodelled bindings (such as IA vertex_fetch layouts, rectangle GS batches, typed/half/indexed-atomic buffer views, or comparison samplers in compute).
    • Compile graphics stages before moving any stage file, withdraw any prior <key>.txt before updating stages or on refusal, write <key>.psdep when .psin was used, and atomically publish <key>.txt last.
    • Open frontend and DXIL cache entries with FILE_SHARE_DELETE during cache lookups (src/direct_compute_cache.cpp, src/shader_dxil_compiler.cpp) so concurrent --jobs workers sharing a stage do not fail when MoveFileExW replaces an identical entry.
  • End-to-end fixture & docs: add tests/native_startup_request_cache_check.py (tests/cmake/native_startup_request_cache.cmake) and docs/experiments/native-startup-request-cache.md.

Closes #2933

Verification

Windows 11 (10.0.26100), Release preset (MSVC 19.44, Windows SDK 10.0.26100.0 DXC), X2W_D3D12_DEBUG=1 (0 D3D12 debug-layer errors) on Microsoft Basic Render Driver (WARP) (1414:008c, driver 10.0.26100.9818) and AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010):

cmake --preset release
cmake --build --preset release
ctest --preset release --no-tests=error --output-on-failure -j 8 -R "^(native_.*|docs_links|bidi_controls)$"
  • native_startup_request_cache_controls: PASS (in-place .psin graphics + .c67 compute publication, gfx2hlsl.pending_keys completion check, revision-literal pinning between shader_compute_request.cpp and d3d12_draw.inl, stale-stage manifest withdrawal, and 8 fresh-directory refusal controls)
  • native_startup_request_cache_warp: PASS (91-pixel .psin draws for (0x8002, 0x8003) and (0x8002, 0x8002) + mismatched-mask negative control, end-to-end startup_stream_consumer -> compile_dxil --requests -> d3d12_xs graphics draw, and Wave-4 WARP compute manifest/root loader check)
  • native_startup_request_cache_hardware (RX 9070 XT): PASS (full end-to-end .psin draws, d3d12_xs graphics draw, and d3d12_xs slot-67 .c67 Dispatch(3, 2, 2) matching all 320 output dwords without manual renaming)
  • Full ^native_ suite (40 tests: 39 passed, 1 skipped native_comparison_pso_warp) + docs_links + bidi_controls: PASS

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518408479 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2955). Originally posted by [consolelogkyo](https://github.com/consolelogkyo) on 2026-11-26T23:12:53Z. --- ## Summary Make `compile_dxil --requests` consume revision-28 startup requests (including ASCII `req_<key>.psin` stream descriptions) and publish runtime-named stage binaries and `<key>.txt` manifests accepted directly by the startup runtime cache loaders: - **Request keys & `.psin` stream descriptions (`src/shader_compute_request.cpp`, `src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_graphics.inl`, `src/guest_shader_container.h`):** - Parse ASCII `req_<key>.psin` (`psin1 <16-hex-key> ena=0x<mask> addr=0x<mask>`), reject malformed lines, duplicate/missing masks, embedded keys naming another pipeline, or contradictory `(ena & ~addr) != 0` masks, and fold `b"psin1" + struct.pack("<II", ena, addr)` into the graphics FNV-1a key identically to `tools/startup/gfx2hlsl.py:pipeline_key`. - Honour both `SPI_PS_INPUT_ADDR` (entry VGPR layout) and `SPI_PS_INPUT_ENA` (loaded entry inputs) in raw graphics lowering, refusing reads of allocated-but-disabled pixel entry VGPRs and keying raw parameter/wave acceptance off verified `enable_mask` center inputs rather than a binary interpolant count. - Validate compute part framing before key comparison so tampered `.c67` requests report `"compute request key mismatch"`. - **Runtime stage naming & atomic manifest publication (`src/direct_compute_cache.cpp`, `tools/startup/compile_dxil.cpp`):** - Strip `req_` from `--requests` output stems (`<key>.vs.cso` / `<key>.ps.cso`, `<key>.gs.cso` for `gfx1013-container-rect`, and `<key>.cs.cso` for compute). - Format `x2w-manifest` (`1`/`2` for graphics, `2` + `stage cs` + `group` for compute) for stage bindings modelled by `d3d12_draw.inl:load_translation` and `d3d12_compute_dispatch.inl:load_compute_translation`, skipping manifest emission for unmodelled bindings (such as IA `vertex_fetch` layouts, rectangle GS batches, typed/half/indexed-atomic buffer views, or comparison samplers in compute). - Compile graphics stages before moving any stage file, withdraw any prior `<key>.txt` before updating stages or on refusal, write `<key>.psdep` when `.psin` was used, and atomically publish `<key>.txt` last. - Open frontend and DXIL cache entries with `FILE_SHARE_DELETE` during cache lookups (`src/direct_compute_cache.cpp`, `src/shader_dxil_compiler.cpp`) so concurrent `--jobs` workers sharing a stage do not fail when `MoveFileExW` replaces an identical entry. - **End-to-end fixture & docs:** add `tests/native_startup_request_cache_check.py` (`tests/cmake/native_startup_request_cache.cmake`) and `docs/experiments/native-startup-request-cache.md`. Closes #2933 ## Verification Windows 11 (`10.0.26100`), Release preset (`MSVC 19.44`, Windows SDK `10.0.26100.0` DXC), `X2W_D3D12_DEBUG=1` (`0` D3D12 debug-layer errors) on **Microsoft Basic Render Driver (WARP)** (`1414:008c`, driver `10.0.26100.9818`) and **AMD Radeon RX 9070 XT** (`1002:7550`, driver `32.0.32029.2010`): ```powershell cmake --preset release cmake --build --preset release ctest --preset release --no-tests=error --output-on-failure -j 8 -R "^(native_.*|docs_links|bidi_controls)$" ``` - `native_startup_request_cache_controls`: **PASS** (in-place `.psin` graphics + `.c67` compute publication, `gfx2hlsl.pending_keys` completion check, revision-literal pinning between `shader_compute_request.cpp` and `d3d12_draw.inl`, stale-stage manifest withdrawal, and 8 fresh-directory refusal controls) - `native_startup_request_cache_warp`: **PASS** (91-pixel `.psin` draws for `(0x8002, 0x8003)` and `(0x8002, 0x8002)` + mismatched-mask negative control, end-to-end `startup_stream_consumer` -> `compile_dxil --requests` -> `d3d12_xs` graphics draw, and Wave-4 WARP compute manifest/root loader check) - `native_startup_request_cache_hardware` (`RX 9070 XT`): **PASS** (full end-to-end `.psin` draws, `d3d12_xs` graphics draw, and `d3d12_xs` slot-67 `.c67` `Dispatch(3, 2, 2)` matching all 320 output dwords without manual renaming) - Full `^native_` suite (`40` tests: `39` passed, `1` skipped `native_comparison_pso_warp`) + `docs_links` + `bidi_controls`: **PASS** AI-assisted.
MasterDomino commented 2026-11-26 23:23:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T23:23:43Z.

Review: APPROVED


Review of head 6137bed2, tested merged onto cpp-migration 49e0e36d (after #2950 and #2952). It auto-merges cleanly, and CI on the head is green. I read it against @Not-Saii's notes on #2933. Approving and merging, with follow-ups below.

Checked against those notes:

  • Keys: graphics hashes -28, then a, b, root, .ia, then psin1 + <II>(ena, addr), the same as gfx2hlsl.pipeline_key. Compute hashes -28cs with the same framing.
  • .psin line: it is parsed to read_ps_inputs' rules: at most 128 bytes, psin1 <16 hex> with ena=0x/addr=0x once each, the named key must equal the request's (pixel input description names another pipeline), both masks are required, and ena & ~addr is refused. A key mismatch with a description reports stale pixel input description.
  • Interpolant count: it takes the "description as proof" option. Enable bits now gate each input, and attributes are bounded by the 7-entry table.
  • Publication: the old <key>.txt is withdrawn first, VS/PS (and GS) are compiled in memory, then published atomically, then .psdep, then the manifest last, which matches gfx2hlsl.translate_to.
  • Manifest forms: every line it writes is one the loaders parse (d3d12_draw.inl, d3d12_compute_dispatch.inl). indexed_atomic_uav, comparison samplers in compute, constant blocks over 8 words or 32 in total, vertex fetch and non-SV_VertexID/SV_InstanceID inputs get no manifest.

Runs (Windows 11 26300.9974, AMD Radeon RX 9070 XT, driver 32.0.32029.2010, release):

  • ctest --preset release --no-tests=error -R '^native_': 43 tests, 42 passed and 1 skipped (77, native_comparison_pso_warp). native_startup_request_cache_{controls,warp,hardware} all pass.
  • Mutation: dropping the described_key != expected check fails native_startup_request_cache_controls at psin-other-pipeline. With it restored, it passes.
  • Real runtime cache, counts only: a copy of a revision-28 cache with 2,747 .c67 and 628 graphics requests, run with compile_dxil --jobs 8 … --requests. Compute: 270 compiled, 100 with a manifest. Graphics: 3 compiled, 1 with a manifest. Of the 59 compute keys that also have a gfx2hlsl manifest, 43 have identical binding lines, and 9 differ only in hex formatting (00000092 against 0x92, which the loader's %x reads the same). The rest are binding choices that differ per compiler, which is fine, since each manifest describes its own shader, plus the sampler point below.

Follow-ups, not blocking:

  1. Silent manifest refusals. For 170 of the 270 compiled compute requests (and 2 of 3 graphics), format_*_runtime_manifest returns nullopt. The stage files are published with no manifest and no message saying why. That is safe, because the runtime will not load them, but a report line naming the binding (as #2933 suggested) would make these countable the way --refusals is for gfx2hlsl.
  2. Buffer SRV arrays. The buf SRV branch (buffer_srv, raw_vector_srv, byte_window_srv) does not check array_count == 1, while the texture branches do.
  3. Sampler word 1, in the native compiler and not in this PR. On 6 keys the native manifest writes smpl 0 00000092 00000000 …, where gfx2hlsl writes smp 0 0x92 0xc00000 … for the same request. If I read SQ_IMG_SAMP_WORD1 right, native drops MAX_LOD (12.0 → 0), which would clamp explicit-LOD sampling to mip 0 once these manifests are loaded. That is worth an issue on the sampler extraction.
  4. Drawing through the runtime. As @Not-Saii's §4 says, a published native pair can load and still draw wrong for a non-zero start vertex or a rectangle list. That is #2935's "Graphics through the runtime" item. Until it is done, native graphics manifests should not be published into a live start-up cache.

I will close #2933 by hand.

AI-assisted; the commands above were run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6081435944 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2955#pullrequestreview-6081435944). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T23:23:43Z. **Review:** APPROVED --- Review of head `6137bed2`, tested merged onto `cpp-migration` `49e0e36d` (after #2950 and #2952). It auto-merges cleanly, and CI on the head is green. I read it against @Not-Saii's notes on #2933. Approving and merging, with follow-ups below. **Checked against those notes:** - **Keys:** graphics hashes `-28`, then a, b, root, `.ia`, then `psin1` + `<II>(ena, addr)`, the same as `gfx2hlsl.pipeline_key`. Compute hashes `-28cs` with the same framing. - **`.psin` line:** it is parsed to `read_ps_inputs`' rules: at most 128 bytes, `psin1 <16 hex>` with `ena=0x`/`addr=0x` once each, the named key must equal the request's (`pixel input description names another pipeline`), both masks are required, and `ena & ~addr` is refused. A key mismatch with a description reports `stale pixel input description`. - **Interpolant count:** it takes the "description as proof" option. Enable bits now gate each input, and attributes are bounded by the 7-entry table. - **Publication:** the old `<key>.txt` is withdrawn first, VS/PS (and GS) are compiled in memory, then published atomically, then `.psdep`, then the manifest last, which matches `gfx2hlsl.translate_to`. - **Manifest forms:** every line it writes is one the loaders parse (`d3d12_draw.inl`, `d3d12_compute_dispatch.inl`). `indexed_atomic_uav`, comparison samplers in compute, constant blocks over 8 words or 32 in total, vertex fetch and non-`SV_VertexID`/`SV_InstanceID` inputs get no manifest. **Runs** (Windows 11 26300.9974, AMD Radeon RX 9070 XT, driver 32.0.32029.2010, release): - `ctest --preset release --no-tests=error -R '^native_'`: 43 tests, 42 passed and 1 skipped (77, `native_comparison_pso_warp`). `native_startup_request_cache_{controls,warp,hardware}` all pass. - **Mutation:** dropping the `described_key != expected` check fails `native_startup_request_cache_controls` at `psin-other-pipeline`. With it restored, it passes. - **Real runtime cache, counts only:** a copy of a revision-28 cache with 2,747 `.c67` and 628 graphics requests, run with `compile_dxil --jobs 8 … --requests`. Compute: 270 compiled, **100 with a manifest**. Graphics: 3 compiled, 1 with a manifest. Of the 59 compute keys that also have a `gfx2hlsl` manifest, 43 have identical binding lines, and 9 differ only in hex formatting (`00000092` against `0x92`, which the loader's `%x` reads the same). The rest are binding choices that differ per compiler, which is fine, since each manifest describes its own shader, plus the sampler point below. **Follow-ups, not blocking:** 1. **Silent manifest refusals.** For 170 of the 270 compiled compute requests (and 2 of 3 graphics), `format_*_runtime_manifest` returns `nullopt`. The stage files are published with no manifest and no message saying why. That is safe, because the runtime will not load them, but a `report` line naming the binding (as #2933 suggested) would make these countable the way `--refusals` is for `gfx2hlsl`. 2. **Buffer SRV arrays.** The `buf` SRV branch (`buffer_srv`, `raw_vector_srv`, `byte_window_srv`) does not check `array_count == 1`, while the texture branches do. 3. **Sampler word 1, in the native compiler and not in this PR.** On 6 keys the native manifest writes `smpl 0 00000092 00000000 …`, where `gfx2hlsl` writes `smp 0 0x92 0xc00000 …` for the same request. If I read `SQ_IMG_SAMP_WORD1` right, native drops MAX_LOD (12.0 → 0), which would clamp explicit-LOD sampling to mip 0 once these manifests are loaded. That is worth an issue on the sampler extraction. 4. **Drawing through the runtime.** As @Not-Saii's §4 says, a published native pair can load and still draw wrong for a non-zero start vertex or a rectangle list. That is #2935's "Graphics through the runtime" item. Until it is done, native graphics manifests should not be published into a live start-up cache. I will close #2933 by hand. AI-assisted; the commands above were run locally.
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!2955
No description provided.