gfx2hlsl: compute exec-write clear shapes and join writes once #2527
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2535"
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-25T20:16:01Z.
What changes
tools/startup/gfx2hlsl.pyonly, no behaviour change. The exec-write dataflow that #2509 added is slow on large compute programs:clear_afterre-derived the same facts from the instruction text on every visit. The per-instruction shape is now computed once per text (clear_shape, cached).join_writesrescanned every instruction for every branch. The written registers are now computed once per instruction and each branch takes its range withbisect.Measured
Commit under test: the head of this branch, against
mainat its merge base. Windows 10.0.26300, Python 3 fromout/pe-env. Input: three large locally captured compute requests (counts only), each translated once after a warm-up request, two runs per side.mainThe refusal files written by both sides are byte-identical.
Tests
Not checked
llvm-mcor a D3D12 device were not run: the change does not touch what they cover beyond the translator output, which the no-argument checks compare.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:28:23Z.
Review: COMMENTED
Review of head
d064cf75against current main (comment only).Checked, by reading the diff against the old code:
clear_shape: same decisions as the old inline code (v_cmpx, no-match or saveexec-mov -> no fact, wrong word count or unparsable operand -> no fact). Only the facts that depend on the currentclearset (halves) stay inclear_after. The cache key (name, asm) is a pure function of the text.join_writes: written registers are computed once per instruction (including thes_movreldall-registers case andm0). Thebisectranges match the old conditions: backwardtarget <= off <= branch, forwardbranch < off < target. This relies onself.insbeing in ascending offset order, whichdecodegives. The target key is still created for an empty range, as before.Commands run (Linux):
python3 -B tests/startup_translator_check.py0 failedstartup_gfx2hlsl_loop_constants_check,startup_gfx2hlsl_join_symbols_check,startup_ngg_slice_checkpasspython3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEADcleanGap (not a blocker, this is a speed-only refactor): two mutations of
join_writes(range start moved by one; all written registers dropped) were NOT caught bystartup_translator_check,startup_gfx2hlsl_join_symbols_check,startup_gfx2hlsl_loop_constants_checkorstartup_gfx2hlsl_compute_check. The existing checks do not pin the exact join sets, so the byte-identical refusal comparison in the PR body is the main evidence. A small direct test (join set for one forward and one backward branch) would be a good follow-up.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:28:24Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
d064cf75ea46c848563b7461367890b022818bae:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2):25.73s(configure0.00s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2):42.91s(configure0.00s)tests/mesh_heap_sampler_check.pyok (0.6s),tests/startup_buffer_address_check.pyok (0.3s),tests/startup_buffer_format_word3_table_check.pyok (0.1s),tests/startup_compute_request_offline_check.pyok (0.4s),tests/startup_compute_translate_check.pyok (0.2s),tests/startup_flat_param_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.1s),tests/startup_gfx2hlsl_bit_alu_check.pyok (0.5s),tests/startup_gfx2hlsl_capture_check.pyok (0.8s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.2s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.1s),tests/startup_gfx2hlsl_compute_check.pyok (0.3s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.1s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.1s),tests/startup_gfx2hlsl_f32_lg_check.pyok (1.0s),tests/startup_gfx2hlsl_f32_nan_check.pyok (3.9s),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.1s),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.2s),tests/startup_gfx2hlsl_pack_absdiff_check.pyok (2.0s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.1s),tests/startup_gfx2hlsl_refusals_check.pyok (0.3s),tests/startup_gfx2hlsl_root_check.pyok (0.6s),tests/startup_gfx2hlsl_sad_check.pyok (0.3s),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_scalar_table_arity_check.pyok (0.2s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.2s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.1s),tests/startup_gfx2hlsl_shift64_check.pyok (0.1s),tests/startup_gfx2hlsl_sload_const_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_smem_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_sop2_complement_check.pyok (4.7s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (0.7s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.1s),tests/startup_gfx2hlsl_swap_check.pyok (0.2s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (3.5s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.3s),tests/startup_image_2d_array_check.pyok (0.1s),tests/startup_image_3d_check.pyok (0.1s),tests/startup_image_gather_lz_check.pyok (0.5s),tests/startup_image_load_d16_check.pyok (0.7s),tests/startup_image_sample_a16_check.pyok (0.1s),tests/startup_image_sample_b_check.pyok (0.1s),tests/startup_image_sample_c_check.pyok (0.2s),tests/startup_image_sample_l_check.pyok (0.1s),tests/startup_image_sample_lod_check.pyok (0.5s),tests/startup_inline_sampler_check.pyok (0.1s),tests/startup_mesh57_skeleton_check.pyok (0.1s),tests/startup_run_ps1_check.pyok (7.8s),tests/startup_run_sh_check.pyskipped (0.1s),tests/startup_sampler_heap_check.pyok (0.1s),tests/startup_shader_cache_rekey_check.pyok (1.4s),tests/startup_smem_address_check.pyok (0.1s),tests/startup_stream_fetch_check.pyok (0.2s),tests/startup_stream_interface_check.pyok (0.2s),tests/startup_translator_check.pyok (0.3s)sccache: 1/8 hits; wall114.3sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T20:32:30Z.
Self-review follow-up, pushed as 4251ccdb:
join_writesnow takes each branch's instruction range by bisection, which is only right whileself.insis in offset order. The loop it replaces compared every offset and did not depend on that. The order holds today (the decoder emits it, and the mesh skeleton collapses spans in place), so this adds oneassert offs == sorted(offs)to make a later reorder fail loudly instead of giving a wrong register set.Run at 4251ccdb, Windows 10.0.26300, Python from
out/pe-env:The three large requests from the description still take 5.83 s with the assert (5.65 s / 5.76 s before it).
Not checked: equality with
mainbeyond those three requests and the repository checks; a comparison of every refusal over a full local cache has not been run.