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

Merged
NiiRoZz merged 1 commit from upstream-pr/2535 into main 2026-11-25 20:28:35 +00:00
NiiRoZz commented 2026-11-25 20:16:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T20:16:01Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6612902487 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2535). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T20:16:01Z. --- ## 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 ```powershell 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](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 21:01:19 +00:00
tedin7 commented 2026-11-25 21:01:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:28:23Z.

Review: COMMENTED


Review of head d064cf75 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064500359 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2535#pullrequestreview-6064500359). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:28:23Z. **Review:** COMMENTED --- Review of head d064cf75 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 commented 2026-11-25 21:01:31 +00:00 (Migrated from github.com)

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:

  • 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7173721785 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2535#issuecomment-7173721785). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:28:24Z. --- 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.
NiiRoZz commented 2026-11-25 21:01:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T20:32:30Z.


Self-review follow-up, pushed as 4251ccdb: 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 4251ccdb, 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7173825242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2535#issuecomment-7173825242). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T20:32:30Z. --- Self-review follow-up, pushed as 4251ccdb: `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 4251ccdb, Windows 10.0.26300, Python from `out/pe-env`: ```powershell 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 in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2527
No description provided.