Skip to content

compute: accept vcc_hi as the wave32 mask of SDWA compares - #3157

Merged
tedin7 merged 2 commits into
R0Y00:mainfrom
Leyukaka:sdwa-vcchi
Nov 27, 2026
Merged

tedin7 merged 2 commits into
R0Y00:mainfrom
Leyukaka:sdwa-vcchi

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Part of #2935. Target branch main.

Change (src/gfx1013_compute_native.cpp, one line in docs/experiments/native-sdwa-f16.md): in the direct wave32 compute path, an SDWA VOPC compare or v_cmp_class_f32 may write its lane mask to vcc_hi (s107). Reading vcc_hi as a scalar source was already accepted; the new test covers it.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on main 80668b97 plus this commit.

  • native_sdwa_vcc_hi_hardware (new) runs two 32-thread groups of a wave32 request (.sa bit 20 set).
    • v_cmp_class_f32_sdwa with src1_sel:BYTE_3 writes vcc_hi.
    • Then v_cmp_ne_i32_sdwa vcc_hi, vcc_hi, v6 with src1_sel:BYTE_0 reads it back as its scalar source.
    • Both masks are stored per lane and match a CPU reference, with every other word of the 2,064-word buffer untouched.
  • native_direct_container now also checks that these are refused:
    • a vcc_hi destination in a wave64 container stage, for both forms;
    • destination s108;
    • v_cmpx with vcc_hi.
  • native_sdwa_f16_ir and native_sdwa_f16_hardware pass.
  • Mutation checks, run by hand, each caught by one test:
    • accepting vcc_hi on wave64 fails native_direct_container;
    • keeping the old limit fails native_sdwa_vcc_hi_hardware.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests on main 80668b97.

  • 42 of 2,689 compute requests stopped first at one of the two refusals, all with vcc_hi as the destination: 29 v_cmp_class_f32_sdwa and 13 v_cmp_ne_i32_sdwa.
  • With this change, all 42 pass it. They then stop at "direct resource-heap load requires the selected GPU slot and its view type", so the compiled count stays at 403.
  • No request that compiled before stops compiling. The requests of one start-up run give the same result: 416 before and after.

AI-assisted.

In the direct wave32 compute path a VOPC mask is one SGPR, so an SDWA
compare or v_cmp_class may write it to vcc_hi (s107). The decoder capped
the destination at vcc_lo. A wave64 container stage, graphics, v_cmpx
with an SGPR destination and anything above s107 stay refused.

native_sdwa_vcc_hi_hardware writes both masks to vcc_hi in two groups,
reads vcc_hi back as the scalar source of a second compare, and checks
both per lane against a CPU reference; native_direct_container checks the
wave64 container, s108 and v_cmpx refusals.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of d3bc25a (updated with main). Comment only.

The SDWA compare destination limit becomes 107 (vcc_hi) only for direct wave32 compute (direct && !graphics && !wave64), and stays 106 for graphics and wave64, in both the compare-mask check and the class-modifier check. decode gets the wave size from its one direct caller, and the default wave64=false keeps the other callers as they were. The new refusal cases in native_direct_container_check.py cover vcc_hi under wave64, sdst 108 and v_cmpx with vcc_hi. They run without a GPU and pass here. The positive readback (native_sdwa_vcc_hi_hardware, wave32) skips on WARP and rests on the RTX 5080 run in the description, which also shows that the old limit fails it.

src/gfx1013_compute_native.cpp and tests/native_direct_container_check.py are also touched by cpp-migration. The change merges cleanly there; the native sweep on that merge is in the comment below.

Commands: git diff origin/main...pull/3157/head (read), git merge-tree --write-tree origin/cpp-migration pull/3157/head, plus the Windows commands in the comment below.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Windows Server 2025 verification of d3bc25a724ff6a6b66be77d79c916453a67f2fbf (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump; ctest --preset dev -R <native sweep>: 100% tests passed out of 146 (84 passed, 62 skipped), including native_direct_container and native_sdwa_f16_ir
  • release: same targets with --preset release; ctest --preset release -R <native sweep>: 100% tests passed out of 146 (84 passed, 62 skipped)
  • The same dev and release sweep on this head merged with cpp-migration (a0f67731): 100% tests passed out of 146 in both presets. A first attempt of that release leg stopped in the build when the remote ssh session was refused; the rerun passed.

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 108f554 into R0Y00:main Nov 27, 2026
5 checks passed
@KelboLive

Copy link
Copy Markdown
Contributor

Review of src/gfx1013_direct_compute.inl and src/gfx1013_compute_native.cpp changes:

Image instruction mask change (i.b & 0x3e000000u → 0x3c000000u) ✓

This tightens the rejection mask by removing bit 25 from the forbidden set. The gather_lod path already has its own stricter check at line 747 (i.b & 0xc0000000u), so this change only affects non-gather-lod image ops. Bit 25 of i.b in RDNA2 corresponds to the "unnormalized coordinates" flag for image instructions — allowing it is correct since unnormalized coords are valid for general image operations (just not for gather_lod which requires normalized).

SDWA mask limit variable (wave64-aware) ✓

The change from hardcoded 106/107 to a computed sdwa_mask_limit:

  • wave32 compute mode: limit 107 (register 107 is SCC in wave32)
  • wave64 or graphics mode: limit 106 (EXEC/VCC at 126 are handled separately)

This correctly reflects that register 107 is only a valid scalar mask destination when running in wave32 compute mode. The decoder now properly rejects invalid SDWA destinations based on the actual execution context.

Emit::image() mask change ✓

Same 0x3e → 0x3c change applied to the native pipeline's image validation, keeping both paths consistent.

Summary: Looks correct. Both changes are narrow and well-scoped — one fixes an overly restrictive mask for unnormalized coordinate image ops, the other makes SDWA destination validation wave-mode-aware. No issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants