Repository navigation
Recompiler: complete remaining RDNA2 integer CLAMP=1 saturation (#105) - #202
JGonzalezRodriguez wants to merge 1 commit into
Conversation
|
Independent static code & RDNA2 ISA audit of Verified clean
Concerns / items to check before undrafting
(AI-assisted) |
|
One of the three new GPU tests can't pass yet: DXC turns Tested The head fixes two of its three new GPU tests on Windows/Blackwell. The third reaches a DXIL validation error before dispatch.
At RTX 5070 Ti, 610.74, native Windows D3D12, default SDK DXC 1.7 for the module. Built with Not tested Native wave64, Vulkan/vkd3d-proton, and retail shaders. The standalone compiler reduction was a compile-only check. AI use — Codex, GPT-6.2 Astra. |
Follow-up to ivall#119 (issue ivall#105 item 4), covering the remaining RDNA2 VALU integer instructions that support CLAMP=1 saturation and previously ignored it: - 16-bit integer (valu16 / valu_pk): v_add_nc_u16, v_sub_nc_u16, v_add_nc_i16, v_sub_nc_i16, v_mul_lo_u16, v_mad_u16, v_mad_i16, and v_pk_mul_lo_u16 (plus the legacy u16 aliases already matched in valu16) - 32-bit 24x24 / 16x16 mul/mad: v_mul_u32_u24, v_mul_i32_i24, v_mad_u32_u24, v_mad_i32_i24, v_mad_u32_u16, v_mad_i32_i16 (including SDWA CLAMP=1 forms via Self::mods) - 32-bit SAD/MSAD: v_sad_u32, v_sad_u8, v_sad_hi_u8, v_sad_u16, v_msad_u8 - 32-bit carry-out / carry-in: v_add_co_u32, v_sub_co_u32, v_subrev_co_u32, v_add_co_ci_u32, v_sub_co_ci_u32, v_subrev_co_ci_u32 (VOP3 + SDWA; saturates VDST while preserving unclamped carry/borrow in SDST/VCC) - 64-bit integer MAD (valu64): v_mad_u64_u32 and v_mad_i64_i32 (saturates 64-bit VDST while preserving the unclamped 65-bit SDST bit: unsigned carry-out for u64, bit 64 sign bit of the true 65-bit signed sum for v_mad_i64_i32) Compiler / backend fixes in the HLSL prelude: - sat_u32(uint64_t) uses branchless (uint)r | (0u - min((uint)(r >> 32), 1u)) instead of select(r > 0xFFFFFFFFu, ...): Windows SDK DXC 1.7-1.9.2602 lowers the select form on 64-bit products (v_mul_u32_u24 CLAMP=1) into forbidden llvm.umul.with.overflow.i32, failing DXIL validation. - Adds sat_i16(int) using select instead of ((uint)clamp(r, -32768, 32767) & 0xFFFFu) across 16-bit signed saturation sites: NVIDIA 610.57.4 (Vulkan / vkd3d-proton) drops the & 0xFFFF mask after SMin(SMax(r, -32768), 32767), leaking sign bits into the upper half of the destination VGPR. Adds GPU tests (wave64 + wave32) and a CPU-only HLSL codegen test covering CLAMP=1 saturation, CLAMP=0 wrapping, boundary pairs, SDST/VCC masks, SDWA CLAMP=1, and confirming v_cvt_pkrtz_f16_f32 ignores VOP3 OMOD/CLAMP.
c06f53b to
6c6b000
Compare
|
Thanks @Kalmarv and @ethandepstein-del for the thorough testing and static ISA review! Rebased onto
Re-verified on both RTX 4090 (110/110 + AI-assisted. |
|
Re-checked
Tested RTX 5070 Ti, driver 610.74, native Windows D3D12, SDK DXC 1.7.2308.16. Built with
Not tested
🤖 Claude Opus 5.5 |
|
Tested #202
|
|
Tested Pass: 655 passed, 0 failed, 40 ignored. GPU skips: the same 2 as on Run and written with Claude Code (Claude Opus 5.5). |
|
Tested Tested
Not tested
AI use: Claude Code with Claude Opus 5.5 (ran the tests and wrote this report). |
RDNA3: Radeon RX 7800 XT (native 64-lane waves) –
|
| GPU / driver | AMD Radeon RX 7800 XT (16 GB, RDNA3), driver 32.0.32029.2010; 32–64-lane waves, mesh shaders, SM 6.6 |
| CPU / RAM | AMD Ryzen 7 7800X3D, 32 GB DDR5-6000 |
| OS | Windows 11 Pro 26300 (native) |
| Toolchain | rustc 1.100.0 x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100); system XGameRuntime 10.0.26100.9656 |
Whole suite – .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) with XCL_REQUIRE_GPU=wave64,mesh, so a skipped GPU test would have failed:
| passed | failed | ignored | SKIPPED | |
|---|---|---|---|---|
main 85bdf21 |
665 | 0 | 41 | 0 |
this PR merged (07b7ba0) |
669 | 0 | 41 | 0 |
The 4 extra passes are this PR's tests (int_clamp_hlsl_codegen, gpu_int_clamp_16bit, gpu_int_clamp_32bit_mad_mul_sad, gpu_int_clamp_carry_and_64bit). By exact name with --test-threads=1: 4 passed natively and 4 passed with XCL_SPLIT_WAVE64=1 (the 32-lane split form on AMD); gpu::recomp:: under XCL_SPLIT_WAVE64=1: 186 passed, 0 failed, 18 ignored. So the clamped forms compile in the AMD driver's compiler and give the expected values on 64-lane hardware, in both wave forms.
Regression run – scripts/smoke.ps1 -Game <folder> on a retail title, release builds of main 85bdf21 and of the merge 07b7ba0, no uncommitted changes, same machine, the three runs one after the other in this order. All three: exit 0x0, 0 device removals, 0 crashes. The gpu: line names the wrong adapter (the script's known issue, #281 / #282 / #285); the GPU was the RX 7800 XT. Blocks unedited.
main, first run on an emptycache/(the First run of a title: the coherent window is 512 MB until uma_coherent.txt has been learned (menus at ~12 fps, then 30) #284 first-run window; a warm-up, not for comparison):
xcl-smoke v1
commit: 85bdf2193e7a793d568485b35f9cae5e8159bc39
gpu: Meta Virtual Monitor
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 372 (PresentX 372)
presents per 2 s (last 3): 8 8 7
device removals: 0
crashes: 0
peak commit: 15626 MB
main85bdf21, second run:
xcl-smoke v1
commit: 85bdf2193e7a793d568485b35f9cae5e8159bc39
gpu: Meta Virtual Monitor
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 421 (PresentX 421)
presents per 2 s (last 3): 8 8 8
device removals: 0
crashes: 0
peak commit: 15565 MB
- this PR merged onto
main(07b7ba0), first run with its exe:
xcl-smoke v1
commit: 07b7ba0d119806559a40f72e928fda3302135526
gpu: Meta Virtual Monitor
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 816 (PresentX 816)
presents per 2 s (last 3): 8 7 8
device removals: 0
crashes: 0
peak commit: 15550 MB
Reading: more frames than main (816 vs 421) and a slightly lower peak (15550 vs 15565 MB), no device removal, no crash. The 7–8 presents per 2 s at the end of the minute are the same on both builds: since #283 (9bd7635, in 85bdf21) the title's intro movie is drawn instead of green, and its per-frame plane upload is what sets the rate during the movie (8–9 presents / 2 s on an RX 7800 XT in the #283 thread too, with the detile profiled there). Not this PR's doing; on 9ab7d76 the same minute ran at 60 / 2 s with the green movie (see my #245 comment).
Not tested: release build of the test suite not run; no RDNA4 / RDNA2 here (RDNA2 is in the RX 6600 XT comment above).
Report written with Claude Code (Claude Fable 5.1) from the runs above; the commands and counts are from this machine.
Part of #105 item 4 (follow-up to #119). Completes the remaining RDNA2 (
GFX10.3) integerCLAMP=1saturation paths incrates/xcl/src/gpu/recomp/emit.rsand fixesv_mad_i64_i32SDSTsign-bit calculation.What is in it
valu16&valu_pk(16-bit integerCLAMP=1, preserving untouched half &OP_SEL):v_add_nc_u16,v_sub_nc_u16,v_add_nc_i16,v_sub_nc_i16,v_mul_lo_u16,v_pk_mul_lo_u16,v_mad_u16,v_mad_i16(plus pre-existing aliasesv_add_u16/v_sub_u16/v_subrev_u16). On RDNA2 (GFX10.3), bothv_mul_lo_u16(VOP3) andv_pk_mul_lo_u16(VOP3P) saturate to0xFFFFuunderCLAMP=1(confirmed in AMDrocjitsuRdna2Profileand LLVMVOP3PInstructions.td/llvm-mc -mcpu=gfx1030).valu(32-bit 24×24 / 16×16 MUL & MAD, SAD/MSAD, carry add/sub):v_mul_u32_u24,v_mul_i32_i24,v_mad_u32_u24,v_mad_i32_i24,v_mad_u32_u16,v_mad_i32_i16,v_sad_u32,v_sad_u8,v_sad_hi_u8,v_sad_u16,v_msad_u8,v_add_co_u32,v_sub_co_u32,v_subrev_co_u32,v_add_co_ci_u32,v_sub_co_ci_u32,v_subrev_co_ci_u32(preserving unclampedSDST/VCCcarry/borrow, includingVOP2_VOP_SDWACLAMP=1).valu64(v_mad_u64_u32,v_mad_i64_i32): Saturates 64-bitVDSTunderCLAMP=1, and fixesv_mad_i64_i32SDSTto write bit 64 (sign bit of the exact 65-bit signed sum) instead of unsigned carry-out.v_cvt_pkrtz_f16_f32: Left untouched (VOP3OMOD/CLAMPdo not apply on RDNA2 per Mesa ACOb63aa2bb8eandrocjitsu), with regression tests asserting VOP3OMOD/CLAMPare ignored.sat_i16(int r)usingselect(...)to avoid an NVIDIA610.57.4SPIR-V bug that dropped& 0xFFFFuonclamp(r, -32768, 32767) & 0xFFFFu.sat_u32(uint64_t r)((uint)r | (0u - min((uint)(r >> 32), 1u))) so Windows SDK DXC1.7–1.9.2602does not emit invalidllvm.umul.with.overflow.i32DXIL (caught by@Kalmarv).Tested
rustc 1.98.1x86_64-pc-windows-msvcviaclang-cl 23.1.1+lld-link+xwinSDK10.0.26100, DXC1.9.2609, Proton Experimental + local relaxedvkd3d-proton):cargo build --release --workspace&cargo test --no-run --package xcl --lib: 0 errors, 0 warnings.610.57.4, wave32):gpu::recomp::tests::— 111 passed, 0 failed, 17 ignored (incl.int_clamp_hlsl_codegen, 3 new GPU clamp tests, andgpu_sparse_vram_descriptors_buffers_and_xmem);xcl_testtitle.exe47/50 passed (all 18 D3D12.X checks pass).radv 26.2.4, native wave64 + wave32):gpu::recomp::tests::— 107 passed, 0 failed, 17 ignored (skipping#175+ 3 pre-existing unrelated RADV f64/FMA failures; all newint_clamptests pass in both wave64 and wave32);xcl_testtitle.exe47/50 passed (all 18 D3D12.X checks pass).6c6b000below):@WarmMilkCodes(AMD Radeon RX 6600 XT RDNA2, Windows 11 23H2):cargo test --workspace -- --test-threads=4— 655 passed, 0 failed, 0 GPU tests skipped.@PHeitor1(RTX 5060 Ti, driver621.24, Windows 11 Pro 26300):cargo test --workspace -- --test-threads=4— 655 passed, 0 failed, 40 ignored (2 skips:no wave64).@Kalmarv(RTX 5070 Ti, driver610.74, Windows 11 + SDK DXC1.7.2308.16):gpu::recomp::— 186 passed, 0 failed, 18 ignored (and 187/187 merged with#246).Regression run
scripts/smoke.ps1run by a tester with a retail title.Not tested
scripts/smoke.ps1regression run.AI use