compute: lower ds_bpermute_b32 without an LDS allocation #3320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3320"
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 Leyukaka on 2026-11-28T09:29:40Z.
Part of #3224 (claimed there). Target branch
main.ds_bpermute_b32uses the LDS crossbar but reads and writes no LDS memory. The direct compute path refused it with "LDS instruction without allocation" when the request had no LDS, and it had no lowering of its own.Change
src/gfx1013_compute_native.cpp:is_ds_bpermute()matches DS opcode0xb3with GDS and the reserved bit clear;ds_bpermute_b32 requires guest wave32.src/gfx1013_direct_compute.inl:lower_ds_bpermutecomputes((vaddr + offset) >> 2) & 31and reads that lane's source VGPR withWaveReadLaneAt.@ldsglobal is not emitted for a program whose only DS instruction isds_bpermute_b32.tests/native_direct_container_check.py:compute()takes an LDS block count. The default emits the same bytes as before.Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, Release, on
main3f780716plus this commit.native_ds_bpermute_controlschecks:waveReadLaneAtdataflow;addrspace(3)global or LDS barrier is emitted;ds_permute_b32keep "LDS instruction without allocation", and 32- and 64-thread wave64 requests get the new message.main'scompile_dxilthe positive program is refused with "LDS instruction without allocation", so the test fails there.native_ds_bpermute_hardwarepasses on the RTX 5080: 336 texture words, with lanes 1 and 8 disabled and two lanes reading disabled sources.native_ds_bpermute_warpreports a capability skip (77).ctest -R "native_|startup_compute|compile_dxil|salu"passes 528 of 529.native_scalar_lds_hardwarefails as onmain.compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests(counts only):main3f780716, and 251 with this commit;ds_bpermute_b32refusal, 8,956 dispatches in that run;The fewer-than-32-thread branch and multi-wave wave32 groups (64 threads and up) are not covered by a test. I did not run source mutations. The failure on
maincovers removing the change.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T11:17:58Z.
Review: COMMENTED
Review of head
773d4e3b(the PR's own change isb83a449f; the new head only merges currentmain). Not merged: the PR's own D3D12 WARP readback test fails on Windows Server 2025.What I checked:
src/gfx1013_compute_native.cppandsrc/gfx1013_direct_compute.inl: theds_bpermute_b32match (DS opcode 0xb3, GDS and reserved bit clear), the no-LDS exemption, the wave32-only refusal, and the lowering (byte address from the address VGPR plus offset, source lane = address / 4 masked to 32, an inactive source lane reads zero,waveReadLaneAtfor the data). This follows the public RDNA2 description of the backward permute.uses_ldscorrectly ignores the instruction, so no LDS global is declared.native_direct_containerstill passes.Result on Windows Server 2025, D3D12 WARP 1.0.22,
-R '^native_(ds_bpermute_(controls|warp)|direct_container|lds.*_controls)$':native_ds_bpermute_controlspassed,native_direct_containerpassed,native_ds_bpermute_warpFAILED.compared_words=336 mismatches=7, for exampleword=70 expected=00000022 actual=00000032, so the readback differs from the CPU reference for some lanes (debug layer clean).What is needed: the readback must match on WARP, or the WARP leg must skip cleanly (exit 77) when the adapter's wave behaviour differs, with the real-GPU leg as the guard. As it stands the PR's own WARP test is red, so I did not merge. Both of my mutations (source lane mask 31 to 15, EXEC check dropped) fail the controls test, so the controls do guard the lowering.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T11:26:29Z.
On WARP the per-lane
WaveReadLaneAtindex returned the wrong lane: word 70 expects0x22(lane 14) and reads0x32(lane 30), 16 lanes off. HLSL documents a non-uniform index as a shuffle, so this is a workaround for WARP: the new commit reads each present lane with a constant index and selects the one named by the address.native_ds_bpermute_controlsnow checks the 32 constant-index reads and the per-lane selection, andnative_ds_bpermute_hardwarestill matches 336 words on an RTX 5080. WARP skips here (no 32-lane wave), so the WARP leg is untested on my side.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T03:07:49Z.
Since the review of
773d4e3b:bd310649reads theds_bpermute_b32sources with constant lane indices, for the WARP mismatch reported there.native_ds_bpermute_warpskips here (no 32-lane wave), so a rerun of it on Server 2025 atbd310649is what would confirm the change.Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-29T12:55:12Z.
Review: APPROVED
Independently reviewed
bd310649integrated overmainfe1c1d31(tree2ad63d8c). The trial merge is clean andgit diff --checkis clean.I approve the change. I am not merging it: the WARP mismatch tedin7 reported on Windows Server 2025 (
word=70 expected=00000022 actual=00000032at773d4e3b) is what the second commit is for, and I could not confirm it.native_ds_bpermute_warpskips (77) on my machine because the inbox WARP has no 32-lane wave, and theBuild and test on Windowsjob does not run it either. A rerun of that test on Server 2025 atbd310649is the open item.What I traced
is_ds_bpermute:(i.a >> 16) == 0xdaccis DS encoding0x36, opcode0xb3, with bits 17 and 16 clear. The address, data and destination fields are read from bits 0-7, 8-15 and 24-31 of the second word.lower_ds_bpermute: source lane is((vaddr + offset) >> 2) & 31; the source test uses guest EXEC (s126) at the source lane's bit; the result goes throughvector_write, so an inactive destination lane keeps its old value.waveReadLaneAtcalls and the select chain choose the same lane as the earlier per-lane index. The group-size checks already onmain(partial final wave in multi-wave group) keep every host wave at 32 lanes when the group has 32 or more threads, so the constant indices 0-31 name present lanes there.ds_bpermute_b32now takes the new lowering instead oflocal_memory. No test covers that combination.Tests
Built
compile_dxilandoffscreen_checkindevandrelease, then ranctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^native_(ds_bpermute_(controls|warp)|direct_container|scalar_lds_controls|lds.*_controls|dpp8.*controls|image_atomic.*controls)$'and
native_ds_bpermute_hardwarealone with-j 1:/O2: 7 passed, includingnative_ds_bpermute_controlsandnative_direct_container;native_ds_bpermute_warpreported a capability skip (77), not a pass.native_ds_bpermute_hardwarepassed in both presets on the RTX 5090: 336 texture words matched, debug layer enabled, no debug errors or warnings.main,native_ds_bpermute_controlsandnative_ds_bpermute_hardwarefail.Mutants (dev build; controls and hardware run for each)
Killed, 14:
data1field; address register taken from thedata0field; destination write ignoring EXEC (2 mismatches); only 16 lanes read;@ldsemitted for the instruction; opcode0xb2matched instead of0xb3.l ^ 1(28 mismatches); select compared againstl ^ 1(28 mismatches). The controls test checks that the 32 reads and the 32 compares exist, but not which read each compare selects, so only the GPU leg catches a wrong pairing.Surviving, 3:
(i.a >> 18) == 0x36b3): no case sets either bit;direct_dxilcondition: no case sends the instruction through the non-direct path without an allocation;threads < 32branch removed: no case uses a group smaller than 32 threads (the PR body says so).Equivalent, 1:
source_lane = select(present, source_lane, lane);. With constant-index reads, an absent source lane matches none of thethreadscompares, so the value is 0, andenabledis false for it anyway. That line no longer has an effect and can go.None of the survivors blocks this. A refusal case for the GDS bit and a group of fewer than 32 threads in the hardware test would pin the first and third.
Title run of this head (merged onto the baseline commit): pass.
Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; NVIDIA GeForce RTX 5090 driver 32.0.16.1088, debug layer enabled; inbox WARP (no 32-lane wave,
native_ds_bpermute_warpskipped).CI:
Build and test on Windowspassed onbd310649; it does not run thenative_ds_bpermute_*tests.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T12:55:26Z.
Review of
bd310649against main77d1ba4d. Verdict: hold. It merges cleanly (git merge-tree --write-tree origin/main bd310649→ rc 0), but the WARP fix is still unverified.MUST
native_ds_bpermute_warpwas red on Windows Server 2025 at773d4e3b(compared_words=336 mismatches=7,word=70 expected=00000022 actual=00000032).bd310649changes the lowering for that failure, but nothing has run it on WARP since, because the author's WARP skips with 77. Since #3449 the native path is the default launcher path, so a wrong permute there would replace today's refusal (LDS instruction without allocationfor a program with no LDS) with wrong lane data. A WARP pass atbd310649would clear this.SHOULD
for (unsigned l = 0; l < (std::min)(threads, 32u); ++l)emits onewaveReadLaneAt.i32(DXIL 117) and one select per lane, so 32 of each perds_bpermute_b32. If WARP's non-uniformWaveReadLaneAtis the only problem, the per-lane form is the cheaper lowering for hardware. Please say in the comment or body which adapters showed the wrong lane, so the cost is a known trade.re.searchof theprpreset filter →Falsefornative_ds_bpermute_controlsandnative_ds_bpermute_warp.What I checked by reading:
is_ds_bpermuteis(i.a >> 16) == 0xdacc= DS0x36 << 10 | 0xb3 << 2, so op 179 with GDS and bit 16 clear.((addr + offset) >> 2) & 31, an inactive source reads 0, and wave64 is refused.uses_ldsskips the instruction, so no@ldsglobal is emitted.Nothing built or run here.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T14:14:38Z.
Re: review of
bd310649.MUST 1:
native_ds_bpermute_warppasses on WARP 1.0.22 atbd310649. Built atbd310649itself (not merged;git merge-tree --write-tree origin/main bd310649is clean againstmain0ed385dc),devpreset with-DX2W_WITH_OPUS=OFF, full build.d3d10warp.dllfrom the NuGet packageMicrosoft.Direct3D.WARP1.0.22 was placed next tooffscreen_check.exe.native_ds_bpermute_controlsDS gather DXIL dataflow and refusal diagnostics matchednative_ds_bpermute_warpDS gather and destination preservation matched across 336 texture wordsnative_ds_bpermute_hardwareDS gather and destination preservation matched across 336 texture words100% tests passed, 0 tests failed out of 3native_ds_bpermute_*test does not print the adapter or the driver. The WARP leg is a pass and not a capability skip (77), which the inbox WARP cannot give because it has no 32-lane wave. The WARP version comes from another test'soffscreen_checkoutput in the same session, with the same DLL copied the same way:adapter=Microsoft Basic Render Driver vendor=1414 device=008c,driver=1.0.22.0.debug_layer=unavailable, so the WARP pass is without the debug layer.SHOULD 1: adapters that showed the wrong lane. I have no run that shows it. The only observation is the reported one: WARP 1.0.22 on Windows Server 2025 at
773d4e3b(word=70 expected=00000022 actual=00000032). I did not run the per-lane index form on WARP 1.0.22, so the mismatch is not reproduced here, and the pass above does not show that the constant-index form is what fixes it. On the RTX 5080 onlybd310649was measured in this run.SHOULD 2: CI. Unchanged: this PR does not edit
CMakePresets.json, so theprpreset selects none of thenative_ds_bpermute_*tests.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T03:05:02Z.
The current main now supports padded partial final waves (#3808). Its LDS path explicitly refuses op 0xb3 under padding, but the new
is_ds_bpermutearm runs beforelocal_memory, and it reads unmaskedread(126)withthreads >= 32. This bypasses the refusal and can select a padded lane after a scalar EXEC write. Please rebase and keep the partial-tail refusal or use the valid-lane mask with a tail-lane readback control. The recorded WARP 1.0.22 and hardware passes on the older head are useful for the full-wave path.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T07:34:36Z.
Thanks for catching this. Fixed in
8f5dc89b2(rebased ontomain):lower_ds_bpermutenow refuses with the same reason as the LDS path,DS lane permutation is unsupported with a partial final wave, whenever the dispatch pads a final wave, before any EXEC read. A newpartial-tailcase (48 threads, wave32, no LDS, EXEC set to lanes 16..31) reproduces your scenario and expects that refusal.ds_permuteandds_swizzlestill go through the LDS path, which already refused them.native_ds_bpermute_*andnative_partial_final_wave_*pass on the new head.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T12:19:44Z.
Review: APPROVED
The padded-final-wave issue is addressed on
8f5dc89b. The new 48-thread control exercises a scalar EXEC write and checks the explicit DS permutation refusal before the lane read. I builtcompile_dxilandoffscreen_checkin Debug and ranctest --preset dev --no-tests=error -j 1 -R '^native_(ds_bpermute_|partial_final_wave_|direct_container$)' --output-on-failure. Three translation/control tests and both RTX 4060 Laptop GPU readbacks passed. The two inbox WARP tests returned 77 because it lacks a 32-lane wave (Windows build 26300.9974, NVIDIA driver 32.0.16.1656, WARP 10.0.26100.9818, debug layer enabled). The author's WARP 1.0.22 result remains separate. Trial merge and required Windows CI pass.