shader: refuse stale SCC reads after descriptor arithmetic #2297

Merged
RavenCurseBurg merged 2 commits from upstream-pr/2305 into main 2026-11-25 11:34:29 +00:00
RavenCurseBurg commented 2026-11-25 11:23:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T11:23:35Z.


Refs #2302, item 3.

A scalar ALU operation on a symbolic descriptor word can set SCC without emitting a runtime value for it. A later conditional select, move or branch could then silently consume an earlier comparison. The translator records the actual emitted SCC assignments and descriptor-derived writes. If a descriptor-derived flag can reach an SCC reader on any reachable path, translation reports the reader. A comparison that all such paths pass through makes the flag usable again. The traversal includes direct branches, proven calculated jumps and back edges.

Both the graphics and compute stages use this lowering. Their cache revisions advance together because a complete revision-9 manifest and bytecode would otherwise bypass translation. The runtime, offline key calculation and independent fixture keys use the updated revision.

Verification

  • The issue's eight source-built requests pair four readers (select, move, SCC0 branch and SCC1 branch) with the comparison before or after the AND. At main 5fa712ee, --refusals --json reported 8/8 clear and --pending published all eight manifests. At this head, four stale reads produce the expected per-reader refusal and no manifest, and all four refreshed controls still publish uav 0 table 1 16. These are counts from synthetic requests.
  • python -B tests/startup_gfx2hlsl_compute_check.py passed. The committed controls also cover a skipped refresh, the second pass of a two-iteration loop, an unreachable descriptor operation, 64-bit selects and moves, immediate moves, and a saveexec that supplies a fresh flag. On the base the new check failed because it accepted the stale select.
  • Verified the recorded gfx1013 fixture encodings against LLVM 15.0.7's integrated AMDGPU assembler (clang -cc1as). The upstream binary job uses llvm-mc-15.
  • Ran 59 host checks including all startup_gfx2hlsl*_check.py, the startup translator, compute requests, cache key consistency, documentation links and bidirectional-control checks. All passed. git diff --check passed.
  • Windows CTest selections for this change are ^startup_gfx2hlsl_compute_ and the indirect draw fixture that produces the graphics cache key. I'll post the Windows results on this head.

AI-assisted with Codex (GPT-6.2 Astra, xhigh).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6603376494 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2305). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T11:23:35Z. --- Refs #2302, item 3. A scalar ALU operation on a symbolic descriptor word can set SCC without emitting a runtime value for it. A later conditional select, move or branch could then silently consume an earlier comparison. The translator records the actual emitted SCC assignments and descriptor-derived writes. If a descriptor-derived flag can reach an SCC reader on any reachable path, translation reports the reader. A comparison that all such paths pass through makes the flag usable again. The traversal includes direct branches, proven calculated jumps and back edges. Both the graphics and compute stages use this lowering. Their cache revisions advance together because a complete revision-9 manifest and bytecode would otherwise bypass translation. The runtime, offline key calculation and independent fixture keys use the updated revision. **Verification** - The issue's eight source-built requests pair four readers (select, move, SCC0 branch and SCC1 branch) with the comparison before or after the AND. At main `5fa712ee`, `--refusals --json` reported 8/8 clear and `--pending` published all eight manifests. At this head, four stale reads produce the expected per-reader refusal and no manifest, and all four refreshed controls still publish `uav 0 table 1 16`. These are counts from synthetic requests. - `python -B tests/startup_gfx2hlsl_compute_check.py` passed. The committed controls also cover a skipped refresh, the second pass of a two-iteration loop, an unreachable descriptor operation, 64-bit selects and moves, immediate moves, and a saveexec that supplies a fresh flag. On the base the new check failed because it accepted the stale select. - Verified the recorded gfx1013 fixture encodings against LLVM 15.0.7's integrated AMDGPU assembler (`clang -cc1as`). The upstream binary job uses `llvm-mc-15`. - Ran 59 host checks including all `startup_gfx2hlsl*_check.py`, the startup translator, compute requests, cache key consistency, documentation links and bidirectional-control checks. All passed. `git diff --check` passed. - Windows CTest selections for this change are `^startup_gfx2hlsl_compute_` and the indirect draw fixture that produces the graphics cache key. I'll post the Windows results on this head. AI-assisted with Codex (GPT-6.2 Astra, xhigh).
upstream-sync closed this pull request 2026-11-25 12:01:45 +00:00
tedin7 commented 2026-11-25 12:01:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:26:38Z.

Review: COMMENTED


Review of head d73c12d6c37b5934470932641de4927cd14513ea (Linux only; no Windows run).

Result: no P1, no P2.

What I checked:

  • descriptor_scc_reads walks direct branches, fall-through, back edges and skips proven calculated-PC instructions. A later emitted SCC write (scc_effect == 'emitted') clears the stale state, as the PR text says.
  • Revision bump shader-9 -> shader-10 is consistent: tools/startup/gfx2hlsl.py (pipeline_key, compute_key), src/startup_stubs/d3d12_draw.inl:235,355, tests/startup_indirect_draw_indexed.cpp:235, tests/startup_compute_request_offline_check.py:33, docs/startup-runtime.md:192. No leftover shader-9 outside docs history.
  • set_exec_scc refactor keeps the same emitted text for saveexec/wrexec and now records the SCC effect.

