startup: model the SCC of s_add, s_sub, s_min and s_max in gfx2hlsl #2770
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2778"
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 tedin7 on 2026-11-26T08:15:06Z.
Part of #1723
What this unblocks: stops silently wrong shader output when a branch or select reads the SCC of
s_add,s_sub,s_minors_max.Source: AMD "RDNA 2" Instruction Set Architecture reference guide, SOP2 instructions S_ADD_U32, S_SUB_U32, S_ADD_I32, S_SUB_I32, S_MIN_, S_MAX_ (SCC result definitions) and SOPC / S_CBRANCH_SCC branches that read SCC.
What changed
s_add_u32/i32,s_sub_u32/i32,s_min_u32/i32ands_max_u32/i32were inSCC_UNMODELLED: the lowering emitted the result and left the emittedsccas it was. A laters_cbranch_scc0/1,s_cselectorsrc_sccread a stale value (for examples_add_u32 s23, s7, -1thens_cbranch_scc1branched on a variable that was never assigned).s_add_u32carry out,s_sub_u32borrow (S0 < S1),s_add_i32/s_sub_i32signed overflow,s_min/s_maxSCC = (D == S0), i.e. the first source was chosen (equal operands included). Anulldestination keeps only the SCC. Uniformity of the SCC follows its sources like any other SCC write.scalar_effects, pluss_wqmands_quadmask) and emits nothing for it is recorded; a later SCC reader reachable from it is refused by name:scc from an SCC write that is not modelled in <reader>.startup_gfx2hlsl_compute_check.py(an intervenings_sub_u32, a non-adjacent high add, a different addend or destination now translate with the exact SCC; the branch-into-the-add and the elided descriptor arithmetic stay refused),startup_gfx2hlsl_src_scc_check.py(reads afters_add_u32see its carry),startup_gfx2hlsl_scalar_null_check.py(a null destination computes only its SCC),startup_gfx2hlsl_readfirstlane_uniform_check.py(a select after a carry from a uniform source is proven uniform) and the golden HLSL ofstartup_gfx2hlsl_heap_record_check.py/heap_word_check.py(one morescc = ...line per add).Same shape in the HLSL of 18 existing translated shapes: one more
scc = ...line each, nothing newly translated or refused.Tests
Sintests/startup_gfx2hlsl_compute_check.py(startup_gfx2hlsl_compute_{warp,hardware}): a 4 x 4 grid of 16 groups (the runner accepts at most 5 per axis; S0 from the x index, S1 from the y index), S0 and S1 each from {0, -1, 0x7fffffff, 0x80000000}; all eight forms, each with the destination apart from S0 and with the destination equal to S0; per group a word of the 16 SCC bits and a hash of the 16 results, against a Python reference written from the ISA rules.s-min-strict(strict compare ins_min_u32) ands-borrow-flipped(operands of the borrow swapped), registered inCMakeLists.txtlike the other controls; each must be rejected at a word.check_scc_modelled: the exact SCC text of each form ahead of the branch (fails onmain), and the named refusal for a reader afters_wqm.What stays open
s_min/s_maxequal-operand SCC follows the ISA pseudo-code (SCC = D == S0); the WARP readback checks the lowering against that rule, not against silicon.s_addc_u32/s_subb_u32remain refused.Verification:
python3 -B tests/startup_gfx2hlsl_compute_check.pyand... binary llvm-mc-19: pass.python3 -B tests/startup_gfx2hlsl_{heap_record,heap_word,readfirstlane_uniform,scalar_null,src_scc}_check.py: pass.tests/*check.pyagainstorigin/main: only the scripts named above changed, each updated in this PR (see the sweep below).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:48:44Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
17a05d9a49ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:44Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:47Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T08:30:01Z.
Two findings on
cfd84d2dfrom a native Windows 11 build 26200 Release run.Invalid compute store reference. Case S uses 16×1×1 groups, butread_store_referencecaps each axis at 5. Command:ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute_s-(min-strict|borrow-flipped)_(warp|hardware)$' -V. In a local test-only control limited to 16×1×1, all four ran. The min mutation changed 4/320 words and flipped borrow changed 12/320 on each adapter, as expected. Please keep all sixteen input pairs and use a fixture shape that the reader accepts, or extend the test reader with a bounded case.96a7b4fbhad 16/320 mismatches on each adapter (first word expected0000ff00, actual00000000). The new shader had 0/320. Both use the same compute cache key with identical inputs, so existing cached bytecode can mask the fix. Please advance the shared runtime/offline key after the other shader guard PRs and retain a known-answer check.WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with debug enabled. Six focused Python controls passed before the test-only reader edit.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T08:39:41Z.
I will independently verify the newly modelled SCC outputs when the scalar destination aliases the second input, including carry/borrow, signed overflow and equal min/max operands. I will source-assemble a separate fixture, use a CPU integer reference, and check the stored results and SCC observations on native Intel, NVIDIA and WARP.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:45:55Z.
Thank you for the native run. Both findings, on head
edc27b203:read_store_referenceaccepts it with all sixteen input pairs and no C++ change. The expected words and the two controls (s-min-strict,s-borrow-flipped) are unchanged; each control text still occurs exactly once in the generated HLSL.x2w-startup-shader-25/25csto26/26cs(runtimed3d12_draw.inl, offlinegfx2hlsl.py, the two C++ test mirrors, the docs line). The known-answer checks stay and carry the new values: the graphics vector pair instartup_shader_cache_key_check.py(recomputed with a separate FNV-1a loop, same result) and the framed compute key instartup_compute_request_offline_check.py;startup_gfx2hlsl_fract_check.pypins the revision. The C++ targets were not built here. Note for the merge order: any other PR that changes translated output without advancing the revision (for example the whole-wave branch refusals in #2772, whose refused programs could still be served from a cached translation) is covered by this bump only if this PR merges after it; if this one merges first, the later PR needs its own bump to 27.Verification:
python3 -B tests/startup_gfx2hlsl_compute_check.py(andbinary llvm-mc-19),startup_shader_cache_key_check.py,startup_compute_request_offline_check.py,startup_gfx2hlsl_fract_check.py,startup_gfx2hlsl_buffer_store_check.py,startup_packed_position_provenance_check.py: pass.tests/*check.pysweep againstorigin/main: no script changes result.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:40:22Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
04d19ceℹ️ 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 tedin7 on 2026-11-26T08:40:09Z.
Independent Stage-2 gate of head
e2659bf4c: PASS (supersedes my earlier receipts for17a05d9a4,edc27b203and04d19ce64).Checked:
add_sub_min_max_scc) evaluated with u32 / int semantics over 39200 operand pairs per run (edge values and random) against the RDNA 2 ISA rule written out by hand: 0 mismatches. The SCC is emitted ahead of the destination write, also when the destination is a source.Verification:
python3 -B tests/startup_gfx2hlsl_compute_check.pyand... binary llvm-mc-19, and the five other scripts of the PR: pass on Linux; sweep oftests/*check.pyagainstorigin/main: 0 scripts change result.x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute'on WARP: dev 450/450 and release 450/450 passed, includingstartup_gfx2hlsl_compute_{warp,hardware},..._s-min-strict_{warp,hardware}and..._s-borrow-flipped_{warp,hardware}.Open, as the PR says: the s_min / s_max equal-operand SCC follows the ISA pseudo-code, checked against that rule and not against silicon.
Update, head
04d19ce64(fixes the two review threads ofedc27b203):src_sccas an operand of s_add / s_sub / s_min / s_max: the destination is written first and the SCC after, from the incoming SCC; a destination that is also a source (or m0, exec, vcc, null) is refused by name. All eight forms withsrc_sccas first or second operand give the right destination and SCC.check_scc_modelledis now called from the controls; with the old order (SCC first)startup_gfx2hlsl_src_scc_checkfails.x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute|shader_cache_key'on WARP: dev 451/451 and release 451/451 passed; Linux scripts and the sweep againstorigin/main(0 scripts change result) pass.Update, head
e2659bf4c(main merged in, cache revision 27):fresh_gateGO (0 behindorigin/main); the same Linux scripts, thesrc_sccforms and the sweep againstorigin/main(0 scripts change result) pass;x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute|shader_cache_key': dev 453/453 and release 453/453 passed.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:48:44Z.
Code review location:
tools/startup/gfx2hlsl.py; line 5177When an operand is
src_scc,valuesandexprcontain a live reference to the HLSLsccvariable. This assignment overwrites that variable before the destination expression is emitted, so the destination reads the outgoing SCC instead of the incoming operand. For example,s_cmp_eq_u32 0, 0; s_add_u32 s1, src_scc, 1now clearssccand then assignss1 = 1, although the ISA result and the parent lowering produce2. The newly accepted non-adjacent carry-read adds are affected too. Preserve the incoming SCC or compute the result into a temporary before committing the new SCC.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:48:44Z.
Code review location:
tests/startup_gfx2hlsl_compute_check.py; line 1258A repository-wide search finds only this definition: neither
check_controls()nor any__main__mode calls it. Consequently, the per-form branch assertions and boths_wqmstale-SCC refusal cases are skipped by the Linux and CTest controls runs. Wire this helper intocheck_controls()so those regressions are exercised. Calling it directly currently also exposes a hidden assertion failure: the decoder returnss_cbranch_scc1 label_0x8, while the assertion expectss_cbranch_scc1 1.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:44Z.
Code review location:
tools/startup/gfx2hlsl.py; line 5177Real, and fixed on
04d19ce64: when an operand issrc_scc, the add now writes its destination first and emits its own SCC afterwards, so the destination reads the incoming SCC (s_cmp_eq_u32 0, 0; s_add_u32 s1, src_scc, 1givess1 = (scc ? 1u : 0u) + 1u;and only then the carry). A destination that is also a source, or m0 / exec / vcc / null, combined withsrc_sccis refused by name (the carry could not be computed from unchanged sources). The previous assertion instartup_gfx2hlsl_src_scc_check.pyonly checked that the SCC line preceded a later reader, so it encoded the wrong order; it now pins the order and the refusal, and fails on the previous head. Linux: the six affected scripts and the sweep againstorigin/mainpass (0 differ).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:47Z.
Code review location:
tests/startup_gfx2hlsl_compute_check.py; line 1258Real, and fixed on
04d19ce64:check_scc_modelledis now called fromcheck_controls()(the call had been lost because it was added next to a helper that lives on another branch). Running it exposed the decoder text of the branch word (s_cbranch_scc1 label_0x8); the word check now compares the mnemonic for branches. The per-form SCC assertions and boths_wqmstale-SCC refusals run in the Linux and CTest controls now (checked by counting the call).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T09:33:19Z.
Review: APPROVED
Rechecked current
e2659bf4on native Windows 11 build 26200, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with debug enabled. The 4×4×1 case ran through the unmodified renderer and matched all 320 words on both adapters. The strict-min tie and flipped-borrow controls gave 4 and 12 differences respectively on each. The compute translation tests and both graphics/compute cache-key checks passed. The shared runtime/offline revision is now 27/27cs. This resolves my two findings about the fixture grid and old cached shader reuse.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T09:16:04Z.
I checked the second-source alias on PR head
17a05d9a. For each of eight scalar ops the guest setss21 = s5, executesop s21, s4, s21, and immediately saves SCC withs_cselect_b32. The two operands come from runtime root constants. Six input words, including equality, signed limits and unsigned wrap, give 36 ordered pairs. The CPU reference uses unbounded integer arithmetic and the PR's first-source tie rule.WARP, Intel UHD 770 and RTX 4060 each passed all 36 dispatches with the translated DXC shader. Each readback checks 16 result/flag words and 304 sentinel words. Moving unsigned-add carry calculation after the aliased write produced exactly the 16 predicted word-1 failures on each adapter. The other 20 input pairs still passed that modified shader.
Reproduction script and guest assembly generator. With LLVM 15, DXC 1.9 and the MSVC-built renderer, run:
For physical adapters use
hardwareand setXBOX2WINDOWS_ADAPTERto the adapter substring. This covers the translated D3D12 behavior of the eight operations. I didn't measure tie behavior on native gfx1013 hardware.