Repository navigation
startup: read src_scc as the SCC bit - #1821
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
tedin7
left a comment
There was a problem hiding this comment.
Review of de00628e (startup: read src_scc as the SCC bit). Verdict: no P1, no P2. One optional P3.
What I checked
- The change is 4 lines in
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. - The source is routed through
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. - The census form keeps
1.0as the raw bits0x3f800000uand multiplies by the SCC bit, which is what a scalar integer multiply does. - The change is clean-room and title-neutral: it uses the public scalar source encoding and the PR text names no title.
Commands run (Linux, on exactly de00628ec96b9b2a5f941b0ea47eabbd97f4ff61)
python3 -B tests/startup_gfx2hlsl_src_scc_check.py -> PASS (5 checks)
for t in tests/startup_gfx2hlsl*_check.py; do python3 -B $t; done -> 12 scripts, all rc=0
git diff --check origin/main...HEAD -> clean
python3 -B tests/docs_links_check.py -> Checked 18 Markdown files and 369 links
python3 -B tests/bidi_controls_check.py -> no bidirectional controls
Mutations of the PR code (each restored afterwards)
| mutation | result |
|---|---|
'(scc ? 1u : 0u)' to '(scc ? 0u : 1u)' |
test FAILS (3 checks) |
'(scc ? 1u : 0u)' to '0u' |
test FAILS (3 checks) |
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.
R0Y00
left a comment
There was a problem hiding this comment.
I found one correctness blocker at de00628. The new source reads the HLSL SCC variable after any accepted scalar operation, but the startup lowerer has no SCC update for s_add_u32. A source-built sequence that first sets SCC to 0 with a compare, then adds 0xffffffff + 1 with s_add_u32, then moves src_scc to 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.
Ran it, and broke the three things that matterThis 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: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_src_scc_check.py
a defined SCC is read back by the next instruction: ok
PASS exit 0Three mutations to
The middle one is the case I flagged when withdrawing my duplicate: an implementation that accepts the operand but drops the s28 = 0x3f800000u * (scc ? 1u : 0u);i.e. the raw bits of the inline float, with The inverted-conditional mutation is the one I added on top: it is a single character swap that keeps every string comparison Scope note
VerdictReviewed. The three behaviours that decide whether this is right are each pinned by a mutation I ran. No objections — this is Notes
|
|
@triggered02 could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
|
@triggered02 could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
|
Rebased onto current
Two of the five I closed rather than rebased, because their content is already on
AI-assisted (Claude Code). |
5dc597c to
4ee0460
Compare
|
Rebased onto current Head is Verification on this tree: 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). |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 4ee046058db02b1220015088b21f4ce96f1becc4 (Linux only).
Summary: src_scc (scalar source 253) now lowers to (scc ? 1u : 0u) in Stage.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.- Mutation: flipped the lowering to
(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.- Title is neutral, test is registered in CMake next to its siblings, docs section added.
Findings:
- P1: none.
- P2: none blocking. The lowering is string-checked only. Repo convention for gfx2hlsl lowerings is a WARP readback vs CPU reference; a dispatch with SCC set and clear (e.g.
s_cmpthens_mul_i32 ..., src_scc) would close that. Fine as a follow-up since the expression is a plain ternary. - nit:
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. - nit: CI checks (Linux, Windows, gfx1013 fixtures) were still pending when I reviewed; confirm they are green before merge.
No Windows run: the change is a pure-Python string lowering, no C++ touched.
AI-assisted; commands listed were executed locally.
4ee0460 to
619dfcf
Compare
Fixes R0Y00#1820. Addresses review feedback on R0Y00#1821: Stage.u() now refuses src_scc unless a modeled SCC writer set scc_verified on the reaching path in the current block. scc_verified starts False at entry, clears at branch targets/joins, non-fallthroughs, SCC_UNMODELLED (such as s_add_u32, cleared after reading its sources), descriptor-elided SCC writes, calculated-PC elision, and s_wqm. Test runs full Stage.translate() over synthetic bytes covering entry refusal, modeled compare/bitwise writers, low16_only=True, the s_add_u32 carry case, input-before-write on s_add_u32, and CFG joins; all 62 pure-Python startup_gfx2hlsl checks and CTest src_scc/sopk_accum/startup_translator pass.
|
Addressed the What changed
Measured checks
Not established
AI-assisted (Gemini). |
|
@R0Y00 the CHANGES_REQUESTED blocker from your review of de00628 is addressed in 619dfcf (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 619dfcf. Could you re-review when you have a moment so the CHANGES_REQUESTED state is cleared? Nothing else has changed since that comment. |
|
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 The control that pins your blocker is in
Verified on branch head Nothing else in the PR changed; still asking for a re-review to clear |
# Conflicts: # CMakeLists.txt # docs/experiments.md # tests/startup_gfx2hlsl_src_scc_check.py # tools/startup/gfx2hlsl.py
619dfcf to
e09daaa
Compare
Fixes R0Y00#1820. Addresses review feedback on R0Y00#1821: Stage.u() now refuses src_scc unless a modeled SCC writer set scc_verified on the reaching path in the current block. scc_verified starts False at entry, clears at branch targets/joins, non-fallthroughs, SCC_UNMODELLED (such as s_add_u32, cleared after reading its sources), descriptor-elided SCC writes, calculated-PC elision, and s_wqm. Test runs full Stage.translate() over synthetic bytes covering entry refusal, modeled compare/bitwise writers, low16_only=True, the s_add_u32 carry case, input-before-write on s_add_u32, and CFG joins; all 62 pure-Python startup_gfx2hlsl checks and CTest src_scc/sopk_accum/startup_translator pass.
Fixes R0Y00#1820. Addresses review feedback on R0Y00#1821: Stage.u() now refuses src_scc unless a modeled SCC writer set scc_verified on the reaching path in the current block. scc_verified starts False at entry, clears at branch targets/joins, non-fallthroughs, SCC_UNMODELLED (such as s_add_u32, cleared after reading its sources), descriptor-elided SCC writes, calculated-PC elision, and s_wqm. Test runs full Stage.translate() over synthetic bytes covering entry refusal, modeled compare/bitwise writers, low16_only=True, the s_add_u32 carry case, input-before-write on s_add_u32, and CFG joins; all 62 pure-Python startup_gfx2hlsl checks and CTest src_scc/sopk_accum/startup_translator pass.
e09daaa to
bc801eb
Compare
tedin7
left a comment
There was a problem hiding this comment.
Review of head bc801eb1 (Linux). @R0Y00's blocker from de00628e looks 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.- Mutations: dropping the
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. - It merges cleanly with current
main(21 commits ahead, including the scalarnullwork from #2698). - #2577 is not a duplicate: it says "Depends on #1821" and extends the proof across branch targets. This PR goes first.
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_scc stored 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 bc801eb1 merged with origin/main locally, not pushed): python3 tests/startup_gfx2hlsl_src_scc_check.py PASS, python3 tests/startup_gfx2hlsl_scalar_null_check.py ok, python3 tests/startup_gfx2hlsl_compute_check.py ok, python3 tests/startup_translator_check.py 0 failed, python3 tests/startup_gfx2hlsl_scalar_table_arity_check.py 0 failed. Win2025 on this head is running, and a receipt will follow.
AI-assisted; commands listed were executed locally.
R0Y00
left a comment
There was a problem hiding this comment.
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.
… reaches (#2577) * startup: verify reaching SCC writer before reading src_scc Fixes #1820. Addresses review feedback on #1821: Stage.u() now refuses src_scc unless a modeled SCC writer set scc_verified on the reaching path in the current block. scc_verified starts False at entry, clears at branch targets/joins, non-fallthroughs, SCC_UNMODELLED (such as s_add_u32, cleared after reading its sources), descriptor-elided SCC writes, calculated-PC elision, and s_wqm. Test runs full Stage.translate() over synthetic bytes covering entry refusal, modeled compare/bitwise writers, low16_only=True, the s_add_u32 carry case, input-before-write on s_add_u32, and CFG joins; all 62 pure-Python startup_gfx2hlsl checks and CTest src_scc/sopk_accum/startup_translator pass. * startup: keep src_scc proven at a branch target one uniform SCC write reaches A compiler copies SCC into an SGPR on both arms of an if/else (s_cmp_* or s_bitcmp*, s_cbranch_scc0/1, then s_mov_b32 sN, src_scc in each arm). The arm at the branch target was refused as unverified, because every target dropped SCC. In 230 of the 239 locally refused requests, the first refused read has a single reaching SCC write. Each forward branch now carries the offset of the emitted SCC write that reaches it, but only when that write was uniform. A target keeps SCC proven when the fall-through and every edge into it carry the same write and no back edge enters it. Lane-mask SCC, unmodelled and elided writers, different writes on different paths, and loop heads stay refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: read back src_scc at a branch target on D3D12 (WARP) --------- Co-authored-by: triggered02 <153171514+triggered02@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: tedin7 <tommasoderosa94@gmail.com>
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).