In-place verdicts by row ends: texels that share a line of the device's memory with bytes beside them, and texels that share none

On the Iris Xe (ANV) a pass that clears and stores a linear image, and a draw into it, write back
whole the 64-byte line that holds a row's last texels. That puts an older value back over a CPU
write beside the texels, so the check fails render targets over host pages there, and every such
texture is a shadow. The write-back cannot reach a CPU write when no line holds both a texel and
a byte beside the texels: the probe read 0/100 for rows that end on a line, and 0/25 for a
3840x2160 surface of tight rows. A 3840x2160 BGRA8Unorm surface's 15360-byte rows are 240 lines
each.

The check's verdicts are now kept per class, access and row ends (in_place::RowEnds):
- The line is the device's nonCoherentAtomSize. vkspec defines it as "the size and alignment in
  bytes that bounds concurrent access to host-mapped device memory".
- RowEnds::of reads the texels' address, offset and pitches. Texels are OnLines where their first
  byte and their end lie on a line, and so do each row's (or slice's) start and end where bytes
  lie between rows (or slices). Elsewhere they are InLines.
- The check runs the shapes whose texels share no line first (Shape::rows; seven of SHAPES at
  64-byte lines). A byte changed beside one of them fails both row ends. A byte changed beside a
  shape that shares a line fails InLines alone, since the OnLines rounds have already run (the
  verdicts function). A device that fails InLines now also runs its OnLines shapes.
- SHAPES gains two shapes whose rows end inside a 16-byte line, at the 16-byte pitch a driver
  that lays rows tight uses: BGRA8Unorm 101x51 at 416 bytes and RGBA16Float 33x17 at 272, the
  same shapes STORE_SHAPES already holds. MoltenVK makes no linear image with bytes between rows
  except at that pitch, and its line is 16 bytes. Without these two, none of its shapes whose
  texels share a line was made, so its reads and renders were Unchecked for those texels: on
  the M3, a probe of this change without them gave Pointer and Fresh reads and renders Unchecked
  5/5 for InLines (m3-max-6750).
- SHAPES and STORE_SHAPES gain the same widths at the 64-byte pitch of a driver that lays rows
  at the next multiple of 64: BGRA8Unorm 101x51 at 448 and RGBA16Float 33x17 at 320, and
  RGBA8Uint 101x51 at 448 and RG32Uint 33x17 at 320. On lavapipe (llvmpipe's linear images take
  64-byte rows, its line 64 bytes) no shape whose texels share a line was made without them:
  tests::in_place_check::the_in_place_check_checks_fresh_pages_where_held_imports_cost_submissions
  read the Fresh verdicts Unchecked for all three accesses of those texels (m3-max-6991). The
  shape test now holds that drivers whose rows lie at the next multiple of 16, 64, 128 or 256
  bytes each have such a shape, for each access.
- The record holds 18 verdicts. CHECK_VERSION goes to 6, so a record of the old check is not read.
- The report keeps its nine lines, now the InLines verdicts (the old verdict exactly, since an
  OnLines failure fails both), and adds nine ", rows on lines" lines after them.
