Skip to content

startup: read src_scc as the SCC bit - #1821

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/src-scc
Nov 26, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/src-scc

Conversation

@triggered02

Copy link
Copy Markdown
Contributor

Fixes #1820. Found in the refusal census (#870). 1 refused shader:

s_mul_i32 s28, 1.0, src_scc    -> REFUSED: operand 'src_scc'

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, because Stage.u() only understood registers, inline constants and m0.

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:

if tok == 'src_scc':
    # Source code 253 reads the SCC bit as the integer value 0 or 1 (used by e.g. s_mul_i32).
    return '(scc ? 1u : 0u)'

Measured on main at 813045b3:

form before after
s_mul_i32 s28, 1.0, src_scc refused s28 = 0x3f800000u * (scc ? 1u : 0u);
s_and_b32 s28, src_scc, s5 refused s28 = (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 as 1u.

Test

startup_gfx2hlsl_src_scc builds SOP2 encodings from the checked-in decoder's layout ([31:30] == 0b10, opcode w0[29:23], destination w0[22:16], src1 w0[15:8], src0 w0[7:0]), decodes them, then translates. Five checks: the census form decodes and lowers, src_scc works 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; then s29 = 0x3f800000u * (scc ? 1u : 0u);).

dev:     19/21 - the 2 failures are pre-existing (below)
release: startup_gfx2hlsl_src_scc Passed 0.14 s

Fail-first, both caught:

refuse src_scc again          -> Unsupported: operand 'src_scc'
lower it as the constant 0u   -> "a defined SCC is read back by the next instruction" FAIL

Pre-existing failures, not from this PR

startup_gfx2hlsl_mad_preserve_{warp,hardware} fail in this dev tree with Unknown GPU operation or invalid arguments: --raw-uav-dump-sm62 — the built offscreen_check is stale. Confirmed identical on origin/main with the same binary. A rebuild fixes it; this branch does not touch that tool.

What this does not establish

  • That the emitted HLSL compiles or computes the right value — the test compares text; DXC/WARP were not run here.
  • The s_cselect-style conditional uses of SCC (cond operand) are separate and already handled.

AI-assisted (Claude Code).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T19:15:51.274627Z de00628 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) gets F((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.0 as the raw bits 0x3f800000u and 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.py gains a blank line with trailing indentation after the return in u(); 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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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:

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 0

Three mutations to Stage.u(), each reverted:

mutation result
the src_scc branch back to raise Unsupported('operand %r' % tok) caught
(scc ? 1u : 0u) → the constant 1u caught
(scc ? 1u : 0u) → (scc ? 0u : 1u) (inverted) caught

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

s28 = 0x3f800000u * (scc ? 1u : 0u);

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) at
the 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.md gains a row, which is the one thing my withdrawn branch was missing. Nothing else in gfx2hlsl.py moves.

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

  • AI-assisted review.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@triggered02 could you rebase this branch onto current main and force-push?

GitHub reports head de00628e as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (cf97bee1):

  • CMakeLists.txt

Commands run locally:

git fetch origin main pull/1821/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1821 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@triggered02 could you rebase this branch onto current main and force-push?

GitHub reports head 5dc597c1 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (214ed093):

  • CMakeLists.txt
  • docs/experiments.md

Commands run locally:

git fetch origin main pull/1821/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1821 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@triggered02

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and force-pushed.

  • #1821 (src_scc): merged main in, resolved the CMakeLists.txt registration conflict keeping both sides, head is 5dc597c1. startup_gfx2hlsl_src_scc and startup_translator pass.
  • #1778 (modifier-free): head 7a72fab0. Merging main surfaced a real behaviour change — v_interp_mov_f32 now decodes the parameter selector as p10, p20, p0 and refuses p10/p20 because they need per-vertex attribute values. My test used the old p0 encoding, which now decodes as p10, so it failed. Fixed the fixture (src1 = 2 for p0) and added checks that p10 and p20 are refused rather than read as p0. startup_gfx2hlsl_modifier_free and startup_translator pass.
  • #1722 (1D sampling): head b96eb6b7; the only conflict was an older docs/experiments.md paragraph you had since rewritten, so I kept main's version of it and dropped my wording-only change there. startup_gfx2hlsl_image_1d, startup_image_sample_l and startup_translator pass.

Two of the five I closed rather than rebased, because their content is already on main or duplicated:

AI-assisted (Claude Code).

@triggered02

Copy link
Copy Markdown
Contributor Author

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 the src_scc case, tests/startup_gfx2hlsl_src_scc_check.py is registered at the sdwa anchor, and docs/experiments.md has its own ## \src_scc` as a scalar source` section instead of a paragraph spliced between unrelated ones.

Verification on this tree: startup_gfx2hlsl_src_scc and startup_translator pass, 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).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 scc is 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_cmp then s_mul_i32 ..., src_scc) would close that. Fine as a follow-up since the expression is a plain ternary.
  • nit: u() is also reached with low16_only=True. src_scc returns 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.

triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 25, 2026
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.
@triggered02

Copy link
Copy Markdown
Contributor Author

Addressed the CHANGES_REQUESTED correctness blocker from @R0Y00 and the review nits from @tedin7 in the latest commit on startup/src-scc (re-created as a single clean commit on origin/main 7092683a).

