rt and translator: a buffer slot's pushed word is its address less 2^31, and an access adds its offset plus 2^31, zero-extended

Under the identity domains a buffer slot aligned to its argument was reached as its pushed address
plus the access's 32-bit byte offset sign-extended to 64 bits. The sign extension is what keeps an
offset below the bind address exact, but a device cannot split a sign-extended offset into a
scalar base and a vector offset as it does a zero-extended one. Now rt pushes the slot's address
less 2^31, and an access adds its offset plus 2^31 (modulo 2^32) to that word, zero-extended. That
is the same address for every offset in [-2^31, 2^31), which the 2 GiB buffer cap guarantees, in
one 32-bit add that a device fuses with the index's shift. A unit index x + c with a constant c
folds c into the bias: (x + c) * s + 2^31 = x * s + (c * s + 2^31) mod 2^32. The builder notes
each u32 sum of a value and a constant for that; the note changes no emitted word.

One place on each side:
- rt: pipeline::address_word, used by the compute and render push writers for every
  BufferAddress field: a bound buffer, a setBytes copy, or the nil buffer.
- translator: lower::access::pointer.
  - biased_slot_address feeds the direct reach.
  - slot_address (the word plus 2^31) feeds every other reader: an access from the word below
    it, a pointer compare, ptrtoint, the memmove overlap's Metal addresses, and pulled vertex
    fetch.
  - The bias applies only under the identity domains and only where the word is pushed: a
    replay variant reads the true address from its root entry.

Unchanged:
- A texture's or sampler's resource ID and the parameter block's address are not biased.
- A pointer loaded from an argument buffer keeps today's form: the address the buffer holds.
- The default domains, which the old runtime and the golden tables use, take no new instruction:
  the readers there load and bitcast the field in the same order as before.

Argument-buffer pointers left in their form (planner's condition):
- They are 19.6% of the corpus's device and constant accesses.
- Time-weighted, they are 0.8% of accesses on the 780M stream gb-780m-u4 and 2.4% on the RTX 3090
  stream gb-3090-r5.
- Kernels with any such access take 1.9% and 8.4% of those streams' GPU time.

Slot pointers used as values, in the entry functions of the corpus's 11,580 kernels (census over
the local sources shards):
- 781 (6.7%) use one as a value: 14 convert one to an integer, 46 compare one, and 731 store one.
  Every such store but one writes private memory (a pointer cell); the one other writes device
  memory.
- 3,511 (30.3%) pass one to a non-inlined function.
- 33 pass one to an air.* call (command encoding, intersect).
A ptrtoint and a compare read slot_address. A pointer parked in a private cell or passed to a
function stays a fat pointer, whose accesses take the forms above. The one store to device memory
makes a wide pointer, which reads the root table, a field identity_admits does not admit. A new
engine test, a_slot_pointer_used_as_a_value_is_its_metal_address,
runs a kernel under the identity domains with biased pushes on the interpreter. It does a ptrtoint
to i64 and to i32, an address compare, and loads 4 bytes below a bind address and 20 above
another, and checks each against the true addresses.

