From 0c166a0d098d197ebdfc5ee9be6b2e02c6558f70 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 8 Nov 2026 20:05:13 -0800 Subject: [PATCH] fd blocks: clippy fixes; reclaim bench: dual-handle arms, compatible types, plane formats and the check's verdicts Clippy (m3-max-10619) found an unused accessor (the test now reads Memory's field), a closure for bool::then, and a test variable that shadowed the descriptor helper. The bench gains arms whose memory is exportable as both an opaque fd and a dma-buf (make, held 64, two queues), the external facts print compatibleHandleTypes and cover the two-plane 4:2:0 formats the YCbCr planes image takes, and print the in-place check's verdicts once settled. Verified: not yet built. (cherry picked from commit acca6b48661251f20f9625d74f86cb2e5ce0e2cf) --- crates/metal2vulkan-runtime/src/device/mod.rs | 2 +- crates/metal2vulkan-runtime/src/memory.rs | 8 +- .../src/tests/exported_textures.rs | 6 +- .../src/tests/reclaim_submit_bench.rs | 93 ++++++++++++++----- 4 files changed, 77 insertions(+), 32 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/device/mod.rs b/crates/metal2vulkan-runtime/src/device/mod.rs index 9ec8176b9..d72f6cf2e 100644 --- a/crates/metal2vulkan-runtime/src/device/mod.rs +++ b/crates/metal2vulkan-runtime/src/device/mod.rs @@ -2141,7 +2141,7 @@ impl Device { Some(_) => { let usages = [ Some(super::buffer::usage(false)), - device_address.then(|| usage), + device_address.then_some(usage), ]; let pooled = usages.into_iter().flatten().all(|usage| { // SAFETY: as above. diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs index e7658d938..ce73655c9 100644 --- a/crates/metal2vulkan-runtime/src/memory.rs +++ b/crates/metal2vulkan-runtime/src/memory.rs @@ -1611,7 +1611,7 @@ pub(super) struct Memory { fd_address_types: Option, /// The memory types whose [`Holds::FdBuffers`] blocks are allocated exportable, as bits, or /// why none are ([`fd_buffer_types`]). - fd_buffer_types: Result, + pub(super) fd_buffer_types: Result, fd_blocks: FdBlocks, /// The pools the runtime's encodings and commits place their own resources in, once asked /// ([`Memory::kept`], [`keep_room`]). @@ -1836,12 +1836,6 @@ impl Memory { self.fd_buffer_types = types; } - /// The memory types whose [`Holds::FdBuffers`] blocks are allocated exportable, as bits, or - /// why none are. - pub(super) fn fd_buffer_types(&self) -> Result { - self.fd_buffer_types - } - /// The kind of block the buffers `buffer.rs`'s `placed_new_buffer` makes for the program and /// for the runtime take: [`Holds::FdBuffers`] where the device allocates any of them /// exportable ([`Memory::fd_buffer_blocks`]), else [`Holds::Buffers`]. diff --git a/crates/metal2vulkan-runtime/src/tests/exported_textures.rs b/crates/metal2vulkan-runtime/src/tests/exported_textures.rs index 2a2944678..46c119df1 100644 --- a/crates/metal2vulkan-runtime/src/tests/exported_textures.rs +++ b/crates/metal2vulkan-runtime/src/tests/exported_textures.rs @@ -694,14 +694,14 @@ fn an_nv12_picture_s_planes_over_a_buffer_of_the_runtime_s_own_name_its_block_s_ let scratch = Scratch::new("own-buffer-textures"); let device = device(&watched, &scratch.0); let name = device.name().to_owned(); - let types = crate::device::lock(&device.shared().memory).fd_buffer_types(); + let types = crate::device::lock(&device.shared().memory).fd_buffer_types; eprintln!("EXPORTED-TEXTURES on {name}: the blocks of the runtime's own buffers: {types:?}"); let mut first = true; for options in [ResourceOptions::private(), ResourceOptions::shared()] { - let descriptor = BufferDescriptor::new(LENGTH, options, BufferContents::Zero) + let made = BufferDescriptor::new(LENGTH, options, BufferContents::Zero) .with_aligned_byte(LUMA_AT) .with_padding_unobserved(); - let picture = device.new_buffer_with_descriptor(descriptor).unwrap(); + let picture = device.new_buffer_with_descriptor(made).unwrap(); let (bound, counts) = (picture.bound_memory(), device.work_counts()); match types { Ok(_) => { diff --git a/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs b/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs index 45687a430..e2d5b8d52 100644 --- a/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs +++ b/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs @@ -36,37 +36,42 @@ //! memory type that is host-visible and host-coherent but not device-local or cached (where a //! unified-memory device's `Private` blocks lie, `memory.rs`, `candidates`), of 64 MiB every //! [`RAW_EVERY`] or of 4 MiB sixteen times as often, [`RAW_BYTES`] a phase. -//! - **System heap, 64 MiB, exportable** and **System heap, 64 MiB, opaque fd**: the system -//! heap's 64 MiB allocations, each exportable (`VkExportMemoryAllocateInfo`) as a dma-buf or as -//! an opaque file descriptor. +//! - **System heap, 64 MiB, exportable**, **System heap, 64 MiB, opaque fd** and **System heap, +//! 64 MiB, both**: the system heap's 64 MiB allocations, each exportable +//! (`VkExportMemoryAllocateInfo`) as a dma-buf, as an opaque file descriptor, or as both. //! - **Carve-out, 64 MiB**: the same of the first device-local memory type that is not //! host-visible. //! - **Made before**: [`HELD_BUFFERS`] `Private` buffers of [`RUNTIME_BUFFER_BYTES`] made before //! the quiet phase, and nothing made in the phases. -//! - **Exportable, held 32**, **Exportable, held 64** and **Opaque fd, held 64**: that many of -//! the system heap's 64 MiB allocations, each exportable as a dma-buf or as an opaque file -//! descriptor, made before the quiet phase, and nothing made in the phases: what holding memory +//! - **Exportable, held 32**, **Exportable, held 64**, **Opaque fd, held 64** and **Both, held +//! 64**: that many of the system heap's 64 MiB allocations, each exportable as a dma-buf, as an +//! opaque file descriptor or as both, made before the quiet phase, and nothing made in the phases: what holding memory //! that is not private to the device's process costs each submission. //! - **Nothing made**: the copies' buffers alone. //! -//! Three arms ask instead whether memory allocated exportable holds one queue's work behind +//! Four arms ask instead whether memory allocated exportable holds one queue's work behind //! another's, as memory that synchronizes implicitly would: **Two queues, private**, **Two -//! queues, exportable** and **Two queues, opaque fd** each allocate [`TWO_QUEUE_BYTES`] of the -//! system heap, as a plain allocation or exportable as a dma-buf or an opaque file descriptor, -//! and bind three buffers in it, each made for that handle -//! type where the memory is exportable (`VUID-vkBindBufferMemory-memory-02726`). For -//! [`TWO_QUEUE_ROUNDS`] rounds, a second queue fills the first buffer [`LONG_FILLS`] times, and a millisecond later a command queue's `VkQueue` (lent, +//! queues, exportable**, **Two queues, opaque fd** and **Two queues, both** each allocate +//! [`TWO_QUEUE_BYTES`] of the system heap, as a plain allocation or exportable as a dma-buf, an +//! opaque file descriptor or both, and bind three buffers in it, each made for those handle +//! types where the memory is exportable (`VUID-vkBindBufferMemory-memory-02726`). For +//! [`TWO_QUEUE_ROUNDS`] rounds, a second queue (one the device reserved for the caller, else a +//! compute queue it made beside its own) fills the first buffer [`LONG_FILLS`] times, and a +//! millisecond later a command queue's `VkQueue` (lent, //! `CommandQueue::with_vk_queue`) copies [`COPY_BYTES`] from the second into the third, each //! waited for by its fence: printed, the fills' and the copies' times from submission to their //! fence, and the rounds whose copy completed while the fills ran. Copies held behind the fills //! take as long as the fills' rest, and complete after them. //! -//! **Export facts** prints, for each of those handle types, what the device answers for the -//! runtime's buffers (`vkGetPhysicalDeviceExternalBufferProperties`, of a buffer of the runtime's -//! usage with and without the device-address usage) and for linear and `DRM_FORMAT_MOD_LINEAR` -//! images of [`FACT_FORMATS`] that are sampled and copied, and rendered to +//! **Export facts** prints, for a dma-buf and an opaque file descriptor, what the device answers +//! for the runtime's buffers (`vkGetPhysicalDeviceExternalBufferProperties`, of a buffer of the +//! runtime's usage with and without the device-address usage), for linear and +//! `DRM_FORMAT_MOD_LINEAR` images of [`FACT_FORMATS`] that are sampled and copied, and rendered +//! to, and for sampled images of [`PLANE_FORMATS`] (as `texture/ycbcr_planes.rs` makes them) //! (`vkGetPhysicalDeviceImageFormatProperties2` with `VkPhysicalDeviceExternalImageFormatInfo`): -//! the result, and whether such memory is exportable and only as a dedicated allocation. +//! the result, whether such memory is exportable and only as a dedicated allocation, and the +//! handle types it is compatible with; then the device's in-place check's verdicts for each +//! class, access and row ends, once it settled. //! //! Printed (`RECLAIM-SUBMIT`), per arm and phase: the submissions; for `commit_and_submit` and for //! the turnaround each, those of 8 ms or more and of 17 ms or more, the median, 99th percentile and @@ -99,6 +104,7 @@ const WAIT: Duration = Duration::from_secs(60); type Handle = vk::ExternalMemoryHandleTypeFlags; const DMA_BUF: Handle = vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT; const OPAQUE_FD: Handle = vk::ExternalMemoryHandleTypeFlags::OPAQUE_FD; +const BOTH: Handle = OPAQUE_FD.union(DMA_BUF); const PAGE: u64 = 4096; const MIB: u64 = 1 << 20; const GIB: u64 = 1 << 30; @@ -143,6 +149,11 @@ const FACT_FORMATS: [vk::Format; 6] = [ vk::Format::A2B10G10R10_UNORM_PACK32, vk::Format::R16G16B16A16_SFLOAT, ]; +/// The formats of a two-plane 4:2:0 video surface's image (`texture/ycbcr_planes.rs`). +const PLANE_FORMATS: [vk::Format; 2] = [ + vk::Format::G8_B8R8_2PLANE_420_UNORM, + vk::Format::G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16, +]; /// The two-queue arms' allocation, the bytes of its first buffer, which the second queue /// fills, the fills in each of its command buffers, and the rounds. const TWO_QUEUE_BYTES: u64 = 128 * MIB; @@ -838,9 +849,10 @@ fn reclaim_submit_bench_export_facts() { let features = |properties: vk::ExternalMemoryProperties| { let features = properties.external_memory_features; format!( - "exportable {}, dedicated only {}", + "exportable {}, dedicated only {}, compatible {:#x}", features.contains(F::EXPORTABLE), - features.contains(F::DEDICATED_ONLY) + features.contains(F::DEDICATED_ONLY), + properties.compatible_handle_types.as_raw() ) }; for (name, handle) in [("dma-buf", DMA_BUF), ("opaque fd", OPAQUE_FD)] { @@ -864,7 +876,11 @@ fn reclaim_submit_bench_export_facts() { ); } let copied = I::SAMPLED | I::TRANSFER_SRC | I::TRANSFER_DST; - for format in FACT_FORMATS { + let images = (FACT_FORMATS.iter()).flat_map(|&format| { + [copied, copied | I::COLOR_ATTACHMENT].map(|usage| (format, usage)) + }); + let planes = PLANE_FORMATS.map(|format| (format, I::SAMPLED)); + for (format, usage) in images.chain(planes) { for (tiling, tiling_name) in [ (vk::ImageTiling::LINEAR, "linear"), ( @@ -872,7 +888,7 @@ fn reclaim_submit_bench_export_facts() { "DRM_FORMAT_MOD_LINEAR", ), ] { - for usage in [copied, copied | I::COLOR_ATTACHMENT] { + { let mut external = vk::PhysicalDeviceExternalImageFormatInfo::default().handle_type(handle); let mut modifier = vk::PhysicalDeviceImageDrmFormatModifierInfoEXT::default() @@ -913,6 +929,17 @@ fn reclaim_submit_bench_export_facts() { } } } + let settled = device.settle_in_place_checks(WAIT); + for class in crate::in_place::PagesClass::ALL { + for access in crate::in_place::Access::ALL { + let verdicts = (crate::in_place::RowEnds::ALL) + .map(|rows| (rows, device.in_place_verdict(class, access, rows))); + eprintln!( + "RECLAIM-SUBMIT export facts, the in-place check (settled {settled}): {class:?} \ + {access:?}: {verdicts:?}" + ); + } + } } #[test] @@ -933,6 +960,12 @@ fn reclaim_submit_bench_two_queues_opaque_fd() { two_queues("two queues, opaque fd", Some(OPAQUE_FD)); } +#[test] +#[ignore = "a measurement of the GPU's queues: run alone on its host by name"] +fn reclaim_submit_bench_two_queues_both() { + two_queues("two queues, both", Some(BOTH)); +} + #[test] #[ignore = "a measurement that presses the host's memory: run alone on its host by name"] fn reclaim_submit_bench_runtime() { @@ -987,6 +1020,18 @@ fn reclaim_submit_bench_system_heap_64mib_opaque_fd() { ); } +#[test] +#[ignore = "a measurement that presses the host's memory: run alone on its host by name"] +fn reclaim_submit_bench_system_heap_64mib_both() { + arm( + "system heap, 64 MiB, both", + Arm::SystemHeap { + bytes: 64 * MIB, + export: Some(BOTH), + }, + ); +} + #[test] #[ignore = "a measurement that presses the host's memory: run alone on its host by name"] fn reclaim_submit_bench_carve_out_64mib() { @@ -1017,6 +1062,12 @@ fn reclaim_submit_bench_opaque_fd_held_64() { arm("opaque fd, held 64", Arm::ExportableHeld(64, OPAQUE_FD)); } +#[test] +#[ignore = "a measurement that presses the host's memory: run alone on its host by name"] +fn reclaim_submit_bench_both_held_64() { + arm("both, held 64", Arm::ExportableHeld(64, BOTH)); +} + #[test] #[ignore = "a measurement that presses the host's memory: run alone on its host by name"] fn reclaim_submit_bench_nothing_made() {