What changed

  1. Verified incoming SCC tracking (tools/startup/gfx2hlsl.py):

    • Stage.u() refuses src_scc (Unsupported: src_scc with unverified SCC) unless self.scc_verified is True on the reaching path in the current block.
    • self.scc_verified starts False at shader entry (Stage.translate() and getattr(self, 'scc_verified', False) for unit probes), is reset to False at every branch target / control-flow join and on non-fallthrough terminators, and is cleared after SCC_UNMODELLED scalar ops (s_add_u32, s_sub_u32, etc. — after reading their own sources so s_add_u32 dst, src_scc, 1 still reads the incoming verified SCC), descriptor-elided SCC writes, calculated-PC s_add_u32/s_addc_u32, and s_wqm_b32/s_wqm_b64.
    • Modeled SCC writers (set_scc(), set_exec_scc(), scalar_wide_op()) set self.scc_verified = True.
    • Added the explicit comment in Stage.u() noting src_scc returns (scc ? 1u : 0u) cleanly for low16_only=True as well (0/1 fits in 16 bits).
  2. Tests (tests/startup_gfx2hlsl_src_scc_check.py, 12 checks via full Stage.translate()):

    • Entry refusal: src_scc at offset 0 in s_mul_i32 and s_and_b32 refuses with src_scc with unverified SCC.
    • Distinguishing carry case: s_cmp_eq_u32 0, 1 (sets scc = false) → s_add_u32 s1, 0xffffffff, 1 (hardware carry 1, unmodeled in HLSL) → s_mul_i32 s28, 1.0, src_scc refuses with src_scc with unverified SCC instead of reading stale 0.
    • Preserved compare & bitwise cases: 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, and low16_only=True all pass.
    • Input-before-write: s_cmp_eq_u32 0, 0 → s_add_u32 s1, src_scc, 1 passes, while a subsequent src_scc refuses.
    • Control-flow join: s_cmp_eq_u32 → s_cbranch_scc0 → s_nop 0 → src_scc at the branch target refuses; a modeled compare inside the joined block before src_scc passes.

Measured checks

  • tests/startup_gfx2hlsl_src_scc_check.py: 12/12 ok, PASS.
  • All 62 tests/startup_gfx2hlsl_*_check.py scripts (including startup_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) and tests/bidi_controls_check.py (1,723 files): passed.
  • Fail-first mutations on tools/startup/gfx2hlsl.py: flipping (scc ? 1u : 0u), bypassing the scc_verified check in u(), dropping the SCC_UNMODELLED clear, and dropping the join clear all fail startup_gfx2hlsl_src_scc_check.py (exit 1).

Not established

  • No DXC/WARP GPU dispatch was run on the emitted src_scc ternary expression.

AI-assisted (Gemini).

@triggered02

Copy link
Copy Markdown
Contributor Author

@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.

@triggered02

Copy link
Copy Markdown
Contributor Author

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 treats s_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 later src_scc read is refused with src_scc with unverified SCC instead of reading a stale scc variable. That is the safe direction for exactly the case in your review: s_cmp_eq_u32 sets SCC=0, s_add_u32 0xffffffff + 1 sets the hardware carry, and a following src_scc would otherwise read the stale 0.

The control that pins your blocker is in tests/startup_gfx2hlsl_src_scc_check.py:

  • §4, s_add_u32 carry after compare leaves SCC unverified and is refused — asserts refused_reason(...) == 'src_scc with unverified SCC' for the compare → s_add_u32 carry → src_scc sequence.
  • §5, reading src_scc after s_add_u32 is refused — the plain unmodeled-writer case, and s_add_u32 reading incoming verified src_scc is accepted for the input-before-write ordering.
  • §6, src_scc across a control-flow join is refused — the same state across a branch join.

Verified on branch head 619dfcf3 just now: tests/startup_gfx2hlsl_src_scc_check.py exit 0, tests/startup_translator_check.py exit 0, tests/docs_links_check.py exit 0 (git diff --check clean, tree clean). Removing the unverified-SCC transition makes §4/§5/§6 fail with the stale-scc lowering, 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.

legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
# Conflicts:
#	CMakeLists.txt
#	docs/experiments.md
#	tests/startup_gfx2hlsl_src_scc_check.py
#	tools/startup/gfx2hlsl.py
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 25, 2026
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.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_scc now lowers to (scc ? 1u : 0u) only while scc_verified is set. set_scc, set_exec_scc and the compare path set it. It is cleared at entry, at every join, at a non-fallthrough block start, after s_add_u32/s_addc_u32 on varying data, after every SCC_UNMODELLED op, and on the descriptor path. So the requested case (compare sets SCC to 0, then s_add_u32 0xffffffff + 1, then read src_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_UNMODELLED reset makes the carry checks fail (2 MISMATCH). Dropping the join reset also fails. Dropping only the if 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 scalar null work 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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 12c45b8 into R0Y00:main Nov 26, 2026
5 checks passed
tedin7 added a commit that referenced this pull request Nov 26, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup: src_scc is refused as an unknown scalar operand (1 of the remaining loading-screen shader refusals)

4 participants