Skip to content

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

Merged
tedin7 merged 1 commit into
R0Y00:mainfrom
JohnConnorNPC:startup/gfx2hlsl-slot57-entry-key
Nov 29, 2026
Merged

tedin7 merged 1 commit into
R0Y00:mainfrom
JohnConnorNPC:startup/gfx2hlsl-slot57-entry-key

Conversation

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Change

Since #3094 (71844ba), 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 ea68a60 = main f1236fd + 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 (f1236fd) 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 ea68a60 (runtime identical to f1236fd), 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 1a0120b 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 1a0120b and f1236fd neither gfx2hlsl.py nor shader_compute_request.cpp changed, and the d3d12_draw.inl changes don't touch request keys. I did not run f1236fd 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

The runtime and the native request reader fold req_<key>.ps57in into a
slot 57 pipeline's key (71844ba). gfx2hlsl did not, so it refused every
such request with "shader request source key mismatch". pipeline_key now
hashes the record's 12 bytes as stored, after .ia. load_request reads and
validates the record and refuses a request that has both .psin and .ps57in.
The translation does not read the record's values.

startup_shader_cache_key covers the new identity with known answers from
the C++ reader. It also runs in the Linux Python job now.
@tedin7
tedin7 merged commit 20bd155 into R0Y00:main Nov 29, 2026
5 checks passed
Ammmae0x added a commit to Ammmae0x/Xbox2Windows that referenced this pull request Nov 29, 2026
…the remaining gaps

R0Y00#3448 already hashes .ps57in into pipeline_key (read_slot57_entry /
slot57_entry) and R0Y00#3449 already made the launcher default to
X2W_NATIVE_SHADERS_ONLY=1, so this branch drops its duplicate
read_ps57_inputs and its run.ps1 edits and keeps only what main lacks:
request_ps_inputs takes the pixel input masks from the entry and
validates its layout, translate_request writes no .psdep for an entry,
shader_cache_rekey carries .ps57in, and cached_translation reuses a
cached plain-key translation outside native-shaders-only mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants