From 5bde7c16ed4b2d8175674d7e1cd08a2caeb64946 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 25 Nov 2026 11:40:23 -0800 Subject: [PATCH] Tests: the small-level device test's textures take indices; place() asks is_multiple_of What: every_device_copies_a_level_smaller_than_a_block_at_the_block_s_size makes its textures ShaderRead, and the runtime gives a ShaderRead texture an index, so the test now takes a grant of 64 texture indices (19 textures a format) and hands each texture its own. place()'s whole-block test reads `size.is_multiple_of(grid)`. Why: job m3-max-73723 (the quick check of 1549e2e3a3) failed two ways. Clippy, in all three configurations, flagged `size[axis] % grid == 0` as a manual is_multiple_of. On lavapipe the device test stopped at its first texture: "a texture shaders read or write, or a colour render target, takes an index, and none was given". The other 737 runtime tests passed there, the unit tests of small_levels among them. Verified: not yet; the next quick check runs at this commit's successor. --- .../src/tests/small_levels.rs | 15 ++++++++++++--- crates/metal2vulkan-runtime/src/texture.rs | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/small_levels.rs b/crates/metal2vulkan-runtime/src/tests/small_levels.rs index 3515bc7be..49be44f45 100644 --- a/crates/metal2vulkan-runtime/src/tests/small_levels.rs +++ b/crates/metal2vulkan-runtime/src/tests/small_levels.rs @@ -190,9 +190,10 @@ mod on_device { use crate::tests::command::on_device::{each_device, finished}; use crate::{ BlitCommandEncoder, Block, Buffer, BufferLayout, CommandBuffer, CommandQueue, Device, - Error, Gap, HostBytes, MemoryClass, PixelFormat, Region, StorageMode, Texture, + Error, Gap, HostBytes, IndexClass, MemoryClass, PixelFormat, Region, StorageMode, Texture, TextureDescriptor, TexturePlace, TextureType, TextureUsage, }; + use std::cell::Cell; /// The levels each case fills and reads back: 8 (8 x 4 texels), 9 (4 x 2), 10 (2 x 1) and 11 /// (1 x 1). @@ -247,6 +248,8 @@ mod on_device { block: &'a Block, format: PixelFormat, unit: usize, + /// The next texture index of the run's grant. + next: &'a Cell, } impl Run<'_> { @@ -255,7 +258,8 @@ mod on_device { d.mipmap_level_count = 12; d.usage = TextureUsage::SHADER_READ; d.storage_mode = storage_mode; - (self.device.new_texture(&d, None)) + let index = self.next.replace(self.next.get() + 1); + (self.device.new_texture(&d, Some(index))) .unwrap_or_else(|error| panic!("{}: {error}", self.name)) } @@ -441,13 +445,17 @@ mod on_device { each_device("small_levels", |name, _, device| { let queue = device.new_command_queue(4).expect("a queue"); let block = (device.take_block(MemoryClass::Shared, 4096)).expect("a Shared block"); + // The textures, 19 a format, take an index each from one grant. + let _grant = (device.grant_indices(IndexClass::Texture, 1, 64)).expect("indices"); + let next = Cell::new(1); for (format, unit, label) in [ (PixelFormat::BC1RGBA, 8, "bc1"), (PixelFormat::BC3RGBA, 16, "bc3"), ] { let mut d = TextureDescriptor::new(TextureType::Type2D, format, 2048, 1024); d.mipmap_level_count = 12; - match device.new_texture(&d, None) { + d.usage = TextureUsage::SHADER_READ; + match device.new_texture(&d, Some(next.replace(next.get() + 1))) { Ok(_) => {} Err(Error::Unsupported(Gap::TextureFormat { .. })) => { println!("{name}: no {format:?} texture on this device"); @@ -462,6 +470,7 @@ mod on_device { block: &block, format, unit, + next: &next, }; let size = [4, 4, 1]; for level in 9..=11 { diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index be10505db..47e087586 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -3621,7 +3621,7 @@ pub(crate) fn place( for axis in 0..3 { let (origin, edge, grid) = (region.origin[axis], extent[axis], block[axis]); let end = origin.checked_add(size[axis]).ok_or_else(outside)?; - let whole = size[axis] % grid == 0; + let whole = size[axis].is_multiple_of(grid); let on_grid = origin % grid == 0 && (whole || end == edge); // Whole blocks may end in the level's last block past its edge, where the edge is no // whole blocks: the block it rounds up to.