shader: lower 32-bit scalar ALU, comparisons and SCC selects in pixel_aot #254
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/257"
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 Vonsek on 2026-11-21T19:34:42Z.
Change
tools/pixel_aot.pynow lowers gfx1013 scalar ALU instructions that work on uniform 32-bit values. Their sources can be immediates (including float inline constants as bit patterns), constant words loaded withs_buffer_load_dwordx4, and earlier scalar results. Each result becomes an HLSLuintlocal. A vector operand orv_mov_b32reads a scalar result throughasfloat.s_add_u32,s_sub_u32,s_add_i32,s_sub_i32,s_mul_i32,s_min_u32,s_max_u32,s_min_i32,s_max_i32,s_and_b32,s_or_b32,s_xor_b32,s_andn2_b32,s_orn2_b32,s_lshl_b32,s_lshr_b32,s_ashr_i32,s_cselect_b32s_not_b32(s_mov_b32was already supported)s_cmp_{eq,lg,gt,ge,lt,le}_{i32,u32}s_movk_i32was already lowered and is now exercised by a fixtureSCC is tracked as an HLSL boolean expression, following the RDNA definitions: carry or borrow for
s_add_u32ands_sub_u32; signed overflow fors_add_i32ands_sub_i32; the comparison result for min, max ands_cmp_*; a nonzero result for the bitwise and shift forms.s_mul_i32leaves SCC unchanged. A shift uses the low five bits of its count.s_cselect_b32is rejected unless the lowerer saw an SCC write.s_wqm_b64 exec, execand thes_and_b64exec restore clear the tracked SCC, because those instructions also write SCC.The lowerer rejects operands still loading before
s_waitcnt lgkmcnt(0)or destinations those loads will still fill; descriptor words, the texture pointer, lane masks,vcc,exec, VGPRs and unset registers; and destinations other than a plain SGPR. Scalar results are not folded to constants, so they cannot supply a texture address or a sampler word.These neighboring forms remain unsupported and are tested as rejections:
s_addc_u32,s_subb_u32,s_mul_hi_u32,s_absdiff_i32,s_nand_b32,s_xnor_b32,s_bfe_u32,s_lshl1_add_u32,s_abs_i32,s_brev_b32, 64-bit forms,s_cselect_b64,s_cmp_eq_u64,s_bitcmp1_b32,s_cmpk_eq_u32ands_cmovk_i32.A second commit regenerates
docs/coverage/dashboard.svgwithtools/form_coverage.pyandtools/coverage_svg.pyfrom a full Windows run of this branch.Interaction with other open PRs: #232 touches the same README row (one-line conflict); #169 already conflicts with current main and this adds one more
tests/pixel_aot_check.pyhunk to that conflict.Verification
scalar()intests/pixel_aot_check.py: 23 SCC producers, each followed bys_cselect_b32and ans_or_b32into a flag word; 32-bit results mixed into a hash withs_mul_i32/s_add_u32. The 23 flags and a 17-bit fold of the hash are packed into four 10-bit fields exported as1 + k/1024, which binary16 holds exactly, so the comparison is bitwise.scalar_reference()is a Python interpreter written from the ISA definitions, using wide-integer range checks for carry and overflow (the translator uses an XOR-based overflow test). Every flag select takes a different arm between the two constant sets, (−16, 32, 0x80000000, 1) and (5, 5, 0x7fffffff, 0xffffffff), and each of three mutations changes the reference for at least one set:s_ashr_i32→s_lshr_b32,s_cmp_lt_i32→s_cmp_lt_u32, and swappeds_sub_u32sources.pixel_mismatch.tests/pixel_aot_check.py binary ...passes (assembled, wrapped, extracted, disassembled, lowered; HLSL matches lowering the source text).tests/form_coverage_check.pyasserts that all 32 new SOP1/SOP2/SOPC/SOPK forms are counted against bothgfx1013.tsvandrdna2.tsv, and that the rejected neighbors are not. gfx1013 forms counted by the pixel test went from 43 to 75 (SOP1/SOP2/SOPC/SOPK from 4 to 36); gfx1030 changed the same way.tools/pixel_aot.pyreverted to main, both checks fail withUnsupported instruction 22: s_add_u32 s62, s44, s45.ctest --preset dev --no-tests=error -R '^pixel_aot_' -Vat872f529(rebased on maind311159; earlier runs at 1602962 and 38590ab gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed. This is the first DXC compile and D3D12 draw ofscalar(); it needed no changes.pixel_aot_hardwareon an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) andpixel_aot_warpon the Microsoft Basic Render Driver reportpixels=4096 channels=16384 max_absolute_error=0for every draw, including both constant sets ofscalar(), and the three mutations report the expected mismatch. The NaN and −0.0 constant patterns therefore arrive unchanged through the float constant buffer on both backends. The D3D12 debug layer was not available. The fullctest --preset dev --no-tests=errorpassed 136/136, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped. On that runtools/form_coverage.pyreports gfx1013 93 of 1968 forms and gfx1030 93 of 1863 (all of main's pixel programs plus this one), x64 49 of 948.Evidence and follow-up
asuint(params[...])of a float cbuffer. Several inputs (0xfffffff0, 0x7fffffff, 0xffffffff) are NaN bit patterns and 0x80000000 is −0.0, so the draw also checks that these patterns are not canonicalized through a bitcast.s_addc_u32,s_subb_u32),s_cmov*,s_cmpk_*, bitfield and 64-bit scalar forms, and scalar results used as descriptors or branch conditions.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:37:03Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
7b9adbbℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T19:44:59Z.
Heads-up to avoid duplicate work: I'm building the complementary half of the SALU block as a separate PR - the 64-bit forms this PR leaves out (
s_cmov_b64,s_and/or/xor/andn2/orn2_b64,s_lshl/lshr/ashr_b64) pluss_bfe_u32/i32which this explicitly rejects.Local corpus frequency justifies the split:
s_cmov_b64alone is the largest uncovered SOP form in the inspected package's pixel corpus (58.7k hits across a 1.5k-shader sample, present in ~97% of pixel programs), and the_b64ALU family adds ~22k more. No overlap with the 32-bit forms lowered here; the PR body will name this PR as the complementary half.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:59:23Z.
At
7b9adbb,tests/pixel_aot_check.pyconflicts with main. Please preserve both the new scalar/SCC tests and the landed fract controls when reconciling the test file, then rerun the LLVM round trip and pixel draw checks.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:28:01Z.
c8d5ca2now conflicts inREADME.mdandtests/pixel_aot_check.pyafter #277 landed. Please keep the single-word constant-buffer draw and its readiness controls alongside the scalar/SCC coverage.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:27:49Z.
At
efd3012, the merge conflicts are indocs/coverage/dashboard.svgandtests/pixel_aot_check.py. Please regenerate the dashboard with #294's clipping fix and preserve the ceiling controls alongside the SCC tests.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:59:02Z.
At
efd3012the merge conflicts are indocs/coverage/dashboard.svg,docs/experiments.md,tests/form_coverage_check.py,tests/pixel_aot_check.py,tools/pixel_aot.py. With #279 on main, preserve its 64-bit scalar representation and add the agreed combined cases: a 32-bit result consumed by a 64-bit operation, and a 64-bit SCC producer feeding a 32-bit select. Regenerate the dashboard from the preserved measurement.