diff --git a/crates/metal2vulkan-runtime/src/compute.rs b/crates/metal2vulkan-runtime/src/compute.rs index 0725d7714..c2e9c5f29 100644 --- a/crates/metal2vulkan-runtime/src/compute.rs +++ b/crates/metal2vulkan-runtime/src/compute.rs @@ -96,7 +96,7 @@ use super::pvrtc::degrade_unreadable; use super::replay::{CallLog, ComputeCall, Replay, Resource, SamplersWithLodClamps}; use super::residency::Residency; use super::resource::ResourceRef; -use super::sampler::SamplerState; +use super::sampler::{ArgumentSamplers, SamplerState}; use super::shadow; use super::texture::Texture; use super::used_resources::EncoderKind; @@ -2134,12 +2134,16 @@ fn apart_samplers(device: &Device, objects: &VariantObjects) -> bool { /// What a dispatch settles before it binds ([`settle_dispatch`], [`settle_live`]): the device's /// sampler states it lists (less those at IDs no set-1 sampler array of the variant holds, -/// `unlisted` saying so: `heap_sets::fit_samplers`), the visible-function tables its state made, +/// `unlisted` saying so: `heap_sets::fit_samplers`), where it took them +/// (`sampler::ArgumentSamplers`), the visible-function tables its state made, /// its runtime samplers' address-mode maps, and what it planned: the state's shape, and the variant /// it runs on with its plan, for `planned.dispatch`. Its bind state is apart: the encoder's kept one /// (`compute/live.rs`), or one of its own. pub(super) struct SettledDispatch { - argument_samplers: Vec, + /// `None` where it took none: an encoder's dispatch whose kept state lists every live state + /// at the count of their slots' changes that holds, of a variant with no set-1 arrays, or an + /// entry parked in its command buffer ([`DispatchMemo::unlist_samplers`]). + argument_samplers: Option>, function_tables: Vec, unlisted: Option<(u64, u64)>, sampler_maps: SamplerMaps, @@ -2193,7 +2197,7 @@ fn settle_dispatch<'a>( }; planned_as_before(pipeline, &planned, as_before, direct); let settled = SettledDispatch { - argument_samplers, + argument_samplers: Some(argument_samplers), function_tables, unlisted, sampler_maps, @@ -2203,33 +2207,34 @@ fn settle_dispatch<'a>( } /// [`settle_dispatch`] of a compute encoder's own dispatch, through the encoder's kept bind state -/// `live`, brought in place (`LiveDispatch::refresh`), with `samplers`, the device's sampler -/// states at `changed` changes of their slots: the state's shape kept where nothing brought in may -/// have changed it, else found among those the pipeline state planned for lately or made +/// `live`, brought in place (`LiveDispatch::refresh`), with the device's sampler states `samplers` +/// taken only where the dispatch needs them (`sampler::ArgumentSamplers`), at `changed` changes of +/// their slots: where the kept state lists every live state at that count, of a variant with no +/// set-1 arrays, it takes none. The state's shape kept where nothing brought in may have changed +/// it, else found among those the pipeline state planned for lately or made /// (`LiveDispatch::shape`), and what it planned for that shape, the very one looked for first /// (`ComputePipelineState::planned_for`). Where `refreshed` holds the table's samplers' maps, the -/// state was brought in place with them and `samplers` untrimmed already -/// (`LiveDispatch::settled_across`'s `Across::Refreshed`), which it is not again. +/// state was brought in place with them and `samplers` already (`LiveDispatch::settled_across`'s +/// `Across::Refreshed`), which it is not again. Beside what it settled, the count of slot changes +/// its listing is of: the states', where it took them. fn settle_live<'a>( live: &mut LiveDispatch, tables: &DispatchTables<'_>, (direct, gpu): (Option, Option>), function_tables: Vec, - ((changed, samplers), refreshed): ((u64, Vec), Option), -) -> Result)>, Error> { + ((changed, mut samplers), refreshed): ((u64, ArgumentSamplers), Option), +) -> Result, u64)>, Error> { let pipeline = tables.pipeline; - let counts = pipeline.generation().shared().counts.thread(); - let mut argument_samplers = samplers; + let device = pipeline.generation(); + let counts = device.shared().counts.thread(); let mut unlisted = None; let (sampler_maps, mut in_place) = match refreshed { Some(maps) => (maps, true), None => (tables.sampler_maps()?, false), }; - // Whether the states were trimmed to those a variant's set-1 sampler arrays hold. - let mut trimmed = false; let (planned, as_before, flat) = loop { - let listing = (changed, &argument_samplers[..], trimmed); if !in_place { + let listing = (changed, &mut samplers); live.refresh(tables, &sampler_maps, listing, &function_tables, counts); } in_place = false; @@ -2247,20 +2252,23 @@ fn settle_live<'a>( } }; let set = planned.variant.pipeline().layout.sets.get(1); - if heap_sets::fit_samplers(set, &mut argument_samplers, &mut unlisted) { + if samplers.fit(set, &mut unlisted) { break (planned, as_before, flat); } - trimmed = true; + // A variant of set-1 arrays writes the listed states' elements: it takes the states, + // listed again against them (alike, where the kept listing is current). + samplers.take(device); }; planned_as_before(pipeline, &planned, as_before, direct); + let listed = samplers.taken_at().unwrap_or(changed); let settled = SettledDispatch { - argument_samplers, + argument_samplers: samplers.into_states(), function_tables, unlisted, sampler_maps, planned, }; - Ok(Some((settled, flat))) + Ok(Some((settled, flat, listed))) } /// What a dispatch of a bind state of `shape` in `forms` plans now, of `direct` group counts or of @@ -2479,14 +2487,24 @@ impl DispatchMemo { /// The entry goes on under `stamp`, the stamp of a table that brings in the very state it /// settled (`LiveDispatch::settled_across`), its sampler states listed again where its - /// parking let them go ([`unlist_samplers`](Self::unlist_samplers)): `samplers`, the - /// device's at the count of sampler slot changes the entry was settled at, so the very states - /// it listed (`DeviceShared::sampler_slots_changed`). - fn restamp(&mut self, stamp: Stamp, samplers: &[SamplerState]) { + /// parking let them go ([`unlist_samplers`](Self::unlist_samplers)) and its variant has set-1 + /// arrays, which write their elements: `samplers`, taken from `device` where they were not, + /// at the count of sampler slot changes the entry was settled at, so the very states it + /// listed (`DeviceShared::sampler_slots_changed`). + fn restamp(&mut self, stamp: Stamp, (samplers, device): (&mut ArgumentSamplers, &Device)) { if let Some(kept) = &mut self.0 { kept.stamp = stamp; - if kept.settled.argument_samplers.is_empty() { - kept.settled.argument_samplers.extend_from_slice(samplers); + let settled = &mut kept.settled; + let arrays = settled + .planned + .variant + .pipeline() + .layout + .sets + .get(1) + .is_some(); + if arrays && settled.argument_samplers.is_none() { + settled.argument_samplers = Some(samplers.take(device).clone()); } } } @@ -2497,7 +2515,7 @@ impl DispatchMemo { /// sampler slot changes, which every other use of the entry compares first. fn unlist_samplers(&mut self) { if let Some(kept) = &mut self.0 { - kept.settled.argument_samplers.clear(); + kept.settled.argument_samplers = None; } } } @@ -2613,41 +2631,43 @@ fn record( // A direct dispatch, of a state that made no table, takes the memo. let memo = direct.filter(|_| function_tables.is_empty()); let moved = super::buffer::host_cells_moved(); + let changed = core.generation().sampler_slots_changed(); let held = memo.is_some_and(|dispatch| { - let counted = (moved, core.generation().sampler_slots_changed()); - live.memo.holds(&live.state, tables, &dispatch, counted) + live.memo + .holds(&live.state, tables, &dispatch, (moved, changed)) }); - // The sampler states, with the count of changes they are live at, where it is not. - let listing = (!held).then(|| core.device().argument_samplers_at()); + // The device's sampler states, taken only where the dispatch needs them + // (`sampler::ArgumentSamplers`). + let mut samplers = ArgumentSamplers::untaken(); // Else an entry an earlier compute encoder of the command buffer settled and parked, // where the table, read now, brings in the very state it settled (`compute/live.rs`). - let across = match (memo, &listing) { - (Some(dispatch), Some((changed, samplers))) => { + let across = match memo.filter(|_| !held) { + Some(dispatch) => { let thread = pipeline.generation().shared().counts.thread(); live.settled_across( tables, - (&dispatch, (moved, *changed)), - (*changed, samplers), + (&dispatch, (moved, changed)), + &mut samplers, &function_tables, thread, )? } - _ => Across::Missed, + None => Across::Missed, }; if held { core.counts().dispatch_settled_as_before(); } else if let Across::Taken = across { core.counts().dispatch_settled_across_encoders(); - } else if let Some(settling) = listing { - let changed = settling.0; + } else { let refreshed = match across { Across::Refreshed(maps) => Some(maps), Across::Taken | Across::Missed => None, }; - let settling = (settling, refreshed); + let settling = ((changed, samplers), refreshed); let settled = settle_live(live, tables, (direct, gpu), function_tables, settling); // The kept state is no longer what the memo's entry settled. - let Some((settled, flat_call)) = settled.inspect_err(|_| live.let_go())? else { + let Some((settled, flat_call, changed)) = settled.inspect_err(|_| live.let_go())? + else { live.let_go(); return Ok(false); }; @@ -2713,10 +2733,22 @@ fn record( // (`Planned::grids`); a flat indirect dispatch's, its planned's. let (unlisted, dispatch) = (*unlisted, direct.unwrap_or(*dispatch)); let interface = &variant.pipeline().interface; - core.device().degrade_argument_pixel_samplers( - std::slice::from_ref(&variant.pipeline().stage), - argument_samplers, - ); + // A notice that names a state of pixel coordinates lists the states, taken here where the + // dispatch settled without them. + let stages = std::slice::from_ref(&variant.pipeline().stage); + if core + .device() + .argument_pixel_samplers_noted(stages) + .is_some() + { + let mut taken = ArgumentSamplers::untaken(); + let states = match argument_samplers { + Some(states) => states, + None => &*taken.take(core.device()), + }; + core.device() + .degrade_argument_pixel_samplers(stages, states); + } tables .table .check_function_tables(call, Stage::Kernel, interface)?; @@ -2856,7 +2888,10 @@ fn record( // function-table array reads in set 0, which has no heap of its own. bound_tables = bound_tables.with_function_tables(function_tables); if let Some(heap) = &heap { - bound_tables = bound_tables.with_heap(argument_samplers, heap); + // Taken as the dispatch settled: its variant has set-1 arrays. + let states = (argument_samplers.as_deref()) + .ok_or_else(|| internal("a heap's dispatch without its argument samplers"))?; + bound_tables = bound_tables.with_heap(states, heap); } let pipeline_stage = &variant.pipeline().stage; // A flat dispatch's indirect arguments are its preprocess's command, in the command's own diff --git a/crates/metal2vulkan-runtime/src/compute/live.rs b/crates/metal2vulkan-runtime/src/compute/live.rs index 15f342e33..00cfe4dd1 100644 --- a/crates/metal2vulkan-runtime/src/compute/live.rs +++ b/crates/metal2vulkan-runtime/src/compute/live.rs @@ -91,7 +91,7 @@ use crate::heap_sets; use crate::live_bind::{Reshape, ValueKinds}; use crate::pipeline::{ComputePipelineState, WeakComputePipelineState}; use crate::pvrtc::ResidentUnreadable; -use crate::sampler::SamplerState; +use crate::sampler::{ArgumentSamplers, SamplerState}; use crate::shadow::ResidentShadows; use crate::work_counts::Counting; @@ -176,15 +176,16 @@ impl LiveDispatch { /// its samplers bound as `maps` binds them, its threadgroup memory lengths, the imageblock size /// for a kernel with an explicit imageblock (one without plans with none, so its shape is the /// one the executor computes for it), the stage-in region, the resources the encoder made - /// resident, `samplers` listed (the device's sampler states at `changed` changes of their - /// slots, those a variant's set-1 arrays hold alone where `trimmed`), and the live tables the - /// pipeline state made. Each change that may change the shape is noted, and the shape kept only - /// where none may have. The kinds of values it changed. + /// resident, the device's sampler states listed (those `samplers` took, which it takes where + /// the kept listing is not of every live state at `changed` changes of their slots: + /// `sampler::ArgumentSamplers`), and the live tables the pipeline state made. Each change that + /// may change the shape is noted, and the shape kept only where none may have. The kinds of + /// values it changed. pub(in crate::compute) fn refresh( &mut self, tables: &DispatchTables<'_>, maps: &SamplerMaps, - (changed, samplers, trimmed): (u64, &[SamplerState], bool), + (changed, samplers): (u64, &mut ArgumentSamplers), function_tables: &[VisibleFunctionTable], counts: Counting<'_>, ) -> ValueKinds { @@ -251,13 +252,15 @@ impl LiveDispatch { } self.read_from.resident = Some(generation); // Listed again only where the device's sampler states changed since: not where the - // listing kept is of every live state at the count of their slots' changes they were taken - // at; else they are compared state by state. - if trimmed || self.listed_at != Some(changed) { - if !heap_sets::lists(&state.argument_samplers, samplers) { - reshape.field(&mut state.argument_samplers, heap_sets::listed(samplers)); + // listing kept is of every live state at the count of their slots' changes that holds; + // else they are taken and compared state by state. + let current = samplers.states().is_none() && self.listed_at == Some(changed); + if !current { + let states = samplers.take(tables.pipeline.generation()); + if !heap_sets::lists(&state.argument_samplers, states) { + reshape.field(&mut state.argument_samplers, heap_sets::listed(states)); } - self.listed_at = (!trimmed).then_some(changed); + self.listed_at = samplers.listed_at(); } let listed = function_tables .iter() @@ -271,7 +274,7 @@ impl LiveDispatch { reshape.unshaped(&mut state.used_in_token_order, true); reshape.unshaped(&mut state.resident_apart, true); #[cfg(debug_assertions)] - self.check_whole(tables, maps, samplers, function_tables); + self.check_whole(tables, maps, samplers.states(), function_tables); if reshape.may_reshape() { self.shape = None; } @@ -283,16 +286,16 @@ impl LiveDispatch { /// and parked (the module docs, **Parked in its command buffer**), serves a direct dispatch of /// `tables` and `dispatch` at `counted` moves and sampler slot changes: it holds in every /// input but its table's stamp (`DispatchMemo::holds_but_stamp`), and the table, read now with - /// its samplers' maps and `listing` (the device's sampler states at their count of changes), - /// brings in the very state it settled, no value of any kind changed, with the samplers' maps - /// it was settled with. Then it goes on under the table's stamp ([`Across::Taken`]). Where the + /// its samplers' maps and the device's sampler states `samplers` takes where it needs them + /// ([`refresh`](Self::refresh)), brings in the very state it settled, no value of any kind + /// changed, with the samplers' maps it was settled with. Then it goes on under the table's stamp ([`Across::Taken`]). Where the /// entry holds but for the stamp, the state is brought in place either way, and a dispatch that /// takes it not settles from the state as it lies ([`Across::Refreshed`]). pub(in crate::compute) fn settled_across( &mut self, tables: &DispatchTables<'_>, (dispatch, counted): (&Dispatch, (u64, u64)), - listing: (u64, &[SamplerState]), + samplers: &mut ArgumentSamplers, function_tables: &[VisibleFunctionTable], counts: Counting<'_>, ) -> Result { @@ -300,8 +303,7 @@ impl LiveDispatch { return Ok(Across::Missed); } let maps = tables.sampler_maps()?; - let (changed, samplers) = listing; - let listing = (changed, samplers, false); + let listing = (counted.1, &mut *samplers); let moved = self.refresh(tables, &maps, listing, function_tables, counts); let same = moved == ValueKinds::default() && (self.memo.entry()).is_some_and(|kept| kept.settled.sampler_maps == maps); @@ -313,23 +315,26 @@ impl LiveDispatch { .is_some_and(|kept| *kept.settled.planned.shape == self.state.shape()), "a parked dispatch memo taken for a state of another shape" ); - self.memo.restamp(tables.table.stamp(), samplers); + let device = tables.pipeline.generation(); + self.memo.restamp(tables.table.stamp(), (samplers, device)); Ok(Across::Taken) } /// That the state brought in place is the one a dispatch of `tables` makes whole /// (`DispatchTables::bind_state` with `maps` applied), field by field (debug builds): the /// kernel's table as `ArgumentTable::check_reading` compares it (a float's sign told apart, - /// every NaN alike), and every other field equal. + /// every NaN alike), the argument samplers as `samplers` lists them where the dispatch took + /// the device's (else the kept listing is of every live state at the count that holds), and + /// every other field equal. #[cfg(debug_assertions)] fn check_whole( &self, tables: &DispatchTables<'_>, maps: &SamplerMaps, - samplers: &[SamplerState], + samplers: Option<&[SamplerState]>, function_tables: &[VisibleFunctionTable], ) { - let mut whole = tables.bind_state(samplers, function_tables); + let mut whole = tables.bind_state(samplers.unwrap_or_default(), function_tables); maps.apply(&mut whole); let state = &self.state; let kept = &state.stages[&Stage::Kernel]; @@ -342,7 +347,7 @@ impl LiveDispatch { "{DIFFERS}: its threadgroup lengths" ); assert!( - heap_sets::lists(&state.argument_samplers, samplers), + samplers.is_none_or(|samplers| heap_sets::lists(&state.argument_samplers, samplers)), "{DIFFERS}: its argument samplers" ); // Every other field equal, the table and the listing compared above, as their values diff --git a/crates/metal2vulkan-runtime/src/sampler.rs b/crates/metal2vulkan-runtime/src/sampler.rs index a1b1ac1f5..e16139040 100644 --- a/crates/metal2vulkan-runtime/src/sampler.rs +++ b/crates/metal2vulkan-runtime/src/sampler.rs @@ -931,9 +931,9 @@ impl Device { (changed, states.into_iter().map(SamplerState).collect()) } - /// [`argument_samplers_at`](Self::argument_samplers_at), for a draw's listing: counted - /// (`WorkCounts::argument_samplers_taken`). - fn argument_samplers_for_draw(&self) -> (u64, Vec) { + /// [`argument_samplers_at`](Self::argument_samplers_at), for a draw's or a compute encoder's + /// dispatch's listing: counted (`WorkCounts::argument_samplers_taken`). + fn argument_samplers_for_listing(&self) -> (u64, Vec) { self.shared().counts.argument_samplers_taken(); self.argument_samplers_at() } @@ -949,11 +949,12 @@ impl crate::device::DeviceShared { } } -/// The device's live sampler states a draw lists (`BindState::argument_samplers`), each at the -/// heap element of its resource ID, taken from the device only where the draw needs them -/// (`RenderCommandEncoder::settle_draw`): a kept bind state listed at the count of the sampler -/// IDs' slots' changes that still holds lists them already (`LiveBind::listed_at`), and a draw -/// that writes no heap element and names no state in a notice takes none. +/// The device's live sampler states a draw or a compute encoder's dispatch lists +/// (`BindState::argument_samplers`), each at the heap element of its resource ID, taken from the +/// device only where it needs them (`RenderCommandEncoder::settle_draw`, `compute::settle_live`): +/// a kept bind state listed at the count of the sampler IDs' slots' changes that still holds lists +/// them already (`LiveBind::listed_at`, `compute/live.rs`'s `LiveDispatch::listed_at`), and a +/// command that writes no heap element and names no state in a notice takes none. pub(super) struct ArgumentSamplers { /// The states and the count of slot changes they were live at, once taken. taken: Option<(u64, Vec)>, @@ -974,7 +975,7 @@ impl ArgumentSamplers { /// `device`'s, taken now. pub(super) fn taken(device: &Device) -> ArgumentSamplers { ArgumentSamplers { - taken: Some(device.argument_samplers_for_draw()), + taken: Some(device.argument_samplers_for_listing()), trimmed: false, } } @@ -983,7 +984,7 @@ impl ArgumentSamplers { pub(super) fn take(&mut self, device: &Device) -> &mut Vec { let (_, states) = self .taken - .get_or_insert_with(|| device.argument_samplers_for_draw()); + .get_or_insert_with(|| device.argument_samplers_for_listing()); states } @@ -992,6 +993,16 @@ impl ArgumentSamplers { self.taken.as_ref().map(|(_, states)| &states[..]) } + /// The count of slot changes the states were live at, where they were taken. + pub(super) fn taken_at(&self) -> Option { + self.taken.as_ref().map(|(changed, _)| *changed) + } + + /// The states, where they were taken: what a command that settled with them binds. + pub(super) fn into_states(self) -> Option> { + self.taken.map(|(_, states)| states) + } + /// The count of slot changes every live state is listed at: where the states were taken /// and not trimmed. pub(super) fn listed_at(&self) -> Option { diff --git a/crates/metal2vulkan-runtime/src/tests/compute_sampler_listing.rs b/crates/metal2vulkan-runtime/src/tests/compute_sampler_listing.rs new file mode 100644 index 000000000..93b6f96a5 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/compute_sampler_listing.rs @@ -0,0 +1,90 @@ +//! A compute encoder's dispatches take the device's live sampler states to list only where they +//! changed since the listing their encoder's bind state keeps, as draws do +//! (`sampler::ArgumentSamplers`, `WorkCounts::argument_samplers_taken`): a kernel whose variant has +//! no set-1 arrays, dispatched with a constant of its own each time (so no memo entry holds), +//! takes none while no sampler state is made or goes, beside eight a program keeps alive; a state +//! made between two dispatches, and that state gone, each make the next dispatch take them once. +//! Every dispatch writes its own words, read back against Metal's answer. +//! +//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, +//! `m2v_cpu_icd`), on the kind of device the cfg selects. The kernel is `grid_classes`'s `flat2d` +//! (`llvm-as`). + +use super::blit_holds::{device, Scratch, WAIT}; +use super::grid_classes::{state, FLAT}; +use super::opencl_mode::{words, words_buffer}; +use crate::{CommandBufferStatus, Size}; +use metal2vulkan::bind::SamplerDescriptor; + +/// The dispatches of the encoder. +const DISPATCHES: usize = 9; + +/// The words each dispatch has to itself. +const WORDS: usize = 64; + +/// The threads of each dispatch's ragged grid of one row. +const THREADS: u32 = 37; + +/// What a word holds before a dispatch writes it. +const UNWRITTEN: u32 = u32::MAX; + +#[test] +fn dispatches_take_the_device_s_sampler_states_only_where_they_changed() { + let scratch = Scratch::new("compute-sampler-listing"); + let device = device(&scratch.0); + let state = state(&device, FLAT, "flat2d"); + // A program's sampler states, alive through the dispatches. + let _kept: Vec<_> = (0..8) + .map(|n| { + let mut descriptor = SamplerDescriptor::new(); + descriptor.lod_max_clamp = 1.0 + n as f32; + device.new_sampler_state(&descriptor).unwrap() + }) + .collect(); + let out = words_buffer(&device, &vec![UNWRITTEN; WORDS * DISPATCHES]); + let queue = device.new_command_queue().unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut encoder = command_buffer.compute_command_encoder().unwrap(); + encoder.set_compute_pipeline_state(&state).unwrap(); + let taken = || device.work_counts().argument_samplers_taken; + let mut counts = Vec::new(); + let mut made = None; + for n in 0..DISPATCHES { + // A sampler state made before dispatch 3, gone before dispatch 6. + if n == 3 { + let mut descriptor = SamplerDescriptor::new(); + descriptor.lod_max_clamp = 99.0; + made = Some(device.new_sampler_state(&descriptor).unwrap()); + } + if n == 6 { + made = None; + } + let before = taken(); + let k = n as u32 + 1; + encoder + .set_buffer(Some(&out), (n * WORDS * 4) as u64, 0) + .unwrap(); + encoder.set_bytes(&k.to_le_bytes(), 1).unwrap(); + let grid = Size::new(u64::from(THREADS), 1, 1); + encoder.dispatch_threads(grid, Size::new(64, 1, 1)).unwrap(); + counts.push(taken() - before); + } + assert!(made.is_none()); + encoder.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + // The first dispatch settles the encoder's state from none, and may take them. + assert_eq!(counts[1..], [0, 0, 1, 0, 0, 1, 0, 0], "{counts:?}"); + let written = words(&out); + for n in 0..DISPATCHES { + let k = n as u32 + 1; + let want: Vec = (0..WORDS as u32) + .map(|i| match i < THREADS { + true => 3 * i + k, + false => UNWRITTEN, + }) + .collect(); + assert_eq!(written[n * WORDS..(n + 1) * WORDS], want, "dispatch {n}"); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/grid_classes.rs b/crates/metal2vulkan-runtime/src/tests/grid_classes.rs index 2c8612b80..757fe8b2b 100644 --- a/crates/metal2vulkan-runtime/src/tests/grid_classes.rs +++ b/crates/metal2vulkan-runtime/src/tests/grid_classes.rs @@ -31,7 +31,7 @@ use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource}; /// `flat2d(device uint *out [[buffer(0)]], constant uint &k [[buffer(1)]], uint2 gid /// [[thread_position_in_grid]], uint2 size [[threads_per_grid]])`: `out[gid.y * size.x + gid.x] = /// 3 * (gid.y * size.x + gid.x) + k`. It observes no threadgroup partition. -const FLAT: &str = r#"target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" +pub(super) const FLAT: &str = r#"target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" target triple = "air64_v28-apple-macosx26.0.0" define void @flat2d(ptr addrspace(1) noundef %out, ptr addrspace(2) noundef %k, <2 x i32> noundef %gid, <2 x i32> noundef %size) { @@ -137,7 +137,7 @@ impl Grid { } /// The state of the kernel `name` of `text` on `device`. -fn state(device: &Device, text: &str, name: &str) -> ComputePipelineState { +pub(super) fn state(device: &Device, text: &str, name: &str) -> ComputePipelineState { let air = metal2vulkan_devtools::llvm_assemble_text(text).unwrap(); let library = metal2vulkan::library::Library::from_air(&air).unwrap(); let function = device diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index ab1fbd921..ce5fd08b2 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -95,6 +95,8 @@ mod compute_create_bench; mod compute_instantiated; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod compute_parked; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod compute_sampler_listing; mod contexts; mod copied; #[cfg(any(m2v_gpu, m2v_cpu_icd))] diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index 165cb252c..7260f9611 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -8708,10 +8708,13 @@ pub struct WorkCounts { /// per table looked for at each draw and tile dispatch (`heap_sets::texture_table`, /// `sampler_table`). pub heap_tables_worked_out: u64, - /// Draws (and commands of other encoders that settle as draws do) that took the device's - /// live sampler states to list as their argument samplers: none for a draw whose kept bind - /// state lists them at the count of their slots' changes that still holds, whose variant has - /// no set-1 arrays and names no state in a notice (`sampler::ArgumentSamplers`). + /// Draws (and commands of other encoders that settle as draws do) and compute encoders' + /// dispatches that settled (no memo entry held) that took the device's live sampler states to + /// list as their argument samplers: none for one whose kept bind state lists them at the count + /// of their slots' changes that still holds, whose variant has no set-1 arrays and names no + /// state in a notice (`sampler::ArgumentSamplers`). A compute encoder's dispatch whose memo + /// entry, parked in its command buffer, goes on in the next encoder takes them where that + /// entry's variant has set-1 arrays (`compute::DispatchMemo::restamp`). pub argument_samplers_taken: u64, /// Texture slot views binds worked out: none for a render or compute encoder's bind of a /// texture, as a view, that a bind of the same or an earlier encoder of its kind of the device diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 59c1c88a3..a72fdaa1e 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 = 523; /// 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 = 2364; +pub const RUNTIME_VERSION: u32 = 2365; /// 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