From 201fcfe1f0af13403ba026405f5f73b1807fe8e8 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 11:27:49 -0800 Subject: [PATCH] The offset-0 class goes: no storage view declares RangeAtBindOffset since its workaround went PushReadsLengthenThreadPayload was the only reason a storage view declared SpecKey::RangeAtBindOffset, and lower::access now declares it for a uniform view alone. What told offset 0 apart for such a view had no reader left: StageTable::zero_offset_views, bind::ZERO_OFFSET_CLASS and ZERO_OFFSET_TOLD, PipelineInterface::storage_view_buffers, and the storage arms of range_at_bind_offset. No crate of ours or the consumer's names them (the runtime never set zero_offset_views). They go, with the test of the storage form, the offset class test's offset-0 half, the validation executor's line that set every slot's bit, and the API guide's paragraph. range_at_bind_offset answers false for a storage view: it reads at its residual. Verified: nothing yet; the gate follows. --- .../src/candidate/engine.rs | 9 +-- .../metal2vulkan/src/bind/graphics/tests.rs | 13 ---- crates/metal2vulkan/src/bind/mod.rs | 2 +- crates/metal2vulkan/src/bind/plan/slots.rs | 30 +++----- .../metal2vulkan/src/bind/plan/slots/tests.rs | 71 ------------------- crates/metal2vulkan/src/bind/state.rs | 45 ++---------- crates/metal2vulkan/src/pipeline/interface.rs | 1 - crates/metal2vulkan/src/pipeline/sym.rs | 9 +-- crates/metal2vulkan/tests/api_surface.rs | 2 - docs/API.md | 20 +----- 10 files changed, 21 insertions(+), 181 deletions(-) diff --git a/crates/metal2vulkan-validation/src/candidate/engine.rs b/crates/metal2vulkan-validation/src/candidate/engine.rs index e65b4a45d..f8ed5a251 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine.rs @@ -880,13 +880,7 @@ pub fn function_constants( /// view, and the plans of the two are the same. pub const VIEW_BASE_ALIGNMENT: u32 = 256; -/// `state` telling [`VIEW_BASE_ALIGNMENT`] apart at every buffer slot of each of its stages, and -/// offset 0 too (`StageTable::zero_offset_views`): on a profile that takes -/// `DriverWorkaround::PushReadsLengthenThreadPayload` a storage view bound at offset 0, as every -/// buffer the executor binds is, then reads at its bind offset alone in its plan, as in the -/// runtime's plan of the same binds, which tells offset 0 apart at the slots its pipeline reads -/// through a storage view there. Elsewhere no storage view declares the key, and a uniform view's -/// range starts at its bind offset at offset 0 under either class, so the plan is the same. Each +/// `state` telling [`VIEW_BASE_ALIGNMENT`] apart at every buffer slot of each of its stages. Each /// stage table classes its buffers' lengths under `ranges` (`StageTable::buffer_ranges`), the /// device's range limits (`BufferRanges::of`), as the runtime's tables class them, so a buffer's /// shape states the length class the runtime's shape of the same bind states. @@ -894,7 +888,6 @@ pub fn views_told_apart(mut state: BindState, ranges: BufferRanges) -> BindState state.view_base_alignment = VIEW_BASE_ALIGNMENT; for table in state.stages.values_mut() { table.at_bind_views = u64::MAX; - table.zero_offset_views = u64::MAX; table.buffer_ranges = ranges; } state diff --git a/crates/metal2vulkan/src/bind/graphics/tests.rs b/crates/metal2vulkan/src/bind/graphics/tests.rs index a2d9a22ed..e7128e507 100644 --- a/crates/metal2vulkan/src/bind/graphics/tests.rs +++ b/crates/metal2vulkan/src/bind/graphics/tests.rs @@ -387,19 +387,6 @@ fn fixed_function_fetches_only_what_vulkan_can_bind() { offsets.map(|o| offset_alignment(o, 64)), [64, 1, 2, 1, 4, 2, 4, 4, 64, 64, 64, 2] ); - // Where offset 0 is told apart, it alone takes its class, which the vertex fetch reads as any - // aligned offset's; every other offset classes as where nothing is told apart. - use crate::bind::{ZERO_OFFSET_CLASS, ZERO_OFFSET_TOLD}; - assert_eq!( - offsets.map(|o| offset_alignment(o, ZERO_OFFSET_TOLD)), - [ZERO_OFFSET_CLASS, 1, 2, 1, 4, 2, 4, 4, 4, 4, 4, 2] - ); - assert!(fetchable( - &first, - &rules(None, true), - ZERO_OFFSET_CLASS, - None - )); } /// An attribute's alignment is its component size (the whole word of a packed format) and the diff --git a/crates/metal2vulkan/src/bind/mod.rs b/crates/metal2vulkan/src/bind/mod.rs index 2557dbe36..8fa5c246b 100644 --- a/crates/metal2vulkan/src/bind/mod.rs +++ b/crates/metal2vulkan/src/bind/mod.rs @@ -303,7 +303,7 @@ pub use state::{ ResourceClass, SamplerDescriptor, SamplerShape, StageInRegion, StageShape, StageTable, TessellationFactorBuffer, TessellationFactors, TextureFacts, TextureShape, TileThreadgroupArgument, TileThreadgroupMemory, UsedClass, UsedResource, UsedShape, - VertexAmplification, ViewMapping, ZERO_OFFSET_CLASS, ZERO_OFFSET_TOLD, + VertexAmplification, ViewMapping, }; // How `BindState::shape` classes a buffer: the crate reads it from `state`, and a consumer takes // shapes from `BindState::shape`; only the crate's tests and validation reach it here. diff --git a/crates/metal2vulkan/src/bind/plan/slots.rs b/crates/metal2vulkan/src/bind/plan/slots.rs index 5c58fb44b..dd97acad1 100644 --- a/crates/metal2vulkan/src/bind/plan/slots.rs +++ b/crates/metal2vulkan/src/bind/plan/slots.rs @@ -164,37 +164,27 @@ pub(crate) fn plan_buffer( /// consumer's aligned upload; a buffer read through a uniform view, at an offset whose alignment /// class (`BufferShape::Buffer::offset_alignment`: `BindState::view_base_alignment` where the /// runtime tells it apart at the slot and it divides the offset, else a power of two up to 4) the -/// base alignment divides; a buffer read through a storage view, at offset 0 alone -/// (`bind::ZERO_OFFSET_CLASS`, where the runtime tells it apart at the slot): a storage view's -/// range starts at the buffer's start or its window's aligned first byte -/// (`instantiate::planned_range`), so its residual is 0 there and elsewhere the bind offset's share -/// of it, which keeps the bytes before the bind offset reachable as Metal's are. A slot bound to -/// nothing has the residual 0 (`instantiate::slot_field`), so either form reads the Metal offset -/// alone of the same descriptor: a uniform view's takes false, the form that reads at the -/// residual, which keeps the key of a draw that leaves the slot unbound the key that reads every -/// such slot at its residual; a storage view's takes what a bind at offset 0 takes, the -/// commonest bind, so that a plan of nothing bound, which a consumer makes before any draw binds -/// the slot (the runtime's creation, `pipeline/predicted.rs` and `pipeline/dispatch_making.rs`, -/// and a warm pass's replay of a dispatch, `pipeline/dispatch_record.rs`), names the key of the -/// draw that binds it there. +/// base alignment divides. A slot bound to nothing has the residual 0 +/// (`instantiate::slot_field`), so either form reads the Metal offset alone of the same +/// descriptor: it takes false, the form that reads at the residual, which keeps the key of a draw +/// that leaves the slot unbound the key that reads every such slot at its residual. Only a uniform +/// view declares the key (`lower::access`); a storage view's range starts at the buffer's start or +/// its window's aligned first byte (`instantiate::planned_range`), read at its residual, so it +/// takes false too. pub(crate) fn range_at_bind_offset( b: &BufferSlot, shape: Option<&BufferShape>, limits: &Limits, ) -> bool { + if !b.form.uniform_view() { + return false; + } let (min, _) = b.form.view_limits(limits); let offset = match shape { - // A storage view's range starts at its bind offset only where that is the buffer's start. - Some(&BufferShape::Buffer { - offset_alignment: crate::bind::ZERO_OFFSET_CLASS, - .. - }) if !b.form.uniform_view() => 0, - Some(BufferShape::Buffer { .. }) if !b.form.uniform_view() => return false, Some(&BufferShape::Buffer { offset_alignment, .. }) => u64::from(offset_alignment), Some(BufferShape::Bytes { .. }) => 0, - None if !b.form.uniform_view() => 0, None => return false, }; let alignment = crate::memory::views::base_alignment(min); diff --git a/crates/metal2vulkan/src/bind/plan/slots/tests.rs b/crates/metal2vulkan/src/bind/plan/slots/tests.rs index 13c788770..5b6a2e76f 100644 --- a/crates/metal2vulkan/src/bind/plan/slots/tests.rs +++ b/crates/metal2vulkan/src/bind/plan/slots/tests.rs @@ -637,77 +637,6 @@ fn a_uniform_range_starts_at_the_bind_offset_where_the_specialization_says() { } } -/// A storage view's `RangeAtBindOffset` (which its module declares on a profile that takes -/// `DriverWorkaround::PushReadsLengthenThreadPayload`) holds only at bind offset 0 of a slot the -/// runtime tells offset 0 apart at (`StageTable::zero_offset_views`, the class -/// `ZERO_OFFSET_CLASS`), and there only where instantiation's range starts at the bind offset, its -/// residual 0: on every committed profile, under each window, for an allocation the view's range -/// holds whole (whose range runs from the buffer's start) and one longer than the view's maximum -/// (a block or the bind offset's own range). At every other bind offset it is false, the residual -/// form, whose range from the buffer's start keeps the bytes before the bind offset reachable; and -/// so it is at every offset of a slot whose class tells no offset apart, as on every profile -/// without the row. Bound to nothing, it is what offset 0 gives. -#[test] -fn a_storage_range_starts_at_the_bind_offset_only_at_offset_0() { - for (stem, p) in committed_profiles().expect("profiles") { - let limits = &p.fields().limits; - let past = u64::from(limits.max_storage_buffer_range) + (1 << 20); - for window in [ - Window::Whole, - Window::Bounded { start: 0, len: 64 }, - Window::Bounded { start: 4, len: 28 }, - Window::Bounded { - start: 192, - len: 16, - }, - Window::Bounded { start: -8, len: 40 }, - ] { - let b = BufferSlot { - access: AccessSet::READ, - window, - form: BufferForm::Descriptor(DescriptorView::Storage), - kind: BufferKind::Buffer, - }; - let bindings = [(BindingSource::Buffer(slot(0)), (0, 0))].into(); - for length in [4096, past] { - for bind_offset in [0, 4, 16, 64, 256, 1024] { - let what = format!("{stem} {window:?} {length} {bind_offset}"); - let bound = BoundBuffer::Buffer { - gpu_address: 0x1_0000, - length, - offset: bind_offset, - device_address: None, - attribute_stride: None, - }; - let untold = bound.shape(0, BufferRanges::default()); - assert!( - !range_at_bind_offset(&b, Some(&untold), limits), - "{what}: untold" - ); - let told = bound.shape(crate::bind::ZERO_OFFSET_TOLD, BufferRanges::default()); - let at = range_at_bind_offset(&b, Some(&told), limits); - let pb = plan_buffer((slot(0), &b, Some(&told)), false, limits, &bindings) - .unwrap_or_else(|e| panic!("{what}: {e:?}")); - let starts = crate::bind::instantiate::starts_at_bind(0, window, pb.alignment); - assert_eq!(at, bind_offset == 0 && starts, "{what}"); - // Bound to nothing, as at offset 0 (`range_at_bind_offset`'s docs). - if bind_offset == 0 { - let unbound = range_at_bind_offset(&b, None, limits); - assert_eq!(unbound, at, "{what}: unbound"); - } - // A range past the view's maximum that no form holds takes the device-address - // variant (`BufferRangeLimit`), whose module declares no key. - let range = - crate::bind::instantiate::planned_range(&pb, bind_offset, length, false); - if let (true, Ok((_, residual))) = (at, range) { - assert_eq!(residual, 0, "{what}"); - } - } - } - } - } -} - /// A slot whose function observes residency (`RuntimeFact::SparseTexture`) binds a texture that is /// not sparse (or nothing) on every profile, and a sparse one where the module has the sparse arm /// or the tile-map arm; without either a sparse texture is refused, naming diff --git a/crates/metal2vulkan/src/bind/state.rs b/crates/metal2vulkan/src/bind/state.rs index 03c03f9dc..047d2a779 100644 --- a/crates/metal2vulkan/src/bind/state.rs +++ b/crates/metal2vulkan/src/bind/state.rs @@ -183,9 +183,7 @@ pub struct BindState { /// Whether the consumer reads every uniform view at its residual: it draws and dispatches /// with each plan's key at every uniform view's `SpecKey::RangeAtBindOffset` 0, as the runtime /// does on a device whose driver loads no uniform read at a constant offset ahead of the - /// shader (a storage view's, which only a profile taking - /// `DriverWorkaround::PushReadsLengthenThreadPayload` declares, as the plan gives it). A - /// uniform view's descriptor range then need not start at its bind offset, and + /// shader. A uniform view's descriptor range then need not start at its bind offset, and /// instantiation binds one that a run of bind offsets of the bound buffer shares (the buffer /// from its start where it fits the view's maximum range), its `SlotBindOffset` residual the /// rest: a command that moves only such a slot's offset binds the same descriptor, keeps its @@ -1025,14 +1023,10 @@ impl StageTable { } /// The alignment above the vertex fetch's that the bind offset class of a buffer at index - /// `index` tells apart ([`BoundBuffer::shape`]): offset 0 at a slot of - /// [`zero_offset_views`](Self::zero_offset_views) ([`ZERO_OFFSET_TOLD`]), - /// `view_base_alignment` at a slot of [`at_bind_views`](Self::at_bind_views), else 0 (none). + /// `index` tells apart ([`BoundBuffer::shape`]): `view_base_alignment` at a slot of + /// [`at_bind_views`](Self::at_bind_views), else 0 (none). pub fn class_alignment(&self, index: u32, view_base_alignment: u32) -> u32 { - let told = |slots: u64| index < u64::BITS && (slots >> index) & 1 == 1; - if told(self.zero_offset_views) { - ZERO_OFFSET_TOLD - } else if told(self.at_bind_views) { + if index < u64::BITS && (self.at_bind_views >> index) & 1 == 1 { view_base_alignment } else { 0 @@ -1113,17 +1107,6 @@ impl BoundBuffer { } } -/// The bind offset class of a buffer bound at offset 0 at a slot of -/// [`StageTable::zero_offset_views`] ([`BufferShape::Buffer::offset_alignment`]): a power of two, -/// which divides 0 and above every alignment a class tells apart, so the vertex fetch reads it as -/// any aligned offset's; no other bind offset takes it, there or elsewhere. -pub const ZERO_OFFSET_CLASS: u32 = 1 << 31; - -/// The class alignment ([`StageTable::class_alignment`]) of a slot of -/// [`StageTable::zero_offset_views`], which the binder's offset classes read as telling offset 0 -/// apart ([`ZERO_OFFSET_CLASS`]) and no alignment above the vertex fetch's. -pub const ZERO_OFFSET_TOLD: u32 = u32::MAX; - /// The alignment class of bind offset `offset` (a buffer's, /// [`BufferShape::Buffer::offset_alignment`]): `view_base_alignment` where that divides it (the /// uniform views' descriptor base alignment, [`BindState::view_base_alignment`]: a view's range @@ -1132,16 +1115,8 @@ pub const ZERO_OFFSET_TOLD: u32 = u32::MAX; /// fixed-function vertex input can fetch every attribute format at a buffer bound there). These /// are the only predicates a plan reads of a bind offset, so offsets moving between multiples of /// 4 that the base alignment does not divide, or between those it divides, keep one shape; a -/// `view_base_alignment` of 4 or less (0, the default) tells only the vertex fetch's apart. At a -/// slot that tells offset 0 apart (`view_base_alignment` [`ZERO_OFFSET_TOLD`]), offset 0 is -/// [`ZERO_OFFSET_CLASS`] and every other offset classes as under 0. +/// `view_base_alignment` of 4 or less (0, the default) tells only the vertex fetch's apart. pub fn offset_alignment(offset: u64, view_base_alignment: u32) -> u32 { - if view_base_alignment == ZERO_OFFSET_TOLD { - return match offset { - 0 => ZERO_OFFSET_CLASS, - _ => offset_alignment(offset, 0), - }; - } if view_base_alignment > metal::vertex::MAX_VERTEX_ALIGNMENT && offset.is_multiple_of(u64::from(view_base_alignment)) { @@ -1281,16 +1256,6 @@ pub struct StageTable { /// runtime leaves out a slot it finds bound at moving offsets, so that its draws keep one shape. #[cfg_attr(feature = "serde", serde(default))] pub at_bind_views: u64, - /// The buffer slots (bit `i` for index `i`) whose bind offset class tells offset 0 apart - /// ([`ZERO_OFFSET_CLASS`]), which the runtime sets on a profile that takes - /// `DriverWorkaround::PushReadsLengthenThreadPayload`: the slots its function reads through a - /// storage view, whose residual is 0 where the buffer is bound at offset 0 - /// (`SpecKey::RangeAtBindOffset`). No plan reads that predicate of another slot. A slot left - /// out (none, the default) reads its view at its residual, exact at every offset: a runtime - /// leaves out a slot it finds bound at an offset other than 0, so that its draws and dispatches - /// keep one shape. - #[cfg_attr(feature = "serde", serde(default))] - pub zero_offset_views: u64, /// The device's buffer range limits, which the runtime sets: its buffers' length classes are /// told apart only as far as those limits tell them apart ([`BufferRanges::length_class`]), /// all a plan reads of a buffer's length, so its buffers of lengths they do not tell apart diff --git a/crates/metal2vulkan/src/pipeline/interface.rs b/crates/metal2vulkan/src/pipeline/interface.rs index e184cf499..9dd05f019 100644 --- a/crates/metal2vulkan/src/pipeline/interface.rs +++ b/crates/metal2vulkan/src/pipeline/interface.rs @@ -896,7 +896,6 @@ pub enum PatchDomain { Quad, } -impl PipelineInterface {} impl StageInterface { /// The Vulkan stage of the module: the evaluation stage for a post-tessellation vertex diff --git a/crates/metal2vulkan/src/pipeline/sym.rs b/crates/metal2vulkan/src/pipeline/sym.rs index 21edfe48f..cb3f7c994 100644 --- a/crates/metal2vulkan/src/pipeline/sym.rs +++ b/crates/metal2vulkan/src/pipeline/sym.rs @@ -860,13 +860,8 @@ pub enum SpecKey { /// first aligned block. A slot bound to nothing takes true: its residual is 0. Where it holds, /// the function reads the slot at the Metal offset alone, a constant for a constant member, /// which a driver can load into registers ahead of the shader (Mesa's ANV does so only for a - /// uniform load at a constant offset); elsewhere at the residual plus the offset. A slot read - /// through a storage view declares it too on a profile that takes - /// `DriverWorkaround::PushReadsLengthenThreadPayload`: true where the buffer is bound at - /// offset 0 (inline bytes, or a buffer whose bind offset class is - /// `bind::ZERO_OFFSET_CLASS`), where its range starts at the buffer's start, the bind offset, - /// so the residual is 0 and the function reads no push word for it; false elsewhere, so the - /// bytes before a bind offset stay reachable through the residual as Metal's are. + /// uniform load at a constant offset); elsewhere at the residual plus the offset. Only a slot + /// read through a uniform view declares it. RangeAtBindOffset(SlotRef), /// The word of the runtime sampler bound to the slot (`u32`: its whole /// [`SamplerWord`](crate::metal::sampler::SamplerWord), its address modes as the bound diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index 4afa5bdcc..f76abe592 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -544,8 +544,6 @@ surface! { enum UsedClass N; struct UsedResource N; struct UsedShape N; - const ZERO_OFFSET_CLASS; - const ZERO_OFFSET_TOLD; struct VertexAmplification N; struct ViewMapping N; struct ImageblockSize N; diff --git a/docs/API.md b/docs/API.md index 7e1ef33e9..3233c2de1 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1185,24 +1185,8 @@ for dependency in &pipeline.dependencies { runtime does on every device whose driver is not measured to load such reads ahead of the shader) says so with `state.uniform_views_at_residual = true`: its uniform views then bind ranges their bind offsets - share (below), as a bounded storage view's do. On a profile that takes - `DriverWorkaround::PushReadsLengthenThreadPayload` (ANV on the Iris Xe RPL-P, where a light kernel - that reads a pushed word was measured at about 2.2 times the time of one that reads none) a - storage view declares the key too, and takes the form that reads no residual only at bind offset 0 - of a slot whose table tells offset 0 apart (the slot's bit in its table's - `zero_offset_views`), its class then - `bind::ZERO_OFFSET_CLASS`: leave out a slot bound at another offset, as the runtime does, so that - the bytes before a bind offset stay reachable through the range from the buffer's start and its - dispatches keep one shape. A storage view's slot bound to nothing takes the value a bind at - offset 0 gives it, so a plan of nothing bound (a creation's prediction) names the key of a - command that binds its storage views at offset 0, the commonest bind. The runtime keeps that key - and makes it at a state's creation together with its general form (every view read at its - residual), which a command binding a storage view at another offset takes at once while its own - key is made, so neither is a second pipeline made at a first command. It reads the profile's - uniform views at their residuals: there a kernel of three storage views at offset 0 and inline - bytes ran in 161.8 us a dispatch with the bytes' uniform view read at its bind offset, and in - 142.8 us with it read at its residual. Elsewhere no storage view declares the key, and `zero_offset_views` - changes nothing. + share (below), as a bounded storage view's do. No storage view declares the key: it reads at its + residual, its range from the buffer's start, so the bytes before a bind offset stay reachable. - A bound buffer's length enters its shape only as a length class (`bind::length_class`), which a plan compares with the device's `maxUniformBufferRange` and `maxStorageBufferRange` alone (whether every range of the buffer fits each). Set each table's