compute: treat scalar min, max and absdiff as SCC writers #3301

Merged
SimSalabimse merged 2 commits from upstream-pr/3301 into main 2026-11-28 07:06:47 +00:00
SimSalabimse commented 2026-11-28 06:25:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-28T06:25:39Z.


Refs #3224.

uses_scc_after treated s_absdiff_i32, s_min_u32, s_min_i32 and s_max_i32 as SCC readers. The direct lowering already writes SCC for them: the min/max compare, and D != 0 for s_absdiff_i32. A symbolic byte-window descriptor field immediately before one of those ops was refused with "numeric SCC from a symbolic descriptor field".

They are now overwrites, next to s_max_u32. s_cselect, s_cmov and an SCC branch stay readers. A field whose result can be zero is still refused when a later instruction actually reads that SCC.

Tests. tests/native_direct_container_check.py adds source-built compute containers shaped like descriptor-sop1-preserves-scc: the address-field rewrite, then each of the four ops, then a use of the destination. descriptor-absdiff-then-cselect reads the SCC those ops just wrote. descriptor-sop1-before-scc-read still refuses s_cselect with no writer in between. check_scc_writer_mutant deletes the four overwrite entries from a copy of the list; each new case is then live and would refuse.

Linux ran that mutant and a syntax check of the test. The container compile needs the Windows test PC:

ctest --preset dev --no-tests=error -j 1 -R '^(native_direct_container|native_bytewin_store_controls)$'

Windows test PC at 2e44056f: native_direct_container and native_bytewin_store_controls both passed (2/2), and again on a second run (exit 0 both times).

AI-assisted (Cursor)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5537438739 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3301). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-28T06:25:39Z. --- Refs #3224. uses_scc_after treated s_absdiff_i32, s_min_u32, s_min_i32 and s_max_i32 as SCC readers. The direct lowering already writes SCC for them: the min/max compare, and D != 0 for s_absdiff_i32. A symbolic byte-window descriptor field immediately before one of those ops was refused with "numeric SCC from a symbolic descriptor field". They are now overwrites, next to s_max_u32. s_cselect, s_cmov and an SCC branch stay readers. A field whose result can be zero is still refused when a later instruction actually reads that SCC. Tests. tests/native_direct_container_check.py adds source-built compute containers shaped like descriptor-sop1-preserves-scc: the address-field rewrite, then each of the four ops, then a use of the destination. descriptor-absdiff-then-cselect reads the SCC those ops just wrote. descriptor-sop1-before-scc-read still refuses s_cselect with no writer in between. check_scc_writer_mutant deletes the four overwrite entries from a copy of the list; each new case is then live and would refuse. Linux ran that mutant and a syntax check of the test. The container compile needs the Windows test PC: ctest --preset dev --no-tests=error -j 1 -R '^(native_direct_container|native_bytewin_store_controls)$' Windows test PC at 2e44056f: native_direct_container and native_bytewin_store_controls both passed (2/2), and again on a second run (exit 0 both times). AI-assisted (Cursor)
Leyukaka commented 2026-11-28 06:48:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T06:48:53Z.


I reviewed the diff (not run). Treating these ops as SCC writers looks right. The PR only changes the liveness list in uses_scc_after. The SCC predicates in the lowering are unchanged, and neither the existing nor the new checks read the flag back:

  • Compile only, with equal inputs. Each new case compiles one op on s22 = s23 = 0 and checks that the container is produced. With equal operands, min, max and absdiff all give D = 0 and SCC = 0. The existing lowering would still pass if it set SCC from <= instead of <, or did not write SCC at all.
  • The cselect case does not observe the flag. descriptor-absdiff-then-cselect selects between two zero registers into s25, which nothing reads. v_mov reads s26. So the select result does not depend on SCC either.
  • A readback would pin the flag. A dispatch that stores D and SCC for each op would do it, for example with s_cselect_b32 between distinct constants. Useful operand pairs:
    • S0 < S1 and S0 > S1;
    • S0 == S1, for the tie;
    • 0xffffffff against 1, which separates signed from unsigned min and max;
    • 0x80000000 against 0, for absdiff.

