shader: prove formatted load descriptor words across a join #3488

Manually merged
github merged 1 commit from github-bot/gh-3486 into gh-pr/3486/base 2026-11-30 08:50:55 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-29 17:25 UTC · original
Leyukaka:shader-gfx2hlsl-format-load-proof → main · +104 −21 · 3 files · 1 commits · merged 2026-11-30 08:45 UTC

Refs #3480 (item 3).

What changes

buffer_load_format_* past the entry block was accepted only when the descriptor load sat in the same block (formatted_descriptor_from_block). A load in an earlier block that dominates the use was refused with formatted buffer load requires descriptor words proven in the entry block or a local table load.

formatted_descriptor_from_predecessor (tools/startup/gfx2hlsl.py) adds a second proof. It runs only after the existing checks in mubuf_format: all four words still carry the loaded symbol, the source is a hardware table, and the block proof failed. It accepts when:

  • one literal s_load_dwordx4/8/16 is the last writer of all four descriptor words on every incoming path. Any other writer of any word on any path, back edges included, is a second writer and refuses. A path that carries the entry value refuses;
  • that load has three operands, only glc/dlc modifiers, a destination covering the four words at the expected position, an immediate offset equal to the descriptor's table offset, and a 64-bit SGPR base;
  • the high address word's last writer on every path is the single s_mov_b32 s<hi>, 0;
  • the low address word is the entry table pointer, directly or through one proven s_mov_b32 copy, with no write on any path;
  • stride, record count and format come from the same SRV key as before. No new descriptor source.

formatted_pointer_copy is refactored onto the shared descriptor_last_writers walk.

Refusal texts and conditions are unchanged. One existing control changed meaning: the compute case s_branch 0 followed by the load ("at a branch target there is no local descriptor load to prove") is removed and replaced by an accepted join case, since that is the shape the proof now accepts.

This does not touch "buffer load through a modified descriptor" (#3100): that control is unchanged and the new path is reached only when all four words are unmodified.

Tests

New controls:

  • compute (startup_gfx2hlsl_compute_check.py): join accepted with the same manifest; refused with a word-3 write on one arm, with high word = 1, and with the entry pointer rewritten (s_mov_b32 s6, s6).
  • pixel (startup_gfx2hlsl_join_symbols_check.py): s_load_dwordx8 join accepted, stride and format taken from the second descriptor; refused with a word-3 write on a forward arm and on a back edge.

Passed (17, 0 FAIL): gfx2hlsl_compute, gfx2hlsl_join_symbols, gfx2hlsl_load_desc, gfx2hlsl_compute_spill, gfx2hlsl_readfirstlane_load_recompute, gfx2hlsl_readfirstlane_uniform, gfx2hlsl_tbuffer_16f, gfx2hlsl_heap_record, gfx2hlsl_handler_arity, buffer_address, buffer_format_word3_table, gfx2hlsl_refusals, gfx2hlsl_op_refusals, gfx2hlsl_spill_branches, gfx2hlsl_compute_mask_spill, mesh57_skeleton, vertex_fetch_formats controls.

Mutation: with the predecessor proof walking word 0 only, compute_check fails (accepted, expected a refusal naming 'local table load') and join_symbols fails (FORMATTED_REWRITE accepted). Restored, both pass.

Not run

  • binary <llvm-mc> modes of compute and join_symbols: llvm-mc is not installed on our host, so the new SOURCE_L_JOIN and FORMATTED* word encodings are not checked against an assembler.
  • startup_mubuf_descriptor_check and the startup_compute_store_* ctests (need built binaries).
  • This and the #3480 items 1-2 PR (v_subrev_f32_dpp / v_writelane_b32 shapes) both edit the formatted-descriptor area of gfx2hlsl.py. They merge without conflict; the combined tree was not tested.
**@⁠Leyukaka** on GitHub · 2026-11-29 17:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3486) `Leyukaka:shader-gfx2hlsl-format-load-proof` → `main` · +104 −21 · 3 files · 1 commits · merged 2026-11-30 08:45 UTC Refs #3480 (item 3). ## What changes `buffer_load_format_*` past the entry block was accepted only when the descriptor load sat in the same block (`formatted_descriptor_from_block`). A load in an earlier block that dominates the use was refused with `formatted buffer load requires descriptor words proven in the entry block or a local table load`. `formatted_descriptor_from_predecessor` (`tools/startup/gfx2hlsl.py`) adds a second proof. It runs only after the existing checks in `mubuf_format`: all four words still carry the loaded symbol, the source is a hardware table, and the block proof failed. It accepts when: - one literal `s_load_dwordx4/8/16` is the last writer of all four descriptor words on every incoming path. Any other writer of any word on any path, back edges included, is a second writer and refuses. A path that carries the entry value refuses; - that load has three operands, only `glc`/`dlc` modifiers, a destination covering the four words at the expected position, an immediate offset equal to the descriptor's table offset, and a 64-bit SGPR base; - the high address word's last writer on every path is the single `s_mov_b32 s<hi>, 0`; - the low address word is the entry table pointer, directly or through one proven `s_mov_b32` copy, with no write on any path; - stride, record count and format come from the same SRV key as before. No new descriptor source. `formatted_pointer_copy` is refactored onto the shared `descriptor_last_writers` walk. Refusal texts and conditions are unchanged. One existing control changed meaning: the compute case `s_branch 0` followed by the load ("at a branch target there is no local descriptor load to prove") is removed and replaced by an accepted join case, since that is the shape the proof now accepts. This does not touch "buffer load through a modified descriptor" (#3100): that control is unchanged and the new path is reached only when all four words are unmodified. ## Tests New controls: - compute (`startup_gfx2hlsl_compute_check.py`): join accepted with the same manifest; refused with a word-3 write on one arm, with high word = 1, and with the entry pointer rewritten (`s_mov_b32 s6, s6`). - pixel (`startup_gfx2hlsl_join_symbols_check.py`): `s_load_dwordx8` join accepted, stride and format taken from the second descriptor; refused with a word-3 write on a forward arm and on a back edge. Passed (17, 0 FAIL): gfx2hlsl_compute, gfx2hlsl_join_symbols, gfx2hlsl_load_desc, gfx2hlsl_compute_spill, gfx2hlsl_readfirstlane_load_recompute, gfx2hlsl_readfirstlane_uniform, gfx2hlsl_tbuffer_16f, gfx2hlsl_heap_record, gfx2hlsl_handler_arity, buffer_address, buffer_format_word3_table, gfx2hlsl_refusals, gfx2hlsl_op_refusals, gfx2hlsl_spill_branches, gfx2hlsl_compute_mask_spill, mesh57_skeleton, vertex_fetch_formats controls. Mutation: with the predecessor proof walking word 0 only, compute_check fails (`accepted, expected a refusal naming 'local table load'`) and join_symbols fails (`FORMATTED_REWRITE accepted`). Restored, both pass. ## Not run - `binary <llvm-mc>` modes of compute and join_symbols: `llvm-mc` is not installed on our host, so the new `SOURCE_L_JOIN` and `FORMATTED*` word encodings are not checked against an assembler. - `startup_mubuf_descriptor_check` and the `startup_compute_store_*` ctests (need built binaries). - This and the #3480 items 1-2 PR (v_subrev_f32_dpp / v_writelane_b32 shapes) both edit the formatted-descriptor area of `gfx2hlsl.py`. They merge without conflict; the combined tree was not tested.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 17:27:39 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 08:20 UTC · original · approved these changes

