diff --git a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs index 9ab3aef8a..4776ec8cb 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs @@ -5206,6 +5206,22 @@ impl CommandBufferShared { /// write, or another segment's step waits for the GPU (an indirect dispatch's, a loop's check, /// an execution inside a block of command predication): its gate is every queue's work. pub(crate) fn step_reads(&self, index: usize) -> Option>> { + self.reads_of_step(index, true) + } + + /// What the host step of batch `index` reads on the host of what the GPU may write, as + /// [`step_reads`](Self::step_reads) answers, and also where `commit` could not bound a + /// segment's uses (`Segment::bound`'s `None`: what its recording may use on the GPU is not + /// known): its records and ranges are still all its step reads on the host. For the + /// scheduler's order across queues once the step took its gate (`scheduler/mod.rs`'s + /// `place_of`). `None` where the step waits for more, as there. + pub(crate) fn step_host_reads(&self, index: usize) -> Option>> { + self.reads_of_step(index, false) + } + + /// [`step_reads`](Self::step_reads)'s answer where `bounded`, else + /// [`step_host_reads`](Self::step_host_reads)'s. + fn reads_of_step(&self, index: usize, bounded: bool) -> Option>> { let state = lock(&self.state); let recorded = &state.recorded[state.batch_range(index)]; let mut sparse = recorded.iter().flat_map(|encoder| &encoder.sparse); @@ -5218,7 +5234,9 @@ impl CommandBufferShared { return None; } if segment.steps_after_the_gpu() { - segment.bound.as_ref()?; + if bounded { + segment.bound.as_ref()?; + } reads.extend(segment.work.host_reads()?); } } diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 39ba9662d..f0c46eeb9 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -724,9 +724,10 @@ degradations! { writer wait for it once (where Metal tracks neither, or the step reads more, as \ inside a block of command predication: its command buffer's work before it, and \ every batch submitted before that on any queue); meanwhile the device's other \ - batches go, but for a later one that shares a \ - resource the execution may reach (one made resident, the records), and the first \ - command of a threadgroup size or threadgroup lengths its pipeline state has not \ + batches go, a later commit of another queue going ahead of it but where it writes \ + the records or the range or shares a fence with it (where the step reads more: \ + where it shares a resource the execution may reach, one made resident, the \ + records), and the first command of a threadgroup size or threadgroup lengths its pipeline state has not \ dispatched makes that VkPipeline then, as does a render command's draw of a state \ the CPU set on none of the commands. In a rate-mapped pass whose host step fans \ its triangles out, a render execution kept from the GPU alone by the rate map alone \ diff --git a/crates/metal2vulkan-runtime/src/scheduler/mod.rs b/crates/metal2vulkan-runtime/src/scheduler/mod.rs index e2e0b01b3..f8fcbe374 100644 --- a/crates/metal2vulkan-runtime/src/scheduler/mod.rs +++ b/crates/metal2vulkan-runtime/src/scheduler/mod.rs @@ -69,12 +69,18 @@ //! before is submitted; a signal from the caller was submitted before the commit. //! - **Tracking** ([`Tracker`]). Each batch is planned as it is submitted, against the device's //! hazard state, in this order: the order Metal follows across queues. A batch held for its -//! checks, or for a host step whose gate was taken, keeps its place among the tracked accesses: -//! a later commit's batch on another queue that conflicts with it waits behind it, its own host -//! step and checks too ([`Order::is_behind`]). One held for its pipelines' making, or for a step -//! that has not taken its gate, gives way but to a later commit that shares a fence with it: -//! that commit goes first and the held batch after it, as an x86 Mac's GPU may take a later -//! commit of another queue first (`order.rs`, **Held batches give way**). +//! checks, or for a host step whose gate was taken and whose host reads are not known, keeps +//! its place among the tracked accesses: a later commit's batch on another queue that conflicts +//! with it waits behind it, its own host step and checks too ([`Order::is_behind`]). One held +//! for its pipelines' making, or for a step that has not taken its gate, gives way but to a +//! later commit that shares a fence with it: that commit goes first and the held batch after it, +//! as an x86 Mac's GPU may take a later commit of another queue first (`order.rs`, **Held +//! batches give way**). So does one whose step took its gate and reads on the host what is +//! known (its executions' records and ranges), but for a later commit that writes those too, +//! which the gate does not cover: a step that waits for the GPU's long work before it in its +//! command buffer holds back no other queue's command buffer, a compositor's included, that +//! writes none of it (`tests::held_step_order`; on an RTX 3090 such a step held every queue's +//! commits for an 89 ms pass). //! - **Many logical queues on few `VkQueue`s.** A logical queue keeps its `VkQueue` from a //! command buffer's making to its completion, and moves only where it holds no other //! uncompleted one (`queue_share.rs`); each `VkQueue` signals its own timeline semaphore with @@ -741,6 +747,10 @@ struct Held { /// value of the last batch submitted there that wrote what the step reads, or of the last /// batch submitted there, which the queue's completed value reaches before the step. gate: Option>, + /// What its host step reads on the host, as the gate was taken, where those reads are known + /// (`CommandBufferShared::step_host_reads`): it then gives way to a later commit of another + /// queue but for one that writes them or shares a fence with it ([`place_of`]). + gate_reads: Option>>, /// Its command buffer has a submission check, so it may wait for checks to run. checked: bool, /// Who took its checks to run, once. @@ -1578,6 +1588,7 @@ fn take_in(state: &mut State, commits: &mut Vec, spent: &mut Spent) - binary_signals: batch.binary_signals, segments: batch.segments, gate: None, + gate_reads: None, checked: batch.checked, checks_taken: None, hastened: false, @@ -2365,7 +2376,7 @@ fn unshared_on_their_way( order: &Order, binary: &BinarySignals, (decodes, untracked_decodes): (&BTreeMap, usize), - memo: &mut Behind>>>, + memo: &mut Behind, ) -> Vec<(usize, u64)> { let heads: Vec<(u64, usize, u64)> = (order.heads()) .filter(|(_, held)| { @@ -2817,6 +2828,10 @@ fn gate_heads(state: &mut State, behind: &[u64], left: &mut Left, awaits: left.push(Kind::Step, (held.buffer.hold(), held.index)); continue; } + if held.gate.is_none() { + held.gate_reads = (held.buffer.step_host_reads(held.index)) + .map(|reads| Arc::new(Footprint::of_uses(&reads))); + } let gate = (held.gate).get_or_insert_with(|| { let (buffer, index) = (&held.buffer, held.index); gate_of(buffer, index, tracker, values) @@ -2865,8 +2880,8 @@ fn gate_heads(state: &mut State, behind: &[u64], left: &mut Left, awaits: /// line that may write those bytes and keeps its place holds it behind until submitted /// (`is_behind`, whose footprints hold the step's reads, `ExecutionRange::host_reads`), and one /// that gives way goes after it; a later commit's that may write them waits behind it from the -/// gate on, the step's batch keeping its place once its gate is taken (`order.rs`, **Held batches -/// give way**), and before it went first, so the gate covers it. +/// gate on (`is_behind`, for the step's batch that gives way with its host reads, [`place_of`], +/// or keeps its place), and before it went first, so the gate covers it. fn gate_of( buffer: &Hold, index: usize, @@ -2888,16 +2903,25 @@ fn gate_of( writes } +/// What the order across queues compares of a batch ([`is_behind`]): its footprint, and, for one +/// held at its host step's gate whose step's host reads are known, those reads +/// ([`Held::gate_reads`]). +struct Standing { + footprint: Option>>, + reads: Option>>, +} + /// Whether the head of commit sequence number `sequence` waits behind a batch committed before it /// ([`Order::is_behind`]) whose binary semaphores' signals are submitted and whose event values /// are reached, as are every batch's before it on its line: one that keeps its place, whose /// footprint and the head's run in commit order ([`tracker::ordered`]), or one that gives way -/// ([`place_of`]), whose footprint and the head's share a fence ([`tracker::fenced`]). `memo` -/// holds what this pass found. +/// ([`place_of`]), whose footprint and the head's share a fence ([`tracker::fenced`]), or that +/// waits at its host step's gate and whose step reads on the host what the head writes (or may +/// write: a head whose uses are not known yet). `memo` holds what this pass found. fn is_behind( order: &Order, binary: &BinarySignals, - memo: &mut Behind>>>, + memo: &mut Behind, sequence: u64, ) -> bool { order.is_behind( @@ -2905,12 +2929,20 @@ fn is_behind( memo, ( &mut |held: &Held| place_of(held, binary), - &mut |held: &Held| held.buffer.footprint(held.index), - &|earlier: &Option>>, - later: &Option>>, - gives_way| match gives_way { - false => tracker::ordered(earlier.as_deref(), later.as_deref()), - true => tracker::fenced(earlier.as_deref(), later.as_deref()), + &mut |held: &Held| Standing { + footprint: held.buffer.footprint(held.index), + reads: held.gate_reads.clone(), + }, + &|earlier: &Standing, later: &Standing, gives_way| { + let (footprint, later) = (earlier.footprint.as_deref(), later.footprint.as_deref()); + match gives_way { + false => tracker::ordered(footprint, later), + true => { + tracker::fenced(footprint, later) + || (earlier.reads.as_deref()) + .is_some_and(|reads| tracker::ordered(Some(reads), later)) + } + } }, ), ) @@ -2920,12 +2952,20 @@ fn is_behind( /// waits for the program while a binary semaphore's signal it needs is not submitted or an event /// value it waits for is not reached; it gives way while it holds segments whose host step has /// not taken its gate (its pipelines being made, or a step that reads nothing the GPU writes), -/// so the step reads what a later commit that goes first writes; else it keeps its place. +/// so the step reads what a later commit that goes first writes; and it gives way once its gate +/// was taken where what its step reads on the host is known ([`Held::gate_reads`]), but for a +/// later commit that writes that, which [`is_behind`] holds behind it, as the gate covers no +/// write submitted after it. Else (a step whose host reads are not known: a staged gather's, an +/// indirect dispatch's, a loop's check, an execution inside a block of command predication, an +/// indirect sparse update; its submission checks; or it is ready) it keeps its place. fn place_of(held: &Held, binary: &BinarySignals) -> Place { if !binary.ready(&held.binary_needs) || !events_reachable(held) { return Place::Stops; } - if held.segments && held.gate.is_none() && held.buffer.needs_host_step(held.index) { + if held.segments + && (held.gate.is_none() || held.gate_reads.is_some()) + && held.buffer.needs_host_step(held.index) + { return Place::GivesWay; } Place::Keeps diff --git a/crates/metal2vulkan-runtime/src/scheduler/order.rs b/crates/metal2vulkan-runtime/src/scheduler/order.rs index b8efba095..e6c1e3c21 100644 --- a/crates/metal2vulkan-runtime/src/scheduler/order.rs +++ b/crates/metal2vulkan-runtime/src/scheduler/order.rs @@ -28,10 +28,14 @@ //! give way with it. A head still waits behind such a batch where the two share a fence (one //! updates a fence the other waits for or updates, or a batch whose uses are not known yet and //! one that names a fence): a batch is never moved after a fence update it waits for. A step -//! whose gate was taken keeps its place: what it reads stands from its gate on, and a later -//! write going first would land after the step read. (A cold compute pipeline's making of 3 s -//! on an Iris Xe held one guest process's command buffer, and with it every other process's -//! frames over a surface they shared: the guest's display froze for 3.1 s.) +//! whose gate was taken still gives way, but to a later write of what it reads on the host (its +//! executions' records and ranges): what it reads stands from its gate on, and that write going +//! first would land after the step read; the caller's `ordered` says so for it. A step whose +//! host reads are not known keeps its place from its gate on. (A cold compute pipeline's making +//! of 3 s on an Iris Xe held one guest process's command buffer, and with it every other +//! process's frames over a surface they shared: the guest's display froze for 3.1 s. A step +//! waiting at its gate for an 89 ms pass before it in its command buffer held every queue's +//! commits on an RTX 3090, a compositor's included.) //! - **Which batches keep their place.** Every batch of a line up to the first that waits for //! an event value not yet reached by a submitted signal or the host, or for a binary //! semaphore whose signal is not yet submitted. That one and those after it wait for the @@ -461,9 +465,11 @@ struct Kept { pub(crate) enum Place { /// It keeps its place: a later commit of another line that conflicts with it waits. Keeps, - /// It is held unsubmitted for its host step before the step read anything the GPU writes: - /// a later commit of another line goes ahead of it, but where the two share a fence, and so - /// do the batches after it on its line (**Held batches give way**). + /// It is held unsubmitted for its host step before the step read anything the GPU writes, or + /// at or past its gate where what the step reads on the host is known: a later commit of + /// another line goes ahead of it, but where the caller's `ordered` says the two still run in + /// commit order given that it gives way (a fence both name; a write of what the step reads), + /// and so do the batches after it on its line (**Held batches give way**). GivesWay, /// It waits for the program (an event value or a binary semaphore's signal): it and the /// batches after it on its line keep no place. diff --git a/crates/metal2vulkan-runtime/src/tests/held_step_order.rs b/crates/metal2vulkan-runtime/src/tests/held_step_order.rs new file mode 100644 index 000000000..100be2937 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/held_step_order.rs @@ -0,0 +1,213 @@ +//! A command buffer whose second batch waits at its host step's gate for the GPU's long work +//! before it (a rate-mapped pass executing an indirect command buffer whose records that work +//! resets, `tests/host_step_rules.rs`'s workload), and an unshared queue's command buffer +//! committed while that work runs (`scheduler/order.rs`, **Held batches give way**): +//! +//! - one small fill of a buffer of its own, which shares nothing with the pass: its submission +//! waits for no host step, whether the pass's uses are bounded (it counts no visibility results, +//! `DeferredPass::bound`) or not known until its step records it (it does: `tracker::ordered`'s +//! `None`). On an RTX 3090 a step so held every queue's commits, a compositor's unshared ones +//! included, until an 89 ms pass before it ended; on lavapipe, before the step gave way, the +//! fill of the second kind went 111 ms after its commit, as the pass's batch did; +//! - a reset of the records the pass's step reads: it waits behind the step's batch, as the gate +//! covers no write submitted after it. +//! +//! A device test: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind +//! of device the cfg selects. + +use super::blit_holds::{Scratch, WAIT}; +use super::host_step_rules::{Heard, Workload}; +use crate::{ + Buffer, CommandBuffer, CommandQueue, LoadAction, RenderPassDescriptor, ResourceOptions, + StoreAction, TextureDescriptor, VisibilityResultMode, +}; +use metal2vulkan::metal::{PixelFormat, TextureUsage}; +use std::time::{Duration, Instant}; + +/// The bytes one fill of the long work writes. +const FILL_BYTES: u64 = 64 << 20; + +/// The long work's length the fills are calibrated to, in seconds. +const LONG: f64 = 0.1; + +/// The runs a leg makes, at most, for one whose fill was committed before the pass's batch went +/// (the test's thread late on a loaded host shows nothing). +const RUNS: usize = 3; + +/// What the unshared queue's command buffer does. +#[derive(Clone, Copy, PartialEq, Eq)] +enum Unshared { + /// One small fill of a buffer of its own. + Fill, + /// A reset of the pass's empty command, in the records its step reads. + Reset, +} + +/// One run's host times, in seconds of `host_time`'s clock, and its holds. +struct Run { + /// The unshared queue's commit returned. + committed: f64, + /// The scheduler called its submission (its kernel end). + called: f64, + /// The scheduler called the pass's batch's submission (the long command buffer's kernel end), + /// once the long work completed and the step recorded the pass. + pass_called: f64, + /// The long command buffer's GPU end. + long_end: f64, + /// Looks that held a head behind an earlier commit + /// (`WorkCounts::heads_held_for_earlier_commits`). + held: u64, +} + +impl Run { + /// Whether the unshared one was committed at least half the long work before the pass's + /// batch went: else the test's thread came late (a loaded host), and the run shows nothing. + fn early(&self) -> bool { + self.pass_called - self.committed > LONG / 2.0 + } +} + +/// The fills that take about [`LONG`] of `queue`'s GPU. +fn long_fills(queue: &CommandQueue, target: &Buffer) -> usize { + let mut fills = 64; + for _ in 0..3 { + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + for fill in 0..fills { + blit.fill_buffer(target, 0..FILL_BYTES, fill as u8).unwrap(); + } + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + let gpu = command_buffer.gpu_end_time().unwrap() - command_buffer.gpu_start_time().unwrap(); + fills = ((fills as f64 * LONG / gpu.max(1e-6)) as usize).clamp(8, 4096); + } + fills +} + +/// The long command buffer: `fills` fills of `big`, a reset of the buffer's empty command after +/// them, then the pass executing both commands, counting visibility results where `counted`. +fn long(work: &Workload, big: &Buffer, fills: usize, counted: bool) -> CommandBuffer { + let size = work.map.physical_size_for_layer(0); + let mut d = + TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, size.width, size.height, false); + d.usage = TextureUsage::RENDER_TARGET; + let target = work.device.new_texture(&d).unwrap(); + let command_buffer = work.queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + for fill in 0..fills { + blit.fill_buffer(big, 0..FILL_BYTES, fill as u8).unwrap(); + } + // The GPU writes the records last: the pass's step waits for the whole batch. + blit.reset_commands_in_buffer(&work.icb, 1..2).unwrap(); + blit.end_encoding().unwrap(); + let mut pass = RenderPassDescriptor::new(); + let color = &mut pass.color_attachments[0]; + color.texture = Some(target); + color.load_action = LoadAction::Clear; + color.store_action = StoreAction::Store; + pass.rasterization_rate_map = Some(work.map.clone()); + pass.visibility_result_buffer = Some(work.visibility.clone()); + let mut encoder = command_buffer.render_command_encoder(&pass).unwrap(); + encoder.set_render_pipeline_state(&work.pipeline).unwrap(); + if counted { + (encoder.set_visibility_result_mode(VisibilityResultMode::Boolean, 0)).unwrap(); + } + encoder.execute_commands_in_buffer(&work.icb, 0..2).unwrap(); + encoder.end_encoding().unwrap(); + command_buffer +} + +/// Commit the long command buffer, wait until its pass's batch waits at its gate, then commit the +/// unshared queue's command buffer, `what`. +fn run( + work: &Workload, + unshared: &CommandQueue, + (big, small): (&Buffer, &Buffer), + fills: usize, + (counted, what): (bool, Unshared), +) -> Run { + let long = long(work, big, fills, counted); + let before = work.device.work_counts(); + long.commit().unwrap(); + let began = Instant::now(); + while work.device.work_counts().heads_waiting_at_their_gate + == before.heads_waiting_at_their_gate + { + assert!( + began.elapsed() < WAIT, + "the pass's batch waited at its gate" + ); + std::thread::sleep(Duration::from_millis(1)); + } + let other = unshared.command_buffer().unwrap(); + let mut blit = other.blit_command_encoder().unwrap(); + match what { + Unshared::Fill => blit.fill_buffer(small, 0..256, 1).unwrap(), + Unshared::Reset => blit.reset_commands_in_buffer(&work.icb, 1..2).unwrap(), + } + blit.end_encoding().unwrap(); + other.commit().unwrap(); + let committed = crate::host_time(); + other.wait_until_completed_for(WAIT).unwrap(); + long.wait_until_completed_for(WAIT).unwrap(); + let after = work.device.work_counts(); + Run { + committed, + called: other.kernel_end_time(), + pass_called: long.kernel_end_time(), + long_end: long.gpu_end_time().unwrap(), + held: after.heads_held_for_earlier_commits - before.heads_held_for_earlier_commits, + } +} + +/// The unshared queue's fill, the pass's uses bounded or not known, is submitted with no look +/// holding it behind an earlier commit, before half the long work ran; its reset of the records +/// the step reads waits behind the pass's batch, held so. +#[test] +fn an_unshared_queue_s_fill_does_not_wait_for_another_queue_s_host_step() { + let scratch = Scratch::new("held-step-order"); + let work = Workload::new(&scratch, &Heard::default()); + let unshared = work.device.new_command_queue_unshared(64).unwrap(); + let private = ResourceOptions::private(); + let big = work.device.new_buffer(FILL_BYTES, private).unwrap(); + let small = work.device.new_buffer(4096, private).unwrap(); + let fills = long_fills(&work.queue, &big); + let legs = [ + ("a fill, the pass bounded", false, Unshared::Fill), + ("a fill, the pass's uses not known", true, Unshared::Fill), + ("a reset of the records", false, Unshared::Reset), + ]; + for (leg, counted, what) in legs { + let run = (0..RUNS) + .map(|_| run(&work, &unshared, (&big, &small), fills, (counted, what))) + .inspect(|run| { + println!( + "{leg}: committed at 0, called at {:.2} ms; the pass called at {:.2} ms, the \ + long work's end {:.2} ms; {} looks held behind an earlier commit", + (run.called - run.committed) * 1e3, + (run.pass_called - run.committed) * 1e3, + (run.long_end - run.committed) * 1e3, + run.held + ) + }) + .find(Run::early) + .expect("a run committed the unshared one before half the long work ran"); + match what { + Unshared::Fill => { + assert_eq!(run.held, 0, "{leg}: no look held it behind the pass"); + assert!( + run.called - run.committed < LONG / 2.0, + "{leg}: it went before half the long work ran" + ); + } + Unshared::Reset => { + assert!(run.held > 0, "{leg}: a look held it behind the pass"); + assert!( + run.called > run.pass_called, + "{leg}: it went after the pass's batch" + ); + } + } + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/host_step_rules.rs b/crates/metal2vulkan-runtime/src/tests/host_step_rules.rs index 2ce5b274b..7ed750fc6 100644 --- a/crates/metal2vulkan-runtime/src/tests/host_step_rules.rs +++ b/crates/metal2vulkan-runtime/src/tests/host_step_rules.rs @@ -43,24 +43,24 @@ const VISIBILITY: &str = "the encoder counts visibility results"; const PAST: &str = "past that rule"; /// What the sink heard: each `host-replayed-indirect-commands` notice. -type Heard = Arc>>; +pub(super) type Heard = Arc>>; /// The device, its queue, the pipeline, the triangle's buffers, the indirect command buffer and -/// the map. -struct Workload { - device: Device, - queue: CommandQueue, - pipeline: RenderPipelineState, +/// the map (`held_step_order.rs`'s too). +pub(super) struct Workload { + pub(super) device: Device, + pub(super) queue: CommandQueue, + pub(super) pipeline: RenderPipelineState, _drawing: [Buffer; 3], - icb: IndirectCommandBuffer, - map: RasterizationRateMap, - visibility: Buffer, + pub(super) icb: IndirectCommandBuffer, + pub(super) map: RasterizationRateMap, + pub(super) visibility: Buffer, } impl Workload { /// The workload on a device of the kind the cfg selects, its shader cache in `scratch`, its /// host-step notices into `heard`. - fn new(scratch: &Scratch, heard: &Heard) -> Workload { + pub(super) fn new(scratch: &Scratch, heard: &Heard) -> Workload { let mut options = options(&scratch.0); let into = Arc::clone(heard); options.messages = Some(MessageSink::new(move |message| { diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 41f0284b3..fd8b2bb6e 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -329,6 +329,8 @@ mod held_depth; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod held_lately; #[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod held_step_order; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] mod hold_sites; mod host_aliases; mod host_bytes; diff --git a/crates/metal2vulkan-runtime/src/tracker.rs b/crates/metal2vulkan-runtime/src/tracker.rs index 65d1dbe7b..082eccee6 100644 --- a/crates/metal2vulkan-runtime/src/tracker.rs +++ b/crates/metal2vulkan-runtime/src/tracker.rs @@ -2604,6 +2604,18 @@ impl Footprint { Footprint::gathered(summaries).sorted() } + /// The footprint of `uses` alone, as one command that makes them in every stage records them, + /// naming no fence: what a host step reads on the host, for the scheduler's order across + /// queues (`scheduler/mod.rs`'s `place_of`), where a later write of it waits behind the step. + pub(super) fn of_uses(uses: &[Use]) -> Footprint + where + K: Hash, + { + let mut recorded = EncoderUses::new(false); + recorded.record(vk::PipelineStageFlags2::ALL_COMMANDS, uses, None); + Footprint::of([&recorded.finish()]) + } + /// What these summaries' footprint holds, copied out of them, its uses not sorted yet /// ([`sorted`](Self::sorted)): a caller that must not hold the summaries' lock while it /// sorts gathers under it and sorts after. diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index 35e98892d..f6126c6c0 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -7458,10 +7458,12 @@ pub struct WorkCounts { /// keeps its place and whose footprint runs in commit order with the head's /// (`scheduler/order.rs`): Metal tracks a resource across queues in the order the GPU takes /// the command buffers, so a batch the runtime holds for its submission checks, or for a host - /// step whose gate was taken, must not let a later commit's conflicting batch go first. A batch - /// held for its pipelines' making, or for a step that has not taken its gate, gives way: it - /// holds a head back only where the two share a fence, as an x86 Mac's GPU may take a later - /// commit of another queue first. This is + /// step whose gate was taken and whose host reads are not known, must not let a later + /// commit's conflicting batch go first. A batch held for its pipelines' making, or for a step + /// that has not taken its gate, gives way: it holds a head back only where the two share a + /// fence, as an x86 Mac's GPU may take a later commit of another queue first; one whose step + /// took its gate and reads known records and ranges on the host gives way too, but holds a + /// head that writes those as well. This is /// the one hold that crosses logical queues and `VkQueue`s, and a batch whose uses are not /// all known yet (work a host step or its submission records, `tracker::ordered`'s `None`) /// conflicts with every batch that makes a tracked use or names a fence, but for a host diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index f28252579..c086aaaad 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 = 2325; +pub const RUNTIME_VERSION: u32 = 2326; /// 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/docs/API.md b/docs/API.md index ff0398b6b..e07ba87db 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2706,9 +2706,10 @@ bound. from their records, on a thread of the runtime's, and submits the rest, so a command buffer's executions behind one writer wait for it once (where Metal tracks neither, or the step reads more, as inside a block of command predication: its command buffer's work before it, and every - batch submitted before that on any queue); meanwhile the device's other batches go, but for a - later one that shares a resource the execution may reach (one made resident, the records), and - the first command of a threadgroup size or threadgroup lengths its pipeline state has not dispatched makes + batch submitted before that on any queue); meanwhile the device's other batches go, a later + commit of another queue going ahead of it but where it writes the records or the range or + shares a fence with it (where the step reads more: where it shares a resource the execution may + reach, one made resident, the records), and the first command of a threadgroup size or threadgroup lengths its pipeline state has not dispatched makes that VkPipeline then, as does a render command's draw of a state the CPU set on none of the commands. In a rate-mapped pass whose host step fans its triangles out, a render execution kept from the GPU alone by the rate map alone has its records decoded on the GPU at the step, which