From 0a894e85fe9e5b32954ec5e12e55bdf54e730004 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 18 Nov 2026 02:11:22 -0800 Subject: [PATCH] rt arrays tests: set 1's arrays fill past their capacity through one grant of each class The index arrays had no fill-past-capacity test. On every device of the cfg's kind, one grant of the sampler class's whole range takes a sampler state at each of its 3,999 indices, and one grant of the storage-capable class's whole range takes a 1x1 shader-write texture at each of its 4,095. Then 128 of each are dropped one at a time and made again at the index they left, as a consumer reuses an index: 4,127 sampler states and 4,223 storage-capable textures in all. Every make is unwrapped, so an index refused as in use fails the test. The descriptor-slot gauge counts the class's capacity while the arrays are full and the reuse runs, is zero once the objects are gone, and the grants are released; after the device, the sampler, texture and descriptor-slot gauges are zero. Verified: the next job runs it on lavapipe, then on um790's GPUs from the archives. --- crates/metal2vulkan-rt/src/tests/arrays.rs | 88 +++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/crates/metal2vulkan-rt/src/tests/arrays.rs b/crates/metal2vulkan-rt/src/tests/arrays.rs index ff17687ee..b47a59fc3 100644 --- a/crates/metal2vulkan-rt/src/tests/arrays.rs +++ b/crates/metal2vulkan-rt/src/tests/arrays.rs @@ -9,7 +9,11 @@ //! set 1 its default at creation, and holds two `VkSampler`s for it; grants work through the //! device; `Device::new`, and making and destroying a second set 1, are timed and reported, //! and the second set's two samplers are gone after it; every device supports both of the -//! runtime's set layouts, which `Device::new` asks before it makes them. +//! runtime's set layouts, which `Device::new` asks before it makes them; and the arrays fill +//! past their capacity through one grant of each class, the samplers' and the storage-capable +//! textures': every index of the class takes an object, and objects dropped one at a time give +//! their index to the next, more than 4,000 sampler states and 4,096 storage-capable textures +//! in all, none refused as in use, the descriptor-slot gauge back to zero after them. use crate::arrays::Grants; use crate::error::{Error, Limit, Refusal}; @@ -110,10 +114,90 @@ mod on_device { use super::refusal; use crate::arrays::{supported, with_arrays_layout, Arrays, BINDINGS}; use crate::tests::devices_of_the_cfgs_kind; - use crate::{Device, DeviceOptions, IndexClass, Instance, Refusal}; + use crate::{ + Device, DeviceOptions, IndexClass, Instance, PixelFormat, Refusal, SamplerDescriptor, + StorageMode, TextureDescriptor, TextureType, TextureUsage, + }; use ash::vk; + use std::ops::Range; use std::time::Instant; + /// How many objects of each class are made again at an index another left, past the + /// class's capacity. + const AGAIN: u32 = 128; + + /// One object `make` makes at every index of `class`, through one grant of the class's + /// whole range, then [`AGAIN`] of them each dropped and made again at the index it left, as a + /// consumer reuses an index: the descriptor-slot gauge counts the class's capacity while the + /// arrays are full, and is zero once the objects are gone and the grant is released. + fn fill_past_capacity( + name: &str, + device: &Device, + class: IndexClass, + make: impl Fn(u32) -> T, + ) { + let counters = device.counters(); + let Range { start, end } = class.range(); + let grant = (device.grant_indices(class, start, end - start)) + .unwrap_or_else(|error| panic!("{name}: {class:?}: {error}")); + let mut live: Vec> = (start..end).map(|index| Some(make(index))).collect(); + let full = u64::from(end - start); + assert_eq!( + counters.gauges().descriptor_slots, + full, + "{name}: {class:?}" + ); + for (object, index) in live.iter_mut().zip(start..start + AGAIN) { + drop(object.take()); + *object = Some(make(index)); + } + assert_eq!( + counters.gauges().descriptor_slots, + full, + "{name}: {class:?}" + ); + drop(live); + assert_eq!(counters.gauges().descriptor_slots, 0, "{name}: {class:?}"); + (device.release_indices(grant)).unwrap_or_else(|error| panic!("{name}: {error}")); + } + + /// Set 1's arrays filled past their capacity: 3,999 sampler states and 128 more, 4,095 + /// storage-capable textures and 128 more, through one grant of each class. Every make is + /// unwrapped, so an index refused as in use (`Refusal::IndexInUse`) fails the test. + #[test] + fn every_device_fills_set_1_past_its_capacity() { + let instance = Instance::new(&[]).expect("an instance at the floor"); + let devices = devices_of_the_cfgs_kind(&instance); + assert!( + !devices.is_empty(), + "the loader lists no device of this cfg's kind" + ); + for (name, physical) in devices { + let device = Device::new(&physical, DeviceOptions::default()) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let counters = device.counters(); + let sampler = SamplerDescriptor::new(); + fill_past_capacity(&name, &device, IndexClass::Sampler, |index| { + (device.new_sampler_state(&sampler, index)) + .unwrap_or_else(|error| panic!("{name}: sampler {index}: {error}")) + }); + let mut d = TextureDescriptor::new(TextureType::Type2D, PixelFormat::RGBA8Unorm, 1, 1); + d.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; + d.storage_mode = StorageMode::Private; + fill_past_capacity(&name, &device, IndexClass::StorageTexture, |index| { + (device.new_texture(&d, Some(index))) + .unwrap_or_else(|error| panic!("{name}: texture {index}: {error}")) + }); + drop(device); + let gauges = counters.gauges(); + assert_eq!( + (gauges.samplers, gauges.textures, gauges.descriptor_slots), + (0, 0, 0), + "{name}" + ); + } + } + /// The floor's last item, asked of the created device: every device of the cfg's kind /// supports both of the runtime's set layouts (`vkGetDescriptorSetLayoutSupport`), the empty /// set 0 and set 1 of the arrays, which `Device::new` asks before it makes them.