Commands executed locally in the review worktree:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py -> passed
  • python3 -B tests/startup_compute_request_offline_check.py -> passed
  • python3 tests/docs_links_check.py -> 18 files, 446 links, ok
  • python3 tests/bidi_controls_check.py -> ok
  • git diff --check origin/main...HEAD -> clean

Mutations (reverted with git checkout -- .):

  1. Dropped the branch-target propagation in descriptor_scc_reads: the compute check fails (accepted, expected a refusal naming 'scc from descriptor data'). Killed.
  2. Made stale state sticky (stale = stale or ...) so a later emitted SCC write no longer clears it: the compute check fails (a refreshed control is refused). Killed.

Notes (nit):

  • nit: reads_scc is keyed on name prefixes plus src_scc; a future SCC-reading mnemonic (for example s_cmovk, s_absdiff-style carry readers) must be added there. A short comment pointing at the opcode list would help.
  • CI at review time: Linux Python checks pass; Windows build and fixture jobs were still pending. I did not run the Windows WARP pipeline, since this change is translator-side refusal logic covered by the Linux checks above.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6056763787 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2305#pullrequestreview-6056763787). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:26:38Z. **Review:** COMMENTED --- Review of head `d73c12d6c37b5934470932641de4927cd14513ea` (Linux only; no Windows run). **Result: no P1, no P2.** What I checked: - `descriptor_scc_reads` walks direct branches, fall-through, back edges and skips proven calculated-PC instructions. A later emitted SCC write (`scc_effect == 'emitted'`) clears the stale state, as the PR text says. - Revision bump `shader-9` -> `shader-10` is consistent: `tools/startup/gfx2hlsl.py` (`pipeline_key`, `compute_key`), `src/startup_stubs/d3d12_draw.inl:235,355`, `tests/startup_indirect_draw_indexed.cpp:235`, `tests/startup_compute_request_offline_check.py:33`, `docs/startup-runtime.md:192`. No leftover `shader-9` outside docs history. - `set_exec_scc` refactor keeps the same emitted text for saveexec/wrexec and now records the SCC effect. Commands executed locally in the review worktree: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` -> passed - `python3 -B tests/startup_compute_request_offline_check.py` -> passed - `python3 tests/docs_links_check.py` -> 18 files, 446 links, ok - `python3 tests/bidi_controls_check.py` -> ok - `git diff --check origin/main...HEAD` -> clean Mutations (reverted with `git checkout -- .`): 1. Dropped the branch-target propagation in `descriptor_scc_reads`: the compute check fails (`accepted, expected a refusal naming 'scc from descriptor data'`). Killed. 2. Made stale state sticky (`stale = stale or ...`) so a later emitted SCC write no longer clears it: the compute check fails (a refreshed control is refused). Killed. Notes (nit): - nit: `reads_scc` is keyed on name prefixes plus `src_scc`; a future SCC-reading mnemonic (for example `s_cmovk`, `s_absdiff`-style carry readers) must be added there. A short comment pointing at the opcode list would help. - CI at review time: Linux Python checks pass; Windows build and fixture jobs were still pending. I did not run the Windows WARP pipeline, since this change is translator-side refusal logic covered by the Linux checks above. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 12:01:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T11:28:51Z.


Added the LLVM AMDGPU opcode-table reference beside reads_scc in 3e750a37. The existing s_cmov prefix already covers s_cmovk_i32; the updated compute fixture checks it both before and after a fresh comparison. Re-ran the compute controls, offline cache-key test and source hygiene check after the comment change.

The Windows 2025 run at d73c12d6 built the runtime shim and indirect draw fixture. All 11 selected CTests executed and passed, including the translated indirect draw and the compute WARP controls. The WARP compute dispatches reported zero debug-layer warnings and errors. All three standard upstream jobs also passed at that head.

I also tested the accepted path through --pending and the generated CSO. After masking descriptor word 1, the shader compares the X group ID to 1 and stores the selected bit. WARP and a desktop RTX 4060 (32.0.15.9579, Windows 26100.9711) each matched 320/320 words over 12 groups. Flipping the expected predicate changed 288 data words on each adapter and preserved all 32 guard words. On the RTX, all five existing compute cases matched and all ten existing mutation controls produced their expected mismatches. The local renderer was built at 59a05959; the raw-buffer dispatch code is identical to the reviewed head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161102249 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2305#issuecomment-7161102249). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T11:28:51Z. --- Added the LLVM AMDGPU opcode-table reference beside `reads_scc` in 3e750a37. The existing `s_cmov` prefix already covers `s_cmovk_i32`; the updated compute fixture checks it both before and after a fresh comparison. Re-ran the compute controls, offline cache-key test and source hygiene check after the comment change. The [Windows 2025 run at d73c12d6](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45604184667) built the runtime shim and indirect draw fixture. All 11 selected CTests executed and passed, including the translated indirect draw and the compute WARP controls. The WARP compute dispatches reported zero debug-layer warnings and errors. All three standard upstream jobs also passed at that head. I also tested the accepted path through `--pending` and the generated CSO. After masking descriptor word 1, the shader compares the X group ID to 1 and stores the selected bit. WARP and a desktop RTX 4060 (32.0.15.9579, Windows 26100.9711) each matched 320/320 words over 12 groups. Flipping the expected predicate changed 288 data words on each adapter and preserved all 32 guard words. On the RTX, all five existing compute cases matched and all ten existing mutation controls produced their expected mismatches. The local renderer was built at 59a05959; the raw-buffer dispatch code is identical to the reviewed head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2297
No description provided.