gfx2hlsl: prove a compute formatted load whose table pointer copy is in a block above #2453
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2461"
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-25T17:22:01Z.
Refs #870.
What / why
#2398 lowered
buffer_load_format_x/xy/xyz/xyzwfor compute. FORMAT and DST_SEL come from word 3 of thetable descriptor, so past the entry block the translator asks for a proof that the four descriptor words are
the table's: a table load in the same block as the formatted load, through an entry table pointer or through
an
s_mov_b32copy of one made in that same block.In a local set of 2,689 compute requests, 1,088 had this refusal first. In 1,086 of them the table load is in
the same block as the formatted load and covers the four words, but the pointer is a copy of the entry table
pointer made in a block above (the entry block in 1,084, another block that every path runs through in 2).
The copy being outside the block was the only missing link.
Change
tools/startup/gfx2hlsl.py, compute stages only:Stage.formatted_pointer_copy(pointer, before): walks every predecessor path back from the table load(the instruction graph
formatted_pointer_reachesalready builds, calculated jumps included) and stops eachpath at its first write to the pointer register. It returns the copy only if exactly one writer is found,
no path reaches the entry (or an instruction without predecessors) before a write, and that writer is
s_mov_b32 pointer, sN. The writer set is the union ofdescriptor_scalar_writesandscalar_destinations. (s_movrel*has no handler, so a program with one is refused anyway.)formatted_descriptor_from_blockuses it only when its own in-block scan finds no write to the pointer.The existing conditions then apply to the copied register unchanged: it must be an entry table pointer of
the descriptor's table, and
formatted_pointer_reachesmust find no write to it on any path into the copy.No emitted HLSL or manifest line changes. Graphics stages keep the previous rule.
Why it is sound
copy, and no path from the copy to the load writes the pointer again (such a write would be a second
writer). This holds for loops too: a back edge that rewrites the pointer is a second writer.
the existing rule already accepts: the load and the formatted read are in one block with no write to the
four words in between.
Only one copy hop is followed, as before.
Tests
tests/startup_gfx2hlsl_compute_check.py(check_formatted_pointer_copy), built from the source-builtformatted-load fixture:
through;
can refuse it); a back edge below the formatted read writes the pointer and re-enters at the load; the only
writer is not a register copy; the copied register is written on one path into the block that copies it.
The same program with that write replaced by
s_noptranslates.new accepted shape). The existing controls stay: a branch target between the load and the read, and a
rewritten word 3.
tests/startup_vertex_fetch_formats_check.py: a graphics stage with the copy in a block above stays refused.Five local mutants of the new code (accept several writers; ignore the entry path; drop the check on the
copied register; accept a writer that is not a copy; drop the compute gate) each fail these checks. They are not part of the commit.
Commands, Windows, Python 3.13, at
8dd05e2e:Not run:
startup_gfx2hlsl_compute_check.py binary(needs LLVM 15) and thedispatch/controlmodes behindstartup_gfx2hlsl_compute_(warp|hardware)(need DXC and the built runner). They dispatch the unchangedentry-block fixture and this change does not alter emitted HLSL, so what they exercise is unchanged. The new
accepted forms have no GPU run.
Measurement
Local set, first refusal per request, manifest-only (no DXC), translator = upstream main plus other open PRs:
Next first refusals of the 1,086 that moved:
s_and_saveexec_b32inside a blocks_cbranch_execzskips per lane: exec writes_nor_b32on a lane maskv_cndmask_b32s_mov_b32inside a blocks_cbranch_execzskips per lane: definition of vcc, live at the joinv_readfirstlane_b32requires a proven uniform sourcebuffer_store_format_xyzwNote: that one request then raises a TypeError in
ComputePipeline.manifest()(a sampler key with alodprefix, which the compute manifest does not format). Separate defect, not fixed here. No request in this set
translates completely yet, and nothing was compiled with DXC.
Limits
header sits between them; in the other the load overwrites its own pointer register and the read is many
blocks below). Proving those needs a reaching-definition proof for the four words, not for the pointer.
AI-assisted. Tests listed above ran locally.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:32:17Z.
Review: COMMENTED
Review of head
8dd05e2e(Linux only; no Windows run by me).What I checked
tools/startup/gfx2hlsl.py(newStage.formatted_pointer_copy, used only for compute stages when the in-block scan finds no write), the compute check and one formatted-fetch check. No emitted HLSL or manifest line changes, so no GPU readback applies; the body says the same.s_mov_b32 pointer, sNwith a single scalar source. The existing entry-table-pointer andformatted_pointer_reacheschecks then run on the copied register. I found no hole in the soundness argument in the body (loops: a back-edge write would be a second writer).check_formatted_pointer_copyhas accepted shapes and refused shapes (skipped copy, double write, back-edge write, non-copy writer, copied register rewritten on one path, word 3 rewritten between load and read).git checkout -- .:len(writers) != 1changed to< 1: the compute check fails (ValueError in the unpack).Commands run
git diff --check origin/main...HEAD(clean)python3 tests/startup_gfx2hlsl_compute_check.py(passed; the DXC readback part is the author's, I did not check it)python3 tests/startup_vertex_fetch_formats_check.py(passed)AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:59:42Z.
Verified on WARP and on a physical GPU, and the pointer-copy proof is pinned — two whitelist-shaped survivors
The GPU half of this PR I could actually run, because
startup_vertex_fetch_formats_check.pytakes<dxc> <offscreen_check> <adapter>:startup_gfx2hlsl_compute_check.py→compute entry, numthreads, masked bit counts, manifest, offen store forms and the store, descriptor, execz and sample refusals pass, exit 0.Mutations on
formatted_pointer_copylen(writers) != 1→not writers)s_mov_b32kind == 'cs'gate droppedThe middle row matters most: the whole proof is "walk back and find exactly one write, with no path that reaches the entry without a write". Dropping the "no path from the entry" condition means the entry value can be mistaken for a copy — a silently wrong pointer on every lane, which is the failure this change exists to prevent. It is caught, so the fixture builds a program where the pointer has an entry value as well as a write.
The two survivors
name == 's_mov_b32': the fixture's programs only ever uses_mov_b32as the copy, so accepting any two-operand instruction changes nothing observable. As_add_u32 s5, s6, 0in the same position should not be treated as a copy, and one case would pin that.kind == 'cs': the fixture is a compute check throughout, so the gate is constant there.Neither is a defect I can demonstrate: no input the fixture builds distinguishes them.
One thing I would check before merging
formatted_pointer_copyreturns the source register and instruction index, and the caller rewritespointer, read = copybefore consulting the descriptor tables. So the read's descriptor state is taken from a point earlier in program order — that only works if nothing between the copy and the read writes the pointer, which the docstring claims and the writer count is supposed to establish. The single-writer mutation being caught is evidence for it, but only for the program the fixture builds; if you want the claim pinned generally, the case to add is a second write between the copy and the read (still one write reaching the entry, two total), which must returnNone.Registration
No
CMakeLists.txt,AGENTS.mdor CI-list change: the vertex-fetch fixture is an existing one and the compute check is already registered. Both files simply gained cases, which keeps this to one reviewable behaviour.AI-assisted; both adapter runs and the five mutations were executed locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:04:29Z.
Review: COMMENTED
Review of head
b644306a(against current main, 12 commits behind).Checked:
formatted_pointer_copywalks back from the table load, stops each path at its first write, and returns a copy only for ones_mov_b32writer with no path reaching the entry. A later second write is found first, so an earlier copy cannot be mistaken for the last write. The source register is then re-checked byformatted_pointer_reaches.Commands run (all exit 0 unless noted):
git diff --check origin/main...HEADpython3 tests/docs_links_check.pypython3 tests/bidi_controls_check.pypython3 -B tests/startup_gfx2hlsl_compute_check.pylen(writers) != 1changed tonot writers. The compute check fails (ValueError).No blocking findings. Scope note: this is the translator's proof only. No game or executable result is claimed or verified here. The merge decision stays with MasterDomino or @R0Y00.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:14:31Z.
Win2025 WARP receipt for head
8c088116after updating with main (plan: py-checks + startup_vertex_fetch_formats_controls/warp + startup_gfx2hlsl_compute, dev and release).Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
8c088116d1a22515c96adeae1ed215099853badb:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2):1.05s(configure2.91s)ctest --preset dev -R 'startup_vertex_fetch_formats_(controls|warp)|startup_gfx2hlsl_compute' --parallel 2 --no-tests=error --output-on-failure): 29/29 passed (30.19s:startup_gfx2hlsl_compute_hardware2.62s,startup_gfx2hlsl_compute_warp2.38s,startup_gfx2hlsl_compute_b-offset_hardware0.33s,startup_gfx2hlsl_compute_dropped-store_hardware0.35s,startup_gfx2hlsl_compute_c-unpredicated_hardware0.35s,startup_gfx2hlsl_compute_swapped-axes_hardware0.35s,startup_gfx2hlsl_compute_dropped-store_warp0.33s,startup_gfx2hlsl_compute_c-unpredicated_warp0.33s,startup_gfx2hlsl_compute_swapped-axes_warp0.34s,startup_gfx2hlsl_compute_b-offset_warp0.35s,startup_gfx2hlsl_compute_mbcnt_warp0.82s,startup_gfx2hlsl_compute_controls0.44s,startup_gfx2hlsl_compute_mbcnt_hardware0.80s,startup_gfx2hlsl_compute_f-peer_warp0.36s,startup_gfx2hlsl_compute_f-broadcast_warp0.35s,startup_gfx2hlsl_compute_f-peer_hardware0.33s,startup_gfx2hlsl_compute_j-scalar-dropped_warp0.37s,startup_gfx2hlsl_compute_g-swapped-offsets_warp0.37s,startup_gfx2hlsl_compute_h-inner-unpredicated_warp0.39s,startup_gfx2hlsl_compute_g-overlap_warp0.38s,startup_gfx2hlsl_compute_f-broadcast_hardware0.50s,startup_gfx2hlsl_compute_g-swapped-offsets_hardware0.38s,startup_vertex_fetch_formats_controls0.19s,startup_gfx2hlsl_compute_k-block-entered_warp0.57s,startup_gfx2hlsl_compute_k-block-entered_hardware0.42s,startup_gfx2hlsl_compute_h-inner-unpredicated_hardware0.38s,startup_gfx2hlsl_compute_j-scalar-dropped_hardware0.37s,startup_gfx2hlsl_compute_g-overlap_hardware0.38s,startup_vertex_fetch_formats_warp29.99s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2):30.21s(configure3.04s)ctest --preset release -R 'startup_vertex_fetch_formats_(controls|warp)|startup_gfx2hlsl_compute' --parallel 2 --no-tests=error --output-on-failure): 29/29 passed (25.06s:startup_gfx2hlsl_compute_warp2.35s,startup_gfx2hlsl_compute_hardware2.30s,startup_gfx2hlsl_compute_dropped-store_hardware0.30s,startup_gfx2hlsl_compute_swapped-axes_hardware0.29s,startup_gfx2hlsl_compute_mbcnt_warp0.76s,startup_gfx2hlsl_compute_b-offset_hardware0.33s,startup_gfx2hlsl_compute_c-unpredicated_hardware0.30s,startup_gfx2hlsl_compute_b-offset_warp0.32s,startup_gfx2hlsl_compute_c-unpredicated_warp0.32s,startup_gfx2hlsl_compute_dropped-store_warp0.31s,startup_gfx2hlsl_compute_swapped-axes_warp0.34s,startup_gfx2hlsl_compute_controls0.44s,startup_gfx2hlsl_compute_mbcnt_hardware0.75s,startup_gfx2hlsl_compute_h-inner-unpredicated_warp0.32s,startup_gfx2hlsl_compute_f-broadcast_warp0.33s,startup_gfx2hlsl_compute_f-peer_warp0.40s,startup_gfx2hlsl_compute_g-swapped-offsets_warp0.30s,startup_gfx2hlsl_compute_j-scalar-dropped_warp0.34s,startup_gfx2hlsl_compute_g-overlap_warp0.32s,startup_gfx2hlsl_compute_k-block-entered_warp0.36s,startup_vertex_fetch_formats_controls0.16s,startup_gfx2hlsl_compute_k-block-entered_hardware0.34s,startup_gfx2hlsl_compute_g-swapped-offsets_hardware0.42s,startup_gfx2hlsl_compute_f-broadcast_hardware0.34s,startup_gfx2hlsl_compute_g-overlap_hardware0.32s,startup_gfx2hlsl_compute_f-peer_hardware0.32s,startup_gfx2hlsl_compute_h-inner-unpredicated_hardware0.32s,startup_gfx2hlsl_compute_j-scalar-dropped_hardware0.33s,startup_vertex_fetch_formats_warp24.88s)tests/mesh_heap_sampler_check.pyok (1.0s),tests/startup_buffer_address_check.pyok (0.5s),tests/startup_compute_image_store_d16_check.pyok (0.9s),tests/startup_compute_request_offline_check.pyok (2.0s),tests/startup_compute_translate_check.pyok (1.0s),tests/startup_flat_param_check.pyok (0.7s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.4s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.3s),tests/startup_gfx2hlsl_bit_alu_check.pyok (1.1s),tests/startup_gfx2hlsl_capture_check.pyok (1.3s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.3s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.1s),tests/startup_gfx2hlsl_compute_check.pyok (0.5s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.1s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.2s),tests/startup_gfx2hlsl_f32_lg_check.pyok (1.8s),tests/startup_gfx2hlsl_f32_nan_check.pyok (6.8s),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.1s),tests/startup_gfx2hlsl_int_med3_check.pyok (0.2s),tests/startup_gfx2hlsl_join_symbols_check.pyok (0.2s),tests/startup_gfx2hlsl_loop_constants_check.pyok (0.1s),tests/startup_gfx2hlsl_mask_overwrite_check.pyok (0.1s),tests/startup_gfx2hlsl_operand_count_check.pyok (0.3s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.3s),tests/startup_gfx2hlsl_refusals_check.pyok (0.8s),tests/startup_gfx2hlsl_root_check.pyok (0.9s),tests/startup_gfx2hlsl_saveexec_same_reg_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_arity_check.pyok (0.2s),tests/startup_gfx2hlsl_scalar_brev_fold_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_m0_check.pyok (0.1s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.4s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.2s),tests/startup_gfx2hlsl_shift64_check.pyok (0.2s),tests/startup_gfx2hlsl_smem_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_sop2_complement_check.pyok (6.0s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (1.1s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.2s),tests/startup_gfx2hlsl_swap_check.pyok (0.3s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (6.2s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.9s),tests/startup_image_2d_array_check.pyok (0.3s),tests/startup_image_3d_check.pyok (0.1s),tests/startup_image_gather_lz_check.pyok (0.8s),tests/startup_image_load_d16_check.pyok (1.3s),tests/startup_image_sample_a16_check.pyok (0.2s),tests/startup_image_sample_b_check.pyok (0.2s),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 (0.9s),tests/startup_inline_sampler_check.pyok (0.2s),tests/startup_run_ps1_check.pyok (12.8s),tests/startup_run_sh_check.pyFAIL (0.1s),tests/startup_sampler_heap_check.pyok (0.1s),tests/startup_smem_address_check.pyok (0.1s),tests/startup_stream_fetch_check.pyok (0.3s),tests/startup_stream_interface_check.pyok (0.3s),tests/startup_translator_check.pyok (0.6s)sccache: 0/61 hits; wall150.4sAI-assisted; commands listed were executed locally.