gfx2hlsl: lower the compute buffer store off form when its data is proven wave-uniform #2643
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2651"
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 NiiRoZz on 2026-11-26T00:28:23Z.
Refs #1723. Part of #2274. Based on
main; no dependency on another open pull request.What changed
tools/startup/gfx2hlsl.py, compute stage only:buffer_store_dword{,x2,x3,x4}with neitheroffennoridxen(disassembled asoff) gives every lane thesame byte address: soffset (SGPR or inline constant) plus the 12-bit immediate. The active lanes therefore race
on one location. When every data VGPR holds one proven value in all enabled lanes, the race order does not
matter. The store then lowers like the accepted
offenform without the VGPR term(
a = (s20 + 8) & 0xfffffffcu; u0.Store(a, v5);). The descriptor, alignment and raw-conversion checks areshared with
offenthroughraw_table_uav_store, unchanged.v_readfirstlane_b32already uses: in the entry block with a known EXEC, or pastit with a recomputable expression (no join, EXEC write or overwrite since the definition). It is now shared as
Stage.proven_uniform_v, andop_v_readfirstlane_b32calls it; that function's behavior does not change.v_lshrrev_b64,v_lshlrev_b64andv_ashrrev_i64with only scalar or literal sources now mark bothdestination halves uniform. They use the same conditions
Stage.oneapplies to the 32-bitUNIFORM_VALUformsand record a recomputable expression for each half.
offstore is still refused, now with its own reason:buffer store off with data not proven wave-uniform. Thebuffer atomicoffform is unchanged.The address of the
offform follows the precedent already in the translator: the vertex-stageoffstore(
op_buffer_store_vs) and the glcbuffer_atomic_addoffpath both form the address the same way, as soffsetplus the immediate with no VGPR. With
offen = idxen = 0the MUBUF address has no per-lane term. The descriptorstride is cleared or proven zero by
store_descriptor, so a TID-add index contributes nothing either.Tests
On the branch commit, Windows,
out/pe-envPython:New cases in
check_off_stores()intests/startup_gfx2hlsl_compute_check.py. Each one replaces the store ofsynthetic case A:
v_mov_b32 v5, s20+buffer_store_dword v5, off, s[16:19], 0->a = (0) & 0xfffffffcu; u0.Store(a, v5);s20 offset:8->a = (s20 + 8) & 0xfffffffcu;v_lshrrev_b64 v[5:6], 4, s[20:21]+buffer_store_dwordx2 v[5:6], off, ...->u0.Store2(a, uint2(v5, v6));v_cmp+s_and_saveexec_b32+s_cbranch_execzguard: thev_mov_b32storeand the 64-bit-shift
dwordx2store are both accepted asif (exec & 1) u0.Store.... This exercises therecomputable-expression branch of the proof.
Two dispatched cases were added to
CASES. In both, every lane of a group writes the same address, and theexpected output words are computed in the check from the instruction semantics, not from the translator:
O-dword: 4 groups of 8 lanes.buffer_store_dword v5, off, s[16:19], s20 offset:8withv5 = key ^ gid.xand
s20 = 4 * gid.x. Expected: word2 + g=key ^ g, and every other word keeps the sentinel.O-shift: 4 groups of 32 lanes, the large group's shape.buffer_store_dwordx4 v[4:7], off, s[16:19], s22stores(gid.x, v_lshrrev_b64 4 of the (key, stride) pair, 0)with
s22 = 16 * gid.x. Expected: words4g..4g+3=(g, low and high words of (stride:key) >> 4, 0).Built
offscreen_checkin this worktree with the commands below. The run used the tree ofa84b269e, with thetest edits uncommitted at run time but identical to the committed content.
startup_gfx2hlsl_compute_controlsstartup_gfx2hlsl_compute_warpstartup_gfx2hlsl_compute_hardwareBoth runs were on Windows build 10.0.26300.10075 with the debug layer reporting
debug_errors=0 debug_warnings=0.There were no capability skips (77).
Hand-assembled words: six new
SPLICEentries and the 8 instructions of the O cases that were not alreadyrecorded. They are assembled from the RDNA 2 SOP1, SOP2, SOPP, VOP1, VOP3 and MUBUF field layouts.
check_hand_words()decodes each with the repository disassembler (tools/disasm_rdna2.pythroughgfx2hlsl.D) and asserts that the mnemonic and operands equal the intended source line. The branch is checked byits decoded target. CI's
binarymode also reassembles everyCASESsource andSPLICEline with llvm-mc 15.I did not run that locally because no llvm-mc is installed here.
Negative control
buffer store off with data not proven wave-uniform:v_lshrrev_b64 v[5:6], 4, v[3:4]);offcontrol row; only its expected reason textchanged);
v_cmp_gt_u32+s_mov_b32 exec_lo, vcc_lo);are a subset of the defining lanes, but the proof does not track that.
8ecaa8ec) fails on its first new assertion.That run reports
buffer store without the offen address formwhere the new reason is expected.O-dwordandO-shiftare both refused there with the old reasonbuffer store without the offen address form, checked once by translating each case against the basetranslator.
Local observation (counts only)
From one local run's census: 54 compute keys reported
... without the offen address form. Every one is anoffstore, except one that is a non-
glcbuffer atomicoff.Groups (translator tree of that run, data proof evaluated at the refusing store):
v_cmpxguardglcatomicoff(out of scope)After the change:
(52,785). Of these 7, one key accepts an earlier
offstore and is refused at a later one. 2 keys accept theiroffstore and then stop atv_readfirstlane_b32. 33 keys never reach the store, because they stop at earlierrefusals that this PR does not touch and that other local branches fix: resource-heap
s_load14,v_readfirstlane_b3213, other 6.offstore they reach (checked per key by hooking the store handler) and then stop at adifferent refusal, so they are not counted as a success:
s_cbranch_execzskip-per-lane definitions: 12 keys, 2,036,962 dispatches. This includes the 17-key group'slargest members.
v_readfirstlane_b32: 1 key, 4,475.Measured versus hypothesis
independently computed words, with 8 and 32 lanes per group writing the same address;
shows only that the translated HLSL matches the expected semantics on desktop GPUs. The
& 0xfffffffcuroundingof a register soffset is the existing
offenassumption (#2059). The view range for out-of-range stores is alsothe existing
offenassumption.Not verified
SPLICEentries and the O case sources. This is leftto CI's
binarymode; locally the words are checked only against the repository disassembler.This is the same limit every case in this check has.
offform. That form is refused at translation, so the race withdiffering values is never dispatched.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T00:31:37Z.
Review: COMMENTED
Review of head
a84b269e(comment only, not an approval).What I checked:
raw_table_uav_store: theoffform is accepted only whenuniform_offis set (compute buffer store); the atomicoffpath keeps its old rule. Immediate offset withoffis allowed only on that path.proven_uniform_vis the oldv_readfirstlane_b32condition moved into a helper; the readfirstlane call site keeps the same behavior.v_lshrrev_b64/v_lshlrev_b64/v_ashrrev_i64: both halves marked uniform only for scalar/literal sources, with the same entry-block / recomputable-expression conditions as the 32-bit forms.Commands run locally (Linux):
python3 tests/startup_gfx2hlsl_compute_check.pypasspython3 tests/docs_links_check.pypass,python3 tests/bidi_controls_check.pypass,git diff --check origin/main...HEADcleannot proven wave-uniformrefusal -> the test fails ("accepted, expected a refusal").proven_uniform_vignoreuniform_v-> the test fails the same way.No blocking findings. The Windows WARP dispatch of O-dword / O-shift is covered by the Win2025 run, which I will post separately.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T00:40:18Z.
Win2025 WARP receipt for head
6d6caa3aafter updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
6d6caa3abf8a495b7196da87559411b4034d8c9f:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2):42.50s(configure4.34s)ctest --preset dev -R 'startup_gfx2hlsl_compute' --parallel 2 --no-tests=error --output-on-failure): 29/29 passed (7.93s:startup_gfx2hlsl_compute_mbcnt_warp0.80s,startup_gfx2hlsl_compute_swapped-axes_warp0.33s,startup_gfx2hlsl_compute_c-unpredicated_warp0.31s,startup_gfx2hlsl_compute_b-offset_warp0.33s,startup_gfx2hlsl_compute_controls0.61s,startup_gfx2hlsl_compute_warp2.72s,startup_gfx2hlsl_compute_dropped-store_warp0.32s,startup_gfx2hlsl_compute_h-inner-unpredicated_warp0.30s,startup_gfx2hlsl_compute_g-swapped-offsets_warp0.33s,startup_gfx2hlsl_compute_f-broadcast_warp0.30s,startup_gfx2hlsl_compute_j-scalar-dropped_warp0.31s,startup_gfx2hlsl_compute_f-peer_warp0.33s,startup_gfx2hlsl_compute_g-overlap_warp0.34s,startup_gfx2hlsl_compute_k-block-entered_warp0.32s,startup_gfx2hlsl_compute_m-else-unswitched_warp0.31s,startup_gfx2hlsl_compute_mbcnt_hardware0.75s,startup_gfx2hlsl_compute_swapped-axes_hardware0.34s,startup_gfx2hlsl_compute_dropped-store_hardware0.31s,startup_gfx2hlsl_compute_b-offset_hardware0.32s,startup_gfx2hlsl_compute_c-unpredicated_hardware0.35s,startup_gfx2hlsl_compute_f-peer_hardware0.33s,startup_gfx2hlsl_compute_hardware2.66s,startup_gfx2hlsl_compute_f-broadcast_hardware0.36s,startup_gfx2hlsl_compute_g-swapped-offsets_hardware0.31s,startup_gfx2hlsl_compute_g-overlap_hardware0.35s,startup_gfx2hlsl_compute_j-scalar-dropped_hardware0.35s,startup_gfx2hlsl_compute_h-inner-unpredicated_hardware0.35s,startup_gfx2hlsl_compute_k-block-entered_hardware0.31s,startup_gfx2hlsl_compute_m-else-unswitched_hardware0.31s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2):69.50s(configure2.66s)ctest --preset release -R 'startup_gfx2hlsl_compute' --parallel 2 --no-tests=error --output-on-failure): 29/29 passed (7.03s:startup_gfx2hlsl_compute_mbcnt_warp0.63s,startup_gfx2hlsl_compute_controls0.43s,startup_gfx2hlsl_compute_swapped-axes_warp0.24s,startup_gfx2hlsl_compute_b-offset_warp0.27s,startup_gfx2hlsl_compute_dropped-store_warp0.28s,startup_gfx2hlsl_compute_c-unpredicated_warp0.30s,startup_gfx2hlsl_compute_warp2.19s,startup_gfx2hlsl_compute_f-peer_warp0.29s,startup_gfx2hlsl_compute_g-swapped-offsets_warp0.28s,startup_gfx2hlsl_compute_g-overlap_warp0.28s,startup_gfx2hlsl_compute_j-scalar-dropped_warp0.27s,startup_gfx2hlsl_compute_f-broadcast_warp0.26s,startup_gfx2hlsl_compute_h-inner-unpredicated_warp0.27s,startup_gfx2hlsl_compute_k-block-entered_warp0.27s,startup_gfx2hlsl_compute_m-else-unswitched_warp0.28s,startup_gfx2hlsl_compute_mbcnt_hardware0.74s,startup_gfx2hlsl_compute_swapped-axes_hardware0.31s,startup_gfx2hlsl_compute_dropped-store_hardware0.31s,startup_gfx2hlsl_compute_b-offset_hardware0.29s,startup_gfx2hlsl_compute_c-unpredicated_hardware0.30s,startup_gfx2hlsl_compute_f-peer_hardware0.29s,startup_gfx2hlsl_compute_hardware2.48s,startup_gfx2hlsl_compute_f-broadcast_hardware0.35s,startup_gfx2hlsl_compute_g-swapped-offsets_hardware0.33s,startup_gfx2hlsl_compute_g-overlap_hardware0.33s,startup_gfx2hlsl_compute_j-scalar-dropped_hardware0.32s,startup_gfx2hlsl_compute_h-inner-unpredicated_hardware0.33s,startup_gfx2hlsl_compute_k-block-entered_hardware0.31s,startup_gfx2hlsl_compute_m-else-unswitched_hardware0.32s)tests/mesh_heap_sampler_check.pyok (0.8s),tests/startup_buffer_address_check.pyok (0.6s),tests/startup_buffer_format_word3_table_check.pyok (0.1s),tests/startup_compute_image_store_check.pyok (1.0s),tests/startup_compute_image_store_d16_check.pyok (0.9s),tests/startup_compute_request_offline_check.pyok (0.9s),tests/startup_compute_store_format_xyzw_check.pyok (0.5s),tests/startup_compute_translate_check.pyok (0.4s),tests/startup_flat_param_check.pyok (0.3s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.2s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.3s),tests/startup_gfx2hlsl_bit_alu_check.pyok (1.4s),tests/startup_gfx2hlsl_capture_check.pyok (1.8s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.6s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.2s),tests/startup_gfx2hlsl_compute_check.pyok (0.8s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.2s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.4s),tests/startup_gfx2hlsl_cvt_off_f32_i4_check.pyok (0.4s),tests/startup_gfx2hlsl_cvt_pk_int16_check.pyok (0.5s),tests/startup_gfx2hlsl_f32_lg_check.pyok (2.4s),tests/startup_gfx2hlsl_f32_nan_check.pyok (7.8s),tests/startup_gfx2hlsl_fma_mix_check.pyok (0.1s),tests/startup_gfx2hlsl_getpc_refusal_check.pyok (0.1s),tests/startup_gfx2hlsl_handler_arity_check.pyok (0.1s),tests/startup_gfx2hlsl_image_arity_check.pyok (0.1s),tests/startup_gfx2hlsl_image_get_lod_check.pyok (0.2s),tests/startup_gfx2hlsl_int_med3_check.pyok (0.2s),tests/startup_gfx2hlsl_interp_p2_hi_check.pyok (0.3s),tests/startup_gfx2hlsl_join_symbols_check.pyok (0.3s),tests/startup_gfx2hlsl_loop_constants_check.pyok (0.1s),tests/startup_gfx2hlsl_mask_data_check.pyok (0.1s),tests/startup_gfx2hlsl_mask_overwrite_check.pyok (0.1s),tests/startup_gfx2hlsl_operand_count_check.pyok (0.4s),tests/startup_gfx2hlsl_pack_absdiff_check.pyok (5.1s),tests/startup_gfx2hlsl_pack_b32_f16_check.pyok (0.3s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.2s),tests/startup_gfx2hlsl_refusals_check.pyok (1.1s),tests/startup_gfx2hlsl_root_check.pyok (1.2s),tests/startup_gfx2hlsl_s_abs_check.pyok (0.2s),tests/startup_gfx2hlsl_s_bitset_check.pyok (0.1s),tests/startup_gfx2hlsl_sad_check.pyok (0.5s),tests/startup_gfx2hlsl_saveexec_same_reg_check.pyok (0.2s),tests/startup_gfx2hlsl_scalar_arity_check.pyok (0.4s),tests/startup_gfx2hlsl_scalar_brev_fold_check.pyok (0.3s),tests/startup_gfx2hlsl_scalar_m0_check.pyok (0.3s),tests/startup_gfx2hlsl_scalar_table_arity_check.pyok (0.6s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.3s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.4s),tests/startup_gfx2hlsl_shift64_check.pyok (0.4s),tests/startup_gfx2hlsl_sload_const_offset_check.pyok (0.2s),tests/startup_gfx2hlsl_smem_offset_check.pyok (0.2s),tests/startup_gfx2hlsl_sop2_complement_check.pyok (12.3s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (1.9s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.2s),tests/startup_gfx2hlsl_swap_check.pyok (0.6s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (8.9s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (3.2s),tests/startup_image_2d_array_check.pyok (0.3s),tests/startup_image_3d_check.pyok (0.3s),tests/startup_image_gather_lz_check.pyok (1.0s),tests/startup_image_load_d16_check.pyok (2.3s),tests/startup_image_sample_a16_check.pyok (0.4s),tests/startup_image_sample_b_check.pyok (0.4s),tests/startup_image_sample_c_check.pyok (0.3s),tests/startup_image_sample_l_check.pyok (0.3s),tests/startup_image_sample_lod_check.pyok (1.1s),tests/startup_inline_sampler_check.pyok (0.3s),tests/startup_mesh57_loop_refusal_check.pyok (0.3s),tests/startup_mesh57_skeleton_check.pyok (1.0s),tests/startup_run_ps1_check.pyok (20.4s),tests/startup_run_sh_check.pyskipped (0.1s),tests/startup_sampler_heap_check.pyok (0.3s),tests/startup_shader_cache_rekey_check.pyok (4.2s),tests/startup_smem_address_check.pyok (0.3s),tests/startup_stream_fetch_check.pyok (0.3s),tests/startup_stream_interface_check.pyok (0.4s),tests/startup_translator_check.pyok (0.8s)sccache: 71/107 hits; wall236.4sAI-assisted; commands listed were executed locally.