- The texture's own row ends decide, everywhere a texture asks for its verdict: its making
  (Texels::rows), a shadow's move in place (MoveWait, move_wanted) and a copied rebind into fresh
  pages (fresh_pages_take_images, from the watch's place in its pages). ShadowCause::CheckPending,
  CheckFailed and Unchecked name the row ends, and the notice says them.
- Device::in_place_check_line (doc-hidden) answers the line. The lanes that hold a texture to its
  verdict compute its row ends themselves (runtime_lane::in_place_rows, apart from the runtime's
  reckoning) and read that row ends' line.

Docs: FAST-PATHS row 41 and the API guide describe the row ends. The ShadowedTexture notice
docs name them. The known gap for rows that end on a line is closed and deleted.

Tests: RowEnds::of covers an offset, an address, a pitch and slices off a line, tight rows that
do or do not end on a line, a 1-byte line, the 3840 and 3662-wide surfaces, and the check's
shapes per class. The verdicts function: a change beside OnLines texels fails both row ends, a
change beside InLines texels fails InLines alone, and a forced failure and an unchecked class are
covered. The decision test runs every class with both row ends. The record test covers 18
verdicts.

Verified, the whole check on fresh caches (the probe test, this change plus the test alone;
the Iris Xe and RADV runs at 5beb0be2a5, before the 64-byte shapes, on development 0950c1a0ab):
- Iris Xe (RPL-P), ANV, Mesa 26.2.6, 64-byte line (m3-max-6892), 20 runs, every run the same:
  reads Passed for both row ends, Pointer and Fresh; renders and writes Failed for texels that
  share a line and Passed for texels that share none, Pointer and Fresh; DmaBuf Unchecked for
  all six. The failures are a byte between two rows: a clear and store or a draw of R8Unorm
  61x37 at 256 bytes a row (renders), and storage writes of RGBA8Uint 101x51 at 512 (writes).
  323-383 ms a check (median 345), against 156-342 ms before (m3-max-6226): a class that fails
  for texels that share a line now runs its rounds for texels that share none to the end, as a
  passing device's do. A build job ran on the same host meanwhile.
- M3 Max, MoltenVK 1.4.2, 16-byte line: Pointer and Fresh Passed 5/5 for reads, renders and
  writes, for both row ends (12); DmaBuf Unchecked for all six (no dma-bufs on macOS). 290-304
  ms a check at 5beb0be2a5 (m3-max-6804); with the 64-byte shapes, at 19a7c36f69 on
  development ee5d3cfab9 (m3-max-7142), the same verdicts and 306-311 ms, the first run 548 ms.
  Before this change, 299-582 ms (m3-max-6160). That earlier run had six verdicts Passed and
  the three DmaBuf ones Unchecked, not all nine Passed as 31b19fa7f0's body says. No M3 cost
  record's case changes path: every verdict the M3 passed before passes for both row ends.
- RX 7900 XTX, RADV, Mesa 26.2.6, 64-byte line (m3-max-6817): all 18 Passed 5/5. 535-561 ms a
  check, against 626-642 ms before (m3-max-6523).

Verified, self_reads on the Iris Xe (m3-max-6892, release, each process on a cache of its own),
the previous commit's lane alone (before) against this change (after), two rounds each, GPU
ms per frame (median) of the baseline and of 30 self-read pairs:
- 3840x2160 surface over host pages, InPlace policy: before a shadow, 3 shadow copies a frame,
  8294400 texels copied in, 1 keep and 1 merge; baseline 3.487 and 3.526, self-reads 4.994 and
  5.014. After in place: no shadow copy, no texel copied in, no keep or merge; baseline 1.676
  and 1.674, self-reads 4.544 and 4.559 (30 snapshots a frame, as before).
- 3662x2039 surface, InPlace policy: a shadow before and after (its rows end inside a line);
  self-reads 4.141 and 4.187 before, 4.168 and 4.205 after.
- Private targets, unchanged: 3662x2039 self-reads 11.48 to 12.12, 3840x2160 14.68 to 15.04
  (30 splits a frame, before and after, on development 0950c1a0ab). Under 61a367cb51's area
  rule, landed since, these readers are expected to take snapshots instead (not run here).
- The check, as the lane's device ran it: 202.6 and 193.8 ms before, 411.5 and 369.7 after.
The lanes that hold a texture to its verdict passed on the Iris Xe under validation
(in_place_textures 7, linear_attachments 25, snapshot_reads 7, linear_alignments 3,
first_use_writes 1, device_copies 5; m3-max-6892).

Checked at b0043502d1 (this change before the 64-byte shapes, on development ee5d3cfab9;
homelab-gem10-1, m3-max-6991): clippy with --cfg m2v_cpu_icd and with --cfg m2v_gpu, all
targets and features, clean; rustdoc with -D warnings clean; the API tables, the ledger test,
check_draw and tests::in_place (44) passed; on lavapipe 306 of the 307 touched tests passed, and
the one that failed is the fresh-pages test the 64-byte shapes fix (above). That test and the
runtime's in-place tests on lavapipe at this commit: m3-max-7152 (homelab-um870-1). The RADV
probe at this commit plus the probe test: m3-max-7153, then its run on the RX 7900 XTX.

(cherry picked from commit f815203f074e1b2f922cd2a2d337ba31ea51e02f)
This commit is contained in:
Anees Iqbal committed 2026-11-07 22:13:59 -08:00
1 parent 07f51baf16
commit 532fc35b7a
27 files changed
+718 -265

No files matched your search

@@ -56,6 +56,7 @@ use super::degradation::Degradation;
use super::device::lock;
use super::error::{internal, invalid, nil, vulkan, Error, Problem, RuntimeGap};
use super::exit_guard;
use super::in_place::RowEnds;
use super::key_hash::KeyMap;
use super::linear_plan::{
apart_from_plane, is_linear, plan_buffer_texture, plane_rows_share_bytes, BufferFacts,
@@ -1408,6 +1409,17 @@ impl Texels {
self.texel_bytes
}
/// How the texels lie in the device's lines of memory of `line` bytes
/// (`in_place::RowEnds::of`): from their address in the buffer's bytes and where the GPU's
/// commands find them (`layout`). A buffer whose bytes the CPU does not address shares a line
/// as far as anything shows.
pub(super) fn rows(&self, line: u64) -> RowEnds {
match self.buffer.contents() {
Some(at) => RowEnds::of(at.as_ptr().addr() as u64, &self.layout, line),
None => RowEnds::InLines,
}
}
/// The texture's resource options (the `options` field), its hazard tracking mode resolved.
pub(super) fn options(&self) -> ResourceOptions {
self.options
@@ -244,8 +244,10 @@ degradations! {
/// there (`in_place.rs`): the policy keeps the exact form
/// ([`metal2vulkan::device::HostPageTexturePolicy::Shadow`]), the texture's usage renders
/// into it or writes it (`RenderTarget`, `ShaderWrite`, `ShaderAtomic`), the device's
/// check that the move keeps every byte over that kind of pages has not answered yet,
/// found a byte changed or made no image, or no image in place serves the texels (its rows
/// check that the move keeps every byte over that kind of pages, for texels that share a
/// line of the device's memory (`nonCoherentAtomSize`) with bytes beside them or not as
/// the texture's do, has not answered yet, found a byte changed or made no image, or no
/// image in place serves the texels (its rows
/// share bytes, the device lays no linear image's rows at the buffer's pitch, the image's
/// placement or memory misses the pages, the bytes were detached, or no dma-buf of the
/// texture's own pages serves); the notice names which; or its rows (or an array's slices) lie with the buffer's
@@ -2266,7 +2266,10 @@ impl Device {
lost,
textures,
shader_cache,
in_place: crate::in_place::InPlaceChecks::new(fail_in_place_check),
in_place: crate::in_place::InPlaceChecks::new(
fail_in_place_check,
limits.non_coherent_atom_size,
),
submit_checks: Arc::new(crate::submit_check::SubmitChecks::new()),
host_import,
#[cfg(unix)]
+180 -67
View File
@@ -38,11 +38,15 @@
//! leaving every other byte alone, on a discrete GPU as on any other (a discrete Mac's GPU
//! writes a `Shared` texture across its bus). The check
//! (`in_place_check.rs`) runs once per driver and its version, per memory class
//! ([`PagesClass`]) and access ([`Access`]), and its verdicts are kept in the shader cache's
//! content records ([`record_name`]); a class and access it did not pass keep the shadow.
//! ([`PagesClass`]), access ([`Access`]) and how the texels lie in the device's lines of memory
//! ([`RowEnds`]: whether a line holds both a texel and a byte beside the texels, which a device
//! that writes back a texel's line whole puts back over the CPU's write), and its verdicts are
//! kept in the shader cache's content records ([`record_name`]); a class, access and row ends it
//! did not pass keep the shadow.
//! - **Which textures** ([`in_place`]): under `HostPageTexturePolicy::InPlace`, those over a class
//! whose check passed for each access the texture's declared usage (as Metal reports it, an
//! `Unknown` one every usage) takes ([`Access::takes`]): it renders (`RenderTarget`), a shader
//! whose check passed, for texels that lie in lines as the texture's do ([`RowEnds::of`], from
//! the texels' address, offset and pitches), for each access the texture's declared usage (as
//! Metal reports it, an `Unknown` one every usage) takes ([`Access::takes`]): it renders (`RenderTarget`), a shader
//! writes it (`ShaderWrite` or `ShaderAtomic`, of texels of 4, 8 or 16 bytes, the widths the
//! check's kernel stores: [`STORED_TEXEL_BYTES`]), or it is sampled or read alone. Plain Metal
//! also writes through a texture beyond its declared usage, and renders into one made without
@@ -186,13 +190,77 @@ impl Access {
}
}
/// The verdicts a device's check gives: one for each class and access, class by class
/// ([`PagesClass::ALL`]), each class's accesses in [`Access::ALL`]'s order.
pub(crate) const VERDICTS: usize = PagesClass::ALL.len() * Access::ALL.len();
/// How a texture's texels lie in the device's lines of memory, each checked apart: a line is
/// `nonCoherentAtomSize` bytes at a multiple of it, "the size and alignment in bytes that bounds
/// concurrent access to host-mapped device memory" (vkspec, Limits). A device may write back a
/// line that holds a texel whole, as the Iris Xe's clear and store, and its draws, write back the
/// line that holds a row's last texels: a line that also holds bytes beside the texels then puts
/// back an older value over a CPU write there, where a line of texels alone holds nothing the CPU
/// writes beside them.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum RowEnds {
/// A line holds a texel and a byte beside the texels: between two rows or two slices, before
/// the first texel or after the last.
InLines,
/// Every line holds texels alone or bytes beside them alone: the texels start and end on a
/// line, and so does each row (or slice) where bytes lie between rows (or slices).
OnLines,
}
/// The place of `class`'s verdict for `access` among the [`VERDICTS`].
pub(crate) fn verdict_index(class: PagesClass, access: Access) -> usize {
class.index() * Access::ALL.len() + access.index()
impl RowEnds {
/// Both, in the order the record holds their verdicts.
pub(crate) const ALL: [RowEnds; 2] = [RowEnds::InLines, RowEnds::OnLines];
/// Its place in [`ALL`](Self::ALL).
pub(crate) fn index(self) -> usize {
match self {
RowEnds::InLines => 0,
RowEnds::OnLines => 1,
}
}
/// How texels laid out as `layout` in a buffer whose first byte lies `start` bytes past a
/// multiple of `line` lie in the lines of `line` bytes.
pub(crate) fn of(start: u64, layout: &crate::linear_plan::BufferLayout, line: u64) -> RowEnds {
let on = |at: u64| at.is_multiple_of(line.max(1));
let first = start + layout.offset;
let slice = (layout.rows - 1) * layout.row_pitch + layout.row_bytes;
let rows_apart = layout.rows > 1 && layout.row_pitch != layout.row_bytes;
let slices_apart = layout.slices > 1 && layout.slice_pitch != slice;
let owned = on(first)
&& on(start + layout.end())
&& (!rows_apart || (on(layout.row_pitch) && on(first + layout.row_bytes)))
&& (!slices_apart || (on(layout.slice_pitch) && on(first + slice)));
match owned {
true => RowEnds::OnLines,
false => RowEnds::InLines,
}
}
/// How the texels lie, in words, for a notice.
pub(crate) fn words(self) -> &'static str {
match self {
RowEnds::InLines => {
"an image whose texels share a line of memory (the device's nonCoherentAtomSize) \
with bytes beside them"
}
RowEnds::OnLines => {
"an image whose texels share no line of memory (the device's \
nonCoherentAtomSize) with bytes beside them"
}
}
}
}
/// The verdicts a device's check gives: one for each class, access and row ends, those of
/// [`RowEnds::InLines`] first, then those of [`RowEnds::OnLines`], each class by class
/// ([`PagesClass::ALL`]), each class's accesses in [`Access::ALL`]'s order.
pub(crate) const VERDICTS: usize = RowEnds::ALL.len() * PagesClass::ALL.len() * Access::ALL.len();
/// The place of `class`'s verdict for `access` of texels that lie as `rows` says among the
/// [`VERDICTS`].
pub(crate) fn verdict_index(class: PagesClass, access: Access, rows: RowEnds) -> usize {
(rows.index() * PagesClass::ALL.len() + class.index()) * Access::ALL.len() + access.index()
}
/// What the device's check answered for a class and access.
@@ -238,6 +306,7 @@ impl Verdict {
#[derive(Clone)]
pub(crate) struct PendingMove {
pub(crate) class: PagesClass,
pub(crate) rows: RowEnds,
pub(crate) usage: TextureUsage,
pub(crate) plan: crate::image_plan::ImagePlan,
pub(crate) descriptor: crate::texture_descriptor::TextureDescriptor,
@@ -251,12 +320,14 @@ pub(crate) enum ShadowCause {
/// Its usage writes it through a shader, and its texels are of a width (the bytes given) the
/// check's kernel stores none of ([`STORED_TEXEL_BYTES`]): no check covers its writes.
StoreWidth(u64),
/// Its class's check for its access has not answered yet.
CheckPending(PagesClass, Access),
/// Its class's check for its access found a byte changed.
CheckFailed(PagesClass, Access),
/// Its class's check for its access made no image.
Unchecked(PagesClass, Access),
/// Its class's check for its access, of texels that lie in lines as its own do, has not
/// answered yet.
CheckPending(PagesClass, Access, RowEnds),
/// Its class's check for its access, of texels that lie in lines as its own do, found a byte
/// changed.
CheckFailed(PagesClass, Access, RowEnds),
/// Its class's check for its access, of texels that lie in lines as its own do, made no image.
Unchecked(PagesClass, Access, RowEnds),
/// The device makes no image over its texels as Metal lays them out: why, and the words.
Refused(Refusal, String),
}
@@ -328,36 +399,41 @@ impl ShadowCause {
device's check of storage writes stores texels of 4, 8 and 16 bytes, not of \
{bytes}: no check covers a driver's writes of such texels beside them"
),
ShadowCause::CheckPending(class, access) => format!(
"the device's check of {} over {} has not answered yet",
ShadowCause::CheckPending(class, access, rows) => format!(
"the device's check of {} over {}, for {}, has not answered yet",
access.words(),
class.words()
),
ShadowCause::CheckFailed(class, access) => format!(
"the device's check found {} over {} changing a byte the CPU wrote beside it",
access.words(),
class.words()
),
ShadowCause::Unchecked(class, access) => format!(
"the device's check made no image over {} for {}",
class.words(),
access.words()
rows.words()
),
ShadowCause::CheckFailed(class, access, rows) => format!(
"the device's check found {} over {} changing a byte the CPU wrote beside it, \
for {}",
access.words(),
class.words(),
rows.words()
),
ShadowCause::Unchecked(class, access, rows) => format!(
"the device's check made no image over {} for {}, for {}",
class.words(),
access.words(),
rows.words()
),
ShadowCause::Refused(_, why) => why.clone(),
}
}
}
/// Whether a texture over host pages of `class`, of Metal `usage` (as Metal reports it) and texels
/// of `texel` bytes, on a device of `policy`, is tried as an image in place; else why it is a
/// shadow (the module docs). `verdict` answers the device's check for the class and each access
/// the texture takes ([`Access::takes`]), in [`Access::ALL`]'s order, asked only of a texture the
/// policy and texel width let through (a pending one starts the check), until one did not pass.
/// Whether a texture over host pages of `class`, its texels lying in the device's lines as `rows`
/// says, of Metal `usage` (as Metal reports it) and texels of `texel` bytes, on a device of
/// `policy`, is tried as an image in place; else why it is a shadow (the module docs). `verdict`
/// answers the device's check for the class, each access the texture takes ([`Access::takes`]),
/// in [`Access::ALL`]'s order, and the row ends, asked only of a texture the policy and texel
/// width let through (a pending one starts the check), until one did not pass.
pub(crate) fn in_place(
policy: HostPageTexturePolicy,
usage: TextureUsage,
(class, texel): (PagesClass, u64),
mut verdict: impl FnMut(PagesClass, Access) -> Verdict,
(class, rows, texel): (PagesClass, RowEnds, u64),
mut verdict: impl FnMut(PagesClass, Access, RowEnds) -> Verdict,
) -> Result<(), ShadowCause> {
if policy == HostPageTexturePolicy::Shadow {
return Err(ShadowCause::Exact);
@@ -366,20 +442,22 @@ pub(crate) fn in_place(
return Err(ShadowCause::StoreWidth(texel));
}
for access in Access::ALL.into_iter().filter(|access| access.takes(usage)) {
match verdict(class, access) {
match verdict(class, access, rows) {
Verdict::Passed => {}
Verdict::Pending => return Err(ShadowCause::CheckPending(class, access)),
Verdict::Failed => return Err(ShadowCause::CheckFailed(class, access)),
Verdict::Unchecked => return Err(ShadowCause::Unchecked(class, access)),
Verdict::Pending => return Err(ShadowCause::CheckPending(class, access, rows)),
Verdict::Failed => return Err(ShadowCause::CheckFailed(class, access, rows)),
Verdict::Unchecked => return Err(ShadowCause::Unchecked(class, access, rows)),
}
}
Ok(())
}
/// A device's check verdicts (`DeviceShared::in_place`): one per class and access
/// A device's check verdicts (`DeviceShared::in_place`): one per class, access and row ends
/// ([`VERDICTS`]), and whether its check started and settled.
pub(crate) struct InPlaceChecks {
verdicts: [AtomicU8; VERDICTS],
/// The device's line of memory, `nonCoherentAtomSize` bytes ([`RowEnds`]).
line: u64,
/// The check was started on its thread (at most once per device).
started: AtomicBool,
/// Every class's verdict is known: from the record, or the check ended.
@@ -398,10 +476,12 @@ pub(crate) struct InPlaceChecks {
}
impl InPlaceChecks {
/// No verdict yet; `fail` as [`InPlaceChecks::fail`] says.
pub(crate) fn new(fail: bool) -> InPlaceChecks {
/// No verdict yet, on a device whose line is `line` bytes ([`RowEnds`]); `fail` as
/// [`InPlaceChecks::fail`] says.
pub(crate) fn new(fail: bool, line: u64) -> InPlaceChecks {
InPlaceChecks {
verdicts: [0; VERDICTS].map(AtomicU8::new),
line: line.max(1),
started: AtomicBool::new(false),
settled: Mutex::new(false),
wake: Condvar::new(),
@@ -422,9 +502,14 @@ impl InPlaceChecks {
lock(&self.notes).push(line);
}
/// `class`'s verdict for `access` now.
pub(crate) fn verdict(&self, class: PagesClass, access: Access) -> Verdict {
let byte = self.verdicts[verdict_index(class, access)].load(Ordering::Acquire);
/// The device's line of memory, in bytes ([`RowEnds`]).
pub(crate) fn line(&self) -> u64 {
self.line
}
/// `class`'s verdict for `access` of texels that lie in lines as `rows` says, now.
pub(crate) fn verdict(&self, class: PagesClass, access: Access, rows: RowEnds) -> Verdict {
let byte = self.verdicts[verdict_index(class, access, rows)].load(Ordering::Acquire);
Verdict::of_byte(byte).unwrap_or(Verdict::Pending)
}
@@ -436,9 +521,10 @@ impl InPlaceChecks {
})
}
/// Give `class` its verdict for `access`.
pub(crate) fn set(&self, class: PagesClass, access: Access, verdict: Verdict) {
self.verdicts[verdict_index(class, access)].store(verdict.byte(), Ordering::Release);
/// Give `class` its verdict for `access` of texels that lie in lines as `rows` says.
pub(crate) fn set(&self, class: PagesClass, access: Access, rows: RowEnds, verdict: Verdict) {
let at = verdict_index(class, access, rows);
self.verdicts[at].store(verdict.byte(), Ordering::Release);
}
/// Whether the check is to fail whatever the moves did.
@@ -505,7 +591,7 @@ impl Drop for Waiting<'_> {
/// differs, and so does the version it holds). The runtime's own version is not in the record: a
/// release that changes none of these keeps the verdicts the driver gave, so a device made after
/// it reads them again rather than checking anew.
pub(crate) const CHECK_VERSION: u32 = 5;
pub(crate) const CHECK_VERSION: u32 = 6;
/// A record's first bytes.
const MAGIC: [u8; 8] = *b"M2VINPL\0";
@@ -582,7 +668,7 @@ pub(crate) fn record_name(identity: &DriverIdentity) -> String {
/// magic 8 bytes "M2VINPL\0"
/// version u32 CHECK_VERSION
/// identity 32 bytes DriverIdentity::digest
/// verdicts 9 bytes one per class and access, VERDICTS' order (verdict_index)
/// verdicts 18 bytes one per class, access and row ends, VERDICTS' order (verdict_index)
/// checksum 32 bytes SHA-256 of every byte before it
/// ```
///
@@ -686,19 +772,27 @@ impl Device {
if let Lookup::Hit(verdicts) = looked {
for class in PagesClass::ALL {
for access in Access::ALL {
let verdict = verdicts[verdict_index(class, access)];
shared.in_place.set(class, access, verdict);
shared.counts.in_place_check_recalled();
for rows in RowEnds::ALL {
let verdict = verdicts[verdict_index(class, access, rows)];
shared.in_place.set(class, access, rows, verdict);
shared.counts.in_place_check_recalled();
}
}
}
shared.in_place.settle(None);
}
}
/// `class`'s verdict for `access` for a texture asking it as it is made: a pending one
/// starts the check, unless it started already. Never waits (the module docs).
pub(crate) fn in_place_verdict(&self, class: PagesClass, access: Access) -> Verdict {
let verdict = self.shared().in_place.verdict(class, access);
/// `class`'s verdict for `access` of texels that lie in lines as `rows` says, for a texture
/// asking it as it is made: a pending one starts the check, unless it started already. Never
/// waits (the module docs).
pub(crate) fn in_place_verdict(
&self,
class: PagesClass,
access: Access,
rows: RowEnds,
) -> Verdict {
let verdict = self.shared().in_place.verdict(class, access, rows);
if verdict == Verdict::Pending {
self.start_in_place_checks();
}
@@ -741,10 +835,22 @@ impl Device {
self.shared().in_place.took()
}
/// The bytes of the device's line of memory the check's verdicts tell apart
/// (`nonCoherentAtomSize`, `RowEnds`): those of texels that share a line with bytes beside
/// them, and those of texels that share none. A runtime extension for the lanes that read
/// the verdict a texture of theirs takes.
#[doc(hidden)]
pub fn in_place_check_line(&self) -> u64 {
self.current().shared().in_place.line()
}
/// The device's check's verdicts now, one line per class for a texture that reads
/// (`Pointer: Passed`), then one per class for one that renders (`Pointer renders: Passed`),
/// then one per class for one a shader writes (`Pointer writes: Passed`), and what it found
/// changed where one failed. A runtime extension for the lanes that report it.
/// then one per class for one a shader writes (`Pointer writes: Passed`), each for texels that
/// share a line with bytes beside them (`RowEnds::InLines`); then the same nine for texels
/// that share none (`Pointer, rows on lines: Passed`, `Pointer renders, rows on lines:
/// Passed`, `Pointer writes, rows on lines: Passed`); and what it found changed where one
/// failed. A runtime extension for the lanes that report it.
#[doc(hidden)]
pub fn in_place_check_report(&self) -> Vec<String> {
self.current().in_place_check_report_now()
@@ -753,17 +859,24 @@ impl Device {
/// [`Device::in_place_check_report`] on the generation that serves (`device/line.rs`).
pub(crate) fn in_place_check_report_now(&self) -> Vec<String> {
let checks = &self.shared().in_place;
let line = |class: PagesClass, access: Access| {
let verdict = checks.verdict(class, access);
let line = |class: PagesClass, access: Access, rows: RowEnds| {
let verdict = checks.verdict(class, access, rows);
let lines = match rows {
RowEnds::InLines => "",
RowEnds::OnLines => ", rows on lines",
};
match access {
Access::Reads => format!("{class:?}: {verdict:?}"),
Access::Renders => format!("{class:?} renders: {verdict:?}"),
Access::Writes => format!("{class:?} writes: {verdict:?}"),
Access::Reads => format!("{class:?}{lines}: {verdict:?}"),
Access::Renders => format!("{class:?} renders{lines}: {verdict:?}"),
Access::Writes => format!("{class:?} writes{lines}: {verdict:?}"),
}
};
let verdicts = Access::ALL
.into_iter()
.flat_map(|access| PagesClass::ALL.map(|class| line(class, access)));
let line = &line;
let verdicts = RowEnds::ALL.into_iter().flat_map(move |rows| {
Access::ALL
.into_iter()
.flat_map(move |access| PagesClass::ALL.map(|class| line(class, access, rows)))
});
verdicts
.chain(lock(&checks.notes).iter().cloned())
.collect()
+122 -51
View File
@@ -66,12 +66,22 @@
//! - **Its cost** is the pattern's fill and compare of each window, at the speed of a copy and a
//! comparison of memory (a 3840x2160 surface's 33 MB among them), and each image's making and
//! first move (and pass, or kernel's stores): the writes themselves run only while those do.
//! - **Its verdict**, per class and access: passed where every image it made kept every byte (but
//! the texels a pass cleared or a kernel stored), failed where one did not (or the device was
//! made to fail it, `DeviceOptions::fail_in_place_check`), and unchecked where it made none (the
//! device makes no such buffer, image, import, pass or dispatch). Each is the device's as it is
//! known, so a class and access that passed take textures in place while the next is checked.
//! Counted (`WorkCounts::in_place_checks_*`).
//! - **Its verdict**, per class, access and row ends ([`RowEnds`]: whether a line of the device's
//! memory, `nonCoherentAtomSize` bytes, holds both a texel and a byte beside the texels, each
//! shape's from its pitch and width, [`Shape::rows`]): passed where every image it made of
//! shapes of the row ends kept every byte (but the texels a pass cleared or a kernel stored),
//! failed where one did not (or the device was made to fail it,
//! `DeviceOptions::fail_in_place_check`), and unchecked where it made none (the device makes no
//! such buffer, image, import, pass or dispatch) ([`verdicts`]). The shapes whose texels share
//! no line with bytes beside them run first: a byte one of them changed fails both row ends,
//! as a device that changes a byte beside such texels changes one beside any; a byte a shape
//! whose texels share a line changed fails its row ends alone, the others' rounds already run.
//! On the Iris Xe, whose clear and store, and draws, write back the line that holds a row's last
//! texels whole, the first fail and the second pass. Of [`SHAPES`] at 64-byte lines, the five
//! whose rows lie one after another, the 20x9 one at a 512-byte pitch and the 3840x2160 surface
//! share none, and the other six share one. Each is the device's as it is known, so a class,
//! access and row ends that passed take textures in place while the next is checked. Counted
//! (`WorkCounts::in_place_checks_*`).
//! - **Kept.** Once every class answered, the verdicts are written as one record in the shader
//! cache's content directory (`shader_cache/store.rs`), named by the driver's identity (its
//! version and the device's UUID among it) and the check's version ([`record_name`]), not the
@@ -113,7 +123,8 @@ use crate::check_draw::CheckDraw;
use crate::device::holds::Holder;
use crate::exit_guard;
use crate::host_memory::HostMemory;
use crate::in_place::{encode, mark_checking, record_name, Access, PagesClass, Verdict};
use crate::in_place::{encode, mark_checking, record_name, Access, PagesClass, RowEnds, Verdict};
use crate::linear_plan::BufferLayout;
use crate::values::ResourceOptions;
use crate::{
AddressPlacement, Buffer, BufferContents, BufferDescriptor, ClearColor, CommandQueue, Device,
@@ -131,9 +142,9 @@ use std::time::{Duration, Instant};
/// catches a device that writes back the line of a cache that holds a row's last texels: on the
/// Iris Xe a render round (its pass's clear and store, then its draw) caught it in 198 of 200
/// rounds of a 100x50 `BGRA8Unorm` image at a 512-byte pitch and in 200 of 200 of a 33x17
/// `RGBA16Float` one. Four of [`SHAPES`] have rows that end inside such a line, so three rounds
/// of each are twelve chances, of which a device that escapes each as often as the Iris Xe's
/// worst shape did (2 in 200) passes all with odds below one in 10^20.
/// `RGBA16Float` one. Eight of [`SHAPES`] have rows that end inside such a line, so three rounds
/// of each are twenty-four chances, of which a device that escapes each as often as the Iris Xe's
/// worst shape did (2 in 200) passes all with odds below one in 10^40.
pub(crate) const ROUNDS: usize = 3;
/// The longest a render round waits for its pass's command buffer: a pass that clears a 3840x2160
@@ -154,10 +165,14 @@ pub(crate) struct Shape {
/// The shapes each class is checked with: each texel size the formats a buffer backs have (1, 2,
/// 4, 8 and 16 bytes), with rows one after another (a linear image made for the memory, which
/// every driver lays at a 256-byte pitch) and with bytes between them (an image at an explicit
/// pitch, where the device makes one: `texture/in_place_image.rs`), and one 3840x2160 surface of
/// 4-byte texels, last. A shape the device makes no image of in place is skipped: the product
/// makes none of it either.
pub(crate) const SHAPES: [Shape; 11] = [
/// pitch, where the device makes one: `texture/in_place_image.rs`), two of widths whose rows end
/// inside a 16-byte line at the 16-byte pitch a driver that lays rows tight lays them at (MoltenVK
/// makes no other image with bytes between rows, and its line, `nonCoherentAtomSize`, is 16
/// bytes: without them no shape of its whose texels share a line would be made, [`RowEnds`]), the
/// same two at the 64-byte pitch of a driver that lays rows at the next multiple of 64 (llvmpipe,
/// whose line is 64 bytes: likewise), and one 3840x2160 surface of 4-byte texels, last. A shape
/// the device makes no image of in place is skipped: the product makes none of it either.
pub(crate) const SHAPES: [Shape; 15] = [
shape(PixelFormat::R8Unorm, 1, 256, 16, 256),
shape(PixelFormat::RG8Unorm, 2, 128, 16, 256),
shape(PixelFormat::BGRA8Unorm, 4, 64, 16, 256),
@@ -168,6 +183,10 @@ pub(crate) const SHAPES: [Shape; 11] = [
shape(PixelFormat::BGRA8Unorm, 4, 100, 50, 512),
shape(PixelFormat::RGBA16Float, 8, 33, 17, 512),
shape(PixelFormat::RGBA32Float, 16, 20, 9, 512),
shape(PixelFormat::BGRA8Unorm, 4, 101, 51, 416),
shape(PixelFormat::RGBA16Float, 8, 33, 17, 272),
shape(PixelFormat::BGRA8Unorm, 4, 101, 51, 448),
shape(PixelFormat::RGBA16Float, 8, 33, 17, 320),
shape(PixelFormat::BGRA8Unorm, 4, 3840, 2160, 15360),
];
@@ -175,11 +194,11 @@ pub(crate) const SHAPES: [Shape; 11] = [
/// kernel stores through: texels of 4, 8 and 16 bytes (`in_place::STORED_TEXEL_BYTES`, the
/// crate-owned copy-in kernel's views), with rows one after another and with bytes between them
/// (of widths no multiple of 4 and heights no multiple of 2 among them, so that a driver's write
/// of a block wider than a texel past a row's or the image's end shows), at a 512-byte pitch and
/// at the 16-byte pitch a driver that lays rows tight lays them at, and one 1920x1080 surface of
/// 4-byte texels, last. A shape the device makes no image of in place, or no dispatch over, is
/// skipped.
pub(crate) const STORE_SHAPES: [(Shape, ShadowTexelView); 9] = [
/// of a block wider than a texel past a row's or the image's end shows), at a 512-byte pitch, at
/// the 16-byte pitch a driver that lays rows tight lays them at and at the 64-byte pitch of one
/// that lays them at the next multiple of 64 ([`SHAPES`]), and one 1920x1080 surface of 4-byte
/// texels, last. A shape the device makes no image of in place, or no dispatch over, is skipped.
pub(crate) const STORE_SHAPES: [(Shape, ShadowTexelView); 11] = [
(
shape(PixelFormat::RGBA8Uint, 4, 64, 16, 256),
ShadowTexelView::R8G8B8A8Uint,
@@ -212,6 +231,14 @@ pub(crate) const STORE_SHAPES: [(Shape, ShadowTexelView); 9] = [
shape(PixelFormat::RG32Uint, 8, 33, 17, 272),
ShadowTexelView::R32G32Uint,
),
(
shape(PixelFormat::RGBA8Uint, 4, 101, 51, 448),
ShadowTexelView::R8G8B8A8Uint,
),
(
shape(PixelFormat::RG32Uint, 8, 33, 17, 320),
ShadowTexelView::R32G32Uint,
),
(
shape(PixelFormat::RGBA8Uint, 4, 1920, 1080, 7680),
ShadowTexelView::R8G8B8A8Uint,
@@ -235,6 +262,20 @@ impl Shape {
&& offset % self.bytes_per_row < self.width * self.texel
}
/// How its texels lie in lines of `line` bytes ([`RowEnds::of`]): its texture starts the
/// window, which starts on a page.
pub(crate) fn rows(&self, line: u64) -> RowEnds {
let layout = BufferLayout {
offset: 0,
row_pitch: self.bytes_per_row,
slice_pitch: self.bytes_per_row * self.height,
row_bytes: self.width * self.texel,
rows: self.height,
slices: 1,
};
RowEnds::of(0, &layout, line)
}
/// The bytes of the window the check fills and writes: the texture's rows, then the bytes
/// after them to two pages past the page their last byte is in.
fn window(&self, page: u64) -> u64 {
@@ -265,8 +306,10 @@ impl Device {
if started.is_err() {
for class in PagesClass::ALL {
for access in Access::ALL {
if checks.verdict(class, access) == Verdict::Pending {
checks.set(class, access, Verdict::Unchecked);
for rows in RowEnds::ALL {
if checks.verdict(class, access, rows) == Verdict::Pending {
checks.set(class, access, rows, Verdict::Unchecked);
}
}
}
}
@@ -299,24 +342,27 @@ fn run(weak: crate::device::WeakDevice) {
let Some(device) = weak.hold() else {
return;
};
if device.shared().in_place.verdict(class, access) != Verdict::Pending {
let checks = &device.shared().in_place;
let pending = |rows| checks.verdict(class, access, rows) == Verdict::Pending;
if !RowEnds::ALL.into_iter().any(pending) {
continue;
}
if stopped || word_overwritten(&device) {
stopped = true;
device
.shared()
.in_place
.set(class, access, Verdict::Unchecked);
for rows in RowEnds::ALL {
checks.set(class, access, rows, Verdict::Unchecked);
}
continue;
}
let Some(verdict) = check_class(&device, class, access) else {
let Some(verdicts) = check_class(&device, class, access) else {
// The process is exiting, or the program let the device go: nothing is kept.
return;
};
let checks = &device.shared().in_place;
checks.set(class, access, verdict);
device.shared().counts.in_place_check_ran(verdict);
for rows in RowEnds::ALL {
let verdict = verdicts[rows.index()];
checks.set(class, access, rows, verdict);
device.shared().counts.in_place_check_ran(verdict);
}
// Shadows made before their verdicts that know them now may move in place.
device.in_place_verdicts_given();
}
@@ -355,14 +401,18 @@ fn word_overwritten(device: &Device) -> bool {
unsafe { device.shared().loader_word.overwritten() }
}
/// The verdict of `class` for `access` on `device`: every shape's rounds, until one fails, or
/// until the device's loader word is found overwritten (unchecked then where no round ran).
/// `None` where the process is exiting, or the program's last drop stopped the device's holds
/// before a round (`device/holds.rs`).
fn check_class(device: &Device, class: PagesClass, access: Access) -> Option<Verdict> {
/// The verdicts of `class` for `access` on `device`, by row ends ([`RowEnds::ALL`]'s order):
/// every shape's rounds, those of shapes whose texels share no line with bytes beside them first
/// ([`Shape::rows`]), until one fails, or until the device's loader word is found overwritten
/// (unchecked then where no round ran); [`verdicts`] gives them. `None` where the process is
/// exiting, or the program's last drop stopped the device's holds before a round
/// (`device/holds.rs`).
fn check_class(device: &Device, class: PagesClass, access: Access) -> Option<[Verdict; 2]> {
let page = host_page();
let line = device.shared().in_place.line();
let unchecked = [Verdict::Unchecked; 2];
let Some(pages) = ClassPages::make(device, class, BUFFER_BYTES) else {
return Some(Verdict::Unchecked);
return Some(unchecked);
};
// The command queue an image that renders takes its passes on, the check's own, and the
// draw it takes after them.
@@ -375,29 +425,32 @@ fn check_class(device: &Device, class: PagesClass, access: Access) -> Option<Ver
});
match made? {
Ok(renders) => Some(renders),
Err(_) => return Some(Verdict::Unchecked),
Err(_) => return Some(unchecked),
}
}
};
// An image a shader writes takes the shapes its kernel stores, each with its view.
let shapes: Vec<(Shape, Option<ShadowTexelView>)> = match access {
// An image a shader writes takes the shapes its kernel stores, each with its view; those
// whose texels share no line with bytes beside them first.
let mut shapes: Vec<(Shape, Option<ShadowTexelView>)> = match access {
Access::Writes => STORE_SHAPES
.map(|(shape, texel)| (shape, Some(texel)))
.to_vec(),
Access::Reads | Access::Renders => SHAPES.map(|shape| (shape, None)).to_vec(),
};
let mut made = 0;
shapes.sort_by_key(|(shape, _)| shape.rows(line) != RowEnds::OnLines);
let mut made = [0; 2];
for (shape, texel) in shapes {
if shape.window(page) > BUFFER_BYTES {
continue;
}
let rows = shape.rows(line);
for round in 0..ROUNDS {
if !device.holds_go_on(Holder::InPlaceCheck) {
return None;
}
step_aside(device);
if word_overwritten(device) {
return Some(Verdict::Unchecked);
return Some(unchecked);
}
let outcome = {
let _busy = exit_guard::enter()?;
@@ -407,7 +460,7 @@ fn check_class(device: &Device, class: PagesClass, access: Access) -> Option<Ver
}
};
match outcome {
Round::Kept => made += 1,
Round::Kept => made[rows.index()] += 1,
Round::NotMade => break,
Round::Changed((offset, due, read)) => {
let image = shape.bytes_per_row * shape.height;
@@ -419,26 +472,44 @@ fn check_class(device: &Device, class: PagesClass, access: Access) -> Option<Ver
let operations = match access {
Access::Reads => "the first move",
Access::Renders => {
"the first move, feedback loop moves or a pass's clear and store"
"the first move, feedback loop moves, a pass's clear and store or a \
draw"
}
Access::Writes => "the first move or a kernel's storage writes",
};
let lines = match rows {
RowEnds::InLines => "",
RowEnds::OnLines => ", rows on lines",
};
device.shared().in_place.note(format!(
"{class:?}: {operations} of a {:?} image of {}x{} with rows {} bytes \
apart changed byte {offset} ({place}) from {due:#04x} to {read:#04x} in \
round {round}",
"{class:?}{lines}: {operations} of a {:?} image of {}x{} with rows {} \
bytes apart changed byte {offset} ({place}) from {due:#04x} to \
{read:#04x} in round {round}",
shape.format, shape.width, shape.height, shape.bytes_per_row
));
return Some(Verdict::Failed);
let forced = device.shared().in_place.forced_failure();
return Some(verdicts(made, Some(rows), forced));
}
}
}
}
let forced = device.shared().in_place.forced_failure();
Some(match (made, forced) {
(0, _) => Verdict::Unchecked,
(_, true) => Verdict::Failed,
(_, false) => Verdict::Passed,
Some(verdicts(made, None, forced))
}
/// The verdicts, by row ends ([`RowEnds::ALL`]'s order), of a class and access whose rounds kept
/// every byte `made` times for each, until a round of shapes of `changed` row ends changed one,
/// where one did, on a device made to fail its check where `forced`: failed for the row ends that
/// changed a byte, and for both where texels that share no line with bytes beside them did (a
/// device that changes a byte beside such texels changes one beside any); else unchecked for row
/// ends of which no round kept every byte, failed where forced, and passed.
pub(crate) fn verdicts(made: [u32; 2], changed: Option<RowEnds>, forced: bool) -> [Verdict; 2] {
RowEnds::ALL.map(|rows| match (changed, made[rows.index()], forced) {
(Some(RowEnds::OnLines), _, _) => Verdict::Failed,
(Some(at), _, _) if at == rows => Verdict::Failed,
(_, 0, _) => Verdict::Unchecked,
(_, _, true) => Verdict::Failed,
(_, _, false) => Verdict::Passed,
})
}
@@ -1089,7 +1089,9 @@ fn a_copied_rebind_where_fresh_pages_are_unchecked_takes_memory_the_device_alloc
return;
}
for access in Access::ALL {
(device.shared().in_place).set(PagesClass::Fresh, access, Verdict::Unchecked);
for rows in crate::in_place::RowEnds::ALL {
(device.shared().in_place).set(PagesClass::Fresh, access, rows, Verdict::Unchecked);
}
}
let asked: Arc<Mutex<Vec<ImportRequest>>> = Arc::default();
let before = device.work_counts();
@@ -1156,14 +1158,25 @@ fn a_copied_rebind_at_another_pitch_takes_fresh_pages_where_their_check_passed()
/// [`a_copied_rebind_at_another_pitch_takes_fresh_pages_where_their_check_passed`] at `pitch`:
/// a texture in place over `first`, rebound to `second`.
fn rebind_at_pitch(device: &Device, pitch: usize, (first, second): &(Host, Host)) {
use crate::in_place::{Access, PagesClass, Verdict};
use crate::in_place::{Access, PagesClass, RowEnds, Verdict};
let buffer = first.buffer(device, None);
let (texture, in_place) = texture_over_at(device, &buffer, pitch);
if !in_place {
eprintln!("COPIED-REBIND-PITCH {pitch}: the texture is a shadow here; nothing to test");
return;
}
let passed = device.in_place_verdict(PagesClass::Fresh, Access::Reads) == Verdict::Passed;
// The texture's texels in the device's lines of memory, as its rebind asks the check.
let layout = crate::linear_plan::BufferLayout {
offset: 0,
row_pitch: pitch as u64,
slice_pitch: (pitch * SIDE) as u64,
row_bytes: (SIDE * TEXEL) as u64,
rows: SIDE as u64,
slices: 1,
};
let start = buffer.contents().map_or(0, |at| at.as_ptr().addr() as u64);
let rows = RowEnds::of(start, &layout, device.shared().in_place.line());
let passed = device.in_place_verdict(PagesClass::Fresh, Access::Reads, rows) == Verdict::Passed;
let asked: Arc<Mutex<Vec<ImportRequest>>> = Arc::default();
let before = device.work_counts();
let rebound = rebind(&buffer, second, Some(gate(&asked, false)));
@@ -397,10 +397,22 @@ fn a_texture_over_a_long_buffer_is_its_bytes(
let over_fresh = after.shadows_over_fresh_pages - before.shadows_over_fresh_pages;
// SAFETY: the handle is only compared, while the texture lives.
let in_place = unsafe { texture.vk_image() }.is_some();
let renders_in_place = device
.in_place_check_report()
.iter()
.any(|line| line == "Fresh renders: Passed");
// The verdict its texels take: `RGBA8Unorm` rows `pitch` apart from the buffer's start.
let layout = crate::linear_plan::BufferLayout {
offset: 0,
row_pitch: pitch,
slice_pitch: pitch * SIDE,
row_bytes: SIDE * 4,
rows: SIDE,
slices: 1,
};
let start = contents.as_ptr().addr() as u64;
let rows = crate::in_place::RowEnds::of(start, &layout, device.shared().in_place.line());
let renders_in_place = device.shared().in_place.verdict(
crate::in_place::PagesClass::Fresh,
crate::in_place::Access::Renders,
rows,
) == crate::in_place::Verdict::Passed;
// Each cause a shadow over host pages is counted under, by how many it counted now.
let moved = |count: fn(&WorkCounts) -> u64| count(&after) - count(&before);
let causes: [(&str, u64); 12] = [
+154 -44
View File
@@ -5,10 +5,15 @@
//! never asked; under `InPlace` a texture a shader writes (`ShaderWrite`, `ShaderAtomic`,
//! `Unknown`, whatever else it holds) of texels the check's kernel stores none of (1 or 2
//! bytes) is one counted by its width, the check never asked; and every other texture is tried
//! in place exactly where its class's check passed for each access it takes (one that renders,
//! `RenderTarget`, its render check; one a shader writes, its storage check; one that does
//! neither, its read check), asked in that order until one did not pass, else a shadow naming
//! that check's answer (pending, failed, unchecked) and its access.
//! in place exactly where its class's check passed, for texels that lie in lines as its own do,
//! for each access it takes (one that renders, `RenderTarget`, its render check; one a shader
//! writes, its storage check; one that does neither, its read check), asked in that order until
//! one did not pass, else a shadow naming that check's answer (pending, failed, unchecked), its
//! access and its row ends.
//! - **Row ends.** Texels share no line with bytes beside them exactly where their first byte,
//! their end and, with bytes between rows (or slices), each row's (or slice's) start and end lie
//! on a line; and the check's verdicts by row ends fail both where texels that share none
//! changed a byte, and those that share one alone where they did.
//! - **The record.** Its verdicts read back for the identity it was written for, and nothing else
//! reads: a record cut short or grown, of another check version, of another identity, with a
//! byte changed (its checksum), or holding a pending or unknown verdict.
@@ -18,8 +23,10 @@
use crate::in_place::{
decode, encode, in_place, record_name, verdict_index, Access, DriverIdentity, InPlaceChecks,
PagesClass, ShadowCause, Verdict, CHECK_VERSION, STORED_TEXEL_BYTES, VERDICTS,
PagesClass, RowEnds, ShadowCause, Verdict, CHECK_VERSION, STORED_TEXEL_BYTES, VERDICTS,
};
use crate::in_place_check::{verdicts, Shape, SHAPES, STORE_SHAPES};
use crate::linear_plan::BufferLayout;
use metal2vulkan::device::HostPageTexturePolicy;
use metal2vulkan::metal::TextureUsage;
use sha2::{Digest, Sha256};
@@ -100,16 +107,19 @@ fn the_decision_takes_a_texture_whose_class_passed_each_of_its_accesses() {
}
}
}
for class in PagesClass::ALL {
for (class, rows) in PagesClass::ALL
.into_iter()
.flat_map(|class| RowEnds::ALL.map(|rows| (class, rows)))
{
for &usage in &usages {
for texel in [1u64, 2, 4, 8, 16] {
for answer in &answers {
let of = |access: Access| answer[access.index()];
// Shadow: always the exact form, the check never asked.
let asked = std::cell::RefCell::new(Vec::new());
let pages = (class, texel);
let pages = (class, rows, texel);
let policy = HostPageTexturePolicy::Shadow;
let decided = in_place(policy, usage, pages, |_, access| {
let decided = in_place(policy, usage, pages, |_, access, _| {
asked.borrow_mut().push(access);
of(access)
});
@@ -120,8 +130,8 @@ fn the_decision_takes_a_texture_whose_class_passed_each_of_its_accesses() {
// not pass.
let asked = std::cell::RefCell::new(Vec::new());
let policy = HostPageTexturePolicy::InPlace;
let decided = in_place(policy, usage, pages, |of_class, access| {
assert_eq!(of_class, class);
let decided = in_place(policy, usage, pages, |of_class, access, of_rows| {
assert_eq!((of_class, of_rows), (class, rows));
asked.borrow_mut().push(access);
of(access)
});
@@ -139,12 +149,13 @@ fn the_decision_takes_a_texture_whose_class_passed_each_of_its_accesses() {
Verdict::Failed => ShadowCause::CheckFailed,
_ => ShadowCause::Unchecked,
};
(Err(cause(class, access)), accesses[..=at].to_vec())
let cause = cause(class, access, rows);
(Err(cause), accesses[..=at].to_vec())
}
}
}
};
let case = format!("{class:?} {usage:?} {texel} {answer:?}");
let case = format!("{class:?} {rows:?} {usage:?} {texel} {answer:?}");
assert_eq!(decided, expected, "{case}");
assert_eq!(*asked.borrow(), due, "{case}");
}
@@ -155,19 +166,22 @@ fn the_decision_takes_a_texture_whose_class_passed_each_of_its_accesses() {
#[test]
fn every_shadow_cause_names_itself() {
let (inside, on) = (RowEnds::InLines, RowEnds::OnLines);
let causes = [
ShadowCause::Exact,
ShadowCause::StoreWidth(2),
ShadowCause::CheckPending(PagesClass::Pointer, Access::Reads),
ShadowCause::CheckPending(PagesClass::Pointer, Access::Renders),
ShadowCause::CheckFailed(PagesClass::DmaBuf, Access::Reads),
ShadowCause::CheckFailed(PagesClass::DmaBuf, Access::Renders),
ShadowCause::Unchecked(PagesClass::Fresh, Access::Reads),
ShadowCause::Unchecked(PagesClass::Fresh, Access::Renders),
ShadowCause::CheckPending(PagesClass::Pointer, Access::Writes),
ShadowCause::CheckFailed(PagesClass::DmaBuf, Access::Writes),
ShadowCause::Unchecked(PagesClass::Fresh, Access::Writes),
ShadowCause::CheckPending(PagesClass::Pointer, Access::Reads, inside),
ShadowCause::CheckPending(PagesClass::Pointer, Access::Renders, inside),
ShadowCause::CheckFailed(PagesClass::DmaBuf, Access::Reads, inside),
ShadowCause::CheckFailed(PagesClass::DmaBuf, Access::Renders, inside),
ShadowCause::Unchecked(PagesClass::Fresh, Access::Reads, inside),
ShadowCause::Unchecked(PagesClass::Fresh, Access::Renders, inside),
ShadowCause::CheckPending(PagesClass::Pointer, Access::Writes, inside),
ShadowCause::CheckFailed(PagesClass::DmaBuf, Access::Writes, inside),
ShadowCause::Unchecked(PagesClass::Fresh, Access::Writes, inside),
ShadowCause::StoreWidth(1),
ShadowCause::CheckFailed(PagesClass::Pointer, Access::Renders, inside),
ShadowCause::CheckFailed(PagesClass::Pointer, Access::Renders, on),
];
let words: Vec<String> = causes.iter().map(ShadowCause::words).collect();
for (at, word) in words.iter().enumerate() {
@@ -183,6 +197,7 @@ fn every_shadow_cause_names_itself() {
assert!(words[3].contains("render pass"));
assert!(words[4].contains("dma-bufs"));
assert!(words[8].contains("not answered") && words[8].contains("storage writes"));
assert!(words[12].contains("share a line") && words[13].contains("share no line"));
}
/// A driver identity, every field set.
@@ -209,17 +224,8 @@ fn rechecked(mut bytes: Vec<u8>) -> Vec<u8> {
#[test]
fn a_record_reads_back_for_its_identity_alone() {
let identity = identity();
let verdicts = [
Verdict::Passed,
Verdict::Failed,
Verdict::Unchecked,
Verdict::Passed,
Verdict::Failed,
Verdict::Unchecked,
Verdict::Unchecked,
Verdict::Passed,
Verdict::Failed,
];
let verdicts: [Verdict; VERDICTS] =
std::array::from_fn(|at| [Verdict::Passed, Verdict::Failed, Verdict::Unchecked][at % 3]);
let bytes = encode(&identity, verdicts);
assert_eq!(decode(&identity, &bytes), Some(verdicts));
@@ -311,31 +317,44 @@ fn a_record_s_name_follows_every_field_of_the_identity() {
#[test]
fn the_checks_state_settles_once_and_wakes_its_waiters() {
let checks = InPlaceChecks::new(false);
let checks = InPlaceChecks::new(false, 64);
assert_eq!(checks.line(), 64);
assert_eq!(
InPlaceChecks::new(false, 0).line(),
1,
"a line is a byte at least"
);
assert!(!checks.forced_failure());
assert_eq!(checks.verdicts(), [Verdict::Pending; VERDICTS]);
assert!(!checks.wait(Duration::from_millis(1)));
assert!(checks.start());
assert!(!checks.start(), "the check starts once");
checks.set(PagesClass::Fresh, Access::Renders, Verdict::Passed);
let (inside, on) = (RowEnds::InLines, RowEnds::OnLines);
checks.set(PagesClass::Fresh, Access::Renders, on, Verdict::Passed);
assert_eq!(
checks.verdict(PagesClass::Fresh, Access::Renders),
checks.verdict(PagesClass::Fresh, Access::Renders, on),
Verdict::Passed
);
assert_eq!(
checks.verdict(PagesClass::Fresh, Access::Reads),
checks.verdict(PagesClass::Fresh, Access::Renders, inside),
Verdict::Pending
);
assert_eq!(
checks.verdict(PagesClass::Pointer, Access::Renders),
checks.verdict(PagesClass::Fresh, Access::Reads, on),
Verdict::Pending
);
// Each class and access has a place of its own.
let mut places: Vec<usize> = PagesClass::ALL
.into_iter()
.flat_map(|class| Access::ALL.map(|access| verdict_index(class, access)))
.collect();
places.sort_unstable();
assert_eq!(
checks.verdict(PagesClass::Pointer, Access::Renders, on),
Verdict::Pending
);
// Each class, access and row ends has a place of its own, those of texels that share a line
// first, as the record holds them.
let mut places: Vec<usize> = Vec::new();
for rows in RowEnds::ALL {
for class in PagesClass::ALL {
places.extend(Access::ALL.map(|access| verdict_index(class, access, rows)));
}
}
assert_eq!(places, (0..VERDICTS).collect::<Vec<_>>());
std::thread::scope(|scope| {
let waiter = scope.spawn(|| checks.wait(Duration::from_secs(30)));
@@ -343,5 +362,96 @@ fn the_checks_state_settles_once_and_wakes_its_waiters() {
assert!(waiter.join().unwrap_or(false));
});
assert_eq!(checks.took(), Some(Duration::from_millis(5)));
assert!(InPlaceChecks::new(true).forced_failure());
assert!(InPlaceChecks::new(true, 64).forced_failure());
}
/// A texture's layout in a buffer: `rows` rows of `row_bytes` bytes, `row_pitch` apart, from
/// `offset`, in one slice.
fn rows_of(offset: u64, row_bytes: u64, row_pitch: u64, rows: u64) -> BufferLayout {
BufferLayout {
offset,
row_pitch,
slice_pitch: row_pitch * rows,
row_bytes,
rows,
slices: 1,
}
}
#[test]
fn texels_share_no_line_exactly_where_each_gap_starts_and_ends_on_one() {
let (inside, on) = (RowEnds::InLines, RowEnds::OnLines);
// A 3840x2160 BGRA8 surface: 15360-byte rows, 240 lines each.
assert_eq!(RowEnds::of(0, &rows_of(0, 15360, 15360, 2160), 64), on);
assert_eq!(RowEnds::of(0, &rows_of(0, 15360, 16384, 2160), 64), on);
// A 3662-wide one at a 14656-byte pitch: 8 bytes of each row's last line lie beside it.
assert_eq!(RowEnds::of(0, &rows_of(0, 14648, 14656, 2039), 64), inside);
// Rows one after another share lines with each other alone, but the image's end must lie
// on one.
assert_eq!(RowEnds::of(0, &rows_of(0, 61, 61, 64), 64), on);
assert_eq!(RowEnds::of(0, &rows_of(0, 61, 61, 37), 64), inside);
// The first byte off a line, by the buffer's address or by the texture's offset.
assert_eq!(RowEnds::of(16, &rows_of(0, 256, 256, 16), 64), inside);
assert_eq!(RowEnds::of(0, &rows_of(32, 256, 256, 16), 64), inside);
assert_eq!(RowEnds::of(32, &rows_of(32, 256, 256, 16), 64), on);
// The pitch off a line, with bytes between rows.
assert_eq!(RowEnds::of(0, &rows_of(0, 256, 288, 16), 64), inside);
// One row: no bytes between rows, its end on a line.
assert_eq!(RowEnds::of(0, &rows_of(0, 320, 512, 1), 64), on);
// Slices with bytes between them, each starting on a line or not.
let slices = |slice_pitch| BufferLayout {
offset: 0,
row_pitch: 256,
slice_pitch,
row_bytes: 256,
rows: 4,
slices: 3,
};
assert_eq!(RowEnds::of(0, &slices(1024), 64), on);
assert_eq!(RowEnds::of(0, &slices(1088), 64), on);
assert_eq!(RowEnds::of(0, &slices(1056), 64), inside);
// A line of a byte: every byte its own line.
assert_eq!(RowEnds::of(3, &rows_of(5, 61, 67, 37), 1), on);
// The check's shapes at 64-byte lines: seven share none, six share one.
let rows = |line| SHAPES.map(|shape| shape.rows(line));
let shared = rows(64).iter().filter(|&&rows| rows == inside).count();
assert_eq!((SHAPES.len() - shared, shared), (7, 8));
// A driver that makes no linear image with bytes between rows but at the next multiple of its
// own (MoltenVK's 16 bytes, its line 16 bytes; llvmpipe's 64, its line 64; NVIDIA's 128 and
// RADV's 256, their lines 64) has shapes at that pitch whose texels share a line, for each
// access's shapes.
for (multiple, line) in [(16, 16), (64, 64), (128, 64), (256, 64)] {
let at = |shape: &Shape| {
let pitch = (shape.width * shape.texel).next_multiple_of(multiple);
shape.bytes_per_row == pitch && shape.rows(line) == inside
};
assert!(SHAPES.iter().any(at), "{multiple}-byte rows");
assert!(
STORE_SHAPES.iter().any(|(shape, _)| at(shape)),
"{multiple}-byte rows"
);
}
// At the 256-byte lines of a device whose atom is that long, two still share none.
assert!(rows(256).iter().filter(|&&rows| rows == on).count() >= 2);
// And each row ends has shapes of the check of storage writes.
for rows in RowEnds::ALL {
assert!(STORE_SHAPES.iter().any(|(shape, _)| shape.rows(64) == rows));
}
}
#[test]
fn a_change_beside_texels_that_share_no_line_fails_both_row_ends() {
use Verdict::{Failed, Passed, Unchecked};
let (inside, on) = (RowEnds::InLines, RowEnds::OnLines);
assert_eq!(verdicts([9, 21], None, false), [Passed, Passed]);
assert_eq!(verdicts([9, 21], None, true), [Failed, Failed]);
// Texels that share a line changed a byte: those that share none keep their rounds' answer.
assert_eq!(verdicts([0, 21], Some(inside), false), [Failed, Passed]);
assert_eq!(verdicts([0, 21], Some(inside), true), [Failed, Failed]);
assert_eq!(verdicts([0, 0], Some(inside), false), [Failed, Unchecked]);
// Texels that share none changed one: both fail.
assert_eq!(verdicts([0, 4], Some(on), false), [Failed, Failed]);
// Row ends no round kept every byte for are unchecked.
assert_eq!(verdicts([0, 21], None, false), [Unchecked, Passed]);
assert_eq!(verdicts([9, 0], None, false), [Passed, Unchecked]);
}
@@ -14,7 +14,7 @@
use super::blit_holds::{device, Scratch};
use crate::address::{PAGE, SPACE_BASE, SPACE_END};
use crate::fresh_pages::FRESH_PAGES_PAST;
use crate::in_place::{Access, PagesClass, Verdict as InPlaceVerdict};
use crate::in_place::{Access, PagesClass, RowEnds, Verdict as InPlaceVerdict};
use crate::submit_check::{encode, record_name, Check, Measured, Verdict};
use crate::{
AddressPlacement, Buffer, BufferContents, BufferDescriptor, Device, Error, GpuAddress,
@@ -195,7 +195,12 @@ fn the_in_place_check_checks_fresh_pages_where_held_imports_cost_submissions() {
"the recalled answers keep long buffers out of fresh pages"
);
assert!(device.settle_in_place_checks(WAIT), "the check answered");
let fresh = Access::ALL.map(|access| device.in_place_verdict(PagesClass::Fresh, access));
let fresh: Vec<InPlaceVerdict> = RowEnds::ALL
.into_iter()
.flat_map(|rows| {
Access::ALL.map(|access| device.in_place_verdict(PagesClass::Fresh, access, rows))
})
.collect();
eprintln!(
"IN-PLACE-CHECK-TAXED on {}: a long buffer in fresh pages where held imports cost \
nothing {takes}; the Fresh verdicts where they cost {fresh:?}; fresh-page buffers made {}",
@@ -209,7 +214,7 @@ fn the_in_place_check_checks_fresh_pages_where_held_imports_cost_submissions() {
),
false => assert_eq!(
fresh,
[InPlaceVerdict::Unchecked; 3],
[InPlaceVerdict::Unchecked; 6],
"no fresh pages to check"
),
}
@@ -10,6 +10,7 @@
use super::blit_holds::{device, over_host, Host, Scratch};
use crate::framebuffer_fetch::through_storage;
use crate::in_place::Access;
use crate::TextureDescriptor;
use metal2vulkan::metal::{PixelFormat, TextureUsage};
use metal2vulkan::vk::ImageUsageFlags;
@@ -31,7 +32,23 @@ fn a_render_target_in_place_takes_the_storage_usage_only_where_writes_passed() {
};
let settled = device.settle_in_place_checks(Duration::from_secs(120));
let report = device.in_place_check_report();
let passed = |line: &str| report.iter().any(|l| l == line);
// Whether the check passed for `access` over the buffer's pages, for texels of rows of `row`
// bytes one after another from its start (`in_place::RowEnds`).
let passed = |access, row: u64| {
use crate::in_place::{PagesClass, RowEnds, Verdict};
let layout = crate::linear_plan::BufferLayout {
offset: 0,
row_pitch: row,
slice_pitch: row * SIDE,
row_bytes: row,
rows: SIDE,
slices: 1,
};
let start = buffer.contents().map_or(0, |at| at.as_ptr().addr() as u64);
let checks = &device.shared().in_place;
let rows = RowEnds::of(start, &layout, checks.line());
checks.verdict(PagesClass::Pointer, access, rows) == Verdict::Passed
};
let fetches = through_storage(device.compile_device().profile());
for (format, texel) in [
(PixelFormat::RGBA8Unorm, 4),
@@ -53,11 +70,11 @@ fn a_render_target_in_place_takes_the_storage_usage_only_where_writes_passed() {
);
if in_place {
assert!(
passed("Pointer renders: Passed"),
passed(Access::Renders, SIDE * texel),
"{format:?}: in place where the check did not pass for render targets"
);
assert!(
!storage || (passed("Pointer writes: Passed") && feedback && fetches),
!storage || (passed(Access::Writes, SIDE * texel) && feedback && fetches),
"{format:?}: the storage usage where the check did not pass for a shader's \
writes, or with no fetch to read through it"
);
@@ -382,8 +382,23 @@ fn one_scratch(device_of: fn(&Path) -> Device, over: Over, (width, row): (u64, u
// A shadow merged back at each encoder's end: one over bytes another writer may write (all
// but a tracked `Private` buffer's, whose shadow is copied back).
let merged = texture.shadow().is_some_and(|copies| copies.merges_back());
let renders_in_place =
(device.in_place_check_report().iter()).any(|line| line == "Pointer renders: Passed");
// The check's verdict for render targets over host pages, for texels that lie in lines as
// the target's do: `RGBA8Unorm` rows `row` bytes apart from the buffer's start.
let renders_in_place = {
use crate::in_place::{Access, PagesClass, RowEnds, Verdict};
let layout = crate::linear_plan::BufferLayout {
offset: 0,
row_pitch: row,
slice_pitch: row * H,
row_bytes: width * 4,
rows: H,
slices: 1,
};
let start = buffer.contents().map_or(0, |at| at.as_ptr().addr() as u64);
let checks = &device.shared().in_place;
let rows = RowEnds::of(start, &layout, checks.line());
checks.verdict(PagesClass::Pointer, Access::Renders, rows) == Verdict::Passed
};
println!(
"MERGE-SCRATCH {over:?} {width}x{H}, rows of {row}: linear image {linear}, shadow {shadow} \
(merged back {merged}), the in-place check passed for render targets over host pages \
+13 -7
View File
@@ -2359,12 +2359,16 @@ impl Device {
// Texels past the buffer's length lie in no image over its memory: the shadow's copies go
// through the texture's tail (`buffer_texture.rs`).
let past = texels.past().is_some();
// How the texels lie in the device's lines of memory, each checked apart
// (`in_place::RowEnds`).
let rows = texels.rows(self.shared().in_place.line());
let device_copy = match class {
Some(class) if !past && !in_place::checking() && !texels.buffer.detached() => {
let policy = self.compile_device().policy().host_page_textures;
let pages = (class, texels.texel_bytes());
let pages = (class, rows, texels.texel_bytes());
let passed = |_, _, _| Verdict::Passed;
in_place::Access::Reads.takes(usage)
&& in_place::in_place(policy, usage, pages, |_, _| Verdict::Passed).is_ok()
&& in_place::in_place(policy, usage, pages, passed).is_ok()
&& texels.device_copy(self)
}
_ => false,
@@ -2402,11 +2406,11 @@ impl Device {
true => HostPageTexturePolicy::InPlace,
false => self.compile_device().policy().host_page_textures,
};
let verdict = |class, access| match checking {
let verdict = |class, access, rows| match checking {
true => Verdict::Passed,
false => self.in_place_verdict(class, access),
false => self.in_place_verdict(class, access, rows),
};
let pages = (class, texels.texel_bytes());
let pages = (class, rows, texels.texel_bytes());
match in_place::in_place(policy, usage, pages, verdict) {
Ok(()) => {
// A texture that renders takes the storage usage too where the check
@@ -2417,8 +2421,9 @@ impl Device {
// texels in place, as the check's writes do.
let storable = in_place::Access::Renders.takes(usage)
&& !in_place::Access::Writes.takes(usage)
&& in_place::STORED_TEXEL_BYTES.contains(&pages.1)
&& verdict(class, in_place::Access::Writes) == Verdict::Passed;
&& in_place::STORED_TEXEL_BYTES.contains(&pages.2)
&& verdict(class, in_place::Access::Writes, rows)
== Verdict::Passed;
let made = (&*texels, class, storable);
match self.in_place_image(&plan, descriptor, made, &facts)? {
Ok((image, pitched)) => {
@@ -2449,6 +2454,7 @@ impl Device {
if let ShadowCause::CheckPending(..) = cause {
*pending = Some(in_place::PendingMove {
class,
rows,
usage,
plan: plan.clone(),
descriptor: *descriptor,
@@ -53,7 +53,7 @@ use crate::device::lock;
use crate::error::{vulkan, Error, RuntimeGap};
use crate::framebuffer_fetch::storage_candidate;
use crate::image_plan::{ImageFacts, ImagePlan};
use crate::in_place::{Access, PagesClass, Refusal};
use crate::in_place::{Access, PagesClass, Refusal, RowEnds};
use crate::linear_plan::{check_linear_limits, linear_lack, BufferLayout, LinearLack};
use crate::shadow_copy_back::WordView;
use crate::shadow_copy_in::CopyIn;
@@ -780,19 +780,31 @@ impl Device {
/// Whether a rebind's copy of a buffer's bytes (`copied.rs`) may lie in fresh pages the
/// runtime imports (`Device::fresh_page_buffer`) for the images in place that `watches` note:
/// where the device's check passed for fresh pages and each live image's accesses
/// ([`fresh_pages_take`](Self::fresh_pages_take)), as each is then made over them for host
/// allocations. Where it did not, the copy lies in memory the device allocates, and each image
/// where the device's check passed for fresh pages, each live image's accesses and how its
/// texels lie in the device's lines of memory (`in_place::RowEnds`: a rebind keeps the bytes'
/// offset in their page) ([`fresh_pages_take`](Self::fresh_pages_take)), as each is then made
/// over them for host allocations. Where it did not, the copy lies in memory the device allocates, and each image
/// is a linear image of its own over it ([`in_place_over_copy`](Self::in_place_over_copy)).
/// On RADV the check leaves fresh pages unchecked: no new buffer lies in them where each held
/// pointer import costs every submission (`fresh_pages.rs`), so the check finds none to try.
pub(crate) fn fresh_pages_take_images(&self, watches: &[InPlaceWatch]) -> bool {
(watches.iter().filter_map(watched)).all(|image| self.fresh_pages_take(&image))
watches.iter().all(|watch| {
watched(watch)
.is_none_or(|image| self.fresh_pages_take(&image, self.watched_rows(watch)))
})
}
/// Whether the device's check passed for fresh pages and each of `image`'s accesses: an
/// image of attachment usage renders, one of storage usage is written, one of neither reads.
fn fresh_pages_take(&self, image: &Image) -> bool {
/// How the texels `watch` notes lie in the device's lines of memory (`in_place::RowEnds`):
/// `from_base` past the pages' first byte, which starts a page.
fn watched_rows(&self, watch: &InPlaceWatch) -> RowEnds {
let start = watch.from_base - watch.layout.offset;
RowEnds::of(start, &watch.layout, self.shared().in_place.line())
}
/// Whether the device's check passed for fresh pages, each of `image`'s accesses and texels
/// that lie in lines as `rows` says: an image of attachment usage renders, one of storage
/// usage is written, one of neither reads.
fn fresh_pages_take(&self, image: &Image, rows: RowEnds) -> bool {
use metal2vulkan::vk::ImageUsageFlags;
let usage = image.plan().usage;
let renders = usage.contains(ImageUsageFlags::COLOR_ATTACHMENT);
@@ -804,7 +816,7 @@ impl Device {
];
accesses.into_iter().all(|(access, takes)| {
!takes
|| self.in_place_verdict(PagesClass::Fresh, access)
|| self.in_place_verdict(PagesClass::Fresh, access, rows)
== crate::in_place::Verdict::Passed
})
}
@@ -838,7 +850,7 @@ impl Device {
// device allocates, a linear image of its own.
let made = match pages.over_own_pages() {
true => {
if !self.fresh_pages_take(&image) {
if !self.fresh_pages_take(&image, self.watched_rows(watch)) {
return Err(refused());
}
let facts = self
@@ -124,7 +124,7 @@ use crate::framebuffer_fetch::storage_candidate;
use crate::heap_sets;
use crate::image_barrier::{image_barrier, ImageDst};
use crate::image_plan::ImagePlan;
use crate::in_place::{self, Access as InPlaceAccess, PagesClass, Verdict};
use crate::in_place::{self, Access as InPlaceAccess, PagesClass, RowEnds, Verdict};
use crate::memory::Placement;
use crate::tracker::Access;
use crate::values::StorageMode;
@@ -174,6 +174,8 @@ pub(crate) struct StorageForms {
struct MoveWait {
texture: Weak<TextureShared>,
class: PagesClass,
/// How its texels lie in the device's lines of memory (`in_place::RowEnds`).
rows: RowEnds,
usage: TextureUsage,
/// The bytes of one of its texels.
texel: u64,
@@ -185,13 +187,13 @@ impl MoveWait {
/// they would for a texture made now.
fn moves(&self, device: &Device) -> Option<bool> {
let checks = &device.shared().in_place;
let verdict = |class, access| checks.verdict(class, access);
let pending = |access| verdict(self.class, access) == Verdict::Pending;
let verdict = |class, access, rows| checks.verdict(class, access, rows);
let pending = |access| verdict(self.class, access, self.rows) == Verdict::Pending;
if InPlaceAccess::ALL.into_iter().any(pending) {
return None;
}
let policy = device.compile_device().policy().host_page_textures;
let pages = (self.class, self.texel);
let pages = (self.class, self.rows, self.texel);
Some(in_place::in_place(policy, self.usage, pages, verdict).is_ok())
}
}
@@ -584,9 +586,9 @@ impl Texture {
return None;
}
let checks = &image.device.shared().in_place;
let verdict = |class, access| checks.verdict(class, access);
let verdict = |class, access, rows| checks.verdict(class, access, rows);
let policy = image.device.compile_device().policy().host_page_textures;
let pages = (pending.class, texels.texel_bytes());
let pages = (pending.class, pending.rows, texels.texel_bytes());
if texels.buffer.detached() || texels.buffer.copied() {
return None;
}
@@ -594,8 +596,8 @@ impl Texture {
// As the texture would have taken it as it was made (`Device::storage_over_buffer`).
let storable = InPlaceAccess::Renders.takes(pending.usage)
&& !InPlaceAccess::Writes.takes(pending.usage)
&& in_place::STORED_TEXEL_BYTES.contains(&pages.1)
&& verdict(pending.class, InPlaceAccess::Writes) == Verdict::Passed;
&& in_place::STORED_TEXEL_BYTES.contains(&pages.2)
&& verdict(pending.class, InPlaceAccess::Writes, pending.rows) == Verdict::Passed;
Some(Wanted::Move {
texels: Arc::clone(texels),
pending: pending.clone(),
@@ -764,6 +766,7 @@ impl Texture {
let wait = MoveWait {
texture: self.downgrade(),
class: pending.class,
rows: pending.rows,
usage: pending.usage,
texel: texels.texel_bytes(),
};
@@ -6172,9 +6172,10 @@ pub struct WorkCounts {
/// modifier's features or limits, the image's memory past the pages, or the driver's import.
pub host_texture_shadows_refused_dma_buf: u64,
/// Classes of host pages (pointer, dma-buf, fresh), each with each access (an image that
/// reads, one that renders, one a shader writes), the device's check ran for in this process:
/// `in_place_checks_passed`, `in_place_checks_failed` and `in_place_checks_unchecked`
/// together.
/// reads, one that renders, one a shader writes) and each row ends (texels that share a line
/// of memory with bytes beside them, and texels that share none), the device's check ran for
/// in this process: `in_place_checks_passed`, `in_place_checks_failed` and
/// `in_place_checks_unchecked` together.
pub in_place_checks_run: u64,
/// Of `in_place_checks_run`, those whose every image left every byte alone: its first move,
/// for one that renders its pass's load and store and its feedback loop moves, and for one a
@@ -6184,8 +6185,8 @@ pub struct WorkCounts {
pub in_place_checks_failed: u64,
/// Of `in_place_checks_run`, those that made no image of the class for the access.
pub in_place_checks_unchecked: u64,
/// Classes and accesses whose verdict was read from the record of an earlier check of the
/// same driver, device and runtime: no check ran for them.
/// Classes, accesses and row ends whose verdict was read from the record of an earlier check
/// of the same driver, device and check: no check ran for them.
pub in_place_checks_recalled: u64,
/// Textures over host pages made shadows before their pages' in-place verdicts (counted in
/// `host_texture_shadows_check_pending`) that moved in place once the verdicts passed, at
@@ -535,6 +535,8 @@ mod host_replay_frames;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod host_step_frames;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod in_place_rows;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod in_place_textures;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod index_fetches;
@@ -477,7 +477,7 @@ fn a_shared_surface_over_logged_pages_is_no_device_copy() {
let after = device.work_counts();
// SAFETY: the handle is only compared.
let in_place = unsafe { texture.vk_image() }.is_some();
let pointer = passed(&device, "Pointer");
let pointer = passed(&device, "Pointer", &buffer, (w * 4, h, bpr));
eprintln!(
"DEVICE-COPY on {} ({:?}): a Shared surface over logged pages: device copy {}, in place \
{in_place}, in places {}, the check passed for pointer pages {pointer}",
@@ -28,6 +28,7 @@ use super::first_use_writes::CHECK_WAIT;
use super::host_memory::{
counting, gpu_fill, gpu_read, host_page, not_importable, on_device, run, Mapping,
};
use super::in_place_rows;
use super::in_place_textures::refused;
use super::keep_alives::eventually;
use super::no_copy_heaps::{
@@ -1615,11 +1616,9 @@ fn sampled_textures_over_dma_buf_pages_are_in_place_where_their_pages_make_one_d
assert!(device.settle_in_place_checks(CHECK_WAIT));
let report = device.in_place_check_report();
eprintln!("{TEST} on {}: the check: {report:?}", device.name());
let passed = |class: &str| {
report
.iter()
.any(|line| *line == format!("{class}: Passed"))
};
// Whether the check passed for a class, for texels that share no line with bytes beside
// them where `on_lines`, else for those that share one.
let passed = |class: &str, on_lines: bool| in_place_rows::passed(&device, class, on_lines);
let imports = imports_dma_buf(&device);
let queue = device.new_command_queue().unwrap();
let page = host_page();
@@ -1646,6 +1645,8 @@ fn sampled_textures_over_dma_buf_pages_are_in_place_where_their_pages_make_one_d
for (what, ram, view, (width, height, pitch), one) in [one_run, scattered] {
let calls = Calls::default();
let buffer = no_copy(&device, &view, 0, view.len, ram.source(&view, &calls)).unwrap();
let first = buffer.contents().map_or(0, |at| at.as_ptr() as u64);
let on_lines = in_place_rows::on_lines(&device, first, 4 * width, pitch as u64, height);
let before = device.work_counts();
let texture = buffer
.new_texture(
@@ -1678,7 +1679,7 @@ fn sampled_textures_over_dma_buf_pages_are_in_place_where_their_pages_make_one_d
match imports {
Some(true) => {
assert_eq!(over_dma_buf, in_place, "{TEST}: {what}: over a dma-buf");
if passed("DmaBuf") {
if passed("DmaBuf", on_lines) {
assert_eq!((aliased, source), (one, u64::from(!one)), "{TEST}: {what}");
}
}
@@ -1689,7 +1690,7 @@ fn sampled_textures_over_dma_buf_pages_are_in_place_where_their_pages_make_one_d
calls.is_empty(),
"{TEST}: {what}: the source's calls {calls:?}"
);
if passed("Pointer") {
if passed("Pointer", on_lines) {
assert_eq!(
in_place + refused(&before, &after),
1,
@@ -29,6 +29,7 @@
//! the texels read that differ; and the check's verdicts (`IN-PLACE-CHECK`).
use super::host_memory::{counting, no_copy, not_importable, Mapping, GUEST_PAGE};
use super::in_place_rows;
use super::no_copy_textures::{floats, staged};
use super::pitched_surfaces::reading;
use super::{layer_reported_nothing_at_all, validated_device_with, Messages, ScratchCache, WAIT};
@@ -120,10 +121,6 @@ fn first_use_writes_under(policy: HostPageTexturePolicy, lapses: &mut Vec<String
device.in_place_check_took()
);
}
let pointer_passed = device
.in_place_check_report()
.iter()
.any(|line| line == "Pointer: Passed");
let queue = device.new_command_queue().unwrap();
let reads = reading(&device, PixelFormat::BGRA8Unorm, "tob_read");
let corners = staged(&device, &floats([-1.0, -1.0, 1.0, 1.0]));
@@ -164,6 +161,10 @@ fn first_use_writes_under(policy: HostPageTexturePolicy, lapses: &mut Vec<String
}
Err(error) => panic!("new_buffer_with_bytes_no_copy: {error:?}"),
};
// The verdict its texels take, at the start of the pages.
let first = buffer.contents().map_or(0, |at| at.as_ptr() as u64);
let on_lines = in_place_rows::on_lines(&device, first, row, bpr, h);
let pointer_passed = in_place_rows::passed(&device, "Pointer", on_lines);
let mut d = TextureDescriptor::texture_2d(PixelFormat::BGRA8Unorm, w, h, false);
d.usage = TextureUsage::SHADER_READ;
d.resource_options = buffer.resource_options();
@@ -0,0 +1,30 @@
//! The in-place check's verdict a texture over host pages takes (`Device::in_place_check_report`):
//! its class's for its access, for texels that share a line of the device's memory
//! (`Device::in_place_check_line`, its `nonCoherentAtomSize`) with bytes beside them, or for
//! texels that share none (the report's `, rows on lines` lines). Worked out here from the
//! texture's layout, apart from the runtime's own reckoning (`in_place::RowEnds::of`).
use metal2vulkan_runtime::Device;
/// Whether a 2D texture's texels, `rows` rows of `row_bytes` bytes `pitch` apart from `first`
/// bytes past a page (a no-copy buffer's pages start one), share no line of the device's memory
/// with bytes beside them: their first byte and their end lie on a line, and so do each row's
/// start and end where bytes lie between rows.
pub(crate) fn on_lines(device: &Device, first: u64, row_bytes: u64, pitch: u64, rows: u64) -> bool {
let line = device.in_place_check_line();
let on = |at: u64| at.is_multiple_of(line);
let end = first + (rows - 1) * pitch + row_bytes;
let rows_apart = rows > 1 && pitch != row_bytes;
on(first) && on(end) && (!rows_apart || (on(pitch) && on(first + row_bytes)))
}
/// Whether the device's check passed for `what` (`Pointer`, `Pointer renders`, `Fresh writes`,
/// as the report names a class and access), for texels that share no line with bytes beside
/// them where `on_lines`, else for those that share one.
pub(crate) fn passed(device: &Device, what: &str, on_lines: bool) -> bool {
let line = match on_lines {
true => format!("{what}, rows on lines: Passed"),
false => format!("{what}: Passed"),
};
device.in_place_check_report().contains(&line)
}
@@ -1,8 +1,9 @@
//! Device tests of textures over host pages in place (`HostPageTexturePolicy::InPlace`) on the
//! device the cfg selects: a texture over a no-copy buffer's pages or a buffer in fresh pages is an
//! image aliasing the pages where the device's check passed for their class and each of the
//! texture's accesses (one that reads, one that renders, one a shader writes), and a shadow
//! elsewhere, counted by why.
//! texture's accesses (one that reads, one that renders, one a shader writes), for texels that lie
//! in the device's lines of memory as its own do (`in_place_rows`), and a shadow elsewhere,
//! counted by why.
//!
//! - [`sampled_textures_over_host_pages_take_the_path_their_check_answered`], under the
//! validation layer: once the device's check answered (printed, `IN-PLACE-CHECK`, with its
@@ -80,6 +81,7 @@
use super::degrade_notices::counts;
use super::first_use_writes::CHECK_WAIT;
use super::host_memory::{counting, no_copy, not_importable, Mapping, GUEST_PAGE};
use super::in_place_rows;
use super::no_copy_textures::{floats, staged};
use super::pitched_surfaces::reading;
use super::{layer_reported_nothing_at_all, validated_device_with, Messages, ScratchCache, WAIT};
@@ -102,14 +104,22 @@ pub(super) fn in_place(options: &mut DeviceOptions) {
options.policy.host_page_textures = HostPageTexturePolicy::InPlace;
}
/// Whether the device's check passed for `class` (`Pointer`, `Fresh`, `DmaBuf`).
pub(super) fn passed(device: &Device, class: &str) -> bool {
device
.in_place_check_report()
.iter()
.any(|line| *line == format!("{class}: Passed"))
/// Whether the device's check passed for `what` (`Pointer`, `Fresh renders`, `DmaBuf`, ...), for
/// a 2D texture of `(w, h, bpr)` bytes (a row's texels, its rows, their pitch) at the start of
/// `buffer` (`in_place_rows`).
pub(super) fn passed(device: &Device, what: &str, buffer: &Buffer, (w, h, bpr): Rows) -> bool {
let first = buffer.contents().map_or(0, |at| at.as_ptr() as u64);
let on_lines = in_place_rows::on_lines(device, first, w, bpr, h);
in_place_rows::passed(device, what, on_lines)
}
/// A 2D texture's rows: the bytes of a row's texels, its rows, and their pitch.
pub(super) type Rows = (u64, u64, u64);
/// The verdicts the device's check gives, each a line of its report before what it found
/// changed: three classes, three accesses, two row ends.
const VERDICTS: usize = 18;
/// The devices made again where load beside the submission checks split their import tax's tries
/// ([`answered_device`]).
const DEVICES: usize = 3;
@@ -369,7 +379,7 @@ fn sampled_textures_over_host_pages_take_the_path_their_check_answered() {
{refused})",
device.name()
);
let checked = passed(&device, class);
let checked = passed(&device, class, &buffer, (w * texel, h, bpr));
let right = match (checked, path) {
(true, "in place") => (class == "Fresh") == (fresh == 1),
(true, "refused") => true,
@@ -629,7 +639,6 @@ fn written_textures_over_host_pages_take_the_path_their_checks_answered() {
})
.unwrap();
settled(&device);
let checked = passed(&device, "Pointer writes");
let queue = device.new_command_queue().unwrap();
let kernel = super::level_writes_by_usage::kernel(&device, "write_at_level");
let h = 64u64;
@@ -667,6 +676,7 @@ fn written_textures_over_host_pages_take_the_path_their_checks_answered() {
}
Err(error) => panic!("new_buffer_with_bytes_no_copy: {error:?}"),
};
let checked = passed(&device, "Pointer writes", &buffer, (w * 8, h, bpr));
let before = device.work_counts();
let texture = written(&buffer, PixelFormat::RGBA16Float, (w, h, bpr));
let after = device.work_counts();
@@ -755,13 +765,6 @@ fn writes_and_passes_beyond_the_usage_take_their_shadows() {
})
.unwrap();
settled(&device);
if !passed(&device, "Pointer") {
eprintln!(
"IN-PLACE-USAGE on {}: no image in place to write",
device.name()
);
return;
}
let queue = device.new_command_queue().unwrap();
let (w, h) = (64u64, 64u64);
// Padded rows, then packed ones: a device whose linear images take no padded pitch takes
@@ -789,6 +792,13 @@ fn writes_and_passes_beyond_the_usage_take_their_shadows() {
)
}
.unwrap();
if !passed(&device, "Pointer", &buffer, (w * 8, h, bpr)) {
eprintln!(
"IN-PLACE-USAGE on {}: {form}: no image in place to write",
device.name()
);
continue;
}
let texture = sampled(&buffer, PixelFormat::RGBA16Float, (w, h, bpr));
// SAFETY: the handle is only compared, while the texture lives.
let Some(image) = (unsafe { texture.vk_image() }) else {
@@ -882,8 +892,6 @@ fn textures_that_render_or_write_take_the_path_their_checks_answered() {
if policy == HostPageTexturePolicy::InPlace {
settled(&device);
}
let renders_in_place = passed(&device, "Pointer renders");
let writes_in_place = passed(&device, "Pointer writes");
let (w, h, bpr) = (64u64, 64u64, 256u64);
let len = ((bpr * h) as usize).next_multiple_of(GUEST_PAGE);
let mapping = Mapping::anonymous(len);
@@ -904,6 +912,10 @@ fn textures_that_render_or_write_take_the_path_their_checks_answered() {
}
Err(error) => panic!("new_buffer_with_bytes_no_copy: {error:?}"),
};
// The verdicts its `R32Uint` texels take.
let rows = (w * 4, h, bpr);
let renders_in_place = passed(&device, "Pointer renders", &buffer, rows);
let writes_in_place = passed(&device, "Pointer writes", &buffer, rows);
for usage in usages {
let mut d = TextureDescriptor::texture_2d(PixelFormat::R32Uint, w, h, false);
d.usage = usage;
@@ -983,7 +995,10 @@ fn a_failed_check_keeps_the_shadow_and_no_record() {
settled(&device);
let report = device.in_place_check_report();
assert!(
report.iter().take(9).all(|line| !line.ends_with("Passed")),
report
.iter()
.take(VERDICTS)
.all(|line| !line.ends_with("Passed")),
"{report:?}"
);
let len = (7680 * 1080usize).next_multiple_of(GUEST_PAGE);
@@ -1017,15 +1032,15 @@ fn a_failed_check_keeps_the_shadow_and_no_record() {
messages.take_notices();
}
// Nothing kept: the next device on the cache recalls nothing and checks. Its verdicts, one
// per class and access: what the check found changed where one failed follows them in the
// checking process's report alone, which no record keeps.
// per class, access and row ends: what the check found changed where one failed follows them
// in the checking process's report alone, which no record keeps.
let verdicts = {
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), in_place).unwrap();
assert_eq!(device.work_counts().in_place_checks_recalled, 0);
settled(&device);
assert!(device.in_place_check_took().is_some());
let mut report = device.in_place_check_report();
report.truncate(9);
report.truncate(VERDICTS);
report
};
// Its record is recalled whole by the device after it, which checks nothing.
@@ -1033,8 +1048,9 @@ fn a_failed_check_keeps_the_shadow_and_no_record() {
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), in_place).unwrap();
let counts = device.work_counts();
// Each class's verdicts, for a texture that reads, one that renders and one a shader
// writes.
assert_eq!(counts.in_place_checks_recalled, 9);
// writes, each for texels that share a line with bytes beside them and for texels that
// share none.
assert_eq!(counts.in_place_checks_recalled, VERDICTS as u64);
assert_eq!(counts.in_place_checks_run, 0);
assert!(device.settle_in_place_checks(std::time::Duration::ZERO));
assert_eq!(device.in_place_check_took(), None);
@@ -21,6 +21,7 @@
//! time with no record and with it.
use super::host_memory::{counting, no_copy, not_importable, Mapping, GUEST_PAGE};
use super::in_place_rows;
use super::{layer_reported_nothing_at_all, read_buffer, validated_device_with};
use super::{Messages, ScratchCache, WAIT};
use crate::gpu::TEST_DEVICE;
@@ -201,7 +202,6 @@ fn a_texture_at_the_answered_alignment_is_in_place() {
);
assert!(device.settle_in_place_checks(CHECK_WAIT));
let report = device.in_place_check_report();
let passed = report.iter().any(|line| line == "Pointer: Passed");
eprintln!(
"LINEAR-ALIGNMENT on {}: the in-place check {report:?}",
device.name()
@@ -228,7 +228,10 @@ fn a_texture_at_the_answered_alignment_is_in_place() {
let counted =
device.work_counts().host_textures_in_place - before.host_textures_in_place;
assert_eq!(counted, u64::from(aliased), "{what}: its form not counted");
if passed {
// The verdict its texels take, `at.0` past the start of the pages.
let base = over.buffer.contents().map_or(0, |a| a.as_ptr() as u64);
let on_lines = in_place_rows::on_lines(device, base + at.0, w * texel, at.1, ROWS);
if in_place_rows::passed(device, "Pointer", on_lines) {
assert!(aliased, "{what}: a shadow at the answered alignment");
}
in_place += u64::from(aliased);
@@ -99,7 +99,7 @@
use super::degrade_notices::{counts, on_device};
use super::first_use_writes::CHECK_WAIT;
use super::host_memory::{counting, no_copy, not_importable, Mapping, Seen, GUEST_PAGE};
use super::in_place_textures::passed;
use super::in_place_rows;
use super::no_copy_heaps::{no_copy_heap, shared, HEAP};
use super::no_copy_textures::{blending, floats, rects_beside, staged};
use super::rebinds::rebind;
@@ -276,7 +276,9 @@ fn renders_in_place(device: &Device) -> bool {
device.name(),
device.in_place_check_report()
);
passed(device, "Pointer renders")
// The surface's rows lie one after another from the start of its pages.
let on_lines = in_place_rows::on_lines(device, 0, W * TEXEL, W * TEXEL, H);
in_place_rows::passed(device, "Pointer renders", on_lines)
}
/// Whether `texture`'s texels are its own image's: aliased, not a shadow.
@@ -69,6 +69,7 @@
use super::attachment_reads::{corners, floats, function, red, SIDE};
use super::degrade_notices::on_device_with;
use super::host_memory::{no_copy, Mapping, GUEST_PAGE};
use super::in_place_rows;
use metal2vulkan::device::VkFeature;
use metal2vulkan::metal::state::DepthStencilDescriptor;
use metal2vulkan::metal::{
@@ -238,9 +239,10 @@ fn readers_over(
let alias = counts.feedback_loop_alias_images > made.feedback_loop_alias_images;
let shadow = counts.feedback_loop_shadow_images > made.feedback_loop_shadow_images;
// An image in place over host pages takes the storage usage the snapshot's fetch reads
// through where the device's check passed for a shader's writes over such pages.
let writes =
(device.in_place_check_report().iter()).any(|line| line == "Pointer writes: Passed");
// through where the device's check passed for a shader's writes over such pages, for texels
// that lie in lines as the surface's do: its rows one after another from its pages' start.
let on_lines = in_place_rows::on_lines(device, 0, row, row, SIDE);
let writes = in_place_rows::passed(device, "Pointer writes", on_lines);
let made = Made {
feedback: alias || shadow,
fetched: shadow || (alias && (!surface || writes)),
@@ -7954,6 +7954,7 @@ method metal2vulkan-runtime::Device::heap_buffer_size_and_align pub fn heap_buff
method metal2vulkan-runtime::Device::heap_texture_size_and_align pub fn heap_texture_size_and_align(&self, descriptor: &TextureDescriptor) -> Result<SizeAndAlign, Error>
method metal2vulkan-runtime::Device::host_range_remapped pub fn host_range_remapped(&self, bytes: NonNull<u8>, length: u64)
method metal2vulkan-runtime::Device::imports_shared_host_pointers pub fn imports_shared_host_pointers(&self) -> Result<bool, Error>
method metal2vulkan-runtime::Device::in_place_check_line pub fn in_place_check_line(&self) -> u64
method metal2vulkan-runtime::Device::in_place_check_report pub fn in_place_check_report(&self) -> Vec<String>
method metal2vulkan-runtime::Device::in_place_check_took pub fn in_place_check_took(&self) -> Option<Duration>
method metal2vulkan-runtime::Device::metal_heap_texture_size_and_align pub fn metal_heap_texture_size_and_align(&self, descriptor: &TextureDescriptor) -> Result<Option<SizeAndAlign>, Error>
Can't render this file because it is too large.
+10 -2
View File
@@ -348,7 +348,13 @@ their first move, their moves into the feedback loop layout and back, and a rend
clears and stores them, while the CPU writes the bytes between their rows and after them; and for
one a shader writes, images made with `ShaderWrite` usage, whose every texel a kernel stores
through an unsigned-integer view of 4, 8 or 16-byte texels while the CPU writes the bytes beside
them (a program's atomics are among no round). It runs
them (a program's atomics are among no round). Each verdict is given apart for texels that share
a line of the device's memory (`nonCoherentAtomSize` bytes) with bytes beside them and for texels
that share none (their first byte, their end and, with bytes between rows, each row's start and
end on a line): a device that writes back a texel's line whole puts an older value back over a
CPU write in the first alone, as the Iris Xe's clear and store and draws do, so its render targets
and written textures whose rows end on a line, a 3840x2160 `BGRA8Unorm` surface's among them,
take the image in place where the others keep the shadow. It runs
on a thread of its own, which the first such texture starts; a texture made before its kind of
pages and access has its verdict is a shadow, made without waiting for the check
(`WorkCounts::host_texture_shadows_check_pending`), and moves in place, with no copy, at a quiet
@@ -1523,7 +1529,9 @@ bound.
(`HostPageTexturePolicy::Shadow`), a shader writes the texture's texels of 1 or 2 bytes, which
the device's check stores none of, the device's check that the operations of an access of the
texture (the first move; a render pass's load and store; a kernel's storage writes) keep every
byte over that kind of pages has not answered yet, found a byte changed or made no image, or no
byte over that kind of pages, for texels that share a line of the device's memory
(`nonCoherentAtomSize`) with bytes beside them or not as the texture's do, has not answered yet,
found a byte changed or made no image, or no
image in place serves the texels (its rows share bytes, the device lays no linear image's rows at
the buffer's pitch, the image's placement or memory misses the pages, the bytes were detached, or
no dma-buf of the texture's own pages serves); the notice names which, and
+1 -9
View File
@@ -38,7 +38,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X
| 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 first encoder's GPU start is written at the bottom of the pipe, once 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), 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`. 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, round robin, 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 |
| A texture that samples, reads, renders into it or is written through a shader (`ShaderWrite` or `ShaderAtomic` usage, of texels of 4, 8 or 16 bytes) over host pages (a no-copy buffer's, or a no-copy heap's buffer's, imported by their pointer or as dma-bufs; or a buffer in fresh pages) is a linear image aliasing the pages in place, where the device makes the image (its format and usage linear, at the pages' pitch) and its own check shows that the operations Vulkan lets read and write every byte bound to it leave every byte alone while the CPU writes beside it: the image's first move (`VUID-VkImageCreateInfo-pNext-01443` makes such an image start `UNDEFINED`), and for one that renders a render pass's load and store operations and its moves into `ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT` and back, and for one a shader writes a kernel's storage writes of its texels (which of a linear image a driver may widen past a texel), each access checked apart. A deliberate, scoped exception to relying on documented Vulkan behaviour alone, the owner's rulings (2026-10-26, and 2026-10-27 and 2026-11-07 for render targets and written textures: the GPU works on the caller's pages in place as a Mac's does, whatever a linear image costs it, on a discrete GPU too; `in_place.rs`). The check runs once per driver and driver version (its record named by the driver and the check's own version, not the runtime release), per class of pages and access, on a thread of its own, its verdicts kept in the shader cache's directory; a texture made before its verdict is a shadow, made without waiting for the check (its rounds take seconds on some devices and builds; `host_texture_shadows_check_pending`), and moves in place once its class's verdicts pass, at the commit of the device's only uncommitted command buffer, with no copy (`host_textures_moved_in_place`), its shadow's image freed once the command buffer that took the move completed (`host_texture_shadows_freed_after_move`), or, where a view made before the move presents it, a shadow made over it holds it as its truth, or the texture is untracked, once those and the texture went. A texture a shader writes of 1- or 2-byte texels (no check stores them), a check that failed or made no image, and a format, usage or pitch no image takes keep the shadow (`shadowed-texture`, its reason named, `WorkCounts::host_texture_shadows_*`, those that render and those a shader writes counted apart in `host_texture_shadows_render_target` and `host_texture_shadows_shader_write`). On a discrete GPU a `Shared` texture and an IOSurface's are in place too, read across the bus, never copied to the device's memory for speed; a `Managed` texture over a no-copy buffer's bytes that only samples or reads, over memory that carries a log of its writes, is a device copy instead (`WorkCounts::device_copy_textures`), the GPU's copy of the two Metal keeps of a `Managed` resource on a Mac with a discrete GPU, its copies in only the rows the log reports changed. | `host_page_textures = HostPageTexturePolicy::InPlace` | `host_page_textures = HostPageTexturePolicy::Shadow`: every texture over host pages a shadow, its texels copied in before each command buffer that uses it and merged back after each write (the host-pages bullet under **Costs of matching Metal**) | Exact where the driver keeps what its check showed: the check covers texels, the bytes between rows and those after the image, of 1, 2, 4, 8 and 16-byte texels and a 3840x2160 surface, three rounds each, for an image that reads and one that renders (its pass a clear at load and a store, then a draw over its last column in a pass that loads and stores it; a resolve into it is not among the rounds), the CPU writing beside the texels sweep after sweep until each step completed, so that a device that writes back bytes it read beside them, wherever in the step, puts back an older value the check finds, and, for one a shader writes, of 4, 8 and 16-byte texels, rows apart (of widths no multiple of 4 and odd heights among them) or tight, and 1920x1080, each texel stored by a kernel through an unsigned-integer view (a program's atomics, and its stores through a float view, are not among the rounds); a driver whose operations changed a byte outside every round's window would undo a CPU write made meanwhile. Not announced where the check passed. A CPU write reaches the image's reads as it reaches the buffer's (Host Write Ordering Guarantees) | See **Costs of matching Metal** (host pages): the shadow copies a sampled 3840x2160 surface in whole each command buffer, and a render target's shadow copies it in, keeps it and merges it back at each render pass instance |
| A texture that samples, reads, renders into it or is written through a shader (`ShaderWrite` or `ShaderAtomic` usage, of texels of 4, 8 or 16 bytes) over host pages (a no-copy buffer's, or a no-copy heap's buffer's, imported by their pointer or as dma-bufs; or a buffer in fresh pages) is a linear image aliasing the pages in place, where the device makes the image (its format and usage linear, at the pages' pitch) and its own check shows that the operations Vulkan lets read and write every byte bound to it leave every byte alone while the CPU writes beside it: the image's first move (`VUID-VkImageCreateInfo-pNext-01443` makes such an image start `UNDEFINED`), and for one that renders a render pass's load and store operations and its moves into `ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT` and back, and for one a shader writes a kernel's storage writes of its texels (which of a linear image a driver may widen past a texel), each access checked apart, and each apart for texels that share a line of the device's memory (`nonCoherentAtomSize`, "the size and alignment in bytes that bounds concurrent access to host-mapped device memory") with bytes beside them and for texels that share none (their start, their end and, with bytes between rows, each row's start and end on a line; `in_place::RowEnds`): a byte changed beside texels that share none fails both, one changed beside texels that share one fails those alone (the Iris Xe, ANV, Mesa 26.2.6, whose clear and store, and draws, write back whole the 64-byte line that holds a row's last texels, fails renders, and writes, for rows that end inside a line, a byte between rows changed, and passes both for rows that end on one: a 3840x2160 `BGRA8Unorm` surface's 15360-byte rows are 240 lines each). A deliberate, scoped exception to relying on documented Vulkan behaviour alone, the owner's rulings (2026-10-26, and 2026-10-27 and 2026-11-07 for render targets and written textures: the GPU works on the caller's pages in place as a Mac's does, whatever a linear image costs it, on a discrete GPU too; `in_place.rs`). The check runs once per driver and driver version (its record named by the driver and the check's own version, not the runtime release), per class of pages, access and row ends, on a thread of its own, its verdicts kept in the shader cache's directory; a texture made before its verdict is a shadow, made without waiting for the check (its rounds take seconds on some devices and builds; `host_texture_shadows_check_pending`), and moves in place once its class's verdicts pass, at the commit of the device's only uncommitted command buffer, with no copy (`host_textures_moved_in_place`), its shadow's image freed once the command buffer that took the move completed (`host_texture_shadows_freed_after_move`), or, where a view made before the move presents it, a shadow made over it holds it as its truth, or the texture is untracked, once those and the texture went. A texture a shader writes of 1- or 2-byte texels (no check stores them), a check that failed or made no image, and a format, usage or pitch no image takes keep the shadow (`shadowed-texture`, its reason named, `WorkCounts::host_texture_shadows_*`, those that render and those a shader writes counted apart in `host_texture_shadows_render_target` and `host_texture_shadows_shader_write`). On a discrete GPU a `Shared` texture and an IOSurface's are in place too, read across the bus, never copied to the device's memory for speed; a `Managed` texture over a no-copy buffer's bytes that only samples or reads, over memory that carries a log of its writes, is a device copy instead (`WorkCounts::device_copy_textures`), the GPU's copy of the two Metal keeps of a `Managed` resource on a Mac with a discrete GPU, its copies in only the rows the log reports changed. | `host_page_textures = HostPageTexturePolicy::InPlace` | `host_page_textures = HostPageTexturePolicy::Shadow`: every texture over host pages a shadow, its texels copied in before each command buffer that uses it and merged back after each write (the host-pages bullet under **Costs of matching Metal**) | Exact where the driver keeps what its check showed: the check covers texels, the bytes between rows and those after the image, of 1, 2, 4, 8 and 16-byte texels and a 3840x2160 surface, three rounds each, for an image that reads and one that renders (its pass a clear at load and a store, then a draw over its last column in a pass that loads and stores it; a resolve into it is not among the rounds), the CPU writing beside the texels sweep after sweep until each step completed, so that a device that writes back bytes it read beside them, wherever in the step, puts back an older value the check finds, and, for one a shader writes, of 4, 8 and 16-byte texels, rows apart (of widths no multiple of 4 and odd heights among them) or tight, and 1920x1080, each texel stored by a kernel through an unsigned-integer view (a program's atomics, and its stores through a float view, are not Line truncated
| A render or compute state's creation hands the driver's making of its predicted pipeline (`pipeline/predicted.rs`, `pipeline/dispatch_making.rs`) to the runtime's pool, kept by the state as a draw's or dispatch's making is, and waits for it `pipeline_creation_wait` at most; a committed command buffer's recordings wait until its commit plus `pipeline_commit_wait` at most, one deadline its commands share, for its draws' and dispatches' (a compute encoder's, a render pass's tile dispatches) pipelines still being made (the scheduler wakes at the bound, `StepWaits::until`), an execution's replayed draws (`render/pending.rs`) among them, whose pipelines the commit's settle hands to the pool (a device replay's, one recording for every command, waits until made under either value), then record each such command as nothing: a draw's barriers and visibility query, a dispatch's barrier (a tile dispatch's copies into its scratch and back), no draw or dispatch, the command buffer running on without error. The making goes on, and the command buffers after it draw and dispatch with the pipeline once made. Metal compiles inside `newRenderPipelineState`, so no draw of a made state waits or is dropped; a host that creates a state inside a command buffer's encoding (the consumer creates a guest's state at an execution's first lookup of it) held that execution through the driver's whole compile: 11.59 s inside one execution on an M2 Pro (MoltenVK 1.4.2, a cold Metal compiler service; a sample of such a stall finds the compile's thread waiting in `MVKMetalCompiler::compile` for Metal's compiler), past the guest's 10 s FIFO check, which ended the guest's task. Each bound is 4.5 s: a creation and a commit may fall in one step of the guest's FIFO (a task's jobs run one after another, and a draw's own variant waits under its command buffer's bound), and no runtime call waits for both, so one step waits 9 s at most for makings, under that 10 s check. A creation waits on no command buffer's deadline and a `commit` on no creation's; a `commit` waits until its own deadline at most (it records there what it can, an execution of render commands the CPU writes among them), every other recording on the scheduler's thread, a host step's on one of the steps' threads. Made until made under either value, in the call that makes them: a draw that records nothing, one in a pass of custom sample positions and one recorded again into another instance of its pass (each in the draw's call or an execution's replay), a device replay's draws (in its `commit`), and a failed making made again (`PipelineWaitPolicy`'s docs). The runtime's: no pipeline differs. | `pipeline_waits = PipelineWaitPolicy::Bounded`, `pipeline_creation_wait = 4.5 s`, `pipeline_commit_wait = 4.5 s` | `pipeline_waits = PipelineWaitPolicy::Exact`: the creation makes its predicted pipeline before it returns (a render state's first key on its own thread, the rest on the pool, joined; a compute state's on its own thread), an execution's settle makes its replayed draws' pipelines at the commit, and a command buffer waits for each draw's and dispatch's pipeline until it is made | A draw whose pipeline was still being made `pipeline_commit_wait` after its command buffer's commit renders nothing in that command buffer (only there: later ones draw it), where Metal's renders: content drawn once (a layer, a glyph cache) stays without it until redrawn. A creation returns after `pipeline_creation_wait` at most with its making in flight (`WorkCounts::creations_left_making`). `DrawDroppedStillMaking` (`draw-dropped-still-making`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `CommandBuffer::dropped_draw` names the first with `VK_TIMEOUT`; `WorkCounts::draws_dropped_still_making`; `deferred_calls::a_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` and `under_the_exact_wait_a_held_making_holds_its_command_buffer_until_it_lands`. A dispatch whose pipeline was still being made then writes nothing in that command buffer, where Metal's runs: `DispatchDroppedStillMaking` (`dispatch-dropped-still-making`), `WorkCounts::dispatches_dropped_still_making`, the first named by `dropped_draw`; `deferred_calls::a_dispatch_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing`, `a_compute_state_s_creation_waits_its_bound_for_its_predicted_making` and `a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` | No GPU cost. The exact form holds the creating thread, and the command buffer, for the whole compile: up to 11.59 s on the M2 Pro's cold boot (that boot's 2,483 render state creations, translation included: 300 over 16 ms, 151 over 100 ms, 14 over 250 ms, 3 over 1 s, the longest 11.59 s, 5.82 s and 1.17 s), where the default holds a creation for 4.5 s at most and a command buffer for 4.5 s from its commit, which drops the draws of the compiles that outlast those (2 of that boot's 2,483 were over 4.5 s) for the command bufferLine truncated
| A line Apple's `setLineWidth:` widens (`w' = floor(16 w) / 16`, other than 1), and a triangle's edge in fill mode `Lines`, is drawn by the device's own lines at `w'` wherever it draws that width (`wideLines`, `w'` in `lineWidthRange` and above 0), where Metal draws the parallelogram Vulkan's non-strict wide lines may be (`render/line_width.rs`). They are exactly it on a non-strict device whose wide lines are parallelograms (`strictLines` unset, `nonStrictWideLinesUseParallelogram` set) at a width above 1 on its `lineWidthGranularity`, unannounced there; elsewhere they differ: a strict device's rectangle with square ends (lavapipe, NVIDIA), lines Vulkan does not state as parallelograms (ANV, and every width below 1), a width rounded to the granularity. A mesh draw's lines and edges and a tessellated patch draw's edges take the device's lines under either value, the band not drawing them (at the nearest width they draw where they do not draw `w'`, announced `lines-at-nearest-width`: a known gap below). The runtime's: no pipeline's code differs. | `wide_lines = WideLinePolicy::Device` | `wide_lines = WideLinePolicy::Exact`: a draw of lines or edges the device's lines draw otherwise than Metal is the pipeline's band variant (`VariantKey::line_band`, `pipeline::link::band`) on a device with `tessellationShader` (the device's lines where it has none, or where the translator refuses the state's band or the draw's): two triangles over each line's parallelogram, and each triangle's three edges' parallelograms facing as the triangle, through a tessellation control and evaluation stage; every other width other than 1 is the band under either value | The lines can cover pixels the parallelogram does not, and miss others, at each end and along each edge: up to half the width past each end (square ends), and a rounded width. `DeviceWideLines` (`device-wide-lines`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `WorkCounts::device_wide_line_draws`, `line_band_draws`, `nearest_width_line_draws`; `runtime_lane::line_widths` (the band matches Metal's maps of lines and of triangles' edges, their facing, culling, flat inputs, primitive IDs and depth on MoltenVK under both values, which has no `wideLines`; a band of edges under a depth bias is announced `wide-edge-depth-bias`) | Not measured. Expected from the band's form: a second pipeline variant made for each render state that draws such lines or edges (its two synthesized stages), each line tessellated as a patch of two control points into four corners and each triangle as a patch of three into 21 triangles (12 degenerate), and a strip, loop or fan drawn as the list of its primitives |
| A blit or fill through a `BGRA10_XR` or `BGRA10_XR_sRGB` texture Metal keeps losslessly compressed (`allowGPUOptimizedContents`, 16 texels or more a side, neither `ShaderWrite` nor `PixelFormatView` usage, one sample, not over a buffer) is the device's copy, which keeps the bytes it moves, on every device: Metal's GPU blit into, out of or between such textures moves the texels through its compression, which writes each 16-bit field's low six bits cleared and the alpha code clamped to `[384, 894]`, and its fill clears the low six bits alone (an Apple M3 Max under macOS 27.0.1, every direction, storage mode, usage and size that decides the compression; CPU copies keep the bytes on Metal too). A pass's draws through such an attachment are the device-gap row below. The runtime's choice: no pipeline differs (`compressed_blit.rs`). | `extended_range_blits = ExtendedRangeBlitPolicy::Kept` | `extended_range_blits = ExtendedRangeBlitPolicy::Canonical`: after a blit writes such a texture's region, or a blit out of one writes a buffer's words, a texture over a buffer's or another texture's, a compute dispatch (`bind::extended_canonical_module`, `extended_canonical.rs`) rewrites the texels it wrote in Metal's encoding: in place in a buffer's bytes, an image's through a scratch buffer, a copy out and back around the dispatch; a fill's texel is encoded before it is written. A buffer whose words the device cannot bind (an offset or pitch off 4 bytes, a region past `maxStorageBufferRange`) and a texture over a buffer whose rows share bytes keep the bytes under either value, announced | Bytes no Metal write left (uploaded, CPU-copied or kernel-written texels: a field's low six bits, an alpha code outside `[384, 894]`) keep what Metal's blit would rewrite; a texel reads the same value either way, its low six bits unread and its alpha read clamped. `ExtendedRangeBitsKept` (`extended-range-bits-kept`), once per device; under `Canonical` not for the blits it makes exact; `runtime_lane::compressed_blits` (both values on MoltenVK), the conformance cases `compressed-blits-bgra10xr` and `compressed-blits-bgra10xr-srgb` | Measured, `Canonical` against `Kept`, on `Private` `BGRA10_XR` textures Metal keeps compressed (the sRGB twin and fills not measured), 256x256 and 2048x2048, one whole-texture blit a command buffer: p50 of 300 blits a run, the two values interleaved in one process, three runs a host. RTX 5080 Laptop (NVIDIA 615.71.09, the command buffer's GPU time): a buffer into the texture 23.5 against 11.5 us and 761 against 244 us from a `Private` buffer, 42 against 30 us and 1,945 against 1,176 us from a `Shared` one; the texture into a `Private` buffer 14.1 against 11.2 us and 287 against 246 us, into a `Shared` one, whose words the dispatch rewrites in system memory, 66 against 27 us and 3,386 against 1,182 us; texture into texture 22.5 against 9.7 us and 630 against 80 us. Apple M3 Max (MoltenVK 1.4.2, whose GPU times are the host's, so per blit of 16 in one command buffer), the same blits: into the texture +38 to +57 us and +536 to +548 us, out of it into a buffer +15 us and +84 to +94 us, texture into texture +46 to +48 us and +535 to +541 us. Every figure is above its `Kept` one in every run, by more than the runs' spread (under 1 us on the 5080): measurable at both sizes on both hosts. Into an image a blit adds a copy out into a scratch buffer of the region's size, the dispatch, a copy back and the barriers between them; into a buffer the dispatch and a barrier. The scratch is made without zeros, since the copy out writes every byte the dispatch and the copy back read; the figures above were taken while it was zeroed first, by a command buffer of its own (a fill on the 5080, a copy on MoltenVK). CPU from the command buffer's making through its commit, a blit alone: +1 to +3 us on the M3 Max, +1 to +127 us on the 5080, whose host other builds loaded; 16 blits into 2048x2048 images in one command buffer hold 16 scratch buffers of 32 MiB, and encoding each costs 141 to 165 us (5080) and 286 to 356 us (M3 Max), new memory blocks among it, against 2 to 6 us under `Kept`. Nothing for a texture Metal keeps uncompressed or of another format |
@@ -634,14 +634,6 @@ driver's. Each is open work.
compute encoder its unit of command predication reaches past, which is one whose unit laid a
step before it opened or one of its own that the unit's later encoders read, and one whose unit
laid a loop or left work out; work on the GPU alone) fail `EncodedUseRebound` (announced).
- **A render target over host pages whose rows end on a 64-byte line is a shadow where its
device's check of render targets failed on rows that do not** (`in_place_check.rs`): the
verdict is one per class of pages. On the Iris Xe (ANV, Mesa 26.2.6) a pass that clears and
stores a linear image wrote back whole the 64-byte line that holds a row's last texels, putting
back what CPU writes beside them had replaced, in 77 of 100 rounds of a 100x50 `BGRA8Unorm`
image at a 512-byte pitch and 51 of 100 of a 33x17 `RGBA16Float` one, and in none of 100 of
images whose rows end on a line (20x9 `RGBA32Float` at 320 bytes, 64x16 `BGRA8Unorm` at 256)
nor of 25 of a 3840x2160 surface of tight rows: such rows could take the image in place there.
- **A copied rebind under a texture in place, where the device's check did not pass fresh pages
and its own linear image lies at another pitch, is refused** (`NotImplemented(RebindTextures)`).
A rebind whose pages the gate refuses, or whose bytes moved in their page, copies them, and the