startup: apply .ps57in pixel masks, carry .ps57in through rekey, and reuse cached plain-key translations #3410
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3410"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-28T23:10:18Z.
Fixes #3385
With
-NativeShaders, ordinary direct graphics pipelines stopped translating:cached_translationappended thePSI1slot 57 entry to every graphics key, so a translation already cached under the plain key never hit, and the Python fallback refused the suffixed request because it never read.ps57in(shader request source key mismatch).#3448 (
ea68a605) already landed the key half of that onmain:read_slot57_entryandpipeline_key(..., slot57_entry=...)hash the entry bytes into the key, and the request reader refuses a malformed entry. #3449 already made the launcher default to native-shaders-only mode. This PR mergesorigin/main(5de0b114, merge commit1fdd1f7f, no force-push) and is cut down to the three piecesmainstill lacks:tools/startup/gfx2hlsl.py(request_ps_inputs+.psdepguard): takes the pixel input masks from the entry throughmain'sread_slot57_entry— the entry's address is both masks, as the native fixed entry builds them — refuses a request with both.psinand.ps57in, validates the entry's layout (address 2 or0x8002with 1 to 7 interpolants, as inprepare_direct_graphics), and verifies the suffixed key. No.psdepis recorded for a slot 57 entry, since its bytes are part of the key. The native path additionally bounds the interpolant count by the pixel interface's attribute count, which the Python fallback cannot know; that bound stays native-only.tools/startup/shader_cache_rekey.py: carries.ps57ininPARTS/OPTIONALand passesslot57_entry=entrytopipeline_keyincurrent_key(), so a rekeyed slot 57 request is written under its suffixed key with the entry copied unchanged instead of under the plain key with no entry. A request with both records is refused.src/startup_stubs/d3d12_draw.inl(cached_translation): when a translation is already published under the plain key, reuse it instead of suffixing the key. Only a cold pipeline keeps the entry in its key. The reuse is skipped whennative_shaders_only()is true.What each piece does on the default launcher path vs
-Translate(@JohnConnorNPC SHOULD #1): since #3449,run.ps1/run.shsetX2W_NATIVE_SHADERS_ONLY=1unless-Translateis given. In that mode thecached_translationplain-key reuse is skipped (!native_shaders_only() && cache_path(...)), andload_translationnever reads a.txtmanifest, so the masks and the reuse only change-Translateruns. The.ps57inentry itself is built only whenX2W_NATIVE_SHADERSis set; on a-Translaterun that variable comes either from-NativeShadersor from what a previous run in the same PowerShell session left behind.tools/startup/run.ps1is untouched by this PR (zero diff againstmain).Tests:
tests/startup_gfx2hlsl_ps57in_check.py(new, CTeststartup_gfx2hlsl_ps57in): suffixed-key known answer, suffixed request translates and applies the entry masks, plain request still translates without them, address 2 and 7-interpolant entries translate, RTV variant of a suffixed request translates, rekey copies the entry, and negative controls (bad-layout addresses, 0 and 8 interpolants, bad prefix, short and 13-byte entries, both records, entry under the plain key, wide address, bad rekey). Mesh57 native requests still translate. The check also pins thecached_translationguard with in-test mutants.tests/startup_shader_cache_key_check.py: the slot 57 block's "translation does not read the record's values" case is replaced — an address outside the fixed entry's layout (address 3) under its own key is now refused asinvalid slot-57 pixel entry layout, sincerequest_ps_inputsreads the address and count. The key still hashes the record as stored, and a key-mismatched entry is refused byload_requestasshader request source key mismatch.Checks run on Linux (this host cannot run Windows CTest or
compile_dxil):python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linuxwith the affected checks — all 61 checks passedpython -B tests/startup_translator_check.py— 0 failedpython -B tests/startup_gfx2hlsl_watch_check.py— passedpython -B tests/startup_gfx2hlsl_refusals_check.py— passedpython -B tests/startup_archive_requests_check.py— passedpython -B tests/startup_flat_param_check.py— passedpython -B tests/startup_mesh57_skeleton_check.py— passedpython -B tests/run_checks_parallel_check.py— okpython -B tests/form_coverage_check.py— passed (throwaway venv, needsiced-x86)python -B tests/docs_links_check.py— passed (175 Markdown files, 711 links)python -B tests/bidi_controls_check.py— passed (2670 files)py_compileon the touched Python files — okgit merge-tree --write-tree origin/main HEAD— exits 0;git diff --check— cleanSpot mutations (on sandbox copies outside the repo, each restored after), each made the new check fail as expected: dropping the layout validation in
request_ps_inputs(bad-layout entries then translate); dropping the.ps57infile check from the.psdepguard (the suffixed request then writes a.psdepand is no longer complete); dropping the entry branch from rekeycurrent_key(the entry is not copied under the suffixed key); removing!native_shaders_only() &&from the plain-key reuse guard; and dropping the mutual-exclusion check inrequest_ps_inputs(both records are then accepted there;load_requeststill refuses them).Not verified here: Windows CTest,
compile_dxil, and the native graphics draw path; those are for the WIN-VERIFY run.Review feedback addressed (@Leyukaka, @JohnConnorNPC):
main'sread_slot57_entry/slot57_entry(#3448) and kept only the three gaps above; the duplicateread_ps57_inputsand therun.ps1edits are dropped, andrun.ps1has zero diff againstmain. The layout check (address 2 or0x8002, 1 to 7 interpolants) lives inrequest_ps_inputs, as asked.mainare resolved by merge (no force-push); the PR builds onmain's reader, with no second reader. SHOULD #1: the default-path vs-Translatebehaviour is stated above. SHOULD #2: theshader_cache_rekey.pypart is kept as its own piece, as above.X2W_NATIVE_SHADERS_ONLY=1keep the.ps57inentry in the key.Windows Verification
1fdd1f7fb1e3261df9780a82c298fb0e1c00639cdev:ctest --preset dev --no-tests=error -R '^(startup_gfx2hlsl_ps57in|startup_shader_cache_key|startup_tools_lint)$' --output-on-failure->3 passed, 0 failed(2.27s); also^(startup_shader_cache_rekey|startup_translator|startup_run_ps1)$->3 passed, 0 failed(40.91s)release:ctest --preset release --no-tests=error -R '^(startup_gfx2hlsl_ps57in|startup_shader_cache_key|startup_tools_lint)$' --output-on-failure->3 passed, 0 failed(1.97s)form_coverage_check.py,docs_links_check.py(175 Markdown files, 711 links), andbidi_controls_check.py(2666 files) passed.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T23:53:29Z.
Reviewed
ec57297dby its diff. The Python key and translation follow the runtime's order for.ps57in(entry built atd3d12_draw.inl:1161-1173, key and write incached_translation,:652-664), and the mesh path is untouched (with a control). Points:X2W_NATIVE_SHADERS_ONLY=1. In that mode.txtmanifests are ignored, but the reuse guard still looks for one, so a leftover Python manifest strips the entry from the request the native path receives. The native path then either translates a reflected pair without the packed position or refuses it withraw graphics requires its captured pixel entry. Skipping the reuse whennative_shaders_only()would avoid it.0xffffwith enable equal to address and ignores the interpolant count and control flags; the native path accepts only address 2 or0x8002with 1 to 7 interpolants. Refusing the rest would keep both paths aligned.translate_request(the.psdepcondition),'req_%016x.ps57in' % basechanged to% key(an RTV variant gets a.psdep, is refused on the next watcher pass and its.txtremoved); ind3d12_draw.inl,(pixel_entry.empty() ||changed to(slot57_entry.empty() ||(a 0-byte.ps57inunder the warm plain key; the C++ guard is only checked by source text); inread_ps57_inputs,len(entry) != 12changed to< 12(a 13-byte entry raisesstruct.errorout oftranslate_request, recorded astranslator errorinstead of the named refusal).A start-up run with
-NativeShaderson main and on this head, from copies of the same warmed cache, would show how many slot 57 pixel stages get a translation and how many are reused under the plain key.Point 1 should be fixed before merge; 2-4 at the author's choice.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-29T00:49:39Z.
Addressed in
24755d1f(thanks @Leyukaka for the thorough diff review):X2W_NATIVE_SHADERS_ONLY=1):cached_translationinsrc/startup_stubs/d3d12_draw.inlnow skips plain-key reuse whennative_shaders_only()is true, pinned with a failing mutant intests/startup_gfx2hlsl_ps57in_check.py.read_ps57_inputsnow refuses entries outside the native fixed-entry layout (SPI_PS_INPUT_ADDR2or0x8002,1..7interpolants), with positive (2,7) and negative (0x8003,0/8,1,0x10002) controls.X2W_NATIVE_SHADERS_ONLY=1keep.ps57inin the key..psdepabsence (% basevs% key),(pixel_entry.empty() ||vs(slot57_entry.empty() ||inguard_problems(), and a 13-byte.ps57inrefusal (len(entry) != 12vs< 12).Windows verification (
24755d1f,dev&release):5/5passed (0failed,0skipped) in both presets (46.06s/36.80s) plusform_coverage_check,docs_links_check, andbidi_controls_check(3/3passed).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T01:24:58Z.
Review: APPROVED
Re-read
24755d1fby its diff (ec57297d...24755d1f, 3 files) and the full diff against the merge base.cached_translationskips the plain-key reuse whennative_shaders_only()(d3d12_draw.inl:665), so the entry stays in the key and in the request in that mode, as on main. Pinned by source text with the mutantnative-shaders-only guard removed.read_ps57_inputsnow refuses anything but address 2 or0x8002with 1 to 7 interpolants. The native path additionally checks the count against the reflected pixel interface's attribute count and the address against its reflected input address (src/direct_compute_cache.cpp:723-728). The Python reader has no reflected interface, so that part stays native-only, as the body says. No change requested..psdepfor the RTV variant of a suffixed request, the(pixel_entry.empty() ||pin with the mutantpublish gated on the wrong entry, and the 13-byte entry refused asinvalid slot-57 pixel entry record.Not covered: the
cached_translationchange is checked by source text only, andstartup_gfx2hlsl_ps57inis not in theprtest preset, so on this PR CI runs it in the Linux Python job only (tests/checks/python-linux/); the Windows results are the ones reported in the body. No-NativeShadersrun comparing main and this head on a warmed cache.Approving
24755d1f.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T12:50:08Z.
#3448 (
ea68a605) is onmainand already hashes.ps57inintopipeline_key(read_slot57_entry,slot57_entry=b'').git merge-tree --write-tree origin/main 24755d1f(main77d1ba4d) now conflicts intools/startup/gfx2hlsl.py(3 regions:pipeline_key, the key check in the request reader,read_ps57_inputsagainstread_slot57_entry) and intools/startup/run.ps1(#3449 rewrote the-NativeShadersblock where this branch savesnativeShadersBefore).What main still lacks from this branch:
request_ps_inputs) and the layout check (address2or0x8002, 1 to 7 interpolants); main'sread_slot57_entrychecks only the size and thePSI1tag and does not read the values;.ps57ininPARTSandOPTIONALoftools/startup/shader_cache_rekey.py;cached_translation(src/startup_stubs/d3d12_draw.inl), which this branch skips whenX2W_NATIVE_SHADERS_ONLY=1; since #3449run.ps1sets that unless-Translateis given.Could you rebase onto main's
read_slot57_entry/slot57_entryand keep only these?Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T12:55:30Z.
Review of
24755d1fagainst main77d1ba4d. Verdict: hold. This is superseded in its main fix by #3448 (merged as20bd1553, commitea68a605). I'd close it, or cut it down to the parts main still lacks. Leyukaka's comment above already lists those parts and the conflict regions, so I won't repeat them.MUST
git merge-tree --write-tree --name-only origin/main 24755d1f→CONFLICT (content): Merge conflict in tools/startup/gfx2hlsl.pyand... in tools/startup/run.ps1. The.ps57inkey and refusal fix is already on main:git show origin/main:tools/startup/gfx2hlsl.py | grep -n 'def read_slot57_entry\|def pipeline_key'→def pipeline_key(vs_code, ps_code, root_blob, layout=b'', ps_inputs=None, slot57_entry=b''):anddef read_slot57_entry(path):. A rebase should build on those, not add a second reader (read_ps57_inputs) with a different contract.SHOULD (for the cut-down version)
run.ps1/run.shsetX2W_NATIVE_SHADERS_ONLY=1unless-Translateis given. In that mode thecached_translationplain-key reuse is skipped (!native_shaders_only() && cache_path(...)), andload_translationnever reads a.txtmanifest (if (manifest.empty() && native_shaders_only()) { tr.manifest_retry.found(); return; }). So the mask application and the reuse only change-Translateruns. The.ps57inentry itself is built only whenX2W_NATIVE_SHADERSis set (if (GetEnvironmentVariableW(L"X2W_NATIVE_SHADERS", nullptr, 0) && ...). On a-Translaterun that variable comes either from-NativeShadersor from what a previous run in the same PowerShell session left behind.shader_cache_rekey.pypart is a real gap on main and stands on its own.git show origin/main:tools/startup/shader_cache_rekey.py | grep -n "PARTS = "→PARTS = {'g': ('.b', '.root', '.ia', '.psin', '.a'), ..., andcurrent_keycallspipeline_key(...)without the entry. A rekeyed slot 57 request is therefore written under its plain key with no.ps57in. A small PR with just that change and its control would be easy to review.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-29T15:42:31Z.
Rebased onto
upstream/main(5de0b114, merge commit1fdd1f7f) per@Leyukakaand@JohnConnorNPC:read_ps57_inputsreader (usingmain'sread_slot57_entry/pipeline_key(..., slot57_entry=...)from#3448) and dropped alltools/startup/run.ps1edits (zero diff againstmain).SHOULD #1): Kept (1)request_ps_inputslayout check (2/0x8002,1..7interpolants) and.psdepguard intools/startup/gfx2hlsl.py, (2).ps57incarry-over intools/startup/shader_cache_rekey.py, and (3)!native_shaders_only()plain-key reuse insrc/startup_stubs/d3d12_draw.inl, with default (X2W_NATIVE_SHADERS_ONLY=1) vs-Translatebehavior documented in the PR body.1fdd1f7f): Passedd3d12_xs_shimbuild +3/3indev(2.27s) andrelease(1.97s), plusstartup_run_ps1/startup_translator/startup_shader_cache_rekey(3/3,40.91s) and repo Python checks (175docs /2666files).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T16:08:00Z.
Re-review of
1fdd1f7fagainst maincf0c30af, delta only. Verdict: good to merge. 0 MUST. The merge resolved the conflicts I flagged earlier and dropped the duplicate reader.git merge-tree --write-tree origin/main 1fdd1f7fexits 0 (treea56a683e). No change on main since the merge base touchesgfx2hlsl.py,shader_cache_rekey.py,d3d12_draw.inl,direct_compute_cache.cpporstartup_shader_cache_key_check.py(git diff --stat 5de0b114 origin/main -- <those files>is empty).What it still adds after #3448
request_ps_inputs). The layout check matches the native fixed entry.prepare_direct_graphicsalso reads the whole second dword as the count (!interpolants || interpolants > 7), accepts address2or0x8002and buildspsin1with the address twice. The PR does the same:masks = (address, address)..ps57in. Main'sPARTS['g']is('.b', '.root', '.ia', '.psin', '.a'), so main's rekey neither reads nor copies the entry. After a revision bump it would write every suffixed slot-57 request under its plain key, without the entry, and a runtime withX2W_NATIVE_SHADERSset would then miss all of them. This PR fixes that. It only helps caches whose requests have.ps57infiles, though.cached_translation. On the default launcher path this is inert (X2W_NATIVE_SHADERS_ONLY=1). It is active on-Translate/--translateruns withX2W_NATIVE_SHADERSset.Measured on a local warmed cache. A runtime that left the slot-57 entry out of the key built this cache. After #3448, a
--translaterun withX2W_NATIVE_SHADERSset missed 12 slot-57 pipelines. For each one I recomputed the plain key from the run's suffixed request files with this branch'spipeline_keyand looked it up in the source cache (read-only):pipeline_key(..., slot57_entry=entry).<key>.txt, and 10 of them loggedtranslatedin an earlier run of the same cache..ps57infiles, andcurrent_keyon each plain request returns the plain key (0/12 move to the suffixed key).2and 3 have0x8002, with 1 to 4 interpolants.So the reuse would have hit all 12 at pipeline creation. That part is inference: I did not run it. The rekey part would not have changed this cache. Without the reuse, the run skipped those pipelines' draws until the background translator landed them, and 3 had not landed by exit.
Tests:
tests/startup_gfx2hlsl_ps57in_check.py→startup gfx2hlsl ps57in: 0 failed.tests/startup_shader_cache_key_check.py→startup shader cache key checks: passed. Both pass on agit archiveof the PR head and on the merge-tree result. Mutants, each run on a copy:request_ps_inputs→ 10 FAIL (first:entry with another address is refused: got 'ok').if entry:branch in rekeycurrent_key→ 2 FAIL (rekey copies the entry unchanged: got None).CI on
1fdd1f7f: Windows build and test, Linux Python checks and gfx1013 fixtures all pass.SHOULD
const bool base_cached = !native_shaders_only() && cache_path(base_path, ...) && GetFileAttributesW(base_path) ...runs before thetranslation_by_key()lookup. So every new slot-57 pipeline object in that mode probes the cache root, including a repeat of a key already in the map. For a cold key the probe is a miss.src/startup_stubs/cache_index.hsays a missing name in a cache of ~274k entries costs ~155 ms under Wine, which is whynative_mesh57.inlaskscache_lookup(...) == CacheLookup::absentfirst.cache_lookup(L"", key, L".txt") != x2w_startup::CacheLookup::absent && GetFileAttributesW(...)would keep the hit and skip the miss. A.txtwritten by another process during the run would read absent until the next process, which only means it takes the suffixed key, as today. I did not measure the added time.NIT
load_translationfinds the manifest, andtranslation_for_targetsonly callstry_native_graphicswhenmanifest_retry.pending() || native_shaders_only(). So on a hit the native path does not run.0x8002entries, instead of the masked one this PR adds.AI-assisted.