Probe numbers (measured: one particle kernel run alone on RADV 26.2.6, us per dispatch, best of
forward and reverse; the module's two positions accesses changed by hand). Biased form against the
plain zero-extended offset (inexact below the bind address), at subgroup size 32 and at the
driver's 64:
- RX 7900 XTX: 33.6 vs 33.6, 30.8 vs 30.6; at 4x the grid 374.6 vs 374.0, 273.1 vs 272.9.
- PHOENIX 780M: 168.1 vs 168.3, 121.1 vs 120.5; at 4x 2521.9 vs 2522.8, 1744.6 vs 1752.8.
- HawkPoint 780M: 173.3 vs 173.2, 122.5 vs 122.7.
The sign-extended form it replaces measured, at 32:
- HawkPoint: 189.8 (same job), 9.5% slower.
- PHOENIX at 4x: 2735.3 (same job), 8.5% slower.
- XTX: 35.9 (another job), 6.8% slower.
The XOR form with a host-biased word (V7) measured 178.8 on HawkPoint: the add is the one that
fuses.

The tests:
- The identity engine tests push the biased word through engine_word_phases::slot_word.
- rt's three hand-made test kernels (ADD, STEP, WIDE) add 2^31 to each slot word. Their arrays
  are regenerated from the doc GLSL with glslangValidator --target-env vulkan1.2 and checked with
  spirv-val. Today's GLSL reproduced today's arrays exactly before the edit.

docs/API.md (sections 1 and 5), PushField::SlotGuestBase's doc and rt's README known gap on the
2 GiB cap state the word and the form.

SEMANTICS_VERSION 2186 -> 2188 and ARTIFACT_FORMAT_VERSION 544 -> 546. The identity nolockstep
lane holds 2187 and 545, unlanded; these take the next numbers so the two land separately.
This commit is contained in:
Anees Iqbal committed 2026-11-19 03:07:44 -08:00
1 parent fb49fe664c
commit c4b38afdb8
22 files changed
+456 -217

No files matched your search

+16 -6
View File
@@ -111,12 +111,14 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
addresses used directly and a texture's or sampler's handle is its `gpuResourceID`
([RESOURCE-ID.md](RESOURCE-ID.md)). They need `bufferDeviceAddress` and `shaderInt64`. Under
them a buffer slot is reached at its own device address (`gpuAddress` plus the bind offset),
pushed as `PushField::SlotGuestBase`, with no root table, no descriptor and no containment, as
Metal contains no device-address access. A slot whose argument states an alignment of at least
4 (`air.arg_type_align_size`) is reached from that address as it is: each access is at the
address plus its 32-bit byte offset, sign-extended, which is exact as the new runtime makes no
buffer longer than 2 GiB (`MAX_BUFFER_LENGTH`), and an access of 8 or 16 bytes at an offset
proven a multiple of its size is one `uvec2` or `uvec4`. The function states
pushed less 2^31 as `PushField::SlotGuestBase` (section 5), with no root table, no descriptor
and no containment, as Metal contains no device-address access. A slot whose argument states an
alignment of at least 4 (`air.arg_type_align_size`) is reached from that address as it is: each
access is at the pushed word plus its 32-bit byte offset plus 2^31, modulo 2^32, zero-extended,
which is the address plus the offset read as signed, exact as the new runtime makes no buffer
longer than 2 GiB (`MAX_BUFFER_LENGTH`); a constant part of the offset joins the 2^31 in one
constant. An access of 8 or 16 bytes at an offset proven a multiple of its size is one `uvec2`
or `uvec4`. The function states
`RuntimeFact::AddressAlignment` with that alignment (at most 16), and the new runtime refuses
a dispatch whose bound address is not a multiple of it, as Metal's API validation refuses the
bind offset (an accepted difference, section 10). A
@@ -1518,6 +1520,14 @@ for dependency in &pipeline.dependencies {
the shader accesses it, and for a buffer the byte window it can touch. A buffer slot's `kind`
says whether Metal binds a buffer, a visible-function table or an intersection function table
there.
- Under the identity domains (section 1) a buffer slot's `PushField::SlotGuestBase` is its
address, the bound buffer's `gpuAddress` plus the bind offset (or the address of its
`setBytes` copy, or of the consumer's nil buffer where nothing is bound), less 2^31, modulo
2^64. An access through the slot adds its 32-bit byte offset plus 2^31, modulo 2^32,
zero-extended, to that word; a pointer compare, a pointer converted to an integer or stored, a
pulled vertex fetch and an access from the word below it add the 2^31 back to read the address
itself. A pointer loaded from an argument buffer is the address the buffer holds, unbiased. A
texture's or sampler's `SlotGuestBase` is its `gpuResourceID`, unbiased.
- The layout numbers set 0 densely, in `ResourceSlot` order. Set 1 holds the heap arrays (the
resources reached through argument buffers and resource IDs); `pipeline::heap_sampler_capacity`
is the most elements a set-1 sampler array has on a profile. A texture buffer reached so is an