diff --git a/crates/metal2vulkan-runtime/src/pipeline/mod.rs b/crates/metal2vulkan-runtime/src/pipeline/mod.rs index 7b538ceb5..5e6403715 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/mod.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/mod.rs @@ -107,8 +107,9 @@ pub(super) use render::RenderVariant; pub(super) use render::WeakRenderPipelineState; /// The general and residual forms of a key (`render/residual.rs`), for `tests::general_form`. #[cfg(test)] -pub(super) use render::{general_form, residual_form_of}; -pub(super) use render::{reads_views_at_bind, residual_form, uniform_residual_form}; +pub(super) use render::{general_form, residual_form_of, residual_ids}; +pub(super) use render::{reads_views_at_bind, residual_form}; +pub(super) use render::{residual_in_place, uniform_residual_ids}; pub(super) use render::{GraphicsState, Kind as RenderStateKind, StateShared as RenderShared}; pub(super) use render::{ProgramName, Settled}; pub(super) use tile::TileState; @@ -774,6 +775,10 @@ pub(super) struct Variant { objects: Arc, plans: Mutex>>, pipelines: making::Making, + /// The IDs of the stage's constants that a key of a device reading its uniform views at their + /// residuals takes at 0 (`uniform_residual_ids`): what [`keyed_regions`](Self::keyed_regions) + /// zeroes. + uniform_residuals: Box<[u32]>, } /// What a region's `VkPipeline` is made from. @@ -2296,12 +2301,15 @@ impl Variant { memo, }) as Box> }; + let constants = pipeline.stage.specialization.constants.iter(); + let uniform_residuals = uniform_residual_ids(constants, &pipeline.interface).into(); let variant = Arc::new(Variant { key, pipeline, objects: Arc::new(objects), plans: Mutex::new(Lru::counted(PLANS)), pipelines: making::Making::watched(bound, watch), + uniform_residuals, }); for (place, made) in kept { if let kept::Place::Region(region) = place { @@ -2335,20 +2343,15 @@ impl Variant { /// `commands`' regions, each specialization with its uniform views at their residuals where /// `device` reads no uniform view at its bind offset alone (`render/residual.rs`, /// `uniform_residual_form`): what every region of a dispatch or a tile dispatch of the variant - /// takes before its key is looked up. A storage view's key keeps its value. + /// takes before its key is looked up. A storage view's key keeps its value. Written in each + /// key's own bytes, over the constants the variant listed as it was made + /// (`residual_in_place`), so keying a region makes no key. pub(crate) fn keyed_regions(&self, device: &Device, commands: &mut DispatchCommands) { - if reads_views_at_bind(device) { + if self.uniform_residuals.is_empty() || reads_views_at_bind(device) { return; } - let constants = &self.pipeline.stage.specialization.constants; - let interface = &self.pipeline.interface; for region in &mut commands.regions { - let specialization = ®ion.specialization; - if let Some(residual) = - uniform_residual_form(constants.iter(), interface, specialization) - { - region.specialization = residual; - } + residual_in_place(&mut region.specialization, &self.uniform_residuals); } } diff --git a/crates/metal2vulkan-runtime/src/pipeline/render.rs b/crates/metal2vulkan-runtime/src/pipeline/render.rs index 20a680b36..7a1b1e301 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/render.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/render.rs @@ -97,8 +97,9 @@ pub(crate) use residual::views_read_at_bind; /// The general and residual forms of a key, which `tests::general_form` reads from IDs and /// meanings alone. #[cfg(test)] -pub(crate) use residual::{general_form, residual_form_of}; -pub(crate) use residual::{reads_views_at_bind, residual_form, uniform_residual_form}; +pub(crate) use residual::{general_form, residual_form_of, residual_ids}; +pub(crate) use residual::{reads_views_at_bind, residual_form}; +pub(crate) use residual::{residual_in_place, uniform_residual_ids}; /// A Metal render pipeline state (`MTLRenderPipelineState`): one that draws, or a tile pipeline's /// ([`Device::new_tile_render_pipeline_state`]), which dispatches per tile. Cheap to clone (a diff --git a/crates/metal2vulkan-runtime/src/pipeline/render/residual.rs b/crates/metal2vulkan-runtime/src/pipeline/render/residual.rs index 494d8d662..e166cb3bc 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/render/residual.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/render/residual.rs @@ -242,6 +242,48 @@ pub(crate) fn uniform_residual_form<'a>( residual_form_of(constants, uniform, specialization) } +/// The IDs of `constants`' `SpecKey::RangeAtBindOffset` constants whose slot `interface` reads +/// through a uniform view: those [`uniform_residual_form`] zeroes, listed once for a pipeline so +/// each of its keys takes that form in place ([`residual_in_place`]). +pub(crate) fn uniform_residual_ids<'a>( + constants: impl Iterator, + interface: &PipelineInterface, +) -> Vec { + let uniform = |slot| { + matches!(interface.slots.get(&slot), + Some(SlotInterface::Buffer(b)) if b.form.uniform_view()) + }; + residual_ids( + constants.map(|constant| (constant.id, constant.key)), + uniform, + ) +} + +/// The IDs of `constants`' (each its ID and its meaning) `SpecKey::RangeAtBindOffset` constants +/// whose slot `views` holds: those [`residual_form_of`] zeroes. +pub(crate) fn residual_ids( + constants: impl Iterator, + views: impl Fn(SlotRef) -> bool, +) -> Vec { + constants + .filter(|&(_, key)| matches!(key, SpecKey::RangeAtBindOffset(slot) if views(slot))) + .map(|(id, _)| id) + .collect() +} + +/// `specialization` with the value of each constant `ids` names at 0, written in its own bytes: +/// [`residual_form_of`]'s key where `ids` are [`residual_ids`]' of the same constants and views, +/// and `specialization` as it was where that answers `None`, with no key made. +pub(crate) fn residual_in_place(specialization: &mut SpecializationKey, ids: &[u32]) { + let SpecializationKey { data, entries, .. } = specialization; + for entry in entries.iter().filter(|e| ids.contains(&e.constant_id)) { + let at = entry.offset as usize; + if let Some(bytes) = data.get_mut(at..at + entry.size as usize) { + bytes.fill(0); + } + } +} + /// `specialization` with each `SpecKey::RangeAtBindOffset` constant of `constants` (a pipeline's /// stages', each its ID and its meaning) whose slot `views` holds at 0; `None` where every one of /// them is 0 there already. A constant `specialization` gives no entry takes the module's diff --git a/crates/metal2vulkan-runtime/src/tests/general_form.rs b/crates/metal2vulkan-runtime/src/tests/general_form.rs index 2e0dc4baa..f386c85be 100644 --- a/crates/metal2vulkan-runtime/src/tests/general_form.rs +++ b/crates/metal2vulkan-runtime/src/tests/general_form.rs @@ -4,7 +4,7 @@ //! plan takes where the device reads its uniform views at their residuals: those views' constants //! alone at 0. -use crate::pipeline::{general_form, residual_form_of}; +use crate::pipeline::{general_form, residual_form_of, residual_ids, residual_in_place}; use metal2vulkan::cache::SpecializationKey; use metal2vulkan::pipeline::{SlotClass, SlotRef, SpecKey, Stage}; use metal2vulkan::vk::SpecializationMapEntry; @@ -115,3 +115,40 @@ fn a_plans_key_zeroes_its_uniform_views_and_keeps_its_storage_views() { let kept = key([0, 1, 1, 1, 3]); assert_eq!(residual_form_of(constants(), uniform_views, &kept), None); } + +/// A dispatch's regions take that key in their own bytes (`Variant::keyed_regions`): zeroing the +/// constants `residual_ids` lists in place gives `residual_form_of`'s key, or the key as it was +/// where that answers `None`, in the storage the key held, for the uniform views alone and for +/// every view. +#[test] +fn a_key_takes_its_residual_form_in_its_own_bytes() { + let uniform = slot(SlotClass::Buffer, 0); + let texture = slot(SlotClass::Texture, 0); + let constants = || { + vec![ + (0, SpecKey::RangeAtBindOffset(uniform)), + (1, SpecKey::RangeAtBindOffset(slot(SlotClass::Buffer, 1))), + (2, SpecKey::UnmeasuredTexels(texture)), + (3, SpecKey::PlainHalfTexels(texture)), + (4, SpecKey::BicubicTexels(texture)), + ] + .into_iter() + }; + let uniform_views = |at: SlotRef| at == uniform; + let every_view = |_: SlotRef| true; + let views: [&dyn Fn(SlotRef) -> bool; 2] = [&uniform_views, &every_view]; + assert_eq!(residual_ids(constants(), uniform_views), vec![0]); + assert_eq!(residual_ids(constants(), every_view), vec![0, 1]); + for (n, views) in views.into_iter().enumerate() { + for values in [[1, 1, 1, 1, 3], [0, 1, 1, 1, 3], [0, 0, 0, 0, 0]] { + let was = key(values); + let made = residual_form_of(constants(), views, &was).unwrap_or_else(|| was.clone()); + let mut in_place = was.clone(); + let storage = (in_place.data.as_ptr(), in_place.entries.as_ptr()); + residual_in_place(&mut in_place, &residual_ids(constants(), views)); + assert_eq!(in_place, made, "views {n}, {values:?}"); + let kept = (in_place.data.as_ptr(), in_place.entries.as_ptr()); + assert_eq!(kept, storage, "views {n}, {values:?}: the key's storage"); + } + } +} diff --git a/crates/metal2vulkan/src/bind/dispatch.rs b/crates/metal2vulkan/src/bind/dispatch.rs index af7008ccf..20510f67f 100644 --- a/crates/metal2vulkan/src/bind/dispatch.rs +++ b/crates/metal2vulkan/src/bind/dispatch.rs @@ -336,17 +336,16 @@ fn emulated_rules(rules: &LocalRules) -> LocalRules { /// least 1), with every region checked against that pipeline's rules. A flattened tier's dispatch /// with a region that is not whole subgroups runs whole on the emulated-simdgroups variant, so each /// of its regions is checked against the variant's rules ([`emulated_rules`]). -pub(crate) fn fit(rules: &LocalRules, locals: &[[u32; 3]]) -> Result { - if locals.iter().any(|&r| partial(rules, r)) { +pub(crate) fn fit( + rules: &LocalRules, + mut locals: impl Iterator + Clone, +) -> Result { + if locals.clone().any(|r| partial(rules, r)) { let emulated = emulated_rules(rules); - for &r in locals { - check_local(&emulated, r)?; - } + locals.try_for_each(|r| check_local(&emulated, r))?; Ok(Fit::EmulatedSimdgroups) } else { - for &r in locals { - check_local(rules, r)?; - } + locals.try_for_each(|r| check_local(rules, r))?; Ok(Fit::Planned) } } @@ -440,8 +439,8 @@ type Piece = (u32, u32, u32); /// One axis's pieces: `count` groups of `local` threads from group `base`, in chunks of at most /// `max`, then the edge piece where there is one. Held as these numbers alone, so a dispatch's -/// regions are planned with no list of each axis's pieces. -#[derive(Clone, Copy)] +/// regions are planned with no list of each axis's pieces, nor of the regions ([`Regions`]). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] struct Pieces { base: u32, count: u32, @@ -462,13 +461,24 @@ impl Pieces { } } + /// The one piece `(base, count, local)`, whatever its count (0 for an indirect region's). + fn one(base: u32, count: u32, local: u32) -> Pieces { + Pieces { + base, + count: 0, + local, + max: 1, + edge: Some((base, count, local)), + } + } + /// How many pieces the axis has. fn len(&self) -> u64 { u64::from(self.count.div_ceil(self.max)) + u64::from(self.edge.is_some()) } /// The pieces in order: each chunk, then the edge. - fn iter(&self) -> impl Iterator { + fn iter(&self) -> impl Iterator + Clone { let Pieces { base, count, @@ -486,9 +496,66 @@ impl Pieces { } } +/// The regions of a dispatch: the product of each axis's pieces, x slowest, each region taking one +/// piece of every axis, all of one `MultiRegion`. Held as these numbers alone, so planning a +/// dispatch makes no list of its regions: [`Regions::iter`] gives them in order. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) struct Regions { + pieces: [Pieces; 3], + multi: bool, +} + +impl Regions { + /// No region. + fn none() -> Regions { + Regions { + pieces: [Pieces::chunks(0, 0, 0, 1); 3], + multi: false, + } + } + + /// The one region `r`. + fn one(r: Region) -> Regions { + Regions { + pieces: std::array::from_fn(|i| Pieces::one(r.base[i], r.groups[i], r.local[i])), + multi: r.multi, + } + } + + /// How many regions there are. + pub(crate) fn len(&self) -> usize { + self.pieces.iter().map(Pieces::len).product::() as usize + } + + pub(crate) fn is_empty(&self) -> bool { + self.len() == 0 + } + + /// The regions in order. + pub(crate) fn iter(&self) -> impl Iterator + Clone + '_ { + let [x, y, z] = &self.pieces; + let multi = self.multi; + x.iter().flat_map(move |(bx, cx, lx)| { + y.iter().flat_map(move |(by, cy, ly)| { + z.iter().map(move |(bz, cz, lz)| Region { + local: [lx, ly, lz], + groups: [cx, cy, cz], + base: [bx, by, bz], + multi, + }) + }) + }) + } + + /// Every region with `MultiRegion` 1: it reads its record. + fn read_records(&mut self) { + self.multi = true; + } +} + /// The regions of a direct dispatch whose axes split into `pieces`; `MultiRegion` whenever there /// is more than one region or `force_multi`. -fn product(pieces: [Pieces; 3], force_multi: bool) -> Result, BindError> { +fn product(pieces: [Pieces; 3], force_multi: bool) -> Result { let total: u64 = pieces.iter().map(Pieces::len).product(); if total > MAX_REGIONS { let (i, _) = pieces @@ -502,21 +569,10 @@ fn product(pieces: [Pieces; 3], force_multi: bool) -> Result, BindEr }, ))); } - let multi = force_multi || total > 1; - let mut out = Vec::with_capacity(total as usize); - for (bx, cx, lx) in pieces[0].iter() { - for (by, cy, ly) in pieces[1].iter() { - for (bz, cz, lz) in pieces[2].iter() { - out.push(Region { - local: [lx, ly, lz], - groups: [cx, cy, cz], - base: [bx, by, bz], - multi, - }); - } - } - } - Ok(out) + Ok(Regions { + pieces, + multi: force_multi || total > 1, + }) } /// Whether a region of `planned` has more than one row (`y` or `z` above 1), where a simdgroup @@ -545,7 +601,7 @@ fn multi_row(planned: &Planned) -> bool { /// The regions of a dispatch. #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct Planned { - pub regions: Vec, + pub regions: Regions, /// The Metal grid (`threads_per_grid`) the `DispatchRegion` field reports (0 for an indirect /// dispatch, whose grid only the GPU knows). pub grid: [u32; 3], @@ -687,7 +743,7 @@ pub(crate) fn regions( } } let empty = |v: [u32; 3]| v.contains(&0); - let planned = |regions: Vec, grid, emulated: bool| Planned { + let planned = |regions: Regions, grid, emulated: bool| Planned { emulated: emulated && !regions.is_empty(), regions, grid, @@ -696,10 +752,10 @@ pub(crate) fn regions( }; match *dispatch { Dispatch::Threadgroups { groups, .. } => { - let fit = fit(rules, &[l])?; + let fit = fit(rules, std::iter::once(l))?; let grid = threadgroup_grid(groups, nominal)?; if empty(groups) { - return Ok(planned(Vec::new(), grid, false)); + return Ok(planned(Regions::none(), grid, false)); } let pieces = std::array::from_fn(|i| Pieces::chunks(0, groups[i], l[i], rules.max_count[i])); @@ -718,13 +774,13 @@ pub(crate) fn regions( count, .. } => { - let fit = fit(rules, &[l])?; + let fit = fit(rules, std::iter::once(l))?; let grid = threadgroup_grid(groups, nominal)?; let start: [u32; 3] = std::array::from_fn(|i| first[i].min(groups[i])); let end: [u32; 3] = std::array::from_fn(|i| first[i].saturating_add(count[i]).min(groups[i])); if (0..3).any(|i| end[i] <= start[i]) { - return Ok(planned(Vec::new(), grid, false)); + return Ok(planned(Regions::none(), grid, false)); } let pieces = std::array::from_fn(|i| { Pieces::chunks(start[i], end[i] - start[i], l[i], rules.max_count[i]) @@ -738,7 +794,7 @@ pub(crate) fn regions( } Dispatch::Threads { threads, .. } => { if empty(threads) { - return Ok(planned(Vec::new(), threads, false)); + return Ok(planned(Regions::none(), threads, false)); } // A flat variant runs the whole grid in one region of the dispatch's own threadgroup // size: invocation `((wz · ny + wy) · nx + wx) · N + LocalInvocationIndex`, with @@ -748,7 +804,7 @@ pub(crate) fn regions( // in each and run the same threads again: the region is never chunked, and its counts // only have to cover the grid ([`spread`]). if ragged == Ragged::Flat { - let fit = fit(rules, &[l])?; + let fit = fit(rules, std::iter::once(l))?; let n: u64 = l.iter().map(|&x| u64::from(x)).product(); let total: u128 = threads.iter().map(|&x| u128::from(x)).product(); let need = u64::try_from(total.div_ceil(u128::from(n))).map_err(|_| { @@ -766,7 +822,7 @@ pub(crate) fn regions( multi: false, }; return Ok(planned( - vec![region], + Regions::one(region), threads, fit == Fit::EmulatedSimdgroups, )); @@ -781,7 +837,7 @@ pub(crate) fn regions( let pieces = std::array::from_fn(|i| { Pieces::chunks(0, threads[i].div_ceil(l[i]), l[i], rules.max_count[i]) }); - let fit = fit(rules, &[l])?; + let fit = fit(rules, std::iter::once(l))?; let mut out = planned( product(pieces, true)?, threads, @@ -801,12 +857,11 @@ pub(crate) fn regions( p }); let out = product(pieces, edges)?; - let locals: Vec<[u32; 3]> = out.iter().map(|r| r.local).collect(); - let fit = fit(rules, &locals)?; + let fit = fit(rules, out.iter().map(|r| r.local))?; Ok(planned(out, threads, fit == Fit::EmulatedSimdgroups)) } Dispatch::ThreadgroupsIndirect { .. } => { - let fit = fit(rules, &[l])?; + let fit = fit(rules, std::iter::once(l))?; let region = Region { local: l, groups: [0; 3], @@ -814,7 +869,7 @@ pub(crate) fn regions( multi: false, }; Ok(planned( - vec![region], + Regions::one(region), [0; 3], fit == Fit::EmulatedSimdgroups, )) @@ -922,9 +977,7 @@ impl BindingPlan { } // A folded variant's region reads its record. if self.variant.folded_groups { - for r in &mut planned.regions { - r.multi = true; - } + planned.regions.read_records(); } instantiate(t, planned, (state, dispatch), records, commands) } @@ -1001,9 +1054,7 @@ impl BindingPlan { }); } // Every region record states the dispatch's region. - for r in &mut planned.regions { - r.multi = true; - } + planned.regions.read_records(); let mut commands = DispatchCommands::none(); instantiate( t, @@ -1135,18 +1186,30 @@ fn region_specialization( /// [`region_specialization`]'s key of a region of `local` threads, `multi` and `reach`, written /// over `key` in the storage its lists hold ([`spec_key_into`]). +/// +/// The template's fixed constants are the plan's value of every other constant of the layout, in +/// the layout's order, each a function of its key alone (`plan::compute`): each is taken where the +/// one before left off, and found from the start only where that one is another key's, so a +/// region's key takes no search of them. fn region_specialization_into( t: &ComputeTemplate, (local, multi, reach): ([u32; 3], bool, bool), key: &mut SpecializationKey, ) { let n: u64 = local.iter().map(|&x| u64::from(x)).product(); + let next = std::cell::Cell::new(0); let value = |k| match k { SpecKey::LocalSize(a) => Some(u64::from(local[a as usize])), SpecKey::FlatLocalSize => Some(n), SpecKey::MultiRegion => Some(u64::from(multi)), SpecKey::StageInReach => Some(u64::from(reach)), - other => t.fixed.iter().find(|(key, _)| *key == other).map(|f| f.1), + other => match t.fixed.get(next.get()) { + Some(&(at, v)) if at == other => { + next.set(next.get() + 1); + Some(v) + } + _ => t.fixed.iter().find(|(key, _)| *key == other).map(|f| f.1), + }, }; spec_key_into(&t.spec, value, key); } @@ -1479,7 +1542,7 @@ fn instantiate( .. } = planned; let reach = stage_in_reach(t, region, grid, state); - for (r, out) in planned.into_iter().zip(regions_out.iter_mut()) { + for (r, out) in planned.iter().zip(regions_out.iter_mut()) { if let Some(loc) = region_field { let b = match nonuniform { true => nonuniform_region_bytes(r.base, grid, nominal), diff --git a/crates/metal2vulkan/src/bind/dispatch/tests.rs b/crates/metal2vulkan/src/bind/dispatch/tests.rs index 2ddbf9f67..13f0610f0 100644 --- a/crates/metal2vulkan/src/bind/dispatch/tests.rs +++ b/crates/metal2vulkan/src/bind/dispatch/tests.rs @@ -308,6 +308,75 @@ fn instantiating_over_kept_commands_gives_a_fresh_instantiation() { } } +/// `instantiate_dispatch_into` over commands a dispatch of as many regions or more left allocates +/// nothing: the regions are planned as numbers (`Regions`), and each region's key and push write, +/// the ranges and the extents are written in the storage kept. +#[test] +fn instantiating_over_kept_commands_allocates_nothing() { + use crate::tests::constant_blob_footprint::allocations_during; + let plan = compute_plan(&template(), VariantKey::new()); + let ragged = Dispatch::Threads { + threads: [40, 3, 1], + threads_per_group: [16, 2, 1], + }; + let whole = Dispatch::Threadgroups { + groups: [4, 2, 1], + threads_per_group: [16, 2, 1], + }; + let mut kept = plan + .instantiate_dispatch(&state(0), &ragged) + .expect("first"); + assert_eq!(kept.regions.len(), 4, "the interior and three edges"); + for (at, (d, offset)) in [(ragged, 64), (whole, 128), (ragged, 192)] + .into_iter() + .enumerate() + { + let s = state(offset); + let (into, made) = allocations_during(|| plan.instantiate_dispatch_into(&s, &d, &mut kept)); + into.expect("into"); + assert_eq!(made, 0, "dispatch {at}: allocations"); + let fresh = plan.instantiate_dispatch(&s, &d).expect("fresh"); + assert_eq!(kept, fresh, "dispatch {at}"); + } +} + +/// A region's key takes each fixed constant of the template where the walk of the layout left +/// off, the order the planner lists them in, and finds one listed out of that order: the same key +/// either way, each constant at its own value. +#[test] +fn a_regions_key_takes_its_fixed_constants_in_any_order() { + let mut t = template(); + t.spec = vec![ + spec(0, SpecKey::LocalSize(Axis::X)), + spec(1, SpecKey::TgLength(0)), + spec(2, SpecKey::LocalSize(Axis::Y)), + spec(3, SpecKey::TgLength(1)), + spec(4, SpecKey::LocalSize(Axis::Z)), + spec(5, SpecKey::MultiRegion), + spec(6, SpecKey::TgLength(2)), + ]; + let fixed = [ + (SpecKey::TgLength(0), 16), + (SpecKey::TgLength(1), 32), + (SpecKey::TgLength(2), 48), + ]; + let d = Dispatch::Threadgroups { + groups: [4, 2, 1], + threads_per_group: [16, 2, 1], + }; + let mut keys = Vec::new(); + for order in [[0, 1, 2], [2, 0, 1], [1, 2, 0]] { + t.fixed = order.iter().map(|&i| fixed[i]).collect(); + let c = instantiate(&t, &state(0), &d).expect("one region"); + let key = c.regions[0].specialization.clone(); + let values: Vec<_> = (0..7).map(|id| spec_value(&key, id)).collect(); + let expected = [16, 16, 2, 32, 1, 0, 48].map(Some); + assert_eq!(values, expected, "{order:?}"); + keys.push(key); + } + assert!(keys.windows(2).all(|k| k[0] == k[1])); +} + #[test] fn group_counts_above_the_limit_are_split_with_their_base() { let t = template(); @@ -388,25 +457,28 @@ fn local_sizes_are_checked_against_every_d4_limit() { // A partial simdgroup runs on the emulated-simdgroups variant, whose local size is not // flattened: each axis and the product are checked, not `sn` and the subgroups. assert_eq!( - fit(&r, &[[33, 1, 1]]).expect("partial"), + fit(&r, std::iter::once([33, 1, 1])).expect("partial"), Fit::EmulatedSimdgroups ); - assert_eq!(fit(&r, &[[32, 1, 1]]).expect("full"), Fit::Planned); assert_eq!( - fit(&r, &[[1, 1, 1]]).expect("one thread"), + fit(&r, std::iter::once([32, 1, 1])).expect("full"), + Fit::Planned + ); + assert_eq!( + fit(&r, std::iter::once([1, 1, 1])).expect("one thread"), Fit::EmulatedSimdgroups ); r.max_subgroups = 1; assert_eq!( - fit(&r, &[[60, 1, 1]]).expect("the subgroup limit is the flattened tier's"), + fit(&r, std::iter::once([60, 1, 1])).expect("the subgroup limit is the flattened tier's"), Fit::EmulatedSimdgroups ); - let e = fit(&r, &[[1, 1, 65]]).expect_err("z of a partial region"); + let e = fit(&r, std::iter::once([1, 1, 65])).expect_err("z of a partial region"); assert!( matches!(&e, BindError::Unsupported(u) if u.feature == Feature::LocalSize { axis: Some(Axis::Z) }), "{e:?}" ); - let e = fit(&r, &[[33, 33, 1]]).expect_err("invocations of a partial region"); + let e = fit(&r, std::iter::once([33, 33, 1])).expect_err("invocations of a partial region"); assert!( matches!(&e, BindError::Unsupported(u) if u.feature == Feature::LocalSize { axis: None }), "{e:?}" @@ -414,24 +486,27 @@ fn local_sizes_are_checked_against_every_d4_limit() { // The whole dispatch runs on the variant, so every region of a dispatch with a partial one // is checked against the variant's limits, its whole-subgroup regions included: the z of // [1, 1, 96] is past them, and [1, 1, 64], past the flattened tier's subgroups, is not. - let e = fit(&r, &[[1, 1, 96], [1, 1, 4]]).expect_err("z of a whole region"); + let e = fit(&r, [[1, 1, 96], [1, 1, 4]].into_iter()).expect_err("z of a whole region"); assert!( matches!(&e, BindError::Unsupported(u) if u.feature == Feature::LocalSize { axis: Some(Axis::Z) }), "{e:?}" ); assert!( - fit(&r, &[[1, 1, 64]]).is_err(), + fit(&r, std::iter::once([1, 1, 64])).is_err(), "two subgroups on the flattened tier" ); assert_eq!( - fit(&r, &[[1, 1, 64], [1, 1, 36]]).expect("mixed"), + fit(&r, [[1, 1, 64], [1, 1, 36]].into_iter()).expect("mixed"), Fit::EmulatedSimdgroups ); // Outside the flattened tiers a multiple is a derivative group's, and stays refused. let mut d4 = rules(); d4.multiples = vec![4]; - assert_eq!(fit(&d4, &[[8, 1, 1]]).expect("quads"), Fit::Planned); - let e = fit(&d4, &[[6, 1, 1]]).expect_err("a partial quad"); + assert_eq!( + fit(&d4, std::iter::once([8, 1, 1])).expect("quads"), + Fit::Planned + ); + let e = fit(&d4, std::iter::once([6, 1, 1])).expect_err("a partial quad"); assert!( matches!(&e, BindError::Unsupported(u) if u.feature == Feature::ComputeDerivatives), "{e:?}" @@ -970,7 +1045,7 @@ fn a_flat_region_counts_every_grid_thread_exactly_once() { assert_eq!(planned.regions.len(), 1, "{what}"); assert_eq!(planned.grid, threads, "{what}"); assert_eq!(planned.nominal, local, "{what}"); - let r = planned.regions[0]; + let r = planned.regions.iter().next().expect("a region"); assert_eq!(r.local, local, "{what}"); assert_eq!(r.base, [0; 3], "{what}"); for (&count, &limit) in r.groups.iter().zip(&max_count) { diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 8a3163d36..1e3921f09 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 524; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2477; +pub const RUNTIME_VERSION: u32 = 2478; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/crates/metal2vulkan/src/tests/constant_blob_footprint.rs b/crates/metal2vulkan/src/tests/constant_blob_footprint.rs index 2f9118057..9050464f1 100644 --- a/crates/metal2vulkan/src/tests/constant_blob_footprint.rs +++ b/crates/metal2vulkan/src/tests/constant_blob_footprint.rs @@ -133,7 +133,7 @@ pub(crate) fn held_during(work: impl FnOnce() -> T) -> (T, u64) { /// `work`'s result, and the allocations and reallocations it made while it ran (the calling /// thread's). -pub(super) fn allocations_during(work: impl FnOnce() -> T) -> (T, u64) { +pub(crate) fn allocations_during(work: impl FnOnce() -> T) -> (T, u64) { let (value, counts) = measured(work); (value, counts.allocations) }