Push placement: on the floor each stage's push ends with its tail, 24 bytes above its other fields

A driver that uploads a stage's push bytes up to the highest one the stage reads, and widens a
push load past its last byte by up to 28 bytes, read past the upload where a stage's last field
ended its push (RADV: 49 compute stages at tip). A read pinned past the fields (R7) cost the
stages a driver holds whole in registers those registers: the pin raised the used-word count past
the driver's limit (RADV keeps all 16 words of the harness's lcg_step in user SGPRs at tip, none
under R7). The tail adds no read where the stage has a field of a tail kind, and moves one.

- lower/push.rs: on PushWindow::Floor, place() lays the longest prefix of the kind order that
  fits with its tail: the highest field of a tail kind (SlotBounds or ZeroAddress, the two kinds
  whose value the consumer never pushes with every bit set) moves HOLE_BYTES (24) above the other
  pushed fields' end; where the pushed fields hold no tail kind, the zero tail word
  (PushField::TailWord at PushPlacement::tail_word) takes that place, with which push_range ends.
  One pushed field of one or two words has no tail. The guaranteed window is packed as before.
- tail(), check_floor(): the structural tail and the floor's bound, which select checks on every
  placement as an invariant error.
- emit: the stage reads its tail in its first block and returns where it holds the value the
  consumer never pushes there (emit_tail_guard): the word non-zero, bounds with both words all
  ones, the zero range's address all ones.
- PushPlacement::tail_word (public, serde default, codec), PushField::TailWord (codec, API
  table); SEMANTICS_VERSION 2201, ARTIFACT_FORMAT_VERSION 556; the old render descriptor key
  re-pinned at 2201.
- Tests: push.rs's floor placements at their tails, the bound's refusals; engine_identity's
  31-slot kernel spills 4 addresses to its block; engine_identity_render's vertex range ends at
  64. Docs: API.md section 5 (the tail and what the consumer pushes), rt README (24 addresses
  below the tail), the profile's window doc.

Verified at 855d973a38 (this change before development's c39f6e8350 and 1de18aa609, which
touch no translator file), m3-max-58299 on msi: the metal2vulkan and metal2vulkan-rt suites
3911 of 3911 passed; the old-path pins (golden hashes over Device::new and the old render key)
pass. Clippy failed there on four indexing lints in push.rs, fixed here with get().
RADV dump (m3-max-58310, Radeon 780M, Mesa 26.2.6): lcg_step keeps the same 16 push words in
user SGPRs with no push pointer, plus a 3-instruction scalar guard; the 18-word kernel keeps its
two loads (+0x20, 32 bytes; the second now at +0x58).
This commit is contained in:
Anees Iqbal committed 2026-11-20 05:17:29 -08:00
1 parent a507907bd8
commit 0cd2ad765d
16 files changed
+544 -96

No files matched your search

+11 -2
View File
@@ -140,7 +140,7 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
never writes it, so the consumer places it at a multiple of 16 and leaves it unchanged while
the command reads it. A kernel's window is 128 bytes
(256 on a device made by `Device::from_queries`, whose runtime's floor requires that much
`maxPushConstantsSize`: a dispatch region and 28 buffer addresses). On such a device a render
`maxPushConstantsSize`: a dispatch region and 24 buffer addresses below its tail). On such a device a render
pipeline's two functions share one 256-byte range: the vertex function's window is `[0, 248)`,
and the fragment function's runs from the vertex function's end to 256. A
vertex function is lowered without knowing its fragment function, so it leaves the last 8
@@ -148,7 +148,16 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
costs only a vertex function whose own fields pass 248 bytes, which spills where it would have
filled them. The fields only a checked access reads
(`PushField::ZeroAddress` and each `PushField::SlotBounds`) come last in the order, so they
are the first to move to the block. A kernel that reads a grid builtin reads `PushField::DispatchRegion` on
are the first to move to the block. On a device made by `Device::from_queries` each function's
push ends with its tail, 24 bytes or more above its other pushed fields: its highest
`PushField::SlotBounds` or `PushField::ZeroAddress`, moved there, or where it pushes neither, the
zero word `PushField::TailWord` at `PushPlacement::tail_word`, with which its `push_range` ends;
a function that pushes one field of 8 bytes or fewer has none. A driver that uploads a stage's
push bytes up to the highest one the stage reads then holds every load it widens from the other
fields. The function returns at its start where its tail holds what the consumer never pushes
there (a tail word other than zero, bounds whose two words are both all ones, a zero-range
address of all ones), so the consumer pushes the tail word zero with the other fields; the
bytes of the hole are not read. A kernel that reads a grid builtin reads `PushField::DispatchRegion` on
every dispatch: a dispatch the host knows states Metal's grid and its piece's first threadgroup
there, and an indirect dispatch a zero grid, whose kernel takes `NumWorkgroups` times its
workgroup size. On a device made by `Device::new` it declares no `MultiRegion` constant. On one