Skip to content

shader: prove formatted load descriptor words across a join - #3486

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:shader-gfx2hlsl-format-load-proof
Nov 30, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:shader-gfx2hlsl-format-load-proof

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Refs #3478 (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

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (321e63a) 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.

@R0Y00
R0Y00 merged commit 77b1a3a into R0Y00:main Nov 30, 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.

3 participants