Textures over a copied host buffer: an image over the copy where the check passed, not a shadow
Every texture made over a copied host buffer (a no-copy buffer whose import the caller's gate
refused, or that failed) was a shadow, refused as `Refused(Placement)` ("a copy of the caller's
pages in memory of the device's own"), whatever its usage: each command buffer copied the copy's
texels into the shadow's image, and merged writes back, on top of the copy's own copy-in and merge.
A consumer whose views of guest memory pass the host's mapping budget gets copies of its large
window surfaces (reims's Iris census: 112 gate copies, 1.9 GB), and every texture over them is
such a double copy: the boots' 491 refused-placement shadows.
The GPU uses the copy in the pages' stead, so a texture's image can lie there, as a rebind onto a
copy already makes one (`in_place_over_copy`):
- route.rs: a copied buffer's class is its copy's memory's (Fresh in fresh pages the runtime
imported, else Pooled); the in-place decision asks that class's verdicts and the caller's pages'
(Pointer: a rebind may import them), each for texels that lie in lines as they lie there
(`Texels::line_start` reads the copy's offset in its memory; `over_caller_pages` the pages').
- in_place_image.rs: `unplaced` over a copy makes the image in the copy's memory: in fresh pages
the host-allocation one, as over the pages; in memory the device allocates `own_unbound`, the
driver's linear image (PREINITIALIZED) where it lays the rows at the pitch, else the
DRM_FORMAT_MOD_LINEAR one of no external memory (`unbound_in` serves both, and
`in_place_unbound`). The image is watched for rebinds and its first move holds the pages, for any
no-copy buffer's pages (the class no longer decides it). A rebind onto a device-allocated copy
takes the DRM_FORMAT_MOD_LINEAR image too where the pooled class passed for its accesses
(`class_takes`, from `fresh_pages_take`).
- The image's identity is the buffer's, so its uses name the copy: commits copy the CPU's writes
in, completions merge the GPU's back, as for the buffer.
- Counted: `WorkCounts::copied_textures_in_place` (also in `host_textures_in_place`); a shadow's
notice names the copy.
Tests (copied_device.rs): a sampled and a rendered texture over a gate-refused copy take an image
over the copy exactly where the verdicts of the copy's memory and the pages pass (before this,
every one was a shadow, so on a device whose check passes the test fails), read the caller's
texels and a CPU write before a commit, and their blit and clear reach the texels' bytes in the
pages alone; such a texture follows rebinds to another copy and back to an import.
Docs: copied.rs, in_place.rs, in_place_image.rs, route.rs, HOWTO (copied host buffers),
FAST-PATHS (the in-place row), TexturePlacement::InPlace; api_signatures blessed.
(cherry picked from commit e6573e3f1b942d11bda3063f5477745018cf9239)
This commit is contained in:
1 parent
f56371ea90
commit
1cf4730839
13 files changed
+525
-112
No files matched your search
@@ -1616,12 +1616,39 @@ impl Texels {
|
||||
self.texel_bytes
|
||||
}
|
||||
|
||||
/// How the texels lie in the device's lines of memory of `line` bytes over the caller's pages
|
||||
/// themselves, from their address (`in_place::RowEnds::of`), and whether a shader's writes may
|
||||
/// change their rows' padding there (`in_place::Padding::of`): as [`rows`](Self::rows) and
|
||||
/// [`padding`](Self::padding) answer them over an import of the pages, which a copied host
|
||||
/// buffer's rebind may make (`copied.rs`), where [`rows`](Self::rows) answers them in its copy.
|
||||
/// `None` over no caller's pages.
|
||||
pub(super) fn over_caller_pages(&self, line: u64) -> Option<(RowEnds, Padding)> {
|
||||
let start = self.buffer.contents()?.as_ptr().addr() as u64;
|
||||
let padding = Padding::of(start, &self.layout, line, self.padding_owned());
|
||||
Some((
|
||||
RowEnds::of(start, &self.layout, line),
|
||||
padding.declared(self.buffer.padding_unobserved()),
|
||||
))
|
||||
}
|
||||
|
||||
/// Whether the texels' buffer is a copied host buffer (`copied.rs`) whose copy lies in fresh
|
||||
/// pages the runtime mapped and imported by their pointer (`fresh_pages.rs`), not in memory
|
||||
/// the device allocates.
|
||||
pub(super) fn copy_in_fresh_pages(&self) -> bool {
|
||||
self.buffer.copied()
|
||||
&& (self.buffer.host_pages()).is_some_and(|pages| pages.over_own_pages())
|
||||
}
|
||||
|
||||
/// Where the buffer's bytes start, for the device's lines of memory: their address, where the
|
||||
/// CPU addresses them; else, in the runtime's own memory (a `Private` buffer's), their offset
|
||||
/// in its memory object, from whose start the lines count (a `VkMappedMemoryRange`'s offset is
|
||||
/// a multiple of `nonCoherentAtomSize` from it, and the runtime maps a block from its start);
|
||||
/// `None` over the caller's `VkBuffer`.
|
||||
/// CPU addresses them; else, in the runtime's own memory (a `Private` buffer's, or a copied
|
||||
/// host buffer's copy, which the GPU uses in the stead of the caller's pages, `copied.rs`),
|
||||
/// their offset in its memory object, from whose start the lines count (a
|
||||
/// `VkMappedMemoryRange`'s offset is a multiple of `nonCoherentAtomSize` from it, and the
|
||||
/// runtime maps a block from its start); `None` over the caller's `VkBuffer`.
|
||||
fn line_start(&self) -> Option<u64> {
|
||||
if self.buffer.copied() {
|
||||
return Some(self.buffer.memory().1);
|
||||
}
|
||||
match self.buffer.contents() {
|
||||
Some(at) => Some(at.as_ptr().addr() as u64),
|
||||
None if self.buffer.caller_memory().is_none() => Some(self.buffer.memory().1),
|
||||
|
||||
@@ -105,8 +105,18 @@
|
||||
//! copy: in fresh pages the runtime imported where an image in place rides on it, made as over
|
||||
//! the caller's pages; else linear images of its memory that start `PREINITIALIZED`.
|
||||
//! - **What is not copied.** On macOS, memory whose GPU writes Metal's private option bit 24 drops
|
||||
//! imports a read-only view of its pages (`read_only_view.rs`). A texture made over a copied
|
||||
//! buffer is a shadow of its bytes (`shadowed-texture`).
|
||||
//! imports a read-only view of its pages (`read_only_view.rs`).
|
||||
//! - **Textures over a copy.** A texture made over a copied buffer is a linear image over the copy,
|
||||
//! bound in its memory at the texels' offset, where the device's in-place check passed for the
|
||||
//! copy's memory and the caller's pages (a rebind may import them), for the texture's accesses
|
||||
//! and how its texels lie in lines there (`in_place.rs`, `texture/route.rs`; counted:
|
||||
//! `WorkCounts::copied_textures_in_place`): in fresh pages the runtime imported, the image made
|
||||
//! for host allocations, as over the caller's pages; in memory the device allocates, the
|
||||
//! driver's own linear image that starts `PREINITIALIZED`, else a `DRM_FORMAT_MOD_LINEAR` one at
|
||||
//! Metal's pitch, under the check of the runtime's pooled memory (`PagesClass::Pooled`). Its
|
||||
//! hazard identity is the buffer's, so its uses name the copy as the buffer's do: each commit
|
||||
//! copies the CPU's writes in, and each completion that may have written it merges the GPU's
|
||||
//! back. Elsewhere it is a shadow of the copy's bytes (`shadowed-texture`).
|
||||
|
||||
use crate::device::lock;
|
||||
use crate::dirty_pages::{new_writer, DirtySource, DirtyTally, PagesLog};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
//! Textures over host pages, in place: a 2D texture (or array) whose declared usage samples, reads,
|
||||
//! renders into or writes it, over a no-copy buffer's host pages or over a buffer the runtime
|
||||
//! placed in fresh host pages, is a linear image aliasing those pages, where the device's own check
|
||||
//! shows that the operations that may touch bytes beside the texels leave every byte alone.
|
||||
//! shows that the operations that may touch bytes beside the texels leave every byte alone. Over a
|
||||
//! copied host buffer (`copied.rs`) the image aliases the copy the GPU uses in the pages' stead,
|
||||
//! where the check passed for the copy's memory (fresh pages, or the runtime's pooled memory) and
|
||||
//! for the pages, for texels that lie in lines as they lie in each (`texture/route.rs`).
|
||||
//!
|
||||
//! - **What Vulkan says.** An image bound to imported memory starts `UNDEFINED`
|
||||
//! (`VUID-VkImageCreateInfo-pNext-01443`: "If the pNext chain includes a
|
||||
|
||||
@@ -36,6 +36,13 @@
|
||||
//! texture bound to its bytes read and write the new pages. A command buffer committed before
|
||||
//! such a rebind and held back reaches the copy, encoded again; a rebind while one not yet
|
||||
//! committed used the buffer is refused, the gate unasked.
|
||||
//! - **Textures over a copy.** A texture made over a copied buffer, sampled or rendered into, is an
|
||||
//! image over the copy where the device's check passed for the copy's memory and the caller's
|
||||
//! pages (`WorkCounts::copied_textures_in_place`), else a shadow (`shadowed-texture`): either
|
||||
//! way it reads the caller's texels and a CPU write made before a commit, a blit into it and a
|
||||
//! render pass's clear reach the texels' bytes in the pages alone, the bytes between its rows
|
||||
//! and after it kept; a rebind to another copy and back to an import makes its image again over
|
||||
//! each, which it follows.
|
||||
//! - **The answer.** `Buffer::host_backing` says which: a buffer whose pages the device imported
|
||||
//! answers it imported them by their pointer, a copy answers `Copied` (each test's copy above
|
||||
//! too), a buffer placed in a no-copy heap its heap's, a detached one `Detached`, and a buffer
|
||||
@@ -1069,6 +1076,232 @@ fn copied_rebind_makes_a_texture_s_image_in_place_again_over_the_copy() {
|
||||
drop((texture, buffer));
|
||||
}
|
||||
|
||||
/// Whether the device's check passed, for a texture of `usage` over `buffer` (a copied buffer, its
|
||||
/// copy in memory the device allocates) at `pitch`, for its copy's memory (the runtime's pooled
|
||||
/// memory) and the caller's pages, each for texels that lie in lines as they lie there: whether
|
||||
/// the texture is to be an image over the copy (`texture/route.rs`).
|
||||
fn passed_over_copy(
|
||||
device: &Device,
|
||||
buffer: &Buffer,
|
||||
usage: metal2vulkan::metal::TextureUsage,
|
||||
pitch: usize,
|
||||
) -> bool {
|
||||
use crate::in_place::{Access, PagesClass, RowEnds, Verdict};
|
||||
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 line = device.shared().in_place.line();
|
||||
let caller = buffer.contents().unwrap().as_ptr().addr() as u64;
|
||||
let copy = buffer.memory().1;
|
||||
let renders = usage.contains(metal2vulkan::metal::TextureUsage::RENDER_TARGET);
|
||||
let passes = |class, start| {
|
||||
let rows = RowEnds::of(start, &layout, line);
|
||||
let access = match renders {
|
||||
true => Access::Renders,
|
||||
false => Access::Reads,
|
||||
};
|
||||
device.in_place_verdict(class, access, rows) == Verdict::Passed
|
||||
};
|
||||
let policy = device.compile_device().policy().host_page_textures;
|
||||
policy == metal2vulkan::device::HostPageTexturePolicy::InPlace
|
||||
&& passes(PagesClass::Pooled, copy)
|
||||
&& passes(PagesClass::Pointer, caller)
|
||||
}
|
||||
|
||||
/// A 16 x 16 RGBA8 texture of `usage` over `buffer` at 0, its rows `pitch` apart, and whether it
|
||||
/// is an image over the buffer's copy (`WorkCounts::copied_textures_in_place`), its making
|
||||
/// counted as an image in place or a shadow alone.
|
||||
fn texture_over_copy(
|
||||
device: &Device,
|
||||
buffer: &Buffer,
|
||||
usage: metal2vulkan::metal::TextureUsage,
|
||||
pitch: usize,
|
||||
) -> (crate::Texture, bool) {
|
||||
let mut descriptor = crate::TextureDescriptor::texture_2d(
|
||||
metal2vulkan::metal::PixelFormat::RGBA8Unorm,
|
||||
SIDE as u64,
|
||||
SIDE as u64,
|
||||
false,
|
||||
);
|
||||
descriptor.usage = usage;
|
||||
descriptor.resource_options = buffer.resource_options();
|
||||
let before = device.work_counts();
|
||||
let texture = buffer.new_texture(&descriptor, 0, pitch as u64).unwrap();
|
||||
let after = device.work_counts();
|
||||
let over_copy = after.copied_textures_in_place - before.copied_textures_in_place;
|
||||
let in_place = after.host_textures_in_place - before.host_textures_in_place;
|
||||
let shadows = after.shadowed_textures - before.shadowed_textures;
|
||||
assert_eq!(
|
||||
in_place, over_copy,
|
||||
"an image in place over a copy is over the copy"
|
||||
);
|
||||
assert_eq!(over_copy + shadows, 1, "an image over the copy or a shadow");
|
||||
(texture, over_copy == 1)
|
||||
}
|
||||
|
||||
/// A render pass's clear of `texture` (16 x 16 RGBA8 over `buffer`'s copy of `pages` at 0, rows
|
||||
/// `pitch` apart, in `pattern`) reaches the texels' bytes in the pages alone, at its completion.
|
||||
fn clear_reaches_the_pages(
|
||||
device: &Device,
|
||||
texture: &crate::Texture,
|
||||
pages: NonNull<u8>,
|
||||
pattern: &[u8],
|
||||
pitch: usize,
|
||||
) {
|
||||
let mut pass = crate::RenderPassDescriptor::new();
|
||||
let color = &mut pass.color_attachments[0];
|
||||
color.texture = Some(texture.clone());
|
||||
color.load_action = crate::LoadAction::Clear;
|
||||
color.store_action = crate::StoreAction::Store;
|
||||
color.clear_color = crate::ClearColor::new(1.0, 0.0, 1.0, 0.0);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
(command_buffer.render_command_encoder(&pass).unwrap())
|
||||
.end_encoding()
|
||||
.unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.status(), CommandBufferStatus::Completed);
|
||||
// SAFETY: the caller's bytes, which no command buffer uses now.
|
||||
let now = unsafe { std::slice::from_raw_parts(pages.as_ptr(), LENGTH) }.to_vec();
|
||||
for row in 0..SIDE {
|
||||
let (start, end) = (row * pitch, row * pitch + SIDE * TEXEL);
|
||||
assert!(
|
||||
now[start..end]
|
||||
.chunks(4)
|
||||
.all(|texel| texel == [255, 0, 255, 0]),
|
||||
"row {row}: the clear reached the pages"
|
||||
);
|
||||
let next = (row + 1) * pitch;
|
||||
assert_eq!(
|
||||
now[end..next],
|
||||
pattern[end..next],
|
||||
"row {row}: the bytes after it kept"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
now[SIDE * pitch..],
|
||||
pattern[SIDE * pitch..],
|
||||
"past the texels"
|
||||
);
|
||||
}
|
||||
|
||||
/// A texture made over a copied buffer is an image over the copy where the device's check passed
|
||||
/// for the copy's memory and the caller's pages (`texture/route.rs`), sampled and rendered into
|
||||
/// alike; else a shadow. Either way it reads the caller's texels; a CPU write before a commit
|
||||
/// reaches it; a blit into it, and for one that renders a render pass's clear, reach the texels'
|
||||
/// bytes in the pages alone. Before textures took an image over a copy, each was a shadow: on a
|
||||
/// device whose check passed (lavapipe, the Iris Xe) the answer the verdicts give fails it.
|
||||
#[test]
|
||||
fn a_texture_over_a_copied_buffer_is_an_image_over_the_copy_where_the_check_passed() {
|
||||
use metal2vulkan::metal::TextureUsage;
|
||||
let Some((device, _heard)) = device() else {
|
||||
return;
|
||||
};
|
||||
device.settle_in_place_checks(Duration::from_secs(120));
|
||||
let usages = [
|
||||
("sampled", TextureUsage::SHADER_READ),
|
||||
(
|
||||
"rendered",
|
||||
TextureUsage::SHADER_READ | TextureUsage::RENDER_TARGET,
|
||||
),
|
||||
];
|
||||
for (seed, (name, usage)) in (40u8..).zip(usages) {
|
||||
let host = Host::new(seed);
|
||||
let asked: Arc<Mutex<Vec<ImportRequest>>> = Arc::default();
|
||||
let buffer = host.buffer(&device, Some(gate(&asked, false)));
|
||||
assert!(buffer.copied(), "the gate refused the import: a copy");
|
||||
let expected = passed_over_copy(&device, &buffer, usage, PITCH);
|
||||
let (texture, over_copy) = texture_over_copy(&device, &buffer, usage, PITCH);
|
||||
eprintln!(
|
||||
"COPIED-TEXTURE {name} on {}: the check passed {expected}, an image over the copy \
|
||||
{over_copy}",
|
||||
device.name()
|
||||
);
|
||||
assert_eq!(
|
||||
over_copy, expected,
|
||||
"{name}: an image over the copy where the check passed"
|
||||
);
|
||||
// A CPU write before a commit reaches the texture.
|
||||
let pattern = host.pattern();
|
||||
assert_eq!(
|
||||
texels(&device, &texture),
|
||||
rows(&pattern),
|
||||
"{name}: the caller's texels"
|
||||
);
|
||||
host.write(0, &[0x3C; SIDE * TEXEL]);
|
||||
let read = texels(&device, &texture);
|
||||
assert!(
|
||||
read[..SIDE * TEXEL].iter().all(|&byte| byte == 0x3C),
|
||||
"{name}: the CPU's write reached the texture"
|
||||
);
|
||||
let mut written = pattern.clone();
|
||||
written[..SIDE * TEXEL].fill(0x3C);
|
||||
assert_eq!(
|
||||
read[SIDE * TEXEL..],
|
||||
rows(&written)[SIDE * TEXEL..],
|
||||
"{name}: the rest"
|
||||
);
|
||||
if usage.contains(TextureUsage::RENDER_TARGET) {
|
||||
clear_reaches_the_pages(&device, &texture, host.pointer, &written, PITCH);
|
||||
}
|
||||
texture_follows_the_copy(&device, &buffer, &texture, host.pointer, &host.bytes());
|
||||
drop((texture, buffer));
|
||||
}
|
||||
}
|
||||
|
||||
/// A texture made over a copied buffer as an image over the copy follows its buffer's rebinds: to
|
||||
/// another copy (the gate refuses the new pages) and back to an import (no gate), its image made
|
||||
/// again over each (`copied_rebind_images_made` for the copy), reading the new texels, its writes
|
||||
/// reaching the new pages.
|
||||
#[test]
|
||||
fn a_texture_over_a_copy_follows_its_buffer_s_rebinds() {
|
||||
use metal2vulkan::metal::TextureUsage;
|
||||
let (first, second) = (Host::new(44), Host::new(45));
|
||||
let Some((device, _heard)) = device() else {
|
||||
return;
|
||||
};
|
||||
device.settle_in_place_checks(Duration::from_secs(120));
|
||||
let asked: Arc<Mutex<Vec<ImportRequest>>> = Arc::default();
|
||||
let buffer = first.buffer(&device, Some(gate(&asked, false)));
|
||||
let (texture, over_copy) =
|
||||
texture_over_copy(&device, &buffer, TextureUsage::SHADER_READ, PITCH);
|
||||
eprintln!(
|
||||
"COPIED-TEXTURE-REBIND on {}: an image over the copy {over_copy}",
|
||||
device.name()
|
||||
);
|
||||
assert_eq!(texels(&device, &texture), rows(&first.pattern()));
|
||||
let before = device.work_counts();
|
||||
rebind(&buffer, &second, Some(gate(&asked, false))).unwrap();
|
||||
let after = device.work_counts();
|
||||
let images = after.copied_rebind_images_made - before.copied_rebind_images_made;
|
||||
assert_eq!(
|
||||
images,
|
||||
u64::from(over_copy),
|
||||
"the image made again over the new copy"
|
||||
);
|
||||
texture_follows_the_copy(
|
||||
&device,
|
||||
&buffer,
|
||||
&texture,
|
||||
second.pointer,
|
||||
&second.pattern(),
|
||||
);
|
||||
rebind(&buffer, &first, None).unwrap();
|
||||
assert!(!buffer.copied(), "imported again");
|
||||
assert_eq!(
|
||||
texels(&device, &texture),
|
||||
rows(&first.pattern()),
|
||||
"the imported texels"
|
||||
);
|
||||
drop((texture, buffer));
|
||||
}
|
||||
|
||||
/// A rebind's copy under an image in place lies in fresh pages only where the device's check
|
||||
/// passed for them: with the check's verdicts for fresh pages set unchecked (as on a device whose
|
||||
/// check failed them or found none to try), the copy lies in memory the device allocates, and the
|
||||
|
||||
@@ -2405,7 +2405,8 @@ impl Device {
|
||||
if !checking {
|
||||
let counts = &self.shared().counts;
|
||||
let written = in_place::Access::Writes.takes(usage);
|
||||
counts.host_texture_in_place(class, pitched, written);
|
||||
let copied = texels.buffer.copied();
|
||||
counts.host_texture_in_place(class, (pitched, written, copied));
|
||||
let usage = image.plan().usage;
|
||||
if usage.contains(ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT) {
|
||||
counts.feedback_loop_alias_image();
|
||||
@@ -2415,7 +2416,7 @@ impl Device {
|
||||
}
|
||||
Err((refusal, why)) => ShadowCause::Refused(refusal, why),
|
||||
};
|
||||
let shadowed = (class, (rows, padding), cause);
|
||||
let shadowed = ((class, texels.buffer.copied()), (rows, padding), cause);
|
||||
self.host_shadowed(shadowed, (usage, &plan), descriptor, pending)?
|
||||
}
|
||||
Route::Host {
|
||||
@@ -2424,7 +2425,7 @@ impl Device {
|
||||
padding,
|
||||
way: HostWay::Shadow(cause),
|
||||
} => {
|
||||
let shadowed = (class, (rows, padding), cause);
|
||||
let shadowed = ((class, texels.buffer.copied()), (rows, padding), cause);
|
||||
self.host_shadowed(shadowed, (usage, &plan), descriptor, pending)?
|
||||
}
|
||||
Route::Device { holds } => {
|
||||
@@ -2596,7 +2597,8 @@ impl Device {
|
||||
})
|
||||
}
|
||||
|
||||
/// A texture over host pages of `class`, its texels lying in the device's lines as `rows`
|
||||
/// A texture over host pages of `class` (over a copied host buffer's copy of them where
|
||||
/// `copied`, `class` the copy's memory's), its texels lying in the device's lines as `rows`
|
||||
/// says and its rows' padding as `padding` says (`in_place::Padding`), of `usage` and declared
|
||||
/// plan `plan` (`texture`), made with `descriptor`, is a shadow
|
||||
/// for `cause`: counted by why, and where made before its class's verdict for its access,
|
||||
@@ -2605,8 +2607,8 @@ impl Device {
|
||||
/// the image in place.
|
||||
fn host_shadowed(
|
||||
&self,
|
||||
(class, (rows, padding), cause): (
|
||||
PagesClass,
|
||||
((class, copied), (rows, padding), cause): (
|
||||
(PagesClass, bool),
|
||||
(in_place::RowEnds, in_place::Padding),
|
||||
ShadowCause,
|
||||
),
|
||||
@@ -2632,12 +2634,18 @@ impl Device {
|
||||
let renders = in_place::Access::Renders.takes(usage);
|
||||
let accesses = (renders, in_place::Access::Writes.takes(usage));
|
||||
self.shared().counts.host_texture_shadowed(&cause, accesses);
|
||||
if class == PagesClass::Fresh {
|
||||
if class == PagesClass::Fresh && !copied {
|
||||
self.shared().counts.shadow_over_fresh_pages();
|
||||
}
|
||||
let bytes = match (copied, class) {
|
||||
(true, PagesClass::Fresh) => {
|
||||
"a copy of the caller's pages in fresh pages the runtime imported"
|
||||
}
|
||||
(true, _) => "a copy of the caller's pages in memory the device allocates",
|
||||
(false, class) => class.words(),
|
||||
};
|
||||
Ok(format!(
|
||||
"the buffer's bytes are {}, and {}",
|
||||
class.words(),
|
||||
"the buffer's bytes are {bytes}, and {}",
|
||||
cause.words()
|
||||
))
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
//! host allocations too (counted: `WorkCounts::pitched_host_images`); else none (the shadow). An
|
||||
//! import a device takes for such an image only as a dedicated allocation is none: the image is
|
||||
//! bound at an offset of the buffer's import.
|
||||
//! - **Over a copied host buffer's copy of the pages** (`copied.rs`), which the GPU uses in their
|
||||
//! stead: in fresh pages the runtime imported, the image made for host allocations, as over the
|
||||
//! pages; in memory the device allocates, an image made for memory of its own, the driver's
|
||||
//! linear image that starts `PREINITIALIZED` where it lays the rows out at the texture's pitch,
|
||||
//! else a `DRM_FORMAT_MOD_LINEAR` one at that pitch made `UNDEFINED` (`Device::own_unbound`);
|
||||
//! bound in the copy's memory at the texels' offset, as over an import of the pages, and made
|
||||
//! again over a rebind's new pages as an image in place over the pages is.
|
||||
//! - **Over pages imported as dma-bufs** (`dma_buf.rs`): the `DRM_FORMAT_MOD_LINEAR` image at the
|
||||
//! texture's pitches bound to a dedicated import of the one dma-buf the pages' source makes of
|
||||
//! its own pages ([`Device::dma_buf_image`]), as a no-copy heap's texture there takes, its first
|
||||
@@ -334,7 +341,7 @@ impl Device {
|
||||
return Ok(Err(refused));
|
||||
}
|
||||
let make = |plan: &ImagePlan| match self.unplaced(plan, texels, class, facts)? {
|
||||
Ok(unplaced) => self.place(unplaced, plan, descriptor, texels, class),
|
||||
Ok(unplaced) => self.place(unplaced, plan, descriptor, texels),
|
||||
Err(refused) => Ok(Err(refused)),
|
||||
};
|
||||
let mut made = None;
|
||||
@@ -352,19 +359,18 @@ impl Device {
|
||||
Err(refused) => return Ok(Err(refused)),
|
||||
},
|
||||
};
|
||||
// Over a no-copy buffer's pages, noted for a rebind.
|
||||
if class != PagesClass::Fresh {
|
||||
if let Some(base) = texels.buffer.host_pages().map(|pages| pages.memory().1) {
|
||||
let (_, buffer_offset, _) = texels.buffer.memory();
|
||||
let image_any: Arc<dyn Any + Send + Sync> = image.clone();
|
||||
texels.buffer.watch_in_place(InPlaceWatch {
|
||||
image: Arc::downgrade(&image_any),
|
||||
from_base: buffer_offset + layout.offset - base,
|
||||
layout,
|
||||
padding_owned: texels.padding_owned(),
|
||||
texel: texels.texel_bytes(),
|
||||
});
|
||||
}
|
||||
// Over a no-copy buffer's pages (or its copy of them), noted for a rebind; a buffer's own
|
||||
// fresh pages lie in no host pages of a no-copy buffer.
|
||||
if let Some(base) = texels.buffer.host_pages().map(|pages| pages.memory().1) {
|
||||
let (_, buffer_offset, _) = texels.buffer.memory();
|
||||
let image_any: Arc<dyn Any + Send + Sync> = image.clone();
|
||||
texels.buffer.watch_in_place(InPlaceWatch {
|
||||
image: Arc::downgrade(&image_any),
|
||||
from_base: buffer_offset + layout.offset - base,
|
||||
layout,
|
||||
padding_owned: texels.padding_owned(),
|
||||
texel: texels.texel_bytes(),
|
||||
});
|
||||
}
|
||||
Ok(Ok((image, pitched)))
|
||||
}
|
||||
@@ -506,6 +512,9 @@ impl Device {
|
||||
class: PagesClass,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Result<Unplaced, (Refusal, String)>, Error> {
|
||||
if texels.buffer.copied() {
|
||||
return self.copy_unplaced(plan, texels, facts);
|
||||
}
|
||||
match class {
|
||||
PagesClass::DmaBuf => self.dma_buf_unplaced(plan, texels, facts),
|
||||
PagesClass::Pointer | PagesClass::Fresh => self.host_unplaced(plan, texels, facts),
|
||||
@@ -517,6 +526,42 @@ impl Device {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`unplaced`](Self::unplaced) over a copied host buffer's copy of the caller's pages
|
||||
/// (`copied.rs`), which the GPU uses in the stead of the pages: over a copy in fresh pages the
|
||||
/// runtime imported (`fresh_pages.rs`), the image made for host allocations, as over the
|
||||
/// caller's pages ([`host_unplaced`](Self::host_unplaced)); over one in memory the device
|
||||
/// allocates, the image made for memory of its own ([`own_unbound`](Self::own_unbound)). Either
|
||||
/// takes its place in the copy's memory, at the texels' offset ([`placed`]).
|
||||
fn copy_unplaced(
|
||||
&self,
|
||||
plan: &ImagePlan,
|
||||
texels: &Texels,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Result<Unplaced, (Refusal, String)>, Error> {
|
||||
if texels.copy_in_fresh_pages() {
|
||||
return self.host_unplaced(plan, texels, facts);
|
||||
}
|
||||
let layout = texels.layout;
|
||||
let (memory, buffer_offset, type_index) = texels.buffer.memory();
|
||||
let at = buffer_offset + layout.offset;
|
||||
let room = texels.buffer.memory_room().saturating_sub(layout.offset);
|
||||
let (made, pitched) = match self.own_unbound(plan, &layout, facts)? {
|
||||
Ok(made) => made,
|
||||
Err(refused) => return Ok(Err(refused)),
|
||||
};
|
||||
if let Err(refused) = placed(&made.requirements, at, room, type_index) {
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(self.shared().vk(), made.raw) };
|
||||
return Ok(Err(refused));
|
||||
}
|
||||
Ok(Ok(Unplaced::Host {
|
||||
made,
|
||||
pitched,
|
||||
memory,
|
||||
at,
|
||||
}))
|
||||
}
|
||||
|
||||
/// [`unplaced`](Self::unplaced) over pages imported by their pointer.
|
||||
fn host_unplaced(
|
||||
&self,
|
||||
@@ -602,19 +647,18 @@ impl Device {
|
||||
)))
|
||||
}
|
||||
|
||||
/// `unplaced`, an image in place of `plan` over `texels` (host pages of `class`), bound: over
|
||||
/// pages imported by their pointer, in the buffer's memory where it was checked to lie, its
|
||||
/// first move noted; over pages imported as dma-bufs, to a dedicated import of the dma-buf the
|
||||
/// caller's source makes of its pages (called with no lock of the runtime's held), which may
|
||||
/// still refuse it. With whether it is a `DRM_FORMAT_MOD_LINEAR` image made for host
|
||||
/// allocations.
|
||||
/// `unplaced`, an image in place of `plan` over `texels`, bound: over pages imported by their
|
||||
/// pointer (or a copied host buffer's copy of them), in the buffer's memory where it was
|
||||
/// checked to lie, its first move noted; over pages imported as dma-bufs, to a dedicated import
|
||||
/// of the dma-buf the caller's source makes of its pages (called with no lock of the runtime's
|
||||
/// held), which may still refuse it. With whether it is a `DRM_FORMAT_MOD_LINEAR` image at
|
||||
/// Metal's pitch.
|
||||
fn place(
|
||||
&self,
|
||||
unplaced: Unplaced,
|
||||
plan: &ImagePlan,
|
||||
descriptor: &TextureDescriptor,
|
||||
texels: &Texels,
|
||||
class: PagesClass,
|
||||
) -> Result<InPlace, Error> {
|
||||
match unplaced {
|
||||
Unplaced::Host {
|
||||
@@ -625,10 +669,11 @@ impl Device {
|
||||
} => {
|
||||
let raw = made.raw;
|
||||
let raw_device = self.shared().vk();
|
||||
// SAFETY: the image is live and unbound, made for host allocations; the memory is
|
||||
// the buffer's import of host pages (or its fresh pages'), which the image holds,
|
||||
// in a type the image takes, at an offset that meets its alignment, its size inside
|
||||
// the memory (`placed`).
|
||||
// SAFETY: the image is live and unbound, made for host allocations where the
|
||||
// memory is the buffer's import of host pages (or its fresh pages', or its copy's
|
||||
// there), and for memory of its own where it is a copy the device allocated
|
||||
// (`copy_unplaced`); the image holds the memory, in a type it takes, at an offset
|
||||
// that meets its alignment, its size inside the memory (`placed`).
|
||||
if let Err(error) =
|
||||
unsafe { crate::creation::bind_image(raw_device, raw, memory, at) }
|
||||
{
|
||||
@@ -637,12 +682,10 @@ impl Device {
|
||||
return Err(vulkan(error));
|
||||
}
|
||||
let image = self.in_place_of(Raw::new(raw), plan.clone(), descriptor, texels);
|
||||
// Over a no-copy buffer's pages, its move notes them (a rebind may swap the image
|
||||
// out of them); fresh pages are the buffer's for good.
|
||||
let pages = match class {
|
||||
PagesClass::Fresh => None,
|
||||
_ => texels.buffer.host_pages(),
|
||||
};
|
||||
// Over a no-copy buffer's pages (or its copy of them), its move notes them (a
|
||||
// rebind may swap the image out of them); a buffer's own fresh pages are its for
|
||||
// good, no no-copy buffer's pages.
|
||||
let pages = texels.buffer.host_pages();
|
||||
let first = FirstMove::new(
|
||||
raw,
|
||||
image.plan().format,
|
||||
@@ -756,6 +799,34 @@ impl Device {
|
||||
plan: &ImagePlan,
|
||||
layout: &BufferLayout,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Unbound, Error> {
|
||||
self.unbound_in(plan, layout, facts, crate::dma_buf::ModifierMemory::Host)
|
||||
}
|
||||
|
||||
/// As [`in_place_unbound`](Self::in_place_unbound), the image made for memory of the device's
|
||||
/// own (a copied host buffer's copy there, `copied.rs`): the driver's linear image, which
|
||||
/// starts `PREINITIALIZED` and so keeps the memory's bytes at its first move ("the transition
|
||||
/// away from this layout will preserve that data", Image Layouts), else the
|
||||
/// `DRM_FORMAT_MOD_LINEAR` image of no external memory, made `UNDEFINED`, whose first move the
|
||||
/// device's check of its pooled memory covers (`in_place::PagesClass::Pooled`).
|
||||
pub(super) fn own_unbound(
|
||||
&self,
|
||||
plan: &ImagePlan,
|
||||
layout: &BufferLayout,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Unbound, Error> {
|
||||
self.unbound_in(plan, layout, facts, crate::dma_buf::ModifierMemory::Own)
|
||||
}
|
||||
|
||||
/// The unbound image of `plan` for texels laid out as `layout` in `memory` (host allocations,
|
||||
/// or the runtime's own memory): [`in_place_unbound`](Self::in_place_unbound) and
|
||||
/// [`own_unbound`](Self::own_unbound).
|
||||
fn unbound_in(
|
||||
&self,
|
||||
plan: &ImagePlan,
|
||||
layout: &BufferLayout,
|
||||
facts: &ImageFacts<'_>,
|
||||
memory: crate::dma_buf::ModifierMemory,
|
||||
) -> Result<Unbound, Error> {
|
||||
let lies = |report: &vk::SubresourceLayout| {
|
||||
report.offset == 0
|
||||
@@ -769,7 +840,10 @@ impl Device {
|
||||
features,
|
||||
}))
|
||||
}
|
||||
None => self.host_linear_image(plan)?,
|
||||
None => match memory {
|
||||
crate::dma_buf::ModifierMemory::Own => self.linear_image(plan)?,
|
||||
_ => self.host_linear_image(plan)?,
|
||||
},
|
||||
};
|
||||
// Whether the driver made its linear image and laid it out otherwise.
|
||||
let (linear, elsewhere) = match made {
|
||||
@@ -778,8 +852,9 @@ impl Device {
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(self.shared().vk(), made.raw) };
|
||||
let why = format!(
|
||||
"its linear image for host allocations lays rows {} bytes apart (slices {}) \
|
||||
from offset {}, where the texels' lie {} (slices {}) apart from offset 0",
|
||||
"its linear image for {} lays rows {} bytes apart (slices {}) from offset {}, \
|
||||
where the texels' lie {} (slices {}) apart from offset 0",
|
||||
memory.words(),
|
||||
made.report.row_pitch,
|
||||
made.report.array_pitch,
|
||||
made.report.offset,
|
||||
@@ -790,8 +865,7 @@ impl Device {
|
||||
}
|
||||
Err(refusal) => (refusal.describe(plan), false),
|
||||
};
|
||||
let host = crate::dma_buf::ModifierMemory::Host;
|
||||
Ok(match self.pitched_image(plan, layout, facts, host)? {
|
||||
Ok(match self.pitched_image(plan, layout, facts, memory)? {
|
||||
Ok(made) => Ok((made, true)),
|
||||
// A linear image the driver lays out otherwise is refused for its pitch; else the
|
||||
// pitched image's refusal names why.
|
||||
@@ -1056,15 +1130,16 @@ impl Device {
|
||||
/// runtime imports (`Device::fresh_page_buffer`) for the images in place that `watches` note:
|
||||
/// 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
|
||||
/// offset in their page) ([`class_takes`](Self::class_takes)), 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().all(|watch| {
|
||||
watched(watch)
|
||||
.is_none_or(|image| self.fresh_pages_take(&image, self.watched_rows(watch)))
|
||||
watched(watch).is_none_or(|image| {
|
||||
self.class_takes(PagesClass::Fresh, &image, self.watched_rows(watch))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1082,15 +1157,16 @@ impl Device {
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether the device's check passed for fresh pages, each of `image`'s accesses and texels
|
||||
/// of `texel` bytes that lie in lines as `rows` says: an image of attachment usage renders,
|
||||
/// one of storage usage is written, one of neither reads. The writes take the check of the
|
||||
/// texels' width (`in_place::Access::written`), and of one that does not render whose rows'
|
||||
/// padding is free the form that lets it change (`in_place::in_place`); one that renders may
|
||||
/// hold the storage usage a render target takes where the form that keeps it passed
|
||||
/// (`in_place::storable`), which it asks.
|
||||
fn fresh_pages_take(
|
||||
/// Whether the device's check passed for `class` (fresh pages, or the runtime's pooled
|
||||
/// memory), each of `image`'s accesses and texels of `texel` bytes that lie in lines as `rows`
|
||||
/// says: an image of attachment usage renders, one of storage usage is written, one of neither
|
||||
/// reads. The writes take the check of the texels' width (`in_place::Access::written`), and of
|
||||
/// one that does not render whose rows' padding is free the form that lets it change
|
||||
/// (`in_place::in_place`); one that renders may hold the storage usage a render target takes
|
||||
/// where the form that keeps it passed (`in_place::storable`), which it asks.
|
||||
fn class_takes(
|
||||
&self,
|
||||
class: PagesClass,
|
||||
image: &Image,
|
||||
(rows, padding, texel): (RowEnds, Padding, u64),
|
||||
) -> bool {
|
||||
@@ -1110,8 +1186,7 @@ impl Device {
|
||||
accesses.into_iter().all(|(access, takes)| {
|
||||
!takes
|
||||
|| access.is_some_and(|access| {
|
||||
self.in_place_verdict(PagesClass::Fresh, access, rows)
|
||||
== crate::in_place::Verdict::Passed
|
||||
self.in_place_verdict(class, access, rows) == crate::in_place::Verdict::Passed
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1122,12 +1197,14 @@ impl Device {
|
||||
/// a copy in fresh pages the runtime imported (`fresh_pages.rs`), the image an import of the
|
||||
/// caller's pages takes, made for host allocations (the driver's linear image at the texels'
|
||||
/// pitches, else the `DRM_FORMAT_MOD_LINEAR` one), where the device's check passed for fresh
|
||||
/// pages (`in_place.rs`); over one in memory the device allocates, a linear image of its own,
|
||||
/// as a texture's over a buffer of the runtime's, which starts `PREINITIALIZED` and so keeps
|
||||
/// the copy's bytes at its first move ("the transition away from this layout will preserve
|
||||
/// that data", Image Layouts). Either lies at the texels' pitches from offset 0, in a type of
|
||||
/// the copy's memory, at an offset its alignment meets, inside the copy's memory. Refused
|
||||
/// (`NotImplemented(RebindTextures)`) where it does not.
|
||||
/// pages (`in_place.rs`); over one in memory the device allocates, an image of its own memory
|
||||
/// ([`own_unbound`](Self::own_unbound)): the driver's linear image, as a texture's over a
|
||||
/// buffer of the runtime's, which starts `PREINITIALIZED` and so keeps the copy's bytes at its
|
||||
/// first move ("the transition away from this layout will preserve that data", Image Layouts),
|
||||
/// else the `DRM_FORMAT_MOD_LINEAR` one at the texels' pitches where the device's check passed
|
||||
/// for its pooled memory and the image's accesses. Either lies at the texels' pitches from
|
||||
/// offset 0, in a type of the copy's memory, at an offset its alignment meets, inside the
|
||||
/// copy's memory. Refused (`NotImplemented(RebindTextures)`) where it does not.
|
||||
fn in_place_over_copy(
|
||||
&self,
|
||||
image: Arc<Image>,
|
||||
@@ -1142,25 +1219,35 @@ impl Device {
|
||||
// pages takes, made for host allocations (`in_place_unbound`), where the device's check
|
||||
// passed for fresh pages and each of the image's accesses (an image of attachment usage
|
||||
// renders, one of storage usage is written; one of neither reads); one in memory the
|
||||
// device allocates, a linear image of its own.
|
||||
// device allocates, an image of its own memory (`own_unbound`).
|
||||
let facts = self
|
||||
.shared()
|
||||
.textures
|
||||
.facts(self.compile_device().profile());
|
||||
let made = match pages.over_own_pages() {
|
||||
true => {
|
||||
if !self.fresh_pages_take(&image, self.watched_rows(watch)) {
|
||||
if !self.class_takes(PagesClass::Fresh, &image, self.watched_rows(watch)) {
|
||||
return Err(refused());
|
||||
}
|
||||
let facts = self
|
||||
.shared()
|
||||
.textures
|
||||
.facts(self.compile_device().profile());
|
||||
let Ok((made, _)) = self.in_place_unbound(image.plan(), layout, &facts)? else {
|
||||
return Err(refused());
|
||||
};
|
||||
made
|
||||
}
|
||||
false => {
|
||||
let Ok(made) = self.linear_image(image.plan())? else {
|
||||
let Ok((made, pitched)) = self.own_unbound(image.plan(), layout, &facts)? else {
|
||||
return Err(refused());
|
||||
};
|
||||
// The `DRM_FORMAT_MOD_LINEAR` one starts `UNDEFINED`: where the device's check
|
||||
// passed for its pooled memory and the image's accesses, as an image at Metal's
|
||||
// pitch there takes it (`Device::pooled_pitched_image`).
|
||||
if pitched
|
||||
&& !self.class_takes(PagesClass::Pooled, &image, self.watched_rows(watch))
|
||||
{
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(raw_device, made.raw) };
|
||||
return Err(refused());
|
||||
}
|
||||
made
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
//! [`Buffer::texture_placement`](crate::Buffer::texture_placement) answers it. Both call
|
||||
//! [`Device::route_over_buffer`], so the answer is the making's own decision: a tiled texture's
|
||||
//! levels past the first, texels past the buffer's length, a buffer of no host pages, a device
|
||||
//! copy, bytes detached or copied, and over host pages the in-place decision
|
||||
//! (`in_place::in_place`) against the device's check's verdicts. Where that takes the image in
|
||||
//! copy, bytes detached, and over host pages (or a copied host buffer's copy of them) the in-place
|
||||
//! decision (`in_place::in_place`) against the device's check's verdicts. Where that takes the image in
|
||||
//! place, the query also runs the image's making up to the bind (`texture/in_place_image.rs`), so
|
||||
//! a pitch, an image, a placement or rows the device refuses answer the shadow the texture then
|
||||
//! is.
|
||||
@@ -132,9 +132,11 @@ impl Device {
|
||||
/// a tiled texture of more than one level, whatever holds the 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 fresh
|
||||
/// pages the runtime imported for a long buffer of its own, `fresh_pages.rs`): a device copy
|
||||
/// where one serves; else the shadow where the bytes were detached or copied; else as the
|
||||
/// device's policy, the texture's usage and the device's check of the pages' class for each
|
||||
/// access take it (`in_place.rs`), asking the verdicts (a pending one starts the check). The
|
||||
/// where one serves; else the shadow where the bytes were detached; else as the device's
|
||||
/// policy, the texture's usage and the device's check of the pages' class for each access take
|
||||
/// it (`in_place.rs`), asking the verdicts (a pending one starts the check): over a copied host
|
||||
/// buffer (`copied.rs`), the class of the copy's memory (fresh pages, or the runtime's pooled
|
||||
/// memory) and the caller's pages', each for texels that lie in lines as they lie there. The
|
||||
/// device's check's own textures take the image in place whatever the policy and the
|
||||
/// verdicts.
|
||||
pub(crate) fn route_over_buffer(
|
||||
@@ -149,7 +151,15 @@ impl Device {
|
||||
if past {
|
||||
return Route::Past;
|
||||
}
|
||||
let copied = texels.buffer.copied();
|
||||
let class = match texels.buffer.caller_memory() {
|
||||
// A copied host buffer's bytes the GPU uses lie in a copy of the caller's pages in
|
||||
// memory of the device's own (`copied.rs`): fresh pages the runtime imported, or
|
||||
// memory the device allocates, whose class's verdicts the image over it takes.
|
||||
Some(CallerMemory::HostPages) if copied => match texels.copy_in_fresh_pages() {
|
||||
true => PagesClass::Fresh,
|
||||
false => PagesClass::Pooled,
|
||||
},
|
||||
Some(CallerMemory::HostPages) if texels.buffer.over_dma_buf() => PagesClass::DmaBuf,
|
||||
Some(CallerMemory::HostPages) => PagesClass::Pointer,
|
||||
None if texels.buffer.in_fresh_pages() => PagesClass::Fresh,
|
||||
@@ -203,17 +213,6 @@ impl Device {
|
||||
.to_owned(),
|
||||
)));
|
||||
}
|
||||
if texels.buffer.copied() {
|
||||
// A copied host buffer's bytes the GPU uses lie in memory of the device's own, no
|
||||
// import of the pages (`copied.rs`): the shadow copies them, its copies the buffer's
|
||||
// uses, which commits copy in and completions merge back.
|
||||
return host(HostWay::Shadow(ShadowCause::Refused(
|
||||
Refusal::Placement,
|
||||
"the buffer's bytes are a copy of the caller's pages in memory of the device's \
|
||||
own, which no image over the pages lies in"
|
||||
.to_owned(),
|
||||
)));
|
||||
}
|
||||
// The check's own textures measure the device whatever its policy.
|
||||
let policy = match checking {
|
||||
true => HostPageTexturePolicy::InPlace,
|
||||
@@ -223,11 +222,29 @@ impl Device {
|
||||
true => Verdict::Passed,
|
||||
false => self.in_place_verdict(class, access, rows),
|
||||
};
|
||||
match in_place::in_place(policy, usage, pages, verdict) {
|
||||
// Over a copy, an image over the copy's memory where its class's verdicts take it, and
|
||||
// the caller's pages' too, for texels that lie in lines as they lie there: a rebind may
|
||||
// import the pages by their pointer, the image made again over that import as an image in
|
||||
// place over them is (`Device::rebound_in_place_images`).
|
||||
let caller = match copied {
|
||||
true => texels.over_caller_pages(line),
|
||||
false => None,
|
||||
};
|
||||
let decided = in_place::in_place(policy, usage, pages, verdict).and_then(|()| {
|
||||
caller.map_or(Ok(()), |(rows, padding)| {
|
||||
let pages = (PagesClass::Pointer, rows, pages.2, padding);
|
||||
in_place::in_place(policy, usage, pages, verdict)
|
||||
})
|
||||
});
|
||||
match decided {
|
||||
// A texture that renders takes the storage usage too where the check passed for a
|
||||
// shader's writes of its texels over the class (`in_place::storable`).
|
||||
// shader's writes of its texels over the class (`in_place::storable`), and over a
|
||||
// copy, over the caller's pages too.
|
||||
Ok(()) => host(HostWay::InPlace {
|
||||
storable: in_place::storable(usage, (class, rows, pages.2), verdict),
|
||||
storable: in_place::storable(usage, (class, rows, pages.2), verdict)
|
||||
&& caller.is_none_or(|(rows, _)| {
|
||||
in_place::storable(usage, (PagesClass::Pointer, rows, pages.2), verdict)
|
||||
}),
|
||||
}),
|
||||
Err(cause) => host(HostWay::Shadow(cause)),
|
||||
}
|
||||
|
||||
@@ -1113,7 +1113,9 @@ impl Device {
|
||||
};
|
||||
match *counted {
|
||||
MoveCount::Host(class, pitched, written) => {
|
||||
shared.counts.host_texture_in_place(class, pitched, written);
|
||||
// A copied host buffer's shadow does not move (`move_wanted`).
|
||||
let copied = false;
|
||||
(shared.counts).host_texture_in_place(class, (pitched, written, copied));
|
||||
shared.counts.host_texture_moved_in_place();
|
||||
let feedback = metal2vulkan::vk::ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT;
|
||||
let plan = texture.image_plan();
|
||||
|
||||
@@ -21,7 +21,10 @@ pub enum TexturePlacement {
|
||||
/// made it unbound and released it). Over pages imported as dma-bufs the image's making may
|
||||
/// still refuse at the bind, where the caller's source gives no one dma-buf of the pages
|
||||
/// ([`InPlaceRefusal::Source`]) or the driver refuses its import ([`InPlaceRefusal::DmaBuf`]):
|
||||
/// the texture is then a shadow, its notice (`shadowed-texture`) naming why.
|
||||
/// the texture is then a shadow, its notice (`shadowed-texture`) naming why. Over a copied host
|
||||
/// buffer ([`HostBacking::Copied`](crate::HostBacking::Copied)), the image lies over the copy
|
||||
/// the GPU uses in the pages' stead, in the copy's memory, where the check passed for that
|
||||
/// memory's kind and the pages' (`WorkCounts::copied_textures_in_place`).
|
||||
InPlace,
|
||||
/// A shadow now, as the device's check has not answered for the pages' kind and the
|
||||
/// texture's accesses: once it does, at the commit of the device's only uncommitted command
|
||||
@@ -189,8 +192,7 @@ pub enum InPlaceRefusal {
|
||||
Image,
|
||||
/// No image the device makes lays the rows (or slices) at the buffer's pitch.
|
||||
Pitch,
|
||||
/// The image's alignment, size or memory type misses the bytes' place, or the buffer's bytes
|
||||
/// are a copy of the caller's pages in memory of the device's own.
|
||||
/// The image's alignment, size or memory type misses the bytes' place.
|
||||
Placement,
|
||||
/// Over pages imported as dma-bufs: the caller's source made no one dma-buf of the texture's
|
||||
/// own pages.
|
||||
|
||||
@@ -385,6 +385,7 @@ pub(crate) struct Counters {
|
||||
device_copy_textures: AtomicU64,
|
||||
dma_buf_textures_in_place: AtomicU64,
|
||||
fresh_page_textures_in_place: AtomicU64,
|
||||
copied_textures_in_place: AtomicU64,
|
||||
pitched_host_images: AtomicU64,
|
||||
host_texture_shadows_exact: AtomicU64,
|
||||
host_texture_shadows_render_target: AtomicU64,
|
||||
@@ -3075,19 +3076,23 @@ impl Counters {
|
||||
}
|
||||
|
||||
/// A texture over host pages of `class` was made an image in place over them (`in_place.rs`),
|
||||
/// its rows at Metal's pitch in a `DRM_FORMAT_MOD_LINEAR` image made for host allocations
|
||||
/// where `pitched`.
|
||||
/// its rows at Metal's pitch in a `DRM_FORMAT_MOD_LINEAR` image where `pitched`; over a
|
||||
/// copied host buffer's copy of them where `copied` (`copied.rs`), whose class is the copy's
|
||||
/// memory's.
|
||||
pub(crate) fn host_texture_in_place(
|
||||
&self,
|
||||
class: crate::in_place::PagesClass,
|
||||
pitched: bool,
|
||||
written: bool,
|
||||
(pitched, written, copied): (bool, bool, bool),
|
||||
) {
|
||||
use crate::in_place::PagesClass as P;
|
||||
self.host_textures_in_place.fetch_add(1, Ordering::Relaxed);
|
||||
if written {
|
||||
(self.host_textures_in_place_written).fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
if copied {
|
||||
(self.copied_textures_in_place).fetch_add(1, Ordering::Relaxed);
|
||||
return;
|
||||
}
|
||||
match class {
|
||||
P::Pointer => {}
|
||||
P::DmaBuf => {
|
||||
@@ -6275,8 +6280,9 @@ pub struct WorkCounts {
|
||||
/// first move may write any byte bound to it.
|
||||
pub shadows_over_fresh_pages: u64,
|
||||
/// Textures over host pages (a no-copy buffer's, a no-copy heap's buffer's, or a buffer in
|
||||
/// fresh pages it imported) that sample, read, render or are written through a shader, made
|
||||
/// an image aliasing the pages in place, where the device's check passed for their class and
|
||||
/// fresh pages it imported; or a copied host buffer's copy of them, `copied_textures_in_place`)
|
||||
/// that sample, read, render or are written through a shader, made an image aliasing the pages
|
||||
/// in place, where the device's check passed for their class and
|
||||
/// each of their accesses (`HostPageTexturePolicy::InPlace`): no shadow, and no copy in or
|
||||
/// back. One that renders whose image took feedback loop usage is also counted in
|
||||
/// `feedback_loop_alias_images`.
|
||||
@@ -6298,6 +6304,12 @@ pub struct WorkCounts {
|
||||
pub dma_buf_textures_in_place: u64,
|
||||
/// Of `host_textures_in_place`, those over a buffer in fresh pages it imported.
|
||||
pub fresh_page_textures_in_place: u64,
|
||||
/// Of `host_textures_in_place`, those over a copied host buffer (`copied.rs`): an image over
|
||||
/// the copy of the caller's pages the GPU uses in their stead, bound in the copy's memory where
|
||||
/// the device's check passed for that memory's class (fresh pages the runtime imported, or its
|
||||
/// pooled memory) and for the caller's pages', for the texture's accesses. Counted in neither
|
||||
/// `fresh_page_textures_in_place` nor `pitched_host_images`.
|
||||
pub copied_textures_in_place: u64,
|
||||
/// Of `host_textures_in_place`, those whose rows lie at Metal's pitch in a
|
||||
/// `DRM_FORMAT_MOD_LINEAR` image made for host allocations, where the driver's own linear
|
||||
/// image lays them out otherwise.
|
||||
@@ -7678,6 +7690,7 @@ impl Device {
|
||||
fresh_page_textures_in_place: counters
|
||||
.fresh_page_textures_in_place
|
||||
.load(Ordering::Relaxed),
|
||||
copied_textures_in_place: counters.copied_textures_in_place.load(Ordering::Relaxed),
|
||||
pitched_host_images: counters.pitched_host_images.load(Ordering::Relaxed),
|
||||
host_texture_shadows_exact: counters.host_texture_shadows_exact.load(Ordering::Relaxed),
|
||||
host_texture_shadows_render_target: counters
|
||||
|
||||
@@ -2621,6 +2621,7 @@ field metal2vulkan-runtime::WorkCounts.copied_read_only_memory pub copied_read_o
|
||||
field metal2vulkan-runtime::WorkCounts.copied_rebind_images_made pub copied_rebind_images_made: u64
|
||||
field metal2vulkan-runtime::WorkCounts.copied_rebind_pages_made pub copied_rebind_pages_made: u64
|
||||
field metal2vulkan-runtime::WorkCounts.copied_rebind_pages_moved pub copied_rebind_pages_moved: u64
|
||||
field metal2vulkan-runtime::WorkCounts.copied_textures_in_place pub copied_textures_in_place: u64
|
||||
field metal2vulkan-runtime::WorkCounts.copied_unwritable_pages pub copied_unwritable_pages: u64
|
||||
field metal2vulkan-runtime::WorkCounts.copy_regions_split pub copy_regions_split: u64
|
||||
field metal2vulkan-runtime::WorkCounts.copy_sites pub copy_sites: [CopySite; 32]
|
||||
|
||||
|
Can't render this file because it is too large.
|
+1
-1
@@ -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 1, 2, 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 shader's writes of 1- or 2-byte texels apart from those of wider ones, which a driver may store through a wider access), 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 kernel's writes of a texture over a buffer's rows (no IOSurface plane's) whose rows, each to its pitch, start and end on a line, its buffer holding the last row to its pitch, take a verdict of their own from the same rounds, which a round that changed only bytes of its rows' padding (after a row's last texel, before its pitch, the last row's included) passes (`in_place::Padding`, `Access::BufferWrites`): Metal leaves those bytes to the GPU there (an Intel UHD Graphics 630 under macOS 26.7.1 wrote older values back over the CPU's writes to them under a kernel's writes of a texture over a buffer, the last row's included, where an M3 Max under macOS 27.0.1 and a Radeon Pro 5300M kept them, and all three kept them under draws, clears and stores and over IOSurfaces; `crates/metal2vulkan-conformance/probes/row_padding_writes.m`), and the rule follows the x86 Macs' envelope (docs/API.md, section 10, **Kernels**), so the Iris Xe's written textures over a buffer take the image in place whatever their rows' ends. 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`). A texture over a buffer of the runtime's pooled memory whose rows the device's own linear image lays out otherwise (a padded pitch the driver does not take: ANV lays linear rows tight; rows apart only over a buffer that declares them unobserved, `BufferDescriptor::padding_unobserved`) is, by the same rule, a `DRM_FORMAT_MOD_LINEAR` image at Metal's pitch bound in the buffer's memory where the device makes one (no external memory, which Vulkan allows: `VUID-VkImageCreateInfo-tiling-02261`, `VUID-vkBindImageMemory-image-01445`), made `UNDEFINED` (`VUID-VkImageCreateInfo-initialLayout-12478`), whose first move the check's pooled class judges (`PagesClass::Pooled`: a buffer of that memory, its images at Metal's pitch alone; `WorkCounts::pooled_pitched_images`); a texture made before that class's verdict is a shadow that moves to that image once the verdict passes, as one over host pages moves in place (below; `WorkCounts::pooled_textures_moved_in_place`, `pooled_texture_shadows_freed_after_move`). A texture that renders over a buffer that declares its padding unobserved, its rows each to its pitch sharing no line with bytes past them, takes the verdict of renders that lets a byte of its rows' padding change (`Access::UnobservedRenders`, `Padding::Unobserved`), which the renders' own rounds give as the writes' give theirs: the declaration lets a pass's load and store write those bytes (the Iris Xe's clear and store write back the 64-byte line that holds a row's last texels whole), and a byte past the last row's pitch, or a texel, fails it. 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 verLine truncated
|
||||
| A texture that samples, reads, renders into it or is written through a shader (`ShaderWrite` or `ShaderAtomic` usage, of texels of 1, 2, 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; or a copied host buffer's copy of them, `copied.rs`, its image bound in the copy's memory where the check passed for that memory and for the pages, `WorkCounts::copied_textures_in_place`) 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 shader's writes of 1- or 2-byte texels apart from those of wider ones, which a driver may store through a wider access), 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 kernel's writes of a texture over a buffer's rows (no IOSurface plane's) whose rows, each to its pitch, start and end on a line, its buffer holding the last row to its pitch, take a verdict of their own from the same rounds, which a round that changed only bytes of its rows' padding (after a row's last texel, before its pitch, the last row's included) passes (`in_place::Padding`, `Access::BufferWrites`): Metal leaves those bytes to the GPU there (an Intel UHD Graphics 630 under macOS 26.7.1 wrote older values back over the CPU's writes to them under a kernel's writes of a texture over a buffer, the last row's included, where an M3 Max under macOS 27.0.1 and a Radeon Pro 5300M kept them, and all three kept them under draws, clears and stores and over IOSurfaces; `crates/metal2vulkan-conformance/probes/row_padding_writes.m`), and the rule follows the x86 Macs' envelope (docs/API.md, section 10, **Kernels**), so the Iris Xe's written textures over a buffer take the image in place whatever their rows' ends. 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`). A texture over a buffer of the runtime's pooled memory whose rows the device's own linear image lays out otherwise (a padded pitch the driver does not take: ANV lays linear rows tight; rows apart only over a buffer that declares them unobserved, `BufferDescriptor::padding_unobserved`) is, by the same rule, a `DRM_FORMAT_MOD_LINEAR` image at Metal's pitch bound in the buffer's memory where the device makes one (no external memory, which Vulkan allows: `VUID-VkImageCreateInfo-tiling-02261`, `VUID-vkBindImageMemory-image-01445`), made `UNDEFINED` (`VUID-VkImageCreateInfo-initialLayout-12478`), whose first move the check's pooled class judges (`PagesClass::Pooled`: a buffer of that memory, its images at Metal's pitch alone; `WorkCounts::pooled_pitched_images`); a texture made before that class's verdict is a shadow that moves to that image once the verdict passes, as one over host pages moves in place (below; `WorkCounts::pooled_textures_moved_in_place`, `pooled_texture_shadows_freed_after_move`). A texture that renders over a buffer that declares its padding unobserved, its rows each to its pitch sharing no line with bytes past them, takes the verdict of renders that lets a byte of its rows' padding change (`Access::UnobservedRenders`, `Padding::Unobserved`), which the renders' own rounds give as the writes' give theirs: the declaration lets a pass's load and store write those bytes (the Iris Xe's clear and store write back the 64-byte line that holds a row's last texels whole), and a byte past the last row's pitch, or a texel, fails it. The check runs once pLine 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 |
|
||||
|
||||
+14
-4
@@ -469,7 +469,14 @@ the log reports written since the copy's last commit, and the bytes no log keeps
|
||||
publication (bounded) on the committing thread, and every copy compares every byte at its first
|
||||
commit and where a log answers `false`. The runtime reports to the log what the log cannot see: a
|
||||
copy's merge back, as the copy's own write, the GPU's writes into the pages through imports in
|
||||
place, and its own CPU writes into them. A texture over a copied buffer is a shadow of its bytes. The copy reads the pages through the kernel
|
||||
place, and its own CPU writes into them. A texture over a copied buffer is a linear image over the
|
||||
copy, bound in its memory, wherever the device's in-place check passed for that memory and for the
|
||||
caller's pages, for the texture's accesses (`copied_textures_in_place`): in fresh pages the runtime
|
||||
imported, an image made for host allocations, as over the pages; in memory the device allocates,
|
||||
the driver's own linear image where it lays the rows at the texture's pitch, which starts
|
||||
`PREINITIALIZED` and so keeps the copy's bytes, else a `DRM_FORMAT_MOD_LINEAR` image at that pitch
|
||||
under the check of the runtime's pooled memory. Elsewhere it is a shadow of the copy's bytes, its
|
||||
notice naming why. The copy reads the pages through the kernel
|
||||
first, and where the kernel cannot read them, with plain loads where the process maps every page
|
||||
with read permission: on Linux the kernel's read pins each page, which a mapping of a dma-buf
|
||||
(`VM_PFNMAP`) does not allow. Pages not mapped, or mapped
|
||||
@@ -498,12 +505,15 @@ the copy (`copied_rebind_images_made`): where an image in place rides on it, the
|
||||
pages the runtime maps and imports by pointer, and the image is made as over the caller's pages,
|
||||
under the device's in-place check for fresh pages; else the copy is memory the device allocates,
|
||||
and each image a linear image of it that starts `PREINITIALIZED`, so its first move keeps the
|
||||
copy's bytes. Textures held as shadows read the copy. A buffer's
|
||||
copy's bytes, or where the driver lays that image's rows at another pitch, a
|
||||
`DRM_FORMAT_MOD_LINEAR` image at the texture's pitch, under the check of the runtime's pooled
|
||||
memory. Textures held as shadows read the copy. A buffer's
|
||||
rebind to bytes at another offset in their page than the old, under a texture planned at the old
|
||||
offset, is a copy laid out at the old offset too, the gate unasked (`copied_rebind_pages_moved`).
|
||||
A rebind is refused (`NotImplemented(RebindTextures)`) only where the device makes no such image
|
||||
over the copy (its driver lays the linear image out at other pitches, or in memory of another type
|
||||
or alignment), or where the buffer's GPU writes are dropped and its bytes moved in their page.
|
||||
over the copy (its driver lays the linear image out at other pitches and makes no
|
||||
`DRM_FORMAT_MOD_LINEAR` image at the texture's pitch that the pooled memory's check passed, or
|
||||
either lies in memory of another type or alignment), or where the buffer's GPU writes are dropped and its bytes moved in their page.
|
||||
|
||||
### Guest RAM imported whole
|
||||
|
||||
|
||||
Reference in new issue
Block a user