From f2097a3b2e4237be2cf89616be3e95b85dc17975 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 2 Nov 2026 19:16:41 -0800 Subject: [PATCH] host_ab: dispatch_resident_moving variants, the output's offset moved each dispatch The encode workload's dispatch_resident_moving_{0,16,256,4096}: as many dispatches of the tiny kernel after none, 16, 256 or 4096 buffers made resident, each after set_buffer moved the output buffer's offset. The existing resident variants change nothing between dispatches, so every one after the first takes the dispatch memo and none shows what a dispatch that changes a binding costs at a resident count: these do. Verified: built in release; the variants run on the M3 (MoltenVK) and print dispatch_resident_moving_*_encode. (cherry picked from commit fea089d4527bab194df36adb68b1b02bdc7d7cc3) (cherry picked from commit e5732c19aa1b21c56cc5fa8d1bb1c3ce21e32c0e) (cherry picked from commit 09da9fc3166c4f3c8b2e4e26d5fe68620228014b) (cherry picked from commit 09dab5495d35b14ed952fa67257809aa271e6357) --- .../examples/host_ab/main.rs | 6 ++-- .../examples/host_ab/workloads.rs | 29 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/metal2vulkan-runtime/examples/host_ab/main.rs b/crates/metal2vulkan-runtime/examples/host_ab/main.rs index 8b5e26b0b..7d6966da7 100644 --- a/crates/metal2vulkan-runtime/examples/host_ab/main.rs +++ b/crates/metal2vulkan-runtime/examples/host_ab/main.rs @@ -27,7 +27,9 @@ //! Then `dispatch_resident_*`: as many dispatches of the tiny kernel after one //! `useResources:count:usage:` of 0, 1, 256 or 4096 buffers, or of one buffer 4096 times //! (`same_4096`); per variant the `useResources` call, and per dispatch the encoding thread's -//! wall time after it and the process's CPU time. +//! wall time after it and the process's CPU time; `dispatch_resident_moving_0`, `_16`, `_256` +//! and `_4096`: as many after none, 16, 256 or 4096 buffers made resident, the output buffer's +//! offset moved before each dispatch. //! - `fixed`: a command buffer's creation, an encoder of one command each (render, compute, //! blit), and the commit call of a command buffer of 30 such encoders. //! - `calls`: the frames of a guest as reims-vgpu's `frame_cost` measures them, call by call: one @@ -204,7 +206,7 @@ //! cache, with `--side`), `--variants a,b,...` (the encode workload's variants alone: //! `draw_static`, `draw_offset`, `draw_bind`, `draw_pipeline`, `draw_passes`, `dispatch_static`, //! `dispatch_offsets`, `dispatch_churn`, `dispatch_resident_0`, `_1`, `_256`, `_4096`, -//! `_same_4096`; for a profile of one; and the memory workload's parts alone: `create`, +//! `_same_4096`, `dispatch_resident_moving_0`, `_16`, `_256`, `_4096`; for a profile of one; and the memory workload's parts alone: `create`, //! `no_copy`, `held_1m`, `held_64m`, `texture`), `--announce-each a,b,...` (the runtime's device //! announces these degradation kinds, by code with or without its `metal2vulkan-degrade-` prefix, //! or `all` of them, at every occurrence, `DeviceOptions::announce_each`, as a consumer that hears diff --git a/crates/metal2vulkan-runtime/examples/host_ab/workloads.rs b/crates/metal2vulkan-runtime/examples/host_ab/workloads.rs index 57925c4ef..8e089bf31 100644 --- a/crates/metal2vulkan-runtime/examples/host_ab/workloads.rs +++ b/crates/metal2vulkan-runtime/examples/host_ab/workloads.rs @@ -619,15 +619,22 @@ const RESIDENT: usize = 4096; /// The encode workload's `dispatch_resident_*` variants: a compute encoder whose pipeline state /// and buffers are set, one `useResources:count:usage:` (reading) of none, 1, 256 or 4096 /// buffers, or of one buffer 4096 times (`same_4096`), then `draws` single-threadgroup dispatches -/// of the tiny kernel. Per variant: the `useResources` call, the encoding thread's wall time per -/// dispatch, the process's CPU time per dispatch, and the command buffer's whole time. +/// of the tiny kernel; `moving_0`, `_16`, `_256` and `_4096` as many after none, 16, 256 or 4096, +/// each dispatch after the output buffer's offset moved. Per variant: the `useResources` call, the +/// encoding thread's wall time per dispatch, the process's CPU time per dispatch, and the command +/// buffer's whole time. fn encode_resident(g: &G, s: &Scene, sizes: &Sizes, runs: &dyn Fn(String) -> bool) { + // (name, resident buffers, one buffer `count` times, the output's offset moving). let variants = [ - ("0", 0, false), - ("1", 1, false), - ("256", 256, false), - ("4096", 4096, false), - ("same_4096", 4096, true), + ("0", 0, false, false), + ("1", 1, false, false), + ("256", 256, false, false), + ("4096", 4096, false, false), + ("same_4096", 4096, true, false), + ("moving_0", 0, false, true), + ("moving_16", 16, false, true), + ("moving_256", 256, false, true), + ("moving_4096", 4096, false, true), ]; let wanted: Vec<_> = (variants.iter()) .filter(|(name, ..)| runs(format!("dispatch_resident_{name}"))) @@ -637,7 +644,7 @@ fn encode_resident(g: &G, s: &Scene, sizes: &Sizes, runs: &dyn Fn(Str } let n = sizes.draws; let resident: Vec = (0..RESIDENT).map(|_| g.buffer(256)).collect(); - for &&(name, count, same) in &wanted { + for &&(name, count, same, moving) in &wanted { let list: Vec<&G::Buffer> = match same { true => vec![&resident[0]; count], false => resident[..count].iter().collect(), @@ -659,7 +666,11 @@ fn encode_resident(g: &G, s: &Scene, sizes: &Sizes, runs: &dyn Fn(Str let t1 = Instant::now(); g.use_buffers(&mut encoder, &list); let t2 = Instant::now(); - for _ in 0..n { + for dispatch in 0..n { + if moving { + let offset = (dispatch % RECTS) * RECT_STRIDE; + g.set_buffer(&mut encoder, &s.tiny_out, offset, 0); + } g.dispatch(&mut encoder, 1, 64); } let t3 = Instant::now();