Skip to content

gfx2hlsl: compute exec-write clear shapes and join writes once - #2535

Merged
tedin7 merged 1 commit into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-exec-write-speed
Nov 25, 2026
Merged

tedin7 merged 1 commit into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-exec-write-speed

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What changes

tools/startup/gfx2hlsl.py only, no behaviour change. The exec-write dataflow that #2509 added is slow on large compute programs:

  • clear_after re-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_writes rescanned every instruction for every branch. The written registers are now computed once per instruction and each branch takes its range with bisect.

Measured

Commit under test: the head of this branch, against main at its merge base. Windows 10.0.26300, Python 3 from out/pe-env. Input: three large locally captured compute requests (counts only), each translated once after a warm-up request, two runs per side.

run 1 run 2
main 8.66 s 8.73 s
this branch 5.65 s 5.76 s

The refusal files written by both sides are byte-identical.

Tests

python -B tests/startup_translator_check.py        # startup translator checks: 0 failed
python -B tests/startup_gfx2hlsl_<each>_check.py   # every no-argument check exits 0
git diff --check                                   # clean

Not checked

  • Only three requests were timed; other program shapes may gain less.
  • The checks that need llvm-mc or 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

The exec-write pass parsed the same instruction text once per visit and
join_writes rescanned every instruction for every branch. Cache the parse
and the clear shape per text, and compute the written registers once.
Three large compute requests: 19.1 s -> 8.4 s, same refusals.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@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 head d064cf7 against 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 current clear set (halves) stay in clear_after. The cache key (name, asm) is a pure function of the text.
  • join_writes: written registers are computed once per instruction (including the s_movreld all-registers case and m0). The bisect ranges match the old conditions: backward target <= off <= branch, forward branch < off < target. This relies on self.ins being in ascending offset order, which decode gives. The target key is still created for an empty range, as before.
  • Scope is one file, no behaviour change intended; no game or startup-progress claim.

Commands run (Linux):

  • python3 -B tests/startup_translator_check.py 0 failed
  • startup_gfx2hlsl_loop_constants_check, startup_gfx2hlsl_join_symbols_check, startup_ngg_slice_check pass
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD clean

Gap (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 by startup_translator_check, startup_gfx2hlsl_join_symbols_check, startup_gfx2hlsl_loop_constants_check or startup_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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit d064cf75ea46c848563b7461367890b022818bae:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 25.73s (configure 0.00s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 42.91s (configure 0.00s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (0.6s), tests/startup_buffer_address_check.py ok (0.3s), tests/startup_buffer_format_word3_table_check.py ok (0.1s), tests/startup_compute_request_offline_check.py ok (0.4s), tests/startup_compute_translate_check.py ok (0.2s), tests/startup_flat_param_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.1s), tests/startup_gfx2hlsl_bit_alu_check.py ok (0.5s), tests/startup_gfx2hlsl_capture_check.py ok (0.8s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.2s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.3s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.1s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.0s), tests/startup_gfx2hlsl_f32_nan_check.py ok (3.9s), tests/startup_gfx2hlsl_getpc_refusal_check.py ok (0.1s), tests/startup_gfx2hlsl_handler_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_get_lod_check.py ok (0.1s), tests/startup_gfx2hlsl_int_med3_check.py ok (0.1s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.2s), tests/startup_gfx2hlsl_loop_constants_check.py ok (0.1s), tests/startup_gfx2hlsl_mask_overwrite_check.py ok (0.1s), tests/startup_gfx2hlsl_operand_count_check.py ok (0.2s), tests/startup_gfx2hlsl_pack_absdiff_check.py ok (2.0s), tests/startup_gfx2hlsl_readfirstlane_recompute_check.py ok (0.1s), tests/startup_gfx2hlsl_readfirstlane_uniform_check.py ok (0.1s), tests/startup_gfx2hlsl_refusals_check.py ok (0.3s), tests/startup_gfx2hlsl_root_check.py ok (0.6s), tests/startup_gfx2hlsl_sad_check.py ok (0.3s), tests/startup_gfx2hlsl_saveexec_same_reg_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_arity_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_brev_fold_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_m0_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_table_arity_check.py ok (0.2s), tests/startup_gfx2hlsl_sdwa_cvt_check.py ok (0.2s), tests/startup_gfx2hlsl_sgpr_spill_check.py ok (0.1s), tests/startup_gfx2hlsl_shift64_check.py ok (0.1s), tests/startup_gfx2hlsl_sload_const_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_smem_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (4.7s), tests/startup_gfx2hlsl_sopk_accum_check.py ok (0.7s), tests/startup_gfx2hlsl_sopk_signext_check.py ok (0.1s), tests/startup_gfx2hlsl_swap_check.py ok (0.2s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (3.5s), tests/startup_gfx2hlsl_waitcnt_depctr_check.py ok (0.1s), tests/startup_gfx2hlsl_watch_check.py ok (2.3s), tests/startup_image_2d_array_check.py ok (0.1s), tests/startup_image_3d_check.py ok (0.1s), tests/startup_image_gather_lz_check.py ok (0.5s), tests/startup_image_load_d16_check.py ok (0.7s), tests/startup_image_sample_a16_check.py ok (0.1s), tests/startup_image_sample_b_check.py ok (0.1s), tests/startup_image_sample_c_check.py ok (0.2s), tests/startup_image_sample_l_check.py ok (0.1s), tests/startup_image_sample_lod_check.py ok (0.5s), tests/startup_inline_sampler_check.py ok (0.1s), tests/startup_mesh57_skeleton_check.py ok (0.1s), tests/startup_run_ps1_check.py ok (7.8s), tests/startup_run_sh_check.py skipped (0.1s), tests/startup_sampler_heap_check.py ok (0.1s), tests/startup_shader_cache_rekey_check.py ok (1.4s), tests/startup_smem_address_check.py ok (0.1s), tests/startup_stream_fetch_check.py ok (0.2s), tests/startup_stream_interface_check.py ok (0.2s), tests/startup_translator_check.py ok (0.3s)
  • sccache: 1/8 hits; wall 114.3s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 99af3da into R0Y00:main Nov 25, 2026
5 checks passed
@NiiRoZz

NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Self-review follow-up, pushed as 4251ccd: join_writes now takes each branch's instruction range by bisection, which is only right while self.ins is 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 one assert offs == sorted(offs) to make a later reorder fail loudly instead of giving a wrong register set.

Run at 4251ccd, Windows 10.0.26300, Python from out/pe-env:

python -B tests/startup_translator_check.py        # startup translator checks: 0 failed
python -B tests/startup_gfx2hlsl_<each>_check.py   # every no-argument check exits 0
git diff --check                                   # clean

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 main beyond those three requests and the repository checks; a comparison of every refusal over a full local cache has not been run.

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.

2 participants