Skip to content

startup: accept slot 57 VCC branches on a wave-uniform compare (Part of #2413) - #2566

Merged
tedin7 merged 5 commits into
R0Y00:mainfrom
Leyukaka:mesh57-vcc
Nov 25, 2026
Merged

tedin7 merged 5 commits into
R0Y00:mainfrom
Leyukaka:mesh57-vcc

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2413, the extension of the forward-branch work of #2548 (claim).

#2548 refuses s_cbranch_vccz/s_cbranch_vccnz outside the exchanges as a wave-wide condition. This accepts them when VCC is provably the same bit in every lane:

  • On every path reaching the branch, VCC was last written by a v_cmp_* under the full EXEC mask. mesh_skeleton tracks the set of such compares and merges it at joins; a path without one empties it.
  • No other write to VCC follows. Any other VCC write empties the set (scalar writes to VCC are refused).
  • EXEC is still the full mask at the branch.
  • Stage proves each compare's sources wave-uniform: no VGPR operand, uniform SGPRs or constants.

VCC is then all ones or all zeros, so the per-lane test equals the wave-wide one. Anything else stays refused with the existing message.

Three test commits add refusal controls: s_call_b64, s_swappc_b64, a forward s_cbranch_execnz, and an s_branch from between the exchanges to after the count exchange (#2548 had no controls for these), a VCC compare made under a narrowed EXEC before EXEC is restored and the branch is taken, and a compare whose SGPR source was written before a join.

Tests (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100), on main 381abc3 plus the four commits:

  • python -B tests/startup_mesh57_skeleton_check.py: ok.
    • Taken and not-taken vccz and vccnz branches, and a vccz branch after a join, translate.
    • Refused: a VGPR compare, a narrowed EXEC at the branch, a compare made under a narrowed EXEC, a compare of an SGPR written before a join, a VCC write between the compare and the branch, a join where one path has no VCC definition, and the four controls above.
  • ... draw <dxc> offscreen_check warp and hardware: ok. The branch cases are drawn against the CPU model (WARP: Microsoft Basic Render Driver; hardware: NVIDIA GeForce RTX 5080).
  • Also ok: docs_links_check, bidi_controls_check, startup_gfx2hlsl_watch_check, startup_translator_check, startup_gfx2hlsl_join_symbols_check, startup_gfx2hlsl_refusals_check, startup_compute_translate_check, startup_gfx2hlsl_capture_check, startup_gfx2hlsl_waitcnt_depctr_check and startup_gfx2hlsl_loop_constants_check.

Mutation checks, run by hand. The controls fail on each:

  • the EXEC check dropped at the branch;
  • the EXEC check dropped at the compare;
  • uniform_source replaced by True (only the SGPR-before-join control fails; the VGPR control stays refused through mesh_vregs);
  • any VCC write kept as the definition;
  • the join keeping a definition missing on one path;
  • calls accepted;
  • s_cbranch_execnz accepted;
  • a branch crossing an exchange accepted.

Measured on a local capture (counts and instruction shape only, inputs private): with #2548 applied, 77 slot 57 requests stopped at a VCC branch on a wave-wide condition. With this change none stop there, and none of them translates yet: they now stop at a branch enters or crosses a group-memory exchange. In the program I inspected, v_cmpx_gt_u32 narrows EXEC at the end of the region before the count exchange and an s_cbranch_execz targets its first s_barrier, so the exchange is entered under a narrowed EXEC. Supporting that shape is the next step; I inspected one program and have not checked that the others stop for the same reason, and an earlier version of this text wrongly described it as a third group-memory exchange.

AI-assisted.

@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 acc85ad (comment only, not merging for now).

Finding (test gap, not a proven code bug):

  • tools/startup/gfx2hlsl.py:2429 now requires not mesh_vregs([tok]) and self.uniform_source(tok) for every compare source. In the new tests only the VGPR case is exercised ("a VGPR compare"). With self.uniform_source(tok) replaced by True, python3 -B tests/startup_mesh57_skeleton_check.py still prints ok. So the SGPR half of the uniformity proof has no guard: uniform_source also refuses SGPRs in varying_s, in masks, or written before the last join (gfx2hlsl.py:2550-2565), and none of those is covered by a refusal control.
  • Please add a control where the compare source is such an SGPR (for example an SGPR in masks, or one written before a join) and the VCC branch must be refused. It should fail when that call is dropped.

Checked and fine:

  • The VCC definition set at joins (all(definitions) empties the set when a path has none), the EXEC-at-branch and EXEC-at-compare checks, and the refusal of other VCC writes. Mutating if mask is not None or not vcc_compares: to if False: makes the join control fail, as intended.
  • No other open or merged PR covers this slice (only #2548, which this extends).
  • Fixture tests are the in-repo ones; the claim about captures is not something I can verify. The PR does not claim a title startup result.

Still open before a merge: CI is pending on this head, and the WARP/hardware draw cases (draw ... warp) need a Windows run on the head after the branch is brought up to date (5 behind main). I did not run those.

Commands run locally (Linux worktree on this head):

  • python3 -B tests/startup_mesh57_skeleton_check.py: ok
  • mutation 1 (if False: at the branch check): fails as expected
  • mutation 2 (uniform_source replaced by True): still ok (the gap above)
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • git diff --check origin/main...HEAD: clean

AI-assisted; commands listed were executed locally.

s_cbranch_vccz and s_cbranch_vccnz were refused outside the exchanges as a
wave-wide condition. Accept them when every path reaching the branch last
wrote VCC with a v_cmp under the full EXEC mask, no other VCC write follows,
EXEC is still the full mask at the branch, and Stage proves the compare's
sources wave-uniform (no VGPR, uniform SGPRs or constants). VCC is then all
ones or all zeros, so the per-lane test equals the wave-wide one. Anything
else stays refused.

Tests: taken and not-taken vccz and vccnz branches, drawn on WARP and
hardware against the CPU model; refusals for a VGPR compare, a narrowed
EXEC at the branch, a VCC write between the compare and the branch, and a
join where one path has no VCC definition.

Part of R0Y00#2413. AI-assisted.
Refusal controls for the slot 57 branch walk: s_call_b64 and s_swappc_b64
after the count exchange (indirect control flow), a forward
s_cbranch_execnz (wave-wide condition), and an s_branch from between the
exchanges to after the count exchange. Each is derived from an accepted
fixture and checked to reach its own refusal.

AI-assisted.
A uniform compare that writes VCC under a narrowed mask leaves the other
lanes at 0, so restoring EXEC before the branch does not make VCC uniform.
The control narrows EXEC with s_and_saveexec_b64, compares, restores
EXEC to -1 and branches on vccz; it must stay refused.

AI-assisted.
Stage proves each compare source with uniform_source. The VGPR control is
also caught by mesh_vregs, so nothing pinned uniform_source itself: an
SGPR written before the last join is not proven uniform and the VCC
branch must stay refused. Reported in review of the pull request.

AI-assisted.
@Leyukaka

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed: with self.uniform_source(tok) replaced by True the skeleton check still passed, because the VGPR control is also refused by mesh_vregs. The body's mutation list was wrong on that point; I've corrected it.

Added a VCC compare on an SGPR written before a join (f8643e7): s40 is set, a uniform s_cbranch_scc1 skips a second write to it, and the compare after the join reads s40. uniform_source does not prove an SGPR written before the last join, so the vccz branch stays refused. With the mutation above the check now fails on this case (got 'ok'); restored, it passes. A saved EXEC mask as the source did not work as a control: it is refused earlier, as an unproven use of a saved mask.

The branch is rebased onto main 381abc3. On that head: startup_mesh57_skeleton_check.py ok, and draw ... warp and draw ... hardware ok (WARP; NVIDIA GeForce RTX 5080).

AI-assisted.

@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 f8643e7 (fixture and code review only, no executable run).

Code: the proof in mesh_skeleton is sound. VCC compares are tracked as a set, merged at joins (any path without one empties it), emptied by any other VCC write, and the branch needs a full EXEC. Stage.translate then requires every tracked compare to have wave-uniform sources (no VGPR, uniform SGPR or constant). I found no sibling table or callsite left out. No other open or merged PR covers this slice (#2548 is the base).

Checked locally on this head:

  • python3 -B tests/startup_mesh57_skeleton_check.py: ok
  • python3 tests/docs_links_check.py: ok
  • python3 tests/bidi_controls_check.py: ok
  • git diff --check origin/main...HEAD: clean
  • Mutations, each reverted afterwards, and each made the skeleton check fail: dropping the narrowed-EXEC test at the branch; dropping the subset check against uniform compares; letting a join keep a definition from one path only; dropping the uniform_source requirement.
  • One mutation survived: removing the ops[0] in ('vcc', 'vcc_lo') destination test. Not a blocker; a compare writing a non-VCC SGPR pair is not in the set because the VCC-write test is checked first. A one-line control would still pin it.

The CPU-reference draws need DXC and WARP, so they were not run in this review. A Windows WARP run will follow before any merge.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head f084999 after updating with main.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 49.55s (configure 5.42s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 86.83s (configure 4.10s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (1.0s), tests/startup_buffer_address_check.py ok (1.3s), tests/startup_buffer_format_word3_table_check.py ok (0.6s), tests/startup_compute_request_offline_check.py ok (2.3s), tests/startup_compute_translate_check.py ok (0.5s), tests/startup_flat_param_check.py ok (0.2s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.2s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.2s), tests/startup_gfx2hlsl_bit_alu_check.py ok (1.3s), tests/startup_gfx2hlsl_capture_check.py ok (1.5s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.4s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.6s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.2s), tests/startup_gfx2hlsl_cvt_off_f32_i4_check.py ok (0.2s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.8s), tests/startup_gfx2hlsl_f32_nan_check.py ok (7.2s), tests/startup_gfx2hlsl_fma_mix_check.py ok (0.1s), 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.2s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.3s), 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.4s), tests/startup_gfx2hlsl_pack_absdiff_check.py ok (3.8s), 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.7s), tests/startup_gfx2hlsl_root_check.py ok (0.9s), tests/startup_gfx2hlsl_sad_check.py ok (0.5s), tests/startup_gfx2hlsl_saveexec_same_reg_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_arity_check.py ok (0.3s), tests/startup_gfx2hlsl_scalar_brev_fold_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_m0_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_table_arity_check.py ok (0.4s), tests/startup_gfx2hlsl_sdwa_cvt_check.py ok (0.4s), tests/startup_gfx2hlsl_sgpr_spill_check.py ok (0.2s), tests/startup_gfx2hlsl_shift64_check.py ok (0.2s), 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 (8.5s), tests/startup_gfx2hlsl_sopk_accum_check.py ok (1.3s), tests/startup_gfx2hlsl_sopk_signext_check.py ok (0.2s), tests/startup_gfx2hlsl_swap_check.py ok (0.5s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (6.5s), tests/startup_gfx2hlsl_waitcnt_depctr_check.py ok (0.1s), tests/startup_gfx2hlsl_watch_check.py ok (2.6s), tests/startup_image_2d_array_check.py ok (0.2s), tests/startup_image_3d_check.py ok (0.1s), tests/startup_image_gather_lz_check.py ok (0.7s), tests/startup_image_load_d16_check.py ok (0.9s), tests/startup_image_sample_a16_check.py ok (0.2s), tests/startup_image_sample_b_check.py ok (0.2s), tests/startup_image_sample_c_check.py ok (0.3s), tests/startup_image_sample_l_check.py ok (0.2s), tests/startup_image_sample_lod_check.py ok (0.7s), tests/startup_inline_sampler_check.py ok (0.2s), tests/startup_mesh57_skeleton_check.py ok (0.5s), tests/startup_run_ps1_check.py ok (12.9s), 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 (2.7s), tests/startup_smem_address_check.py ok (0.1s), tests/startup_stream_fetch_check.py ok (0.3s), tests/startup_stream_interface_check.py ok (1.0s), tests/startup_translator_check.py ok (1.3s)
  • sccache: 71/298 hits; wall 235.7s

AI-assisted; commands listed were executed locally.

@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 f084999: this head is f8643e7 merged with current main. The PR's own diff (3 files) is unchanged, so the earlier review of f8643e7 applies.

Checked on this head: CI green, and the Windows Server 2025 WARP dev and release run passed (receipt above, tests/startup_mesh57_skeleton_check.py rc=0).
Scope: fixture and code review only. No executable run.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 3fb0c77 into R0Y00:main Nov 25, 2026
5 checks passed
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