startup: hash slot 57 pixel entry records in gfx2hlsl request keys #3448

Merged
JohnConnorNPC merged 1 commit from upstream-pr/3448 into main 2026-11-29 10:37:18 +00:00
JohnConnorNPC commented 2026-11-29 10:25:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T10:25:40Z.


Change

Since #3094 (71844ba0), a native-shader runtime build with X2W_NATIVE_SHADERS set folds a slot 57 pipeline's pixel entry record into the graphics request key. It also publishes the record as req_<key>.ps57in (PSI1 followed by 8 bytes of fixed graphics state). src/shader_compute_request.cpp (read_graphics_request) checks that same key. tools/startup/gfx2hlsl.py was not updated: pipeline_key hashed .psin masks but not .ps57in, so translate_request refused every such request with shader request source key mismatch. When the native path also refused one of these pipelines, nothing could ever be published for its key, and its draws were skipped.

This change makes gfx2hlsl compute the key the way the runtime and the C++ reader do:

  • pipeline_key(..., slot57_entry=b'') hashes the record's 12 bytes as stored, last (after the optional .ia), like cached_translation and graphics_request_key. Without a record the key is unchanged.
  • read_slot57_entry reads req_<key>.ps57in. A record that is not 12 bytes or does not start with PSI1 is refused as invalid slot-57 pixel entry record.
  • load_request includes the record in the base and RTV-source key checks. It refuses a request that has both .psin and .ps57in with conflicting stream and slot-57 pixel entry records, the C++ reader's wording.
  • The translation does not read the record's values. For the same stages the HLSL is unchanged.

The runtime is not changed. The native path needs PSI1 in the key, because direct_compute_cache.cpp reads the record's two words. Dropping the record from the runtime key would give pipelines that differ only in that state the same key, and the native reader would then refuse every slot 57 request as stale.

