Repository navigation
Conversation
|
Tested
No game data used. |
…_u32 as the ISA sets it) into the integration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
Independent check of this PR (head Against the RDNA2 ISA (30-November-2020), 12.1 "SOP2 Instructions"
The PR's tests. Their expected values match the ISA formulas by hand; they are not taken from the code. What they leave out, none of which fails:
Run on hardware.
Not checked: AMD hardware (the expected values are the ISA's; an NVIDIA run shows only that the translated DXIL computes them), literal-constant operands, a title's shaders. Suggestion, optional: add one bit-31 case to each unsigned form and run AI-assisted (Claude Code). |
|
RDNA2 hardware measurement of the SCC rules in the table: all match, including the shifted-out bits for Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 141 operand pairs: all pairs of
For example, AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run. |
|
Both new SCC tests passed at ae8967c on an AMD Radeon RX 6700 XT (driver 32.0.21045.29003, Windows, Rust 1.98.1). I ran each test individually and verified the dispatch device by D3D12 adapter LUID. The RX 6700 XT completed all 12 min/max cases and all 7 shift/add cases. The separate WARP passes also passed, with no hardware skips or fallback. |
catminou4
left a comment
There was a problem hiding this comment.
Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head ae8967c:
cargo test -p victory-shader --locked: compiles clean, all ungated tests pass (no regressions vs main's 56).
Scope note: valu_tests/image_tests in victory-shader are #[cfg(all(test, windows))] — they need the Windows host backend (D3D12/dxil.dll), so they did not run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new SCC checks in valu_tests.rs still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.
These write SCC, but their lowering gave no SCC value, so the generic "result is not zero" stood in. The ISA sets it otherwise: - s_min_i32/u32, s_max_i32/u32: SCC = 1 when src0 is the value chosen (src0 < src1 for min, src0 > src1 for max). - s_lshl1..4_add_u32: SCC = 1 when (src0 << n) + src1 overflows 32 bits, through bits shifted out of src0 or the add's carry. So s_min_u32(5, 3) left SCC = 1 (3 is not zero) where the hardware leaves 0, and s_lshl1_add_u32(1, 0xFFFFFFFE) left 0 where it leaves 1; an s_cselect or s_cbranch_scc after them took the wrong side.
ae8967c to
9483b1a
Compare
…2 as the ISA sets it
…2 as the ISA sets it
tjthebigbearcat-hub
left a comment
There was a problem hiding this comment.
Verified this independently on Windows (hardware D3D12 adapter and WARP) on top of current main (ffe310e).
Results
cargo test --workspace --locked: passes, includings_min_and_s_max_set_scc_when_src0_is_chosenands_lshl_add_sets_scc_on_unsigned_overflow(victory-shader: 122 passed, 1 ignored).cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings.- Independent ISA sweep (tested locally, not part of this PR diff): For all eight instructions (
s_{min,max}_{i32,u32},s_lshl{1,2,3,4}_add_u32), compared both result andSCCagainst RDNA 2 ISA reference models across 265 input pairs each (a 15×15 edge grid around0,±1,2^28–2^31, and0xFFFFFFFx, plus 40 random pairs) on both adapters: 0 mismatches. Onmain, the same sweep fails for all eight sinceSCCfalls through toresult != 0.
Code
- min/max:
SCCuses the select's own comparison, so equal operands giveSCC = 0(src1chosen), matching the ISA. - lshlN_add:
(src0 >> (32 − n)) != 0 || r < tcovers both overflow paths, and withnin1..=4the shift is never 32 bits.
Why it matters: Beyond s_cselect / s_cbranch_scc, the s_lshlN_add_u32 carry feeds s_addc_u32 during 64-bit address calculation (base + (idx << n)). With the old result != 0, the high dword picks up a spurious +1 whenever the low result is non-zero, shifting addresses off by 4 GiB silently.
Nit (optional): The in-tree test covers s_lshl1 and s_lshl4 but not s_lshl2/s_lshl3 (they share the exact same code path and passed the sweep above, so extra cases are purely for completeness).
LGTM.
…fied together Merges Marvisak#156 Marvisak#162 Marvisak#168 Marvisak#169 Marvisak#368 Marvisak#379 Marvisak#456 Marvisak#587 Marvisak#990 Marvisak#1021 Marvisak#1048 Marvisak#1052 Marvisak#1053 Marvisak#1095 Marvisak#1142 Marvisak#1190 Marvisak#1211 Marvisak#1223 Marvisak#1259 Marvisak#1293 on top of the bundle of Marvisak#1402 (which is on Marvisak#1319, on main ffe310e), each head unchanged. Hunks that conflicted in emit/lower.rs, emit/valu_tests.rs and emit/diff_tests.rs were merged by keeping both sides (additions next to each other); a PR was kept only if cargo clippy -p victory-shader --all-targets -- -D warnings still passed with it. No instruction name is handled in two places. Marvisak#98 is not in this version: an offline measurement on a retail dump showed it loses 31 programs that validate on Marvisak#1402. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (381 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
Marvisak#168, Marvisak#89) Under `VICTORY_LATE_WAIT` and `VICTORY_RELAY`, `Shadow::stale_under_writes` and `Shadow::merge_under_writes` (`crates/victory-gpu/src/shadow.rs`) only iterated pages returned by the write-watch delta (`written`). Any page inside a pending shader `GpuWrite` range whose `copied` timestamp was still `0` (never copied into the host copy yet) and that did not appear in `written` was silently skipped, leaving it zeroed on the GPU while `Shadow::update` also skipped the pending range. Mirror `Shadow::copy_stale` by extracting `stale_pages_in` and scanning every page in `[a, e)` for `copied == 0 || write > copied` in both `stale_under_writes` and `merge_under_writes`. Add `shadow::relay_tests::stale_pages_include_uncopied_pages_absent_from_write_watch`.
What's wrong
On the console GPU, many scalar instructions also set a 1-bit flag, SCC, which later instructions can test.
s_cselectpicks between two values on it, ands_cbranch_scc0/1branches on it.ir.rscorrectly marks these instructions as writing SCC:s_min_i32,s_min_u32,s_max_i32,s_max_u32s_lshl1_add_u32,s_lshl2_add_u32,s_lshl3_add_u32,s_lshl4_add_u32Their lowering in
lower.rsdoesn't say what SCC becomes, so it falls back to the generic rule "SCC = result is not zero". The ISA defines SCC differently for these instructions:s_min_*src0 < src1)s_max_*src0 > src1)s_lshlN_add_u32(src0 << N) + src1overflows 32 bitsFor
s_lshlN_add_u32, the overflow includes bits shifted out of src0. The RDNA3 reference writes the pseudocode with a 64-bit intermediate.Examples of what goes wrong today:
Any
s_cselectors_cbranch_scc*that reads SCC after one of these takes the wrong side. Compilers don't often read SCC after these instructions (LLVM never does), but it is legal ISA, and the translated code should behave like the hardware when a shader does.What the fix does
Two small changes in
lower.rs, in the same style as the existing carry handling ofs_add_u32/s_addc_u32:result < src0 << N, unsigned).How it behaves after the fix
Tests
There are two new tests in
valu_tests.rs, using the synthetic-shader harness from #37. Each test runs the instruction on two inputs, reads SCC back withs_cselect_b32 s13, 1, 0, and stores it:s_min_and_s_max_set_scc_when_src0_is_chosen: all four min/max forms, with src0 chosen, src1 chosen, and equal inputs.s_lshl_add_sets_scc_on_unsigned_overflow:s_lshl1_add_u32ands_lshl4_add_u32, with no overflow, overflow through the add, and overflow through the shift.I ran
cargo test -p victory-shaderon GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml. There's no GPU there, so the harness runs the shaders on WARP. Results:This PR: both new tests pass; the shader crate has 71 passed and 0 failed.
The new tests alone on
main: both fail. SCC is 1 where the hardware gives 0 (left: 1, right: 0), because the result is non-zero.With
--test-threads=4, the test process sometimes crashes on that runner (STATUS_ACCESS_VIOLATION) before reporting the GPU tests. Unmodifiedmaindoes this too: it crashed in 3 of 3 runs. So the numbers above come from--test-threads=1runs, which are clean.I tested only the shader crate:
cargo test --workspacedoesn't build onmainright now, because of a duplicatemod testsinvictory-gpu/src/host.rs, which GPU: rename the second test module in host.rs so the tests compile #129 fixes.Not tested: a real GPU, or a title's shaders that use these instructions.