shader: lower s_quadmask_b64 in gfx2hlsl (#1723) #2670
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2678"
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 SimSalabimse on 2026-11-26T01:46:22Z.
Change
Part of #1723: port
s_quadmask_b64frompixel_aotintotools/startup/gfx2hlsl.py.D.lo;D.hiis 0SCC = (D.lo | D.hi) != 0Independent of open #2642 (
s_quadmask_b32). Base ismain.AI-assisted.
Verification
Commit under test: this PR head.
All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free.
Windows (when available):
Evidence and follow-up
disasm_rdna2/gfx2hlsl.decode; no retail bytes.<< 8→<< 0) diverges from the ISA reference.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:57:43Z.
Review: COMMENTED
Review of head
8cbbdc3d(s_quadmask_b64in gfx2hlsl, Part of #1723).One blocking finding: negative inline constants are zero-extended instead of sign-extended.
op_s_quadmask_b64, immediate branch (tools/startup/gfx2hlsl.py, theimm = re.fullmatch(r'-?(0x...|\d+)', ops[1])block): the value is masked to 32 bits and the high word is taken as 0, for every immediate. For an inline integer constant (decoder prints it as a negative decimal, e.g.-1= SSRC 0xc1) the 64-bit operand is the sign-extended value, sos_quadmask_b64 s[10:11], -1must give all sixteen nibbles non-zero:D.lo = 0xffff. This PR folds it to0x000000ff(andsccfrom that). The repository's own reference does it the other way:tools/pixel_aot.pyscalar_u64()returnsbits = value & 0xfffffffffffffffffor-?\d+tokens (so-1-> hi0xffffffff) and only zero-extends the 32-bit hex literal form (0x[0-9a-f]{1,8}). Same convention ass_mov_b64 exec, -1. The PR text says "A 32-bit SOP1 literal/inline zero-extends"; that holds for the literal, not for the inline negatives -1..-16.Reproduction on the PR head (decode the words, run the handler):
s_quadmask_b64 s[10:11], -1->s10 = 0x000000ffu; s11 = 0u, expected0x0000ffffu;s_quadmask_b64 s[12:13], 0xffffffff->0x000000ffuis correct (literal, hi = 0).Suggested fix: in the immediate branch, if the token is a negative decimal, sign-extend to 64 bits (
bits = value & (2**64 - 1), foldnibble_mask(lo) | nibble_mask(hi) << 8); keep hex literals zero-extended. Add-1(and e.g.-16) to the test's immediate list next to the existing0xffffffffcase; today the CPU reference in the test shares the same assumption, so it cannot catch this. A device readback of a one-instruction program with-1would also guard it.What else I checked (all fine)
D.hi = 0,SCC = D != 0; even-aligned pairs only; lane masks and descriptor-bearing SGPRs refused.s_quadmask_b32already merged (#2642); no other open or merged PR lowerss_quadmask_b64in gfx2hlsl (#2076 was closed).tests/startup_gfx2hlsl_s_quadmask_b64_check.py,..._handler_arity_check.py,..._scalar_table_arity_check.py,tests/docs_links_check.py,tests/bidi_controls_check.pypass;git diff --check origin/main...HEADclean.windows.yml(one list entry,.githubcare noted) andAGENTS.mdupdated.I did not run Win2025 on this head because of the finding above; happy to once it is fixed. Merge left to the maintainers.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:11:34Z.
Review: APPROVED
The negative inline operands now follow the existing 64-bit integer convention. The encoded -1 and -16 cases give 0xffff and 0xfffe, while separate 32-bit literal controls leave the upper eight result bits clear. The SGPR pair, SCC, range and refusal checks pass, as do the existing s_ff0, BFM and scalar-arity checks. The merge keeps both test registrations and the previous negative control. This verifies the source-built scalar semantics; no GPU draw is claimed.