Cache effect. Results that a cache holds under keys computed without the record (for example, from before #3094) are not used for these pipelines. Each such pipeline translates once more under its current key. This PR does not cause that; the runtime has used these keys since #3094. With X2W_SKIP_FAILED=1, a cache in which gfx2hlsl already wrote a .fail for one of these keys keeps skipping it until that .fail is removed.

Refs #3094

Verification

Commit ea68a605 = main f1236fd3 + this change. All checks ran on a Debian Linux 6.12 host. I don't have MSVC or a Windows machine.

Check Result
python -B tests/startup_shader_cache_key_check.py pass. Six new slot 57 entry: lines, last line startup shader cache key checks: passed
Linux Python job as windows.yml runs it (python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux ...), which now includes tests/checks/python-linux/startup_shader_cache_key.txt all 261 checks passed, exit 0
python -B tests/startup_tools_lint_check.py tools/startup exit 0
CMake-only checks that call these functions and take no binary: startup_archive_requests_cli, startup_gfx2hlsl_buffer_store, startup_gfx2hlsl_export_mask, startup_gfx2hlsl_fract, startup_mesh86_cache_cli, startup_shader_cache_rekey_cli exit 0, same as on main
native_compile_dxil_rekey, native_rtv_variant, native_startup_request_cache, startup_indirect_mesh_cache, startup_mrt, startup_rect_gap not run: they need Windows binaries (same usage refusal on main)
ctest --preset dev --no-tests=error -R '^startup_shader_cache_key$' -V not run: no Windows

Mutations. Each was applied to a byte copy of gfx2hlsl.py, run against the key check, and restored (sha256 verified):

Mutation Result
load_request ignores .ps57in (the behaviour on main) fails: unsupported: shader request source key mismatch on the first slot 57 case
read_slot57_entry accepts any record fails: the 11-byte record translates (ok)
no conflict check fails: pixel input description names another pipeline instead of the conflict diagnostic
pipeline_key ignores slot57_entry fails at the known-answer assertion
record folded before the .psin masks passes. Equivalent: a request with both records is refused before hashing

The new known answers (0x9ffda271506f7dc6, 0x06315afc32bae986) come from x2w::graphics_request_key, run in a separate driver built with g++ 14.2 against src/shader_compute_request.cpp. The same driver reproduces the existing plain and .ia answers (a837b162afd547ce, 6d5c0b7786182e0e). Its read_graphics_request accepts the keyed synthetic request and refuses the unkeyed one and the short, long, mistagged and empty records, as gfx2hlsl now does.

Evidence and follow-up

The fixture uses the test's existing source-built VS/PS/root blobs and synthetic records. It needs no GPU, compiler or game files (X2W_FXC='', manifest only).

Local data from a console executable (SHA-256 e95020b2fa4a721d…). These are Wine results only: Proton Experimental 11.0-20261123b with vkd3d-proton 30b0eb9b on an NVIDIA GeForce RTX 4070 Ti SUPER, driver 550.163.01, no debug layer, no Windows build. Nothing here was measured on Windows.

  • Offline, on copies of the 9 graphics requests with .ps57in that a run on main refused: main's gfx2hlsl (f1236fd3) gives 9 × shader request source key mismatch. With this change: 9 ok, 0 .fail. The HLSL equals what the cache held for the same stages under keys without the record (18/18 files). The manifests match too (9/9, key names normalised, line endings ignored).
  • Runtime: build of ea68a605 (runtime identical to f1236fd3), run with --render --translate from a fresh copy of the same starting cache. At about 3 minutes, translate.txt has 9 × ok (exactly the 9 keys above), 0 key mismatches, and pipelines translated 11 / missing 0. At 4800 executes there were 90495 translated draws and 6134 not drawn, and the not-drawn count stopped growing after about 2100 executes. The runtime still logs the 9 native refusals; the gfx2hlsl results load after them through the manifest retry. The presented surface's mean level went from 0.00 to 91.82 after about frame 2370.
  • For comparison, the same starting cache on main 1a0120ba read pipelines translated 2 / missing 9, with 9 key mismatches and 8400 translated / 167263 not drawn at 8400 executes. The mean level stayed at 0.00. Between 1a0120ba and f1236fd3 neither gfx2hlsl.py nor shader_compute_request.cpp changed, and the d3d12_draw.inl changes don't touch request keys. I did not run f1236fd3 without this change.

Not covered: tools/startup/shader_cache_rekey.py neither hashes nor copies .ps57in, so it does not handle these requests correctly. That is the same on main and would be a separate change.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5549812991 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3448). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T10:25:40Z. --- ## Change Since #3094 (71844ba0), a native-shader runtime build with `X2W_NATIVE_SHADERS` set folds a slot 57 pipeline's pixel entry record into the graphics request key. It also publishes the record as `req_<key>.ps57in` (`PSI1` followed by 8 bytes of fixed graphics state). `src/shader_compute_request.cpp` (`read_graphics_request`) checks that same key. `tools/startup/gfx2hlsl.py` was not updated: `pipeline_key` hashed `.psin` masks but not `.ps57in`, so `translate_request` refused every such request with `shader request source key mismatch`. When the native path also refused one of these pipelines, nothing could ever be published for its key, and its draws were skipped. This change makes gfx2hlsl compute the key the way the runtime and the C++ reader do: - `pipeline_key(..., slot57_entry=b'')` hashes the record's 12 bytes as stored, last (after the optional `.ia`), like `cached_translation` and `graphics_request_key`. Without a record the key is unchanged. - `read_slot57_entry` reads `req_<key>.ps57in`. A record that is not 12 bytes or does not start with `PSI1` is refused as `invalid slot-57 pixel entry record`. - `load_request` includes the record in the base and RTV-source key checks. It refuses a request that has both `.psin` and `.ps57in` with `conflicting stream and slot-57 pixel entry records`, the C++ reader's wording. - The translation does not read the record's values. For the same stages the HLSL is unchanged. The runtime is not changed. The native path needs PSI1 in the key, because `direct_compute_cache.cpp` reads the record's two words. Dropping the record from the runtime key would give pipelines that differ only in that state the same key, and the native reader would then refuse every slot 57 request as stale. **Cache effect.** Results that a cache holds under keys computed without the record (for example, from before #3094) are not used for these pipelines. Each such pipeline translates once more under its current key. This PR does not cause that; the runtime has used these keys since #3094. With `X2W_SKIP_FAILED=1`, a cache in which gfx2hlsl already wrote a `.fail` for one of these keys keeps skipping it until that `.fail` is removed. Refs #3094 ## Verification Commit ea68a605 = main f1236fd3 + this change. All checks ran on a Debian Linux 6.12 host. I don't have MSVC or a Windows machine. | Check | Result | |---|---| | `python -B tests/startup_shader_cache_key_check.py` | pass. Six new `slot 57 entry:` lines, last line `startup shader cache key checks: passed` | | Linux Python job as `windows.yml` runs it (`python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux ...`), which now includes `tests/checks/python-linux/startup_shader_cache_key.txt` | `all 261 checks passed`, exit 0 | | `python -B tests/startup_tools_lint_check.py tools/startup` | exit 0 | | CMake-only checks that call these functions and take no binary: `startup_archive_requests_cli`, `startup_gfx2hlsl_buffer_store`, `startup_gfx2hlsl_export_mask`, `startup_gfx2hlsl_fract`, `startup_mesh86_cache_cli`, `startup_shader_cache_rekey_cli` | exit 0, same as on main | | `native_compile_dxil_rekey`, `native_rtv_variant`, `native_startup_request_cache`, `startup_indirect_mesh_cache`, `startup_mrt`, `startup_rect_gap` | not run: they need Windows binaries (same usage refusal on main) | | `ctest --preset dev --no-tests=error -R '^startup_shader_cache_key$' -V` | not run: no Windows | Mutations. Each was applied to a byte copy of `gfx2hlsl.py`, run against the key check, and restored (sha256 verified): | Mutation | Result | |---|---| | `load_request` ignores `.ps57in` (the behaviour on main) | fails: `unsupported: shader request source key mismatch` on the first slot 57 case | | `read_slot57_entry` accepts any record | fails: the 11-byte record translates (`ok`) | | no conflict check | fails: `pixel input description names another pipeline` instead of the conflict diagnostic | | `pipeline_key` ignores `slot57_entry` | fails at the known-answer assertion | | record folded before the `.psin` masks | passes. Equivalent: a request with both records is refused before hashing | The new known answers (`0x9ffda271506f7dc6`, `0x06315afc32bae986`) come from `x2w::graphics_request_key`, run in a separate driver built with g++ 14.2 against `src/shader_compute_request.cpp`. The same driver reproduces the existing plain and `.ia` answers (`a837b162afd547ce`, `6d5c0b7786182e0e`). Its `read_graphics_request` accepts the keyed synthetic request and refuses the unkeyed one and the short, long, mistagged and empty records, as gfx2hlsl now does. ## Evidence and follow-up The fixture uses the test's existing source-built VS/PS/root blobs and synthetic records. It needs no GPU, compiler or game files (`X2W_FXC=''`, manifest only). Local data from a console executable (SHA-256 `e95020b2fa4a721d…`). These are Wine results only: Proton Experimental 11.0-20261123b with vkd3d-proton 30b0eb9b on an NVIDIA GeForce RTX 4070 Ti SUPER, driver 550.163.01, no debug layer, no Windows build. Nothing here was measured on Windows. - **Offline**, on copies of the 9 graphics requests with `.ps57in` that a run on main refused: main's gfx2hlsl (f1236fd3) gives 9 × `shader request source key mismatch`. With this change: 9 `ok`, 0 `.fail`. The HLSL equals what the cache held for the same stages under keys without the record (18/18 files). The manifests match too (9/9, key names normalised, line endings ignored). - **Runtime**: build of ea68a605 (runtime identical to f1236fd3), run with `--render --translate` from a fresh copy of the same starting cache. At about 3 minutes, `translate.txt` has 9 × `ok` (exactly the 9 keys above), 0 key mismatches, and `pipelines translated 11 / missing 0`. At 4800 executes there were 90495 translated draws and 6134 not drawn, and the not-drawn count stopped growing after about 2100 executes. The runtime still logs the 9 native refusals; the gfx2hlsl results load after them through the manifest retry. The presented surface's mean level went from 0.00 to 91.82 after about frame 2370. - **For comparison**, the same starting cache on main 1a0120ba read `pipelines translated 2 / missing 9`, with 9 key mismatches and 8400 translated / 167263 not drawn at 8400 executes. The mean level stayed at 0.00. Between 1a0120ba and f1236fd3 neither `gfx2hlsl.py` nor `shader_compute_request.cpp` changed, and the `d3d12_draw.inl` changes don't touch request keys. I did not run f1236fd3 without this change. Not covered: `tools/startup/shader_cache_rekey.py` neither hashes nor copies `.ps57in`, so it does not handle these requests correctly. That is the same on main and would be a separate change. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted
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!3448
No description provided.