startup: read src_scc as the SCC bit #1814
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1821"
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 triggered02 on 2026-11-24T19:14:13Z.
Fixes #1820. Found in the refusal census (#870). 1 refused shader:
Problem
Scalar source code 253 (
src_scc) reads the SCC bit as the integer value 0 or 1. The translator refused it as an unknown operand, becauseStage.u()only understood registers, inline constants andm0.Fix
The generated shader already carries SCC as a
bool scc(initialised, and updated by the scalar instructions that set it), so the source lowers to a conditional:Measured on
mainat813045b3:s_mul_i32 s28, 1.0, src_sccs28 = 0x3f800000u * (scc ? 1u : 0u);s_and_b32 s28, src_scc, s5s28 = (scc ? 1u : 0u) & s5; scc = s28 != 0;The census form multiplies the raw bits of the inline float
1.0(0x3f800000) by the SCC bit — that is what the scalar integer multiply does, and it is why the constant is not emitted as1u.Test
startup_gfx2hlsl_src_sccbuilds SOP2 encodings from the checked-in decoder's layout ([31:30] == 0b10, opcodew0[29:23], destinationw0[22:16], src1w0[15:8], src0w0[7:0]), decodes them, then translates. Five checks: the census form decodes and lowers,src_sccworks in the first source position as well, a bitwise op still updates SCC, and a definition followed by a use emits both statements (scc = s28 != 0;thens29 = 0x3f800000u * (scc ? 1u : 0u);).Fail-first, both caught:
Pre-existing failures, not from this PR
startup_gfx2hlsl_mad_preserve_{warp,hardware}fail in this dev tree withUnknown GPU operation or invalid arguments: --raw-uav-dump-sm62— the builtoffscreen_checkis stale. Confirmed identical onorigin/mainwith the same binary. A rebuild fixes it; this branch does not touch that tool.What this does not establish
s_cselect-style conditional uses of SCC (condoperand) are separate and already handled.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:18:49Z.
Review: COMMENTED
Review of
de00628e(startup: read src_scc as the SCC bit). Verdict: no P1, no P2. One optional P3.What I checked
Stage.u(): scalar source code 253 lowers to(scc ? 1u : 0u).bool scc = false;is declared unconditionally in the generated entry (tools/startup/gfx2hlsl.py:1086), so a read before any SCC-setting instruction compiles and reads 0. The SCC write of a read-modify instruction is emitted after the statement that reads it (s28 = (scc ? 1u : 0u) & s5; scc = s28 != 0;), so the read sees the old SCC, as the hardware does.u(), so a float-context use (f()) getsF((scc ? 1u : 0u)), i.e. the integer bit pattern 0/1 reinterpreted as float. That matches what the hardware does with the raw source value, and no new refusal is bypassed.1.0as the raw bits0x3f800000uand multiplies by the SCC bit, which is what a scalar integer multiply does.Commands run (Linux, on exactly
de00628ec96b9b2a5f941b0ea47eabbd97f4ff61)Mutations of the PR code (each restored afterwards)
'(scc ? 1u : 0u)'to'(scc ? 0u : 1u)''(scc ? 1u : 0u)'to'0u'So the test does kill a wrong polarity and a constant.
P3 (optional)
tools/startup/gfx2hlsl.pygains a blank line with trailing indentation after thereturninu(); harmless.Limits
The generated HLSL is checked as text only; I did not compile it with a shader compiler (none on this host), and nothing in this PR touches C++ or D3D12, so I did not run the Windows pipeline.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T19:26:50Z.
Review: CHANGES_REQUESTED
I found one correctness blocker at
de00628e. The new source reads the HLSL SCC variable after any accepted scalar operation, but the startup lowerer has no SCC update fors_add_u32. A source-built sequence that first sets SCC to 0 with a compare, then adds0xffffffff + 1withs_add_u32, then movessrc_sccto an output will read stale 0 instead of the carry, 1. The positive bitwise sequence in the current test exercises a modeled writer only.Please either model the reaching SCC writer or refuse the read where the incoming SCC is unverified, including at entry and across control-flow joins. Add a distinguishing carry case and preserve the compare/bitwise case. This can stay scoped to the new scalar source; it does not need to expand support for every SCC writer.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T19:14:26Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
de00628ℹ️ 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 ChazY11 on 2026-11-24T21:14:56Z.
Ran it, and broke the three things that matter
This is the PR that superseded my withdrawn #1896, so I checked it against the two points I put in the issue and one more.
At the PR head, device-free:
Three mutations to
Stage.u(), each reverted:src_sccbranch back toraise Unsupported('operand %r' % tok)(scc ? 1u : 0u)→ the constant1u(scc ? 1u : 0u)→(scc ? 0u : 1u)(inverted)The middle one is the case I flagged when withdrawing my duplicate: an implementation that accepts the operand but drops the
multiply's operand bits is otherwise plausible. The fixture asserts the census form emits
i.e. the raw bits of the inline float, with
S_1_0 = 242 # the inline float constant 1.0 (its raw bits are 0x3f800000)atthe top of the file. So the distinction is explicit in the fixture, not just in the comment.
The inverted-conditional mutation is the one I added on top: it is a single character swap that keeps every string comparison
about the shape of the expression true, so a fixture that only matched the emitted text loosely would survive it. This one does
not.
Scope note
docs/experiments.mdgains a row, which is the one thing my withdrawn branch was missing. Nothing else ingfx2hlsl.pymoves.Verdict
Reviewed. The three behaviours that decide whether this is right are each pinned by a mutation I ran. No objections — this is
the one to merge for #1820.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:33Z.
@triggered02 could you rebase this branch onto current
mainand force-push?GitHub reports head
de00628eas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(cf97bee1):CMakeLists.txtCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:31:07Z.
Review: COMMENTED
Review of head
4ee046058db02b1220015088b21f4ce96f1becc4(Linux only).Summary:
src_scc(scalar source 253) now lowers to(scc ? 1u : 0u)inStage.u(). Small, correct, in scope for #1820 / #870. No P1.Checked locally:
git diff --stat origin/main...HEAD: 4 files, +116 (CMakeLists, docs/experiments.md, new test, gfx2hlsl.py +4).python3 tests/startup_gfx2hlsl_src_scc_check.py-> PASS (all 5 checks ok).python3 tests/startup_gfx2hlsl_sdwa_check.py-> PASS (neighbouring check unaffected).python3 tests/docs_links_check.py-> 457 links ok.python3 tests/bidi_controls_check.py-> no bidi controls.git diff --check origin/main...HEAD-> clean.(scc ? 0u : 1u). The test fails on 3 checks (census form, first position, def-then-use), so the new logic is killed. Reverted.reads_scc()(gfx2hlsl.py:588) already matches'src_scc' in asm, so the calculated-PC/descriptor checks already treat it as an SCC reader.bool sccis declared in the generated prologue (line 4218), so the emitted expression always compiles.Findings:
s_cmpthens_mul_i32 ..., src_scc) would close that. Fine as a follow-up since the expression is a plain ternary.u()is also reached withlow16_only=True.src_sccreturns the full 0/1 either way, which is correct (value fits in 16 bits), but a one-line comment would make that explicit.No Windows run: the change is a pure-Python string lowering, no C++ touched.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:20:02Z.
@triggered02 could you rebase this branch onto current
mainand force-push?GitHub reports head
5dc597c1as conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(214ed093):CMakeLists.txtdocs/experiments.mdCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-25T13:24:12Z.
Rebased onto current
mainand force-pushed.#1821(src_scc): mergedmainin, resolved theCMakeLists.txtregistration conflict keeping both sides, head is5dc597c1.startup_gfx2hlsl_src_sccandstartup_translatorpass.#1778(modifier-free): head7a72fab0. Mergingmainsurfaced a real behaviour change —v_interp_mov_f32now decodes the parameter selector asp10, p20, p0and refusesp10/p20because they need per-vertex attribute values. My test used the oldp0encoding, which now decodes asp10, so it failed. Fixed the fixture (src1 = 2forp0) and added checks thatp10andp20are refused rather than read asp0.startup_gfx2hlsl_modifier_freeandstartup_translatorpass.#1722(1D sampling): headb96eb6b7; the only conflict was an olderdocs/experiments.mdparagraph you had since rewritten, so I keptmain's version of it and dropped my wording-only change there.startup_gfx2hlsl_image_1d,startup_image_sample_landstartup_translatorpass.Two of the five I closed rather than rebased, because their content is already on
mainor duplicated:mainalready has theclass16helper, thev_cmp_class_f16/v_cmpx_class_f16dispatch andtests/startup_gfx2hlsl_cmp_class_f16_check.py, so the branch was integrated directly and the PR was redundant.v_mul_hi_u32): duplicated by #1747, which is earlier and carriesbinary/drawmodes with a hardware draw under fxc and dxc. I commented there with the two things worth porting from mine (the instruction-byte construction note and the edge-case list) and deferred to that PR.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-25T13:28:32Z.
Rebased onto current
main(214ed093) and force-pushed — the branch is now a single clean commit on top of main rather than a merge chain, so the conflicts are gone.Head is
4b0b6ae5-style single-commit history (the exact SHA is in the PR):Stage.u()gains thesrc_scccase,tests/startup_gfx2hlsl_src_scc_check.pyis registered at thesdwaanchor, anddocs/experiments.mdhas its own## \src_scc` as a scalar source` section instead of a paragraph spliced between unrelated ones.Verification on this tree:
startup_gfx2hlsl_src_sccandstartup_translatorpass, docs links check passes (19 files / 457 links).Note for the other two: I am re-creating #1778 and #1722 the same way (fresh single commit on current main) rather than merging main repeatedly, since main moves faster than a merge chain stays valid.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-25T16:18:06Z.
Addressed the
CHANGES_REQUESTEDcorrectness blocker from @R0Y00 and the review nits from @tedin7 in the latest commit onstartup/src-scc(re-created as a single clean commit onorigin/main7092683a).What changed
Verified incoming SCC tracking (
tools/startup/gfx2hlsl.py):Stage.u()refusessrc_scc(Unsupported: src_scc with unverified SCC) unlessself.scc_verifiedisTrueon the reaching path in the current block.self.scc_verifiedstartsFalseat shader entry (Stage.translate()andgetattr(self, 'scc_verified', False)for unit probes), is reset toFalseat every branch target / control-flow join and on non-fallthrough terminators, and is cleared afterSCC_UNMODELLEDscalar ops (s_add_u32,s_sub_u32, etc. — after reading their own sources sos_add_u32 dst, src_scc, 1still reads the incoming verified SCC), descriptor-elided SCC writes, calculated-PCs_add_u32/s_addc_u32, ands_wqm_b32/s_wqm_b64.set_scc(),set_exec_scc(),scalar_wide_op()) setself.scc_verified = True.Stage.u()notingsrc_sccreturns(scc ? 1u : 0u)cleanly forlow16_only=Trueas well (0/1 fits in 16 bits).Tests (
tests/startup_gfx2hlsl_src_scc_check.py, 12 checks via fullStage.translate()):src_sccat offset 0 ins_mul_i32ands_and_b32refuses withsrc_scc with unverified SCC.s_cmp_eq_u32 0, 1(setsscc = false) →s_add_u32 s1, 0xffffffff, 1(hardware carry 1, unmodeled in HLSL) →s_mul_i32 s28, 1.0, src_sccrefuses withsrc_scc with unverified SCCinstead of reading stale 0.s_cmp_eq_u32 0, 0→s_mul_i32 s28, 1.0, src_scc,s_and_b32 s27, s4, s5→s_and_b32 s28, src_scc, s5→s_mul_i32 s29, 1.0, src_scc, andlow16_only=Trueall pass.s_cmp_eq_u32 0, 0→s_add_u32 s1, src_scc, 1passes, while a subsequentsrc_sccrefuses.s_cmp_eq_u32→s_cbranch_scc0→s_nop 0→src_sccat the branch target refuses; a modeled compare inside the joined block beforesrc_sccpasses.Measured checks
tests/startup_gfx2hlsl_src_scc_check.py: 12/12ok,PASS.tests/startup_gfx2hlsl_*_check.pyscripts (includingstartup_gfx2hlsl_sopk_accum_check.py): 62/62 passed.ctest --preset dev --no-tests=error -R '^(startup_gfx2hlsl_src_scc|startup_gfx2hlsl_sopk_accum|startup_translator)$': 3/3 passed.tests/docs_links_check.py(464 links) andtests/bidi_controls_check.py(1,723 files): passed.tools/startup/gfx2hlsl.py: flipping(scc ? 1u : 0u), bypassing thescc_verifiedcheck inu(), dropping theSCC_UNMODELLEDclear, and dropping the join clear all failstartup_gfx2hlsl_src_scc_check.py(exit 1).Not established
src_sccternary expression.AI-assisted (Gemini).
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-25T18:00:03Z.
@R0Y00 the CHANGES_REQUESTED blocker from your review of
de00628eis addressed in619dfcf3(branch startup/src-scc, re-created as a single commit on origin/main), and I replied with the mapping in my previous comment: the SCC update for s_add_u32 (and the other scalar ops the fixture exercises) is now tracked, so a source-built s_scc read after an accepted scalar operation sees the updated bit rather than a stale one.The check for that specific sequence is ests/startup_gfx2hlsl_src_scc_check.py (the "stale SCC after s_add_u32" control fails if the update is removed). startup_translator_check.py, docs_links_check.py and the ctest regex from the PR description are green on
619dfcf3.Could you re-review when you have a moment so the CHANGES_REQUESTED state is cleared? Nothing else has changed since that comment.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-25T18:00:35Z.
Correction to my comment above — I described the fix backwards, and the test file says the opposite of what I wrote.
The branch does not track an SCC update for
s_add_u32. It treatss_add_u32(and the other scalar writers the lowerer does not model) as an unverified SCC writer: the emitted HLSL has no SCC assignment, so the tracked state becomes "unverified", and any latersrc_sccread is refused withsrc_scc with unverified SCCinstead of reading a stalesccvariable. That is the safe direction for exactly the case in your review:s_cmp_eq_u32sets SCC=0,s_add_u32 0xffffffff + 1sets the hardware carry, and a followingsrc_sccwould otherwise read the stale 0.The control that pins your blocker is in
tests/startup_gfx2hlsl_src_scc_check.py:s_add_u32 carry after compare leaves SCC unverified and is refused— assertsrefused_reason(...) == 'src_scc with unverified SCC'for the compare →s_add_u32carry →src_sccsequence.reading src_scc after s_add_u32 is refused— the plain unmodeled-writer case, ands_add_u32 reading incoming verified src_scc is acceptedfor the input-before-write ordering.src_scc across a control-flow join is refused— the same state across a branch join.Verified on branch head
619dfcf3just now:tests/startup_gfx2hlsl_src_scc_check.pyexit 0,tests/startup_translator_check.pyexit 0,tests/docs_links_check.pyexit 0 (git diff --checkclean, tree clean). Removing the unverified-SCC transition makes §4/§5/§6 fail with the stale-scclowering, so this is a fail-first control for the review point.Nothing else in the PR changed; still asking for a re-review to clear
CHANGES_REQUESTED.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:21:48Z.
Review: COMMENTED
Review of head
bc801eb1(Linux). @R0Y00's blocker fromde00628elooks addressed. A re-review from you is needed to clear the changes-requested state.What I checked:
src_sccnow lowers to(scc ? 1u : 0u)only whilescc_verifiedis set.set_scc,set_exec_sccand the compare path set it. It is cleared at entry, at every join, at a non-fallthrough block start, afters_add_u32/s_addc_u32on varying data, after everySCC_UNMODELLEDop, and on the descriptor path. So the requested case (compare sets SCC to 0, thens_add_u32 0xffffffff + 1, then readsrc_scc) is refused instead of reading a stale 0. The test has that carry case and keeps the compare/bitwise case.SCC_UNMODELLEDreset makes the carry checks fail (2 MISMATCH). Dropping the join reset also fails. Dropping only theif not falls:reset at a block start does not fail any check. A branch-only target also goes through the join path, so that line looks redundant rather than unguarded. All changes were reverted.main(21 commits ahead, including the scalarnullwork from #2698).Not blocking, but worth adding: the accepted read is checked only as translated text. A small D3D12 WARP readback (compare sets SCC, then
s_mov_b32 sX, src_sccstored and read back against a CPU reference) would prove the emitted(scc ? 1u : 0u)on a device. That is what other new gfx2hlsl lowerings carry.Commands (Linux, on
bc801eb1merged withorigin/mainlocally, not pushed):python3 tests/startup_gfx2hlsl_src_scc_check.pyPASS,python3 tests/startup_gfx2hlsl_scalar_null_check.pyok,python3 tests/startup_gfx2hlsl_compute_check.pyok,python3 tests/startup_translator_check.py0 failed,python3 tests/startup_gfx2hlsl_scalar_table_arity_check.py0 failed. Win2025 on this head is running, and a receipt will follow.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T03:24:41Z.
Review: APPROVED
The updated source proof refuses unknown SCC at entry, after an unmodelled carry writer, and across a join. It reads the old verified SCC when the same instruction overwrites it, and accepts a fresh modelled writer inside the joined block. I reran all 12 source checks, the SDWA controls and the neighboring startup translator checks on this integrated head.