RUNTIME 2538: submission checks: an answer that load could have made stands only for now

What: a merge or import tax answer now stands as far as it earned
(`Stands`). A merge `Holds` clear of the load and repeated, an import tax
`Holds` past its margin and repeated, and an `Unchecked` of a refused call
or a device with no pointer import are recorded. A `Fails` clear of the
load whose every try ran quiet stands for the device's life and is never
recorded. Every other answer stands for now: the checks' thread keeps its
command buffers and fence and checks it again 1, 2, 4 ... 64 s after the
first answers, then each minute, until none stands for now. A check again
replaces the verdict (tries that all split keep it), so a device whose
first merge answer was a loaded `Fails` groups once a check again answers
`Holds`. A record's `Fails` is a hint and no answer: a device that reads
one checks that check again at its making. Before each round and each
submission of a phase the checks stand by, at most 20 ms, until the
device's work is quiet (`DeviceShared::work_quiet_for`, shared with the
checks' thread through `WorkShare`).

The stop rule's thresholds (`Load::ran_quiet`): every stand-by found the
device's work quiet, no round or submission took past QUIET_ROUND_MOST
(2 ms, from its first call to its fence's reset), and all of them no more
than QUIET_TRY_MOST (30 ms). A merge `Fails` must also be clear
(MERGE_FAILS_CLEAR, 0.75 of the calls apart) and repeated
(MERGE_REPEATS); an import tax `Fails` must agree in its halves with a
held import adding at most half its bound (TAX_FAILS_CLEAR).

Why: on the Radeon 780M beside other jobs (m3-max-39740, load average
18-24 on 16 threads), two of four devices answered merge `Fails` at 0.72
and 0.745, both forms lifted by about the same 58-80 us, short of the
record but held for the device's life, so those processes grouped no
batch at all. At 0.75 and up with its repeats, the same load would have
written a `Fails` record that every later device of that release read
without checking. Threads of the process's own spinning or touching fresh
pages (m3-max-39786, 2x the host's threads) lifted every call alike and
left all eight devices at `Holds` (0.23-0.64), so the device test injects
the observed shape instead (`lift_next_merge_tries`: 70 us on the first
call of every round, its stand-bys not quiet).

Costs: a driver that does not merge or whose imports cost nothing pays
that check at every device's making, as before any record, and once more
at least where no try of its first answer ran quiet. An answer for now
costs a check again at each step of the schedule. The import tax is
included: a loaded tax `Fails` placed the device's long buffers in fresh
pages for its life on a driver whose imports do cost (39740's
b202c-bench run: 148.6 against 121.5 us, short of its margin).

CHECK_VERSION 9 (a record may hold no answer of a check, and a `Fails` in
one is no answer). Tests: unit tests of what each answer earns, the
schedule, the quiet bounds and the record; device tests that a recorded
`Fails` is checked again and that a lifted merge answer is checked again
and comes to the answer of a device beside it, with no `Fails` recorded.
in_place_check takes its answers through `answer_next_device`, since a
record can no longer hold a `Fails` as an answer. Forced verdicts
(`SubmitChecks::force`) stand for the device's life.

With it: the drag bench reports the submission checks' answers before and after its measurements
(test only); a lifted try's count goes down by AtomicU32::try_update (fetch_update's new name).

Verified (launchreg lane, tip 942672e8cb = these three commits on development 01415e33d6):
m3-max-39884 (msi): clippy -D warnings plain, m2v_cpu_icd and m2v_gpu 0; lavapipe submit_check,
in_place_check, teardown_threads, relay_facts, fresh_pages, padding_unobserved, host_ram_dma_buf,
dma_buf_parked_images, exported_textures, icb_records_policy, pointer_residency, fast_paths,
queue_quiet and view_check 114/114; view_check_device's stand-by test 3/3. The control (the fix
without the re-check of loaded and recorded answers) fails the new device tests as meant: lavapipe
(m3-max-39818) 2 of 2, RX 550 (39863) 2 of 2, Radeon 780M (39885) the recorded-Fails test; the fix
passes 26/26 on the RX 550 and the 780M. On the 780M (39907, the fix on an earlier base) a device
made under host load answered merge Pending (one try split), then "Holds, recorded (14.4 us in one
call of 4 against 39.4 us apart)" after its re-checks, and grouped; every later device answered
Holds in 3 tries.
This commit is contained in:
Anees Iqbal committed 2026-11-17 02:01:04 -08:00
1 parent 01415e33d6
commit 96e1041dbf
11 files changed
+1085 -268

No files matched your search

