fd blocks: opaque fd only, every image there the device's linear image, behind a cover check
RADV PHOENIX asks a dedicated allocation of a DRM_FORMAT_MOD_LINEAR image made for an opaque fd or a dma-buf (requiresDedicatedAllocation=1 for formats 9/16/37/44/64/97, m3-max-10880), and its image format query takes a dma-buf for no linear-tiling image: the dma-buf blocks of 6798cf39a2 held no texture at all (all 1824 in-place layouts of the placement test lost, m3-max-10884), and the FdBlocks check made nothing. The one image such a block can hold there is the device's linear image made for an opaque fd, and over a plain block's buffer no texture took a DRM_FORMAT_MOD_LINEAR image at Metal's pitch (0 of 1824 over 20736 layouts): the driver takes no explicit pitch but its own. So the blocks are exportable as an opaque fd again (FD_BLOCKS_HANDLE), every texture over such a buffer the linear image made for it, gated on the FdBlocks first-move verdict, and no pitched image there. Guards, from documented queries and made-and-released images, never a driver name: - memory::fd_image_types, at device assembly: per memory type of the system heap, kept where a 64x4 linear image made for an opaque fd (R8, RG8, RGBA8, RGBA16F; format query exportable and not dedicated-only first) takes it wherever the plain linear image does, and not asking a dedicated allocation; the memory log names the kept types and why the others stay plain. - Device::fd_blocks_cover (texture/fd_blocks_cover.rs), in the check's FdBlocks class: for every backed pixel format and the read, write and render usages, the opaque-fd linear image wherever the plain one is made, laid out the same (pitch, offset, size, alignment, types); and no DRM_FORMAT_MOD_LINEAR image of the device's own memory at a pitch other than its linear image's (probed at +256 and twice it). Else the class is unmade (lasting, so recorded), fd_blocks_take refuses, and the memory log says why. Removed: the dma-buf block path, Device::modifier_takes_linear, the probe-then-DRM linear slot, pooled_pitched_image's class parameter. CHECK_VERSION 16. Verified: nothing yet. (cherry picked from commit 0b59a1700f0911b1024f83ed3be30f99fb5e23d8)
This commit is contained in:
1 parent
4521956b6f
commit
005a54ea8d
10 files changed
+440
-226
No files matched your search
@@ -2132,19 +2132,19 @@ impl Device {
|
||||
(usage, handle),
|
||||
)
|
||||
};
|
||||
// The device's own buffers lie in blocks exportable as dma-bufs, never exported,
|
||||
// where it exports such a buffer of a pooled buffer's memory for the usage of those
|
||||
// buffers and of a buffer of addresses, makes images of a DRM format modifier (every
|
||||
// image bound there is a `DRM_FORMAT_MOD_LINEAR` one), and its policy takes textures
|
||||
// over memory of an export in place by its check (`memory.rs`'s "Buffers in
|
||||
// exportable blocks").
|
||||
// The device's own buffers lie in blocks exportable as opaque file descriptors,
|
||||
// never exported, where it exports such a descriptor of a pooled buffer's memory for
|
||||
// the usage of those buffers and of a buffer of addresses, and its policy takes
|
||||
// textures over memory of an export in place by its check; in the memory types its
|
||||
// linear image made for one takes as its own linear image does (`memory.rs`'s
|
||||
// "Buffers in exportable blocks").
|
||||
let in_place = compile.policy().host_page_textures
|
||||
== metal2vulkan::device::HostPageTexturePolicy::InPlace;
|
||||
let usages = [
|
||||
Some(super::buffer::usage(false)),
|
||||
device_address.then_some(usage),
|
||||
];
|
||||
// Whether the device exports each usage's pooled memory as a dma-buf.
|
||||
// Whether the device exports each usage's pooled memory as an opaque file descriptor.
|
||||
let pooled = |functions: &ash::khr::external_memory_fd::Device| {
|
||||
(usages.into_iter().flatten()).all(|usage| {
|
||||
// SAFETY: as above.
|
||||
@@ -2153,7 +2153,7 @@ impl Device {
|
||||
&instance.raw,
|
||||
physical,
|
||||
Some(functions.clone()),
|
||||
(usage, crate::buffer_descriptor::MemoryExport::DmaBuf),
|
||||
(usage, handle),
|
||||
)
|
||||
};
|
||||
export.is_some_and(|export| export.pooled())
|
||||
@@ -2164,21 +2164,32 @@ impl Device {
|
||||
Some(_) if !in_place => {
|
||||
Err("the device's policy shadows every texture over memory of an export")
|
||||
}
|
||||
Some(_) if !dma_buf || !dma_buf_images => Err(
|
||||
"the device enables no dma-buf export, or no image of a DRM format modifier, \
|
||||
which every image in such a block is",
|
||||
),
|
||||
Some(functions) if !pooled(functions) => Err(
|
||||
"the device exports a dma-buf of no pooled buffer's memory of the runtime's \
|
||||
usages",
|
||||
"the device exports an opaque file descriptor of no pooled buffer's memory of \
|
||||
the runtime's usages",
|
||||
),
|
||||
Some(_) => Ok(()),
|
||||
};
|
||||
memory.fd_buffer_blocks(crate::memory::fd_buffer_types(
|
||||
let types = crate::memory::fd_buffer_types(
|
||||
&memory_properties,
|
||||
properties.has_unified_memory,
|
||||
exports,
|
||||
));
|
||||
);
|
||||
let blocks = match types {
|
||||
// SAFETY: as above; the device enables `VK_KHR_external_memory_fd` where
|
||||
// `exports` passed.
|
||||
Ok(types) => match unsafe {
|
||||
crate::memory::fd_image_types((&instance.raw, physical), &raw, types)
|
||||
}? {
|
||||
(0, dropped) => (
|
||||
Err(dropped.map_or("no memory type takes such blocks", |(_, why)| why)),
|
||||
None,
|
||||
),
|
||||
(kept, dropped) => (Ok(kept), dropped),
|
||||
},
|
||||
Err(why) => (Err(why), None),
|
||||
};
|
||||
memory.fd_buffer_blocks(blocks);
|
||||
// As a dma-buf where it enables the route's extensions, which name
|
||||
// `VK_KHR_external_memory_fd`, and the foreign family its acquire names.
|
||||
let dma_buf_functions = functions.filter(|_| dma_buf && foreign_family);
|
||||
|
||||
@@ -88,18 +88,14 @@ use super::host_memory::{based_size, import_refused, not_importable, ImportWindo
|
||||
use super::host_residency::Again;
|
||||
use super::image_plan::{ImageFacts, ImagePlan};
|
||||
use super::in_place_check::Unmade;
|
||||
use super::linear_plan::{
|
||||
check_linear_limits, tiling_lack, viewed_formats, LinearLack, USAGE_FEATURES,
|
||||
};
|
||||
use super::linear_plan::{check_linear_limits, tiling_lack, viewed_formats, LinearLack};
|
||||
use super::memory::{self, ImportFailure, MemoryClass, Placement};
|
||||
use super::program_objects::ProgramObject;
|
||||
use super::Device;
|
||||
use crate::release;
|
||||
use ash::vk;
|
||||
use metal2vulkan::error::RuntimeDriverDefect;
|
||||
use metal2vulkan::vk::{
|
||||
Format, FormatFeatureFlags2, ImageCreateFlags, ImageUsageFlags, SampleCountFlags,
|
||||
};
|
||||
use metal2vulkan::vk::{Format, FormatFeatureFlags2, ImageCreateFlags, SampleCountFlags};
|
||||
use std::ops::Range;
|
||||
use std::os::fd::{AsFd, BorrowedFd, OwnedFd};
|
||||
use std::ptr::NonNull;
|
||||
@@ -1645,55 +1641,6 @@ impl Device {
|
||||
unsafe { crate::creation::image_or_refusal(shared.vk(), &info) }
|
||||
}
|
||||
|
||||
/// Whether a `DRM_FORMAT_MOD_LINEAR` image has, in every color format the runtime views a
|
||||
/// texture of any pixel format as (`ImageFacts::any_views`, of the sampled, storage and
|
||||
/// color attachment usages), each feature the runtime's usages rely on
|
||||
/// (`linear_plan::USAGE_FEATURES`) that both the format's linear and optimal tilings have:
|
||||
/// then such an image takes each usage of a texture over a buffer wherever the device's
|
||||
/// linear image takes it (`linear_plan::linear_lack` and `tiling_lack` ask the same of each
|
||||
/// tiling, a texture over a buffer having one level). Where the runtime's buffers' blocks are
|
||||
/// allocated exportable, every texture over such a buffer is such an image (`memory.rs`'s
|
||||
/// "Buffers in exportable blocks"), so its buffers lie there only where this holds
|
||||
/// (`in_place.rs`'s `Device::fd_blocks_checked`), and a texture over one never loses its place
|
||||
/// for a feature. Else the first format that lacks one, and what it lacks. Worked out at the
|
||||
/// first ask and kept (`TextureState::modifier_takes_linear`).
|
||||
pub(crate) fn modifier_takes_linear(&self) -> Result<(), String> {
|
||||
let shared = self.shared();
|
||||
let kept = shared.textures.modifier_takes_linear.get_or_init(|| {
|
||||
let profile = self.compile_device().profile();
|
||||
let facts = shared.textures.facts(profile);
|
||||
let relied = (USAGE_FEATURES.iter())
|
||||
.fold(FormatFeatureFlags2::empty(), |all, &(_, features)| {
|
||||
all.union(features)
|
||||
});
|
||||
let usages = [
|
||||
ImageUsageFlags::SAMPLED,
|
||||
ImageUsageFlags::STORAGE,
|
||||
ImageUsageFlags::COLOR_ATTACHMENT,
|
||||
];
|
||||
let formats: std::collections::BTreeSet<Format> = (usages.iter())
|
||||
.flat_map(|&usage| facts.any_views.of(usage, profile).iter().copied())
|
||||
.filter(|format| {
|
||||
!(format.block()).is_some_and(|b| b.depth.is_some() || b.stencil.is_some())
|
||||
})
|
||||
.collect();
|
||||
for format in formats {
|
||||
let linear = (facts.optimal(format))
|
||||
.intersection(facts.linear(format))
|
||||
.intersection(relied);
|
||||
let lacks = linear.difference(self.modifier_features(format));
|
||||
if !lacks.is_empty() {
|
||||
return Err(format!(
|
||||
"the DRM_FORMAT_MOD_LINEAR tiling of {format:?} lacks {lacks:?}, which its \
|
||||
linear and optimal tilings have for the runtime's usages"
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
kept.clone()
|
||||
}
|
||||
|
||||
/// The features of `format`'s `DRM_FORMAT_MOD_LINEAR` tiling where the device lists that
|
||||
/// modifier for it with one plane; none elsewhere. The 64-bit list
|
||||
/// (`VkDrmFormatModifierPropertiesList2EXT`) where the device has `format_feature_flags2`, as
|
||||
|
||||
@@ -115,11 +115,12 @@
|
||||
//! linear image is tried first, then the `DRM_FORMAT_MOD_LINEAR` one at Metal's pitch, whose
|
||||
//! own alignment decides.
|
||||
//! - **The runtime's buffers' exportable blocks.** Where the device allocates the blocks its
|
||||
//! buffers lie in exportable as dma-bufs and never exports them (`memory.rs`'s "Buffers in
|
||||
//! exportable blocks"), such a block holds no image of linear tiling, and a texture over such a
|
||||
//! buffer takes a `DRM_FORMAT_MOD_LINEAR` image made for that handle type, so starting
|
||||
//! `UNDEFINED`: of the device's linear image's layout where that lies on Metal's, else at
|
||||
//! Metal's pitch, under the check of such blocks ([`PagesClass::FdBlocks`]). Its
|
||||
//! buffers lie in exportable as opaque file descriptors and never exports them (`memory.rs`'s
|
||||
//! "Buffers in exportable blocks"), a texture over such a buffer takes the device's linear image
|
||||
//! made for that handle type, so starting `UNDEFINED`, under the check of such blocks
|
||||
//! ([`PagesClass::FdBlocks`]), and no `DRM_FORMAT_MOD_LINEAR` one. The class is made only
|
||||
//! where every image a texture over a plain block's buffer takes has that image over such a
|
||||
//! block (`texture.rs`'s `Device::fd_blocks_cover`), so elsewhere its verdicts are unchecked. Its
|
||||
//! verdicts decide, before any buffer lies there, whether the device's buffers do
|
||||
//! ([`fd_blocks_take`]): where every texture over such a buffer takes in place what it takes
|
||||
//! over a plain block's, whose linear image starts `PREINITIALIZED` and needs no verdict.
|
||||
@@ -196,11 +197,10 @@ pub(crate) enum PagesClass {
|
||||
ExportedDmaBuf,
|
||||
/// A buffer of the runtime's own in a block of the kind its buffers take where the device
|
||||
/// allocates their blocks exportable and never exports them (`memory.rs`'s
|
||||
/// `Holds::FdBuffers`, "Buffers in exportable blocks"): a `DRM_FORMAT_MOD_LINEAR` image made
|
||||
/// for the block's handle type, a dma-buf, of the device's linear image's layout where that
|
||||
/// lies on Metal's, else at Metal's pitch, bound in the buffer's memory (`texture.rs`'s
|
||||
/// `alias_image`). Either names that handle type (`VUID-vkBindImageMemory-memory-02728`), so
|
||||
/// it is made `UNDEFINED`
|
||||
/// `Holds::FdBuffers`, "Buffers in exportable blocks"): the device's linear image made for
|
||||
/// the block's handle type, an opaque file descriptor, bound in the buffer's memory
|
||||
/// (`texture.rs`'s `alias_image`). It names that handle type
|
||||
/// (`VUID-vkBindImageMemory-memory-02728`), so it is made `UNDEFINED`
|
||||
/// (`VUID-VkImageCreateInfo-pNext-01443`), and its first move leaves that layout. Its verdicts
|
||||
/// decide whether the device's buffers lie in such blocks at all
|
||||
/// ([`Device::fd_blocks_checked`]).
|
||||
@@ -993,14 +993,13 @@ pub(crate) enum FdBlocksTake {
|
||||
/// in place what it takes over a buffer of a plain block, whose blocks hold the same memory
|
||||
/// exported as no handle type. Over a plain block's buffer, the device's own linear image is
|
||||
/// made `PREINITIALIZED`, whose first move keeps its bytes, and needs no verdict; over an
|
||||
/// exportable block's, a `DRM_FORMAT_MOD_LINEAR` image of its layout takes its place, which names
|
||||
/// the block's handle type and so is made `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), its
|
||||
/// other operations a linear image's as well: so the class's verdict
|
||||
/// of that move ([`Access::Reads`]) must pass for texels of both row ends. A
|
||||
/// `DRM_FORMAT_MOD_LINEAR` image at Metal's pitch is made `UNDEFINED` in both, and takes each
|
||||
/// access its usage takes where its class passed: so every verdict of plain pooled memory
|
||||
/// ([`PagesClass::Pooled`]) that passed must pass for the class too. Pending where one of those
|
||||
/// is pending; else refused for the first access and row ends that did not pass.
|
||||
/// exportable block's, it names the block's handle type and so is made `UNDEFINED`
|
||||
/// (`VUID-VkImageCreateInfo-pNext-01443`), its other operations the same: so the class's verdict
|
||||
/// of that move ([`Access::Reads`]) must pass for texels of both row ends; and every access a
|
||||
/// texture over a plain block's buffer takes in place by the verdicts of plain pooled memory
|
||||
/// ([`PagesClass::Pooled`]) it must take over such a block's by the class's: so every verdict of
|
||||
/// the pooled class that passed must pass for the class too. Pending where one of those is
|
||||
/// pending; else refused for the first access and row ends that did not pass.
|
||||
pub(crate) fn fd_blocks_take(
|
||||
verdict: impl Fn(PagesClass, Access, RowEnds) -> Verdict,
|
||||
) -> FdBlocksTake {
|
||||
@@ -1039,7 +1038,7 @@ pub(crate) fn fd_blocks_take(
|
||||
/// 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 = 15;
|
||||
pub(crate) const CHECK_VERSION: u32 = 16;
|
||||
|
||||
/// A record's first bytes.
|
||||
const MAGIC: [u8; 8] = *b"M2VINPL\0";
|
||||
@@ -1262,18 +1261,11 @@ impl Device {
|
||||
}
|
||||
|
||||
/// Whether the runtime's own buffers lie in blocks allocated exportable (`memory.rs`'s
|
||||
/// "Buffers in exportable blocks"), by the device's `DRM_FORMAT_MOD_LINEAR` tiling, which
|
||||
/// every image there is (`dma_buf.rs`'s `Device::modifier_takes_linear`), and by its verdicts
|
||||
/// ([`fd_blocks_take`]), asked as such a buffer is made: a pending verdict starts the check,
|
||||
/// and the buffer lies in a plain block meanwhile, as it does where the tiling or the verdicts
|
||||
/// refuse such blocks; each counted (`WorkCounts::fd_blocks_awaited`,
|
||||
/// `WorkCounts::fd_blocks_refused`). Never waits.
|
||||
/// "Buffers in exportable blocks"), by the device's verdicts ([`fd_blocks_take`]), asked as
|
||||
/// such a buffer is made: a pending verdict starts the check, and the buffer lies in a plain
|
||||
/// block meanwhile, as it does where the verdicts refuse such blocks; each counted
|
||||
/// (`WorkCounts::fd_blocks_awaited`, `WorkCounts::fd_blocks_refused`). Never waits.
|
||||
pub(crate) fn fd_blocks_checked(&self) -> bool {
|
||||
#[cfg(unix)]
|
||||
if self.modifier_takes_linear().is_err() {
|
||||
self.shared().counts.fd_blocks_refused();
|
||||
return false;
|
||||
}
|
||||
let verdict = |class, access, rows| self.in_place_verdict(class, access, rows);
|
||||
match fd_blocks_take(verdict) {
|
||||
FdBlocksTake::Take => true,
|
||||
|
||||
@@ -1406,14 +1406,22 @@ impl ClassPages {
|
||||
// device allocates their blocks exportable (`memory.rs`'s `Holds::FdBuffers`), whatever
|
||||
// this class's verdicts, which decide whether they lie there
|
||||
// (`Device::fd_blocks_checked`), that declares the bytes between a texture's rows
|
||||
// unobserved, as the product's buffers whose textures take a `DRM_FORMAT_MOD_LINEAR`
|
||||
// image do: its textures take the images a texture over such a buffer takes
|
||||
// unobserved, as a consumer's caches do: its textures take the image a texture over
|
||||
// such a buffer takes, the device's linear image made for the blocks' handle type
|
||||
// (`texture.rs`'s `alias_image`).
|
||||
PagesClass::FdBlocks => {
|
||||
let exportable = lock(&device.shared().memory).fd_buffer_types;
|
||||
if let Err(why) = exportable {
|
||||
return Err(Unmade::lasting(why));
|
||||
}
|
||||
// Made only where such a block holds every image a texture over a plain block's
|
||||
// buffer takes in place (`texture/fd_blocks_cover.rs`), noted in the memory log.
|
||||
#[cfg(unix)]
|
||||
if let Err(why) = device.fd_blocks_cover() {
|
||||
let line = format!("the runtime's own buffers lie in plain blocks: {why}");
|
||||
lock(&device.shared().memory).note(line);
|
||||
return Err(Unmade::lasting(why));
|
||||
}
|
||||
let buffer = (device.pooled_check_buffer(length, Holds::FdBuffers))
|
||||
.map_err(|error| Unmade::of_error("its buffer was refused", &error))?;
|
||||
match buffer.bound_memory() {
|
||||
|
||||
@@ -1094,7 +1094,7 @@ fn plan_iosurface_plane(
|
||||
|
||||
/// The features of an image's tiling each of its usages relies on: what the runtime's views,
|
||||
/// samplers, attachments and copies of the texture may use.
|
||||
pub(super) const USAGE_FEATURES: [(ImageUsageFlags, FormatFeatureFlags2); 6] = [
|
||||
const USAGE_FEATURES: [(ImageUsageFlags, FormatFeatureFlags2); 6] = [
|
||||
(
|
||||
ImageUsageFlags::SAMPLED,
|
||||
FormatFeatureFlags2::SAMPLED_IMAGE
|
||||
|
||||
@@ -67,11 +67,11 @@
|
||||
//! - **Buffers in exportable blocks** ([`Holds::FdBuffers`], [`fd_buffer_types`]). On a device
|
||||
//! with unified memory whose policy takes textures over exported memory in place
|
||||
//! (`HostPageTexturePolicy::InPlace`) and whose memory types of a heap that is not device-local
|
||||
//! (the system heap, where `Private` memory lies first, [`candidates`]) export a dma-buf of a
|
||||
//! pooled buffer's memory (`vkGetPhysicalDeviceExternalBufferProperties`, for the program's
|
||||
//! buffers' usage and a buffer of addresses' usage: exportable, and not only from a dedicated
|
||||
//! allocation), and that enables `VK_EXT_image_drm_format_modifier`, the buffers the runtime's
|
||||
//! buffer path makes (`buffer.rs`'s `placed_new_buffer`: the program's, those of buffer
|
||||
//! (the system heap, where `Private` memory lies first, [`candidates`]) export an opaque file
|
||||
//! descriptor of a pooled buffer's memory (`vkGetPhysicalDeviceExternalBufferProperties`, for
|
||||
//! the program's buffers' usage and a buffer of addresses' usage: exportable, and not only from
|
||||
//! a dedicated allocation), and whose linear image made for one takes them as the device's own
|
||||
//! linear image does ([`fd_image_types`]), the buffers the runtime's buffer path makes (`buffer.rs`'s `placed_new_buffer`: the program's, those of buffer
|
||||
//! descriptors, and the runtime's own, not a heap's own buffer, a copied host buffer's copy nor
|
||||
//! the in-place check's buffer of plain pooled memory) are made with
|
||||
//! `VkExternalMemoryBufferCreateInfo` naming that handle type ([`FD_BLOCKS_HANDLE`]) and lie in
|
||||
@@ -80,13 +80,9 @@
|
||||
//! for it, as a buffer bound in such memory must name it
|
||||
//! (`VUID-vkBindBufferMemory-memory-02726`), and so is an image bound in it
|
||||
//! (`VUID-vkBindImageMemory-memory-02728`, [`BoundMemory::Blocks`]: `texture.rs`'s
|
||||
//! `alias_unbound`), which is so a `DRM_FORMAT_MOD_LINEAR` one: the handle types of such an
|
||||
//! allocation must be ones the image format query takes for each resource in it
|
||||
//! (`VUID-VkExportMemoryAllocateInfo-handleTypes-09860`), and RADV's takes a dma-buf for no
|
||||
//! image of linear tiling, and an opaque file descriptor for a `DRM_FORMAT_MOD_LINEAR` one only
|
||||
//! from a dedicated allocation (`VUID-VkMemoryAllocateInfo-pNext-00639`). Such an image starts
|
||||
//! `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`) where over a plain block's buffer the
|
||||
//! device's linear image starts `PREINITIALIZED`. So the buffers lie there only once the device's in-place
|
||||
//! `alias_unbound`), the device's linear image ([`FD_BLOCKS_HANDLE`] says why no other), which
|
||||
//! so starts `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`) where over a plain block's
|
||||
//! buffer it starts `PREINITIALIZED`. So the buffers lie there only once the device's in-place
|
||||
//! check of such blocks (`in_place.rs`'s `PagesClass::FdBlocks`) passed what a texture over one
|
||||
//! takes that it takes over a plain block's (`in_place.rs`'s `fd_blocks_take`): from the check's
|
||||
//! record as the device is made, else once its check answered, in plain blocks until then
|
||||
@@ -99,8 +95,7 @@
|
||||
//! blocks of the system heap held the scheduler's submissions about 9 ms each on a quiet host
|
||||
//! and up to 56 ms on one whose free memory lay in single pages, where memory allocated
|
||||
//! exportable as an opaque file descriptor is a buffer object of its own reservation, whose
|
||||
//! making held none, as memory exportable as a dma-buf is (`tests::reclaim_submit_bench`).
|
||||
//! Each such block held costs each
|
||||
//! making held none (`tests::reclaim_submit_bench`). Each such block held costs each
|
||||
//! submission about 1 us (`docs/FAST-PATHS.md`). Every other block of buffers, of images and of
|
||||
//! a heap is allocated as before.
|
||||
//!
|
||||
@@ -239,8 +234,8 @@ pub(super) enum MemoryClass {
|
||||
///
|
||||
/// A fifth, [`Holds::FdBuffers`], holds the buffers the runtime's buffer path makes on a device
|
||||
/// whose blocks of them in memory of a heap that is not device-local are allocated exportable as
|
||||
/// a dma-buf ([`FD_BLOCKS_HANDLE`]), never exported (the module docs, "Buffers in exportable
|
||||
/// blocks").
|
||||
/// an opaque file descriptor ([`FD_BLOCKS_HANDLE`]), never exported (the module docs, "Buffers
|
||||
/// in exportable blocks").
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum Holds {
|
||||
Buffers,
|
||||
@@ -312,6 +307,124 @@ pub(super) fn fd_buffer_types(
|
||||
}
|
||||
}
|
||||
|
||||
/// Of the memory types `types` (as bits) whose blocks of [`Holds::FdBuffers`] would be allocated
|
||||
/// exportable ([`fd_buffer_types`]), those a linear image made for [`FD_BLOCKS_HANDLE`] takes
|
||||
/// wherever the device's own linear image takes them, by `vkGetImageMemoryRequirements` of one
|
||||
/// of each of [`FD_IMAGE_FORMATS`] (a texture over a buffer in a type its image takes not lies
|
||||
/// in place: `texture.rs`'s `aliases`), made and destroyed, never bound; and the types dropped,
|
||||
/// with why. Every type is dropped where such an image asks a dedicated allocation. The device's
|
||||
/// check of such blocks covers every format a texture over a buffer may take (`texture.rs`'s
|
||||
/// `Device::fd_blocks_cover`).
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `physical` belongs to `instance`, created at Vulkan 1.2 or later, and `device` is its live
|
||||
/// device, which enables `VK_KHR_external_memory_fd`.
|
||||
pub(super) unsafe fn fd_image_types(
|
||||
(instance, physical): (&ash::Instance, vk::PhysicalDevice),
|
||||
device: &ash::Device,
|
||||
types: u32,
|
||||
) -> Result<(u32, Option<(u32, &'static str)>), Error> {
|
||||
let mut kept = types;
|
||||
for format in FD_IMAGE_FORMATS {
|
||||
let mut external =
|
||||
vk::PhysicalDeviceExternalImageFormatInfo::default().handle_type(FD_BLOCKS_HANDLE);
|
||||
let query = vk::PhysicalDeviceImageFormatInfo2::default()
|
||||
.format(format)
|
||||
.ty(vk::ImageType::TYPE_2D)
|
||||
.tiling(vk::ImageTiling::LINEAR)
|
||||
.usage(FD_IMAGE_USAGE)
|
||||
.push_next(&mut external);
|
||||
let mut answer = vk::ExternalImageFormatProperties::default();
|
||||
let mut properties = vk::ImageFormatProperties2::default().push_next(&mut answer);
|
||||
// SAFETY: the caller's; `query`, `properties` and their chains are valid.
|
||||
let result = unsafe {
|
||||
instance.get_physical_device_image_format_properties2(physical, &query, &mut properties)
|
||||
};
|
||||
let features = answer.external_memory_properties.external_memory_features;
|
||||
if result.is_err()
|
||||
|| !features.contains(vk::ExternalMemoryFeatureFlags::EXPORTABLE)
|
||||
|| features.contains(vk::ExternalMemoryFeatureFlags::DEDICATED_ONLY)
|
||||
{
|
||||
let why = "the device's image format query takes an opaque file descriptor for a \
|
||||
linear image of a common format only from a dedicated allocation, or not \
|
||||
at all";
|
||||
return Ok((0, Some((types, why))));
|
||||
}
|
||||
let [plain, exported] = [None, Some(FD_BLOCKS_HANDLE)]
|
||||
.map(|handle| linear_image_memory(device, format, handle));
|
||||
let ((plain, _), (exported, dedicated)) = (plain?, exported?);
|
||||
if dedicated {
|
||||
let why = "the device's linear image made for an opaque file descriptor asks a \
|
||||
dedicated allocation";
|
||||
return Ok((0, Some((types, why))));
|
||||
}
|
||||
kept &= exported | !plain;
|
||||
}
|
||||
let dropped = types & !kept;
|
||||
let why = "the device's linear image made for an opaque file descriptor takes none of them, \
|
||||
where its own linear image does";
|
||||
Ok((kept, (dropped != 0).then_some((dropped, why))))
|
||||
}
|
||||
|
||||
/// The formats [`fd_image_types`] makes a linear image of: one of each texel width a texture over
|
||||
/// a buffer commonly takes.
|
||||
const FD_IMAGE_FORMATS: [vk::Format; 4] = [
|
||||
vk::Format::R8_UNORM,
|
||||
vk::Format::R8G8_UNORM,
|
||||
vk::Format::R8G8B8A8_UNORM,
|
||||
vk::Format::R16G16B16A16_SFLOAT,
|
||||
];
|
||||
|
||||
/// The usage of [`fd_image_types`]' images: sampled and copied.
|
||||
const FD_IMAGE_USAGE: vk::ImageUsageFlags = vk::ImageUsageFlags::from_raw(
|
||||
vk::ImageUsageFlags::SAMPLED.as_raw()
|
||||
| vk::ImageUsageFlags::TRANSFER_SRC.as_raw()
|
||||
| vk::ImageUsageFlags::TRANSFER_DST.as_raw(),
|
||||
);
|
||||
|
||||
/// The memory types a 64x4 linear image of `format`, sampled and copied, made for `handle` where
|
||||
/// given, takes (as bits), and whether it asks a dedicated allocation: made and destroyed.
|
||||
fn linear_image_memory(
|
||||
device: &ash::Device,
|
||||
format: vk::Format,
|
||||
handle: Option<vk::ExternalMemoryHandleTypeFlags>,
|
||||
) -> Result<(u32, bool), Error> {
|
||||
let mut external =
|
||||
vk::ExternalMemoryImageCreateInfo::default().handle_types(handle.unwrap_or_default());
|
||||
let mut info = vk::ImageCreateInfo::default()
|
||||
.image_type(vk::ImageType::TYPE_2D)
|
||||
.format(format)
|
||||
.extent(vk::Extent3D {
|
||||
width: 64,
|
||||
height: 4,
|
||||
depth: 1,
|
||||
})
|
||||
.mip_levels(1)
|
||||
.array_layers(1)
|
||||
.samples(vk::SampleCountFlags::TYPE_1)
|
||||
.tiling(vk::ImageTiling::LINEAR)
|
||||
.usage(FD_IMAGE_USAGE)
|
||||
.initial_layout(vk::ImageLayout::UNDEFINED);
|
||||
if handle.is_some() {
|
||||
info = info.push_next(&mut external);
|
||||
}
|
||||
// SAFETY: the device is live and `info` valid: every Vulkan device makes linear images of
|
||||
// these formats, sampled and copied, and the caller asked the image format query for one made
|
||||
// for the handle type; the image is destroyed unbound.
|
||||
let image = unsafe { crate::creation::image(device, &info) }?;
|
||||
let mut dedicated = vk::MemoryDedicatedRequirements::default();
|
||||
let mut requirements = vk::MemoryRequirements2::default().push_next(&mut dedicated);
|
||||
let asked = vk::ImageMemoryRequirementsInfo2::default().image(image);
|
||||
// SAFETY: `image` is a live image of this device.
|
||||
unsafe {
|
||||
device.get_image_memory_requirements2(&asked, &mut requirements);
|
||||
crate::release::object(device, image);
|
||||
}
|
||||
let bits = requirements.memory_requirements.memory_type_bits;
|
||||
Ok((bits, dedicated.requires_dedicated_allocation != 0))
|
||||
}
|
||||
|
||||
/// What a new block's memory is allocated exportable as ([`BlockMaker::make_as`]).
|
||||
#[derive(Clone, Copy)]
|
||||
enum Exportable {
|
||||
@@ -349,12 +462,14 @@ pub(super) const DMA_BUF_HANDLE: vk::ExternalMemoryHandleTypeFlags =
|
||||
vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT;
|
||||
|
||||
/// The handle type the blocks of [`Holds::FdBuffers`] are allocated exportable as, never
|
||||
/// exported (the module docs, "Buffers in exportable blocks"): a dma-buf. Every image bound there
|
||||
/// is a `DRM_FORMAT_MOD_LINEAR` one, which RADV's image format query takes as a dma-buf from a
|
||||
/// block that buffers share, where it takes an opaque file descriptor for such an image only from
|
||||
/// a dedicated allocation (`VUID-VkMemoryAllocateInfo-pNext-00639`) and a dma-buf for no image of
|
||||
/// linear tiling (`VUID-VkExportMemoryAllocateInfo-handleTypes-09860`).
|
||||
pub(super) const FD_BLOCKS_HANDLE: vk::ExternalMemoryHandleTypeFlags = DMA_BUF_HANDLE;
|
||||
/// exported (the module docs, "Buffers in exportable blocks"): an opaque file descriptor, the one
|
||||
/// handle type for which RADV makes an image a texture over a buffer takes (the device's linear
|
||||
/// image) bound in a block that buffers share. Its image format query takes a dma-buf for no
|
||||
/// image of linear tiling, and an allocation's handle types must be supported for each resource
|
||||
/// in it (`VUID-VkExportMemoryAllocateInfo-handleTypes-09860`); and a `DRM_FORMAT_MOD_LINEAR`
|
||||
/// image made for either handle type asks a dedicated allocation
|
||||
/// (`VkMemoryDedicatedRequirements`).
|
||||
pub(super) const FD_BLOCKS_HANDLE: vk::ExternalMemoryHandleTypeFlags = EXPORT_HANDLE;
|
||||
|
||||
/// `VK_MEMORY_ALLOCATE_ZERO_INITIALIZE_BIT_EXT` (`VK_EXT_zero_initialize_device_memory`), which
|
||||
/// `ash 0.38` predates.
|
||||
@@ -1758,7 +1873,7 @@ impl AheadBlocks {
|
||||
/// The counts of the blocks of [`Holds::FdBuffers`] made so far.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub(super) struct FdBlocks {
|
||||
/// Allocated exportable as a dma-buf: of a memory type [`fd_buffer_types`]
|
||||
/// Allocated exportable as an opaque file descriptor: of a memory type [`fd_buffer_types`]
|
||||
/// names.
|
||||
pub(super) exportable: u64,
|
||||
/// Allocated as any block of buffers: of a memory type it does not name (device-local memory
|
||||
@@ -1851,16 +1966,24 @@ impl Memory {
|
||||
}
|
||||
|
||||
/// Allocate the blocks of [`Holds::FdBuffers`] of the memory types `types` names (as bits)
|
||||
/// exportable as [`FD_BLOCKS_HANDLE`] from now on, where it names any, else note why not (the
|
||||
/// memory log says which), as the device is made: `buffer.rs`'s `placed_new_buffer` then
|
||||
/// exportable as [`FD_BLOCKS_HANDLE`] from now on, where it names any, else note why not, and
|
||||
/// note the types `dropped` names that stay plain and why ([`fd_image_types`]; the memory log
|
||||
/// says which), as the device is made: `buffer.rs`'s `placed_new_buffer` then
|
||||
/// makes its buffers for that handle type and places them there once the device's check of
|
||||
/// such blocks passed ([`Memory::own_buffers`]).
|
||||
pub(super) fn fd_buffer_blocks(&mut self, types: Result<u32, &'static str>) {
|
||||
pub(super) fn fd_buffer_blocks(
|
||||
&mut self,
|
||||
(types, dropped): (Result<u32, &'static str>, Option<(u32, &'static str)>),
|
||||
) {
|
||||
if let Some(log) = &self.log {
|
||||
log.line(match types {
|
||||
Ok(types) => format!(
|
||||
"the runtime's own buffers lie in blocks of memory types {types:#x} exportable \
|
||||
as dma-bufs once the device's check of them passed"
|
||||
as opaque file descriptors once the device's check of them passed{}",
|
||||
match dropped {
|
||||
Some((dropped, why)) => format!("; types {dropped:#x} stay plain: {why}"),
|
||||
None => String::new(),
|
||||
}
|
||||
),
|
||||
Err(why) => format!("the runtime's own buffers lie in plain blocks: {why}"),
|
||||
});
|
||||
@@ -1879,6 +2002,13 @@ impl Memory {
|
||||
}
|
||||
}
|
||||
|
||||
/// Write `line` to the memory log, where the device keeps one.
|
||||
pub(super) fn note(&self, line: String) {
|
||||
if let Some(log) = &self.log {
|
||||
log.line(line);
|
||||
}
|
||||
}
|
||||
|
||||
/// The counts of the blocks of [`Holds::FdBuffers`] made so far.
|
||||
pub(super) fn fd_blocks(&self) -> FdBlocks {
|
||||
self.fd_blocks
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
//! device allocates its buffers' blocks exportable and the check passed them (`memory.rs`'s
|
||||
//! "Buffers in exportable blocks", `in_place.rs`'s `fd_blocks_take`), its memory is such a block
|
||||
//! (`WorkCounts::fd_buffer_blocks_made`), which the runtime never exports (`export_memory_fd`
|
||||
//! refuses it, `NotExportable`), and each plane is in place, its image a
|
||||
//! `DRM_FORMAT_MOD_LINEAR` one naming the block's handle type, a dma-buf, the layer reporting
|
||||
//! nothing (`VUID-VkExportMemoryAllocateInfo-handleTypes-09860` where the block's handle types
|
||||
//! take no image of linear tiling); elsewhere its memory is a plain block,
|
||||
//! refuses it, `NotExportable`), and each plane is in place, its image the device's linear
|
||||
//! image naming the block's handle type, an opaque file descriptor, the layer reporting nothing
|
||||
//! (`VUID-vkBindImageMemory-memory-02728`, `VUID-VkExportMemoryAllocateInfo-handleTypes-09860`);
|
||||
//! elsewhere its memory is a plain block,
|
||||
//! each plane in place or the shadow the check decided. Each reads the same bytes. A second
|
||||
//! device of the driver, its shader cache the first's, reads the verdicts from the check's
|
||||
//! record as it is made, and lays its first buffer where they say, none waiting for the check.
|
||||
@@ -783,8 +783,7 @@ fn an_nv12_picture_s_planes_over_a_buffer_of_the_runtime_s_own_name_its_block_s_
|
||||
{placement:?}"
|
||||
);
|
||||
// Where the buffers lie in such blocks, every plane is in place as over a plain
|
||||
// block's buffer: a DRM_FORMAT_MOD_LINEAR image the check passed, of the device's
|
||||
// linear image's layout or at Metal's pitch.
|
||||
// block's buffer: the device's linear image made for the blocks' handle type.
|
||||
if exportable {
|
||||
assert_eq!(
|
||||
placement,
|
||||
@@ -887,8 +886,8 @@ fn a_driver_s_second_device_lays_its_first_buffer_where_the_record_says() {
|
||||
/// offset 0 and at that answer, of `ShaderRead`, `ShaderRead | ShaderWrite` and
|
||||
/// `ShaderRead | RenderTarget` usage, a texture over a `Shared` buffer in such a block lies in place
|
||||
/// wherever one over a plain block's buffer of the same layout does (`Buffer::texture_placement`).
|
||||
/// Where the device lays its buffers in such blocks (`in_place.rs`'s `fd_blocks_take` and
|
||||
/// `dma_buf.rs`'s `Device::modifier_takes_linear`), a texture that loses its place fails; elsewhere
|
||||
/// Where the device lays its buffers in such blocks (`in_place.rs`'s `fd_blocks_take`, which
|
||||
/// `texture/fd_blocks_cover.rs` gates), a texture that loses its place fails; elsewhere
|
||||
/// the losses are printed, and those the images alone make, asked as the device's check asks them
|
||||
/// (its verdicts aside), with the notice of the first few such textures.
|
||||
///
|
||||
@@ -931,10 +930,10 @@ fn every_texture_in_place_over_a_plain_block_is_in_place_over_an_exportable_one(
|
||||
}
|
||||
let verdict = |class, access, rows| device.in_place_verdict(class, access, rows);
|
||||
let take = crate::in_place::fd_blocks_take(verdict);
|
||||
let covered = device.modifier_takes_linear();
|
||||
let covered = device.fd_blocks_cover();
|
||||
eprintln!(
|
||||
"EXPORTED-TEXTURES on {name}: the verdicts of exportable blocks: {take:?}; the \
|
||||
DRM_FORMAT_MOD_LINEAR tiling against the linear: {covered:?}"
|
||||
"EXPORTED-TEXTURES on {name}: the verdicts of exportable blocks: {take:?}; such a block \
|
||||
holds every image a plain one does: {covered:?}"
|
||||
);
|
||||
let length = 1 << 20;
|
||||
let plain = (device.pooled_check_buffer(length, Holds::Buffers)).unwrap();
|
||||
@@ -988,9 +987,8 @@ fn every_texture_in_place_over_a_plain_block_is_in_place_over_an_exportable_one(
|
||||
};
|
||||
let product = lost(&exportable);
|
||||
// Of the textures in place over a plain block's buffer, those whose image there is a
|
||||
// DRM_FORMAT_MOD_LINEAR one at Metal's pitch (`WorkCounts::pooled_pitched_images`), which
|
||||
// a block exportable as an opaque file descriptor alone would take only as a dedicated
|
||||
// allocation on a device whose image format query says so.
|
||||
// DRM_FORMAT_MOD_LINEAR one at Metal's pitch (`WorkCounts::pooled_pitched_images`), which an
|
||||
// exportable block takes none of.
|
||||
let mut pitched = Vec::new();
|
||||
for (at, (d, offset, row)) in layouts.iter().enumerate() {
|
||||
if !plain_at[at] {
|
||||
|
||||
@@ -156,6 +156,8 @@ mod attached_reads;
|
||||
mod attributes;
|
||||
pub(super) mod copy_images;
|
||||
pub(crate) mod decoded_twin;
|
||||
#[cfg(unix)]
|
||||
mod fd_blocks_cover;
|
||||
pub(crate) mod first_move;
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
mod first_move_lifetimes;
|
||||
@@ -233,10 +235,6 @@ pub(super) struct TextureState {
|
||||
/// per format at most.
|
||||
#[cfg(unix)]
|
||||
pub(super) modifier_features: Mutex<HashMap<Format, FormatFeatureFlags2>>,
|
||||
/// Whether a `DRM_FORMAT_MOD_LINEAR` image takes in every format what the device's linear
|
||||
/// image takes, worked out at the first ask (`dma_buf.rs`'s `modifier_takes_linear`).
|
||||
#[cfg(unix)]
|
||||
pub(super) modifier_takes_linear: std::sync::OnceLock<Result<(), String>>,
|
||||
/// Every pixel format's `minimumLinearTextureAlignmentForPixelFormat:` answer, worked out at
|
||||
/// the first query of any and kept for the device's life (`texture/linear_alignment.rs`).
|
||||
pub(super) linear_alignments: std::sync::OnceLock<HashMap<PixelFormat, u64>>,
|
||||
@@ -287,8 +285,6 @@ impl TextureState {
|
||||
format_answers: Mutex::new(HashMap::new()),
|
||||
#[cfg(unix)]
|
||||
modifier_features: Mutex::new(HashMap::new()),
|
||||
#[cfg(unix)]
|
||||
modifier_takes_linear: std::sync::OnceLock::new(),
|
||||
linear_alignments: std::sync::OnceLock::new(),
|
||||
heap_types: std::sync::OnceLock::new(),
|
||||
requirements: Mutex::new(requirements::RequirementAnswers::new(
|
||||
@@ -2913,16 +2909,14 @@ impl Device {
|
||||
/// meanwhile), and where the device's image format query takes the handle type for the
|
||||
/// image without a dedicated allocation. The check's own textures take them whatever the
|
||||
/// verdicts.
|
||||
/// - In a block of the runtime's buffers allocated exportable as a dma-buf and never exported
|
||||
/// (`memory.rs`'s "Buffers in exportable blocks"), which holds no image of linear tiling
|
||||
/// (`VUID-VkExportMemoryAllocateInfo-handleTypes-09860`): `DRM_FORMAT_MOD_LINEAR` images
|
||||
/// made for that handle type and so `UNDEFINED`, in the same two places. Where the device's
|
||||
/// linear image, made to be measured and never bound, lies on Metal's layout, one of its
|
||||
/// layout, as over a plain block's buffer, where the device's check of such blocks
|
||||
/// - In a block of the runtime's buffers allocated exportable as an opaque file descriptor and
|
||||
/// never exported (`memory.rs`'s "Buffers in exportable blocks"): the device's linear image
|
||||
/// made for that handle type, and so `UNDEFINED`, where the device's check of such blocks
|
||||
/// ([`PagesClass::FdBlocks`]) passed its first move for texels that lie in its lines as
|
||||
/// these do ([`Device::blocks_linear_image`]); else one at Metal's pitch where it passed
|
||||
/// each access the usage takes, as of plain pooled memory ([`Device::pooled_pitched_image`]).
|
||||
/// Both count as images at Metal's pitch (`WorkCounts::pooled_pitched_images`).
|
||||
/// these do ([`Device::blocks_linear_image`]); no `DRM_FORMAT_MOD_LINEAR` one, which such a
|
||||
/// block holds only where the device makes one for that handle type without a dedicated
|
||||
/// allocation, and the device's buffers lie there only where it makes no such image of its
|
||||
/// own memory either (`Device::fd_blocks_cover`).
|
||||
/// - In a buffer's dedicated allocation (an exportable buffer's where the driver exports
|
||||
/// such memory only so, or prefers or requires it), no image
|
||||
/// (`VUID-vkBindImageMemory-memory-10926`).
|
||||
@@ -3013,38 +3007,19 @@ impl Device {
|
||||
} else if let Some(LinearLack { format, features }) = linear_lack(plan, facts) {
|
||||
Err(LinearRefusal::Need(LinearNeed::Features { format, features }).describe(plan))
|
||||
} else {
|
||||
let made = match memory {
|
||||
ModifierMemory::Own => self.linear_image(plan)?,
|
||||
_ => self.external_linear_image(plan, memory)?,
|
||||
};
|
||||
made.map_err(|refusal| refusal.describe(plan))
|
||||
match (memory, blocks) {
|
||||
(_, true) => self.blocks_linear_image(plan, texels)?,
|
||||
(ModifierMemory::Own, false) => {
|
||||
(self.linear_image(plan)?).map_err(|refusal| refusal.describe(plan))
|
||||
}
|
||||
(_, false) => (self.external_linear_image(plan, memory)?)
|
||||
.map_err(|refusal| refusal.describe(plan)),
|
||||
}
|
||||
};
|
||||
let linear = match linear {
|
||||
Ok(made) => match (elsewhere(&made), blocks) {
|
||||
(None, false) => return Ok(Ok((made, false))),
|
||||
// A block allocated exportable as a dma-buf holds no image of linear tiling: the
|
||||
// device's linear image was made to be measured, and an image of its layout
|
||||
// takes its place there.
|
||||
(None, true) => {
|
||||
release_unbound(made);
|
||||
match self.blocks_linear_image(plan, texels, facts)? {
|
||||
Ok(made) => match elsewhere(&made) {
|
||||
None => return Ok(Ok((made, true))),
|
||||
Some(why) => {
|
||||
release_unbound(made);
|
||||
format!(
|
||||
"its DRM_FORMAT_MOD_LINEAR image of the device's linear \
|
||||
image's layout: {why}"
|
||||
)
|
||||
}
|
||||
},
|
||||
Err(why) => format!(
|
||||
"the device makes no DRM_FORMAT_MOD_LINEAR image of its linear \
|
||||
image's layout: {why}"
|
||||
),
|
||||
}
|
||||
}
|
||||
(Some(why), _) => {
|
||||
Ok(made) => match elsewhere(&made) {
|
||||
None => return Ok(Ok((made, false))),
|
||||
Some(why) => {
|
||||
release_unbound(made);
|
||||
format!("the device's linear image of the texture: {why}")
|
||||
}
|
||||
@@ -3052,16 +3027,14 @@ impl Device {
|
||||
Err(why) => format!("the device makes no linear image of the texture: {why}"),
|
||||
};
|
||||
let pitched = match (memory, blocks) {
|
||||
(_, true) => {
|
||||
let pooled = (
|
||||
PagesClass::FdBlocks,
|
||||
ModifierMemory::Exported(FD_BLOCKS_HANDLE),
|
||||
);
|
||||
self.pooled_pitched_image(plan, texels, usage, facts, pooled)?
|
||||
}
|
||||
(_, true) => Err(ShadowCause::Refused(
|
||||
Refusal::Pitch,
|
||||
"a block of the runtime's buffers allocated exportable takes no \
|
||||
DRM_FORMAT_MOD_LINEAR image at Metal's pitch"
|
||||
.to_owned(),
|
||||
)),
|
||||
(ModifierMemory::Own, false) => {
|
||||
let pooled = (PagesClass::Pooled, ModifierMemory::Own);
|
||||
self.pooled_pitched_image(plan, texels, usage, facts, pooled)?
|
||||
self.pooled_pitched_image(plan, texels, usage, facts)?
|
||||
}
|
||||
(_, false) => (self.pitched_image(plan, &texels.layout, facts, memory)?)
|
||||
.map_err(|(refusal, why)| ShadowCause::Refused(refusal, why)),
|
||||
@@ -3252,16 +3225,13 @@ impl Device {
|
||||
}
|
||||
|
||||
/// A `DRM_FORMAT_MOD_LINEAR` image of `plan` over `texels` in their buffer's pooled memory, its
|
||||
/// one plane at Metal's pitch (`VkImageDrmFormatModifierExplicitCreateInfoEXT`), made for
|
||||
/// `memory`: no external memory (`dma_buf::ModifierMemory::Own`) in a plain block, of class
|
||||
/// [`PagesClass::Pooled`], and the block's handle type in one allocated exportable, of class
|
||||
/// [`PagesClass::FdBlocks`] (`memory.rs`'s "Buffers in exportable blocks"); unbound and made
|
||||
/// `UNDEFINED`
|
||||
/// one plane at Metal's pitch (`VkImageDrmFormatModifierExplicitCreateInfoEXT`), no external
|
||||
/// memory (`dma_buf::ModifierMemory::Own`), unbound and made `UNDEFINED`
|
||||
/// (`Device::pitched_image`), for a texture of Metal `usage` whose texels the device's own
|
||||
/// linear image lays out otherwise: where the device makes such images, the texture's rows to
|
||||
/// their pitch take no more than `in_place::POOLED_PITCHED_BYTES` (past it, a linear image
|
||||
/// renders and samples slower than the shadow), and its policy and its check of `class` take
|
||||
/// each access the usage takes
|
||||
/// renders and samples slower than the shadow), and its policy and its check of the pooled
|
||||
/// class ([`PagesClass::Pooled`]) take each access the usage takes
|
||||
/// for texels that lie in its lines as these do (`in_place::in_place`; a pending verdict
|
||||
/// starts the check, and the texture is a shadow meanwhile); the check's own textures whatever
|
||||
/// the verdicts. Why not.
|
||||
@@ -3284,7 +3254,6 @@ impl Device {
|
||||
texels: &Texels,
|
||||
usage: TextureUsage,
|
||||
facts: &ImageFacts<'_>,
|
||||
(class, memory): (PagesClass, ModifierMemory),
|
||||
) -> Result<Result<LinearMade, ShadowCause>, Error> {
|
||||
if !self.makes_modifier_images() {
|
||||
return Ok(Err(ShadowCause::Refused(
|
||||
@@ -3306,7 +3275,7 @@ impl Device {
|
||||
}
|
||||
let line = self.shared().in_place.line();
|
||||
let pages = (
|
||||
class,
|
||||
PagesClass::Pooled,
|
||||
texels.rows(line),
|
||||
texels.texel_bytes(),
|
||||
texels.padding(line),
|
||||
@@ -3317,27 +3286,24 @@ impl Device {
|
||||
return Ok(Err(cause));
|
||||
}
|
||||
}
|
||||
let made = self.pitched_image(plan, &texels.layout, facts, memory)?;
|
||||
let own = crate::dma_buf::ModifierMemory::Own;
|
||||
let made = self.pitched_image(plan, &texels.layout, facts, own)?;
|
||||
Ok(made.map_err(|(refusal, why)| ShadowCause::Refused(refusal, why)))
|
||||
}
|
||||
|
||||
/// The image that takes the place of the device's linear image of `plan` over `texels`, whose
|
||||
/// layout lies on Metal's, in a block of the runtime's buffers allocated exportable as a
|
||||
/// dma-buf (`memory.rs`'s "Buffers in exportable blocks"), which holds no image of linear
|
||||
/// tiling (`VUID-VkExportMemoryAllocateInfo-handleTypes-09860`): a `DRM_FORMAT_MOD_LINEAR`
|
||||
/// image of that layout (Metal's pitch), unbound, made for that handle type, which an image
|
||||
/// bound there names (`VUID-vkBindImageMemory-memory-02728`), and so made `UNDEFINED`
|
||||
/// (`VUID-VkImageCreateInfo-pNext-01443`), where over a plain block's buffer the linear image
|
||||
/// starts `PREINITIALIZED`: where the device's check of such blocks ([`PagesClass::FdBlocks`])
|
||||
/// The device's linear image of `plan` over `texels` in a block of the runtime's buffers
|
||||
/// allocated exportable as an opaque file descriptor (`memory.rs`'s "Buffers in exportable
|
||||
/// blocks"), unbound, made for that handle type, which an image bound there names
|
||||
/// (`VUID-vkBindImageMemory-memory-02728`), and so made `UNDEFINED`
|
||||
/// (`VUID-VkImageCreateInfo-pNext-01443`), where over a plain block's buffer it starts
|
||||
/// `PREINITIALIZED`: where the device's check of such blocks ([`PagesClass::FdBlocks`])
|
||||
/// passed that move for texels that lie in its lines as these do, as it did wherever the
|
||||
/// device's buffers lie there (`in_place.rs`'s `fd_blocks_take`); the check's own textures
|
||||
/// whatever its verdicts. Its other operations are a linear image's, as over a plain block's
|
||||
/// buffer (the Glossary's Linear Resource). Why not.
|
||||
/// whatever its verdicts. Why not.
|
||||
fn blocks_linear_image(
|
||||
&self,
|
||||
plan: &ImagePlan,
|
||||
texels: &Texels,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Result<LinearMade, String>, Error> {
|
||||
if !in_place::checking() {
|
||||
let rows = texels.rows(self.shared().in_place.line());
|
||||
@@ -3352,8 +3318,8 @@ impl Device {
|
||||
}
|
||||
}
|
||||
let memory = ModifierMemory::Exported(FD_BLOCKS_HANDLE);
|
||||
let made = self.pitched_image(plan, &texels.layout, facts, memory)?;
|
||||
Ok(made.map_err(|(_, why)| why))
|
||||
let made = self.external_linear_image(plan, memory)?;
|
||||
Ok(made.map_err(|refusal| refusal.describe(plan)))
|
||||
}
|
||||
|
||||
/// The linear image of `plan` aliasing `texels` in their buffer's memory (the runtime's own),
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
//! Whether a block of the runtime's buffers allocated exportable as an opaque file descriptor
|
||||
//! holds every image a texture over a buffer takes in place over a plain block (`memory.rs`'s
|
||||
//! "Buffers in exportable blocks"): the device's check makes its class of such blocks
|
||||
//! (`in_place_check.rs`, `PagesClass::FdBlocks`) only where it does, so the device's buffers lie
|
||||
//! there only where no texture over one loses its place (`in_place.rs`'s `fd_blocks_take`).
|
||||
//!
|
||||
//! Over a plain block's buffer a texture takes the device's linear image, else a
|
||||
//! `DRM_FORMAT_MOD_LINEAR` one at Metal's pitch (`texture.rs`'s `alias_unbound`). Over such a
|
||||
//! block it takes the linear image made for the handle type alone. So the device's answers must
|
||||
//! give, for every pixel format a buffer backs and each usage a texture over a buffer reads,
|
||||
//! writes and renders through, a linear image made for the handle type wherever it makes its own,
|
||||
//! laid out as its own (row pitch, alignment, size) and taking each memory type its own takes of
|
||||
//! those the blocks are; and no `DRM_FORMAT_MOD_LINEAR` image of its own memory at a pitch other
|
||||
//! than its linear image's. Each image is made and released, never bound.
|
||||
|
||||
use crate::buffer_texture::texel_bytes;
|
||||
use crate::device::lock;
|
||||
use crate::dma_buf::ModifierMemory;
|
||||
use crate::error::Error;
|
||||
use crate::image_plan::plan_image;
|
||||
use crate::linear_plan::{linear_lack, BufferLayout};
|
||||
use crate::memory::FD_BLOCKS_HANDLE;
|
||||
use crate::texture::linear_alignment::backed_formats;
|
||||
use crate::texture_descriptor::{texture_usage, TextureLayout, TextureSwizzleChannels};
|
||||
use crate::{release, Device};
|
||||
use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage};
|
||||
|
||||
/// The width and height of each texture the cover is asked of.
|
||||
const EXTENT: [u32; 2] = [64, 4];
|
||||
|
||||
/// The usages each format is asked for: read, read and written, read and rendered to.
|
||||
const USAGES: [TextureUsage; 3] = [
|
||||
TextureUsage::SHADER_READ,
|
||||
TextureUsage::SHADER_READ.union(TextureUsage::SHADER_WRITE),
|
||||
TextureUsage::SHADER_READ.union(TextureUsage::RENDER_TARGET),
|
||||
];
|
||||
|
||||
/// The formats the `DRM_FORMAT_MOD_LINEAR` probe tries: one of each common texel width.
|
||||
const PITCHED: [PixelFormat; 3] = [
|
||||
PixelFormat::R8Unorm,
|
||||
PixelFormat::RGBA8Unorm,
|
||||
PixelFormat::RGBA16Float,
|
||||
];
|
||||
|
||||
impl Device {
|
||||
/// Whether a block of the runtime's buffers allocated exportable as an opaque file
|
||||
/// descriptor holds every image a texture over a buffer takes in place over a plain block
|
||||
/// (the module docs); else the first image it would lose, and why.
|
||||
pub(crate) fn fd_blocks_cover(&self) -> Result<(), String> {
|
||||
self.fd_blocks_cover_asked().unwrap_or_else(|error| {
|
||||
Err(format!(
|
||||
"the device's images were refused while its cover was asked: {error}"
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
/// [`fd_blocks_cover`](Self::fd_blocks_cover)'s answer, its images made and released.
|
||||
fn fd_blocks_cover_asked(&self) -> Result<Result<(), String>, Error> {
|
||||
let profile = self.compile_device().profile();
|
||||
let facts = self.shared().textures.facts(profile);
|
||||
let types = lock(&self.shared().memory).fd_buffer_types.unwrap_or(0);
|
||||
let raw_device = self.shared().vk();
|
||||
let exported = ModifierMemory::Exported(FD_BLOCKS_HANDLE);
|
||||
let plan_of = |pf, usage| {
|
||||
let layout = TextureLayout {
|
||||
texture_type: TextureType::Type2D,
|
||||
pixel_format: pf,
|
||||
extent: [EXTENT[0], EXTENT[1], 1],
|
||||
levels: 1,
|
||||
layers: 1,
|
||||
samples: 1,
|
||||
};
|
||||
let usage = texture_usage(usage, TextureSwizzleChannels::DEFAULT);
|
||||
plan_image(&layout, usage, false, &facts).ok()
|
||||
};
|
||||
for pf in backed_formats() {
|
||||
for usage in USAGES {
|
||||
let Some(plan) = plan_of(pf, usage) else {
|
||||
continue;
|
||||
};
|
||||
if linear_lack(&plan, &facts).is_some() {
|
||||
continue;
|
||||
}
|
||||
let Ok(own) = self.linear_image(&plan)? else {
|
||||
continue;
|
||||
};
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(raw_device, own.raw) };
|
||||
let theirs = match self.external_linear_image(&plan, exported)? {
|
||||
Ok(theirs) => theirs,
|
||||
Err(refusal) => {
|
||||
return Ok(Err(format!(
|
||||
"a texture of {pf:?} and {usage:?}: the device makes its own linear \
|
||||
image and none for an opaque file descriptor ({})",
|
||||
refusal.describe(&plan)
|
||||
)))
|
||||
}
|
||||
};
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(raw_device, theirs.raw) };
|
||||
let (mine, other) = (own.requirements, theirs.requirements);
|
||||
let typed = mine.memory_type_bits & types;
|
||||
let lies = theirs.report.row_pitch == own.report.row_pitch
|
||||
&& theirs.report.offset == own.report.offset
|
||||
&& theirs.report.size == own.report.size
|
||||
&& mine.alignment.is_multiple_of(other.alignment.max(1))
|
||||
&& other.size <= mine.size
|
||||
&& other.memory_type_bits & typed == typed;
|
||||
if !lies {
|
||||
return Ok(Err(format!(
|
||||
"a texture of {pf:?} and {usage:?}: the device's linear image for an \
|
||||
opaque file descriptor lies otherwise than its own (rows {} and {} \
|
||||
bytes apart, aligned to {} and {}, of types {:#x} and {:#x})",
|
||||
theirs.report.row_pitch,
|
||||
own.report.row_pitch,
|
||||
other.alignment,
|
||||
mine.alignment,
|
||||
other.memory_type_bits,
|
||||
mine.memory_type_bits
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if !self.makes_modifier_images() {
|
||||
return Ok(Ok(()));
|
||||
}
|
||||
for pf in PITCHED {
|
||||
let Some(plan) = plan_of(pf, TextureUsage::SHADER_READ) else {
|
||||
continue;
|
||||
};
|
||||
let Ok(own) = self.linear_image(&plan)? else {
|
||||
continue;
|
||||
};
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(raw_device, own.raw) };
|
||||
let pitch = own.report.row_pitch;
|
||||
let row_bytes = u64::from(EXTENT[0]) * texel_bytes(pf).unwrap_or(1);
|
||||
for row_pitch in [pitch + 256, pitch * 2] {
|
||||
let rows = u64::from(EXTENT[1]);
|
||||
let layout = BufferLayout {
|
||||
offset: 0,
|
||||
row_pitch,
|
||||
slice_pitch: row_pitch * rows,
|
||||
row_bytes,
|
||||
rows,
|
||||
slices: 1,
|
||||
};
|
||||
let own_memory = ModifierMemory::Own;
|
||||
if let Ok(made) = self.pitched_image(&plan, &layout, &facts, own_memory)? {
|
||||
// SAFETY: the image is live and unbound, and no command uses it.
|
||||
unsafe { release::object(raw_device, made.raw) };
|
||||
return Ok(Err(format!(
|
||||
"a texture of {pf:?} with rows {row_pitch} bytes apart: the device makes \
|
||||
a DRM_FORMAT_MOD_LINEAR image of its own memory at that pitch, where its \
|
||||
linear image's rows lie {pitch} apart, and such a block takes none"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Ok(()))
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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; or a copied host buffer's copy of them, `copied.rs`, its image bound in the copy's memory where the check passed for the pages, and for the copy's fresh pages or, for a `DRM_FORMAT_MOD_LINEAR` image in memory the device allocates, its pooled memory, `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 over a buffer whose memory the runtime exports (`exported_memory.rs`: a block that exportable buffers of one handle type share) is, by the same rule, the device's linear image or that `DRM_FORMAT_MOD_LINEAR` image made for the memory's handle type, which an image bound there must name (`VUID-vkBindImageMemory-memory-02728`), and so made `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), whose first move the check's exported classes judge, one per handle tyLine 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 the pages, and for the copy's fresh pages or, for a `DRM_FORMAT_MOD_LINEAR` image in memory the device allocates, its pooled memory, `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 over a buffer whose memory the runtime exports (`exported_memory.rs`: a block that exportable buffers of one handle type share) is, by the same rule, the device's linear image or that `DRM_FORMAT_MOD_LINEAR` image made for the memory's handle type, which an image bound there must name (`VUID-vkBindImageMemory-memory-02728`), and so made `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), whose first move the check's exported classes judge, one per handle tyLine 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`). No device's are taken as it, announced on every device: 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, and a driver's parallelograms (`strictLines` unset, `nonStrictWideLinesUseParallelogram` set), whose ends the driver places (RADV on the Radeon RX 7900 XTX draws 21 of `runtime_lane::line_widths`'s 48 scattered lines at width 2.5 a row or a column off Metal's at an end). 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 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), a rounded width, and a row or a column at an end (a driver's parallelograms). `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 |
|
||||
@@ -1011,9 +1011,9 @@ driver's. Each is open work.
|
||||
had taken 132 and 126 ms with the placements device-local; with unified memory the heaps keep
|
||||
one budget of an eighth of them all (the row above), which keeps every block: the later clips
|
||||
made none and took 122 and 119 ms. There the blocks of the runtime's buffers (the program's,
|
||||
those of buffer descriptors and its own; not a heap's) are allocated exportable as a dma-buf
|
||||
and never exported (`memory.rs`'s "Buffers in exportable blocks"), every image over one a
|
||||
`DRM_FORMAT_MOD_LINEAR` one, where the device makes such images, its policy takes textures in
|
||||
those of buffer descriptors and its own; not a heap's) are allocated exportable as an opaque
|
||||
file descriptor and never exported (`memory.rs`'s "Buffers in exportable blocks"), every image
|
||||
over one the device's linear image made for it, where its policy takes textures in
|
||||
place by its check and that check of such blocks gave every texture over one what it takes
|
||||
over a plain block's buffer (`in_place::fd_blocks_take`, the in-place row above; plain blocks
|
||||
until it answered, `WorkCounts::fd_blocks_awaited`): on a Radeon 780M (RADV PHOENIX, Mesa
|
||||
|
||||
Reference in new issue
Block a user