diff --git a/crates/metal2vulkan-runtime/src/render/coverage.rs b/crates/metal2vulkan-runtime/src/render/coverage.rs index 37ea9cf94..21f020f72 100644 --- a/crates/metal2vulkan-runtime/src/render/coverage.rs +++ b/crates/metal2vulkan-runtime/src/render/coverage.rs @@ -71,6 +71,16 @@ pub(crate) struct ReaderKey { ordinal: u32, } +impl ReaderKey { + /// The identity of the reader at `ordinal` among the readers of a texture in a pass of the + /// state at `state` (`GraphicsState::address`): for the crate's device tests, which read its + /// count (`Texture::learned_coverage`). + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn of(state: usize, ordinal: u32) -> ReaderKey { + ReaderKey { state, ordinal } + } +} + /// The counts a texture learned of its readers (`Texture::learned_coverage`), the latest of /// each, [`LEARNED`] at most. #[derive(Debug, Default)] diff --git a/crates/metal2vulkan-runtime/src/tests/fresh_pages.rs b/crates/metal2vulkan-runtime/src/tests/fresh_pages.rs index 485edf028..2788a9497 100644 --- a/crates/metal2vulkan-runtime/src/tests/fresh_pages.rs +++ b/crates/metal2vulkan-runtime/src/tests/fresh_pages.rs @@ -33,10 +33,11 @@ //! counted (`host_texture_shadows_refused_pitch` or `_image`): MoltenVK lays a linear image's //! rows at a pitch of its own and enables no `VK_EXT_image_drm_format_modifier`, so on the M3 Max //! the texture at 512 bytes a row is a shadow and the one at its own pitch an image in place. -//! Every shadow is announced (`shadowed-texture`) with its one cause counted, and an image in -//! place neither. Either way a blit out of it reads the bytes the CPU wrote, and a render pass's -//! clear through it reaches them once the command buffer completed, the bytes between its rows -//! kept. +//! Every shadow has its one cause counted, and is announced (`shadowed-texture`) as it is made: +//! one whose rows lie in place (a refused pitch or image) at the first reach of its image +//! (`texture/lazy_shadow.rs`). An image in place has neither. Either way a blit out of it reads +//! the bytes the CPU wrote, and a render pass's clear through it reaches them once the command +//! buffer completed, the bytes between its rows kept. //! //! Device tests: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). @@ -460,8 +461,11 @@ fn a_texture_over_a_long_buffer_is_its_bytes( after.host_textures_in_place - before.host_textures_in_place, u64::from(in_place) ); - // A shadow is announced, with its one cause counted; an image in place is neither. - assert_eq!(announced, u64::from(shadow), "a shadow is announced"); + // A shadow has its one cause counted (below), and is announced as it is made: one left + // unmade, its rows in place, as a reach makes it (`texture/lazy_shadow.rs`), which none + // does here. An image in place has neither. + let made = after.shadowed_textures - before.shadowed_textures; + assert_eq!(announced, made, "a shadow made is announced"); let one_cause: &[&str] = match (policy, in_place, renders_in_place) { (HostPageTexturePolicy::Shadow, ..) => { assert!(shadow, "a shadow under Shadow"); diff --git a/crates/metal2vulkan-runtime/src/tests/leading_snapshots.rs b/crates/metal2vulkan-runtime/src/tests/leading_snapshots.rs index 38dd0e2d4..c18e4618a 100644 --- a/crates/metal2vulkan-runtime/src/tests/leading_snapshots.rs +++ b/crates/metal2vulkan-runtime/src/tests/leading_snapshots.rs @@ -9,10 +9,10 @@ //! The plane is large enough that the area rule takes the snapshot through its whole scissor, //! as it weighs a leading reader even over a buffer's bytes (`RenderLowering::weigh_snapshot`). //! On a device that measures readers (`occlusionQueryPrecise`, queries reset on the host), a -//! reader's pass after one that measured it is weighed by what it covered there -//! (`render/coverage.rs`; a pass whose readers record once the pool made their pipeline measures -//! none): the reader of the whole plane then splits with the copy, and the reader of a small -//! square, through the same scissor, keeps its leading snapshot. +//! reader whose identity holds a count from a pass that measured it (`Texture::learned_coverage`; +//! a reader recorded once the pool made its pipeline is not measured) is weighed by what it +//! covered there (`render/coverage.rs`): the reader of the whole plane then splits with the copy, +//! and the reader of a small square, through the same scissor, keeps its leading snapshot. //! //! The same passes run again with the leading snapshots withheld too //! (`DeviceShared::leading_snapshots_withheld`): each reader then splits the pass and reads the @@ -30,6 +30,8 @@ use super::blit_holds::{device, Scratch, WAIT}; use super::encoder_holds::{bytes_of, library}; use crate::framebuffer_fetch::through_storage; +use crate::pipeline::RenderStateKind; +use crate::render::coverage::ReaderKey; use crate::{ Buffer, CommandQueue, Device, IoSurfacePlane, LoadAction, PipelineOptions, RenderPassDescriptor, RenderPipelineState, ResourceOptions, ScissorRect, StoreAction, Texture, @@ -61,6 +63,9 @@ const DRAWS: [(u8, std::ops::Range, [f32; 4]); 2] = [ (0x55, 256..768, [-0.5, -0.5, -0.375, -0.375]), ]; +/// The pixels each reader of [`DRAWS`] covers: the whole plane, and the square. +const COVERED: [u64; 2] = [WIDTH * HEIGHT, 64 * 64]; + /// The rows `rows` of the plane, every column, as a scissor. const fn rows(rows: std::ops::Range) -> ScissorRect { ScissorRect { @@ -223,6 +228,15 @@ fn leads(device: &Device) -> bool { device.shared().color_write_masks.is_some() && through_storage(profile) && stores_none } +/// The identities of the readers of [`DRAWS`], in their order, all of the state `read`: its first +/// and second readers of the plane in a pass (`render/coverage.rs`'s `ReaderKey`). +fn reader_keys(read: &RenderPipelineState) -> [ReaderKey; 2] { + let RenderStateKind::Graphics(state) = read.kind() else { + panic!("a tile state of a render descriptor"); + }; + [0, 1].map(|ordinal| ReaderKey::of(state.address(), ordinal)) +} + /// Whether `device` measures readers (`render/coverage.rs`: `occlusionQueryPrecise`, and queries /// reset on the host). fn measures(device: &Device) -> bool { @@ -234,9 +248,11 @@ fn measures(device: &Device) -> bool { /// linear alias of the bytes without feedback loop usage, each pass after a fill of the bytes: /// with leading snapshots where the device takes them, then with them withheld. The passes leave /// Metal's bytes under both; the first run's readers take leading snapshots (no split, no texel -/// copied in) where the device leads, but for the whole plane's reader in a pass after one that -/// measured both readers, which splits by what it covered; every other reader splits the pass. -/// A device that leads and measures readers weighs a pass's readers so at least once. +/// copied in) where the device leads, but for the whole plane's reader once a pass measured it, +/// which splits by what it covered; every other reader splits the pass. Each reader is weighed by +/// the count its identity holds as its pass records, where it holds one, the pixels it covers; +/// the others by the area rule. A device that leads and measures readers weighs a pass's readers +/// so at least once. #[test] fn readers_through_leading_snapshots_leave_the_split_s_bytes() { let scratch = Scratch::new("leading-snapshots"); @@ -257,13 +273,25 @@ fn readers_through_leading_snapshots_leave_the_split_s_bytes() { "the plane's image aliases its bytes (in-place checks settled: {settled})" ); let (leads, measures) = (leads(&device), measures(&device)); + let keys = reader_keys(&tools.read); for withheld in [false, true] { (device.shared().leading_snapshots_withheld).store(withheld, Ordering::Relaxed); - // Three times: the first pass's readers may record once the pool made their pipelines, - // unmeasured (`render/coverage.rs`), the later ones' at once; a pass after one that - // measured both readers weighs them by what they covered. - let (mut measured, mut weighed) = (false, false); + // Three times: a reader of the first pass may record once the pool made its pipeline, + // unmeasured (`render/coverage.rs`), the later ones at once; a reader whose identity holds + // a count, from the pass that last measured it, is weighed by it. The counts of a pass are + // kept as its command buffer completes, before the later command buffers of its queue + // (`command_buffer/mod.rs`): the read-back's, which the bytes waited for. + let mut weighed = false; for round in 0..3 { + let counted = keys.map(|key| texture.learned_coverage(key)); + for (reader, count) in counted.iter().enumerate() { + let want = count.map(|_| COVERED[reader]); + assert_eq!(*count, want, "reader {reader}'s count (round {round})"); + } + assert!( + measures || counted == [None; 2], + "a device that measures no reader holds a count (round {round})" + ); tools.fill(&buffer, BEFORE); let counts = tools.pass(&texture); let pooled = counts.1.pipelines_pooled - counts.0.pipelines_pooled; @@ -271,7 +299,8 @@ fn readers_through_leading_snapshots_leave_the_split_s_bytes() { let took = took(counts); eprintln!( "LEADING-SNAPSHOTS {}: leads {leads}, measures {measures}, withheld {withheld}, \ - round {round}: {took:?}, pipelines pooled {pooled}, coverage queries {queries}", + round {round}: the readers' counts held {counted:?}, {took:?}, pipelines pooled \ + {pooled}, coverage queries {queries}", device.name() ); let left = tools.bytes(&buffer); @@ -280,12 +309,15 @@ fn readers_through_leading_snapshots_leave_the_split_s_bytes() { differs, None, "the first byte the readers left otherwise (withheld {withheld}, round {round})" ); - // The readers that split: none, or the whole plane's once it was measured (all of its - // pixels, beyond the area rule's bound: the small square's are within it), or both. - let (leading, by_coverage, shares) = match (leads && !withheld, measured) { - (true, true) => (1, 2, [1, 0, 1]), - (true, false) => (2, 0, [0; 3]), - (false, _) => (0, 0, [0; 3]), + // The readers that split: none, or the whole plane's where its identity held a count + // (all of its pixels, beyond the area rule's bound: the small square's are within it), + // or both. + let (leading, by_coverage, shares) = match leads && !withheld { + true => { + let [plane, square] = counted.map(|count| u64::from(count.is_some())); + (2 - plane, plane + square, [square, 0, plane]) + } + false => (0, 0, [0; 3]), }; let form = Took { leading, @@ -304,7 +336,13 @@ fn readers_through_leading_snapshots_leave_the_split_s_bytes() { "the splits' copies moved texels, and only theirs (round {round})" ); weighed |= by_coverage > 0; - measured = queries == 2; + if queries == 2 { + assert!( + keys.iter() + .all(|&key| texture.learned_coverage(key).is_some()), + "a pass measured both readers, yet an identity holds no count (round {round})" + ); + } } assert_eq!( weighed, diff --git a/crates/metal2vulkan-runtime/src/tests/spares_parts.rs b/crates/metal2vulkan-runtime/src/tests/spares_parts.rs index 687e1a9ce..a32d9bf72 100644 --- a/crates/metal2vulkan-runtime/src/tests/spares_parts.rs +++ b/crates/metal2vulkan-runtime/src/tests/spares_parts.rs @@ -2,9 +2,11 @@ //! compute encoders that each wait for a fence the one before updated, so none records on in the //! one before's `VkCommandBuffer` (`encoder_fold.rs`) and the scheduler records a command buffer //! of barriers before each, many in flight, of a count of encoders that varies from one to the -//! next (`spares.rs`): a guest's command buffers split into parts. Once each count ran with as -//! many in flight, the spares hold what they take: the command buffers made stay flat, and they -//! hold about what is in use at once; once the load falls, they shed down to it. +//! next (`spares.rs`): a guest's command buffers split into parts. The device makes command +//! buffers only as far as the most the load had in use at once needs, with what the pools out +//! of the spares may hold unused: once warm, more are made only for a later, larger peak, and the +//! spares free none and hold about what is in use at once; once the load falls, they shed down to +//! it. //! //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`). The kernel is `scale_and_offset` of the owned fixture @@ -17,6 +19,7 @@ use crate::{ Buffer, CommandBuffer, CommandQueue, ComputePipelineState, Device, PipelineOptions, ResourceOptions, Size, }; +use std::collections::BTreeMap; use std::sync::mpsc; use std::time::{Duration, Instant}; @@ -89,36 +92,49 @@ impl Load { /// `count` command buffers of `encoders(index)` encoders each, at most `in_flight` of them /// committed whose pools are not yet given back, then every one's given back, and the frees - /// their give-backs posted. A completed handler runs once its command buffer's pools went back - /// to the spares (`command_buffer/mod.rs`), so each is counted by its handler: a command - /// buffer's completion seen by a waiter may come before its give-back. - fn run(&self, count: usize, in_flight: usize, encoders: impl Fn(usize) -> usize) { + /// their give-backs posted; and the most they held at once ([`Peak`]). A completed handler + /// runs once its command buffer's pools went back to the spares (`command_buffer/mod.rs`), so + /// each is counted by its handler: a command buffer's completion seen by a waiter may come + /// before its give-back. As each command buffer is encoded, those committed whose handler had + /// not run as it began, with it, hold at least what is in use until the next begins: those + /// before it only complete meanwhile. + fn run(&self, count: usize, in_flight: usize, encoders: impl Fn(usize) -> usize) -> Peak { let (given, back) = mpsc::channel(); - let mut out = 0; + let mut out = BTreeMap::new(); + let mut peak = Peak::default(); for index in 0..count { - let command_buffer = self.encoded(encoders(index)); + while let Ok(done) = back.try_recv() { + out.remove(&done); + } + let encoders = encoders(index); + let before = out.values().copied().map(primaries).sum::(); + peak = peak.max(Peak { + alive: out.len() + 1, + primaries: before + primaries(encoders), + }); + let command_buffer = self.encoded(encoders); let given = given.clone(); (command_buffer.add_completed_handler(Box::new(move |_: &CommandBuffer| { - let _ = given.send(()); + let _ = given.send(index); }))) .unwrap(); command_buffer.commit().unwrap(); - out += 1; - while out > in_flight { - back.recv_timeout(WAIT).unwrap(); - out -= 1; + out.insert(index, encoders); + while out.len() > in_flight { + out.remove(&back.recv_timeout(WAIT).unwrap()); } } - for _ in 0..out { - back.recv_timeout(WAIT).unwrap(); + while !out.is_empty() { + out.remove(&back.recv_timeout(WAIT).unwrap()); } self.device.shared().frees.drain(); + peak } /// A round of [`ROUND`] command buffers of [`PARTS`] encoders in turn, [`IN_FLIGHT`] in - /// flight. - fn round(&self) { - self.run(ROUND, IN_FLIGHT, |index| PARTS[index % PARTS.len()]); + /// flight, and the most they held at once. + fn round(&self) -> Peak { + self.run(ROUND, IN_FLIGHT, |index| PARTS[index % PARTS.len()]) } /// The command buffers and command pools the device made so far, the command buffers the @@ -141,60 +157,96 @@ impl Load { /// The command buffers holding their pools at once: [`IN_FLIGHT`] committed, and the one encoding. const ALIVE: usize = IN_FLIGHT + 1; +/// The most a run's command buffers held at once ([`Load::run`]). +#[derive(Clone, Copy, Debug, Default)] +struct Peak { + /// The command buffers holding their pools: those committed whose completed handler had not + /// run, and the one encoding. + alive: usize, + /// The primaries those have in use, at most ([`primaries`]). + primaries: usize, +} + +impl Peak { + /// The larger of each. + fn max(self, other: Peak) -> Peak { + Peak { + alive: self.alive.max(other.alive), + primaries: self.primaries.max(other.primaries), + } + } +} + +/// At most the primaries a command buffer of `encoders` of the load's encoders has in use: each +/// encoder's own and one of barriers before it, and the batch's own and its first's. +fn primaries(encoders: usize) -> usize { + 2 * encoders + 2 +} + /// At most the primaries the load has in use at once, of [`ALIVE`] command buffers of [`PARTS`] -/// encoders in turn, the largest counts together: each encoder's own and one of barriers before -/// it, and the batch's own and its first's. +/// encoders in turn, the largest counts together ([`primaries`]). fn in_use() -> usize { - let each = |encoders: usize| 2 * encoders + 2; let mut largest = PARTS; largest.sort_unstable_by(|a, b| b.cmp(a)); - let whole = ALIVE / PARTS.len() * PARTS.iter().map(|&n| each(n)).sum::(); + let whole = ALIVE / PARTS.len() * PARTS.iter().copied().map(primaries).sum::(); whole + largest[..ALIVE % PARTS.len()] .iter() - .map(|&n| each(n)) + .copied() + .map(primaries) .sum::() } -/// Once each count ran with as many in flight, the spares hold what the load takes: the command -/// buffers made stay flat, and the spares free none. The most the load takes at once follows the -/// threads' timing, so a later peak may still make a few: fewer than one a command buffer of a -/// round ([`ROUND`]) over the measured rounds here, where none were made after the fourth round -/// in three release runs and after the sixth in a debug one, and sections that took no spare -/// made about 60 a round (lavapipe). And the spares hold at most what the load has in use at once, with what the pools -/// out may hold unused as a command buffer is made: a command buffer takes a pool only once the -/// pools it took handed out every one of the level they held, so only its last may hold some -/// unused, at most [`POOL_HOLDS`]; and each pool holds a primary begun ahead and a secondary -/// besides. Before, the barriers' command buffers, recorded in a section of the exit guard, took -/// no spare, and a command buffer made what it lacked in its first pool until it had handed out -/// 16: the pools grew past what was in use at once to the bound, and each give-back shed the -/// oldest whole, which the next takers made again (the module docs of `spares.rs`). +/// After every round, the command buffers the device holds (made, less those the spares freed) are +/// at most the primaries the load had in use at once so far, by the most its command buffers +/// held at once that the test saw ([`Peak`]), with what the pools out of the spares may hold +/// unused as a command buffer is made: the device makes one only where no spare holds one of +/// its level, and a command buffer takes a pool only once the pools it took handed out every one +/// of the level they held, so only its last may hold some unused, at most [`POOL_HOLDS`]; and +/// each pool holds a primary begun ahead and a secondary besides. The most the load has in use at +/// once follows the threads' timing, as a busier device keeps more in flight: once warm, more are +/// made only as a later peak needs them, where the bound grows with it. Once warm, the spares free +/// none. And the spares hold at most what the load can have in use at once ([`in_use`]), with what +/// the pools out may hold unused. Before, the barriers' command buffers, recorded in a section of +/// the exit guard, took no spare, and a command buffer made what it lacked in its first pool until +/// it had handed out 16: the pools grew past what was in use at once to the bound, and each +/// give-back shed the oldest whole, which the next takers made again (the module docs of +/// `spares.rs`). #[test] fn fenced_command_buffers_in_flight_stay_flat_once_warm() { let scratch = std::env::temp_dir().join(format!("m2v-spares-parts-{}", std::process::id())); std::fs::create_dir_all(&scratch).unwrap(); let load = Load::new(device(&scratch)); let mut rounds = Vec::new(); + let mut peak = Peak::default(); for _ in 0..WARM + MEASURED { - load.round(); - rounds.push(load.counts()); + peak = peak.max(load.round()); + let (made, pools, held, freed) = load.counts(); + rounds.push((made, pools, held, freed, peak.alive, peak.primaries)); } - let (warm, _, _, freed_warm) = rounds[WARM - 1]; - let (made, pools, after, freed) = *rounds.last().unwrap(); - let bound = in_use() + ALIVE * POOL_HOLDS + 2 * pools as usize; + let (warm, _, _, freed_warm, _, _) = rounds[WARM - 1]; + let (made, pools, after, freed, _, _) = *rounds.last().unwrap(); + let unused = |pools: u64| ALIVE * POOL_HOLDS + 2 * pools as usize; + let bound = in_use() + unused(pools); println!( "SPARES-PARTS {}: rounds of {ROUND} command buffers of {PARTS:?} fenced encoders, \ {IN_FLIGHT} in flight: command buffers made, command pools made, command buffers the \ - spares hold and those they freed after each {rounds:?}; at most {} in use at once, the \ - bound {bound}", + spares hold and those they freed after each, and the most command buffers alive at once \ + and the primaries they had in use so far {rounds:?}; {} made once warm; at most {} in \ + use at once, the bound {bound}", load.device.name(), + made - warm, in_use() ); - assert!( - made - warm < ROUND as u64, - "{} command buffers made once warm", - made - warm - ); + for (round, &(made, pools, _, freed, _, needed)) in rounds.iter().enumerate() { + let holds = made - freed.iter().sum::(); + let most = needed + unused(pools); + assert!( + holds <= most as u64, + "after round {round} the device holds {holds} command buffers, past the {needed} \ + primaries the load had in use at once and what the pools may hold unused ({most})" + ); + } assert!(after <= bound, "the spares hold {after}, past {bound}"); assert_eq!( freed, freed_warm, diff --git a/crates/metal2vulkan-validation/src/parity/runtime.rs b/crates/metal2vulkan-validation/src/parity/runtime.rs index a1df944e2..799cfa702 100644 --- a/crates/metal2vulkan-validation/src/parity/runtime.rs +++ b/crates/metal2vulkan-validation/src/parity/runtime.rs @@ -1,11 +1,13 @@ //! The runtime's side of the parity harness: [`Api`] on `metal2vulkan_runtime`, on the device -//! the lane's cfg selects, under the validation layer (`runtime_lane::validated_device`). +//! the lane's cfg selects, under the validation layer (`runtime_lane::validated_device_with`), at +//! its queue plan (`runtime_lane::at_plan`): a fixture's command queues are its own, as many as +//! it asks for, and the lane's queue limits would change the second one's placement. use super::api::{Answer, Api, Completion, Fixture, Layout, Refused, Region, Times}; use super::record::Refusal; use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; -use crate::runtime_lane::{validated_device, Messages, ScratchCache}; +use crate::runtime_lane::{at_plan, validated_device_with, Messages, ScratchCache}; use metal2vulkan_runtime::{ BlitCommandEncoder, BlitOption, Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputeCommandEncoder, ComputePipelineState, Device, Error, EventRef, Fence, PipelineOptions, @@ -29,7 +31,7 @@ impl RuntimeApi { pub(crate) fn open() -> Result { let cache = ScratchCache::new().map_err(|error| error.to_string())?; let messages = Messages::default(); - let device = validated_device(TEST_DEVICE, &messages, cache.path())?; + let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), at_plan)?; Ok(RuntimeApi { device, messages, diff --git a/crates/metal2vulkan-validation/src/parity/sequences/runtime.rs b/crates/metal2vulkan-validation/src/parity/sequences/runtime.rs index d6faad5bb..a92299eae 100644 --- a/crates/metal2vulkan-validation/src/parity/sequences/runtime.rs +++ b/crates/metal2vulkan-validation/src/parity/sequences/runtime.rs @@ -14,7 +14,7 @@ use super::run::{pixel_format, swizzle}; use super::FIXTURE; use crate::air_library::AirLibrary as _; use crate::gpu::TEST_DEVICE; -use crate::runtime_lane::{validated_device_with, LaneChecks, Messages, ScratchCache}; +use crate::runtime_lane::{at_plan, validated_device_with, LaneChecks, Messages, ScratchCache}; use ash::vk::Handle as _; use metal2vulkan::metal::{ BarrierScope, DispatchType, PixelFormat, PrimitiveType, RenderStages, TextureType, @@ -80,7 +80,10 @@ impl RuntimeSeq { fn open_checked(checks: Option) -> Result { let cache = ScratchCache::new().map_err(|error| error.to_string())?; let messages = Messages::default(); + // A program's command queues are its own, as many as it asks for: the lane's queue limits + // would change the second one's placement, so the device takes its plan. let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |options| { + at_plan(options); if let Some(checks) = checks { checks.apply(options); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane.rs b/crates/metal2vulkan-validation/src/runtime_lane.rs index 5143ae68b..d513bd5f8 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane.rs @@ -1864,13 +1864,25 @@ fn case_bound_value_kinds(device: &Device, case: &PublicCase) -> BTreeSet BTreeSet { let shared = degrade_notices::shared_in_system_memory(device); - degrade_notices::forced(&[(Degradation::SharedInSystemMemory, shared)]) + let staged = device.work_counts().icb_records_staged_accesses; + if device.properties().has_unified_memory { + assert_eq!(staged, 0, "unified memory stages no records"); + } + degrade_notices::forced(&[ + (Degradation::SharedInSystemMemory, shared), + (Degradation::StagedIndirectRecords, staged > 0), + ]) } /// Whether `got`, a `float` channel a module converted from a texel's codes, holds as Metal's diff --git a/crates/metal2vulkan-validation/src/runtime_lane/compute_inherited_buffers.rs b/crates/metal2vulkan-validation/src/runtime_lane/compute_inherited_buffers.rs index 36a020403..ab90a0db9 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/compute_inherited_buffers.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/compute_inherited_buffers.rs @@ -33,7 +33,7 @@ use metal2vulkan::metal::{DispatchType, IndirectCommandType, ResourceUsage}; use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource}; use metal2vulkan_devtools::{engine_dir, llvm_assemble}; use metal2vulkan_runtime::{ - ComputePipelineState, Device, DeviceOptions, HeapDescriptor, HeapType, + CommandQueue, ComputePipelineState, Device, DeviceOptions, HeapDescriptor, HeapType, IndirectCommandBufferDescriptor, Library, PipelineOptions, ResourceOptions, Size, }; @@ -117,11 +117,15 @@ const GIVEN: Encoding = Encoding { /// `writer` (`cid_encode`) writes [`COMMANDS`] commands into a buffer that inherits the encoder's /// state and buffers, then an encoder executes them as `encoding` says with `count` (`cid_count`) -/// and its buffers: what `sums` holds, the records the host read across the run, whether the -/// command buffer ran a flat variant (the GPU alone's execution record), the host steps recorded, -/// and the pipeline barriers recorded. +/// and its buffers, in a command buffer of `queue`: what `sums` holds, the records the host read +/// across the run, whether the command buffer ran a flat variant (the GPU alone's execution +/// record), the host steps recorded, and the pipeline barriers recorded. A test's runs share its +/// one queue, whose kept barriers its first run records (`dispatch_executions::own_barriers`): a +/// command queue of each run's own, at the device's queue plan, may take a `VkQueue` of its own, +/// whose kept barriers each run would record again. fn run( device: &Device, + queue: &CommandQueue, (writer, count): (&ComputePipelineState, &ComputePipelineState), encoding: Encoding, ) -> (Vec, (u64, bool, u64, u64)) { @@ -153,7 +157,6 @@ fn run( let multiplier = buffer_with(device, &at(MULTIPLIER_AT, &words([MULTIPLIER]))).unwrap(); // The execution range (location 0, length `COMMANDS`) a ranged execution reads. let range = buffer_with(device, &words([0, COMMANDS as u32])).unwrap(); - let queue = device.new_command_queue().unwrap(); let command_buffer = queue.command_buffer().unwrap(); let before = device.work_counts(); let barriers_before = barriers(device); @@ -225,8 +228,9 @@ fn inherited_buffers_dispatch_on_the_gpu_alone() { &state(device, &library, "cid_encode"), &state(device, &library, "cid_count"), ); - let (cold, (read, flat, _, _)) = run(device, states, GIVEN); - let (sums, (read_warm, flat_warm, steps, _)) = run(device, states, GIVEN); + let queue = device.new_command_queue().unwrap(); + let (cold, (read, flat, _, _)) = run(device, &queue, states, GIVEN); + let (sums, (read_warm, flat_warm, steps, _)) = run(device, &queue, states, GIVEN); let counted = (read_warm, flat_warm, steps); let notices = messages.take_notices(); assert_eq!( @@ -265,17 +269,18 @@ fn a_host_step_orders_the_commands_by_their_barriers_alone() { &state(device, &library, "cid_encode"), &state(device, &library, "cid_count"), ); + let queue = device.new_command_queue().unwrap(); let mut taken = Vec::new(); for dispatch_type in [DispatchType::Serial, DispatchType::Concurrent] { let encoding = Encoding { dispatch_type, ranged: true, }; - let (cold, _) = run(device, states, encoding); + let (cold, _) = run(device, &queue, states, encoding); assert_eq!(cold, expected(), "{dispatch_type:?}: the first run"); let at = format!("{dispatch_type:?}"); taken.push(own_barriers(device, &at, || { - let (sums, (_, flat, steps, barriers)) = run(device, states, encoding); + let (sums, (_, flat, steps, barriers)) = run(device, &queue, states, encoding); assert_eq!(sums, expected(), "{at}"); assert_eq!((flat, steps), (false, 1), "{at}: in the host step"); barriers diff --git a/crates/metal2vulkan-validation/src/runtime_lane/pooled_cells.rs b/crates/metal2vulkan-validation/src/runtime_lane/pooled_cells.rs index 9fe5ac9e5..c1d9aef98 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/pooled_cells.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/pooled_cells.rs @@ -17,8 +17,8 @@ //! what each word is. Every answer is a small integer or a half, exact in `float`. use super::{ - buffer_with, layer_reported_nothing_at_all, read_buffer, validated_device_with, Messages, - ScratchCache, WAIT, + at_plan, buffer_with, layer_reported_nothing_at_all, read_buffer, validated_device_with, + Messages, ScratchCache, WAIT, }; use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; @@ -162,7 +162,9 @@ fn pointers_a_closure_array_holds_answer_as_metal() { let messages = Messages::default(); let cache = ScratchCache::new().unwrap(); { - let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |_| {}).unwrap(); + // A command queue for each dispatch: the lane's queue limits would change the second + // one's placement, so the device takes its plan. + let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), at_plan).unwrap(); check( "pooled_closures", &dispatched(&device, "pooled_closures", None, &[]), diff --git a/crates/metal2vulkan-validation/src/runtime_lane/render_executions.rs b/crates/metal2vulkan-validation/src/runtime_lane/render_executions.rs index 0cde055e4..d6c6dbec6 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/render_executions.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/render_executions.rs @@ -39,9 +39,7 @@ //! over the `Private` buffer its color target lies over), reading it as it stood before. use super::apart_writes::{layer_reported_nothing_but_apart_writes, NotedWrites}; -use super::degrade_notices::{ - assert_made_once, forced, made_render_kinds, on_device, on_device_with, shared_in_system_memory, -}; +use super::degrade_notices::{assert_made_once, made_render_kinds, on_device, on_device_with}; use super::indirect_command_buffers::{render_template_descriptor, render_template_state}; use super::indirect_host_steps::{self, complete, param, HOST_STEPS}; use super::patch_indices::Lane; @@ -277,15 +275,13 @@ pub(super) fn pass() -> RenderPassDescriptor { } /// The kinds a test's steps force beside its own, where the device has not announced them: the -/// makings of the pipeline states of `made`, and the `Shared` buffers' system memory. +/// makings of the pipeline states of `made`, and what its `Shared` storage forces +/// ([`shared_kinds`](super::shared_kinds)). pub(super) fn forced_with( device: &Device, made: &[metal2vulkan::pipeline::RenderPipelineDescriptor], ) -> std::collections::BTreeSet { - let mut kinds = forced(&[( - Degradation::SharedInSystemMemory, - shared_in_system_memory(device), - )]); + let mut kinds = super::shared_kinds(device); for descriptor in made { kinds.extend(made_render_kinds(device, descriptor)); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/shader_stencil.rs b/crates/metal2vulkan-validation/src/runtime_lane/shader_stencil.rs index 955b5101a..5fae0b563 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/shader_stencil.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/shader_stencil.rs @@ -44,7 +44,6 @@ //! shadow's plan binds a neutral its state's creation made; beside a stencil, the shadow's run is //! one of another shape, whose render pass, framebuffer and shadow the host step makes. -use super::degrade_notices::shared_in_system_memory; use super::degrade_notices::{assert_made_once, forced, made_compute_kinds, made_render_kinds}; use super::{ buffer_with, layer_reported_nothing_at_all, read_buffer, validated_device_with, Messages, @@ -732,7 +731,6 @@ fn a_stencil_output_tests_and_writes_the_stencil_as_metal() { .properties() .driver_facts .contains(&DriverFact::DontCareStoreIsMetals); - let system_memory = shared_in_system_memory(&device); let lane = Lane::new(device); if !lane.outputs_stencil() { continue; @@ -788,10 +786,8 @@ fn a_stencil_output_tests_and_writes_the_stencil_as_metal() { Err(error) => panic!("{at} on {name}: {error}"), } // The passes draw from `Shared` buffers. - let mut first = forced(&[ - (Degradation::DontCareStore, dont_care && !dont_care_metals), - (Degradation::SharedInSystemMemory, system_memory), - ]); + let mut first = forced(&[(Degradation::DontCareStore, dont_care && !dont_care_metals)]); + first.extend(super::shared_kinds(&lane.device)); first.extend(made); if shadow && drew { let mut kinds = vec![Degradation::ShaderSideStencil, Degradation::RenderPassSplit]; @@ -846,7 +842,6 @@ fn executed_commands_test_and_write_the_stencil_as_metal() { ); let form = if shadow { "shadow" } else { "export" }; let name = device.name().to_owned(); - let system_memory = shared_in_system_memory(&device); let lane = Lane::new(device); if !lane.outputs_stencil() { continue; @@ -885,7 +880,7 @@ fn executed_commands_test_and_write_the_stencil_as_metal() { true => vec![Degradation::ShaderSideStencil, Degradation::RenderPassSplit], false => Vec::new(), }; - let mut first = forced(&[(Degradation::SharedInSystemMemory, system_memory)]); + let mut first = super::shared_kinds(&lane.device); first.extend(made); let counts = assert_made_once(&messages, &kinds, &first); assert_eq!( @@ -930,7 +925,6 @@ fn a_host_step_s_draw_whose_stencil_output_reaches_no_attachment_binds_the_neutr ); let form = if shadow { "shadow" } else { "export" }; let name = device.name().to_owned(); - let system_memory = shared_in_system_memory(&device); let lane = Lane::new(device); if !lane.outputs_stencil() { continue; @@ -951,7 +945,7 @@ fn a_host_step_s_draw_whose_stencil_output_reaches_no_attachment_binds_the_neutr assert_eq!(color, [COLORS[0]; WIDTH as usize], "{form} on {name}"); // The commands and the buffers are `Shared`. let descriptor = lane.stepped_descriptor(false); - let mut first = forced(&[(Degradation::SharedInSystemMemory, system_memory)]); + let mut first = super::shared_kinds(&lane.device); first.extend(made_render_kinds(&lane.device, &descriptor)); let counts = assert_made_once(&messages, &super::indirect_host_steps::HOST_STEPS, &first); @@ -994,7 +988,6 @@ fn a_host_step_s_run_of_another_shape_makes_its_objects_and_draws() { ); let form = if shadow { "shadow" } else { "export" }; let name = device.name().to_owned(); - let system_memory = shared_in_system_memory(&device); let lane = Lane::new(device); if !lane.outputs_stencil() { continue; @@ -1018,10 +1011,10 @@ fn a_host_step_s_run_of_another_shape_makes_its_objects_and_draws() { // shape splits the pass around the shadow's copies. let descriptor = lane.stepped_descriptor(true); let mut first = forced(&[ - (Degradation::SharedInSystemMemory, system_memory), (Degradation::ShaderSideStencil, shadow), (Degradation::RenderPassSplit, shadow), ]); + first.extend(super::shared_kinds(&lane.device)); first.extend(made_render_kinds(&lane.device, &descriptor)); assert_made_once(&messages, &super::indirect_host_steps::HOST_STEPS, &first); drop(lane);