+49 -5
View File
@@ -919,16 +919,60 @@ impl DeviceShared {
/// its `VkQueue`s is under way; else the time since the last such use ended
/// (`queue_quiet.rs`).
pub(crate) fn work_quiet_for(&self) -> Option<Duration> {
if self.batch_in_flight() || !self.scheduler.holds_none() {
return None;
}
self.queue_quiet.unused_for()
quiet_for(
&self.queues,
|| self.scheduler.holds_none(),
&self.queue_quiet,
)
}
/// Whether a batch submitted to one of the device's `VkQueue`s is not seen complete there.
pub(crate) fn batch_in_flight(&self) -> bool {
(self.queues.iter()).any(|slot| slot.completed_value() < slot.submitted_value())
in_flight(&self.queues)
}
/// A share of what tells whether its work is quiet, for a thread that holds no device
/// (`submit_check.rs`).
pub(crate) fn work_share(&self) -> WorkShare {
WorkShare {
queues: Arc::clone(&self.queues),
holds: self.scheduler.holds_share(),
uses: Arc::clone(&self.queue_quiet),
}
}
}
/// What tells whether a device's work is quiet ([`DeviceShared::work_quiet_for`]), shared with a
/// thread that holds no device: its `VkQueue`s, the scheduler's holds and its queue uses.
pub(crate) struct WorkShare {
queues: Arc<[QueueSlot]>,
holds: crate::scheduler::HoldsShare,
uses: Arc<queue_quiet::QueueQuiet>,
}
impl WorkShare {
/// [`DeviceShared::work_quiet_for`].
pub(crate) fn quiet_for(&self) -> Option<Duration> {
quiet_for(&self.queues, || self.holds.holds_none(), &self.uses)
}
}
/// Whether a batch submitted to one of `queues` is not seen complete there.
fn in_flight(queues: &[QueueSlot]) -> bool {
(queues.iter()).any(|slot| slot.completed_value() < slot.submitted_value())
}
/// How long the work of a device of `queues`, whose scheduler holds none of it where `holds_none`
/// and whose queue uses are `uses`, has been quiet ([`DeviceShared::work_quiet_for`]).
fn quiet_for(
queues: &[QueueSlot],
holds_none: impl FnOnce() -> bool,
uses: &queue_quiet::QueueQuiet,
) -> Option<Duration> {
if in_flight(queues) || !holds_none() {
return None;
}
uses.unused_for()
}
impl DeviceShared {
@@ -35,7 +35,8 @@
//! mark after it ([`DeviceWord::end_step`]: the use's last submission on the queue, whose Metal
//! command buffer completes after the check's own), so the
//! runtime's loader-served calls on other threads may wait for one step of theirs, once, while they
//! run (the checks run once per driver and runtime, for milliseconds); elsewhere the word never
//! run (the checks run for milliseconds, as a device is made and, where an answer of the
//! submission checks stands only for now, again in its life); elsewhere the word never
//! changes and they hold it across their submission calls alone. A narrower hold, around the calls
//! that read the word alone, cannot exclude the writer: MoltenVK writes from its own threads as
//! each of the checks' Metal command buffers completes, at no call of the runtime's, so only
@@ -483,6 +483,17 @@ pub(crate) struct Scheduler {
thread: Mutex<Option<JoinHandle<()>>>,
}
/// A share of the scheduler's state that reads whether it holds any batch committed and not
/// submitted ([`Scheduler::holds_share`]).
pub(crate) struct HoldsShare(Arc<SchedulerShared>);
impl HoldsShare {
/// [`Scheduler::holds_none`].
pub(crate) fn holds_none(&self) -> bool {
self.0.holds_none()
}
}
struct SchedulerShared {
/// The state, under the lock a pass holds, with the commits a pass under way takes in.
inbox: Inbox<State, Committed>,
@@ -644,6 +655,13 @@ impl Posted {
}
impl SchedulerShared {
/// [`Scheduler::holds_none`].
fn holds_none(&self) -> bool {
let inbox = &self.inbox;
let state = lock(inbox.state());
state.order.is_empty() && state.grouped.is_empty() && !inbox.holds_commits()
}
/// A pass that took in `taken` commits ended, its submissions made and counted, under the
/// lock: counted, released after them (`WorkCounts::commits_taken_in`).
fn took_in(&self, taken: usize) {
@@ -1278,9 +1296,13 @@ impl Scheduler {
/// semaphore, a host step, a check or a group, or waits in the inbox
/// (`texture/storage_form.rs`).
pub(crate) fn holds_none(&self) -> bool {
let inbox = &self.shared.inbox;
let state = lock(inbox.state());
state.order.is_empty() && state.grouped.is_empty() && !inbox.holds_commits()
self.shared.holds_none()
}
/// A share of its state that reads [`holds_none`](Self::holds_none) alone, for a thread that
/// holds no device (`submit_check.rs`).
pub(crate) fn holds_share(&self) -> HoldsShare {
HoldsShare(Arc::clone(&self.shared))
}
/// A CPU decode into the decoded twin of the resource `key` was queued: every batch whose
File diff suppressed because it is too large. Load diff
@@ -32,7 +32,9 @@
//! (`CommandBuffer::submit_returned_time`, the device noting queue times: its planning, any
//! hold in a group, and the call), and from there to its GPU start; and why the commits' passes
//! left batches (the `WorkCounts::scheduler_at_commit_left_*` counts) and the groups held past
//! a pass for two submissions in flight (`WorkCounts::groups_kept_pending`). And (`DRAG-FRAME`)
//! a pass for two submissions in flight (`WorkCounts::groups_kept_pending`); the device's
//! submission checks' report (`Device::submit_check_report`) heads them and ends them, as the
//! merge check decides whether its batches group. And (`DRAG-FRAME`)
//! each frame's whole (medians and 90th percentiles): from its first commit call to the GPU start
//! and the GPU end of its last part with work, and its commit calls' time, the committing
//! thread's for the frame. A part's time from its own commit call leaves out the commit calls
@@ -112,10 +114,11 @@ fn drag_submit_bench() {
// Each command buffer's submission's return (`CommandBuffer::submit_returned_time`).
device.shared().timing.note_queue_times();
println!(
"DRAG-PATH on {}: completion {:?}, submissions merge {}",
"DRAG-PATH on {}: completion {:?}, submissions merge {}; its submission checks: {}",
device.name(),
device.compile_device().policy().completion,
device.submissions_merge(),
device.submit_check_report(),
);
let len = 2 * LISTED * LISTED_BYTES;
let ram = Ram::new(len, 0, len);
@@ -316,5 +319,10 @@ fn drag_submit_bench() {
device.fast_submit_call_every(None);
device.leave_calls_from(None);
}
println!(
"DRAG-PATH after the measurements: submissions merge {}; its submission checks: {}",
device.submissions_merge(),
device.submit_check_report(),
);
drop(listed);
}
@@ -10,13 +10,13 @@
//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
//! `m2v_cpu_icd`), on the kind of device the cfg selects. Each device's shader cache is a fresh
//! directory, so no record holds its verdicts and its check runs; the two devices the placement
//! test compares find there only a record of the same submission-check answers ([`answering`]).
//! test compares take the same submission-check answers ([`answering`]).
use super::blit_holds::{device, options, Scratch};
use crate::address::{PAGE, SPACE_BASE, SPACE_END};
use crate::fresh_pages::FRESH_PAGES_PAST;
use crate::in_place::{verdict_index, Access, PagesClass, RowEnds, Verdict as InPlaceVerdict};
use crate::submit_check::{encode, record_name, Check, Measured, Verdict};
use crate::submit_check::{answer_next_device, Check, Verdict};
use crate::{
AddressPlacement, Buffer, BufferContents, BufferDescriptor, DebugMessage, Device,
DeviceOptions, Error, GpuAddress, MessageSink, ResourceId, ResourceIdKind, ResourceOptions,
@@ -24,7 +24,7 @@ use crate::{
};
use metal2vulkan::bind::SamplerDescriptor;
use metal2vulkan::metal::{PixelFormat, TextureUsage};
use std::path::{Path, PathBuf};
use std::path::Path;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
@@ -49,43 +49,16 @@ const ANSWERS: [Verdict; Check::COUNT] = [Verdict::Fails, Verdict::Fails];
/// long buffers take no fresh pages (`fresh_pages.rs`).
const TAXED: [Verdict; Check::COUNT] = [Verdict::Fails, Verdict::Holds];
/// A record of submission-check answers for the driver of the device the cfg selects, and its
/// path under a shader cache's directory.
struct AnswersRecord {
answers: [Verdict; Check::COUNT],
bytes: Vec<u8>,
under: PathBuf,
}
impl AnswersRecord {
/// The record of `answers`, its identity and path read from a device made over a cache of its
/// own and dropped before any device that recalls the record is made.
fn new(answers: [Verdict; Check::COUNT]) -> AnswersRecord {
let scratch = Scratch::new("in-place-check-identity");
let probe = device(&scratch.0);
let identity = probe.driver_identity();
let path = (probe.shared().shader_cache.content_store().directory())
.expect("a device over a cache of its own")
.record_path(&record_name(&identity));
let under = path.strip_prefix(&scratch.0).unwrap().to_owned();
AnswersRecord {
answers,
bytes: encode(&identity, answers, Measured::default()),
under,
}
}
}
/// A device over `scratch`'s shader cache that recalls `record`'s answers, written there before
/// it is made, and runs no submission check (`submit_check.rs`): what places the product's long
/// buffers in fresh pages or not (`fresh_pages.rs`). Two devices made so place them alike, where
/// the submission checks each timed under the load beside it can answer apart: a held import
/// measured to cost 1.2 us a submission on one llvmpipe device and 0.3 us on the next, either side
/// of the check's 1 us (`TAX_FLOOR`).
fn answering(scratch: &Scratch, record: &AnswersRecord) -> Device {
let path = scratch.0.join(&record.under);
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, &record.bytes).unwrap();
/// A device over `scratch`'s shader cache that takes `answers` as its submission checks'
/// verdicts, as a record's, and runs no submission check (`submit_check.rs`,
/// `answer_next_device`): what places the product's long buffers in fresh pages or not
/// (`fresh_pages.rs`). Two devices made so place them alike, where the submission checks each
/// timed under the load beside it can answer apart: a held import measured to cost 1.2 us a
/// submission on one llvmpipe device and 0.3 us on the next, either side of the check's 1 us
/// (`TAX_FLOOR`). A record's `Fails` is no answer (the device checks again), so a record could
/// not hold these.
fn answering(scratch: &Scratch, answers: [Verdict; Check::COUNT]) -> Device {
answer_next_device(answers);
let device = device(&scratch.0);
let counts = device.work_counts();
assert_eq!(
@@ -94,10 +67,7 @@ fn answering(scratch: &Scratch, record: &AnswersRecord) -> Device {
"the device recalled the written answers and ran no submission check"
);
let recalled = Check::ALL.map(|check| device.shared().submit_checks.verdict(check));
assert_eq!(
recalled, record.answers,
"the recalled submission-check verdicts"
);
assert_eq!(recalled, answers, "the recalled submission-check verdicts");
device
}
@@ -132,10 +102,9 @@ fn the_in_place_check_takes_no_range_of_the_metal_space() {
.take(lines)
.collect()
};
let record = AnswersRecord::new(ANSWERS);
let reference = {
let scratch = Scratch::new("in-place-check-reference");
let device = answering(&scratch, &record);
let device = answering(&scratch, ANSWERS);
assert!(
device.settle_in_place_checks(WAIT),
"the reference check answered"
@@ -143,7 +112,7 @@ fn the_in_place_check_takes_no_range_of_the_metal_space() {
verdicts(&device)
};
let scratch = Scratch::new("in-place-check-placement");
let device = answering(&scratch, &record);
let device = answering(&scratch, ANSWERS);
let rest = SPACE_BASE + LOW;
// The pool's span is its pages and one guard page, to the space's end.
let pool = device
@@ -189,12 +158,12 @@ fn the_in_place_check_takes_no_range_of_the_metal_space() {
fn the_in_place_check_checks_fresh_pages_where_held_imports_cost_submissions() {
let takes = {
let scratch = Scratch::new("in-place-check-untaxed");
let device = answering(&scratch, &AnswersRecord::new(ANSWERS));
let device = answering(&scratch, ANSWERS);
let buffer = device.new_buffer(2 * FRESH_PAGES_PAST, ResourceOptions::shared());
buffer.unwrap().in_fresh_pages()
};
let scratch = Scratch::new("in-place-check-taxed");
let device = answering(&scratch, &AnswersRecord::new(TAXED));
let device = answering(&scratch, TAXED);
assert!(
!device.fresh_pages_pay(),
"the recalled answers keep long buffers out of fresh pages"
@@ -242,13 +211,12 @@ fn the_in_place_check_checks_fresh_pages_where_held_imports_cost_submissions() {
#[test]
fn an_unchecked_verdict_is_checked_again_where_its_cause_may_pass_and_kept_where_it_lasts() {
let scratch = Scratch::new("in-place-check-unmade-pages");
let record = AnswersRecord::new(ANSWERS);
let pointer_reads = |device: &Device| {
let checks = &device.shared().in_place;
RowEnds::ALL.map(|rows| checks.verdict(PagesClass::Pointer, Access::Reads, rows))
};
let (first, note, first_notes) = {
let device = answering(&scratch, &record);
let device = answering(&scratch, ANSWERS);
device.fail_next_host_imports(1);
assert!(
device.settle_in_place_checks(WAIT),
@@ -279,7 +247,7 @@ fn an_unchecked_verdict_is_checked_again_where_its_cause_may_pass_and_kept_where
};
let dma_buf_reads = verdict_index(PagesClass::DmaBuf, Access::Reads, RowEnds::InLines);
let (second_reads, second_recalled) = {
let device = answering(&scratch, &record);
let device = answering(&scratch, ANSWERS);
let recalled = device.shared().in_place.verdicts();
let held = recalled
.iter()
@@ -335,7 +303,7 @@ fn an_unchecked_verdict_is_checked_again_where_its_cause_may_pass_and_kept_where
.count();
(reads, (held, unchecked))
};
let device = answering(&scratch, &record);
let device = answering(&scratch, ANSWERS);
assert_eq!(
pointer_reads(&device),
second_reads,
@@ -3,11 +3,14 @@
use crate::in_place::DriverIdentity;
use crate::submit_check::{
apart_floor, decode, encode, merge_clear, merge_tried, merge_try, merge_verdict, record_name,
tax_clear, tax_holds, tax_tried, tax_try, tax_verdict, tried, Measured, SubmitChecks, Timed,
Verdict, MERGED, MERGE_FAILS_CLEAR, MERGE_HOLDS_CLEAR, MERGE_RATIO, MERGE_REPEATS, ROUNDS,
TAX_FLOOR, TAX_MARGIN, TAX_PHASES, TAX_REPEATS, TAX_SUBMITS, TRIES,
apart_floor, decode, encode, merge_clear, merge_stands, merge_tried, merge_try, merge_verdict,
recalled, recheck_after, record_name, tax_clear, tax_holds, tax_stands, tax_tried, tax_try,
tax_verdict, tried, Load, Measured, Stands, SubmitChecks, Timed, Verdict, MERGED,
MERGE_FAILS_CLEAR, MERGE_HOLDS_CLEAR, MERGE_RATIO, MERGE_REPEATS, QUIET_ROUND_MOST,
QUIET_TRY_MOST, RECHECK_EVERY, RECHECK_FIRST, ROUNDS, TAX_FLOOR, TAX_MARGIN, TAX_PHASES,
TAX_REPEATS, TAX_SUBMITS, TRIES,
};
use std::time::Duration;
/// The probe's medians (2026-11-07, Mesa 26.2.6 under Linux 7.3.1, MoltenVK 1.4.2 under macOS
/// 27.0.1), in nanoseconds: one call of four infos and four calls apart; a submission with one
@@ -460,8 +463,8 @@ fn identity(device_id: u32) -> DriverIdentity {
}
/// A record decodes for its own identity alone, every verdict and measurement as written, and
/// names itself apart from another identity's; a record with a pending verdict, a truncated one
/// and one whose bytes changed decode to nothing.
/// names itself apart from another identity's; a record with no answer of a check holds it
/// pending; a truncated one and one whose bytes changed decode to nothing.
#[test]
fn a_record_holds_its_identity_s_verdicts() {
let (one, other) = (identity(0x15bf), identity(0x1114));
@@ -480,6 +483,117 @@ fn a_record_holds_its_identity_s_verdicts() {
let mut changed = bytes.clone();
changed[60] ^= 1;
assert_eq!(decode(&one, &changed), None);
let pending = encode(&one, [Verdict::Holds, Verdict::Pending], measured);
assert_eq!(decode(&one, &pending), None);
let pending = [Verdict::Holds, Verdict::Pending];
let bytes = encode(&one, pending, measured);
assert_eq!(decode(&one, &bytes), Some((pending, measured)));
}
/// A record's `Holds` and `Unchecked` stand for the device that reads it; its `Fails` is a hint
/// and no answer, as a check it holds none of: the device checks again (the load of one device's
/// checks would otherwise hold every later device of the release to a `Fails`).
#[test]
fn a_recorded_fails_is_no_answer() {
assert_eq!(recalled(Verdict::Holds), Some(Verdict::Holds));
assert_eq!(recalled(Verdict::Unchecked), Some(Verdict::Unchecked));
assert_eq!(recalled(Verdict::Fails), None);
assert_eq!(recalled(Verdict::Pending), None);
}
/// How far each answer stands: a `Holds` earned (clear of the load and repeated, past its margin
/// for the import tax) is recorded, and so is an `Unchecked` of a call refused; a `Fails` clear
/// of the load whose tries each ran quiet stands for the device's life and no further; every other
/// answer stands for now: a `Holds` or a `Fails` short of its record, a `Fails` whose tries did
/// not all run quiet, tries that all split. An import tax `Fails` is clear where a held import
/// adds at most half its bound: 2.1 against 2.2 us, as the RTX 5080's quiet devices measured, but
/// not 0.7 us more where the bound is 1 us.
#[test]
fn an_answer_stands_as_far_as_it_earned() {
let earned = [
(Verdict::Holds, true, Stands::Recorded),
(Verdict::Holds, false, Stands::Recorded),
(Verdict::Unchecked, true, Stands::Recorded),
(Verdict::Fails, true, Stands::Life),
(Verdict::Fails, false, Stands::Now),
];
for (verdict, quiet, stands) in earned {
assert_eq!(
merge_stands(verdict, true, quiet),
stands,
"{verdict:?} quiet {quiet}"
);
}
for verdict in [Verdict::Holds, Verdict::Fails, Verdict::Unchecked] {
for quiet in [true, false] {
assert_eq!(
merge_stands(verdict, false, quiet),
Stands::Now,
"{verdict:?} unearned"
);
}
}
let clear = (2_100, 2_200);
let held = (1_900 + TAX_FLOOR, 1_900);
assert_eq!(
tax_stands(Verdict::Holds, held, true, false),
Stands::Recorded
);
assert_eq!(
tax_stands(Verdict::Unchecked, (0, 0), true, true),
Stands::Recorded
);
assert_eq!(tax_stands(Verdict::Fails, clear, true, true), Stands::Life);
assert_eq!(tax_stands(Verdict::Fails, clear, true, false), Stands::Now);
assert_eq!(
tax_stands(Verdict::Fails, (1_900, 1_200), true, true),
Stands::Now
);
assert_eq!(tax_stands(Verdict::Fails, clear, false, true), Stands::Now);
assert_eq!(tax_stands(Verdict::Holds, held, false, true), Stands::Now);
assert_eq!(
tax_stands(Verdict::Unchecked, clear, false, true),
Stands::Now
);
}
/// An answer for now is checked again 1, 2, 4 ... 64 s after the one before, then each minute.
#[test]
fn checks_again_wait_twice_as_long_up_to_a_minute_apart() {
let waits: Vec<Duration> = (0..10).map(recheck_after).collect();
let seconds = |s: u64| Duration::from_secs(s);
assert_eq!(waits[0], RECHECK_FIRST);
assert_eq!(
waits,
[1, 2, 4, 8, 16, 32, 64, 60, 60, 60].map(seconds).to_vec()
);
assert_eq!(recheck_after(u32::MAX), RECHECK_EVERY);
}
/// A try ran quiet where each of its stand-bys found the device's work quiet, no round took past
/// [`QUIET_ROUND_MOST`] and all of them no more than [`QUIET_TRY_MOST`]: the Radeon 780M's quiet
/// tries (rounds of 61 to 104 us, the longest 1.3 ms, 4 to 6 ms a try) did; its loaded ones,
/// which waited 9.4 ms and more for a submission, did not.
#[test]
fn a_try_runs_quiet_within_its_bounds() {
let rounds = |quiet: bool, each: i64, count: usize| {
let mut load = Load::default();
for _ in 0..count {
load.round(quiet, each);
}
load
};
// A merge try's timed rounds, of both forms.
let count = 2 * ROUNDS;
assert!(rounds(true, 64_000, count).ran_quiet(), "a quiet try");
assert!(
!rounds(false, 64_000, count).ran_quiet(),
"a stand-by not found quiet"
);
let mut long = rounds(true, 64_000, count);
long.round(true, 9_400_000);
assert!(!long.ran_quiet(), "a round of 9.4 ms");
let mut longest = rounds(true, 64_000, count);
longest.round(true, QUIET_ROUND_MOST);
assert!(longest.ran_quiet(), "a round at the bound");
let slow = rounds(true, QUIET_TRY_MOST / count as i64 + 1, count);
assert!(!slow.ran_quiet(), "a try past its bound in all");
}
@@ -1,6 +1,6 @@
//! The device's submission checks (`submit_check.rs`) on the device the cfg selects: they answer,
//! a second device of the same driver reads their record and runs none, and the paths they choose
//! follow their verdicts alone.
//! a second device of the same driver reads their record and runs those it holds, and the paths
//! they choose follow their verdicts alone.
//!
//! - **They answer.** A device made over a fresh shader cache runs its checks once
//! (`WorkCounts::submit_checks_run`), each verdict an answer (never pending once settled), their
@@ -8,10 +8,12 @@
//! (`device_checks`), and their commands among none of the device's (`commands_recorded`: a
//! device that ran them recorded the copies one that recalled them did, besides its priming's,
//! which a device made again on what stays loaded leaves out); a later device over the
//! same cache recalls them
//! (`submit_checks_recalled`), runs none, and holds the verdicts of the last device that ran
//! them: the first's, or, where load split its tries or its import tax answered `Holds` short
//! of a record and nothing was recorded, those of the next device that ran them.
//! same cache recalls each answer the first recorded (`submit_checks_recalled`) and checks again
//! each other, a `Fails` among them: a record's `Fails` is no answer
//! ([`a_recorded_fails_is_checked_again`]).
//! - **Load lifts an answer for now.** A merge answer whose tries load lifted is checked again
//! in the device's life, which comes to the answer of tries clear of it and records no `Fails`
//! ([`a_lifted_merge_answer_is_checked_again`]).
//! - **No remap under an import.** The checks map no page over a live import of it: they make and
//! bind no buffer, and every import of theirs is freed by the time they answer
//! ([`a_device_s_checks_map_no_pages_over_a_live_import`]).
@@ -31,7 +33,10 @@
use super::blit_holds::{Scratch, WAIT};
use crate::fresh_pages::FRESH_PAGES_PAST;
use crate::submit_check::{record_name, Check, Verdict, MERGED, TAX_IMPORTS};
use crate::submit_check::{
decode, encode, lift_next_merge_tries, record_name, Check, Measured, Stands, Verdict, MERGED,
MERGE_REPEATS, TAX_IMPORTS,
};
use crate::tests::SETTLE;
use crate::{
CommandBufferStatus, Device, DeviceKind, DeviceOptions, EventRef, LayerSetting,
@@ -118,7 +123,7 @@ fn the_checks_answer_once_and_a_second_device_recalls_them() {
let counts = first.work_counts();
// The copies besides its priming's, which a device made again on what stays loaded leaves
// out.
let mut copies = counts.commands_recorded.cmd_copy_buffer - primed;
let copies = counts.commands_recorded.cmd_copy_buffer - primed;
assert_eq!(counts.submit_checks_run, 1);
assert_eq!(counts.submit_checks_recalled, 0);
assert!(
@@ -148,50 +153,213 @@ fn the_checks_answer_once_and_a_second_device_recalls_them() {
// it) as it goes, so the second is a new device over the same directory, as a later
// process's would be.
let identity = first.driver_identity();
let recorded = recorded_of(&first);
drop(first);
// The verdicts of the last device that ran the checks, which its record holds where it wrote
// one (a device whose tries split, or whose import tax `Holds` fell short of its margin or of
// its record, writes none, and the next runs them again).
let mut ran = answered;
let start = std::time::Instant::now();
loop {
let (second, primed) = device_primed(&scratch.0);
assert!(
second.settle_submit_checks(SETTLE),
"the second device never answered"
// The second recalls each answer the first recorded, and checks again each other: a `Fails`
// (never recorded), and an answer for now (tries split or short of their record).
let (second, primed) = device_primed(&scratch.0);
assert!(
second.settle_submit_checks(SETTLE),
"the second device never answered"
);
let counts = second.work_counts();
let checks = &second.shared().submit_checks;
let tries = [
checks.merge_tries.load(Ordering::Relaxed),
checks.tax_tries.load(Ordering::Relaxed),
];
println!(
"{} again, the first's answers recorded {recorded:?}: {}",
second.name(),
second.submit_check_report()
);
let name = record_name(&identity);
assert_eq!(
counts.submit_checks_recalled,
u64::from(recorded.iter().any(Option::is_some)),
"the record {name} was read where the first recorded an answer: found at {:?}, \
identities {identity:?} and {:?}",
files_named(&scratch.0, &name),
second.driver_identity(),
);
for (at, check) in Check::ALL.into_iter().enumerate() {
match recorded[at] {
Some(verdict) => {
assert_eq!(
tries[at], 0,
"{check:?}: a recorded answer was checked again"
);
assert_eq!(
checks.verdict(check),
verdict,
"{check:?}: the recorded answer"
);
}
None => assert!(
tries[at] > 0,
"{check:?}: an answer that earned no record was not checked again"
),
}
}
if recorded.iter().all(Option::is_some) {
assert_eq!(counts.submit_checks_run, 0);
assert_eq!(counts.submit_check_calls, 0);
assert_eq!(verdicts(&second), answered);
assert_eq!(
counts.commands_recorded.cmd_copy_buffer - primed,
copies,
"the device that ran the checks recorded other copies than one that recalled them"
);
let counts = second.work_counts();
if counts.submit_checks_recalled == 1 {
assert_eq!(counts.submit_checks_run, 0);
assert_eq!(counts.submit_check_calls, 0);
assert_eq!(verdicts(&second), ran);
assert_eq!(
counts.commands_recorded.cmd_copy_buffer - primed,
copies,
"the device that ran the checks recorded other copies than one that recalled them"
);
}
}
/// Each answer of `device`'s checks that earned a record (`Stands::Recorded`), by check.
fn recorded_of(device: &Device) -> [Option<Verdict>; Check::COUNT] {
let checks = &device.shared().submit_checks;
Check::ALL.map(|check| {
(checks.stands(check) == Some(Stands::Recorded)).then(|| checks.verdict(check))
})
}
/// A record's `Fails` is a hint and no answer (`submit_check.rs`, "Kept"): a device that reads a
/// record holding a `Fails` of each check, as an earlier device's checks under load could have
/// written, checks both again; one that reads a merge `Holds` and an import tax `Fails` takes the
/// `Holds` and checks the import tax again. Printed (`STALE-FAILS`).
#[test]
fn a_recorded_fails_is_checked_again() {
let scratch = Scratch::new("submit-check-stale-fails");
let first = device(&scratch.0);
assert!(
first.settle_submit_checks(SETTLE),
"the checks never answered"
);
let identity = first.driver_identity();
let path = (first.shared().shader_cache.content_store().directory())
.expect("a device over a cache of its own")
.record_path(&record_name(&identity));
// Its own record, where it wrote one, is in place once it is gone.
drop(first);
for planted in [
[Verdict::Fails, Verdict::Fails],
[Verdict::Holds, Verdict::Fails],
] {
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, encode(&identity, planted, Measured::default())).unwrap();
let device = device(&scratch.0);
assert!(
device.settle_submit_checks(SETTLE),
"the checks never answered"
);
let checks = &device.shared().submit_checks;
let tries = [
checks.merge_tries.load(Ordering::Relaxed),
checks.tax_tries.load(Ordering::Relaxed),
];
println!(
"STALE-FAILS {} read {planted:?}: {}",
device.name(),
device.submit_check_report()
);
assert_eq!(
device.work_counts().submit_checks_recalled,
1,
"the planted record was not read"
);
for (at, check) in Check::ALL.into_iter().enumerate() {
match planted[at] {
Verdict::Fails => {
assert!(
tries[at] > 0,
"{check:?}: a recorded Fails was taken as its answer"
);
assert!(
checks.stands(check).is_some(),
"{check:?}: checked again, it gave no answer"
);
}
verdict => {
assert_eq!(
tries[at], 0,
"{check:?}: a recorded {verdict:?} was checked again"
);
assert_eq!(checks.verdict(check), verdict);
}
}
}
drop(device);
}
}
/// A merge answer whose tries the load beside them lifted stands only for now: the device checks
/// again later in its life, takes the answer of tries clear of that load, and records no `Fails`
/// (`submit_check.rs`, "Load beside it", "Answers for now"). The load is the one the Radeon
/// 780M's checks met beside other jobs on its host: one call of every round of both forms about
/// 70 us longer, which `lift_next_merge_tries` adds to each try of the device's first merge
/// answer (`LIFT`), each of them read as not quiet. A device of the same driver made before it
/// over a cache of its own gives the answer the lifted one comes to. Printed (`LIFTED`).
#[test]
fn a_lifted_merge_answer_is_checked_again() {
let quiet = Scratch::new("submit-check-unlifted");
let reference = device(&quiet.0);
assert!(
reference.settle_submit_checks(SETTLE),
"the checks never answered"
);
let scratch = Scratch::new("submit-check-lifted");
lift_next_merge_tries(1 + MERGE_REPEATS as u32);
let device = device(&scratch.0);
assert!(
device.settle_submit_checks(SETTLE),
"the checks never answered"
);
let checks = &device.shared().submit_checks;
let first = (checks.verdict(Check::Merge), checks.stands(Check::Merge));
println!(
"LIFTED {} first: {}",
device.name(),
device.submit_check_report()
);
assert_eq!(
first.1,
Some(Stands::Now),
"a lifted answer stood past now: {first:?}"
);
// Within the first checks again, the device comes to the answer the device beside it gives.
let deadline = Instant::now() + WAIT;
loop {
let expected = reference.shared().submit_checks.verdict(Check::Merge);
let rechecked = checks.rechecks.load(Ordering::Relaxed) > 0;
if rechecked && checks.verdict(Check::Merge) == expected {
break;
}
if counts.submit_checks_run == 1 {
println!("{} again: {}", second.name(), second.submit_check_report());
ran = verdicts(&second);
copies = counts.commands_recorded.cmd_copy_buffer - primed;
}
if start.elapsed() >= WAIT {
let name = record_name(&second.driver_identity());
let found = files_named(&scratch.0, &name);
let statistics = second.shader_cache_statistics();
panic!(
"no device recalled the record {name}: found at {found:?}; the second device's \
cache rejected {} and failed {} reads; identities {:?} and {:?}",
statistics.rejected,
statistics.read_failures,
identity,
second.driver_identity(),
);
}
drop(second);
std::thread::sleep(std::time::Duration::from_millis(50));
assert!(
Instant::now() < deadline,
"the lifted device kept {:?} where the other answers {expected:?}: {}; the other: {}",
checks.verdict(Check::Merge),
device.submit_check_report(),
reference.submit_check_report(),
);
std::thread::sleep(Duration::from_millis(10));
}
println!(
"LIFTED {} then: {}; the device beside it: {}",
device.name(),
device.submit_check_report(),
reference.submit_check_report()
);
// Its record, where it wrote one, holds no merge `Fails`.
let path = (device.shared().shader_cache.content_store().directory())
.expect("a device over a cache of its own")
.record_path(&record_name(&device.driver_identity()));
let identity = device.driver_identity();
drop(device);
if let Ok(bytes) = std::fs::read(&path) {
let (verdicts, _) = decode(&identity, &bytes).expect("the device's record decodes");
assert_ne!(
verdicts[0],
Verdict::Fails,
"the record holds the merge's Fails"
);
}
}
+1 -1
View File
@@ -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 = 2534;
pub const RUNTIME_VERSION: u32 = 2538;
/// 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
+1 -1
View File
@@ -35,7 +35,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X
| A blend into a packed 16-bit attachment the device renders through its word view (`A1BGR5Unorm`, `ABGR4Unorm` on the RTX 5080; `WordAttachment`), which the function computes in the interlocked storage form, reads the attachment's codes, where Metal's tile holds the pass's clear and each earlier blend's result as a `half`, finer; under fast math it also sums a few states otherwise than Metal. Every device rendering such an attachment. | The in-shader blend over the codes (no switch) | **Not built yet:** the extended-range attachments' `half` shadow (`render/extended_shadow.rs`, `VariantKey::extended_shadows`) taken by word attachments: the runtime's shadow start and end, its load of the codes and the clear's halves, and the word's shadowed variant in `lower::fragment::fetch`, for a single-sampled pass and a multisampled one (an extended-range color's shadow holds per sample, from the pass's clear). Fast math's regrouped sums have no model | One code: without fast math exact over a loaded attachment (the 2,891 states of the M3 sweep, every channel), under fast math 3,527 of 94,732,288 channels a code apart; after a clear or an earlier blend in the pass, a code apart where the two readings store different codes. `DeviceColorConversion` (`device-color-conversion`) | Not measured. Expected from the shadow's form: an `R16G16B16A16_SFLOAT` image of the pass's extent per such color (8 bytes a pixel, 16.6 MB at 1920x1080), set at the draw it starts by a fill or a load dispatch, and an 8-byte storage read and write per blended fragment inside the interlock beside the word's |
| A heap's colour texture that Metal keeps losslessly compressed (`allowGPUOptimizedContents`, no `ShaderWrite`, `PixelFormatView` or `ShaderAtomic` usage, 16 texels or more a side), on a driver whose compressed images may keep their texels apart from the memory they are bound to (`DriverFact::CompressedImagesHideAliasedWrites`: ANV), is the driver's compressed optimal image, its compression and fast clears kept. A texture Metal keeps uncompressed takes the uncompressed image under either value. The runtime's choice: no pipeline differs. | `heap_compression = HeapCompressionPolicy::Compressed` | `heap_compression = HeapCompressionPolicy::Uncompressed`: an image the driver keeps uncompressed in the heap's bytes, as for a texture Metal keeps uncompressed: host-transfer usage where the device enabled `hostImageCopy` (`heap-texture-host-transfer`), else a linear image (`heap-texture-linear`), else the optimal one (`heap-texture-hides-aliased-writes`) | A write through a buffer or another texture over the texture's bytes may leave its texels as they were or change them otherwise than as written, where Metal's texture reads opaque magenta (`0xffff00ff`) in every texel of drawn content the write covers and the written bytes where it held only a clear; the texture's own writes may show in those bytes compressed. Within Metal's contract: Metal documents such a texture's layout as its own (`allowGPUOptimizedContents` lets it "adjust the private layout"), so no write through another view over its bytes has a defined result there either. `HeapTextureCompressed` (`heap-texture-compressed`), announced once per device where such a texture is made; `runtime_lane::heap_textures` | ANV (Iris Xe of RPL-P; `heap_textures::heap_compression_costs`), a 2048x2048 `RGBA8Unorm` render target in a `Private` placement heap: a pass that clears it 26.9 us against 676.2-676.5 us; a copy into another such texture 647.7-649.1 us against 673.9-693.2 us. The compressed image lies in the heap only where the heap's answer holds it (`heap_answers = HeapAnswerPolicy::Device`, the next row). This 2048x2048 texture's does not under either answer policy, so it takes the linear image under either compression value: a clear 963.5 us against 958.4 us under `heap_answers = HeapAnswerPolicy::Metal`, 955.3 us against 971.4 us under the default, the copy 488-496 us |
| A heap texture whose image of the route the device takes for it needs more bytes or a coarser alignment of the heap than Metal's answer (each of a guest compositor's 22 heap shapes, `RGBA16Float` 2D arrays of one slice and 2D textures to 456x255: on ANV, whose compressed images align to 64 KiB; on the RTX 3090 at 1024; on the RX 7900 XTX at 256 to 64 KiB, where Metal answers 128 for each but the 299x299 array's 16 KiB): the size query (`heapTextureSizeAndAlign`) answers the larger of Metal's answer and that image's, and the texture lies in that image in the heap's bytes. A `Shared` texture's answer also holds the linear image a heap over host pages binds for it. Its alignment is the device's up to a heap's memory's own, 256 KiB, past which no image binds there (on the RX 7900 XTX, 128 KiB for a depth image and 256 KiB for a 4-sample render target past 128 texels a side). Where that image's alignment is past 256 KiB, or past both 4 KiB and the texture's size, the texture's image that a 4 KiB alignment holds takes its place (host-transfer usage, else linear), the answer that one's; else Metal's answer, as under the switch. A multisample texture takes it too and lies in its image in the heap's bytes, in the driver's layout of its samples, where under the switch it is a shadow of its samples in Metal's tiles (`heap_placed_targets`: a frame's 4-sample `RGBA16Float` and `Depth32Float` targets placed in a tracked `Private` heap). Metal's measured answers (4:2:2, one-plane YCbCr, two-plane extended-range, `X32_Stencil8`, `BlockWritesOnly` textures) and textures whose image lies in memory of its own keep Metal's answer. The runtime's choice: no pipeline differs. | `heap_answers = HeapAnswerPolicy::Device` | `heap_answers = HeapAnswerPolicy::Metal`: Metal's answer; the texture lies in an image that fits it (host-transfer usage, else linear: `heap-texture-host-transfer`, `heap-texture-linear`), else is a shadow of the heap's bytes in Metal's tiles, copied in before and out after the commands that use it (`shadowed-texture`) | A heap holds fewer such textures than Metal's: of the 22 shapes, the small arrays answer 4096 bytes where Metal answers 128 to 2176 (on ANV and the XTX; the XTX's 1x1 answers 256), and the 22 answers take 3769962 bytes of heaps placed one after another on ANV and 4155498 on the XTX, against Metal's 3656426 (`heap_texture_images`, `HEAP-COUNT`). A program that places a heap's resources by sizes of its own rather than the query's may overlap the texture with its neighbour; Metal's answer differs by GPU too (65536 on an AMD Radeon Pro 5300M, 4096 on an Intel UHD 630, 128 on an M3). `HeapTextureLargerThanMetal` (`heap-texture-larger-than-metal`), announced once per device; `tests::heap`, `tests::heap_placed_targets`, `heap_shadow_costs::heap_texture_images` | Of the 22 shapes made in heaps under the switch (`heap_texture_images`), on ANV (Iris Xe of RPL-P) 14 lie in an image put in place of their first one and 7 are shadows in Metal's tiles; on the RX 7900 XTX (RADV) 1 and 8, every other answer Metal's; under the default none on either. ANV (`heap_shadow_costs::heap_texture_shadow_costs`), a 1x1 `RGBA16Float` array held as a shadow: a frame that clears it and blits it 34.7 us in the heap against 8.2 us outside |
| Batches of command buffers committed on one queue that the scheduler finds ready together (a backlog) go to the driver in one `vkQueueSubmit`, at most four and at most 16 ms of their queues' expected GPU runs summed (`GROUP_RUN`, `command_buffer/group.rs`: a kernel job that a timeout ends as a whole, as Linux's amdgpu ends one past 2 s by default, never carries more of the others' expected work than that), only the last signalling the queue's timeline, on a device whose own check finds a submission that signals nothing merged into the next (`submit_check.rs`, once per driver, release and kernel: one `vkQueueSubmit` of four empty infos against four calls of one, merged where the one costs at most 0.6 of the four; Mesa 26.2.6's RADV on the Radeon 780M, the RX 7900 XTX and the RX 550 at 0.33-0.38, ANV on the Iris Xe of RPL-P at 0.39, MoltenVK 1.4.2 on the M3 Max at 0.98; a device whose check has not answered, or that does not merge, takes the ungrouped form under either value of the switch): one kernel submission, where ANV on i915 lists every `VkDeviceMemory` in each (the consumer's guest drag on the Iris Xe: about 300 entries per execbuffer, 260 of them its host imports, at 112 to 128 execbuffers a frame). A batch's event signals ride to the group's end, which signals each event's semaphore to the highest index the batches held signal it to (an event's indices rise in commit order). A batch that signals a binary semaphore, takes a fence, binds a sparse update, does first work, names the caller's wrapped image, or waits for anything not seen complete (an event, another queue's work) goes alone, after the batches held: a batch with a wait leads a group, never joins one. Nor does an unshared queue's batch (`Device::new_command_queue_unshared`) on a `VkQueue` whose other queues' work is held back for it (`UnsharedIsolationPolicy::Bounded`, the default), and no group is kept there while earlier work runs (below): on RADV, ANV and lavapipe, whose one graphics `VkQueue` every command queue shares, a live unshared queue so keeps no group of any queue. Each batch on a `VkQueue` whose batches group that goes in a kernel submission of its own counts once by why (`WorkCounts::batches_alone_unshared` and kin), and `WorkCounts::batches_of_unshared_queues` counts the unshared queues' batches under either value. So does a batch whose queue's expected run is unknown (none of its batches seen complete yet) or would take the group past 16 ms (`WorkCounts::group_ends_long`), leading the next group where its own run is within the bound; a queue's expected GPU run follows its command buffers' own GPU times by their timestamps (raised at once by a longer one, halved toward a shorter one), which other `VkDevice`s' work on the GPU does not lengthen; with `DeviceOptions::gpu_times_from_host` it follows those host times, which hold other clients' work on the GPU too, so under contention there a queue's batches may stop grouping. So that checked command buffers (the consumer checks each) are found ready together, the submission checks of up to three batches right behind a line's head that goes run with the head's, in commit order, none committed after another queue's batch: such a check runs before the previous batch's `vkQueueSubmit` rather than after it, in the scheduler pass that submits its own batch. A pass that finds no batch ready sends the batches held, unless two or more earlier submissions of their `VkQueue` are not seen complete: the GPU runs those first in any case, so the batches stay held, and those committed meanwhile join them, until one submission is left in flight (a completion turn wakes the scheduler at its value), the group fills, a later batch sends it, a head waits for the GPU, or a thread waits for one of their command buffers' completion, which sends them at once; nor are they kept where the scheduler's thread runs next a submission handler of another queue's command buffer (one a pass that settled a switch of storage forms keeps; the thread hands every other pass's to the device's handler threads, where none holds its passes back): they go first, as Metal schedules a queue's command buffers whatever another queue's handler does (an M3 Max, probe `cross_queue_handler_waits`); a batch that ends a command buffer with a switch of storage forms riding on it, which settles by its submission's outcome, is never kept so. A batch a committing thread submits (`CommandBuffer::commit_and_submit`) goes alone where its `VkQueue` runs at most one earlier submission not seen complete, as the pass that held it would send the group at once; where two or more run it is left to the scheduler's thread, which holds it. A held batch that ends its command buffer is `Scheduled` as it is held, its submission handlers run first, then its scheduled handlers, and its kernel end time set, as an M3 Max schedules a command buffer committed behind running work 0.04 to 0.18 ms after its commit. The runtime's: no pipeline differs. | `completLine truncated
| Batches of command buffers committed on one queue that the scheduler finds ready together (a backlog) go to the driver in one `vkQueueSubmit`, at most four and at most 16 ms of their queues' expected GPU runs summed (`GROUP_RUN`, `command_buffer/group.rs`: a kernel job that a timeout ends as a whole, as Linux's amdgpu ends one past 2 s by default, never carries more of the others' expected work than that), only the last signalling the queue's timeline, on a device whose own check finds a submission that signals nothing merged into the next (`submit_check.rs`, once per driver, release and kernel where it finds the merge, at each device's making where it does not, a `Fails` never recorded, and again in the device's life, 1, 2, 4 ... 64 s after its first answer and then each minute, where load beside its tries left the answer open: one `vkQueueSubmit` of four empty infos against four calls of one, merged where the one costs at most 0.6 of the four; Mesa 26.2.6's RADV on the Radeon 780M, the RX 7900 XTX and the RX 550 at 0.33-0.38, ANV on the Iris Xe of RPL-P at 0.39, MoltenVK 1.4.2 on the M3 Max at 0.98; a device whose check has not answered, or that does not merge, takes the ungrouped form under either value of the switch, and one whose check answers `Holds` later in its life groups from then): one kernel submission, where ANV on i915 lists every `VkDeviceMemory` in each (the consumer's guest drag on the Iris Xe: about 300 entries per execbuffer, 260 of them its host imports, at 112 to 128 execbuffers a frame). A batch's event signals ride to the group's end, which signals each event's semaphore to the highest index the batches held signal it to (an event's indices rise in commit order). A batch that signals a binary semaphore, takes a fence, binds a sparse update, does first work, names the caller's wrapped image, or waits for anything not seen complete (an event, another queue's work) goes alone, after the batches held: a batch with a wait leads a group, never joins one. Nor does an unshared queue's batch (`Device::new_command_queue_unshared`) on a `VkQueue` whose other queues' work is held back for it (`UnsharedIsolationPolicy::Bounded`, the default), and no group is kept there while earlier work runs (below): on RADV, ANV and lavapipe, whose one graphics `VkQueue` every command queue shares, a live unshared queue so keeps no group of any queue. Each batch on a `VkQueue` whose batches group that goes in a kernel submission of its own counts once by why (`WorkCounts::batches_alone_unshared` and kin), and `WorkCounts::batches_of_unshared_queues` counts the unshared queues' batches under either value. So does a batch whose queue's expected run is unknown (none of its batches seen complete yet) or would take the group past 16 ms (`WorkCounts::group_ends_long`), leading the next group where its own run is within the bound; a queue's expected GPU run follows its command buffers' own GPU times by their timestamps (raised at once by a longer one, halved toward a shorter one), which other `VkDevice`s' work on the GPU does not lengthen; with `DeviceOptions::gpu_times_from_host` it follows those host times, which hold other clients' work on the GPU too, so under contention there a queue's batches may stop grouping. So that checked command buffers (the consumer checks each) are found ready together, the submission checks of up to three batches right behind a line's head that goes run with the head's, in commit order, none committed after another queue's batch: such a check runs before the previous batch's `vkQueueSubmit` rather than after it, in the scheduler pass that submits its own batch. A pass that finds no batch ready sends the batches held, unless two or more earlier submissions of their `VkQueue` are not seen complete: the GPU runs those first in any case, so the batches stay held, and those committed meanwhile join them, until one submission is left in flight (a completion turn wakes the scheduler at its value), the group fills, a later batch sends it, a head waits for the GPU, or a thread waits for one of their command buffers' completion, which sends them at once; nor are they kept where the scheduler's thread runs next a submission handler of another queue's command buffer (one a pass that settled a switch of storage forms keeps; the thread hands every other pass's to the device's handler threads, where none holds its passes back): they go first, as Metal schedules a queue's command buffers whatever another queue's handler does (an M3 Max, probe `cross_queue_handler_waits`); a batch that ends a command buffer with a switch of storage forms riding on it, which settles by its submission's outcome, is never kept so. A batch a committing thread submits (`CommandBuffer::commit_and_submit`) goes alone where its `VkQueue` runs at most one earlier submission not seen complete, as the pass that held it would send the group at once; where two or more run it is left to the scheduler's thread, which holds it. A helLine truncated
| Batches of command buffers on one `VkQueue`, on a driver measured to start no kernel submission of a queue before the one before it completed (ANV, RADV and NVIDIA's; `batch_order.rs`), are ordered by their ends: each ends with a barrier ordering its work before every later command of its `VkQueue` (the exact form's end orders it before the host's reads and writes alone), so a batch that depends on an earlier one there begins with no barrier of its own, often no command buffer of barriers, and its GPU start, written at the top of the pipe, waits behind that end barrier until everything before it completed. Metal starts an independent command buffer committed behind running work while that work runs (an M3 Max under macOS 27.0.1, probe `gpustart`); those drivers ran two batches of independent work one after the other under every shape measured (no end barrier, the host's or the widened one; in one `vkQueueSubmit` or two, merged into one kernel submission or not), where two dispatches of one command buffer ran side by side. The runtime's: no pipeline differs. | `batch_order = BatchOrderPolicy::Ends` | `batch_order = BatchOrderPolicy::Exact`: a barrier for each dependency of a batch's work on an earlier batch's of its `VkQueue`, the end's barrier to the host's reads and writes alone, the GPU start written at the top of the pipe; every other driver takes it under either value | None: on those drivers each batch starts once the one before it completed under either value, so the work's order, its results and its GPU times are the same, and a batch's GPU start is the end of the work before it, when such a driver starts it. Not announced; `runtime_lane::commit_work` and `runtime_lane::gpu_times` test both values | UHD 770 (ANV, RPL-S), the consumer's frame shape over 520 host imports, 67 command buffers a frame, Grouped completion, the widened end barrier against the exact form (a probe build of each): with no fill ahead of each command buffer, 67.0 command buffers submitted a frame against 129.3-129.7, the GPU's span a frame 1.84-1.90 ms against 1.99-2.06 ms, a frame through completion 2.13-2.22 ms against 2.27-2.38 ms; with a 1 MiB fill ahead of each, 134.0 against 262.9, 8.03-8.22 ms against 8.32-8.42 ms, 9.00-9.15 ms against 9.25-9.36 ms. Radeon 780M (RADV, Mesa 26.0.8), this switch: with no fill, 67.0 against 128.9-129.0, a frame through completion 48.3-48.6 ms against 42.6-47.0 ms; with a 16 MiB fill committed at once, 134.0 against 251.0-251.1, 50.6-50.8 ms against 50.8-57.3 ms; committed every 1 ms, 134.0 against 249.7-250.2, 71.3-83.6 ms against 106.3-113.6 ms (each kernel submission there leaves about 2.5 ms of the GPU idle over 520 host imports, which sets these frames) |
| Command queues on a device whose GPU idles when consecutive work comes from another `VkQueue` share `VkQueue`s by choice (`queue_share.rs`): the runtime's own self-check, not a `DriverFact` row, measures that idling once per driver, release and runtime on a thread of its own and keeps its verdict (`Idles`, `DoesNotIdle`, `Unchecked`) in the shader cache's directory, as the in-place check keeps its own (`queue_switch_check.rs`: 48.7 to 51.3 us a switch on the RTX 5080 Laptop GPU, NVIDIA 615.71.09, `Idles` above 20 us). A command queue that makes a command buffer while it holds no other uncompleted one moves onto the busy `VkQueue` of its family whose oldest batch has run under 0.5 ms, the most batches in flight first, so short command buffers of several queues run with no switch between them. A queue one of whose command buffers ran on the GPU for over 2 ms, by its own timestamps (not the host's view of how long it ran as its `VkQueue`'s oldest, which also holds its wait for the GPU to start it and the waiter's lateness to see it complete), or held its `VkQueue` for over 2 ms from the submission of a batch that waited on the GPU for another `VkQueue`'s work (an `MTLEvent`'s signal, the tracker's wait, new resources' first work) to its own GPU end, is long: no queue joins its `VkQueue` while it lives, and it moves once more, at its next idle point, to an idle `VkQueue` no long or unshared queue holds. A queue whose command buffers must never wait behind another queue's (a compositor's beside an application's) is made with `Device::new_command_queue_unshared`: it never moves and no queue joins its `VkQueue`. Under either value, as a queue is made, it takes the round robin's `VkQueue` the fewest live command queues hold, of those no unshared queue holds, in turn among equals, and an unshared queue one no command queue holds where one is free (one pass over the `VkQueue`s' counts; one that finds none shares the one the fewest hold, `WorkCounts::unshared_queues_sharing_a_vk_queue`). Presenting queues and a queue that lent its `VkQueue` (`with_vk_queue`) never move. Before the verdict, and where it is not `Idles` or there are no two `VkQueue`s of one family (MoltenVK, RADV, lavapipe), every queue keeps the `VkQueue` it took at its creation; so does every queue of a device whose command buffers write no GPU timestamps it reads (`gpu_times_from_host`, or a driver whose timestamps wait for every queue's), which does not share and is counted (`WorkCounts::queue_sharing_untimed`). The runtime's: no pipeline differs. | `queue_sharing = QueueSharingPolicy::Adaptive` | `queue_sharing = QueueSharingPolicy::PerQueue`: each command queue keeps the `VkQueue` it took at its creation (the fewest live queues' as above), and the check does not run | A command buffer waits behind the command buffers of the queues sharing its `VkQueue`, where Metal's queues wait for each other only inside one command. The residual stall: once per logical queue that goes long, for a queue that joined its `VkQueue` during its short phase, about one long command buffer's length: the command buffers committed behind that queue's first long one there wait for its whole length (and those behind its later ones while it holds work, until its next idle point). Measured on the RTX 5080 Laptop GPU beside an application that alternates draws with 30 ms command buffers: a shared compositor's commits at 4,800 a second had 64 completions over 10 ms, at most 26.4 to 30.1 ms, in each of 3 runs of each of two such shapes (one join each), against none over 10 ms under `PerQueue` in those 6 runs (at most 5.6 to 9.7 ms); with 2 ms of draws between long command buffers, none over 10 ms in 3 runs (at most 5.7 to 9.8 ms) against 7, 0 and 0 under `PerQueue` (at most 6.9 to 11.2 ms). On an unshared queue, 0 over 10 ms in every run. A command buffer's GPU start time includes the other queues' work before it. `QueueSharing` (`queue-sharing`), at the device's first join | Command buffers a second on the RTX 5080 Laptop GPU, one-draw command buffers, each thread its own queue, the default against `PerQueue`, runs after a lock hold's first: 8 threads with 3 in flight 50.7k to 54.7k against 27.4k to 28.0k (5 runs each); 8 threads with 1 in flight 47.0k to 50.1k against 13.9k to 14.3k (5); 2 threads with 3 in flight 28.0k to 53.7k against 21.4k to 28.0k (10 each, in turn, the default above `PerQueue` in each pair; no thread's queue marked long), and beside another process's 30 ms command buffers 5.1k to 6.7k against 4.0k to 4.1k (3 each; the host's view marked a thread's queue long in 1 of 3 runs, which then ran at `PerQueue`'s 4.1k); 2 threads with 1 in flight 16.9k to 20.7k against 10.1k to 11.5k (5); one thread over 16 queues in turn 21.7k to 43.3k against 10.2k to 11.1k, over 2,048 20.0k to 39.2k against 10.2k to 11.2k (4). Beside an application whose queue never shared with the compositor (isolation, 300 and 30 dispatches), both 0 over 10 ms |
| A chain of `half` additions, subtractions and products on a device without `shaderFloat16` (vk12-floor, SwiftShader, Pascal; capability emulation: the module computes each in `float` and rounds it by the device's `OpQuantizeToF16`): an operation whose flags hold `contract` and `reassoc` and whose result only such operations read is held at `float` precision unrounded, so the chain rounds where a value leaves it (a store, an output, a conversion, a comparison, a call, a phi, a vector move, an operation without both flags), one quantize per exit instead of one per operation (`lower::arith::half_chain`). A device with `shaderFloat16` computes `half` alike under either value. | `half_chains = HalfChainPolicy::AtExits` | `half_chains = HalfChainPolicy::EachOperation`: every operation's result rounded to `half`, as the AIR computes it | The result may differ from the rounded operations' by the roundings the chain skips, each within half a unit in the last place of a `half` at its step, compounded along the chain; a value inside the chain past `half`'s range (65504) stays finite where the rounded operations reach infinity. Within the AIR's flags, which let a compiler regroup and fuse such operations. `FastMathRewrites` (`fast-math-rewrites`) | Not timed. Size on vk12-floor (the fixtures' SPIR-V words, the default against the accurate form): `hfb_filter_bank` 121,270 against 131,766 (1,024 quantizes against 2,464), `grd_half_many_samples` 82,019 against 84,627, `nan_half_fast` 9,808 against 9,832 |
+5 -2
View File
@@ -424,8 +424,11 @@ released:
does.
A blit whose released buffer the device cannot import again (out of memory) is refused.
- An import of the pointer, on a device whose held pointer imports add to every submission's cost,
as the device checks once per driver, release and kernel (its import tax check, which holds 32
imports of its own pages through timed submissions; RADV and ANV on i915 pay it). The new import
as the device checks (its import tax check, which holds 32 imports of its own pages through
timed submissions; RADV and ANV on i915 pay it): once per driver, release and kernel where it
finds that cost, at each device's making where it does not (an answer that no import costs is
never recorded), and again in the device's life where load beside its tries left the answer
open. The new import
at the same pointer reads the pages the kept one did: `HostMemory::new`'s contract keeps the
caller's pages mapped there, with the same backing, while the buffer lives. Buffers made before
the check answered keep their imports. A blit whose released buffer the device cannot import