Repository navigation
shader: clear the lane-mask mark on scalar writes of descriptor data in gfx2hlsl (Part of #1723) - #2795
Conversation
…in gfx2hlsl Scalar ALU on descriptor data (an s_mov of a descriptor word, a field extract or mask of one, an s_add_u32 to a descriptor pointer) records only a symbol for its destination and skipped set_s, so the destination kept a lane-mask mark from an earlier write. The stride clamp of a structured-to-raw conversion (s_bfe_u32 sN, desc, 0xe0010 then s_max_u32 sN, sN, 1) then read as a lane-mask read. The descriptor-data path now clears the mark on its destination SGPRs before writing them; lower() has already classified the sources, so a mask read by the same instruction is treated as before. Part of R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sir6MraM8AjP6AcLDr3paU
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sir6MraM8AjP6AcLDr3paU
tedin7
left a comment
There was a problem hiding this comment.
Review of head eb86524 (comment only, no approval).
What is good
- The fix is small and in the right place:
tools/startup/gfx2hlsl.py:5313clearsmasksandmask_highon the destination SGPRs of the descriptor-data path.lower()classifies the sources first, so an instruction that really reads a mask as a number is still refused. - The new checks in
tests/startup_gfx2hlsl_mask_overwrite_check.pycover ps and vs, the four scalar forms (s_mov, s_bfe_u32, s_and_b32, s_add_u32 pointer add), the s_bfe_u32 + s_max_u32 stride clamp, and a control (write into s8 keeps the mark on s6). - Mutation: replacing the
masksdiscard withpassmakes the check fail (6 failures). The control and the refusal tests from #2122/#2702 still pass.
What is missing
- No real D3D12 WARP readback vs CPU reference. Before this change the stride clamp program was refused; now it translates, so a new HLSL path is emitted for it (s_bfe_u32 then s_max_u32 on a register that earlier held a v_cmp result). The current tests only check Python mask bookkeeping. Please add one case to an existing WARP-based gfx2hlsl check (for example next to
tests/startup_gfx2hlsl_desc_vcc_check.py): compare, then s_bfe_u32 of a descriptor word, then s_max_u32 with 1, store the result, read it back from WARP and compare it with a CPU value. A control where the clamp reads a real mask must still be refused. - Overlap to settle: #2784 (a 32-bit integer scalar result ends the lane-mask tag of its register) touches the same mark-clearing area. Different slice (numeric results vs descriptor data) but please confirm with @R0Y00 / the #2784 author that the two do not collide in
set_sand the descriptor path.
Checks run locally on the worktree at this head (0 commits behind main):
- python3 tests/startup_gfx2hlsl_mask_overwrite_check.py -> ok
- python3 tests/docs_links_check.py -> ok
- python3 tests/bidi_controls_check.py -> ok
- git diff --check origin/main...HEAD -> clean
- one code mutation of the new line -> new check fails as expected
CI was still pending at review time and no Windows run was done, so this is not a merge decision. Merge stays after the WARP readback case is added.
AI-assisted; commands listed were executed locally.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sir6MraM8AjP6AcLDr3paU
… in its register Case I-raw-mask of startup_gfx2hlsl_compute_check writes a lane mask into s21 with v_cmp_gt_u32_e64, then extracts and clamps the store descriptor's stride into s21 and stores as case A. The WARP and hardware dispatches compare all 320 words with the CPU reference. Control: s_max_u32 of the mask itself stays refused. On the translator without the descriptor-data mark clear, the case is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. Pushed WARP readback. On the current translator the extract and the clamp emit no HLSL: the clamped stride stays a symbol, and a numeric read of it is refused (
Windows 11 26200, MSVC Build Tools 2022, DXC 10.0.26100:
#2784. That PR has since been withdrawn, so there's no collision in |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 9ef253d1 (the author's 6b08636e updated with main; comment review, no approval). The PR's own diff is unchanged by that update (4 files, +68/-2).
The earlier request (a real WARP readback) is met. Case I-raw-mask in tests/startup_gfx2hlsl_compute_check.py is a real dispatch: CASES.items() feeds the dispatch mode, which compiles the translated HLSL with DXC cs_6_0, runs it on the adapter and compares every output word with the CPU reference (expected('A')). The program is: compare into s21, descriptor stride extract, s_max_u32 s21, s21, 1, the rest of the structured-to-raw conversion, then case A's store. The translated HLSL differs from I-raw only by the dead compare line, and the controls assert exactly that one extra line. So the readback proves the clamped conversion now stores the same words as before, not just that the Python mark is cleared.
It fails without the fix. I removed the masks.discard on the destination in tools/startup/gfx2hlsl.py. Then:
python3 -B tests/startup_gfx2hlsl_compute_check.py(controls) stops withUnsupported: s_max_u32 reads lane mask s21 as numeric data, soI-raw-maskcannot even translate;python3 -B tests/startup_gfx2hlsl_mask_overwrite_check.pyreports failures (7 lines with "fail").
Restored withgit checkout -- ..
The refusal stays. The new control s_max_u32 s21, s21, 1 straight after the compare (the instruction really reads the mask) is still refused. lower() classifies the sources before the new discard runs, so a real mask read is not hidden.
Scope. The code change is 8 lines at tools/startup/gfx2hlsl.py (descriptor-data path): it clears the lane-mask mark and the wave64 high-word mark on the destination SGPRs only, as set_s does. #2784 was withdrawn, so the overlap I raised before is gone.
Commands run (Linux)
python3 -B tests/startup_gfx2hlsl_compute_check.pyrc=0;python3 -B tests/startup_gfx2hlsl_mask_overwrite_check.pyrc=0python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: clean- one mutation of the new code, as above: both checks fail
The Windows Server 2025 WARP receipt follows in a separate comment. Real-GPU run not available (RunPod stopped).
AI-assisted; commands listed were executed locally.
|
Win2025 WARP receipt for head 9ef253d (the author head 6b08636 updated with main; the PR diff is unchanged). Includes the new case I-raw-mask in startup_gfx2hlsl_compute_warp. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
Change
Part of #1723.
Scalar ALU on descriptor data in
tools/startup/gfx2hlsl.pyrecords only a symbol for its destination and never callsset_s. That covers ans_movof a descriptor word, a field extract or mask of one (the structured-to-raw conversion of #2546), and ans_add_u32to a descriptor pointer throughpointer_add. Since #2122,set_sis what clears a register's lane-mask mark, so these writes kept a mark left by an earlierv_cmp/saveexec into the same SGPR.Since #2702, a scalar instruction that reads a lane mask as a number is refused. So the stride clamp of a structured-to-raw conversion in a register that once held a mask was refused, even though the register holds a descriptor field:
The descriptor-data path now clears the mark (and the wave64 high-word mark) on its destination SGPRs before writing them.
lower()classifies the sources before_lower()runs, so an instruction that itself reads a mask as a number is still refused. Every later branch of the path either writes the destination or refuses the program. The change is 8 lines in one place. It closes the gap the existing docs section listed as not covered ("the other symbol-only scalar writes ... still keep a mark they find").Verification
Base:
700522ef(upstreammain). Windows 11 10.0.26200, Python 3.11 venv fromrequirements-dev.txt. All checks below are pure Python; no GPU involved.python -B tests/startup_gfx2hlsl_mask_overwrite_check.py: all checks ok. New cases, each afterv_cmp_eq_u32_e64 s6, v0, v1, in a pixel and a vertex stage:s_mov_b32 s6, s17,s_bfe_u32 s6, s17, 0xe0010,s_and_b32 s6, s19, 0xcfffffffands_add_u32 s6, s2, 16on descriptor or pointer symbols clear the mark on s6.s_bfe_u32 s6, s17, 0xe0010thens_max_u32 s6, s6, 1is not refused.s_bfe_u32 s8, s17, 0xe0010keeps the mark on s6 (only the destination is cleared).tools/startup/gfx2hlsl.pyat700522effails 6 checks: thes_bfe_u32ands_add_u32clearing checks and the stride clamp (s_max_u32 reads lane mask s6 as numeric data), each in both stages. Thes_mov_b32ands_and_b32cases already pass there.ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_mask_overwrite_controls$': 1/1 passed.windows.yml(203 checks) viatools/run_checks_parallel.py -j 12:startup_run_sh_check,startup_build_rev_check).dxc_cache_check(OSError: [WinError 193]). It fails the same way on unpatchedmainon this machine (a local DXC setup issue), unrelated to this change.docs_links_checkandbidi_controls_check: ok.How it was found: local integration of open PRs
I found this while checking how much a combination of the open translator PRs would help locally captured shader requests (local data, not included; about 3,800 requests, 585 graphics pipelines). The integration branch was
b457f7ffplus a--no-ffmerge of each of these PR heads, re-keyed withtools/startup/shader_cache_rekey.pyand translated withgfx2hlsl.py --pending:startup_image_get_lod_flow_check.py,startup_image_sample_b_flow_check.py); PR side takengfx2hlsl.pyand runtime sourcesmainthen failed (startup_gfx2hlsl_readfirstlane_uniform_check,startup_compute_readfirstlane_check,startup_gfx2hlsl_compute_check), becausemain's newer tests expect refusals the PR acceptsIn that integration, 116 graphics pipelines stopped first at
s_max_u32 reads lane mask sN as numeric data. With this patch none do. They then stop at their next refusal, mostly DPP forms (v_min_u32_dpp,v_subrev_f32_dpp) in pixel programs with branches, so the count of translated graphics pipelines does not change (89 of 585). This PR is based on and verified againstmainonly. It does not depend on any of the PRs above.Evidence and follow-up
v_min_u32_dppand similar) in pixel programs with non-uniform branches are the most common first refusal for the remaining graphics pipelines in the local capture (about 180 of 311 missing).Checklist
docs/experiments.md, "Startup translator: lane-mask marks after a scalar overwrite").This change was AI-assisted (Claude Code).
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sir6MraM8AjP6AcLDr3paU