The branch also conflicts with main now: main added s_or_saveexec_b32 on the same overwrites line.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235534165 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3301#issuecomment-7235534165). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-28T06:48:53Z. --- I reviewed the diff (not run). Treating these ops as SCC writers looks right. The PR only changes the liveness list in `uses_scc_after`. The SCC predicates in the lowering are unchanged, and neither the existing nor the new checks read the flag back: - **Compile only, with equal inputs.** Each new case compiles one op on `s22 = s23 = 0` and checks that the container is produced. With equal operands, min, max and absdiff all give D = 0 and SCC = 0. The existing lowering would still pass if it set SCC from `<=` instead of `<`, or did not write SCC at all. - **The cselect case does not observe the flag.** `descriptor-absdiff-then-cselect` selects between two zero registers into `s25`, which nothing reads. `v_mov` reads `s26`. So the select result does not depend on SCC either. - **A readback would pin the flag.** A dispatch that stores D and SCC for each op would do it, for example with `s_cselect_b32` between distinct constants. Useful operand pairs: - S0 < S1 and S0 > S1; - S0 == S1, for the tie; - `0xffffffff` against 1, which separates signed from unsigned min and max; - `0x80000000` against 0, for absdiff. The branch also conflicts with `main` now: `main` added `s_or_saveexec_b32` on the same `overwrites` line. AI-assisted.
pigalot commented 2026-11-28 06:54:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T06:54:09Z.


Merged main 48ca9ab1 into this branch as 1fae35a5 (a merge commit, no rebase) so the PR can merge again.

Resolved conflict. tests/native_direct_container_check.py: this branch's SCC-writer checks (SCC_WRITERS, check_scc_writer_mutant, the descriptor-<name>-kills-scc and descriptor-absdiff-then-cselect cases) and main's descriptor-or-saveexec-kill and or-saveexec-exec-destination checks are both kept, in that order. src/gfx1013_direct_compute.inl merged without conflict, and each new writer name appears once in the uses_scc_after overwrites list.

What I ran on 1fae35a5.

  • Builds: full dev and release /O2.
  • Python: python -B tests/native_direct_container_check.py passes, including the SCC-writer mutant step (each new case fails once its overwrites entry is removed).
  • CPU: ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^native_' -E '_hardware$' gives 158 tests in each preset: 140 pass, 0 fail and 18 are capability skips. native_direct_container passes.
  • Hardware: under the GPU lock, native_wave_request_hardware, native_descriptor_scc_hardware and native_or_saveexec_hardware pass 3/3 in each preset at -j 1, with no skips.
  • Full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 2042 tests: 1982 pass, 0 fail and 60 are capability skips.

