Repository navigation
shader: clear the lane-mask mark on scalar writes of descriptor data in gfx2hlsl (Part of #1723) - #2795
Open
Miffedrandir wants to merge 3 commits into
Open
shader: clear the lane-mask mark on scalar writes of descriptor data in gfx2hlsl (Part of #1723)#2795Miffedrandir wants to merge 3 commits into
Miffedrandir wants to merge 3 commits into
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
reviewed
Nov 26, 2026
tedin7
left a comment
Collaborator
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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