diff --git a/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs b/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs index 2d765a33a..68db0489b 100644 --- a/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs +++ b/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs @@ -1854,6 +1854,10 @@ impl Gpu for Runtime { c.set_zero_writes_if_shapes_shared, ), ("dispatches_pushing_set_zero", c.dispatches_pushing_set_zero), + ( + "dispatch_set_zero_writes_pushed", + c.dispatch_set_zero_writes_pushed, + ), ("set_zero_sets_reused", c.set_zero_sets_reused), ("set_zero_sets_found", c.set_zero_sets_found), ("draw_shapes_reused", c.draw_shapes_reused), diff --git a/crates/metal2vulkan-runtime/src/compute.rs b/crates/metal2vulkan-runtime/src/compute.rs index 57725b579..c705c45e1 100644 --- a/crates/metal2vulkan-runtime/src/compute.rs +++ b/crates/metal2vulkan-runtime/src/compute.rs @@ -3151,7 +3151,7 @@ fn record( } core.shadow_copies(&copies); if !pushed.is_empty() { - device.shared().counts.thread().dispatch_pushing_set_zero(); + (device.shared().counts.thread()).dispatch_pushing_set_zero(pushed.len() as u64); } let recording = Recording { layout: objects.layout(), diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index d1f8eea61..a3444b07d 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -866,6 +866,7 @@ struct CommandCounters { dispatches_planned_across_grids: AtomicU64, whole_dispatches_on_partial_variants: AtomicU64, dispatches_pushing_set_zero: AtomicU64, + dispatch_set_zero_writes_pushed: AtomicU64, baked_sampler_dispatches_apart: AtomicU64, argument_tables_retained: AtomicU64, argument_objects_retained: AtomicU64, @@ -1669,9 +1670,12 @@ impl Counting<'_> { self.0.add(|counts| &counts.draws_pushing_set_zero, 1); } - /// A dispatch encoded with its set 0 pushed (`pipeline::objects::pushes_set_zero`). - pub(crate) fn dispatch_pushing_set_zero(&self) { + /// A dispatch encoded with its set 0 pushed (`pipeline::objects::pushes_set_zero`), its push + /// carrying `writes` descriptor writes. + pub(crate) fn dispatch_pushing_set_zero(&self, writes: u64) { self.0.add(|counts| &counts.dispatches_pushing_set_zero, 1); + self.0 + .add(|counts| &counts.dispatch_set_zero_writes_pushed, writes); } /// A command that bound the set 0 its encoder's last command wrote, the same descriptors @@ -9080,6 +9084,10 @@ pub struct WorkCounts { /// a kernel's variant whose set 0 a push descriptor set layout can hold, on a device of Vulkan /// 1.4 or `VK_KHR_push_descriptor`. Every dispatch pushes all of its set's writes. pub dispatches_pushing_set_zero: u64, + /// The descriptor writes those dispatches' pushes carried: each push's whole set 0 (its + /// writes, then its variant's baked samplers' pushes), one write a descriptor, so over + /// `dispatches_pushing_set_zero` the descriptors a dispatch's push writes. + pub dispatch_set_zero_writes_pushed: u64, /// Draws and dispatches that bound the set 0 their encoder's last command allocated and wrote, /// rather than allocating and writing their own: those that write the same descriptors into a /// set of the same layout (`binding::LastSetZero`). Their recording binds no set where the set @@ -12305,6 +12313,9 @@ impl Device { &counts.set_zero_writes_if_shapes_shared }), dispatches_pushing_set_zero: commands(|counts| &counts.dispatches_pushing_set_zero), + dispatch_set_zero_writes_pushed: commands(|counts| { + &counts.dispatch_set_zero_writes_pushed + }), set_zero_sets_reused: commands(|counts| &counts.set_zero_sets_reused), set_zero_sets_found: commands(|counts| &counts.set_zero_sets_found), draw_shapes_reused: commands(|counts| &counts.draw_shapes_reused), diff --git a/crates/metal2vulkan-validation/src/runtime_lane/dispatch_work.rs b/crates/metal2vulkan-validation/src/runtime_lane/dispatch_work.rs index 1b7f22d53..995c746be 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/dispatch_work.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/dispatch_work.rs @@ -1,7 +1,8 @@ //! Device tests of a dispatch's set 0 on the device the cfg selects, under the validation layer: //! pushed (`vkCmdPushDescriptorSet` at the compute bind point) where the device has the push //! command, else allocated, written and bound, and the same words either way -//! (`WorkCounts::dispatches_pushing_set_zero`); and what a dispatch settles, taken again by the +//! (`WorkCounts::dispatches_pushing_set_zero`), each push's writes counted +//! (`dispatch_set_zero_writes_pushed`); and what a dispatch settles, taken again by the //! encoder's next dispatch only where its inputs are the same (`WorkCounts:: //! dispatches_settled_as_before`, `set_zero_sets_reused`). Each runs both ways //! (`draw_work::on_device_both_ways`). And what a dispatch settles with what the encoder made @@ -33,7 +34,8 @@ const THREADS: u64 = 16; const DISPATCHES: u64 = 4; /// Dispatches that each bind other offsets of the same buffers push their set 0 where the device -/// pushes it, and bind it where it does not: every dispatch's words are its own, both ways. +/// pushes it, and bind it where it does not: every dispatch's words are its own, both ways. Each +/// push carries the same writes, at least one, and counts them. #[test] fn dispatches_push_their_set_zero_where_the_device_pushes() { on_device_both_ways(|device| { @@ -56,8 +58,20 @@ fn dispatches_push_their_set_zero_where_the_device_pushes() { .dispatch_threads(Size::new(THREADS, 1, 1), Size::new(THREADS, 1, 1)) .unwrap(); } - let pushed = - device.work_counts().dispatches_pushing_set_zero - before.dispatches_pushing_set_zero; + let counts = device.work_counts(); + let pushed = grew(&before, &counts, |counts| { + counts.dispatches_pushing_set_zero + }); + let writes = grew(&before, &counts, |counts| { + counts.dispatch_set_zero_writes_pushed + }); + eprintln!("DISPATCH-WORK: {pushed} pushes carried {writes} descriptor writes"); + assert!( + writes >= pushed && (pushed == 0 || writes.is_multiple_of(pushed)), + "each push carries its set's writes, the same for each dispatch: {pushed} pushes, \ + {writes} writes" + ); + assert_eq!(writes == 0, pushed == 0); encoder.end_encoding().unwrap(); command_buffer.commit().unwrap(); command_buffer.wait_until_completed_for(WAIT).unwrap(); diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 39d759439..d3751ffd9 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 = 2385; +pub const RUNTIME_VERSION: u32 = 2386; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 6cb03a297..f4884461e 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2905,6 +2905,7 @@ field metal2vulkan-runtime::WorkCounts.dirty_wait_nanos pub dirty_wait_nanos: u6 field metal2vulkan-runtime::WorkCounts.dirty_waits pub dirty_waits: u64 field metal2vulkan-runtime::WorkCounts.dirty_waits_unanswered pub dirty_waits_unanswered: u64 field metal2vulkan-runtime::WorkCounts.dispatch_pipelines_pooled pub dispatch_pipelines_pooled: u64 +field metal2vulkan-runtime::WorkCounts.dispatch_set_zero_writes_pushed pub dispatch_set_zero_writes_pushed: u64 field metal2vulkan-runtime::WorkCounts.dispatch_shapes_found pub dispatch_shapes_found: u64 field metal2vulkan-runtime::WorkCounts.dispatch_shapes_made pub dispatch_shapes_made: u64 field metal2vulkan-runtime::WorkCounts.dispatch_used_resources_listed pub dispatch_used_resources_listed: u64