Since then main has moved to bbf4687b (#3295, #3293). 1fae35a5 still merges cleanly over it, and #3295's one hunk in src/gfx1013_direct_compute.inl adds a new lowering away from the SCC liveness code.

This is not a review. Because I pushed the merge, another reviewer should review the PR.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235589383 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3301#issuecomment-7235589383). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-28T06:54:09Z. --- Merged `main` `48ca9ab1` into this branch as `1fae35a5` (a merge commit, no rebase) so the PR can merge again. **Resolved conflict.** `tests/native_direct_container_check.py`: this branch's SCC-writer checks (`SCC_WRITERS`, `check_scc_writer_mutant`, the `descriptor-<name>-kills-scc` and `descriptor-absdiff-then-cselect` cases) and `main`'s `descriptor-or-saveexec-kill` and `or-saveexec-exec-destination` checks are both kept, in that order. `src/gfx1013_direct_compute.inl` merged without conflict, and each new writer name appears once in the `uses_scc_after` `overwrites` list. **What I ran on `1fae35a5`.** - **Builds:** full `dev` and `release` `/O2`. - **Python:** `python -B tests/native_direct_container_check.py` passes, including the SCC-writer mutant step (each new case fails once its `overwrites` entry is removed). - **CPU:** `ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^native_' -E '_hardware$'` gives 158 tests in each preset: 140 pass, 0 fail and 18 are capability skips. `native_direct_container` passes. - **Hardware:** under the GPU lock, `native_wave_request_hardware`, `native_descriptor_scc_hardware` and `native_or_saveexec_hardware` pass 3/3 in each preset at `-j 1`, with no skips. - **Full suite:** `ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)'` gives 2042 tests: 1982 pass, 0 fail and 60 are capability skips. Since then `main` has moved to `bbf4687b` (#3295, #3293). `1fae35a5` still merges cleanly over it, and #3295's one hunk in `src/gfx1013_direct_compute.inl` adds a new lowering away from the SCC liveness code. This is not a review. Because I pushed the merge, another reviewer should review the PR. Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off. This reply was AI-assisted.
pigalot commented 2026-11-28 07:06:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T07:06:16Z.

Review: APPROVED


I reviewed 1fae35a5 merged over main bbf4687b. The merge is clean (tree d7e61802) and git diff --cached --check is clean. This is the first content review of this PR; the merge of main was pushed by another session. main has since moved to 336e1206 (#3014, #3302). Neither touches either changed file, and the merge is still clean.

Merge resolution. git show --remerge-diff 1fae35a5 shows that only tests/native_direct_container_check.py conflicted. Both sides are kept:

  • this branch's four descriptor-*-kills-scc cases and descriptor-absdiff-then-cselect;
  • main's s_or_saveexec_b32 cases.

In uses_scc_after, the overwrites list now has both main's s_or_saveexec_b32 and this PR's four ops.

What I traced. The RDNA 2 ISA defines how these ops set SCC:

  • S_MIN_I32/S_MIN_U32/S_MAX_I32 set SCC = (S0 < S1) or (S0 > S1);
  • S_ABSDIFF_I32 sets SCC = (D != 0).

The direct lowering already writes SCC for all four:

  • the min/max block writes zext(pred) to SCC when scalar;
  • s_absdiff_i32 takes the scalar tail's cmp ne z, 0.

None of them reads the incoming SCC, so moving them into overwrites next to s_max_u32 is right. s_cselect, s_cmov and an SCC branch remain readers.

The new words decode as SOP2 ops 6, 7, 8 and 0x2c (s_min_i32, s_min_u32, s_max_i32, s_absdiff_i32), writing s26 from s22, s23. 0x85191716 is s_cselect_b32 s25, s22, s23.

What I ran. I built compile_dxil native_store_replay offscreen_check native_compute_ir_dump native_global_srv_heap_replay native_compute_manifest_reasons in dev and release, then ran:

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^native_' -E '_hardware'
python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^native_.*(scalar|sop|scc|absdiff|min|max|direct|bytewin|descriptor).*_hardware$'
  • Non-hardware: 154 tests per preset. 136 pass and 18 skip with 77 (capability skips), in both Debug and Release /O2. native_direct_container and native_bytewin_store_controls pass.
  • Hardware: 9/9 pass in both presets, including native_descriptor_scc_hardware, native_absdiff_hardware, native_bytewin_store_hardware and native_int32_minmax3_hardware.

Mutants. check_scc_writer_mutant reads the .inl source, so a mutant of the list fails at its count == 1 assert before any container compiles. To see whether the compiled cases catch the change on their own, I removed that call from a scratch copy of the test. Then I dropped one entry at a time from overwrites, rebuilt compile_dxil in dev, and ran the copy:

Mutant Result
s_min_u32 not an overwrite killed (its descriptor-…-kills-scc compile refuses)
s_min_i32 not an overwrite killed
s_max_i32 not an overwrite killed
s_absdiff_i32 not an overwrite killed

So each new case would also fail on main, where all four entries are missing.

Non-blocking: nothing pins the SCC values these ops write. Leyukaka is right that the new cases only compile. I checked whether anything else on main pins those values. Each mutant below was rebuilt in dev and run against all non-hardware ^native_ tests, then against the six hardware tests above (absdiff, descriptor_scc, int32_minmax3, scalar_lds, bytewin_store, lane_spill_descriptor):

Mutant Result
scalar min/max SCC from <=/>= (ties set SCC; D unchanged) survives
scalar min/max SCC not written survives
s_absdiff_i32 SCC inverted killed by native_absdiff_hardware

This PR doesn't change those predicates. But it lets a later s_cselect consume the min/max SCC after a symbolic field, where that program used to be refused. So the unpinned min/max flag now matters in more programs.

A small readback dispatch would pin it. Store D and s_cselect_b32 of two distinct constants on the flag for:

  • S0 < S1, S0 > S1 and S0 == S1;
  • 0xffffffff against 1, which separates signed from unsigned.

That would fit a follow-up for #3224; it doesn't need to block this PR.

Verdict: approve on 1fae35a5.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.
CI: Build and test on Windows passes on 1fae35a5.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6096397036 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3301#pullrequestreview-6096397036). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-28T07:06:16Z. **Review:** APPROVED --- I reviewed `1fae35a5` merged over `main` `bbf4687b`. The merge is clean (tree `d7e61802`) and `git diff --cached --check` is clean. This is the first content review of this PR; the merge of `main` was pushed by another session. `main` has since moved to `336e1206` (#3014, #3302). Neither touches either changed file, and the merge is still clean. **Merge resolution.** `git show --remerge-diff 1fae35a5` shows that only `tests/native_direct_container_check.py` conflicted. Both sides are kept: - this branch's four `descriptor-*-kills-scc` cases and `descriptor-absdiff-then-cselect`; - `main`'s `s_or_saveexec_b32` cases. In `uses_scc_after`, the `overwrites` list now has both `main`'s `s_or_saveexec_b32` and this PR's four ops. **What I traced.** The RDNA 2 ISA defines how these ops set SCC: - `S_MIN_I32`/`S_MIN_U32`/`S_MAX_I32` set `SCC = (S0 < S1)` or `(S0 > S1)`; - `S_ABSDIFF_I32` sets `SCC = (D != 0)`. The direct lowering already writes SCC for all four: - the min/max block writes `zext(pred)` to SCC when `scalar`; - `s_absdiff_i32` takes the scalar tail's `cmp ne z, 0`. None of them reads the incoming SCC, so moving them into `overwrites` next to `s_max_u32` is right. `s_cselect`, `s_cmov` and an SCC branch remain readers. The new words decode as SOP2 ops 6, 7, 8 and `0x2c` (`s_min_i32`, `s_min_u32`, `s_max_i32`, `s_absdiff_i32`), writing `s26` from `s22`, `s23`. `0x85191716` is `s_cselect_b32 s25, s22, s23`. **What I ran.** I built `compile_dxil native_store_replay offscreen_check native_compute_ir_dump native_global_srv_heap_replay native_compute_manifest_reasons` in `dev` and `release`, then ran: ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^native_' -E '_hardware' python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^native_.*(scalar|sop|scc|absdiff|min|max|direct|bytewin|descriptor).*_hardware$' ``` - **Non-hardware:** 154 tests per preset. 136 pass and 18 skip with 77 (capability skips), in both Debug and Release `/O2`. `native_direct_container` and `native_bytewin_store_controls` pass. - **Hardware:** 9/9 pass in both presets, including `native_descriptor_scc_hardware`, `native_absdiff_hardware`, `native_bytewin_store_hardware` and `native_int32_minmax3_hardware`. **Mutants.** `check_scc_writer_mutant` reads the `.inl` source, so a mutant of the list fails at its `count == 1` assert before any container compiles. To see whether the compiled cases catch the change on their own, I removed that call from a scratch copy of the test. Then I dropped one entry at a time from `overwrites`, rebuilt `compile_dxil` in `dev`, and ran the copy: | Mutant | Result | |---|---| | `s_min_u32` not an overwrite | killed (its `descriptor-…-kills-scc` compile refuses) | | `s_min_i32` not an overwrite | killed | | `s_max_i32` not an overwrite | killed | | `s_absdiff_i32` not an overwrite | killed | So each new case would also fail on `main`, where all four entries are missing. **Non-blocking: nothing pins the SCC values these ops write.** Leyukaka is right that the new cases only compile. I checked whether anything else on `main` pins those values. Each mutant below was rebuilt in `dev` and run against all non-hardware `^native_` tests, then against the six hardware tests above (`absdiff`, `descriptor_scc`, `int32_minmax3`, `scalar_lds`, `bytewin_store`, `lane_spill_descriptor`): | Mutant | Result | |---|---| | scalar min/max SCC from `<=`/`>=` (ties set SCC; D unchanged) | survives | | scalar min/max SCC not written | survives | | `s_absdiff_i32` SCC inverted | killed by `native_absdiff_hardware` | This PR doesn't change those predicates. But it lets a later `s_cselect` consume the min/max SCC after a symbolic field, where that program used to be refused. So the unpinned min/max flag now matters in more programs. A small readback dispatch would pin it. Store D and `s_cselect_b32` of two distinct constants on the flag for: - `S0 < S1`, `S0 > S1` and `S0 == S1`; - `0xffffffff` against `1`, which separates signed from unsigned. That would fit a follow-up for #3224; it doesn't need to block this PR. **Verdict:** approve on `1fae35a5`. Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status. CI: `Build and test on Windows` passes on `1fae35a5`. This reply was AI-assisted.
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!3301
No description provided.