From c4b38afdb8ab75dcfec15055eaddeede397c24be Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 19 Nov 2026 02:45:30 -0800 Subject: [PATCH] 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. --- crates/metal2vulkan-rt/README.md | 13 +- crates/metal2vulkan-rt/src/encoder.rs | 7 +- crates/metal2vulkan-rt/src/pipeline.rs | 19 +- crates/metal2vulkan-rt/src/render_encoder.rs | 6 +- crates/metal2vulkan-rt/src/tests/kernels.rs | 275 +++++++++--------- crates/metal2vulkan/src/cache/mod.rs | 4 +- .../metal2vulkan/src/lower/access/dynamic.rs | 3 +- crates/metal2vulkan/src/lower/access/emit.rs | 17 +- crates/metal2vulkan/src/lower/access/mod.rs | 11 +- .../metal2vulkan/src/lower/access/pointer.rs | 64 +++- crates/metal2vulkan/src/lower/access/psb.rs | 64 ++-- .../metal2vulkan/src/lower/access/pulled.rs | 3 +- crates/metal2vulkan/src/memory/leaf.rs | 8 + crates/metal2vulkan/src/pipeline/sym.rs | 5 +- .../src/spirv/builder/function.rs | 10 + .../metal2vulkan/src/spirv/builder/module.rs | 4 + .../metal2vulkan/src/tests/engine_identity.rs | 116 +++++++- .../src/tests/engine_offsets_to_2gib.rs | 4 +- .../src/tests/engine_pointer_memory.rs | 4 +- .../src/tests/engine_simd_emulated.rs | 6 +- .../src/tests/engine_word_phases.rs | 8 +- docs/API.md | 22 +- 22 files changed, 456 insertions(+), 217 deletions(-) diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index b2ac81ae0..01b38151c 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -439,10 +439,15 @@ between, `external_writes_done` comes first, as above. offers a non-host-visible type first. - rt caps a buffer at 2 GiB (`MAX_BUFFER_LENGTH`), where the M3's Metal allows 38.88 GiB (`maxBufferLength`, 41,747,087,360 bytes), about twenty times as much: shaders reach a buffer's - bytes by 32-bit offsets from its bind address, which bought 4.3 to 6.6% on AMD cards and more on - the RTX 3090 in a probe of constant reads, where a 64-bit sum without them was 8.9% slower on the - RX 7900 XTX, and lifting the cap would put 64-bit offset arithmetic on every buffer access. A - longer buffer is `Refusal::BufferTooLong`. + bytes by 32-bit offsets from its bind address, and lifting the cap would put 64-bit offset + arithmetic on every buffer access. The word rt pushes for a buffer slot is the slot's address + less 2^31; an access adds its 32-bit offset plus 2^31 to that word, zero-extended, which is the + offset read as signed in one 32-bit add. In a probe of one particle kernel that form was within + 0.7% of a zero-extended offset (inexact below the bind address) on the RX 7900 XTX and two + Radeon 780Ms at the kernel's grid, and on the XTX and one 780M at four times it, where the + sign-extended offset it replaced was 6.8 to 9.5% slower. In an earlier probe of constant reads, + 32-bit offsets bought 4.3 to 6.6% on AMD cards and more on the RTX 3090, where a 64-bit sum was + 8.9% slower on the RX 7900 XTX. A longer buffer is `Refusal::BufferTooLong`. - A dispatch whose indirect arguments, or an indexed draw whose indices, start at a byte of their block that is not a multiple of 4, or of the index size, is refused (`Refusal::ArgumentPlace`). Metal's offset rules keep both at that multiple of the buffer's start, so only a buffer that diff --git a/crates/metal2vulkan-rt/src/encoder.rs b/crates/metal2vulkan-rt/src/encoder.rs index d1789fefa..334f1a355 100644 --- a/crates/metal2vulkan-rt/src/encoder.rs +++ b/crates/metal2vulkan-rt/src/encoder.rs @@ -12,8 +12,8 @@ use crate::kept::{Handle, Lent, Uncounted}; use crate::memory::BlockId; use crate::over; use crate::pipeline::{ - ComputePipelineState, FieldValue, Form, Interface, Kernel, Place, Which, PUSH_BYTES, - PUSH_STAGES, SQUARE, + address_word, ComputePipelineState, FieldValue, Form, Interface, Kernel, Place, Which, + PUSH_BYTES, PUSH_STAGES, SQUARE, }; use crate::record::Reach; use crate::ring::CHUNK; @@ -1292,7 +1292,8 @@ impl Parameters { Some(Slot::Bytes(address)) => *address, Some(Slot::Empty) | None => nil, }; - bytes[at..at + 8].copy_from_slice(&address.to_le_bytes()); + let word = address_word(address); + bytes[at..at + 8].copy_from_slice(&word.to_le_bytes()); } FieldValue::TextureId(slot) => { let id = match textures.get(slot as usize) { diff --git a/crates/metal2vulkan-rt/src/pipeline.rs b/crates/metal2vulkan-rt/src/pipeline.rs index ddb46ddb0..811b8d1d6 100644 --- a/crates/metal2vulkan-rt/src/pipeline.rs +++ b/crates/metal2vulkan-rt/src/pipeline.rs @@ -538,14 +538,23 @@ pub(crate) enum Place { Block(u32), } +/// The word a buffer slot's [`FieldValue::BufferAddress`] parameter holds for `address`: the +/// address less 2^31, as the translator's identity domains read a buffer slot's `SlotGuestBase` +/// (`docs/API.md`, section 5). A module adds an access's 32-bit byte offset plus 2^31 to the word, +/// zero-extended, which is the address plus the offset read as signed, and adds 2^31 back where it +/// reads the address itself. +pub(crate) fn address_word(address: u64) -> u64 { + address.wrapping_sub(1 << 31) +} + /// What a parameter holds. #[derive(Clone, Copy)] pub(crate) enum FieldValue { - /// A `u64`: the address of the buffer bound at the slot plus its offset, the address of the - /// slot's `set_bytes` copy, or 0 where nothing is bound. `mask` is the alignment the module - /// takes that address to have, less 1 (`RuntimeFact::AddressAlignment`), 0 where it takes - /// none: a dispatch whose bound buffer's address it does not divide is refused - /// (`Refusal::BufferOffsetAlignment`). + /// A `u64`: the [`address_word`] of the address of the buffer bound at the slot plus its + /// offset, of the address of the slot's `set_bytes` copy, or of the nil buffer's address where + /// nothing is bound. `mask` is the alignment the module takes that address to have, less 1 + /// (`RuntimeFact::AddressAlignment`), 0 where it takes none: a dispatch whose bound buffer's + /// address it does not divide is refused (`Refusal::BufferOffsetAlignment`). BufferAddress { slot: u32, mask: u64 }, /// A `u64`: the `gpuResourceID` of the texture bound at the slot, 0 where none is. TextureId(u32), diff --git a/crates/metal2vulkan-rt/src/render_encoder.rs b/crates/metal2vulkan-rt/src/render_encoder.rs index 3b3ad7322..ab07337e2 100644 --- a/crates/metal2vulkan-rt/src/render_encoder.rs +++ b/crates/metal2vulkan-rt/src/render_encoder.rs @@ -83,7 +83,7 @@ use crate::hazard::Access; use crate::kept::{Handle, Lent, Uncounted}; use crate::over; use crate::pass::{layout_barrier, ops, LoadAction, Pass, RenderPassDescriptor, StoreAction}; -use crate::pipeline::{FieldValue, PUSH_STAGES}; +use crate::pipeline::{address_word, FieldValue, PUSH_STAGES}; use crate::record::{memory_barrier, Reach}; use crate::render::{Draws, RenderPipelineState, FRAGMENT, VERTEX}; use crate::ring::{Placed, CHUNK}; @@ -2246,8 +2246,8 @@ fn fill_push( match value { // At a multiple of the argument's alignment, which the draw checked first. FieldValue::BufferAddress { slot, .. } => { - let address = tables.address(slot, nil); - push[at..at + 8].copy_from_slice(&address.to_le_bytes()); + let word = address_word(tables.address(slot, nil)); + push[at..at + 8].copy_from_slice(&word.to_le_bytes()); } FieldValue::TextureId(slot) => { let id = (tables.texture(slot)).map_or(0, |t| { diff --git a/crates/metal2vulkan-rt/src/tests/kernels.rs b/crates/metal2vulkan-rt/src/tests/kernels.rs index c1f5a3ad9..1de26cce3 100644 --- a/crates/metal2vulkan-rt/src/tests/kernels.rs +++ b/crates/metal2vulkan-rt/src/tests/kernels.rs @@ -2,7 +2,8 @@ //! doc comment with `glslangValidator -V --target-env vulkan1.2` (whose workgroup size is the //! specialized `WorkgroupSize`: `LocalSizeId` needs `maintenance4`) and checked with `spirv-val`. //! Each reads its parameters as the translator's kernels do: the dispatch region first, then -//! buffer addresses, past the push window through a block in the parameter ring. +//! buffer addresses, each pushed less 2^31 (`pipeline::address_word`), past the push window through +//! a block in the parameter ring. /// A kernel over three buffers: `o[i] = a[i] + b[i]` below the grid, which an indirect /// dispatch (a zero grid) takes from its workgroup count. @@ -14,16 +15,17 @@ /// layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; /// layout(buffer_reference, std430, buffer_reference_align = 4) buffer Words { uint w[]; }; /// layout(push_constant, std430) uniform Params { uvec4 region[2]; uint64_t a; uint64_t b; uint64_t o; } p; +/// const uint64_t BIAS = 0x80000000ul; /// void main() { /// uint grid = p.region[1].x != 0u ? p.region[1].x : gl_NumWorkGroups.x * gl_WorkGroupSize.x; /// uint i = gl_GlobalInvocationID.x; /// if (i >= grid) return; -/// Words(p.o).w[i] = Words(p.a).w[i] + Words(p.b).w[i]; +/// Words(p.o + BIAS).w[i] = Words(p.a + BIAS).w[i] + Words(p.b + BIAS).w[i]; /// } /// ``` #[rustfmt::skip] -pub(crate) const ADD: [u32; 535] = [ - 0x07230203, 0x00010500, 0x0008000b, 0x0000004f, 0x00000000, 0x00020011, 0x00000001, 0x00020011, +pub(crate) const ADD: [u32; 555] = [ + 0x07230203, 0x00010500, 0x0008000b, 0x00000053, 0x00000000, 0x00020011, 0x00000001, 0x00020011, 0x0000000b, 0x00020011, 0x000014e3, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x000014e4, 0x00000001, 0x0008000f, 0x00000005, 0x00000004, 0x6e69616d, 0x00000000, 0x0000000f, 0x00000021, 0x0000002d, 0x00060010, 0x00000004, 0x00000011, 0x00000001, @@ -36,15 +38,15 @@ pub(crate) const ADD: [u32; 535] = [ 0x00000002, 0x00000062, 0x00040006, 0x0000000d, 0x00000003, 0x0000006f, 0x00030005, 0x0000000f, 0x00000070, 0x00070005, 0x00000021, 0x4e5f6c67, 0x6f576d75, 0x72476b72, 0x7370756f, 0x00000000, 0x00030005, 0x0000002c, 0x00000069, 0x00080005, 0x0000002d, 0x475f6c67, 0x61626f6c, 0x766e496c, - 0x7461636f, 0x496e6f69, 0x00000044, 0x00040005, 0x0000003c, 0x64726f57, 0x00000073, 0x00040006, - 0x0000003c, 0x00000000, 0x00000077, 0x00040047, 0x0000000b, 0x00000006, 0x00000010, 0x00030047, + 0x7461636f, 0x496e6f69, 0x00000044, 0x00040005, 0x0000003e, 0x64726f57, 0x00000073, 0x00040006, + 0x0000003e, 0x00000000, 0x00000077, 0x00040047, 0x0000000b, 0x00000006, 0x00000010, 0x00030047, 0x0000000d, 0x00000002, 0x00050048, 0x0000000d, 0x00000000, 0x00000023, 0x00000000, 0x00050048, 0x0000000d, 0x00000001, 0x00000023, 0x00000020, 0x00050048, 0x0000000d, 0x00000002, 0x00000023, 0x00000028, 0x00050048, 0x0000000d, 0x00000003, 0x00000023, 0x00000030, 0x00040047, 0x00000021, 0x0000000b, 0x00000018, 0x00040047, 0x00000025, 0x00000001, 0x00000000, 0x00040047, 0x00000026, 0x00000001, 0x00000001, 0x00040047, 0x00000027, 0x00000001, 0x00000002, 0x00040047, 0x00000028, - 0x0000000b, 0x00000019, 0x00040047, 0x0000002d, 0x0000000b, 0x0000001c, 0x00040047, 0x0000003b, - 0x00000006, 0x00000004, 0x00030047, 0x0000003c, 0x00000002, 0x00050048, 0x0000003c, 0x00000000, + 0x0000000b, 0x00000019, 0x00040047, 0x0000002d, 0x0000000b, 0x0000001c, 0x00040047, 0x0000003d, + 0x00000006, 0x00000004, 0x00030047, 0x0000003e, 0x00000002, 0x00050048, 0x0000003e, 0x00000000, 0x00000023, 0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00040015, 0x00000006, 0x00000020, 0x00000000, 0x00040020, 0x00000007, 0x00000007, 0x00000006, 0x00040017, 0x00000009, 0x00000006, 0x00000004, 0x0004002b, 0x00000006, 0x0000000a, 0x00000002, 0x0004001c, @@ -59,37 +61,40 @@ pub(crate) const ADD: [u32; 535] = [ 0x00000006, 0x00000026, 0x00000001, 0x00040032, 0x00000006, 0x00000027, 0x00000001, 0x00060033, 0x0000001f, 0x00000028, 0x00000025, 0x00000026, 0x00000027, 0x0004003b, 0x00000020, 0x0000002d, 0x00000001, 0x0004002b, 0x00000010, 0x00000036, 0x00000003, 0x00040020, 0x00000037, 0x00000009, - 0x0000000c, 0x00030027, 0x0000003a, 0x000014e5, 0x0003001d, 0x0000003b, 0x00000006, 0x0003001e, - 0x0000003c, 0x0000003b, 0x00040020, 0x0000003a, 0x000014e5, 0x0000003c, 0x00040020, 0x00000043, - 0x000014e5, 0x00000006, 0x0004002b, 0x00000010, 0x00000046, 0x00000002, 0x00050036, 0x00000002, - 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x0004003b, 0x00000007, 0x00000008, - 0x00000007, 0x0004003b, 0x00000007, 0x00000019, 0x00000007, 0x0004003b, 0x00000007, 0x0000002c, - 0x00000007, 0x00070041, 0x00000014, 0x00000015, 0x0000000f, 0x00000011, 0x00000012, 0x00000013, - 0x0004003d, 0x00000006, 0x00000016, 0x00000015, 0x000500ab, 0x00000017, 0x00000018, 0x00000016, - 0x00000013, 0x000300f7, 0x0000001b, 0x00000000, 0x000400fa, 0x00000018, 0x0000001a, 0x0000001e, - 0x000200f8, 0x0000001a, 0x00070041, 0x00000014, 0x0000001c, 0x0000000f, 0x00000011, 0x00000012, - 0x00000013, 0x0004003d, 0x00000006, 0x0000001d, 0x0000001c, 0x0003003e, 0x00000019, 0x0000001d, - 0x000200f9, 0x0000001b, 0x000200f8, 0x0000001e, 0x00050041, 0x00000022, 0x00000023, 0x00000021, - 0x00000013, 0x0004003d, 0x00000006, 0x00000024, 0x00000023, 0x00050051, 0x00000006, 0x00000029, - 0x00000028, 0x00000000, 0x00050084, 0x00000006, 0x0000002a, 0x00000024, 0x00000029, 0x0003003e, - 0x00000019, 0x0000002a, 0x000200f9, 0x0000001b, 0x000200f8, 0x0000001b, 0x0004003d, 0x00000006, - 0x0000002b, 0x00000019, 0x0003003e, 0x00000008, 0x0000002b, 0x00050041, 0x00000022, 0x0000002e, - 0x0000002d, 0x00000013, 0x0004003d, 0x00000006, 0x0000002f, 0x0000002e, 0x0003003e, 0x0000002c, - 0x0000002f, 0x0004003d, 0x00000006, 0x00000030, 0x0000002c, 0x0004003d, 0x00000006, 0x00000031, - 0x00000008, 0x000500ae, 0x00000017, 0x00000032, 0x00000030, 0x00000031, 0x000300f7, 0x00000034, - 0x00000000, 0x000400fa, 0x00000032, 0x00000033, 0x00000034, 0x000200f8, 0x00000033, 0x000100fd, - 0x000200f8, 0x00000034, 0x00050041, 0x00000037, 0x00000038, 0x0000000f, 0x00000036, 0x0004003d, - 0x0000000c, 0x00000039, 0x00000038, 0x00040078, 0x0000003a, 0x0000003d, 0x00000039, 0x0004003d, - 0x00000006, 0x0000003e, 0x0000002c, 0x00050041, 0x00000037, 0x0000003f, 0x0000000f, 0x00000012, - 0x0004003d, 0x0000000c, 0x00000040, 0x0000003f, 0x00040078, 0x0000003a, 0x00000041, 0x00000040, - 0x0004003d, 0x00000006, 0x00000042, 0x0000002c, 0x00060041, 0x00000043, 0x00000044, 0x00000041, - 0x00000011, 0x00000042, 0x0006003d, 0x00000006, 0x00000045, 0x00000044, 0x00000002, 0x00000004, - 0x00050041, 0x00000037, 0x00000047, 0x0000000f, 0x00000046, 0x0004003d, 0x0000000c, 0x00000048, - 0x00000047, 0x00040078, 0x0000003a, 0x00000049, 0x00000048, 0x0004003d, 0x00000006, 0x0000004a, - 0x0000002c, 0x00060041, 0x00000043, 0x0000004b, 0x00000049, 0x00000011, 0x0000004a, 0x0006003d, - 0x00000006, 0x0000004c, 0x0000004b, 0x00000002, 0x00000004, 0x00050080, 0x00000006, 0x0000004d, - 0x00000045, 0x0000004c, 0x00060041, 0x00000043, 0x0000004e, 0x0000003d, 0x00000011, 0x0000003e, - 0x0005003e, 0x0000004e, 0x0000004d, 0x00000002, 0x00000004, 0x000100fd, 0x00010038, + 0x0000000c, 0x0005002b, 0x0000000c, 0x0000003a, 0x80000000, 0x00000000, 0x00030027, 0x0000003c, + 0x000014e5, 0x0003001d, 0x0000003d, 0x00000006, 0x0003001e, 0x0000003e, 0x0000003d, 0x00040020, + 0x0000003c, 0x000014e5, 0x0000003e, 0x00040020, 0x00000046, 0x000014e5, 0x00000006, 0x0004002b, + 0x00000010, 0x00000049, 0x00000002, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, + 0x000200f8, 0x00000005, 0x0004003b, 0x00000007, 0x00000008, 0x00000007, 0x0004003b, 0x00000007, + 0x00000019, 0x00000007, 0x0004003b, 0x00000007, 0x0000002c, 0x00000007, 0x00070041, 0x00000014, + 0x00000015, 0x0000000f, 0x00000011, 0x00000012, 0x00000013, 0x0004003d, 0x00000006, 0x00000016, + 0x00000015, 0x000500ab, 0x00000017, 0x00000018, 0x00000016, 0x00000013, 0x000300f7, 0x0000001b, + 0x00000000, 0x000400fa, 0x00000018, 0x0000001a, 0x0000001e, 0x000200f8, 0x0000001a, 0x00070041, + 0x00000014, 0x0000001c, 0x0000000f, 0x00000011, 0x00000012, 0x00000013, 0x0004003d, 0x00000006, + 0x0000001d, 0x0000001c, 0x0003003e, 0x00000019, 0x0000001d, 0x000200f9, 0x0000001b, 0x000200f8, + 0x0000001e, 0x00050041, 0x00000022, 0x00000023, 0x00000021, 0x00000013, 0x0004003d, 0x00000006, + 0x00000024, 0x00000023, 0x00050051, 0x00000006, 0x00000029, 0x00000028, 0x00000000, 0x00050084, + 0x00000006, 0x0000002a, 0x00000024, 0x00000029, 0x0003003e, 0x00000019, 0x0000002a, 0x000200f9, + 0x0000001b, 0x000200f8, 0x0000001b, 0x0004003d, 0x00000006, 0x0000002b, 0x00000019, 0x0003003e, + 0x00000008, 0x0000002b, 0x00050041, 0x00000022, 0x0000002e, 0x0000002d, 0x00000013, 0x0004003d, + 0x00000006, 0x0000002f, 0x0000002e, 0x0003003e, 0x0000002c, 0x0000002f, 0x0004003d, 0x00000006, + 0x00000030, 0x0000002c, 0x0004003d, 0x00000006, 0x00000031, 0x00000008, 0x000500ae, 0x00000017, + 0x00000032, 0x00000030, 0x00000031, 0x000300f7, 0x00000034, 0x00000000, 0x000400fa, 0x00000032, + 0x00000033, 0x00000034, 0x000200f8, 0x00000033, 0x000100fd, 0x000200f8, 0x00000034, 0x00050041, + 0x00000037, 0x00000038, 0x0000000f, 0x00000036, 0x0004003d, 0x0000000c, 0x00000039, 0x00000038, + 0x00050080, 0x0000000c, 0x0000003b, 0x00000039, 0x0000003a, 0x00040078, 0x0000003c, 0x0000003f, + 0x0000003b, 0x0004003d, 0x00000006, 0x00000040, 0x0000002c, 0x00050041, 0x00000037, 0x00000041, + 0x0000000f, 0x00000012, 0x0004003d, 0x0000000c, 0x00000042, 0x00000041, 0x00050080, 0x0000000c, + 0x00000043, 0x00000042, 0x0000003a, 0x00040078, 0x0000003c, 0x00000044, 0x00000043, 0x0004003d, + 0x00000006, 0x00000045, 0x0000002c, 0x00060041, 0x00000046, 0x00000047, 0x00000044, 0x00000011, + 0x00000045, 0x0006003d, 0x00000006, 0x00000048, 0x00000047, 0x00000002, 0x00000004, 0x00050041, + 0x00000037, 0x0000004a, 0x0000000f, 0x00000049, 0x0004003d, 0x0000000c, 0x0000004b, 0x0000004a, + 0x00050080, 0x0000000c, 0x0000004c, 0x0000004b, 0x0000003a, 0x00040078, 0x0000003c, 0x0000004d, + 0x0000004c, 0x0004003d, 0x00000006, 0x0000004e, 0x0000002c, 0x00060041, 0x00000046, 0x0000004f, + 0x0000004d, 0x00000011, 0x0000004e, 0x0006003d, 0x00000006, 0x00000050, 0x0000004f, 0x00000002, + 0x00000004, 0x00050080, 0x00000006, 0x00000051, 0x00000048, 0x00000050, 0x00060041, 0x00000046, + 0x00000052, 0x0000003f, 0x00000011, 0x00000040, 0x0005003e, 0x00000052, 0x00000051, 0x00000002, + 0x00000004, 0x000100fd, 0x00010038, ]; /// A kernel that reads and writes one buffer: `x[i] = x[i] * 2 + 1` below the grid. @@ -101,15 +106,16 @@ pub(crate) const ADD: [u32; 535] = [ /// layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; /// layout(buffer_reference, std430, buffer_reference_align = 4) buffer Words { uint w[]; }; /// layout(push_constant, std430) uniform Params { uvec4 region[2]; uint64_t x; } p; +/// const uint64_t BIAS = 0x80000000ul; /// void main() { /// uint i = gl_GlobalInvocationID.x; /// if (i >= p.region[1].x) return; -/// Words(p.x).w[i] = Words(p.x).w[i] * 2u + 1u; +/// Words(p.x + BIAS).w[i] = Words(p.x + BIAS).w[i] * 2u + 1u; /// } /// ``` #[rustfmt::skip] -pub(crate) const STEP: [u32; 390] = [ - 0x07230203, 0x00010500, 0x0008000b, 0x0000003a, 0x00000000, 0x00020011, 0x00000001, 0x00020011, +pub(crate) const STEP: [u32; 405] = [ + 0x07230203, 0x00010500, 0x0008000b, 0x0000003d, 0x00000000, 0x00020011, 0x00000001, 0x00020011, 0x0000000b, 0x00020011, 0x000014e3, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x000014e4, 0x00000001, 0x0007000f, 0x00000005, 0x00000004, 0x6e69616d, 0x00000000, 0x0000000b, 0x00000017, 0x00060010, 0x00000004, 0x00000011, 0x00000001, 0x00000001, @@ -120,13 +126,13 @@ pub(crate) const STEP: [u32; 390] = [ 0x0000000b, 0x475f6c67, 0x61626f6c, 0x766e496c, 0x7461636f, 0x496e6f69, 0x00000044, 0x00040005, 0x00000015, 0x61726150, 0x0000736d, 0x00050006, 0x00000015, 0x00000000, 0x69676572, 0x00006e6f, 0x00040006, 0x00000015, 0x00000001, 0x00000078, 0x00030005, 0x00000017, 0x00000070, 0x00040005, - 0x00000028, 0x64726f57, 0x00000073, 0x00040006, 0x00000028, 0x00000000, 0x00000077, 0x00040047, + 0x0000002a, 0x64726f57, 0x00000073, 0x00040006, 0x0000002a, 0x00000000, 0x00000077, 0x00040047, 0x0000000b, 0x0000000b, 0x0000001c, 0x00040047, 0x00000013, 0x00000006, 0x00000010, 0x00030047, 0x00000015, 0x00000002, 0x00050048, 0x00000015, 0x00000000, 0x00000023, 0x00000000, 0x00050048, - 0x00000015, 0x00000001, 0x00000023, 0x00000020, 0x00040047, 0x00000027, 0x00000006, 0x00000004, - 0x00030047, 0x00000028, 0x00000002, 0x00050048, 0x00000028, 0x00000000, 0x00000023, 0x00000000, - 0x00040047, 0x00000036, 0x00000001, 0x00000000, 0x00040047, 0x00000037, 0x00000001, 0x00000001, - 0x00040047, 0x00000038, 0x00000001, 0x00000002, 0x00040047, 0x00000039, 0x0000000b, 0x00000019, + 0x00000015, 0x00000001, 0x00000023, 0x00000020, 0x00040047, 0x00000029, 0x00000006, 0x00000004, + 0x00030047, 0x0000002a, 0x00000002, 0x00050048, 0x0000002a, 0x00000000, 0x00000023, 0x00000000, + 0x00040047, 0x00000039, 0x00000001, 0x00000000, 0x00040047, 0x0000003a, 0x00000001, 0x00000001, + 0x00040047, 0x0000003b, 0x00000001, 0x00000002, 0x00040047, 0x0000003c, 0x0000000b, 0x00000019, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00040015, 0x00000006, 0x00000020, 0x00000000, 0x00040020, 0x00000007, 0x00000007, 0x00000006, 0x00040017, 0x00000009, 0x00000006, 0x00000003, 0x00040020, 0x0000000a, 0x00000001, 0x00000009, 0x0004003b, 0x0000000a, 0x0000000b, @@ -137,27 +143,29 @@ pub(crate) const STEP: [u32; 390] = [ 0x00000015, 0x0004003b, 0x00000016, 0x00000017, 0x00000009, 0x00040015, 0x00000018, 0x00000020, 0x00000001, 0x0004002b, 0x00000018, 0x00000019, 0x00000000, 0x0004002b, 0x00000018, 0x0000001a, 0x00000001, 0x00040020, 0x0000001b, 0x00000009, 0x00000006, 0x00020014, 0x0000001e, 0x00040020, - 0x00000023, 0x00000009, 0x00000014, 0x00030027, 0x00000026, 0x000014e5, 0x0003001d, 0x00000027, - 0x00000006, 0x0003001e, 0x00000028, 0x00000027, 0x00040020, 0x00000026, 0x000014e5, 0x00000028, - 0x00040020, 0x0000002f, 0x000014e5, 0x00000006, 0x0004002b, 0x00000006, 0x00000033, 0x00000001, - 0x00040032, 0x00000006, 0x00000036, 0x00000001, 0x00040032, 0x00000006, 0x00000037, 0x00000001, - 0x00040032, 0x00000006, 0x00000038, 0x00000001, 0x00060033, 0x00000009, 0x00000039, 0x00000036, - 0x00000037, 0x00000038, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, - 0x00000005, 0x0004003b, 0x00000007, 0x00000008, 0x00000007, 0x00050041, 0x0000000d, 0x0000000e, - 0x0000000b, 0x0000000c, 0x0004003d, 0x00000006, 0x0000000f, 0x0000000e, 0x0003003e, 0x00000008, - 0x0000000f, 0x0004003d, 0x00000006, 0x00000010, 0x00000008, 0x00070041, 0x0000001b, 0x0000001c, - 0x00000017, 0x00000019, 0x0000001a, 0x0000000c, 0x0004003d, 0x00000006, 0x0000001d, 0x0000001c, - 0x000500ae, 0x0000001e, 0x0000001f, 0x00000010, 0x0000001d, 0x000300f7, 0x00000021, 0x00000000, - 0x000400fa, 0x0000001f, 0x00000020, 0x00000021, 0x000200f8, 0x00000020, 0x000100fd, 0x000200f8, - 0x00000021, 0x00050041, 0x00000023, 0x00000024, 0x00000017, 0x0000001a, 0x0004003d, 0x00000014, - 0x00000025, 0x00000024, 0x00040078, 0x00000026, 0x00000029, 0x00000025, 0x0004003d, 0x00000006, - 0x0000002a, 0x00000008, 0x00050041, 0x00000023, 0x0000002b, 0x00000017, 0x0000001a, 0x0004003d, - 0x00000014, 0x0000002c, 0x0000002b, 0x00040078, 0x00000026, 0x0000002d, 0x0000002c, 0x0004003d, - 0x00000006, 0x0000002e, 0x00000008, 0x00060041, 0x0000002f, 0x00000030, 0x0000002d, 0x00000019, - 0x0000002e, 0x0006003d, 0x00000006, 0x00000031, 0x00000030, 0x00000002, 0x00000004, 0x00050084, - 0x00000006, 0x00000032, 0x00000031, 0x00000012, 0x00050080, 0x00000006, 0x00000034, 0x00000032, - 0x00000033, 0x00060041, 0x0000002f, 0x00000035, 0x00000029, 0x00000019, 0x0000002a, 0x0005003e, - 0x00000035, 0x00000034, 0x00000002, 0x00000004, 0x000100fd, 0x00010038, + 0x00000023, 0x00000009, 0x00000014, 0x0005002b, 0x00000014, 0x00000026, 0x80000000, 0x00000000, + 0x00030027, 0x00000028, 0x000014e5, 0x0003001d, 0x00000029, 0x00000006, 0x0003001e, 0x0000002a, + 0x00000029, 0x00040020, 0x00000028, 0x000014e5, 0x0000002a, 0x00040020, 0x00000032, 0x000014e5, + 0x00000006, 0x0004002b, 0x00000006, 0x00000036, 0x00000001, 0x00040032, 0x00000006, 0x00000039, + 0x00000001, 0x00040032, 0x00000006, 0x0000003a, 0x00000001, 0x00040032, 0x00000006, 0x0000003b, + 0x00000001, 0x00060033, 0x00000009, 0x0000003c, 0x00000039, 0x0000003a, 0x0000003b, 0x00050036, + 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x0004003b, 0x00000007, + 0x00000008, 0x00000007, 0x00050041, 0x0000000d, 0x0000000e, 0x0000000b, 0x0000000c, 0x0004003d, + 0x00000006, 0x0000000f, 0x0000000e, 0x0003003e, 0x00000008, 0x0000000f, 0x0004003d, 0x00000006, + 0x00000010, 0x00000008, 0x00070041, 0x0000001b, 0x0000001c, 0x00000017, 0x00000019, 0x0000001a, + 0x0000000c, 0x0004003d, 0x00000006, 0x0000001d, 0x0000001c, 0x000500ae, 0x0000001e, 0x0000001f, + 0x00000010, 0x0000001d, 0x000300f7, 0x00000021, 0x00000000, 0x000400fa, 0x0000001f, 0x00000020, + 0x00000021, 0x000200f8, 0x00000020, 0x000100fd, 0x000200f8, 0x00000021, 0x00050041, 0x00000023, + 0x00000024, 0x00000017, 0x0000001a, 0x0004003d, 0x00000014, 0x00000025, 0x00000024, 0x00050080, + 0x00000014, 0x00000027, 0x00000025, 0x00000026, 0x00040078, 0x00000028, 0x0000002b, 0x00000027, + 0x0004003d, 0x00000006, 0x0000002c, 0x00000008, 0x00050041, 0x00000023, 0x0000002d, 0x00000017, + 0x0000001a, 0x0004003d, 0x00000014, 0x0000002e, 0x0000002d, 0x00050080, 0x00000014, 0x0000002f, + 0x0000002e, 0x00000026, 0x00040078, 0x00000028, 0x00000030, 0x0000002f, 0x0004003d, 0x00000006, + 0x00000031, 0x00000008, 0x00060041, 0x00000032, 0x00000033, 0x00000030, 0x00000019, 0x00000031, + 0x0006003d, 0x00000006, 0x00000034, 0x00000033, 0x00000002, 0x00000004, 0x00050084, 0x00000006, + 0x00000035, 0x00000034, 0x00000012, 0x00050080, 0x00000006, 0x00000037, 0x00000035, 0x00000036, + 0x00060041, 0x00000032, 0x00000038, 0x0000002b, 0x00000019, 0x0000002c, 0x0005003e, 0x00000038, + 0x00000037, 0x00000002, 0x00000004, 0x000100fd, 0x00010038, ]; /// A kernel over sixteen buffers, eleven of their addresses in the push window and five in @@ -171,19 +179,20 @@ pub(crate) const STEP: [u32; 390] = [ /// layout(buffer_reference, std430, buffer_reference_align = 4) buffer Words { uint w[]; }; /// layout(buffer_reference, std430, buffer_reference_align = 16) buffer Block { uint64_t s[5]; }; /// layout(push_constant, std430) uniform Params { uvec4 region[2]; uint64_t block; uint64_t s[11]; } p; +/// const uint64_t BIAS = 0x80000000ul; /// void main() { /// uint i = gl_GlobalInvocationID.x; /// if (i >= p.region[1].x) return; /// uint sum = 0u; -/// for (int k = 0; k < 11; k++) sum += Words(p.s[k]).w[i]; +/// for (int k = 0; k < 11; k++) sum += Words(p.s[k] + BIAS).w[i]; /// Block b = Block(p.block); -/// for (int k = 0; k < 4; k++) sum += Words(b.s[k]).w[i]; -/// Words(b.s[4]).w[i] = sum; +/// for (int k = 0; k < 4; k++) sum += Words(b.s[k] + BIAS).w[i]; +/// Words(b.s[4] + BIAS).w[i] = sum; /// } /// ``` #[rustfmt::skip] -pub(crate) const WIDE: [u32; 691] = [ - 0x07230203, 0x00010500, 0x0008000b, 0x0000006b, 0x00000000, 0x00020011, 0x00000001, 0x00020011, +pub(crate) const WIDE: [u32; 711] = [ + 0x07230203, 0x00010500, 0x0008000b, 0x0000006f, 0x00000000, 0x00020011, 0x00000001, 0x00020011, 0x0000000b, 0x00020011, 0x000014e3, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x000014e4, 0x00000001, 0x0007000f, 0x00000005, 0x00000004, 0x6e69616d, 0x00000000, 0x0000000b, 0x00000019, 0x00060010, 0x00000004, 0x00000011, 0x00000001, 0x00000001, @@ -195,18 +204,18 @@ pub(crate) const WIDE: [u32; 691] = [ 0x00000017, 0x61726150, 0x0000736d, 0x00050006, 0x00000017, 0x00000000, 0x69676572, 0x00006e6f, 0x00050006, 0x00000017, 0x00000001, 0x636f6c62, 0x0000006b, 0x00040006, 0x00000017, 0x00000002, 0x00000073, 0x00030005, 0x00000019, 0x00000070, 0x00030005, 0x00000025, 0x006d7573, 0x00030005, - 0x00000027, 0x0000006b, 0x00040005, 0x00000037, 0x64726f57, 0x00000073, 0x00040006, 0x00000037, - 0x00000000, 0x00000077, 0x00040005, 0x00000044, 0x636f6c42, 0x0000006b, 0x00040006, 0x00000044, - 0x00000000, 0x00000073, 0x00030005, 0x00000046, 0x00000062, 0x00030005, 0x0000004a, 0x0000006b, + 0x00000027, 0x0000006b, 0x00040005, 0x00000039, 0x64726f57, 0x00000073, 0x00040006, 0x00000039, + 0x00000000, 0x00000077, 0x00040005, 0x00000046, 0x636f6c42, 0x0000006b, 0x00040006, 0x00000046, + 0x00000000, 0x00000073, 0x00030005, 0x00000048, 0x00000062, 0x00030005, 0x0000004c, 0x0000006b, 0x00040047, 0x0000000b, 0x0000000b, 0x0000001c, 0x00040047, 0x00000013, 0x00000006, 0x00000010, 0x00040047, 0x00000016, 0x00000006, 0x00000008, 0x00030047, 0x00000017, 0x00000002, 0x00050048, 0x00000017, 0x00000000, 0x00000023, 0x00000000, 0x00050048, 0x00000017, 0x00000001, 0x00000023, - 0x00000020, 0x00050048, 0x00000017, 0x00000002, 0x00000023, 0x00000028, 0x00040047, 0x00000036, - 0x00000006, 0x00000004, 0x00030047, 0x00000037, 0x00000002, 0x00050048, 0x00000037, 0x00000000, - 0x00000023, 0x00000000, 0x00040047, 0x00000043, 0x00000006, 0x00000008, 0x00030047, 0x00000044, - 0x00000002, 0x00050048, 0x00000044, 0x00000000, 0x00000023, 0x00000000, 0x00030047, 0x00000046, - 0x000014ec, 0x00040047, 0x00000067, 0x00000001, 0x00000000, 0x00040047, 0x00000068, 0x00000001, - 0x00000001, 0x00040047, 0x00000069, 0x00000001, 0x00000002, 0x00040047, 0x0000006a, 0x0000000b, + 0x00000020, 0x00050048, 0x00000017, 0x00000002, 0x00000023, 0x00000028, 0x00040047, 0x00000038, + 0x00000006, 0x00000004, 0x00030047, 0x00000039, 0x00000002, 0x00050048, 0x00000039, 0x00000000, + 0x00000023, 0x00000000, 0x00040047, 0x00000045, 0x00000006, 0x00000008, 0x00030047, 0x00000046, + 0x00000002, 0x00050048, 0x00000046, 0x00000000, 0x00000023, 0x00000000, 0x00030047, 0x00000048, + 0x000014ec, 0x00040047, 0x0000006b, 0x00000001, 0x00000000, 0x00040047, 0x0000006c, 0x00000001, + 0x00000001, 0x00040047, 0x0000006d, 0x00000001, 0x00000002, 0x00040047, 0x0000006e, 0x0000000b, 0x00000019, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00040015, 0x00000006, 0x00000020, 0x00000000, 0x00040020, 0x00000007, 0x00000007, 0x00000006, 0x00040017, 0x00000009, 0x00000006, 0x00000003, 0x00040020, 0x0000000a, 0x00000001, 0x00000009, 0x0004003b, 0x0000000a, @@ -220,54 +229,56 @@ pub(crate) const WIDE: [u32; 691] = [ 0x0000001a, 0x0000001c, 0x00000001, 0x00040020, 0x0000001d, 0x00000009, 0x00000006, 0x00020014, 0x00000020, 0x00040020, 0x00000026, 0x00000007, 0x0000001a, 0x0004002b, 0x0000001a, 0x0000002e, 0x0000000b, 0x0004002b, 0x0000001a, 0x00000030, 0x00000002, 0x00040020, 0x00000032, 0x00000009, - 0x00000014, 0x00030027, 0x00000035, 0x000014e5, 0x0003001d, 0x00000036, 0x00000006, 0x0003001e, - 0x00000037, 0x00000036, 0x00040020, 0x00000035, 0x000014e5, 0x00000037, 0x00040020, 0x0000003a, - 0x000014e5, 0x00000006, 0x00030027, 0x00000041, 0x000014e5, 0x0004002b, 0x00000006, 0x00000042, - 0x00000005, 0x0004001c, 0x00000043, 0x00000014, 0x00000042, 0x0003001e, 0x00000044, 0x00000043, - 0x00040020, 0x00000041, 0x000014e5, 0x00000044, 0x00040020, 0x00000045, 0x00000007, 0x00000041, - 0x0004002b, 0x0000001a, 0x00000051, 0x00000004, 0x00040020, 0x00000055, 0x000014e5, 0x00000014, - 0x00040032, 0x00000006, 0x00000067, 0x00000001, 0x00040032, 0x00000006, 0x00000068, 0x00000001, - 0x00040032, 0x00000006, 0x00000069, 0x00000001, 0x00060033, 0x00000009, 0x0000006a, 0x00000067, - 0x00000068, 0x00000069, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, - 0x00000005, 0x0004003b, 0x00000007, 0x00000008, 0x00000007, 0x0004003b, 0x00000007, 0x00000025, - 0x00000007, 0x0004003b, 0x00000026, 0x00000027, 0x00000007, 0x0004003b, 0x00000045, 0x00000046, - 0x00000007, 0x0004003b, 0x00000026, 0x0000004a, 0x00000007, 0x00050041, 0x0000000d, 0x0000000e, - 0x0000000b, 0x0000000c, 0x0004003d, 0x00000006, 0x0000000f, 0x0000000e, 0x0003003e, 0x00000008, - 0x0000000f, 0x0004003d, 0x00000006, 0x00000010, 0x00000008, 0x00070041, 0x0000001d, 0x0000001e, - 0x00000019, 0x0000001b, 0x0000001c, 0x0000000c, 0x0004003d, 0x00000006, 0x0000001f, 0x0000001e, - 0x000500ae, 0x00000020, 0x00000021, 0x00000010, 0x0000001f, 0x000300f7, 0x00000023, 0x00000000, - 0x000400fa, 0x00000021, 0x00000022, 0x00000023, 0x000200f8, 0x00000022, 0x000100fd, 0x000200f8, - 0x00000023, 0x0003003e, 0x00000025, 0x0000000c, 0x0003003e, 0x00000027, 0x0000001b, 0x000200f9, - 0x00000028, 0x000200f8, 0x00000028, 0x000400f6, 0x0000002a, 0x0000002b, 0x00000000, 0x000200f9, - 0x0000002c, 0x000200f8, 0x0000002c, 0x0004003d, 0x0000001a, 0x0000002d, 0x00000027, 0x000500b1, - 0x00000020, 0x0000002f, 0x0000002d, 0x0000002e, 0x000400fa, 0x0000002f, 0x00000029, 0x0000002a, - 0x000200f8, 0x00000029, 0x0004003d, 0x0000001a, 0x00000031, 0x00000027, 0x00060041, 0x00000032, - 0x00000033, 0x00000019, 0x00000030, 0x00000031, 0x0004003d, 0x00000014, 0x00000034, 0x00000033, - 0x00040078, 0x00000035, 0x00000038, 0x00000034, 0x0004003d, 0x00000006, 0x00000039, 0x00000008, - 0x00060041, 0x0000003a, 0x0000003b, 0x00000038, 0x0000001b, 0x00000039, 0x0006003d, 0x00000006, - 0x0000003c, 0x0000003b, 0x00000002, 0x00000004, 0x0004003d, 0x00000006, 0x0000003d, 0x00000025, - 0x00050080, 0x00000006, 0x0000003e, 0x0000003d, 0x0000003c, 0x0003003e, 0x00000025, 0x0000003e, - 0x000200f9, 0x0000002b, 0x000200f8, 0x0000002b, 0x0004003d, 0x0000001a, 0x0000003f, 0x00000027, - 0x00050080, 0x0000001a, 0x00000040, 0x0000003f, 0x0000001c, 0x0003003e, 0x00000027, 0x00000040, - 0x000200f9, 0x00000028, 0x000200f8, 0x0000002a, 0x00050041, 0x00000032, 0x00000047, 0x00000019, - 0x0000001c, 0x0004003d, 0x00000014, 0x00000048, 0x00000047, 0x00040078, 0x00000041, 0x00000049, - 0x00000048, 0x0003003e, 0x00000046, 0x00000049, 0x0003003e, 0x0000004a, 0x0000001b, 0x000200f9, - 0x0000004b, 0x000200f8, 0x0000004b, 0x000400f6, 0x0000004d, 0x0000004e, 0x00000000, 0x000200f9, - 0x0000004f, 0x000200f8, 0x0000004f, 0x0004003d, 0x0000001a, 0x00000050, 0x0000004a, 0x000500b1, - 0x00000020, 0x00000052, 0x00000050, 0x00000051, 0x000400fa, 0x00000052, 0x0000004c, 0x0000004d, - 0x000200f8, 0x0000004c, 0x0004003d, 0x00000041, 0x00000053, 0x00000046, 0x0004003d, 0x0000001a, - 0x00000054, 0x0000004a, 0x00060041, 0x00000055, 0x00000056, 0x00000053, 0x0000001b, 0x00000054, - 0x0006003d, 0x00000014, 0x00000057, 0x00000056, 0x00000002, 0x00000008, 0x00040078, 0x00000035, - 0x00000058, 0x00000057, 0x0004003d, 0x00000006, 0x00000059, 0x00000008, 0x00060041, 0x0000003a, - 0x0000005a, 0x00000058, 0x0000001b, 0x00000059, 0x0006003d, 0x00000006, 0x0000005b, 0x0000005a, - 0x00000002, 0x00000004, 0x0004003d, 0x00000006, 0x0000005c, 0x00000025, 0x00050080, 0x00000006, - 0x0000005d, 0x0000005c, 0x0000005b, 0x0003003e, 0x00000025, 0x0000005d, 0x000200f9, 0x0000004e, - 0x000200f8, 0x0000004e, 0x0004003d, 0x0000001a, 0x0000005e, 0x0000004a, 0x00050080, 0x0000001a, - 0x0000005f, 0x0000005e, 0x0000001c, 0x0003003e, 0x0000004a, 0x0000005f, 0x000200f9, 0x0000004b, - 0x000200f8, 0x0000004d, 0x0004003d, 0x00000041, 0x00000060, 0x00000046, 0x00060041, 0x00000055, - 0x00000061, 0x00000060, 0x0000001b, 0x00000051, 0x0006003d, 0x00000014, 0x00000062, 0x00000061, - 0x00000002, 0x00000008, 0x00040078, 0x00000035, 0x00000063, 0x00000062, 0x0004003d, 0x00000006, - 0x00000064, 0x00000008, 0x0004003d, 0x00000006, 0x00000065, 0x00000025, 0x00060041, 0x0000003a, - 0x00000066, 0x00000063, 0x0000001b, 0x00000064, 0x0005003e, 0x00000066, 0x00000065, 0x00000002, - 0x00000004, 0x000100fd, 0x00010038, + 0x00000014, 0x0005002b, 0x00000014, 0x00000035, 0x80000000, 0x00000000, 0x00030027, 0x00000037, + 0x000014e5, 0x0003001d, 0x00000038, 0x00000006, 0x0003001e, 0x00000039, 0x00000038, 0x00040020, + 0x00000037, 0x000014e5, 0x00000039, 0x00040020, 0x0000003c, 0x000014e5, 0x00000006, 0x00030027, + 0x00000043, 0x000014e5, 0x0004002b, 0x00000006, 0x00000044, 0x00000005, 0x0004001c, 0x00000045, + 0x00000014, 0x00000044, 0x0003001e, 0x00000046, 0x00000045, 0x00040020, 0x00000043, 0x000014e5, + 0x00000046, 0x00040020, 0x00000047, 0x00000007, 0x00000043, 0x0004002b, 0x0000001a, 0x00000053, + 0x00000004, 0x00040020, 0x00000057, 0x000014e5, 0x00000014, 0x00040032, 0x00000006, 0x0000006b, + 0x00000001, 0x00040032, 0x00000006, 0x0000006c, 0x00000001, 0x00040032, 0x00000006, 0x0000006d, + 0x00000001, 0x00060033, 0x00000009, 0x0000006e, 0x0000006b, 0x0000006c, 0x0000006d, 0x00050036, + 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x0004003b, 0x00000007, + 0x00000008, 0x00000007, 0x0004003b, 0x00000007, 0x00000025, 0x00000007, 0x0004003b, 0x00000026, + 0x00000027, 0x00000007, 0x0004003b, 0x00000047, 0x00000048, 0x00000007, 0x0004003b, 0x00000026, + 0x0000004c, 0x00000007, 0x00050041, 0x0000000d, 0x0000000e, 0x0000000b, 0x0000000c, 0x0004003d, + 0x00000006, 0x0000000f, 0x0000000e, 0x0003003e, 0x00000008, 0x0000000f, 0x0004003d, 0x00000006, + 0x00000010, 0x00000008, 0x00070041, 0x0000001d, 0x0000001e, 0x00000019, 0x0000001b, 0x0000001c, + 0x0000000c, 0x0004003d, 0x00000006, 0x0000001f, 0x0000001e, 0x000500ae, 0x00000020, 0x00000021, + 0x00000010, 0x0000001f, 0x000300f7, 0x00000023, 0x00000000, 0x000400fa, 0x00000021, 0x00000022, + 0x00000023, 0x000200f8, 0x00000022, 0x000100fd, 0x000200f8, 0x00000023, 0x0003003e, 0x00000025, + 0x0000000c, 0x0003003e, 0x00000027, 0x0000001b, 0x000200f9, 0x00000028, 0x000200f8, 0x00000028, + 0x000400f6, 0x0000002a, 0x0000002b, 0x00000000, 0x000200f9, 0x0000002c, 0x000200f8, 0x0000002c, + 0x0004003d, 0x0000001a, 0x0000002d, 0x00000027, 0x000500b1, 0x00000020, 0x0000002f, 0x0000002d, + 0x0000002e, 0x000400fa, 0x0000002f, 0x00000029, 0x0000002a, 0x000200f8, 0x00000029, 0x0004003d, + 0x0000001a, 0x00000031, 0x00000027, 0x00060041, 0x00000032, 0x00000033, 0x00000019, 0x00000030, + 0x00000031, 0x0004003d, 0x00000014, 0x00000034, 0x00000033, 0x00050080, 0x00000014, 0x00000036, + 0x00000034, 0x00000035, 0x00040078, 0x00000037, 0x0000003a, 0x00000036, 0x0004003d, 0x00000006, + 0x0000003b, 0x00000008, 0x00060041, 0x0000003c, 0x0000003d, 0x0000003a, 0x0000001b, 0x0000003b, + 0x0006003d, 0x00000006, 0x0000003e, 0x0000003d, 0x00000002, 0x00000004, 0x0004003d, 0x00000006, + 0x0000003f, 0x00000025, 0x00050080, 0x00000006, 0x00000040, 0x0000003f, 0x0000003e, 0x0003003e, + 0x00000025, 0x00000040, 0x000200f9, 0x0000002b, 0x000200f8, 0x0000002b, 0x0004003d, 0x0000001a, + 0x00000041, 0x00000027, 0x00050080, 0x0000001a, 0x00000042, 0x00000041, 0x0000001c, 0x0003003e, + 0x00000027, 0x00000042, 0x000200f9, 0x00000028, 0x000200f8, 0x0000002a, 0x00050041, 0x00000032, + 0x00000049, 0x00000019, 0x0000001c, 0x0004003d, 0x00000014, 0x0000004a, 0x00000049, 0x00040078, + 0x00000043, 0x0000004b, 0x0000004a, 0x0003003e, 0x00000048, 0x0000004b, 0x0003003e, 0x0000004c, + 0x0000001b, 0x000200f9, 0x0000004d, 0x000200f8, 0x0000004d, 0x000400f6, 0x0000004f, 0x00000050, + 0x00000000, 0x000200f9, 0x00000051, 0x000200f8, 0x00000051, 0x0004003d, 0x0000001a, 0x00000052, + 0x0000004c, 0x000500b1, 0x00000020, 0x00000054, 0x00000052, 0x00000053, 0x000400fa, 0x00000054, + 0x0000004e, 0x0000004f, 0x000200f8, 0x0000004e, 0x0004003d, 0x00000043, 0x00000055, 0x00000048, + 0x0004003d, 0x0000001a, 0x00000056, 0x0000004c, 0x00060041, 0x00000057, 0x00000058, 0x00000055, + 0x0000001b, 0x00000056, 0x0006003d, 0x00000014, 0x00000059, 0x00000058, 0x00000002, 0x00000008, + 0x00050080, 0x00000014, 0x0000005a, 0x00000059, 0x00000035, 0x00040078, 0x00000037, 0x0000005b, + 0x0000005a, 0x0004003d, 0x00000006, 0x0000005c, 0x00000008, 0x00060041, 0x0000003c, 0x0000005d, + 0x0000005b, 0x0000001b, 0x0000005c, 0x0006003d, 0x00000006, 0x0000005e, 0x0000005d, 0x00000002, + 0x00000004, 0x0004003d, 0x00000006, 0x0000005f, 0x00000025, 0x00050080, 0x00000006, 0x00000060, + 0x0000005f, 0x0000005e, 0x0003003e, 0x00000025, 0x00000060, 0x000200f9, 0x00000050, 0x000200f8, + 0x00000050, 0x0004003d, 0x0000001a, 0x00000061, 0x0000004c, 0x00050080, 0x0000001a, 0x00000062, + 0x00000061, 0x0000001c, 0x0003003e, 0x0000004c, 0x00000062, 0x000200f9, 0x0000004d, 0x000200f8, + 0x0000004f, 0x0004003d, 0x00000043, 0x00000063, 0x00000048, 0x00060041, 0x00000057, 0x00000064, + 0x00000063, 0x0000001b, 0x00000053, 0x0006003d, 0x00000014, 0x00000065, 0x00000064, 0x00000002, + 0x00000008, 0x00050080, 0x00000014, 0x00000066, 0x00000065, 0x00000035, 0x00040078, 0x00000037, + 0x00000067, 0x00000066, 0x0004003d, 0x00000006, 0x00000068, 0x00000008, 0x0004003d, 0x00000006, + 0x00000069, 0x00000025, 0x00060041, 0x0000003c, 0x0000006a, 0x00000067, 0x0000001b, 0x00000068, + 0x0005003e, 0x0000006a, 0x00000069, 0x00000002, 0x00000004, 0x000100fd, 0x00010038, ]; diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 1bd00ccfe..94fbe224e 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -62,7 +62,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 2186; +pub const SEMANTICS_VERSION: u32 = 2188; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -72,7 +72,7 @@ pub const SEMANTICS_VERSION: u32 = 2186; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 544; +pub const ARTIFACT_FORMAT_VERSION: u32 = 546; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle diff --git a/crates/metal2vulkan/src/lower/access/dynamic.rs b/crates/metal2vulkan/src/lower/access/dynamic.rs index a252358ba..7f8bc91d2 100644 --- a/crates/metal2vulkan/src/lower/access/dynamic.rs +++ b/crates/metal2vulkan/src/lower/access/dynamic.rs @@ -1329,8 +1329,7 @@ pub(super) fn static_guest_address( crate::pipeline::interface::Window::Bounded { start, .. } => start, crate::pipeline::interface::Window::Whole => 0, }; - let base = cx.push_field(fb, PushField::SlotGuestBase(choice.slot))?; - let base = super::pointer::slot_guest_base_u64(fb, base)?; + let base = super::pointer::slot_address(cx, fb, choice.slot)?; let disp = super::psb::displacement(fb, m, start)?; let guest = fb.binary(BinOp::IAdd, base, disp)?; let r = k32(fb, t.root)?; diff --git a/crates/metal2vulkan/src/lower/access/emit.rs b/crates/metal2vulkan/src/lower/access/emit.rs index e93810ce6..d76848fb6 100644 --- a/crates/metal2vulkan/src/lower/access/emit.rs +++ b/crates/metal2vulkan/src/lower/access/emit.rs @@ -275,15 +275,20 @@ pub(super) fn prepare( let ops = WordOps::of(crate::lower::sync::memory_model::coherence(cx.plan)); if let Some(SlotLowering::Psb { start }) = lowering { // Under the identity domains a slot whose address the binder holds to its argument's - // alignment is reached from that address as it is, with `uvec2` and `uvec4` units at - // offsets proven multiples of their size; any other from the word below each access. + // alignment is reached from that address as it is (its biased word), with `uvec2` and + // `uvec4` units at offsets proven multiples of their size; any other from the word below + // each access. let aligned = cx.plan.families.access.aligned.contains(&t.slot); let a = if cx.plan.families.access.identity { - let address = cx.push_field(fb, PushField::SlotGuestBase(choice.slot))?; - let address = super::pointer::slot_guest_base_u64(fb, address)?; match aligned { - true => psb::prepare_direct(address, m), - false => psb::prepare_at(fb, address, m, start)?, + true => { + let base = super::pointer::biased_slot_address(cx, fb, choice.slot)?; + psb::prepare_direct(base, m) + } + false => { + let address = super::pointer::slot_address(cx, fb, choice.slot)?; + psb::prepare_at(fb, address, m, start)? + } } } else { let table = cx.push_field(fb, PushField::RootTableAddress)?; diff --git a/crates/metal2vulkan/src/lower/access/mod.rs b/crates/metal2vulkan/src/lower/access/mod.rs index 3fe490848..b3718a746 100644 --- a/crates/metal2vulkan/src/lower/access/mod.rs +++ b/crates/metal2vulkan/src/lower/access/mod.rs @@ -1306,12 +1306,19 @@ impl Census { } /// The field a slot's device address is read from under the identity domains: its Metal address, -/// the bound buffer's `gpuAddress` plus the bind offset, which is its Vulkan device address there -/// (`SlotGuestBase`'s value, a `uvec2`, low word first). +/// the bound buffer's `gpuAddress` plus the bind offset, which is its Vulkan device address there, +/// less [`SLOT_ADDRESS_BIAS`] (`SlotGuestBase`'s value, a `uvec2`, low word first). fn address_field(slot: SlotRef) -> PushField { PushField::SlotGuestBase(slot) } +/// The bias of a buffer slot's `SlotGuestBase` word under the identity domains, 2^31: the runtime +/// pushes the slot's address less it. An access adds its 32-bit byte offset plus the bias to the +/// word, zero-extended ([`psb::prepare_direct`]), which is the address plus the offset read as +/// signed in one 32-bit add, and every other read of the word adds the bias back +/// ([`pointer::slot_address`]). +pub(crate) const SLOT_ADDRESS_BIAS: u64 = 1 << 31; + /// Whether profile `p` takes the identity domains, where a pointer is a device address used /// directly. pub(crate) fn identity(p: &DeviceProfile) -> bool { diff --git a/crates/metal2vulkan/src/lower/access/pointer.rs b/crates/metal2vulkan/src/lower/access/pointer.rs index 6febe4d16..3ddef8b2b 100644 --- a/crates/metal2vulkan/src/lower/access/pointer.rs +++ b/crates/metal2vulkan/src/lower/access/pointer.rs @@ -750,22 +750,39 @@ fn displacement( )?)) } -/// `SlotGuestBase(slot)` (a `uvec2` push field) in the address form. +/// Buffer slot `slot`'s Metal address ([`slot_address`]) in the address form. fn guest_base( cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, slot: SlotRef, words: bool, ) -> BResult
{ - let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?; - if words { - return Ok(Address::Words(wide::split(fb, v)?)); + if !words { + return Ok(Address::U64(slot_address(cx, fb, slot)?)); } - Ok(Address::U64(slot_guest_base_u64(fb, v)?)) + let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?; + let word = wide::split(fb, v)?; + if !biased(cx) { + return Ok(Address::Words(word)); + } + let bias = Pair { + lo: k32(fb, super::SLOT_ADDRESS_BIAS as u32)?, + hi: k32(fb, 0)?, + }; + Ok(Address::Words(wide::add(fb, word, bias)?)) } -/// A `SlotGuestBase` field's value (a `uvec2`, low word first) as a `u64` (needs `shaderInt64`). -pub(super) fn slot_guest_base_u64(fb: &mut FunctionBuilder<'_>, v: SValue) -> BResult { +/// Whether buffer slots' `SlotGuestBase` words are their Metal addresses less +/// [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS): under the identity domains, where the runtime +/// pushes them. A replay variant reads each slot's address itself from its root entry. +fn biased(cx: &EmitCx<'_>) -> bool { + cx.plan.families.access.identity && !cx.plan.families.access.replay +} + +/// Buffer slot `slot`'s `SlotGuestBase` word (a `uvec2`, low word first) as a `u64` (needs +/// `shaderInt64`). +fn slot_word(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, slot: SlotRef) -> BResult { + let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?; let u64_ = fb.module().ty(SType::Int { width: 64, signed: false, @@ -773,6 +790,39 @@ pub(super) fn slot_guest_base_u64(fb: &mut FunctionBuilder<'_>, v: SValue) -> BR fb.convert(ConvOp::Bitcast, v, u64_) } +/// Buffer slot `slot`'s Metal address, the bound buffer's `gpuAddress` plus the bind offset, as a +/// `u64` (needs `shaderInt64`): its `SlotGuestBase` word, plus +/// [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS) where the word is biased ([`biased`]). What a +/// pointer compare, a converted or stored pointer, and an access from the word below it read. +pub(super) fn slot_address( + cx: &mut EmitCx<'_>, + fb: &mut FunctionBuilder<'_>, + slot: SlotRef, +) -> BResult { + let word = slot_word(cx, fb, slot)?; + if !biased(cx) { + return Ok(word); + } + let bias = k64(fb, super::SLOT_ADDRESS_BIAS)?; + fb.binary(BinOp::IAdd, word, bias) +} + +/// Buffer slot `slot`'s Metal address less [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS), a +/// `u64`: its `SlotGuestBase` word where the word is biased ([`biased`]), the base an access +/// reached from the slot's own address adds its biased offset to (`psb::prepare_direct`). +pub(super) fn biased_slot_address( + cx: &mut EmitCx<'_>, + fb: &mut FunctionBuilder<'_>, + slot: SlotRef, +) -> BResult { + let word = slot_word(cx, fb, slot)?; + if biased(cx) { + return Ok(word); + } + let bias = k64(fb, super::SLOT_ADDRESS_BIAS)?; + fb.binary(BinOp::ISub, word, bias) +} + /// The start of the 2³² bytes a pointer into plan slot `slot` whose offset range the analysis /// does not bound is taken to lie in. 0 when the slot's window lies in the binding's first 2³² /// bytes (`Whole`, or `Bounded` within them): that span holds every pointer an access of the diff --git a/crates/metal2vulkan/src/lower/access/psb.rs b/crates/metal2vulkan/src/lower/access/psb.rs index 05e306cf7..5cec10373 100644 --- a/crates/metal2vulkan/src/lower/access/psb.rs +++ b/crates/metal2vulkan/src/lower/access/psb.rs @@ -31,8 +31,9 @@ //! storage class as they cover `StorageBuffer`. A sub-word store there is one narrow store; without //! the access it stays the two word atomics ([`PsbMem`]'s `write_bits`). +use super::SLOT_ADDRESS_BIAS; use crate::device::DeviceProfile; -use crate::memory::leaf::{Units, WordMem, WordOps}; +use crate::memory::leaf::{k32, u32_op, Units, WordMem, WordOps}; use crate::spirv::builder::FunctionBuilder; use crate::spirv::error::BResult; use crate::spirv::ids::{TypeId, Value}; @@ -176,14 +177,18 @@ enum Reach { /// making no buffer longer than 2 GiB (`metal2vulkan_rt::MAX_BUFFER_LENGTH`), so the product is /// exact, and no 64-bit shift or multiply scales an index. Below, - /// From a slot's own device address under the identity domains ([`prepare_direct`]): each - /// unit at that address plus its 32-bit byte offset sign-extended, in 64-bit integers, then - /// one `OpConvertUToPtr` to the unit's block (`NonWritable` for a load of an unwritten slot). + /// From a slot's own device address under the identity domains ([`prepare_direct`]), held + /// as that address less [`SLOT_ADDRESS_BIAS`] (2^31): each unit at that base plus its 32-bit + /// byte offset plus 2^31, modulo 2^32, zero-extended, in 64-bit integers, then one + /// `OpConvertUToPtr` to the unit's block (`NonWritable` for a load of an unwritten slot). /// Every byte of a buffer lies within 2^31 bytes of each bind address in it, the runtime - /// making no buffer longer than 2 GiB (`metal2vulkan_rt::MAX_BUFFER_LENGTH`), so the sign - /// extension is exact. It is the integer form of an access chain's signed index, which a device adds as - /// it would that index: no shift of the offset in 64 bits, no zero-extended offset to split - /// into a scalar base and a vector one, and no pointer bitcast. + /// making no buffer longer than 2 GiB (`metal2vulkan_rt::MAX_BUFFER_LENGTH`), so the offset + /// read as signed is in `[-2^31, 2^31)`, the biased one is that offset plus 2^31 exactly, and + /// the sum is the address plus the offset. A unit index `x + c` with a constant `c` folds + /// `c`'s bytes into the bias: `(x + c) * s + 2^31` is `x * s + (c * s + 2^31)` modulo 2^32. + /// The bias is one 32-bit add, which a device fuses with the index's shift; the offset is + /// zero-extended, which a device splits into a scalar base and a vector offset; no shift of + /// the offset in 64 bits and no pointer bitcast. Direct, } @@ -219,18 +224,18 @@ pub fn prepare_at( } /// Prepare an access of a static slot at the `u32` displacement `m` from its bind offset, under -/// the identity domains, from `address` (a `u64`), the slot's own device address, which the -/// binder holds to a multiple of the argument's alignment (`RuntimeFact::AddressAlignment`): the -/// access is the byte offset `m`, read as signed, from `address`, as a descriptor view's is `m` -/// from its base. Every byte of a buffer lies within 2^31 bytes of each bind address in it, the -/// runtime making no buffer longer than 2 GiB (`metal2vulkan_rt::MAX_BUFFER_LENGTH`), so the -/// offset is exact whatever the slot's window. Nothing is rounded, so a constant offset is one -/// immediate. Uncontained, as Metal contains no device-address access. -pub fn prepare_direct(address: Value, m: Value) -> PsbAccess { +/// the identity domains, from `base` (a `u64`), the slot's own device address less +/// [`SLOT_ADDRESS_BIAS`], an address the binder holds to a multiple of the argument's alignment +/// (`RuntimeFact::AddressAlignment`): the access is the byte offset `m`, read as signed, from that +/// address, as a descriptor view's is `m` from its base ([`Reach::Direct`]). Every byte of a +/// buffer lies within 2^31 bytes of each bind address in it, the runtime making no buffer longer +/// than 2 GiB (`metal2vulkan_rt::MAX_BUFFER_LENGTH`), so the offset is exact whatever the slot's +/// window. Nothing is rounded. Uncontained, as Metal contains no device-address access. +pub fn prepare_direct(base: Value, m: Value) -> PsbAccess { PsbAccess { mem: PsbMem { reach: Reach::Direct, - ..PsbMem::at(address) + ..PsbMem::at(base) }, off: m, inb: None, @@ -338,15 +343,24 @@ impl PsbMem { let addr = fb.binary(BinOp::IAdd, self.base, d)?; self.place(fb, addr, ty, load) } - Reach::Below | Reach::Direct => { - let shift = crate::memory::leaf::k32(fb, bytes.trailing_zeros())?; - let at = crate::memory::leaf::u32_op(fb, BinOp::ShiftLeftLogical, index, shift)?; + Reach::Below => { + let shift = k32(fb, bytes.trailing_zeros())?; + let at = u32_op(fb, BinOp::ShiftLeftLogical, index, shift)?; let u64_ = u64_ty(fb)?; - let widen = match self.reach { - Reach::Direct => ConvOp::SConvert, - _ => ConvOp::UConvert, - }; - let d = fb.convert(widen, at, u64_)?; + let d = fb.convert(ConvOp::UConvert, at, u64_)?; + let addr = fb.binary(BinOp::IAdd, self.base, d)?; + self.place(fb, addr, ty, load) + } + Reach::Direct => { + let shift = bytes.trailing_zeros(); + let (x, c) = fb.sum_of(index).unwrap_or((index, 0)); + let s = k32(fb, shift)?; + let at = u32_op(fb, BinOp::ShiftLeftLogical, x, s)?; + let bias = (c << shift).wrapping_add(SLOT_ADDRESS_BIAS as u32); + let bias = k32(fb, bias)?; + let at = u32_op(fb, BinOp::IAdd, at, bias)?; + let u64_ = u64_ty(fb)?; + let d = fb.convert(ConvOp::UConvert, at, u64_)?; let addr = fb.binary(BinOp::IAdd, self.base, d)?; self.place(fb, addr, ty, load) } diff --git a/crates/metal2vulkan/src/lower/access/pulled.rs b/crates/metal2vulkan/src/lower/access/pulled.rs index e9a2f94f7..80ad3b560 100644 --- a/crates/metal2vulkan/src/lower/access/pulled.rs +++ b/crates/metal2vulkan/src/lower/access/pulled.rs @@ -409,8 +409,7 @@ fn source(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, buffer: u32) -> BRe Ok(Source::View { view, residual }) } (Some(SlotLowering::Psb { start }), _) if identity => { - let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?; - let address = super::pointer::slot_guest_base_u64(fb, v)?; + let address = super::pointer::slot_address(cx, fb, slot)?; Ok(Source::Address { address, start }) } (Some(SlotLowering::Psb { start }), _) => { diff --git a/crates/metal2vulkan/src/memory/leaf.rs b/crates/metal2vulkan/src/memory/leaf.rs index 4afa06c63..2d7e904ce 100644 --- a/crates/metal2vulkan/src/memory/leaf.rs +++ b/crates/metal2vulkan/src/memory/leaf.rs @@ -636,6 +636,14 @@ pub fn u32_op(fb: &mut FunctionBuilder<'_>, op: BinOp, a: Value, b: Value) -> BR (BinOp::IMul, Some(1), _) | (BinOp::BitwiseAnd, Some(u32::MAX), _) => Ok(b), (BinOp::IMul | BinOp::BitwiseAnd, Some(0), _) | (BinOp::IMul | BinOp::BitwiseAnd, _, Some(0)) => k32(fb, 0), + // A sum of a value and a constant is noted, for a consumer that folds the constant + // (`psb`'s biased offsets). + (BinOp::IAdd, None, Some(c)) | (BinOp::IAdd, Some(c), None) => { + let x = if y.is_some() { a } else { b }; + let r = fb.binary(op, a, b)?; + fb.note_sum(r, x, c); + Ok(r) + } _ => fb.binary(op, a, b), } } diff --git a/crates/metal2vulkan/src/pipeline/sym.rs b/crates/metal2vulkan/src/pipeline/sym.rs index 42ab0db9f..229d4f29b 100644 --- a/crates/metal2vulkan/src/pipeline/sym.rs +++ b/crates/metal2vulkan/src/pipeline/sym.rs @@ -1097,8 +1097,9 @@ pub enum PushField { /// modulo 2^32. SlotBindOffset(SlotRef), /// Guest base address of a static-root slot. Under the identity domains, a `u64`: a buffer - /// slot's device address (its `gpuAddress` plus the bind offset), and a texture or sampler - /// slot's `gpuResourceID` (`docs/RESOURCE-ID.md`), 0 for nil. + /// slot's device address (its `gpuAddress` plus the bind offset) less 2^31, modulo 2^64 + /// (`docs/API.md`, section 5), and a texture or sampler slot's `gpuResourceID` + /// (`docs/RESOURCE-ID.md`), 0 for nil. SlotGuestBase(SlotRef), /// Stride of a pulled vertex buffer layout. VertexBufferStride(u32), diff --git a/crates/metal2vulkan/src/spirv/builder/function.rs b/crates/metal2vulkan/src/spirv/builder/function.rs index ae24f8dd0..840aa039c 100644 --- a/crates/metal2vulkan/src/spirv/builder/function.rs +++ b/crates/metal2vulkan/src/spirv/builder/function.rs @@ -134,6 +134,16 @@ impl<'m> FunctionBuilder<'m> { self.m.lanes.get(&y).copied() } + /// Note that `y`, a 32-bit unsigned integer, is `x + c` modulo 2^32: `x` dominates `y`. + pub fn note_sum(&mut self, y: Value, x: Value, c: u32) { + self.m.sums.insert(y, (x, c)); + } + + /// The value and constant `y` was noted to add. + pub fn sum_of(&self, y: Value) -> Option<(Value, u32)> { + self.m.sums.get(&y).copied() + } + /// Note that `y`, a 32-bit unsigned integer, is the zero extension of 16-bit integer `of`: /// `of` dominates `y`. pub fn note_widened16(&mut self, y: Value, of: Value) { diff --git a/crates/metal2vulkan/src/spirv/builder/module.rs b/crates/metal2vulkan/src/spirv/builder/module.rs index 64a0e1074..209c2b6f6 100644 --- a/crates/metal2vulkan/src/spirv/builder/module.rs +++ b/crates/metal2vulkan/src/spirv/builder/module.rs @@ -136,6 +136,9 @@ pub struct ModuleBuilder { /// The vector, lane value, and lane index of each narrow lane insert the lowering noted /// (`FunctionBuilder::note_insert`). pub(super) inserts: HashMap, + /// The value and constant each 32-bit unsigned sum of a value and a constant the lowering + /// noted adds (`FunctionBuilder::note_sum`). Nothing here changes the IR. + pub(super) sums: HashMap, /// How each struct the builder made holds its members, and what each extract from a struct /// reads (`FunctionBuilder::member_source`): every `OpCompositeConstruct` and /// `OpCompositeInsert` of a struct type and every `OpCompositeExtract` from one, by result. @@ -432,6 +435,7 @@ impl ModuleBuilder { + map_bytes(&self.bits) + map_bytes(&self.lanes) + map_bytes(&self.inserts) + + map_bytes(&self.sums) + map_bytes(&self.structs) + self.struct_bytes + map_bytes(&self.widened16) diff --git a/crates/metal2vulkan/src/tests/engine_identity.rs b/crates/metal2vulkan/src/tests/engine_identity.rs index f8732e2d0..2e632852e 100644 --- a/crates/metal2vulkan/src/tests/engine_identity.rs +++ b/crates/metal2vulkan/src/tests/engine_identity.rs @@ -79,6 +79,7 @@ use std::collections::{BTreeMap, BTreeSet}; use std::sync::atomic::{AtomicU64, Ordering}; +use super::engine_word_phases::slot_word; use crate::bind::{BindState, BoundBuffer, Dispatch, StageTable}; use crate::budget::Budget; use crate::device::profile::{DeviceProfile, HandleDomain, PointerDomain}; @@ -252,7 +253,7 @@ fn a_buffer_kernel_reads_each_slot_at_its_pushed_device_address() { match f.field { PushField::SlotGuestBase(s) => { let (base, bind) = at[s.index as usize]; - push[o..o + 8].copy_from_slice(&(base + bind).to_le_bytes()); + push[o..o + 8].copy_from_slice(&slot_word(base + bind).to_le_bytes()); read.push(s); } PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), @@ -291,6 +292,90 @@ fn a_buffer_kernel_reads_each_slot_at_its_pushed_device_address() { } } +/// A slot pointer used as a value under the identity domains is its Metal address, though the +/// runtime pushes each buffer slot's address less 2^31 (`lower::access::SLOT_ADDRESS_BIAS`): a +/// `ptrtoint` to `i64` and to `i32` and an address compare add the bias back, and the loads beside +/// them, one 4 bytes below its slot's bind address, add their offsets plus the bias to the word. +#[test] +fn a_slot_pointer_used_as_a_value_is_its_metal_address() { + use super::engine_pointer_memory::{assemble, kernel}; + let body = " %p = getelementptr inbounds i8, ptr addrspace(1) %b0, i64 20 + %a = ptrtoint ptr addrspace(1) %p to i64 + store i64 %a, ptr addrspace(1) %b2, align 8 + %a32 = ptrtoint ptr addrspace(1) %b1 to i32 + %o2 = getelementptr inbounds i32, ptr addrspace(1) %b2, i64 2 + store i32 %a32, ptr addrspace(1) %o2, align 4 + %lt = icmp ult ptr addrspace(1) %b0, %b1 + %z = zext i1 %lt to i32 + %o3 = getelementptr inbounds i32, ptr addrspace(1) %b2, i64 3 + store i32 %z, ptr addrspace(1) %o3, align 4 + %q = getelementptr inbounds i8, ptr addrspace(1) %b1, i64 -4 + %w = load i32, ptr addrspace(1) %q, align 4 + %o4 = getelementptr inbounds i32, ptr addrspace(1) %b2, i64 4 + store i32 %w, ptr addrspace(1) %o4, align 4 + %v = load i32, ptr addrspace(1) %p, align 4 + %o5 = getelementptr inbounds i32, ptr addrspace(1) %b2, i64 5 + store i32 %v, ptr addrspace(1) %o5, align 4 +"; + let name = "slot_values"; + let Some(bc) = assemble(name, &kernel(name, 3, body, "")) else { + return; + }; + // (the buffer's device address, the bind offset): above 4 GiB, so a dropped high word shows. + let at = [ + (0x1_0000_0000u64, 0u64), + (0x2_0000_1000, 16), + (0x3_0000_2000, 0), + ]; + let words = + |base: u32| -> Vec { (0..16u32).flat_map(|i| (base + i).to_le_bytes()).collect() }; + let bytes = [words(0x100), words(0x200), vec![0xEE; 28]]; + let slot_address = |i: usize| at[i].0 + at[i].1; + let mut want = slot_address(0).wrapping_add(20).to_le_bytes().to_vec(); + want.extend_from_slice(&(slot_address(1) as u32).to_le_bytes()); + want.extend_from_slice(&1u32.to_le_bytes()); + want.extend_from_slice(&bytes[1][12..16]); + want.extend_from_slice(&bytes[0][20..24]); + want.extend_from_slice(&[0xEE; 4]); + for stem in PROFILES { + let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}")); + let (a, plan, module) = + compile_kept(&bc, name, &p).unwrap_or_else(|e| panic!("{stem}: {e}")); + assert!(a.interface.descriptors.is_empty(), "{stem}"); + link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}")); + let mut push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)]; + let region = region_bytes([0; 3], [1, 1, 1], [1, 1, 1]).expect("packs"); + for f in &plan.push.fields { + let PushLoc::Push { offset } = f.loc else { + panic!("{stem}: {f:?} spilled"); + }; + let o = offset as usize; + match f.field { + PushField::SlotGuestBase(s) => { + let word = slot_word(slot_address(s.index as usize)); + push[o..o + 8].copy_from_slice(&word.to_le_bytes()); + } + PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), + _ => panic!("{stem}: unexpected push field {f:?}"), + } + } + let buffers = (0..3) + .map(|i| Buffer { + slot: None, + address: Some(at[i].0), + bytes: bytes[i].clone(), + }) + .collect(); + let res = Resources { + buffers, + push, + spec: local_size(1), + }; + let got = run(&module, &Config::default(), res).unwrap_or_else(|e| panic!("{stem}: {e}")); + assert_eq!(got.buffers[2], want, "{stem}: out"); + } +} + /// The harness's sampling kernels (`fixtures/public/harness/workloads.ll`, our own), assembled. fn workloads() -> Option> { let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) @@ -693,7 +778,7 @@ fn the_stage_in_region_is_read_from_its_pushed_field() { let o = offset as usize; match f.field { PushField::SlotGuestBase(s) if s == slot(0) => { - push[o..o + 8].copy_from_slice(&OUT.to_le_bytes()) + push[o..o + 8].copy_from_slice(&slot_word(OUT).to_le_bytes()) } PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), PushField::StageInRegion => push[o..o + 32].copy_from_slice(®ion_in), @@ -1035,9 +1120,11 @@ fn textures_at_their_resource_ids(ab: bool) { let o = offset as usize; let bytes = match field.field { PushField::SlotGuestBase(s) => match (ab, s.class, s.index) { - (false, SlotClass::Buffer, 0) | (true, SlotClass::Buffer, 1) => OUT, + (false, SlotClass::Buffer, 0) | (true, SlotClass::Buffer, 1) => { + slot_word(OUT) + } (false, SlotClass::Texture, i @ 0..=2) => ids[i as usize], - (true, SlotClass::Buffer, 0) => AB, + (true, SlotClass::Buffer, 0) => slot_word(AB), _ => panic!("{stem}: unexpected slot {s:?}"), }, PushField::DispatchRegion => { @@ -1192,11 +1279,19 @@ fn many_placed( } (PushField::SlotGuestBase(s), PushLoc::Push { offset }) => { pushed.push(s); - (BASE + u64::from(s.index) * STRIDE, &mut push, offset) + ( + slot_word(BASE + u64::from(s.index) * STRIDE), + &mut push, + offset, + ) } (PushField::SlotGuestBase(s), PushLoc::ArgumentTable { offset }) => { spilled.push(s); - (BASE + u64::from(s.index) * STRIDE, &mut block, offset) + ( + slot_word(BASE + u64::from(s.index) * STRIDE), + &mut block, + offset, + ) } other => panic!("{stem}: unexpected push field {other:?}"), }; @@ -1328,7 +1423,7 @@ fn grid_push(plan: &Plan, out: u64, region: [u8; 32]) -> Vec { let o = offset as usize; match f.field { PushField::SlotGuestBase(s) if s == slot(0) => { - push[o..o + 8].copy_from_slice(&out.to_le_bytes()) + push[o..o + 8].copy_from_slice(&slot_word(out).to_le_bytes()) } PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), _ => panic!("unexpected push field {f:?}"), @@ -2289,10 +2384,10 @@ fn the_emulated_tiers_barriers_run_only_in_a_threadgroup_of_several_threads() { let o = offset as usize; match f.field { PushField::SlotGuestBase(s) if s == slot(0) => { - push[o..o + 8].copy_from_slice(&INPUT.to_le_bytes()) + push[o..o + 8].copy_from_slice(&slot_word(INPUT).to_le_bytes()) } PushField::SlotGuestBase(s) if s == slot(1) => { - push[o..o + 8].copy_from_slice(&OUT.to_le_bytes()) + push[o..o + 8].copy_from_slice(&slot_word(OUT).to_le_bytes()) } PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), _ => panic!("unexpected push field {f:?}"), @@ -2479,7 +2574,8 @@ fn unwritten_slots_are_loaded_through_non_writable_places() { let o = offset as usize; match f.field { PushField::SlotGuestBase(s) => { - push[o..o + 8].copy_from_slice(&AT[s.index as usize].to_le_bytes()); + push[o..o + 8] + .copy_from_slice(&slot_word(AT[s.index as usize]).to_le_bytes()); } PushField::DispatchRegion => { let region = region_bytes([0; 3], [1, 1, 1], [1, 1, 1]).expect("packs"); diff --git a/crates/metal2vulkan/src/tests/engine_offsets_to_2gib.rs b/crates/metal2vulkan/src/tests/engine_offsets_to_2gib.rs index 8dfddc808..885d9b071 100644 --- a/crates/metal2vulkan/src/tests/engine_offsets_to_2gib.rs +++ b/crates/metal2vulkan/src/tests/engine_offsets_to_2gib.rs @@ -9,7 +9,7 @@ use std::collections::BTreeMap; -use super::engine_word_phases::identity_profiles; +use super::engine_word_phases::{identity_profiles, slot_word}; use crate::lower::dispatch::region_bytes; use crate::pipeline::interface::PushLoc; use crate::pipeline::sym::{Axis, PushField, SpecKey}; @@ -86,7 +86,7 @@ fn accesses_up_to_2_gib_land_at_their_own_words() { match f.field { PushField::SlotGuestBase(s) => { let address = if s.index == 0 { IDX } else { SLOT }; - push[o..o + 8].copy_from_slice(&address.to_le_bytes()); + push[o..o + 8].copy_from_slice(&slot_word(address).to_le_bytes()); } PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), _ => panic!("{stem}: unexpected push field {f:?}"), diff --git a/crates/metal2vulkan/src/tests/engine_pointer_memory.rs b/crates/metal2vulkan/src/tests/engine_pointer_memory.rs index 159004774..80a6333c2 100644 --- a/crates/metal2vulkan/src/tests/engine_pointer_memory.rs +++ b/crates/metal2vulkan/src/tests/engine_pointer_memory.rs @@ -93,7 +93,7 @@ fn profiles() -> Vec<(String, DeviceProfile)> { out } -fn assemble(name: &str, text: &str) -> Option> { +pub(super) fn assemble(name: &str, text: &str) -> Option> { static NEXT: AtomicU64 = AtomicU64::new(0); let dir = std::env::temp_dir().join(format!( "m2v-pointer-memory-{}-{}-{name}", @@ -140,7 +140,7 @@ fn meta(name: &str, buffers: u32) -> String { } /// A kernel `name(b0, .., b{buffers-1}, t)` with `body` and the declarations `decls`. -fn kernel(name: &str, buffers: u32, body: &str, decls: &str) -> String { +pub(super) fn kernel(name: &str, buffers: u32, body: &str, decls: &str) -> String { let params: Vec = (0..buffers) .map(|i| format!("ptr addrspace(1) noundef \"air-buffer-no-alias\" %b{i}")) .collect(); diff --git a/crates/metal2vulkan/src/tests/engine_simd_emulated.rs b/crates/metal2vulkan/src/tests/engine_simd_emulated.rs index e6651ff4b..96d5b035b 100644 --- a/crates/metal2vulkan/src/tests/engine_simd_emulated.rs +++ b/crates/metal2vulkan/src/tests/engine_simd_emulated.rs @@ -144,7 +144,11 @@ fn run_all( // Zero residuals: each buffer is bound at its start. PushField::SlotBindOffset(_) => {} PushField::SlotGuestBase(s) => { - push[o..o + 8].copy_from_slice(&guest_base(s.index).to_le_bytes()); + let word = match plan.families.access.identity { + true => super::engine_word_phases::slot_word(guest_base(s.index)), + false => guest_base(s.index), + }; + push[o..o + 8].copy_from_slice(&word.to_le_bytes()); addressed = true; } PushField::DispatchRegion => { diff --git a/crates/metal2vulkan/src/tests/engine_word_phases.rs b/crates/metal2vulkan/src/tests/engine_word_phases.rs index 3697e8926..4ed9450d4 100644 --- a/crates/metal2vulkan/src/tests/engine_word_phases.rs +++ b/crates/metal2vulkan/src/tests/engine_word_phases.rs @@ -57,6 +57,12 @@ fn bitcode() -> Option> { } } +/// The word the runtime pushes for a buffer slot's `SlotGuestBase` at `address` under the identity +/// domains: the address less 2^31 (`lower::access::SLOT_ADDRESS_BIAS`). +pub(super) fn slot_word(address: u64) -> u64 { + address.wrapping_sub(crate::lower::access::SLOT_ADDRESS_BIAS) +} + /// Every committed profile `Device::from_queries` derives under the identity domains (those with /// `bufferDeviceAddress` and `shaderInt64`), by stem. pub(super) fn identity_profiles() -> Vec<(String, DeviceProfile)> { @@ -266,7 +272,7 @@ fn dispatch( match f.field { PushField::SlotGuestBase(s) => { let (address, bind, _) = &buffers[s.index as usize]; - push[o..o + 8].copy_from_slice(&(address + bind).to_le_bytes()); + push[o..o + 8].copy_from_slice(&slot_word(address + bind).to_le_bytes()); } PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), _ => return Err(format!("unexpected push field {f:?}")), diff --git a/docs/API.md b/docs/API.md index e8bd295ac..7a8c32390 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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