RUNTIME 2530: a dispatch memo keeps no residual-form pipeline
A dispatch whose region's own key is still being made takes the key's
residual form at once (dispatch_making.rs, begin_region_pipeline). compute.rs
then kept the pipelines it recorded in its encoder's memo entry
(DispatchMemo::made) whatever they were; only Planned::made checked that
they were the keys' own. A later dispatch of the same inputs takes the
memo's pipelines first, so it stayed on the residual form after the own
key's making landed, for the rest of the command buffer (the memo goes on
with the live state to the command buffer's next compute encoders).
The own-form check (Variant::made_as for each region) now gates both: the
memo entry and the plan keep the pipelines only where every region took
its own key's. A dispatch that took a residual form keeps nothing, so the
next dispatch of its inputs asks its regions' pipelines again, takes the
residual form again (counted) while the making runs, and its own key's
once made.
Cost: the check is one look in the variant's pipeline memo a region, on
the path that asks the pipelines (no pipelines kept for the dispatch). It
used to be skipped there where the plan already held pipelines (another
grid of its class); the memo-hit path and the plan's path look at nothing,
as before. While a making runs, a repeated dispatch of the same inputs
asks begin_region_pipeline again instead of taking the memo's pipelines.
Docs: DispatchMemo::made, and render/residual.rs's dispatch sentence.
Test: tests::residual_memo (lavapipe, view facts fixed to
PushReadsLengthenThreadPayload) fails without this change (the second
dispatch binds no pipeline) and passes with it.
Test: tests::residual_memo (lavapipe, --cfg m2v_cpu_icd): with the pipeline pool held, a dispatch
whose key differs from its residual form takes the residual form; once the pool lets go and the
dispatch's own pipeline is made, a second dispatch of the same inputs in the same encoder takes
the first one's memo entry and must bind its own key's pipeline (cmd_bind_pipeline +1,
residual_form_draws +0).
Verified (photokernel lane, tip 6f606837ad on 64921c846a): m3-max-39676 (msi, lavapipe): the test
alone at 87089d16a4 (without the fix) FAILS at the second dispatch, (0, 0) against (0, 1); at the
fix, residual_memo, uniform_bind_offsets, set_zero_at_offsets, general_form, kept_across_calls,
unit_axes and every compute test 70/70; clippy -D warnings plain, m2v_gpu and m2v_cpu_icd 0 for
metal2vulkan-runtime and metal2vulkan; rustdoc 0. No new Degradation kind, WorkCounts field or
public signature.
This commit is contained in:
1 parent
ad195fb66c
commit
4bf38fc0ff
5 files changed
+154
-13
No files matched your search
@@ -2505,7 +2505,8 @@ pub(super) struct KeptDispatch {
|
||||
/// Its commands: those the encoder's kept state keeps where they are of its planned
|
||||
/// ([`Instantiated`]), else instantiated.
|
||||
commands: OnceLock<Arc<DispatchCommands>>,
|
||||
/// Each region's `VkPipeline`, where all were found made.
|
||||
/// Each region's `VkPipeline`, where all were found made, each its own key's: never a key's
|
||||
/// residual form, which serves a dispatch only while its own is made.
|
||||
made: OnceLock<Vec<Arc<RawPipeline>>>,
|
||||
}
|
||||
|
||||
@@ -3235,17 +3236,22 @@ fn record(
|
||||
match made {
|
||||
Some(made) if !apart_samplers(core.device(), objects) => {
|
||||
// Kept with the entry, which the next dispatch of its inputs takes, and with
|
||||
// what it planned, which the next dispatch of its shape takes.
|
||||
if let Some(kept) = kept {
|
||||
drop(kept.made.set(made.clone()));
|
||||
}
|
||||
// Not a key's residual form, which serves only while its own is made.
|
||||
let own = (begun.iter().zip(&made)).all(|((key, _), made)| {
|
||||
planned.made.get().is_none() && variant.made_as(key, made)
|
||||
});
|
||||
// what it planned, which the next dispatch of its shape takes; but never a
|
||||
// key's residual form, which serves only while its own is made: a later
|
||||
// dispatch of either asks its regions' pipelines again, as this one did, and
|
||||
// takes its own key's once made (`tests::residual_memo`). The check costs one
|
||||
// look in the variant's memo a region, on this path alone (no pipelines kept
|
||||
// for the dispatch); a dispatch that takes kept ones looks at none.
|
||||
let own = (begun.iter().zip(&made))
|
||||
.all(|((key, _), made)| variant.made_as(key, made));
|
||||
if own {
|
||||
let keys = begun.iter().map(|(key, _)| key.clone()).collect();
|
||||
drop(planned.made.set((keys, made.clone())));
|
||||
if let Some(kept) = kept {
|
||||
drop(kept.made.set(made.clone()));
|
||||
}
|
||||
if planned.made.get().is_none() {
|
||||
let keys = begun.iter().map(|(key, _)| key.clone()).collect();
|
||||
drop(planned.made.set((keys, made.clone())));
|
||||
}
|
||||
}
|
||||
(Cow::Owned(made), None)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@
|
||||
//! Only that direction: a draw whose key has 0
|
||||
//! where a made pipeline has 1 waits for its own making, as any draw does. A dispatch or a tile
|
||||
//! dispatch whose region's `VkPipeline` is not made takes its residual form's alike
|
||||
//! (`Variant::begin_region_pipeline`).
|
||||
//! (`Variant::begin_region_pipeline`), and keeps it neither in its encoder's memo of what it
|
||||
//! settled (`compute::DispatchMemo`) nor in what it planned, so a later dispatch of the same
|
||||
//! inputs asks again and takes the key's own pipeline once made.
|
||||
//! - **One form where the bind offset buys nothing** ([`reads_views_at_bind`]). Where the driver
|
||||
//! is not measured to load a uniform read at a constant offset ahead of the shader
|
||||
//! (`DriverFact::ConstantOffsetUniformReadsPreloaded`, which no driver carries today), every
|
||||
|
||||
@@ -745,6 +745,8 @@ mod reserved_queues;
|
||||
mod residency;
|
||||
#[cfg(all(debug_assertions, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
mod resident_uses;
|
||||
#[cfg(m2v_cpu_icd)]
|
||||
mod residual_memo;
|
||||
mod resource;
|
||||
mod resource_ids;
|
||||
mod retained;
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
//! A dispatch that took its key's residual form while its own key was made on the device's pool
|
||||
//! (`pipeline/dispatch_making.rs`, `pipeline/render/residual.rs`), and a later dispatch of the
|
||||
//! same inputs in its encoder, which takes what the first settled (`compute::DispatchMemo`): once
|
||||
//! the own key's making landed, the later dispatch runs the own key's pipeline. The residual form
|
||||
//! serves only while the own key is made, so the memo's entry never keeps it.
|
||||
//!
|
||||
//! A device test on the CPU ICD alone (`m2v_cpu_icd`): lavapipe, under a device whose view
|
||||
//! check's facts the test fixes (`DeviceOptions::view_facts`) to
|
||||
//! `DriverWorkaround::PushReadsLengthenThreadPayload`, stands in for a profile whose storage
|
||||
//! views declare `SpecKey::RangeAtBindOffset`, where a key and its residual form differ. The
|
||||
//! kernel is `engine/buffer_end_byte_load.ll`'s (`out[0] = in[5]`).
|
||||
|
||||
use super::blit_holds::{options, Scratch, WAIT};
|
||||
use super::uniform_bind_offsets::idle;
|
||||
use crate::{Buffer, ComputePipelineState, Device, PipelineOptions, ResourceOptions, Size};
|
||||
use metal2vulkan::device::DriverWorkaround;
|
||||
use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource};
|
||||
|
||||
/// The threadgroup the state requires, so its creation makes its predicted region and that
|
||||
/// region's residual form (`pipeline/dispatch_making.rs`).
|
||||
const THREADS: [u32; 3] = [32, 1, 1];
|
||||
|
||||
/// Where the source is bound: past offset 0, so its slot reads at its residual from then on
|
||||
/// (`argument_table::AtBindViews`), a key no creation made.
|
||||
const MOVED: u64 = 64;
|
||||
|
||||
/// A device whose profile's storage views declare `SpecKey::RangeAtBindOffset`.
|
||||
fn device(cache: &std::path::Path) -> Device {
|
||||
let mut options = options(cache);
|
||||
let fact = DriverWorkaround::PushReadsLengthenThreadPayload;
|
||||
options.view_facts = Some([fact].into());
|
||||
let device = Device::system_default_with(&options).unwrap();
|
||||
let workarounds = device.compile_device().profile().workarounds();
|
||||
assert!(
|
||||
workarounds.contains(&fact),
|
||||
"the compile device's profile keys its storage views: {workarounds:?}"
|
||||
);
|
||||
device
|
||||
}
|
||||
|
||||
/// The compute state of `buffer_end_byte_load`, its descriptor requiring [`THREADS`].
|
||||
fn state(device: &Device) -> ComputePipelineState {
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("buffer_end_byte_load.ll");
|
||||
let bitcode = metal2vulkan_devtools::llvm_assemble(&ll).unwrap();
|
||||
let library = metal2vulkan::library::Library::from_air(&bitcode).unwrap();
|
||||
let function = (device.new_library_with_compile_library(library))
|
||||
.new_function_with_name("buffer_end_byte_load")
|
||||
.unwrap();
|
||||
let mut descriptor =
|
||||
ComputePipelineDescriptor::new(StageSource::Function(function.function_descriptor()));
|
||||
descriptor.required_threads_per_threadgroup = Some(THREADS);
|
||||
device
|
||||
.new_compute_pipeline_state(&descriptor, &PipelineOptions::default())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// The first byte of `buffer`, which no command uses now.
|
||||
fn first_byte(buffer: &Buffer) -> u8 {
|
||||
let contents = buffer.contents().unwrap();
|
||||
// SAFETY: the buffer's first byte, which no command uses now.
|
||||
unsafe { *contents.as_ptr() }
|
||||
}
|
||||
|
||||
/// With the device's pool held, the first dispatch, its source at [`MOVED`], hands its own key's
|
||||
/// making to the pool and takes the residual form the creation made. The pool let go and its
|
||||
/// making landed, a second dispatch of the same inputs in the same encoder takes the first's
|
||||
/// settle (`dispatches_settled_as_before`) and binds its own key's pipeline: one pipeline bound
|
||||
/// and no residual-form dispatch more. Both read the source's byte `MOVED + 5`.
|
||||
#[test]
|
||||
fn a_settle_taken_again_runs_its_own_key_once_made_not_the_residual_form() {
|
||||
let scratch = Scratch::new("residual-memo");
|
||||
let device = device(&scratch.0);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let state = state(&device);
|
||||
let created = idle(&device);
|
||||
let data: Vec<u8> = (0..=255).collect();
|
||||
let source = device
|
||||
.new_buffer_with_bytes(&data, ResourceOptions::shared())
|
||||
.unwrap();
|
||||
let output = device.new_buffer(16, ResourceOptions::shared()).unwrap();
|
||||
let [width, height, depth] = THREADS;
|
||||
let threads = Size::new(u64::from(width), u64::from(height), u64::from(depth));
|
||||
let hold = crate::pipeline::pool::held::hold();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut encoder = command_buffer.compute_command_encoder().unwrap();
|
||||
encoder.set_compute_pipeline_state(&state).unwrap();
|
||||
encoder.set_buffer(Some(&source), MOVED, 0).unwrap();
|
||||
encoder.set_buffer(Some(&output), 0, 1).unwrap();
|
||||
encoder
|
||||
.dispatch_threadgroups(Size::new(1, 1, 1), threads)
|
||||
.unwrap();
|
||||
let first = device.work_counts();
|
||||
assert_eq!(
|
||||
(
|
||||
first.residual_form_draws - created.residual_form_draws,
|
||||
first.residual_form_makings - created.residual_form_makings,
|
||||
first.dispatch_pipelines_pooled - created.dispatch_pipelines_pooled,
|
||||
),
|
||||
(1, 1, 1),
|
||||
"the first dispatch: residual-form dispatches, their makings and regions pooled"
|
||||
);
|
||||
drop(hold);
|
||||
let landed = idle(&device);
|
||||
assert_eq!(
|
||||
landed.variant_pipelines_made - first.variant_pipelines_made,
|
||||
1,
|
||||
"the own key's pipeline, made once the pool ran"
|
||||
);
|
||||
encoder
|
||||
.dispatch_threadgroups(Size::new(1, 1, 1), threads)
|
||||
.unwrap();
|
||||
let second = device.work_counts();
|
||||
assert_eq!(
|
||||
second.dispatches_settled_as_before - landed.dispatches_settled_as_before,
|
||||
1,
|
||||
"the second dispatch took the first's settle"
|
||||
);
|
||||
assert_eq!(
|
||||
(
|
||||
second.residual_form_draws - landed.residual_form_draws,
|
||||
second.commands_recorded.cmd_bind_pipeline - landed.commands_recorded.cmd_bind_pipeline,
|
||||
),
|
||||
(0, 1),
|
||||
"the second dispatch: residual-form dispatches, and pipelines bound (its own key's)"
|
||||
);
|
||||
encoder.end_encoding().unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
assert_eq!(first_byte(&output), data[MOVED as usize + 5]);
|
||||
}
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 525;
|
||||
/// 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 = 2529;
|
||||
pub const RUNTIME_VERSION: u32 = 2530;
|
||||
|
||||
/// 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
|
||||
|
||||
Reference in new issue
Block a user