From d0e8f9285e912753f462e648bc46f80652299e63 Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Tue, 1 Dec 2026 12:36:08 +0000 Subject: [PATCH] tooling: replay revision 28 compute request archives Refs #2182 gfx2hlsl.compute_key now takes an explicit revision. load_compute_request checks the current 29cs key and then the archived 28cs key, like read_compute_request in src/shader_compute_request.cpp, and keeps the same "compute request files do not match the key in their name" refusal when both miss. The graphics path and the other revisions are unchanged. The regression builds Case A with a revision-28 key, checks the key against the runtime length-framed chain, translates it manifest-only, and checks that a revision-28 request altered after naming is refused. Commands and results: - python -B tests/startup_compute_translate_check.py exit 0: revision-28 replay and altered revision-28 refusal; 5 malformed requests refused; renamed/incomplete requests refused; done tests pass. - python -B tests/startup_shader_cache_revision_check.py exit 0: PASS. - python -B tests/startup_shader_cache_rekey_check.py exit 0: all checks passed. - python -B tests/startup_shader_cache_rekey_cli_check.py exit 0: 4 tests OK. - python -B tests/startup_compute_request_offline_check.py exit 0: key vector, pending/refusals checks pass. - python -B tests/startup_tools_lint_check.py tools/startup exit 0: PASS, 26 files parse. - ctest --preset dev --no-tests=error -R '^startup_compute_translate_requests$' not run: the new worktree has no out/build/dev; no full build was started. --- tests/startup_compute_translate_check.py | 46 +++++++++++++++++++----- tools/startup/gfx2hlsl.py | 19 +++++++--- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/tests/startup_compute_translate_check.py b/tests/startup_compute_translate_check.py index 069b6b2a9d..e979c8eaee 100644 --- a/tests/startup_compute_translate_check.py +++ b/tests/startup_compute_translate_check.py @@ -5,10 +5,12 @@ Request checks: cache files are written here with gfx2hlsl.compute_key. Case A of startup_gfx2hlsl_compute_check.py, with a 28-byte state block A carrying its group size and COMPUTE_PGM_RSRC2, -translates (manifest only, X2W_FXC empty) to a `stage cs` manifest. Each malformed request is refused into -.fail with no manifest: code of 0 bytes or not whole dwords, code without s_endpgm, a part whose length -disagrees with the size words in .desc, files that do not hash to the key in their name, a state block A that -is not 28 bytes, and a missing part (the .fail text names no path). +translates (manifest only, X2W_FXC empty) to a `stage cs` manifest. The same case keyed with the revision-28 +hash replays through the same path, while a revision-28 request altered after naming is refused with the +key-mismatch reason. Each malformed request is refused into .fail with no manifest: code of 0 bytes or not +whole dwords, code without s_endpgm, a part whose length disagrees with the size words in .desc, files that do +not hash to the key in their name, a state block A that is not 28 bytes, and a missing part (the .fail text +names no path). e2e: the stand-in publishes case A, gfx2hlsl.py --pending translates it with DXC, and offscreen_check dispatches the published .cs.cso and compares all 320 words with that test's expectation. This proves the plumbing @@ -27,17 +29,20 @@ from startup_compute_request_check import DATA, STATE_B, prepare, run from startup_stream_check import gfx2hlsl as G +REVISION_28 = b'x2w-startup-shader-28cs' + def state_a(group, rsrc2): # Dword 3 holds X and Y, dword 4 holds Z and the wave32 bit, and dword 6 holds COMPUTE_PGM_RSRC2. return struct.pack('<7I', 0, 0, 0, group[0] | group[1] << 16, group[2] | (1 << 20), 0, rsrc2) -def write_request(cache, code, state, data=DATA, root=None, desc_sizes=None): +def write_request(cache, code, state, data=DATA, root=None, desc_sizes=None, revision=None): root = C.root_blob() if root is None else root sizes = desc_sizes or (len(state), len(STATE_B), len(code), len(data)) desc = struct.pack('<12Q', 0, 0, sizes[0], 0, sizes[1], 0, sizes[2], 0, sizes[3], 0, 0, 11) - key = G.compute_key(code, data, root, desc, state, STATE_B) + extra = {} if revision is None else {'revision': revision} + key = G.compute_key(code, data, root, desc, state, STATE_B, **extra) for ext, part in (('.desc', desc), ('.sa', state), ('.sb', STATE_B), ('.data', data), ('.root', root), ('.c67', code)): (cache / ('req_%016x%s' % (key, ext))).write_bytes(part) return key @@ -55,6 +60,29 @@ def check_requests(directory): assert manifest.startswith('x2w-manifest 2\nstage cs\ngroup 2 3 4\n'), manifest assert '[numthreads(2, 3, 4)]' in (cache / ('%016x.cs.hlsl' % key)).read_text() + # Revision-28 archives remain replayable, as src/shader_compute_request.cpp read_compute_request accepts the + # revision-28 hash after the current one. Case A keyed with that revision translates the same way. + key28 = write_request(cache, words, good, revision=REVISION_28) + assert key28 != key + legacy = G.fnv(REVISION_28) + for ext in ('.c67', '.data', '.root', '.desc', '.sa', '.sb'): + part = (cache / ('req_%016x%s' % (key28, ext))).read_bytes() + legacy = G.fnv(part, G.fnv(struct.pack('cs' literal and must keep seeing COMPUTE_REVISION alone. The runtime still accepts +# revision-28 archives (src/shader_compute_request.cpp read_compute_request). +COMPUTE_REVISION_28 = 'x2w-startup-shader-28cs'.encode('ascii') + + +def compute_key(cs_code, data, root_blob, desc, state_a=b'', state_b=b'', *, revision=COMPUTE_REVISION): """The runtime key of a device slot 67 compute request (req_.c67, .data, .root, .desc, .sa, .sb): the graphics revision followed by "cs", then each part preceded by its length as a little-endian u64: the code, the words 7-8 blob, the root signature, the 12 description words with their pointers zeroed and the two - state blocks.""" - key = fnv(b'x2w-startup-shader-29cs') + state blocks. revision names the hash revision: the current one by default, revision 28 when replaying an + older archive.""" + key = fnv(revision) for part in (cs_code, data, root_blob, desc, state_a, state_b): key = fnv(part, fnv(struct.pack('