From a508b327deb6fc7534dafa14198f3dc07c57f9b8 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 7 Nov 2026 18:25:17 -0800 Subject: [PATCH] Zero-initialized images: an enables test, API.md's runtime-own extensions, the signature table Enables::enable_zero_initialize_device_memory gets the test each runtime-own enable has (tests/enables.rs: the structure, of the registry's type 1000620000, is chained only once enabled, its member TRUE, the extension's name after host image copy's). docs/API.md's paragraph of what the runtime enables for itself outside the vocabulary names VK_EXT_zero_initialize_device_memory and when. api_signatures.tsv gains WorkCounts::images_started_zeroed (scripts/api-signatures, --bless). Not yet built; the next gem10 build runs it. (cherry picked from commit 2ec9061a61c7262e7a05b4e42f0e1122518439cf) --- .../metal2vulkan-runtime/src/tests/enables.rs | 51 ++++++++++++++++++- crates/metal2vulkan/tests/api_signatures.tsv | 1 + docs/API.md | 6 ++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/enables.rs b/crates/metal2vulkan-runtime/src/tests/enables.rs index 08d991a14..c008a7369 100644 --- a/crates/metal2vulkan-runtime/src/tests/enables.rs +++ b/crates/metal2vulkan-runtime/src/tests/enables.rs @@ -1,6 +1,6 @@ use crate::enables::{ - host_image_copy_names, linear_color_attachment_names, names_of, Enables, Promotion, CORE_1_3, - MEMBERS, + host_image_copy_names, linear_color_attachment_names, names_of, Enables, Promotion, + ZeroInitializeDeviceMemoryFeatures, CORE_1_3, MEMBERS, }; use crate::error::{Error, RuntimeGap}; use ash::vk; @@ -472,6 +472,53 @@ fn linear_color_attachment_is_enabled_in_its_own_structure() { assert_eq!(read(&mut enables), (Some(vk::TRUE), names)); } +/// The runtime's own `zeroInitializeDeviceMemory` is set in its own structure, of the registry's +/// structure type, chained into the create info only once enabled, with +/// `VK_EXT_zero_initialize_device_memory` after host image copy's names. +#[test] +fn zero_initialize_device_memory_is_enabled_in_its_own_structure() { + let read = |enables: &mut Enables| { + enables.with_create_info(&[], |info| { + let mut member = None; + let mut next = info.p_next.cast::(); + while !next.is_null() { + // SAFETY: every structure of the chain lives for the call, and each begins with + // `sType` and `pNext`. + let base = unsafe { &*next }; + if base.s_type + == ::STRUCTURE_TYPE + { + // SAFETY: a structure of this type is the zero initialize features'. + let zero = unsafe { &*next.cast::() }; + member = Some(zero.zero_initialize_device_memory); + } + next = base.p_next; + } + let names: Vec = (0..info.enabled_extension_count as usize) + // SAFETY: the create info's names are its count of live C strings. + .map(|i| unsafe { CStr::from_ptr(*info.pp_enabled_extension_names.add(i)) }) + .map(CStr::to_owned) + .collect(); + (member, names) + }) + }; + // The registry's `VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_DEVICE_MEMORY_FEATURES_EXT`. + assert_eq!( + ::STRUCTURE_TYPE.as_raw(), + 1_000_620_000 + ); + let api = ApiVersion::V1_3; + let mut enables = Enables::of(&EnableSet::new(), api, &BTreeSet::new(), &[]).unwrap(); + assert_eq!(read(&mut enables), (None, Vec::new())); + enables.enable_host_image_copy(host_image_copy_names(api)); + enables.enable_zero_initialize_device_memory(); + let names = vec![ + c"VK_EXT_host_image_copy".to_owned(), + c"VK_EXT_zero_initialize_device_memory".to_owned(), + ]; + assert_eq!(read(&mut enables), (Some(vk::TRUE), names)); +} + /// A caller's extension whose feature structure the runtime knows (`VK_KHR_`/`VK_EXT_swapchain_ /// maintenance1`, `VK_KHR_`/`VK_EXT_present_mode_fifo_latest_ready`) takes its structure, once /// for both names, chained with every feature set where the device has them; a device without diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index d1291764c..1ac61a1fb 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2816,6 +2816,7 @@ field metal2vulkan-runtime::WorkCounts.host_textures_moved_in_place pub host_tex field metal2vulkan-runtime::WorkCounts.idle_submits pub idle_submits: u64 field metal2vulkan-runtime::WorkCounts.image_blits_recorded pub image_blits_recorded: u64 field metal2vulkan-runtime::WorkCounts.images_started_on_the_host pub images_started_on_the_host: u64 +field metal2vulkan-runtime::WorkCounts.images_started_zeroed pub images_started_zeroed: u64 field metal2vulkan-runtime::WorkCounts.in_place_checks_failed pub in_place_checks_failed: u64 field metal2vulkan-runtime::WorkCounts.in_place_checks_passed pub in_place_checks_passed: u64 field metal2vulkan-runtime::WorkCounts.in_place_checks_recalled pub in_place_checks_recalled: u64 diff --git a/docs/API.md b/docs/API.md index c4d01380b..42adeac4d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -308,7 +308,11 @@ the device refuses (`HostMemory::with_dma_buf`), `VK_EXT_external_memory_dma_buf `VK_EXT_queue_family_foreign` beside them, wherever a device lists them, and `VK_EXT_pageable_device_local_memory` with `VK_EXT_memory_priority`, where a device lists both and has `pageableDeviceLocalMemory`: its driver may then move device-local memory to host-local memory -to make room rather than fail an allocation, every allocation at the default priority. +to make room rather than fail an allocation, every allocation at the default priority; and +`VK_EXT_zero_initialize_device_memory`, where a device the runtime made lists it, has +`zeroInitializeDeviceMemory` and copies textures on the host: a `Shared` or `Managed` texture's +image that copies on the host then starts in memory of its own the driver zeroed, with no write of +the host's (`WorkCounts::images_started_zeroed`). A texture over host pages is one over a no-copy buffer's (imported by their pointer or as dma-bufs), or over a host-visible buffer of the runtime's own longer than 32 MiB where the device