From 0307fb8c9de32b0ae584f2c2ea84d9f8133465eb Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 14 Oct 2026 13:47:38 +0300 Subject: [PATCH] Run every Linux CI step in the gate's container, and fix what the gate caught The Linux gate's work packet: CI's Linux steps now run in the gate's own container, and the failures that run found are fixed: depth and stencil formats over a DRM_FORMAT_MOD_LINEAR image, test IR that LLVM 21 rejects, and a frame-cost check that allocated. Run every Linux step of ci.yml in the Linux gate's container: What: scripts/linux-gate-ci gains the three steps ci.yml's Linux job runs and it did not: "Clippy under each feature alone" (metal2vulkan with no feature and with serde, ash and cli each alone; metal2vulkan-runtime; metal2vulkan-air with no feature and with serde), "Build the new API's consumer reference" (scripts/api-docs) and "Package the published crates". Its "Test metal2vulkan" step now tests the packages ci.yml's does (metal2vulkan, -air, -runtime and -devtools), where it tested metal2vulkan alone. The steps run in ci.yml's order, each with the container's build share. Why: the script's header says every Linux run: step of ci.yml has one step here, and docs/VALIDATION.md presents the container as ci.yml's Linux job; a change that broke only a feature-alone build, the reference, packaging, or the AIR front end's, runtime's or dev tools' tests passed the container and failed CI. Verified: bash -n; the steps compared one by one with ci.yml at fd22785008. A full container run of the script follows on msi-laptop. Make no DRM_FORMAT_MOD_LINEAR image of a depth or stencil format: What: Device::modifier_image_checks, which every DRM_FORMAT_MOD_LINEAR image the runtime makes passes (host_pitched_image's at Metal's row pitch over host pages since 1cf79a9617, and dma_buf_image's and dma_buf_natural_layout's over dma-buf pages since 11715e2a3f), refuses a format with a depth or stencil component (FormatBlock::depth / ::stencil of the image's format). Such a texture takes the shadow (`shadowed-texture`, naming why), as it already did on every driver that lists no linear modifier for the format. RUNTIME_VERSION 1187; the runtime-sources pin moves with it. docs/API.md (the dma-buf paragraph and the shadowed-texture notice), docs/HOWTO.md and Degradation::ShadowedTexture's rustdoc say so. Why: the runtime asks the layout of every such image of memory plane 0, and Vulkan has no valid such query of a depth or stencil format. Vulkan 1.4.357's validusage.json: of a DRM format modifier's tiling the aspect "must be VK_IMAGE_ASPECT_MEMORY_PLANE_i_BIT_EXT" (VUID-vkGetImageSubresourceLayout-tiling-09433), of a format with a depth component it "must contain VK_IMAGE_ASPECT_DEPTH_BIT" (-format-04462; stencil, -format-04463), and it "must only have a single bit set" (-aspectMask-00997). lavapipe (Mesa 26.2.4) lists the linear modifier for D16_UNORM, D32_SFLOAT and D32_SFLOAT_S8_UINT, so since 1cf79a9617 a depth or stencil texture over a no-copy buffer's surface plane was made at Metal's row pitch and the validation layer reported -format-04462/-04463, failing CI's CPU-ICD step: runtime_lane::buffer_texture_blits::a_planar_surface_s_depth_or_stencil_texture_reads_and_stores_the_plane and ..._s_passes_write_metal_s_elements_alone. The dma-buf paths had the same gap, reached only where a driver refuses the host pointer and lists the modifier for such a format. Test: runtime_lane::buffer_texture_blits::no_depth_or_stencil_texture_over_a_buffer_asks_for_a_modifier_image makes each depth or stencil format's texture over a surface plane (ordinary and no-copy buffers, read and render usage, rows 64 and 256 bytes apart) and checks that WorkCounts' pitched_host_images, pitched_host_image_refusals and dma_buf_images do not move (each layout query follows such an image), and that the validation layer reports nothing. Verified on msi-laptop, lavapipe (llvmpipe, LLVM 23.1.1, 256 bits; Mesa 26.2.4, validation layer 1.4.357), --cfg m2v_cpu_icd, LP_NUM_THREADS=1, VK_DRIVER_FILES=lvp_icd.json: without the modifier_image_checks change the new test fails ("NoCopy Depth16Unorm MTLTextureUsageShaderRead, rows 64 bytes apart": (1, 0, 0) against (0, 0, 0)) beside the old one; with it, every test of runtime_lane::{buffer_texture_blits, no_copy_textures, dma_buf_imports, surface_texture_costs, pitched_surfaces} passes (47 of 49 selected) except pitched_surfaces::a_half_float_tile_reads_writes_and_renders_as_metal, the known-open lavapipe padding-bytes failure 1cf79a9617 names (fleet/fix-pitched owns it), and the runtime-sources pin, which printed the hash written here. Write the handle tests' sample coordinates as floats LLVM 21 reads: What: tests::engine_handles' sampled-handle kernels (the 2D and 3D sample calls of heap_gathers_and_nearest_samples_fetch_by_the_handle_s_class, heap_half_texels_convert_by_the_handle_s_class and heap_linear_samples_are_emulated_by_the_handle_s_class) state their coordinates as the hex of the floats they meant, 0x3FD3333340000000, 0x3FE3333340000000 and 0x3FDCCCCCC0000000, in place of the decimals 0.3, 0.6 and 0.45. Why: LLVM 21's llvm-as, which CI's Linux job (Ubuntu 26.04) assembles with, refuses a float decimal that is not exactly a float ("floating point constant invalid for type"), so the three tests failed there; LLVM 23 rounds it to the nearest float, which is the value the hex states (checked on msi-laptop: `ret float 0.3` under llvm-as 23 and `ret float 0x3FD3333340000000` under llvm-as 21 disassemble alike), so the modules are unchanged where they assembled before. These were the only float or half decimals in crates/ that a float does not hold exactly (a scan of every .rs and .ll). Verified on msi-laptop with /opt/llvm-21.1.8 first on PATH and METAL2VULKAN_TEST_REQUIRE_PINNED_LLVM=1, as CI runs: the three tests failed at fd22785008 and pass here. Check a stage table brought in place slot by slot, allocating nothing: What: the debug builds' check in ArgumentTable::refresh_reading, that the table it brought in place is the table the stage's function reads whole, is ArgumentTable::check_reading. It compares slot by slot, with no table read whole made and nothing printed unless a slot differs: every kept buffer, texture and sampler slot against the binding stage_table_reading would derive for it (and the sampler as the address maps bind it), every slot that reading has against the kept table, and the kept threadgroup lengths and acceleration structures against none. A sampler is compared as it prints (same_as_printed: every field by `==`, the LOD clamps as bits or both NaN, since `{:?}` tells -0.0 from 0.0 and prints every NaN alike). A slot that differs is named in the panic. Builds without debug assertions compile none of it: their behaviour is unchanged, so RUNTIME_VERSION stays; the runtime-sources pin moves. Why: the check read the whole table again and compared the two as format!("{:?}") strings at every draw, so a debug build's draw made several times the allocations of a release build's, and CI's CPU-ICD step (a debug build) failed runtime_lane::frame_costs::a_frame_s_draws_and_pass_ends_allocate_within_their_bounds at every sha since its bound came: 86.60 allocations a draw on lavapipe against the bound's 27, where the same build with CARGO_PROFILE_DEV_DEBUG_ASSERTIONS=false makes 24.62. With this, a debug build's draw makes 35.93; the rest of the difference is LiveBind::shape's checks, which build whole bind shapes and stay exact (the next part bounds a debug draw with them). Tests: tests::argument_table::samplers_compare_as_they_print holds same_as_printed equal to comparing the printed forms (opposite zero signs, NaNs of other sign and payload, a NaN against a number, f32::MAX against infinity, and other fields); the_check_compares_every_field fails when StageTable, BoundSampler or SamplerDescriptor gains a field, until the check compares it. Verified on msi-laptop (Linux, debug, LLVM 21): clippy --workspace --all-targets --all-features -D warnings clean; the two unit tests pass; on lavapipe (--cfg m2v_cpu_icd), the frame_costs draws count 35.93 (86.60 before) and runtime_lane::{render_state, function_tables, buffer_texture_blits}, whose draws run the check, pass (32 tests); the runtime-sources pin test passes with the hash written here. Bound a debug build's draw allocations by what its shape checks add: What: runtime_lane::frame_costs::a_frame_s_draws_and_pass_ends_allocate_within_their_bounds holds a build with debug assertions' draws to DRAW_ALLOCATIONS_DEBUG (38) and other builds' to DRAW_ALLOCATIONS (27, unchanged). The new bound states what it holds: the draw path's allocations and those of LiveBind::shape's two debug_assert!s, which build the state's whole bind shape at each draw to compare the kept or the found one with it; measured 35.93 on lavapipe (llvmpipe, LLVM 23.1.1, Mesa 26.2.4), where a build without debug assertions makes 24.62. The pass end, pass open and commit bounds hold unchanged in both builds. Why: CI's tests are debug builds, and its CPU-ICD step failed this test at every sha since the bound came (86.60 allocations a draw; 35.93 since the previous part made the stage table's check allocation-free). The shape checks stay exact: making them allocation-free would compare through BindState::has_shape, the function the found-shape check exists to cross-check, and a reusable shape would need new public API in the published crate. With a debug bound the CPU-ICD step keeps holding the draw path in CI: a new allocation in it moves both counts alike, and the bound keeps the release bound's slack (about 2.4 allocations). Verified on msi-laptop, lavapipe, --cfg m2v_cpu_icd, debug, LP_NUM_THREADS=1, twice: the four a_frame_s_ bound tests pass (draws 35.93 of 38, pass ends 38.63 of 40, opens 13.00 of 14, commits 5.00 of 6 and 17.08 / 17.24 of 20 on the other threads); the same tests with CARGO_PROFILE_DEV_DEBUG_ASSERTIONS=false at fd22785008 gave 24.62, 38.63, 13.00 and 4.99; clippy --workspace --all-targets --all-features under --cfg m2v_gpu is clean. Versions: RUNTIME_VERSION 1186 -> 1195. RUNTIME_VERSION moves: a depth or stencil texture over a buffer no longer gets a linear image. crates/metal2vulkan-validation/runtime-sources.sha256 holds 4a161b14058fa3e4c4b039726845c4bb221965a409dae3153e6232d213f22330, the hash of this tree's runtime inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values the work's branch built with. Each part's Verified lines name the tree it ran at. --- .../src/argument_table.rs | 118 ++++++++++++++++-- .../metal2vulkan-runtime/src/degradation.rs | 3 +- crates/metal2vulkan-runtime/src/dma_buf.rs | 23 +++- .../src/tests/argument_table.rs | 111 ++++++++++++++++ crates/metal2vulkan-runtime/src/tests/mod.rs | 2 + .../runtime-sources.sha256 | 2 +- .../src/runtime_lane/buffer_texture_blits.rs | 62 +++++++++ .../src/runtime_lane/frame_costs.rs | 37 ++++-- crates/metal2vulkan/src/cache/mod.rs | 2 +- .../metal2vulkan/src/tests/engine_handles.rs | 4 +- docs/API.md | 7 +- docs/HOWTO.md | 4 +- scripts/linux-gate-ci | 28 ++++- 13 files changed, 367 insertions(+), 36 deletions(-) create mode 100644 crates/metal2vulkan-runtime/src/tests/argument_table.rs diff --git a/crates/metal2vulkan-runtime/src/argument_table.rs b/crates/metal2vulkan-runtime/src/argument_table.rs index 9ff1c5535..51926b887 100644 --- a/crates/metal2vulkan-runtime/src/argument_table.rs +++ b/crates/metal2vulkan-runtime/src/argument_table.rs @@ -232,6 +232,23 @@ fn bound_texture(texture: &Texture) -> BoundTexture { } } +/// Whether `a` and `b` print alike (`{:?}`), told without printing them +/// ([`ArgumentTable::check_reading`]): every field as `==` compares it, but the descriptor's LOD +/// clamps, which print a float's sign (`0.0` and `-0.0` differ, where `==` takes them for equal) +/// and print every NaN alike (where `==` takes no NaN for equal). `tests/argument_table.rs` fails +/// when `BoundSampler` or `SamplerDescriptor` gains a field, so a new one is compared here too. +#[cfg(debug_assertions)] +pub(super) fn same_as_printed(a: &BoundSampler, b: &BoundSampler) -> bool { + let alike = |x: f32, y: f32| x.to_bits() == y.to_bits() || (x.is_nan() && y.is_nan()); + let clamps = alike(a.desc.lod_min_clamp, b.desc.lod_min_clamp) + && alike(a.desc.lod_max_clamp, b.desc.lod_max_clamp); + let [mut a, mut b] = [*a, *b]; + for desc in [&mut a.desc, &mut b.desc] { + [desc.lod_min_clamp, desc.lod_max_clamp] = [0.0; 2]; + } + clamps && a == b +} + impl ArgumentTable { /// A compute encoder's table (the module docs). pub(super) fn compute() -> ArgumentTable { @@ -783,25 +800,104 @@ impl ArgumentTable { BoundSampler::shape, ); } - // The table read whole, as before (debug builds): the same bindings, a float's sign and - // a NaN's included (compared as printed). #[cfg(debug_assertions)] - { - let mut whole = self.stage_table_reading(stage, interface); - for (&index, bound) in &mut whole.samplers { + self.check_reading(kept, read, maps); + } + + /// That `kept`, brought in place by [`refresh_reading`](Self::refresh_reading), is the table + /// `stage`'s function of `interface` reads whole + /// ([`stage_table_reading`](Self::stage_table_reading)), each sampler as `maps` binds it + /// (debug builds): the same slots, each bound alike as its value prints (a float's sign told + /// apart, every NaN alike: [`same_as_printed`]), and nothing else in the table. Compared slot + /// by slot, with no table read whole made and nothing printed unless a slot differs, so a + /// draw allocates as many times with debug assertions as without (`runtime_lane::frame_costs` + /// holds its bound in every build). A slot that differs is named in the panic. + #[cfg(debug_assertions)] + fn check_reading( + &self, + kept: &StageTable, + read: (Stage, &PipelineInterface), + maps: &SamplerMaps, + ) { + let (stage, _) = read; + const DIFFERS: &str = "a stage table brought in place that is not the table read whole"; + // A buffer slot as `stage_table_reading` reads it: inline bytes where they are bound, + // else the buffer within its length, and nothing where the function reads it unbound. + let buffer = |index: u32| { + if self.reads_unbound(read, index) { + return None; + } + match self.bytes.get(&index) { + Some(bytes) => Some(bound_bytes(bytes)), + None => self.buffers.get(&index).and_then(|(buffer, offset)| { + let stride = self.attribute_strides.get(&index).copied(); + bound_buffer(buffer, *offset, stride) + }), + } + }; + for (&index, bound) in &kept.buffers { + let whole = buffer(index); + assert!( + whole.as_ref() == Some(bound), + "{DIFFERS}: {stage:?} buffer {index} kept as {bound:?}, read whole as {whole:?}" + ); + } + for &index in self.buffers.keys().chain(self.bytes.keys()) { + if let Some(whole) = buffer(index) { + assert!( + kept.buffers.contains_key(&index), + "{DIFFERS}: {stage:?} buffer {index} not kept, read whole as {whole:?}" + ); + } + } + for (&index, bound) in &kept.textures { + let whole = self.textures.get(&index).map(bound_texture); + assert!( + whole.as_ref() == Some(bound), + "{DIFFERS}: {stage:?} texture {index} kept as {bound:?}, read whole as {whole:?}" + ); + } + for (&index, texture) in &self.textures { + assert!( + kept.textures.contains_key(&index), + "{DIFFERS}: {stage:?} texture {index} not kept, read whole as {:?}", + bound_texture(texture) + ); + } + let sampler = |index: u32| { + self.samplers.get(&index).map(|(sampler, clamps)| { let slot = SlotRef { stage, class: SlotClass::Sampler, index, }; - bound.desc = maps.sampler(slot, bound.desc); - } - debug_assert_eq!( - format!("{kept:?}"), - format!("{whole:?}"), - "a stage table brought in place that is not the table read whole" + let mut whole = BoundSampler::new(bound_sampler(sampler, *clamps)); + whole.desc = maps.sampler(slot, whole.desc); + whole + }) + }; + for (&index, bound) in &kept.samplers { + let whole = sampler(index); + assert!( + whole.is_some_and(|whole| same_as_printed(&whole, bound)), + "{DIFFERS}: {stage:?} sampler {index} kept as {bound:?}, read whole as {whole:?}" ); } + for &index in self.samplers.keys() { + assert!( + kept.samplers.contains_key(&index), + "{DIFFERS}: {stage:?} sampler {index} not kept, read whole as {:?}", + sampler(index) + ); + } + // A table read whole binds nothing else (`stage_table` starts from the empty table). + assert!( + kept.threadgroup_lengths.is_empty() && kept.acceleration_structures.is_empty(), + "{DIFFERS}: {stage:?} keeps threadgroup lengths {:?} and acceleration structures {:?}, \ + where the table read whole has none", + kept.threadgroup_lengths, + kept.acceleration_structures + ); } /// Each object bound, by slot, in the table's order: its buffers, then its textures, then diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index b1276b409..dd74ad17f 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -224,7 +224,8 @@ degradations! { /// host memory, no linear image made for host allocations does: neither the driver's own /// nor, where the device enables `VK_EXT_image_drm_format_modifier`, a /// `DRM_FORMAT_MOD_LINEAR` image laid out at Metal's row pitch, which the driver may refuse - /// for the texture's format, usage or pitch), or the buffer is over + /// for the texture's format, usage or pitch, and which the runtime makes of no depth or + /// stencil format), or the buffer is over /// the caller's `VkBuffer`, whose memory backs no image of the runtime's, or over host /// pages imported as dma-bufs (`HostMemory::with_dma_buf`) where the device makes no image /// over a dma-buf of the texture's own pages (the notice names why). Also a heap's depth diff --git a/crates/metal2vulkan-runtime/src/dma_buf.rs b/crates/metal2vulkan-runtime/src/dma_buf.rs index de4490e54..ce227e927 100644 --- a/crates/metal2vulkan-runtime/src/dma_buf.rs +++ b/crates/metal2vulkan-runtime/src/dma_buf.rs @@ -907,9 +907,17 @@ impl Device { /// What a `DRM_FORMAT_MOD_LINEAR` image of `plan` for `memory` takes before its plane is laid /// out, on a device that enables `VK_EXT_image_drm_format_modifier`: the formats it lists for /// its views; why not where the device makes none: the plan has several levels, depth or - /// samples, or a mutable format with no list of its views; the modifier's tiling lacks a - /// feature the plan's optimal tiling has for its usage; the format query refuses such an - /// image for `memory`, or the plan passes its limits. + /// samples, or a mutable format with no list of its views; its format has a depth or stencil + /// component; the modifier's tiling lacks a feature the plan's optimal tiling has for its + /// usage; the format query refuses such an image for `memory`, or the plan passes its limits. + /// + /// The runtime takes a modifier image's plane layout from the driver + /// (`vkGetImageSubresourceLayout`), and Vulkan has no valid such query of a format with a + /// depth or stencil component: of a DRM format modifier's tiling its aspect must be a memory + /// plane's (`VUID-vkGetImageSubresourceLayout-tiling-09433`), of a format with depth or + /// stencil it must contain that aspect (`-format-04462`, `-format-04463`), and it is one bit + /// (`-aspectMask-00997`). So it makes none of such a format, wherever a driver lists the + /// modifier for it. pub(super) fn modifier_image_checks( &self, plan: &ImagePlan, @@ -923,6 +931,15 @@ impl Device { plan.levels, plan.extent[2], plan.samples ))); } + if (plan.format.block()) + .is_some_and(|block| block.depth.is_some() || block.stencil.is_some()) + { + return Ok(Err(format!( + "{:?} has a depth or stencil component, and Vulkan has no query of where a \ + DRM_FORMAT_MOD_LINEAR plane of such a format lies", + plan.format + ))); + } // A DRM format modifier's mutable image lists its views' formats // (`VUID-VkImageCreateInfo-tiling-02353`): a plan whose views take any compatible format // lists each the runtime views a texture as (`linear_plan::viewed_formats`), its own diff --git a/crates/metal2vulkan-runtime/src/tests/argument_table.rs b/crates/metal2vulkan-runtime/src/tests/argument_table.rs new file mode 100644 index 000000000..e22300a78 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/argument_table.rs @@ -0,0 +1,111 @@ +//! The debug builds' check that a stage table brought in place is the table read whole +//! (`ArgumentTable::check_reading`, `argument_table.rs`), which compares a sampler as it prints +//! without printing it (`same_as_printed`). + +use super::super::argument_table::same_as_printed; +use metal2vulkan::bind::{BoundSampler, SamplerDescriptor, StageTable}; + +/// The field names of a value's `{:?}` print, `Name { a: .., b: .. }`, at its top level. +fn field_names(printed: &str) -> Vec { + let inner = &printed[printed.find('{').unwrap() + 1..printed.rfind('}').unwrap()]; + let mut names = Vec::new(); + let (mut depth, mut start) = (0, 0); + for (at, c) in inner.char_indices() { + match c { + '{' | '(' | '[' => depth += 1, + '}' | ')' | ']' => depth -= 1, + ',' if depth == 0 => { + names.push(inner[start..at].trim().to_owned()); + start = at + 1; + } + _ => {} + } + } + names.push(inner[start..].trim().to_owned()); + names + .iter() + .filter(|field| !field.is_empty()) + .map(|field| field.split(':').next().unwrap().trim().to_owned()) + .collect() +} + +/// Two bound samplers compare alike exactly where they print alike: LOD clamps of opposite zero +/// signs differ, NaN clamps of any sign and payload are alike, and every other field differs +/// where its value does. +#[test] +fn samplers_compare_as_they_print() { + let base = BoundSampler::new(SamplerDescriptor::new()); + let clamped = |min: f32, max: f32| { + let mut sampler = base; + sampler.desc.lod_min_clamp = min; + sampler.desc.lod_max_clamp = max; + sampler + }; + let other = |change: fn(&mut BoundSampler)| { + let mut sampler = base; + change(&mut sampler); + sampler + }; + let pairs = [ + (base, base), + (clamped(0.0, 1.0), clamped(-0.0, 1.0)), + (clamped(0.0, 0.0), clamped(0.0, -0.0)), + (clamped(f32::NAN, 1.0), clamped(-f32::NAN, 1.0)), + ( + clamped(0.5, f32::from_bits(0x7fc0_0001)), + clamped(0.5, f32::NAN), + ), + (clamped(f32::NAN, 1.0), clamped(0.0, 1.0)), + (clamped(0.0, f32::MAX), clamped(0.0, f32::INFINITY)), + (base, other(|s| s.desc.max_anisotropy = 4)), + (base, other(|s| s.desc.normalized_coordinates = false)), + (base, other(|s| s.resource_id = Some(7))), + ]; + for (a, b) in pairs { + assert_eq!( + same_as_printed(&a, &b), + format!("{a:?}") == format!("{b:?}"), + "{a:?} against {b:?}" + ); + } +} + +/// The fields the check compares: a field added to a stage table, a bound sampler or a sampler +/// descriptor fails this until `check_reading` and `same_as_printed` compare it as it prints. +#[test] +fn the_check_compares_every_field() { + assert_eq!( + field_names(&format!("{:?}", StageTable::default())), + [ + "buffers", + "textures", + "samplers", + "threadgroup_lengths", + "acceleration_structures" + ] + ); + let sampler = BoundSampler::new(SamplerDescriptor::new()); + assert_eq!( + field_names(&format!("{sampler:?}")), + ["desc", "resource_id"] + ); + assert_eq!( + field_names(&format!("{:?}", sampler.desc)), + [ + "min_filter", + "mag_filter", + "mip_filter", + "s_address_mode", + "t_address_mode", + "r_address_mode", + "border_color", + "normalized_coordinates", + "lod_min_clamp", + "lod_max_clamp", + "lod_average", + "max_anisotropy", + "compare_function", + "reduction_mode" + ] + ); +} diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 4a5f23cd5..f3bc39963 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -12,6 +12,8 @@ mod amplification; mod apple_only; mod argument_buffers; mod argument_encoder; +#[cfg(debug_assertions)] +mod argument_table; mod attachmentless; mod attributes; mod batches; diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 292a0377f..d5207651d 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -2f7e93a9335e29d38177e561a877ec40a69994fbe733a2dd0bdff75c96a8ce3e +4a161b14058fa3e4c4b039726845c4bb221965a409dae3153e6232d213f22330 diff --git a/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs b/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs index 0d3f5f8f6..e9a210ff4 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs @@ -1402,6 +1402,68 @@ fn a_planar_surface_s_depth_or_stencil_texture_s_passes_write_metal_s_elements_a ); } +/// No depth or stencil texture over a buffer's bytes asks the driver for a +/// `DRM_FORMAT_MOD_LINEAR` image, at Metal's row pitch over host pages or over dma-buf pages, even +/// where the driver lists the modifier for its format (lavapipe does): the runtime asks the layout +/// of every such image it makes of a memory plane (`VUID-vkGetImageSubresourceLayout-tiling-09433`), +/// and Vulkan has no such query of a format with depth or stencil, whose aspect it must name +/// (`-format-04462`, `-format-04463`). Each texture of a surface's plane is made, at a padded row +/// pitch and a browser's, and the work counts show no such image made or refused. +#[test] +fn no_depth_or_stencil_texture_over_a_buffer_asks_for_a_modifier_image() { + use metal2vulkan_runtime::WorkCounts; + let asked = |counts: &WorkCounts| { + ( + counts.pitched_host_images, + counts.pitched_host_image_refusals, + counts.dma_buf_images, + ) + }; + let messages = Messages::default(); + let cache = ScratchCache::new().unwrap(); + { + let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); + eprintln!("device {}", device.name()); + for kind in [Kind::Ordinary, Kind::NoCopy] { + let Some(held) = Held::new(&device, kind) else { + eprintln!("{}: no {kind:?} buffer", device.name()); + continue; + }; + for pf in [ + PixelFormat::Depth16Unorm, + PixelFormat::Depth32Float, + PixelFormat::Depth32FloatStencil8, + PixelFormat::Stencil8, + PixelFormat::X32Stencil8, + ] { + for usage in [TextureUsage::SHADER_READ, TextureUsage::RENDER_TARGET] { + for bpr in [64, 256] { + let what = format!("{kind:?} {pf:?} {usage:?}, rows {bpr} bytes apart"); + let mut d = TextureDescriptor::texture_2d(pf, 4, 4, false); + d.usage = usage; + d.resource_options = held.buffer.resource_options(); + let before = device.work_counts(); + held.buffer + .new_texture_with_iosurface_plane(&d, IoSurfacePlane::new(0, bpr, true)) + .unwrap_or_else(|e| panic!("{what}: {e}")); + assert_eq!( + asked(&device.work_counts()), + asked(&before), + "{what}: DRM_FORMAT_MOD_LINEAR images asked of the driver (made at \ + Metal's row pitch, refused there, made over dma-bufs)" + ); + } + } + } + } + } + let messages = messages.take(); + assert!( + messages.is_empty(), + "the validation layer reported: {messages:#?}" + ); +} + /// The rows of a `w`x`h` plane `row` bytes wide, from `offset`, `pitch` bytes apart. fn plane_rows(offset: u64, pitch: u64, row: u64, h: u64) -> Vec> { (0..h) diff --git a/crates/metal2vulkan-validation/src/runtime_lane/frame_costs.rs b/crates/metal2vulkan-validation/src/runtime_lane/frame_costs.rs index 1e1684a57..cd328276e 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/frame_costs.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/frame_costs.rs @@ -68,7 +68,8 @@ //! Three checks run by default where the allocations are counted: //! `a_frame_s_draws_and_pass_ends_allocate_within_their_bounds` holds a frame's draws to //! [`DRAW_ALLOCATIONS`] on the encoding thread, a draw's state changes and its draw call -//! together, and its passes' ends to [`PASS_END_ALLOCATIONS`], each on average; +//! together ([`DRAW_ALLOCATIONS_DEBUG`] in a build with debug assertions), and its passes' ends +//! to [`PASS_END_ALLOCATIONS`], each on average; //! `a_frame_s_pass_opens_allocate_within_their_bound` its pass opens to [`OPEN_ALLOCATIONS`]; and //! `a_frame_s_commits_allocate_within_their_bound` holds a checked frame's commits to //! [`COMMIT_ALLOCATIONS`] on the encoding thread and to [`SUBMIT_ALLOCATIONS`] on the others @@ -131,6 +132,12 @@ const SHAPE_BYTES: usize = 64; /// and the format table its entries. #[cfg(not(m2v_system_alloc))] const DRAW_ALLOCATIONS: f64 = 27.0; +/// [`DRAW_ALLOCATIONS`] in a build with debug assertions, which CI's tests are: the draw path's +/// allocations and those of `LiveBind::shape`'s checks there, which build the state's whole bind +/// shape at each draw to compare the kept or found one with it. Measured: 35.93 on lavapipe +/// (llvmpipe, LLVM 23.1.1, Mesa 26.2.4), where a build without debug assertions makes 24.62. +#[cfg(not(m2v_system_alloc))] +const DRAW_ALLOCATIONS_DEBUG: f64 = 38.0; /// The most allocations a frame's pass open (`render_command_encoder`) makes on the encoding /// thread on average, once every pipeline is made. Measured: 13.0 on RADV (Radeon 780M), on /// lavapipe and on ANV (Iris Xe); 18.0 on RADV and ANV before the device kept each pass shape's @@ -1251,24 +1258,28 @@ fn allocations_each(frame: &Frame, steps: StepsOf) -> f64 { allocations as f64 / steps.len() as f64 } -/// A frame's draws allocate at most [`DRAW_ALLOCATIONS`] each on average on the encoding thread, -/// once every pipeline is made: what the draw path keeps of what it found before (each texture's -/// storage view formats, the pipeline state's routing into the pass's colors, the settles of its -/// latest bind shapes and the shapes themselves, the format table) is not made again at each -/// draw, and what a draw retains, binds and records it holds and builds without allocating where -/// the object or the list allows. Its passes' ends allocate at most [`PASS_END_ALLOCATIONS`] each: -/// a pass end retains what its commands use as one object, and makes no tile grid where a draw -/// reaches every tile, no sample planes' steps in a pass without planes, and no scrub's list for a -/// texture that is not sparse. +/// A frame's draws allocate at most [`DRAW_ALLOCATIONS`] each on average on the encoding thread +/// ([`DRAW_ALLOCATIONS_DEBUG`] with debug assertions), once every pipeline is made: what the draw +/// path keeps of what it found before (each texture's storage view formats, the pipeline state's +/// routing into the pass's colors, the settles of its latest bind shapes and the shapes +/// themselves, the format table) is not made again at each draw, and what a draw retains, binds +/// and records it holds and builds without allocating where the object or the list allows. Its +/// passes' ends allocate at most [`PASS_END_ALLOCATIONS`] each: a pass end retains what its +/// commands use as one object, and makes no tile grid where a draw reaches every tile, no sample +/// planes' steps in a pass without planes, and no scrub's list for a texture that is not sparse. #[cfg(not(m2v_system_alloc))] #[test] fn a_frame_s_draws_and_pass_ends_allocate_within_their_bounds() { let (device, frame) = counted(); let each = allocations_each(&frame, |f| &f.draws); - eprintln!("FRAME-COST {device}: {each:.2} allocations a draw, at most {DRAW_ALLOCATIONS} kept"); + let bound = match cfg!(debug_assertions) { + true => DRAW_ALLOCATIONS_DEBUG, + false => DRAW_ALLOCATIONS, + }; + eprintln!("FRAME-COST {device}: {each:.2} allocations a draw, at most {bound} kept"); assert!( - each <= DRAW_ALLOCATIONS, - "{each:.2} allocations a draw, more than {DRAW_ALLOCATIONS}" + each <= bound, + "{each:.2} allocations a draw, more than {bound}" ); let each = allocations_each(&frame, |f| &f.end); eprintln!( diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index c63c17514..35410a111 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 399; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 1186; +pub const RUNTIME_VERSION: u32 = 1195; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/crates/metal2vulkan/src/tests/engine_handles.rs b/crates/metal2vulkan/src/tests/engine_handles.rs index 608a397b7..4b45dce25 100644 --- a/crates/metal2vulkan/src/tests/engine_handles.rs +++ b/crates/metal2vulkan/src/tests/engine_handles.rs @@ -2867,14 +2867,14 @@ fn heap_linear_kernel(through: CompareThrough, three: bool) -> String { true => ( "texture3d", format!( - "@air.sample_texture_3d.v4f32(ptr addrspace(1) %t, ptr addrspace(2) {operand}, <3 x float> , i1 true, <3 x i32> zeroinitializer, i1 true, float 0.0, float 0.0, i32 0)" + "@air.sample_texture_3d.v4f32(ptr addrspace(1) %t, ptr addrspace(2) {operand}, <3 x float> , i1 true, <3 x i32> zeroinitializer, i1 true, float 0.0, float 0.0, i32 0)" ), "declare { <4 x float>, i8 } @air.sample_texture_3d.v4f32(ptr addrspace(1), ptr addrspace(2), <3 x float>, i1, <3 x i32>, i1, float, float, i32)", ), false => ( "texture2d", format!( - "@air.sample_texture_2d.v4f32(ptr addrspace(1) %t, ptr addrspace(2) {operand}, <2 x float> , i1 true, <2 x i32> zeroinitializer, i1 true, float 0.0, float 0.0, i32 0)" + "@air.sample_texture_2d.v4f32(ptr addrspace(1) %t, ptr addrspace(2) {operand}, <2 x float> , i1 true, <2 x i32> zeroinitializer, i1 true, float 0.0, float 0.0, i32 0)" ), "declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr addrspace(2), <2 x float>, i1, <2 x i32>, i1, float, float, i32)", ), diff --git a/docs/API.md b/docs/API.md index 13a902c1c..ec987355e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -147,7 +147,9 @@ 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. With them enabled, a texture over a no-copy buffer's pages imported by their pointer is also a `DRM_FORMAT_MOD_LINEAR` image made for host allocations at Metal's row pitch where the driver's own linear image lays its -rows out otherwise (ANV packs them tight) and the driver takes that layout +rows out otherwise (ANV packs them tight) and the driver takes that layout, of a format with no depth +or stencil component (Vulkan has no query of where such a format's memory plane lies, so the runtime +makes no `DRM_FORMAT_MOD_LINEAR` image of one) (`WorkCounts::pitched_host_images`; HOWTO.md section 6 lists what each measured driver takes). `Texture::vk_image` then gives that image. A layout the driver refused is kept per device and not asked again (`pitched_host_image_refusals`, `pitched_host_image_refusals_recalled`). @@ -695,7 +697,8 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound. buffer's memory (over a no-copy buffer's imported host memory, no linear image made for host allocations does: neither the driver's own nor, where the device enables `VK_EXT_image_drm_format_modifier`, a `DRM_FORMAT_MOD_LINEAR` image laid out at Metal's row - pitch, which the driver may refuse for the texture's format, usage or pitch; + pitch, which the driver may refuse for the texture's format, usage or pitch, and which the + runtime makes of no depth or stencil format; `WorkCounts::pitched_host_images` counts those made, `pitched_host_image_refusals` those the driver refused), or the buffer is over the caller's `VkBuffer`, whose memory backs no image of the runtime's, or over host pages imported as dma-bufs (`HostMemory::with_dma_buf`) where the diff --git a/docs/HOWTO.md b/docs/HOWTO.md index 20763935a..17f33eaf0 100644 --- a/docs/HOWTO.md +++ b/docs/HOWTO.md @@ -177,7 +177,9 @@ is refused (`NotImplemented(RebindTextures)`). `WorkCounts::dma_buf_imports`, A texture over pages imported by their pointer aliases them where the device lays an image's rows at the texture's `bytes_per_row`: the driver's own linear image, or, where that lays its rows -otherwise, a `DRM_FORMAT_MOD_LINEAR` image at that pitch, which the driver may refuse. Measured +otherwise, a `DRM_FORMAT_MOD_LINEAR` image at that pitch, which the driver may refuse (and which +the runtime makes of no depth or stencil format, as it makes no image over a dma-buf of one: Vulkan +has no query of where such a format's memory plane lies). Measured (`runtime_lane::surface_texture_costs::pitch_classes`, nine formats, four usages, rows padded by each power of two from 16 to 4096 bytes): diff --git a/scripts/linux-gate-ci b/scripts/linux-gate-ci index 5e67fc882..54db8cf90 100755 --- a/scripts/linux-gate-ci +++ b/scripts/linux-gate-ci @@ -48,6 +48,25 @@ cpu_icd_tests() { cargo nextest run -p metal2vulkan-validation --all-features --build-jobs "$jobs" } +feature_clippy() { + local features + for features in "" serde ash cli; do + echo "::group::features=${features:-none}" + cargo clippy -p metal2vulkan --all-targets --no-default-features --features "$features" \ + -j "$jobs" -- -D warnings + echo "::endgroup::" + done + echo "::group::metal2vulkan-runtime" + cargo clippy -p metal2vulkan-runtime --all-targets -j "$jobs" -- -D warnings + echo "::endgroup::" + for features in "" serde; do + echo "::group::metal2vulkan-air features=${features:-none}" + cargo clippy -p metal2vulkan-air --all-targets --no-default-features --features "$features" \ + -j "$jobs" -- -D warnings + echo "::endgroup::" + done +} + gpu_cfg_clippy() { # As cpu_icd_tests, a sibling target dir keeps the ordinary build warm. CARGO_TARGET_DIR="${CARGO_TARGET_DIR}-gpucfg" RUSTFLAGS='-Dwarnings --cfg m2v_gpu' \ @@ -63,10 +82,17 @@ step "Install LLVM + SPIR-V tools (probe)" tools_probe step "Format" cargo fmt --all -- --check step "Clippy (warnings denied)" \ cargo clippy --workspace --all-targets --all-features -j "$jobs" -- -D warnings +step "Clippy under each feature alone (warnings denied)" feature_clippy step "Clippy under --cfg m2v_gpu (warnings denied)" gpu_cfg_clippy step "Build public documentation (warnings denied)" \ env RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --all-features --no-deps -j "$jobs" -step "Test metal2vulkan" cargo nextest run -p metal2vulkan --all-features --build-jobs "$jobs" +step "Build the new API's consumer reference (warnings denied)" scripts/api-docs +step "Package the published crates" \ + cargo package --workspace --exclude metal2vulkan-validation --exclude metal2vulkan-devtools \ + -j "$jobs" +step "Test metal2vulkan" \ + cargo nextest run -p metal2vulkan -p metal2vulkan-air -p metal2vulkan-runtime \ + -p metal2vulkan-devtools --all-features --build-jobs "$jobs" step "Test validation suite" \ cargo nextest run -p metal2vulkan-validation --all-features --build-jobs "$jobs" step "Doc tests" cargo test --workspace --all-features --doc -j "$jobs"