Reviewed 4a1e9685 by reading the diff; not built or run.

Verdict: approve. The predecessor proof is a sound reaching-definition check, and stricter than the block proof it sits behind. One SHOULD, which can follow. No MUST.

  • SHOULD: this widens a scope #2461 (321e63a9) kept on purpose: "Graphics stages keep the previous rule. Descriptor words loaded in another block than the formatted load stay refused." The new path accepts a cross-block load in every stage, and calls formatted_pointer_copy without the block proof's kind == 'cs' guard (gfx2hlsl.py:7882 vs :7918). So a pixel shader whose table pointer is copied in a block above is now accepted, while the FORMATTED* cases use s[8:9] directly. Say so in the body and add one pixel case with a copy, or keep the guard for the copy.
  • Writers: descriptor_scalar_writes (destinations, vcc, a VOP3 v_cmp destination) plus scalar_destinations (movrel gives 'any'). A v_readlane_b32 reload is a writer that is not an s_load, so it refuses. That is conservative.
  • Stricter than the block proof: the immediate offset must equal first[2], only glc/dlc are allowed, an SGPR soffset refuses (_lit_u32 gives None), and the high word must be s_mov_b32 s<hi>, 0 on every path.
  • The formatted_pointer_copy refactor keeps the old behaviour: an entry-reaching path adds None, and both len != 1 and index is None still return None.

Tests: the compute join plus three refusals, the pixel dwordx8 join (stride and format from the second descriptor) plus forward-arm and back-edge refusals, and the word-0 mutation all reach the new function. CI ran both files on Linux and in binary mode with llvm-mc-15 in the gfx1013 job (both ok), so the new encodings match the assembler. That closes the body's first "Not run" item.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 08:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3486#pullrequestreview-6108808254) · **approved these changes** Reviewed `4a1e9685` by reading the diff; not built or run. **Verdict: approve.** The predecessor proof is a sound reaching-definition check, and stricter than the block proof it sits behind. One SHOULD, which can follow. No MUST. - **SHOULD:** this widens a scope #2461 (321e63a9) kept on purpose: "Graphics stages keep the previous rule. Descriptor words loaded in another block than the formatted load stay refused." The new path accepts a cross-block load in every stage, and calls `formatted_pointer_copy` without the block proof's `kind == 'cs'` guard (`gfx2hlsl.py:7882` vs `:7918`). So a pixel shader whose table pointer is copied in a block above is now accepted, while the `FORMATTED*` cases use `s[8:9]` directly. Say so in the body and add one pixel case with a copy, or keep the guard for the copy. - Writers: `descriptor_scalar_writes` (destinations, `vcc`, a VOP3 `v_cmp` destination) plus `scalar_destinations` (`movrel` gives `'any'`). A `v_readlane_b32` reload is a writer that is not an `s_load`, so it refuses. That is conservative. - Stricter than the block proof: the immediate offset must equal `first[2]`, only `glc`/`dlc` are allowed, an SGPR soffset refuses (`_lit_u32` gives None), and the high word must be `s_mov_b32 s<hi>, 0` on every path. - The `formatted_pointer_copy` refactor keeps the old behaviour: an entry-reaching path adds `None`, and both `len != 1` and `index is None` still return None. Tests: the compute join plus three refusals, the pixel `dwordx8` join (stride and format from the second descriptor) plus forward-arm and back-edge refusals, and the word-0 mutation all reach the new function. CI ran both files on Linux and in `binary` mode with `llvm-mc-15` in the gfx1013 job (both ok), so the new encodings match the assembler. That closes the body's first "Not run" item.
github-bot changed target branch from main to gh-pr/3486/base 2026-11-30 08:50:53 +00:00
github manually merged commit 4a1e96856e into gh-pr/3486/base 2026-11-30 08:50:55 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.