From ea68a605f829d4ff5efb5bc2965cbde7cb24e85b Mon Sep 17 00:00:00 2001 From: JohnConnorNPC <128232619+JohnConnorNPC@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:09:10 +1000 Subject: [PATCH] startup: hash slot 57 pixel entry records in gfx2hlsl request keys The runtime and the native request reader fold req_.ps57in into a slot 57 pipeline's key (71844ba0). 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. --- docs/experiments.md | 11 +++++ .../native-startup-request-cache.md | 4 +- .../python-linux/startup_shader_cache_key.txt | 2 + tests/startup_shader_cache_key_check.py | 46 ++++++++++++++++++- tools/startup/gfx2hlsl.py | 35 ++++++++++++-- 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 tests/checks/python-linux/startup_shader_cache_key.txt diff --git a/docs/experiments.md b/docs/experiments.md index c73393fa35..e7fa723759 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -17698,6 +17698,17 @@ A literal known-answer vector independently executed with the runtime C++ `fnv_b and revision/order (including optional `.ia`) (`src/startup_stubs/d3d12_draw.inl`) prevents a shared Python-key error from silently agreeing in both producer and validator. +A slot 57 request can carry a pixel entry record, `req_.ps57in`: `PSI1` followed by 8 bytes of +fixed graphics state. A native-shader runtime build with `X2W_NATIVE_SHADERS` set writes it. Its 12 +bytes are hashed as stored after the optional `.ia`, as the runtime and `src/shader_compute_request.cpp` +already do. The two known answers for it come from that reader's `graphics_request_key`, built on its +own. The check accepts a request keyed with its record. It rejects a key without the record, a missing +or changed record, and an RTV variant whose base key lacks the record. A short, long, mistagged or +empty record is refused by name even when the key hashes exactly those bytes, and so is a request with +both `.psin` and `.ps57in`. Two different records on the same stages translate to identical HLSL: +gfx2hlsl does not read the record's values. Before this change, gfx2hlsl refused every keyed slot 57 +request with `shader request source key mismatch`. + ```powershell python -B tests/startup_shader_cache_key_check.py ctest --preset dev --no-tests=error -j 1 -R '^startup_shader_cache_key$' -V diff --git a/docs/experiments/native-startup-request-cache.md b/docs/experiments/native-startup-request-cache.md index 85fe9f4c99..9d07ed87b8 100644 --- a/docs/experiments/native-startup-request-cache.md +++ b/docs/experiments/native-startup-request-cache.md @@ -50,7 +50,9 @@ ctest --preset release --no-tests=error -R '^native_compute_pack(_hardware)?$' - Graphics requests validate `x2w-startup-shader-29` or the archived revision 28 over `.a`, `.b`, `.root`, and optional `.ia`. When `req_.psin` is present, the reader parses `psin1 ena=0x addr=0x`, checks that the embedded key matches `` and `(ena & ~addr) == 0`, and folds `b"psin1" + struct.pack(".ps57in` + (`PSI1` and 8 state bytes, 12 in all) is folded as stored, again as `pipeline_key` does. A request with + both records is refused. - Compute requests validate `x2w-startup-shader-29cs` or the archived revision 28 over length-framed `.c67`, `.data`, `.root`, `.desc`, `.sa`, and `.sb` identically to `d3d12_draw.inl:publish_compute_request` and `gfx2hlsl.py:compute_key`. - In raw graphics translation (`src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_graphics.inl`), pixel diff --git a/tests/checks/python-linux/startup_shader_cache_key.txt b/tests/checks/python-linux/startup_shader_cache_key.txt new file mode 100644 index 0000000000..274c6d1ce6 --- /dev/null +++ b/tests/checks/python-linux/startup_shader_cache_key.txt @@ -0,0 +1,2 @@ +# Startup request identity: gfx2hlsl.pipeline_key, including .ia, .psin and slot 57 .ps57in records. +tests/startup_shader_cache_key_check.py diff --git a/tests/startup_shader_cache_key_check.py b/tests/startup_shader_cache_key_check.py index 134cfccf96..f64ddf3e3f 100644 --- a/tests/startup_shader_cache_key_check.py +++ b/tests/startup_shader_cache_key_check.py @@ -17,7 +17,7 @@ BASE_MISMATCH = "shader request source key mismatch" -def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None): +def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None, records=None): with tempfile.TemporaryDirectory() as directory: cache = Path(directory) base = int(rtv_request.split()[1]) if rtv_request else key @@ -25,6 +25,8 @@ def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None): (cache / f"req_{base:016x}{suffix}").write_bytes(data) if layout is not None: (cache / f"req_{base:016x}.ia").write_bytes(layout) + for suffix, data in (records or {}).items(): # pixel input records (.psin, .ps57in) of the base request + (cache / f"req_{base:016x}{suffix}").write_bytes(data) if rtv_request: (cache / f"req_{key:016x}.rtv").write_text(rtv_request, encoding="ascii") # Explicit upstream manifest-only mode; real hashing, parsing and HLSL translation. @@ -47,6 +49,47 @@ def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None): return outputs +def check_slot57_entry(vector, blobs, canonical): + """A slot 57 request's pixel entry record (req_.ps57in) is part of its identity, as stored.""" + # Known answers from x2w::graphics_request_key (src/shader_compute_request.cpp, the native request reader), + # built and run separately: the record's 12 bytes follow the optional .ia bytes with no tag or length, as + # the runtime's cached_translation hashes them. + entry = b"PSI1" + struct.pack(".psin) also hashes its pixel input masks: b'psin1' and then SPI_PS_INPUT_ENA and SPI_PS_INPUT_ADDR as little-endian u32. Two pipelines with the same stages, root signature and input layout but different masks are then two requests with their own results. Without a - description the key is unchanged.""" + description the key is unchanged. + + A slot 57 pipeline whose request has a pixel entry record (req_.ps57in, see read_slot57_entry) hashes + its 12 bytes as stored, last, as the runtime's cached_translation and shader_compute_request.cpp's + graphics_request_key do. This translator does not read the record's values.""" key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-29')))) key = fnv(layout, key) if layout else key - return key if ps_inputs is None else fnv(b'psin1' + struct.pack('.ps57in) as stored, or b'' without the file. + + A native-shader runtime build with X2W_NATIVE_SHADERS set publishes it before .a for a slot 57 pipeline whose + stages are not DXBC containers: b'PSI1' and the + 8 bytes at offset 0x58 of the fixed graphics state, which d3d12_draw.inl reads as SPI_PS_INPUT_ADDR and + SPI_PS_IN_CONTROL. Any other size or tag is refused by name; shader_compute_request.cpp's reader refuses + the same records.""" + if not os.path.isfile(path): + return b'' + with open(path, 'rb') as file: + entry = file.read(13) + if len(entry) != 12 or not entry.startswith(b'PSI1'): + raise Unsupported('invalid slot-57 pixel entry record') + return entry + + def mesh57_key(ms, ps, root): value = fnv(b'x2w-startup-mesh-57-3') for part in (ms, ps, root):