Correct the SCC of scalar shift-adds, give signed scalar adds their overflow, and make exact f16 rounding cheaper #345
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
needs-logs
old-names
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!345
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-345"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@zhaochengggg on GitHub · 2026-11-27 18:47 UTC · original
zhaochengggg:fix/scalar-carry-and-f16-rounding→main· +60949 −5190 · 201 files · 634 commits · closed without mergingBase:
mainat10675b5Translator version: 15 → 16
What this changes
s_lshl1_add_u32…s_lshl4_add_u32set SCC to the carry. The ISA defines SCC as the carry out of(S0 << n) + S1taken in 64 bits: bits shifted out of the top count as well as the add's own carry. The lowering returned no carry, so SCC fell through to the default "result is not zero". A shader that branches on that SCC, or feeds it tos_addc_u32, got the wrong value.s_add_i32,s_sub_i32ands_addk_i32produce their SCC: signed overflow, as the ISA pseudocode defines it. A shader that read it was refused with "the carry of a scalar operation". It now translates.f16_nearest(VICTORY_F16_NEAREST=1, off by default) is computed on the bits. It uses the method of F. Giesen's public-domainfloat_to_half_fast3_rtne. The old form used four conversion ops (onef32tof16, threef16tof32). The new one uses integer ops and one f32 add. The results are identical (checked below). The new form also no longer depends on how the host'sf32tof16rounds.emit/alu_diff_tests.rs: a differential test of the integer ALU and the conversions. Each case is a one-instruction RDNA2 compute shader with a reference model written from AMD's ISA definitions. Inputs are edge values plus seeded random ones. Each case runs on the hardware adapter and on WARP. The test compares the result and the flags: SCC, VCC, the VOP3 carry-out, and, for ops the ISA says leave SCC alone, that SCC is unchanged.VICTORY_ALU_DIFF_ROUNDS=<n>multiplies the random inputs.Unused flag values are removed by the default
DEADpass, so DXIL only changes where an SCC from these instructions is actually read. The version bump covers any cached translation that reads one.How it was found and checked
Test PC: RTX 5070 Ti 16 GB (driver 621.14), 24-core / 32-thread Intel, 48 GB, Windows 11 26100. Also WARP. No title files were used: every shader is synthetic.
main(first harness version)s_lshl{1-4}_add_u32SCC, hardware and WARP) + 72 WARP pipeline-creation failuresVICTORY_F16_NEAREST=1, this branchv_cvt_f32_u32rounding slip is filtered; the hardware matches)main, all ofs_lshl{1,2,3,4}_add_u32gave SCC = 1 for inputs such as(0 << 1) + 1, on both the hardware and WARP. The ISA gives 0.s_mul_hi_*,s_bfm_b32,s_pack_*,s_ff1/s_flbit,s_bitset*,s_cmov,s_mulk_i32, …) left a preset SCC unchanged. This confirmsir::writes_scc.v_cvt_f16_f32,v_cvt_f16_u16,v_cvt_f16_i16) round toward zero on the RTX 5070 Ti and on WARP. Examples: 0.49999997 gives0x37FFinstead of0x3800; 3059 gives 3058 instead of 3060; 65520 and up give 65504 instead of +inf. This is the documented shortcut. WithVICTORY_F16_NEAREST=1every case matches the ISA, before and after this change.Cost of exact f16 rounding (
bench_f16_rounding_cost, ignored by default)The benchmark runs 4096 groups × 64 threads × 256 iterations of four dependent 16-long
v_add_f16chains. Times are the GPU time per dispatch: median of 10 samples of 64 timed dispatches, repeated in two runs.f32tof16(default, rounds toward zero on NVIDIA)VICTORY_F16_NEAREST=1,mainVICTORY_F16_NEAREST=1, this branchThis makes the exact path about 12% faster and 29% smaller in DXIL. It is still about 5.8× the default in this worst case, where every op is a half add. Whether the default should change is a decision for an in-game A/B run, which this PR does not make.
Regression tests
cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with--all-features: clean.cargo test -p victory-shader: 342 passed. The only 3 failures (rect::tests×2,barycentric_tests::first_half_values…) fail identically onmainon this PC. The validator there is the Windows SDK 10.0.22000dxil.dll(1.6.2104), which rejects the PSV0 part of the rectangle GS and the barycentric PS. See the notes below.cargo test -p victory-gpu: 496 passed.cargo xtask: passes.What this does not show
victory shaderson this branch and report how many translations changed.s_absdiff_i32,s_cmov_b32,s_bcnt0/s_ff0_i32_b32,s_sext_i32_i8/i16,s_brev_b64,s_flbit_i32_b64v_mul_lo_i32,v_add_nc_i32/v_sub_nc_i32,v_add_nc_i16/v_sub_nc_i16,v_mad_u32_u16/v_mad_i32_i16,v_lerp_u8,v_cmp_{f,t}_{i,u}64v_frexp_*_f32,v_cvt_pknorm_*,v_cvt_pk_{u16_u32,i16_i32},v_ldexp_f32, the f64 conversionsNotes for testers (not part of the change)
mainbecause that SDK's validator rejects PSV0.victory-hle'slifecycle::tests::direct_close_suspends_and_exitsand the diagnosticsreplaytest fail when run over SSH. They need an interactive desktop for windows and swap chains.🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 19:35 UTC · original
@zhaochengggg The WARP cases stop at compute pipeline creation with
The parameter is incorrect, before the value comparisons. The shift-add SCC fix would be easier to verify on its own with one WARP case that creates and dispatches the pipeline on the Windows runner. CI run@zhaochengggg on GitHub · 2026-11-28 01:27 UTC · original
Thanks. The failures were in the harness, not in the values: the runner has no hardware adapter, so WARP was the only device, and the cases whose programs declare the console's 32-lane wave size (lane masks read as numbers:
v_cmp_*, the VOP3 carry-outs,v_mad_u64_u32) were counted as wrong when WARP refused their pipelines. The skip only applied when a hardware adapter was there as well.fd03777:lower'swave_size), with or without hardware; without hardware such a case is listed as "run on no device". Any other pipeline failure is still wrong.scalar_shift_add_scc_is_the_64_bit_carry_on_warp:s_lshl{1..4}_add_u32on WARP only (pipeline creation and dispatch must succeed), from a table of expected values with rows where the 64-bit carry differs from "the result is not zero". Each row runs with SCC preset to 0 and to 1.signed_scalar_add_scc_is_the_overflow_on_warp: the same fors_add_i32,s_sub_i32,s_addk_i32, with rows where the signed overflow differs from the unsigned carry.With
main'slower.rsboth new tests fail (s_lshl1_add_u32inputs(0, 1): SCC 1, the ISA gives 0; the signed ones are refused); with this branch they pass. Locally (RTX 5070 Ti + WARP) the full differential run is unchanged: 401 cases, 26,880 runs, 0 wrong, 72 not made on WARP (fixed wave size). Clippy is clean in both configurations.On a runner without a graphics card WARP is the only device, and the cases whose programs declare the console's 32-lane wave size (lane masks read as numbers: v_cmp_*, the VOP3 carry-outs, v_mad_u64_u32) were counted as wrong when WARP refused their pipelines. A WARP pipeline failure is now skipped only for a program that declares a wave size, with or without a hardware adapter; such a case is listed as run on no device when there is no hardware. Any other pipeline failure is still wrong. Two small tests check the SCC changes on WARP alone, from tables of expected values: s_lshl{1..4}_add_u32 (the 64-bit carry, with rows where it differs from "the result is not zero") and s_add_i32 / s_sub_i32 / s_addk_i32 (the signed overflow, with rows where it differs from the unsigned carry). Each row runs with SCC preset to 0 and to 1. Both fail on main and pass here. Co-Authored-By: Claude Opus 5.5 <[email protected]>@TaynanGT on GitHub · 2026-11-29 11:24 UTC · original
Thanks for distinguishing unsupported wave-size pipelines from incorrect results. The main-versus-branch WARP controls with both initial SCC values are useful. Please keep cases that ran on no device explicit in the output.
@zhaochengggg on GitHub · 2026-11-29 17:22 UTC · original
Thanks. They are: the summary line counts them, and the next line names each one ("run on no device (no hardware adapter): …"). The CI run for
fd03777is waiting for approval.@TaynanGT on GitHub · 2026-11-29 19:02 UTC · original
Great, that explicit list is exactly what I wanted. I'll treat the pending CI run separately from the local differential results; unsupported fixed-wave cases should not count as successful executions.
@TaynanGT on GitHub · 2026-11-30 17:11 UTC · original
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.Pull request closed