shader: lower the SAD operations in the direct C++ compute path #2990
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2990"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T03:29:07Z.
Change
The direct compute frontend now lowers
v_sad_u8,v_sad_hi_u8,v_sad_u16,v_sad_u32andv_msad_u8. Before, it refused them withdirect DXIL lowering for <name>. Refs #2987, part of the integer-ALU coverage in #2935, from the same VOP3 probe as #2985.The results are those of
gfx2hlsl.py'ssad_u8,sad4_u8,sad_u16andsad_u32helpers and oftools/pixel_aot.py. Each adds S2 and wraps modulo 2^32:v_sad_u8v_sad_hi_u8v_sad_u16v_sad_u32v_msad_u8Source abs/neg, clamp and output modifiers stay refused with
direct ALU operand modifiers, as for the other integer VOP3 forms.Verification
Commit
750739d2oncpp-migration4ff5e36d, Windows 10.0.26100.9711,devpreset. NVIDIA Quadro M1000M, driver 32.0.15.7371, debug layer unavailable.ctest --preset dev --no-tests=error -R '^native_sad_|^native_direct_container$': 2 passed, 1 skipped.native_sad_controlspassed. It compiles the program, refuses the clamp form ofv_sad_u8, and checks that four mutated references each differ from the expected words: signed differences, msad unmasked, sad_hi unshifted, and S2 dropped.native_sad_hardwareskipped (77). It needs shader model 6.6 with wave32. The readback is not measured here. A run on a wave32 SM 6.6 adapter would be welcome.tests/startup_gfx2hlsl_sad_check.py(ref_sad_u8,ref_sad_u16,ref_sad_u32) andtests/startup_gfx2hlsl_sad_hi_msad_check.py(sad4_u8). I checked this once while writing the fixture; the fixture does not import them.python -B tests/docs_links_check.py: ok.Evidence and follow-up
The words were assembled with LLVM 15.0.7 (
clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding). The dispatch has two groups of 32 lanes. With n = lane + 32 * group:S0 bytes both above and below the S1 bytes occur. The 320 results and the guard words are compared with the reference. The note is
docs/experiments/native-direct-sad.md.Checklist
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T03:47:09Z.
Review: APPROVED
Review of head
750739d2. CI on the head is green. This is the wave32 SM 6.6 readback you asked for. Approving and merging.Code read: the five forms lower as unsigned
ABSDIFFover byte, halfword or dword lanes plus S2, modulo 2^32.v_sad_hi_u8shifts the byte sum by 16, andv_msad_u8drops each byte whose S1 byte is zero. This matches the RDNA 2 ISA definitions recorded for the pixel path indocs/experiments.md, including both halfword lanes forv_sad_u16and the mask taken from the S1 reference. Modifiers stay refused by the shared integer VOP3 check.Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2989, #2992 and #2994 merged onto
cpp-migration4ff5e36d; all four merge cleanly with each other.ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$'gives 88 tests, 84 passed and 4 skipped (77:native_comparison_pso_warp,native_heap_handle_probe_warp,native_global_srv_heap_replay_warpandstartup_compute_dispatch_native_warp, because WARP has no 32-lane waves).native_sad_hardwarepassed: "five SAD operations: 320 words of two groups and the guards matched".native_sad_controlspassed.Mutation here: taking the
v_msad_u8mask from S0 instead of S1 failsnative_sad_hardware, for example(12, '0x1ad', '0x0'). With it restored, it passes.As with the other ALU readbacks, this shows that the DXIL computes the documented operation on a desktop GPU, not what the console does. I will close #2987 by hand.
AI-assisted; the commands above were run locally.