From 4df69ca062c1ea730282ce7f1f5a83ca2bdae96a Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 18 Nov 2026 18:20:40 -0800 Subject: [PATCH] rt: generateMipmapsForTexture:, the device's linear blit of each level, under a static note web3d calls generateMipmapsForTexture: once in each stream, which the player skipped and counted (mipmaps 1). It is built as Apple defines the call: each level below the texture's first made from the level above it, over each slice, a view's levels and slices its own. - BlitCommandEncoder::generate_mipmaps: one vkCmdBlitImage a level with VK_FILTER_LINEAR, the first level read and the rest written whole (their old contents discarded) behind the copy's first barrier, one barrier between each level and the next, and the last bringing every level home, the last level's writes visible to every later command. A texture of one level records nothing. - Refusal::MipmapFormat for a format Apple defines no mipmaps of (a depth or stencil, compressed, YCbCr or integer one: not colour-renderable and filterable); Gap::MipmapFilter where the device's format query lacks blits from and to the image's format or its linear filtering, where the image holds the pixel format through a conversion, and for a view in another format than its image's, whose blit would filter the image's. - PrecisionNote::DeviceFilteredMipmaps, the static note BlitCommandEncoder::GENERATE_MIPMAPS_NOTE carries: the filter is the device's, where Apple states none. The old runtime announces it as its existing device-filtered-mipmaps kind; validation allows it unbounded; codec and ARTIFACT_FORMAT_VERSION 541, fast_paths' list, API.md's catalogue entry. - The conformance rt side plays Step::GenerateMipmaps and announces the note; the replay player plays the call and its skipped_mipmaps counter is gone (REPLAY-STREAM.md). - Test: an 8x8 RGBA8Unorm texture of four levels, each level below the first within one code of the box of the four texels it halves in the level above as the device left them, its first level kept, one submission and the chain's four barriers besides the segment's end; one level records nothing; RGBA8Uint is Refusal::MipmapFormat. REFUSALS and api_signatures regenerated. --- .../metal2vulkan-conformance/src/rt_side.rs | 11 +- .../src/rt_side/work.rs | 7 +- crates/metal2vulkan-rt/README.md | 11 + crates/metal2vulkan-rt/src/blit.rs | 188 +++++++++++++++++- crates/metal2vulkan-rt/src/error.rs | 32 +++ crates/metal2vulkan-rt/src/tests/mipmaps.rs | 165 +++++++++++++++ crates/metal2vulkan-rt/src/tests/mod.rs | 1 + crates/metal2vulkan-rt/src/texture.rs | 44 ++++ .../metal2vulkan-runtime/src/degradation.rs | 4 +- .../src/observation_contract/comparison.rs | 3 +- .../observation_contract/comparison/tests.rs | 1 + .../src/replay/new_runtime/encoders.rs | 4 +- .../src/replay/new_runtime/mod.rs | 7 +- crates/metal2vulkan/src/cache/codec.rs | 1 + crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/src/pipeline/artifact.rs | 16 ++ crates/metal2vulkan/src/tests/fast_paths.rs | 1 + crates/metal2vulkan/tests/api_signatures.tsv | 9 +- docs/API.md | 3 + docs/REFUSALS.md | 16 +- docs/REPLAY-STREAM.md | 8 +- 21 files changed, 507 insertions(+), 27 deletions(-) create mode 100644 crates/metal2vulkan-rt/src/tests/mipmaps.rs diff --git a/crates/metal2vulkan-conformance/src/rt_side.rs b/crates/metal2vulkan-conformance/src/rt_side.rs index a740cca9c..4d0c52783 100644 --- a/crates/metal2vulkan-conformance/src/rt_side.rs +++ b/crates/metal2vulkan-conformance/src/rt_side.rs @@ -1063,10 +1063,17 @@ impl Side for RtSide<'_> { Ok(keep(&mut self.textures, texture)) } - /// The program on the runtime, as the old runtime's side runs it (`rt_side::work`). + /// The program on the runtime, as the old runtime's side runs it (`rt_side::work`); a + /// program that generates mipmaps announces the blit encoder's static note of them. fn work(&mut self, work: &crate::work::Work) -> Answer { let on = self.on; - work::run(on, self.queue()?, work) + let done = work::run(on, self.queue()?, work)?; + let mipmaps = + |step: &crate::work::Step| matches!(step, crate::work::Step::GenerateMipmaps { .. }); + if work.steps.iter().any(mipmaps) { + (self.encoder_notes).insert(rt::BlitCommandEncoder::GENERATE_MIPMAPS_NOTE); + } + Ok(done) } /// At the next sampler index. Every state the runtime makes has a resource ID, so diff --git a/crates/metal2vulkan-conformance/src/rt_side/work.rs b/crates/metal2vulkan-conformance/src/rt_side/work.rs index b1845335b..76793a260 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/work.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/work.rs @@ -10,7 +10,7 @@ //! //! A step the runtime has no counterpart of answers `Unavailable` with its Metal call: the two //! fills (Apple SPI, whose Metal answers are carried), the whole-texture and slice copies, -//! `generateMipmapsForTexture:`, the two optimize calls, `synchronizeTexture:slice:level:`, and a +//! the two optimize calls, `synchronizeTexture:slice:level:`, and a //! copy with a depth, stencil or PVRTC blit option. A heap other than Private or Shared, and a //! buffer of Memoryless storage, which Metal makes no buffer of, are unavailable too. @@ -577,7 +577,10 @@ impl Run<'_> { "copyFromTexture:sourceSlice:sourceLevel:toTexture:destinationSlice:\ destinationLevel:sliceCount:levelCount:", )), - Step::GenerateMipmaps { .. } => Err(Failure::unavailable("generateMipmapsForTexture:")), + Step::GenerateMipmaps { texture } => { + let texture = self.texture(*texture)?; + (self.encoder()?.generate_mipmaps(&texture)).map_err(of_rt) + } Step::OptimizeForGpuAccess { .. } => { Err(Failure::unavailable("optimizeContentsForGPUAccess:")) } diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 2a531aa3e..f8b1584dd 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -1124,6 +1124,17 @@ that touch blocks first. reads where shaders write it, and of a texture without named bytes, which has none the host reads apart from its image, it records nothing. Metal's validation stops it on a resource that is not Managed; the runtime keeps no storage mode for those and does not refuse it. +- `generate_mipmaps` is `generateMipmapsForTexture:`: each level below the texture's first made + from the level above it, over each slice, by one `vkCmdBlitImage` a level with the linear + filter, the device's filter under the static note `PrecisionNote::DeviceFilteredMipmaps` + (`BlitCommandEncoder::GENERATE_MIPMAPS_NOTE`; Apple states no filter). A view's levels and + slices are its own. The levels leave home behind the copy's first barrier, with one barrier + between each level and the next, and come back in the last. A texture of one level records + nothing. Refused (`Refusal::MipmapFormat`), as Apple defines mipmaps of colour-renderable, + filterable formats alone: a depth or stencil, compressed, YCbCr or integer format. Not built + (`Gap::MipmapFilter`): an image the device's blits do not filter linearly (its format query), + one that holds its pixel format through a conversion (extended-range, YCbCr), and a view in + another format than its image's. - The slice-and-level and whole-texture forms of `copyFromTexture`, `synchronizeTexture:slice:level:` (no recorded stream calls it), and the other blit commands are not built yet. diff --git a/crates/metal2vulkan-rt/src/blit.rs b/crates/metal2vulkan-rt/src/blit.rs index 84c877b66..2ffc14d64 100644 --- a/crates/metal2vulkan-rt/src/blit.rs +++ b/crates/metal2vulkan-rt/src/blit.rs @@ -35,7 +35,9 @@ use crate::over; use crate::record::{memory_barrier, Reach}; use crate::texture::{place, BytesPlace, CopyUnit, Placed, Region, Texture, TextureDescriptor}; use ash::vk; -use metal2vulkan::metal::TextureType; +use metal2vulkan::metal::format::{self as formats, FormatEmulation}; +use metal2vulkan::metal::{PixelFormat, TextureType}; +use metal2vulkan::pipeline::{PrecisionNote, SampledType}; use std::ops::Range; use std::sync::Arc; @@ -538,6 +540,168 @@ impl BlitCommandEncoder { Ok(()) } + /// The static precision note of [`generate_mipmaps`](Self::generate_mipmaps): each level is + /// the device's linear filter of the one above, where Apple states no filter. + pub const GENERATE_MIPMAPS_NOTE: PrecisionNote = PrecisionNote::DeviceFilteredMipmaps; + + /// `generateMipmapsForTexture:`: each level of `texture` below its first made from the level + /// above it, over each of its slices, as Apple defines the call: one `vkCmdBlitImage` a level + /// with the linear filter, the device's ([`GENERATE_MIPMAPS_NOTE`](Self::GENERATE_MIPMAPS_NOTE)). + /// A view's levels and slices are its own, its first level the source of the rest. A texture + /// of one level has none to make: the call records nothing. The levels leave the texture's + /// home layout for the chain and come back in the same call, between a copy's barriers with + /// one between each level and the next; the command buffer keeps the texture until it retires. + /// + /// Err: [`Refusal::OtherDevice`] for another device's texture; [`Refusal::MipmapFormat`] for + /// a format Apple defines no mipmaps of; [`Gap::MipmapFilter`] where the device's blits do not + /// filter the texture's image; [`Error::Vulkan`] where the command buffer cannot record. + pub fn generate_mipmaps(&mut self, texture: &Texture) -> Result<(), Error> { + let (core, building) = self.parts(); + if !texture.is_of(core) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + let d = *texture.descriptor(); + let pixel_format = d.pixel_format; + if d.mipmap_level_count < 2 { + return Ok(()); + } + if !mipmapped(pixel_format) { + return Err(Error::Refused(Refusal::MipmapFormat { pixel_format })); + } + // The blit filters the image's own format, so a view in another format's levels, or a + // format the image holds through a conversion, would be filtered as other values. + use vk::FormatFeatureFlags2 as F; + let filters = F::BLIT_SRC | F::BLIT_DST | F::SAMPLED_IMAGE_FILTER_LINEAR; + let (_, optimal) = core.format_features(texture.image_format()); + if texture.format() != texture.image_format() + || !filtered(texture.emulation()) + || !optimal.contains(filters) + { + return Err(Error::Unsupported(Gap::MipmapFilter { pixel_format })); + } + building.keep_texture(texture); + building.wrote_texture_managed(texture); + let overs = [(texture.hazard_id(), Access::ReadWrite)]; + building.overs_before(&overs, false)?; + let command = building.ordered_command()?; + if texture.host_reads() { + building.wrote_host(); + } + building.overs_after(&overs, false); + use vk::AccessFlags2 as A; + use vk::PipelineStageFlags2 as S; + let (read, write) = ( + texture.copy_layout(vk::ImageLayout::TRANSFER_SRC_OPTIMAL), + texture.copy_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL), + ); + let levels = d.mipmap_level_count; + let earlier = [memory_barrier(Reach::Commands)]; + // The first level is read; every other is written whole, its contents discarded. + let away = [ + texture + .levels_barrier(0..1, None, Some(read)) + .src_stage_mask(S::ALL_COMMANDS) + .src_access_mask(A::MEMORY_WRITE) + .dst_stage_mask(S::BLIT) + .dst_access_mask(A::TRANSFER_READ), + texture + .levels_barrier(1..levels, Some(vk::ImageLayout::UNDEFINED), Some(write)) + .src_stage_mask(S::ALL_COMMANDS) + .src_access_mask(A::NONE) + .dst_stage_mask(S::BLIT) + .dst_access_mask(A::TRANSFER_WRITE), + ]; + // Home: every level but the last from the layout it was read in, the last from the one + // it was written in, its writes visible to every later command. + let back = [ + texture + .levels_barrier(0..levels - 1, Some(read), None) + .src_stage_mask(S::BLIT) + .src_access_mask(A::NONE) + .dst_stage_mask(S::ALL_COMMANDS) + .dst_access_mask(A::MEMORY_READ | A::MEMORY_WRITE), + texture + .levels_barrier(levels - 1..levels, Some(write), None) + .src_stage_mask(S::BLIT) + .src_access_mask(A::TRANSFER_WRITE) + .dst_stage_mask(S::ALL_COMMANDS) + .dst_access_mask(A::MEMORY_READ | A::MEMORY_WRITE), + ]; + let [level, layer] = texture.base(); + let slices = match d.texture_type { + TextureType::Cube | TextureType::CubeArray => d.array_length * 6, + TextureType::Type3D => 1, + _ => d.array_length, + }; + let extent = |at: u32| [d.width, d.height, d.depth].map(|e| (e >> at).max(1)); + let corner = |e: [u32; 3]| vk::Offset3D { + // A level's extent is a `u32` the image format query bounds far below 2^31. + x: e[0] as i32, + y: e[1] as i32, + z: e[2] as i32, + }; + let layers = |at: u32| vk::ImageSubresourceLayers { + aspect_mask: vk::ImageAspectFlags::COLOR, + mip_level: level + at, + base_array_layer: layer, + layer_count: slices, + }; + let device = &core.device; + // SAFETY: the command buffer records outside any render pass and keeps the image until it + // retires; its levels are in their home layout between commands and in the chain's + // layouts between its barriers; each blit reads one level and writes the next, two + // different subresources, inside both; the image has the transfer usages every image + // takes, and its format filters linearly in blits (checked above). + unsafe { + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default() + .memory_barriers(&earlier) + .image_memory_barriers(&away), + ); + for at in 1..levels { + let region = vk::ImageBlit { + src_subresource: layers(at - 1), + src_offsets: [vk::Offset3D::default(), corner(extent(at - 1))], + dst_subresource: layers(at), + dst_offsets: [vk::Offset3D::default(), corner(extent(at))], + }; + device.cmd_blit_image( + command, + texture.image(), + read, + texture.image(), + write, + &[region], + vk::Filter::LINEAR, + ); + if at + 1 == levels { + break; + } + // The level written is read by the next blit. + let written = [texture + .levels_barrier(at..at + 1, Some(write), Some(read)) + .src_stage_mask(S::BLIT) + .src_access_mask(A::TRANSFER_WRITE) + .dst_stage_mask(S::BLIT) + .dst_access_mask(A::TRANSFER_READ)]; + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().image_memory_barriers(&written), + ); + } + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().image_memory_barriers(&back), + ); + } + // The chain's barriers: before it, between each level and the next, and after it. + for _ in 0..levels { + building.count(Metric::Barriers); + } + Ok(()) + } + /// `synchronizeResource:`: the host's bytes of a Managed `resource` brought up to date with /// the GPU's writes to it before the call, which the host reads once the command buffer /// completes or it sees an event signaled after the call. Counted in @@ -1059,3 +1223,25 @@ pub(crate) fn texture_copy( aspect: unit.aspect, })) } + +/// Whether Apple defines mipmaps of `pf`: a colour-renderable, filterable format, which is not a +/// depth or stencil, compressed, YCbCr or integer one ("generateMipmapsForTexture:"). +pub(crate) fn mipmapped(pf: PixelFormat) -> bool { + !formats::is_depth_stencil(pf) + && formats::block_extent(pf).is_none() + && !formats::ycbcr(pf) + && formats::sampled_type(pf) == Some(SampledType::Float) +} + +/// Whether an image holding its pixel format as `emulation` holds each channel as one channel of +/// the same values, which a blit filters as the pixel format's. +fn filtered(emulation: FormatEmulation) -> bool { + matches!( + emulation, + FormatEmulation::Direct + | FormatEmulation::SwizzledView + | FormatEmulation::AlphaInRed + | FormatEmulation::RotatedView + | FormatEmulation::XChannel + ) +} diff --git a/crates/metal2vulkan-rt/src/error.rs b/crates/metal2vulkan-rt/src/error.rs index 6acf98ea4..e97121a81 100644 --- a/crates/metal2vulkan-rt/src/error.rs +++ b/crates/metal2vulkan-rt/src/error.rs @@ -517,6 +517,18 @@ pub enum Refusal { /// The view's. view: PixelFormat, }, + /// [`BlitCommandEncoder::generate_mipmaps`](crate::BlitCommandEncoder::generate_mipmaps) of a + /// texture of more than one level whose pixel format is not a colour-renderable, filterable + /// one: a depth or stencil, compressed, YCbCr or integer format. + /// + /// Basis: metal-measured (Apple's `generateMipmaps(for:)` page: mipmap generation works only + /// for textures with colour-renderable and colour-filterable pixel formats; Metal's API + /// validation stops the others, measured on an Apple M3 Max and an M4 for + /// `metal2vulkan-runtime`'s mipmap plan). + MipmapFormat { + /// The texture's pixel format. + pixel_format: PixelFormat, + }, /// [`BlitCommandEncoder::copy_from_texture`](crate::BlitCommandEncoder::copy_from_texture) /// between textures of two pixel formats, or of two sample counts. /// @@ -797,6 +809,17 @@ pub enum Gap { /// The pixel format asked for. pixel_format: PixelFormat, }, + /// [`BlitCommandEncoder::generate_mipmaps`](crate::BlitCommandEncoder::generate_mipmaps) of a + /// texture whose image the device's blits do not filter: its format query lacks blits from + /// or to the image's format, or its linear filtering, or the image holds the pixel format + /// through a conversion (an extended-range or YCbCr format), or the texture is a view in + /// another format than its image's, whose blit would filter the image's. + /// + /// Basis: ours (the device's format query; the levels are the device's blit chain alone). + MipmapFilter { + /// The texture's pixel format. + pixel_format: PixelFormat, + }, /// A sampler state whose minification or magnification filter is cubic /// ([`Device::new_sampler_state`](crate::Device::new_sampler_state)). /// @@ -1428,6 +1451,11 @@ impl fmt::Display for Refusal { f, "a {view:?} view of a {texture:?} texture made without PixelFormatView usage" ), + Refusal::MipmapFormat { pixel_format } => write!( + f, + "mipmaps of a {pixel_format:?} texture, which is not a colour-renderable, \ + filterable format" + ), Refusal::TextureCopyMismatch { source, destination, @@ -1549,6 +1577,10 @@ impl fmt::Display for Gap { f, "no texture of {pixel_format:?} is made on this device for the usage" ), + Gap::MipmapFilter { pixel_format } => write!( + f, + "mipmaps of a {pixel_format:?} texture, whose image this device's blits do not filter" + ), Gap::TextureBytes { pixel_format } => write!( f, "bytes are not copied to or from this texture of {pixel_format:?}" diff --git a/crates/metal2vulkan-rt/src/tests/mipmaps.rs b/crates/metal2vulkan-rt/src/tests/mipmaps.rs new file mode 100644 index 000000000..55087b04e --- /dev/null +++ b/crates/metal2vulkan-rt/src/tests/mipmaps.rs @@ -0,0 +1,165 @@ +//! `generateMipmapsForTexture:` on the blit encoder. +//! +//! - Apple defines mipmaps of colour-renderable, filterable formats alone: a depth or stencil, +//! compressed, YCbCr or integer format is not one (`mipmapped`). +//! - Under a device cfg, on every device of the cfg's kind: each level below the first of an +//! 8 by 8 `RGBA8Unorm` texture of four levels is, in every channel, within one code of the box +//! of the four texels it halves in the level above as the device left them (the static note +//! `BlitCommandEncoder::GENERATE_MIPMAPS_NOTE`: the filter is the device's), its first level +//! kept; the chain is one submission and its four barriers, besides the segment's end. A +//! texture of one level records nothing, +//! and one of an integer format is `Refusal::MipmapFormat`. + +use crate::blit::mipmapped; +use crate::PixelFormat; + +#[test] +fn mipmaps_are_of_colour_renderable_filterable_formats() { + for (pf, expected) in [ + (PixelFormat::RGBA8Unorm, true), + (PixelFormat::RGBA8UnormSRGB, true), + (PixelFormat::BGRA8Unorm, true), + (PixelFormat::RGBA16Float, true), + (PixelFormat::R32Float, true), + (PixelFormat::RGBA8Uint, false), + (PixelFormat::R32Sint, false), + (PixelFormat::BC1RGBA, false), + (PixelFormat::Depth32Float, false), + (PixelFormat::Stencil8, false), + ] { + assert_eq!(mipmapped(pf), expected, "{pf:?}"); + } +} + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::tests::blit::on_device::settled; + use crate::tests::command::on_device::{each_device, finished}; + use crate::{ + BlitCommandEncoder, Device, Error, PixelFormat, Refusal, Region, StorageMode, Texture, + TextureDescriptor, TextureType, TextureUsage, + }; + + /// The texture's side, and its levels. + const SIDE: u32 = 8; + const LEVELS: u32 = 4; + + /// A Shared 2D texture of `pf`, `SIDE` square, of `levels` levels. + fn texture(name: &str, device: &Device, pf: PixelFormat, levels: u32) -> Texture { + let mut d = TextureDescriptor::new(TextureType::Type2D, pf, SIDE, SIDE); + d.mipmap_level_count = levels; + d.usage = TextureUsage::RENDER_TARGET; + d.storage_mode = StorageMode::Shared; + (device.new_texture(&d, None)).unwrap_or_else(|error| panic!("{name}: {error}")) + } + + /// Level `level` of an `RGBA8Unorm` texture, row by row. + fn level_bytes(name: &str, texture: &Texture, level: u32) -> Vec { + let side = (SIDE >> level).max(1); + let mut bytes = vec![0u8; (side * side * 4) as usize]; + let whole = Region { + origin: [0; 3], + size: [side, side, 1], + }; + let row = u64::from(side) * 4; + (texture.get_bytes(&mut bytes, row, row * u64::from(side), whole, level, 0)) + .unwrap_or_else(|error| panic!("{name}: level {level}: {error}")); + bytes + } + + /// One blit encoder's `generate_mipmaps` of `texture`, committed and finished. + fn generate(name: &str, device: &Device, texture: &Texture) -> Result<(), Error> { + let queue = device.new_command_queue(1).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder: BlitCommandEncoder = + (command_buffer.blit_command_encoder()).expect("an encoder"); + let generated = encoder.generate_mipmaps(texture); + encoder.end_encoding(); + command_buffer.commit().expect("a commit"); + finished(name, &command_buffer); + assert_eq!(command_buffer.error(), None, "{name}"); + generated + } + + #[test] + fn every_device_makes_each_level_a_box_of_the_one_above() { + each_device("mipmaps", |name, _, device| { + let mipmapped = texture(name, &device, PixelFormat::RGBA8Unorm, LEVELS); + // Texel (x, y)'s channel c, a pattern no box of four texels makes even. + let first: Vec = (0..SIDE * SIDE * 4) + .map(|i| { + let (texel, c) = (i / 4, i % 4); + ((texel % SIDE) * 37 + (texel / SIDE) * 59 + c * 83) as u8 + }) + .collect(); + let whole = Region { + origin: [0; 3], + size: [SIDE, SIDE, 1], + }; + let row = u64::from(SIDE) * 4; + (mipmapped.replace_region(whole, 0, 0, &first, row, row * u64::from(SIDE))) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let counters = device.counters(); + settled(&device); + let before = counters.metrics(); + (generate(name, &device, &mipmapped)).unwrap_or_else(|e| panic!("{name}: {e}")); + let after = counters.metrics(); + assert_eq!( + ( + after.submissions - before.submissions, + after.barriers - before.barriers + ), + (1, u64::from(LEVELS) + 1), + "{name}: submissions, barriers (the chain's and the segment's end)" + ); + assert_eq!(level_bytes(name, &mipmapped, 0), first, "{name}: level 0"); + let mut worst = 0.0f32; + for level in 1..LEVELS { + let above = level_bytes(name, &mipmapped, level - 1); + let got = level_bytes(name, &mipmapped, level); + let (side, wide) = ((SIDE >> level) as usize, (SIDE >> (level - 1)) as usize); + for y in 0..side { + for x in 0..side { + for c in 0..4 { + let at = |x: usize, y: usize| f32::from(above[(y * wide + x) * 4 + c]); + let (x2, y2) = (2 * x, 2 * y); + let boxed = + (at(x2, y2) + at(x2 + 1, y2) + at(x2, y2 + 1) + at(x2 + 1, y2 + 1)) + / 4.0; + let texel = f32::from(got[(y * side + x) * 4 + c]); + let off = (texel - boxed).abs(); + worst = worst.max(off); + assert!( + off <= 1.0, + "{name}: level {level} texel ({x}, {y}) channel {c}: {texel} \ + against the box {boxed}" + ); + } + } + } + } + + // One level: nothing to make, nothing recorded but the command buffer's own. + let one = texture(name, &device, PixelFormat::RGBA8Unorm, 1); + settled(&device); + let before = counters.metrics(); + (generate(name, &device, &one)).unwrap_or_else(|e| panic!("{name}: {e}")); + let after = counters.metrics(); + assert_eq!(after.barriers, before.barriers, "{name}: one level"); + + // An integer format: Apple defines no mipmaps of it. + let integer = texture(name, &device, PixelFormat::RGBA8Uint, LEVELS); + match generate(name, &device, &integer) { + Err(Error::Refused(Refusal::MipmapFormat { + pixel_format: PixelFormat::RGBA8Uint, + })) => {} + other => panic!("{name}: an integer format's mipmaps: {other:?}"), + } + drop((mipmapped, one, integer)); + println!( + "{name}: each of {} levels within {worst} of a code of the box above", + LEVELS - 1 + ); + }); + } +} diff --git a/crates/metal2vulkan-rt/src/tests/mod.rs b/crates/metal2vulkan-rt/src/tests/mod.rs index 3f6c8b85d..26fcaa3a6 100644 --- a/crates/metal2vulkan-rt/src/tests/mod.rs +++ b/crates/metal2vulkan-rt/src/tests/mod.rs @@ -23,6 +23,7 @@ pub(crate) mod layouts; mod locks; mod managed; mod memory; +mod mipmaps; mod narrow; mod null_descriptor; mod one_path; diff --git a/crates/metal2vulkan-rt/src/texture.rs b/crates/metal2vulkan-rt/src/texture.rs index 069e79bce..bf1b5de2d 100644 --- a/crates/metal2vulkan-rt/src/texture.rs +++ b/crates/metal2vulkan-rt/src/texture.rs @@ -2476,6 +2476,32 @@ impl TextureInner { fn base(&self) -> [u32; 2] { self.view.as_ref().map_or([0, 0], |view| view.base) } + + /// A layout change of the texture's levels `levels`, counted from its first, over each of its + /// slices and every aspect, from `old` to `new`, `None` naming the image's home layout, with + /// no scopes yet. + fn levels_barrier( + &self, + levels: Range, + old: Option, + new: Option, + ) -> vk::ImageMemoryBarrier2<'static> { + let [level, layer] = self.base(); + let home = self.image.home; + vk::ImageMemoryBarrier2::default() + .old_layout(old.unwrap_or(home)) + .new_layout(new.unwrap_or(home)) + .src_queue_family_index(vk::QUEUE_FAMILY_IGNORED) + .dst_queue_family_index(vk::QUEUE_FAMILY_IGNORED) + .image(self.image.image) + .subresource_range(vk::ImageSubresourceRange { + aspect_mask: self.image.aspects, + base_mip_level: level + levels.start, + level_count: levels.end - levels.start, + base_array_layer: layer, + layer_count: slices(&self.descriptor), + }) + } } impl Texture { @@ -2881,6 +2907,24 @@ impl Texture { self.inner.format } + /// The format its image is made in, which a blit of the image filters by: a view in another + /// format's differs from [`format`](Self::format). + pub(crate) fn image_format(&self) -> vk::Format { + self.inner.image.format + } + + /// A layout change of its levels `levels`, counted from its first, over each of its slices, + /// from `old` to `new`, `None` naming its home layout, with no scopes yet + /// ([`BlitCommandEncoder::generate_mipmaps`](crate::BlitCommandEncoder::generate_mipmaps)). + pub(crate) fn levels_barrier( + &self, + levels: Range, + old: Option, + new: Option, + ) -> vk::ImageMemoryBarrier2<'static> { + self.inner.levels_barrier(levels, old, new) + } + /// How its image holds its pixel format. pub(crate) fn emulation(&self) -> FormatEmulation { self.inner.emulation diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index bef085dfc..1f900626a 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -245,13 +245,15 @@ macro_rules! degradations { /// profile of `Device::from_queries` records, announces this runtime's kind for the /// same codes, [`Degradation::SnormMinimumKept`]; [`PrecisionNote::DepthDenormals`], /// which `metal2vulkan-rt`'s depth-stencil state carries, announces - /// [`Degradation::DepthDenormals`]. + /// [`Degradation::DepthDenormals`]; and [`PrecisionNote::DeviceFilteredMipmaps`], which + /// its blit encoder carries, [`Degradation::DeviceFilteredMipmaps`]. pub const fn from_precision_note(note: PrecisionNote) -> Degradation { match note { $(PrecisionNote::$note => Degradation::$note,)* PrecisionNote::CappedLodBias => Degradation::CappedLodBias, PrecisionNote::SnormMinimumKept => Degradation::SnormMinimumKept, PrecisionNote::DepthDenormals => Degradation::DepthDenormals, + PrecisionNote::DeviceFilteredMipmaps => Degradation::DeviceFilteredMipmaps, PrecisionNote::DeviceReconvergence => { Degradation::ImplementationDefinedReconvergence } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index e8ebdffaf..6fb71c8a0 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -345,7 +345,8 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::DeviceReconvergence | N::SnormMinimumKept | N::DeviceDepthBias - | N::DepthDenormals => Allowance::Unbounded, + | N::DepthDenormals + | N::DeviceFilteredMipmaps => Allowance::Unbounded, } } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs index 77df18f61..9c6414311 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -84,6 +84,7 @@ fn every_precision_note_has_its_table_row() { (N::SnormMinimumKept, Allowance::Unbounded), (N::DeviceDepthBias, Allowance::Unbounded), (N::DepthDenormals, Allowance::Unbounded), + (N::DeviceFilteredMipmaps, Allowance::Unbounded), ]; for (note, expected) in rows { assert_eq!(allowance(note), expected, "{note:?}"); diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs index 531dd0133..b5027ddac 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs @@ -664,8 +664,8 @@ impl NewRuntime { Ok(()) } "generateMipmapsForTexture:" => { - self.skips.mipmaps += 1; - Ok(()) + let texture = self.texture_of(call, Self::id(call, 0)?)?; + self.blit(id).generate_mipmaps(&texture) } _ => return Err(refuse(call, "not played on a blit encoder")), }; diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs index 5cdb6dd2e..65839dc05 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs @@ -61,10 +61,8 @@ struct Skips { /// Pieces of the host's copies from the guest's RAM that the play cannot copy: a piece not of /// whole 4-byte words at a 4-byte offset into a buffer with no mapping to fill the rest from. guest_ram_writes: u64, - /// `synchronizeTexture:slice:level:` and `generateMipmapsForTexture:`, which the runtime - /// does not build yet. + /// `synchronizeTexture:slice:level:`, which the runtime does not build yet. texture_syncs: u64, - mipmaps: u64, /// Sampler binds of LOD clamps the runtime answers with `Gap::LodClamps`: clamps whose samples /// read otherwise than the sampler's own. clamped_samplers: u64, @@ -125,7 +123,6 @@ impl Skips { blits, guest_ram_writes, texture_syncs, - mipmaps, clamped_samplers, calls, resource_ids, @@ -138,7 +135,6 @@ impl Skips { blits, guest_ram_writes, texture_syncs, - mipmaps, clamped_samplers, calls, resource_ids, @@ -2198,7 +2194,6 @@ impl Backend for NewRuntime { ("copied_back_guest_ram_bytes", self.copied_back_bytes), ("skipped_guest_ram_writes", self.skips.guest_ram_writes), ("skipped_texture_syncs", self.skips.texture_syncs), - ("skipped_mipmaps", self.skips.mipmaps), ("skipped_clamped_samplers", self.skips.clamped_samplers), ("substituted_surface_textures", self.substitutes.surfaces), ("substituted_tiled_textures", self.substitutes.tiled), diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index bcf174a71..72b24e14a 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1536,6 +1536,7 @@ codec_enum! { SnormMinimumKept, DeviceDepthBias, DepthDenormals, + DeviceFilteredMipmaps, } BindingSource { Buffer(f0), Texture(f0), Sampler(f0), CombinedTextureSampler { texture, sampler }, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 5731b53fa..09cec6001 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -72,7 +72,7 @@ pub const SEMANTICS_VERSION: u32 = 2184; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 540; +pub const ARTIFACT_FORMAT_VERSION: u32 = 541; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 21aa7fc3e..8132422a3 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -2456,6 +2456,22 @@ pub enum PrecisionNote { /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. DepthDenormals, + /// `generateMipmapsForTexture:` of a filterable colour format: each level below the first is + /// the device's linear filter of the one above, its blit (`vkCmdBlitImage` with + /// `VK_FILTER_LINEAR`, the level above sampled at each texel's centre scaled into it). + /// Apple's documentation states no filter. Metal filters bilinearly at the same scaled + /// centres, measured on an M3 Max and an M4, but by Apple's datapath, whose answers differ + /// between those GPUs by up to a unit in the last place (`metal2vulkan-runtime`'s + /// `device-filtered-mipmaps`). Where a level halves an even size, each sample falls between + /// two texels on the axis, so the filter is a box of them at the device's filter precision; an + /// sRGB format is filtered in linear space. Static per operation: no + /// pipeline stage records it; `metal2vulkan-rt`'s blit encoder carries it + /// (`BlitCommandEncoder::GENERATE_MIPMAPS_NOTE`). `metal2vulkan-runtime` announces the same + /// difference as its `device-filtered-mipmaps` kind, which this note announces too. + /// + /// Validation derives no tolerance from it: a difference stays a mismatch, which the note + /// explains. + DeviceFilteredMipmaps, } /// The math mode of an entry's module, which decides, on a device whose `float` functions are diff --git a/crates/metal2vulkan/src/tests/fast_paths.rs b/crates/metal2vulkan/src/tests/fast_paths.rs index 0c4c3b193..cb7eb172c 100644 --- a/crates/metal2vulkan/src/tests/fast_paths.rs +++ b/crates/metal2vulkan/src/tests/fast_paths.rs @@ -233,6 +233,7 @@ fn notes() -> Vec<(&'static str, Ledger)> { SnormMinimumKept, DeviceDepthBias, DepthDenormals, + DeviceFilteredMipmaps, ], } } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 922755250..8108518ee 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -43,6 +43,7 @@ assoc-const metal2vulkan-air::ir::BinOp::ALL pub const ALL: [BinOp; 18] assoc-const metal2vulkan-air::ir::FloatPredicate::ALL pub const ALL: [FloatPredicate; 16] assoc-const metal2vulkan-air::ir::IntPredicate::ALL pub const ALL: [IntPredicate; 10] assoc-const metal2vulkan-air::metal::DataType::ALL pub const ALL: [DataType; 17] +assoc-const metal2vulkan-rt::BlitCommandEncoder::GENERATE_MIPMAPS_NOTE pub const GENERATE_MIPMAPS_NOTE: PrecisionNote assoc-const metal2vulkan-rt::RenderCommandEncoder::DEPTH_BIAS_NOTE pub const DEPTH_BIAS_NOTE: PrecisionNote assoc-const metal2vulkan-rt::ResourceUsage::READ pub const READ: ResourceUsage assoc-const metal2vulkan-rt::ResourceUsage::SAMPLE pub const SAMPLE: ResourceUsage @@ -572,6 +573,7 @@ assoc-const-value metal2vulkan-air::ir::BinOp::ALL [BinOp::Add, BinOp::Sub, BinO assoc-const-value metal2vulkan-air::ir::FloatPredicate::ALL [FloatPredicate::False, FloatPredicate::Oeq, FloatPredicate::Ogt, FloatPredicate::Oge, FloatPredicate::Olt, FloatPredicate::Ole, FloatPredicate::One, FloatPredicate::Ord, FloatPredicate::Uno, FloatPredicate::Ueq, FloatPredicate::Ugt, FloatPredicate::Uge, FloatPredicate::Ult, FloatPredicate::Ule, FloatPredicate::Une, FloatPredicate::True] assoc-const-value metal2vulkan-air::ir::IntPredicate::ALL [IntPredicate::Eq, IntPredicate::Ne, IntPredicate::Ugt, IntPredicate::Uge, IntPredicate::Ult, IntPredicate::Ule, IntPredicate::Sgt, IntPredicate::Sge, IntPredicate::Slt, IntPredicate::Sle] assoc-const-value metal2vulkan-air::metal::DataType::ALL [DataType::Float32, DataType::Float16, DataType::BFloat16, DataType::Int2, DataType::Int4, DataType::Int8, DataType::Int16, DataType::Int32, DataType::UInt2, DataType::UInt4, DataType::UInt8, DataType::UInt16, DataType::UInt32, DataType::Fp4E2M1, DataType::Fp8E4M3, DataType::Fp8E5M2, DataType::Fp8UE8M0] +assoc-const-value metal2vulkan-rt::BlitCommandEncoder::GENERATE_MIPMAPS_NOTE PrecisionNote::DeviceFilteredMipmaps assoc-const-value metal2vulkan-rt::RenderCommandEncoder::DEPTH_BIAS_NOTE PrecisionNote::DeviceDepthBias assoc-const-value metal2vulkan-rt::ResourceUsage::READ ResourceUsage(1) assoc-const-value metal2vulkan-rt::ResourceUsage::SAMPLE ResourceUsage(4) @@ -9099,7 +9101,7 @@ macro-template metal2vulkan-rt::vk_bit! ( $(#[$meta:meta])* $name:ident($raw:ty) macro-template metal2vulkan-rt::vk_enum! ( $(#[$meta:meta])* $name:ident($raw:ty) = $vk:literal { $($konst:ident = $value:literal, $vkname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] pub struct $name($raw); impl $name { $( #[doc = concat!("`", $vkname, "`.")] pub const $konst: $name = $name($value); )* pub const VK_NAME: &'static str = $vk; pub const KNOWN: &'static [$name] = &[$($name::$konst),*]; const NAMES: &'static [($name, &'static str)] = &[$(($name::$konst, $vkname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn from_raw(raw: $raw) -> $name { $name(raw) } pub const fn as_raw(self) -> $raw { self.0 } pub fn name(self) -> Option<&'static str> { Self::NAMES.iter().find(|(v, _)| *v == self).map(|(_, n)| *n) } pub fn is_known(self) -> bool { self.name().is_some() } pub fn from_name(name: &str) -> Option<$name> { Self::NAMES .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { match self.name() { Some(name) => f.write_str(name), None => write!(f, "{}({})", $vk, self.0), } } } }; macro-template metal2vulkan-rt::vk_flags! ( $(#[$meta:meta])* $name:ident($raw:ty) = $vk:literal { $($konst:ident = $value:literal, $vkname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] pub struct $name($raw); impl $name { $( #[doc = concat!("`", $vkname, "`.")] pub const $konst: $name = $name($value); )* pub const VK_NAME: &'static str = $vk; pub const KNOWN: &'static [($name, &'static str)] = &[$(($name::$konst, $vkname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn empty() -> $name { $name(0) } pub const fn from_raw(raw: $raw) -> $name { $name(raw) } pub const fn as_raw(self) -> $raw { self.0 } pub const fn is_empty(self) -> bool { self.0 == 0 } pub const fn contains(self, other: $name) -> bool { self.0 & other.0 == other.0 } pub const fn intersects(self, other: $name) -> bool { self.0 & other.0 != 0 } pub const fn union(self, other: $name) -> $name { $name(self.0 | other.0) } pub const fn intersection(self, other: $name) -> $name { $name(self.0 & other.0) } pub const fn difference(self, other: $name) -> $name { $name(self.0 & !other.0) } pub const fn known_bits() -> $name { let mut bits: $raw = 0; let mut i = 0; while i < Self::KNOWN.len() { let v = Self::KNOWN[i].0 .0; if v.count_ones() == 1 { bits |= v; } i += 1; } $name(bits) } pub fn name(self) -> Option<&'static str> { Self::KNOWN.iter().find(|(v, _)| *v == self).map(|(_, n)| *n) } pub fn from_name(name: &str) -> Option<$name> { Self::KNOWN .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl ::std::ops::BitOr for $name { type Output = $name; fn bitor(self, rhs: $name) -> $name { self.union(rhs) } } impl ::std::ops::BitOrAssign for $name { fn bitor_assign(&mut self, rhs: $name) { *self = self.union(rhs); } } impl ::std::ops::BitAnd for $name { type Output = $name; fn bitand(self, rhs: $name) -> $name { self.intersection(rhs) } } impl ::std::ops::BitAndAssign for $name { fn bitand_assign(&mut self, rhs: $name) { *self = self.intersection(rhs); } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { if let Some(name) = self.name() { return f.write_str(name); } let mut rest = self.0; let mut first = true; for (v, n) in Self::KNOWN { if v.0.count_ones() == 1 && rest & v.0 != 0 { if !first { f.write_str(" | ")?; } f.write_str(n)?; rest &= !v.0; first = false; } } if rest != 0 || first { if !first { f.write_str(" | ")?; } write!(f, "{:#x}", rest)?; } Ok(()) } } }; macro-template metal2vulkan-runtime::commands! ( v1_0 { $($v0:ident $f0:ident $n0:literal ($($a0:ident: $t0:ty),*) $(-> $r0:ty)?;)* } v1_3 { $($v3:ident $f3:ident $n3:literal ($($a3:ident: $t3:ty),*) $(-> $r3:ty)?;)* } extension { $($ve:ident $fe:ident $ne:literal ($($ae:ident: $te:ty),*) $(-> $re:ty)?;)* } ) => { #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub(crate) enum Command { $($v0,)* $($v3,)* $($ve,)* } impl Command { pub(crate) const ALL: &'static [Command] = &[ $(Command::$v0,)* $(Command::$v3,)* $(Command::$ve,)* ]; pub(crate) const COUNT: usize = Command::ALL.len(); pub(crate) fn name(self) -> &'static CStr { match self { $(Command::$v0 => $n0,)* $(Command::$v3 => $n3,)* $(Command::$ve => $ne,)* } } } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct CommandsRecorded { $( #[doc = concat!("The calls of `", stringify!($v0), "`.")] pub $f0: u64, )* $( #[doc = concat!("The calls of `", stringify!($v3), "`.")] pub $f3: u64, )* $( #[doc = concat!("The calls of `", stringify!($ve), "`.")] pub $fe: u64, )* } impl CommandsRecorded { fn read(shards: &[Shard; SHARDS + 1]) -> CommandsRecorded { let sum = |command: Command| { let counts = shards.iter().map(|shard| &shard.0[command as usize]); counts.map(|count| count.load(Ordering::Relaxed)).sum() }; CommandsRecorded { $($f0: sum(Command::$v0),)* $($f3: sum(Command::$v3),)* $($fe: sum(Command::$ve),)* } } } struct Real { $($f0: [AtomicPtr; SLOTS],)* $($f3: [AtomicPtr; SLOTS],)* $($fe: [AtomicPtr; SLOTS],)* } static REAL: Real = Real { $($f0: [const { AtomicPtr::new(std::ptr::null_mut()) }; SLOTS],)* $($f3: [const { AtomicPtr::new(std::ptr::null_mut()) }; SLOTS],)* $($fe: [const { AtomicPtr::new(std::ptr::null_mut()) }; SLOTS],)* }; commands!(@thunks $($v0 $f0 $n0 ($($a0: $t0),*) $(-> $r0)?;)*); commands!(@thunks $($v3 $f3 $n3 ($($a3: $t3),*) $(-> $r3)?;)*); commands!(@thunks $($ve $fe $ne ($($ae: $te),*) $(-> $re)?;)*); pub(super) fn thunk(command: Command) -> *const c_void { match command { $(Command::$v0 => $f0:: as *const c_void,)* $(Command::$v3 => $f3:: as *const c_void,)* $(Command::$ve => $fe:: as *const c_void,)* } } pub(super) fn store(index: usize, command: Command, real: *const c_void) { let real = real.cast_mut(); match command { $(Command::$v0 => REAL.$f0[index].store(real, Ordering::Release),)* $(Command::$v3 => REAL.$f3[index].store(real, Ordering::Release),)* $(Command::$ve => REAL.$fe[index].store(real, Ordering::Release),)* } } pub(super) fn real(index: usize, command: Command) -> *const c_void { let real = match command { $(Command::$v0 => REAL.$f0[index].load(Ordering::Acquire),)* $(Command::$v3 => REAL.$f3[index].load(Ordering::Acquire),)* $(Command::$ve => REAL.$fe[index].load(Ordering::Acquire),)* }; real.cast_const() } pub(super) fn clear(index: usize) { $(REAL.$f0[index].store(std::ptr::null_mut(), Ordering::Release);)* $(REAL.$f3[index].store(std::ptr::null_mut(), Ordering::Release);)* $(REAL.$fe[index].store(std::ptr::null_mut(), Ordering::Release);)* } pub(super) fn route_tables( v1_0: &mut ash::DeviceFnV1_0, v1_3: &mut ash::DeviceFnV1_3, ) { $( store(S, Command::$v0, v1_0.$f0 as *const c_void); v1_0.$f0 = $f0::; )* $( store(S, Command::$v3, v1_3.$f3 as *const c_void); v1_3.$f3 = $f3::; )* } }; (@thunks $($v:ident $f:ident $n:literal ($($a:ident: $t:ty),*) $(-> $r:ty)?;)*) => { $( unsafe extern "system" fn $f( command_buffer: vk::CommandBuffer, $($a: $t,)* ) $(-> $r)? { let at = held(); crate::shards::add(at, &COUNTS[S][at].0[Command::$v as usize], 1); let real = REAL.$f[S].load(Ordering::Acquire); if real.is_null() { missing($n); } unsafe { let real = std::mem::transmute::< *mut c_void, unsafe extern "system" fn(vk::CommandBuffer, $($t,)*) $(-> $r)?, >(real); real(command_buffer, $($a,)*) } } )* }; -macro-template metal2vulkan-runtime::degradations! ( runtime { $( $(#[doc = $doc:literal])* $kind:ident = $code:literal, $category:ident, $cost:literal; )* } notes { $( $(#[doc = $note_doc:literal])* $note:ident = $note_code:literal; )* } ) => { #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Degradation { $($(#[doc = $doc])* $kind,)* $( #[doc = concat!( "A pipeline stage records [`PrecisionNote::", stringify!($note), "`]." )] $(#[doc = $note_doc])* $note, )* } impl Degradation { pub const ALL: &'static [Degradation] = &[$(Degradation::$kind,)* $(Degradation::$note,)*]; pub const fn code(self) -> &'static str { match self { $(Degradation::$kind => concat!("metal2vulkan-degrade-", $code),)* $(Degradation::$note => concat!("metal2vulkan-degrade-", $note_code),)* } } pub const fn category(self) -> DegradationCategory { match self { $(Degradation::$kind => DegradationCategory::$category,)* $(Degradation::$note => DegradationCategory::Precision,)* } } pub const fn cost(self) -> &'static str { match self { $(Degradation::$kind => $cost,)* $(Degradation::$note => NOTE_COST,)* } } pub const fn precision_note(self) -> Option { match self { $(Degradation::$kind => None,)* $(Degradation::$note => Some(PrecisionNote::$note),)* } } pub const fn from_precision_note(note: PrecisionNote) -> Degradation { match note { $(PrecisionNote::$note => Degradation::$note,)* PrecisionNote::CappedLodBias => Degradation::CappedLodBias, PrecisionNote::SnormMinimumKept => Degradation::SnormMinimumKept, PrecisionNote::DepthDenormals => Degradation::DepthDenormals, PrecisionNote::DeviceReconvergence => { Degradation::ImplementationDefinedReconvergence } } } } }; +macro-template metal2vulkan-runtime::degradations! ( runtime { $( $(#[doc = $doc:literal])* $kind:ident = $code:literal, $category:ident, $cost:literal; )* } notes { $( $(#[doc = $note_doc:literal])* $note:ident = $note_code:literal; )* } ) => { #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Degradation { $($(#[doc = $doc])* $kind,)* $( #[doc = concat!( "A pipeline stage records [`PrecisionNote::", stringify!($note), "`]." )] $(#[doc = $note_doc])* $note, )* } impl Degradation { pub const ALL: &'static [Degradation] = &[$(Degradation::$kind,)* $(Degradation::$note,)*]; pub const fn code(self) -> &'static str { match self { $(Degradation::$kind => concat!("metal2vulkan-degrade-", $code),)* $(Degradation::$note => concat!("metal2vulkan-degrade-", $note_code),)* } } pub const fn category(self) -> DegradationCategory { match self { $(Degradation::$kind => DegradationCategory::$category,)* $(Degradation::$note => DegradationCategory::Precision,)* } } pub const fn cost(self) -> &'static str { match self { $(Degradation::$kind => $cost,)* $(Degradation::$note => NOTE_COST,)* } } pub const fn precision_note(self) -> Option { match self { $(Degradation::$kind => None,)* $(Degradation::$note => Some(PrecisionNote::$note),)* } } pub const fn from_precision_note(note: PrecisionNote) -> Degradation { match note { $(PrecisionNote::$note => Degradation::$note,)* PrecisionNote::CappedLodBias => Degradation::CappedLodBias, PrecisionNote::SnormMinimumKept => Degradation::SnormMinimumKept, PrecisionNote::DepthDenormals => Degradation::DepthDenormals, PrecisionNote::DeviceFilteredMipmaps => Degradation::DeviceFilteredMipmaps, PrecisionNote::DeviceReconvergence => { Degradation::ImplementationDefinedReconvergence } } } } }; macro-template metal2vulkan-runtime::exposures! ($($exposure:expr => [$($feature:ident),* $(,)?];)*) => { impl VkFeature { pub const ALL: &'static [VkFeature] = &[$($(VkFeature::$feature),*),*]; pub fn exposure(self) -> Exposure { match self { $($(VkFeature::$feature)|* => $exposure,)* } } } }; macro-template metal2vulkan-runtime::flag_set! ( $(#[$doc:meta])* $name:ident { $($(#[$fdoc:meta])* $flag:ident = $bit:expr),* $(,)? } $(#[$all:meta])* ALL ) => { $(#[$doc])* #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct $name(u8); impl $name { pub const NONE: $name = $name(0); $($(#[$fdoc])* pub const $flag: $name = $name($bit);)* $(#[$all])* pub const ALL: &'static [($name, &'static str)] = &[$(($name::$flag, stringify!($flag))),*]; pub const fn union(self, other: $name) -> $name { $name(self.0 | other.0) } pub const fn contains(self, other: $name) -> bool { self.0 & other.0 == other.0 } #[cfg(test)] pub const fn bits(self) -> u8 { self.0 } } }; macro-template metal2vulkan-runtime::id_type! ($(#[$doc:meta])* $name:ident) => { $(#[$doc])* #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $name(pub u32); impl $name { pub const fn new(index: u32) -> $name { $name(index) } pub const fn index(self) -> usize { self.0 as usize } } }; @@ -9492,6 +9494,7 @@ method metal2vulkan-rt::BlitCommandEncoder::copy_from_texture pub fn copy_from_t method metal2vulkan-rt::BlitCommandEncoder::copy_from_texture_to_buffer pub fn copy_from_texture_to_buffer(&mut self, source: &Texture, from: TexturePlace, size: [u32; 3], destination: &Buffer, layout: BufferLayout) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::end_encoding pub fn end_encoding(mut self) method metal2vulkan-rt::BlitCommandEncoder::fill_buffer pub fn fill_buffer(&mut self, buffer: &Buffer, range: Range, value: u8) -> Result<(), Error> +method metal2vulkan-rt::BlitCommandEncoder::generate_mipmaps pub fn generate_mipmaps(&mut self, texture: &Texture) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::synchronize_resource pub fn synchronize_resource(&mut self, resource: Resource<'_>) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::update_fence pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> method metal2vulkan-rt::BlitCommandEncoder::wait_for_fence pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> @@ -13687,6 +13690,7 @@ variant metal2vulkan-rt::Gap::IndirectCommandBuffers IndirectCommandBuffers variant metal2vulkan-rt::Gap::KernelInput KernelInput variant metal2vulkan-rt::Gap::LodClamps LodClamps variant metal2vulkan-rt::Gap::MemorylessTexture MemorylessTexture +variant metal2vulkan-rt::Gap::MipmapFilter MipmapFilter { pixel_format: PixelFormat } variant metal2vulkan-rt::Gap::NoStageInRegion NoStageInRegion variant metal2vulkan-rt::Gap::PartialSimdgroups PartialSimdgroups { threads_per_threadgroup: [u32; 3], width: u32 } variant metal2vulkan-rt::Gap::PartialThreadgroups PartialThreadgroups { threads_per_grid: [u32; 3], threads_per_threadgroup: [u32; 3] } @@ -13736,6 +13740,7 @@ variant metal2vulkan-rt::PrecisionNote::DeviceArithmetic DeviceArithmetic variant metal2vulkan-rt::PrecisionNote::DeviceColorConversion DeviceColorConversion variant metal2vulkan-rt::PrecisionNote::DeviceDenormals DeviceDenormals variant metal2vulkan-rt::PrecisionNote::DeviceDepthBias DeviceDepthBias +variant metal2vulkan-rt::PrecisionNote::DeviceFilteredMipmaps DeviceFilteredMipmaps variant metal2vulkan-rt::PrecisionNote::DeviceInterpolation DeviceInterpolation variant metal2vulkan-rt::PrecisionNote::DeviceInterpolationOffset DeviceInterpolationOffset variant metal2vulkan-rt::PrecisionNote::DeviceNanEncoding DeviceNanEncoding @@ -13830,6 +13835,7 @@ variant metal2vulkan-rt::Refusal::ManagedCopyMissing ManagedCopyMissing variant metal2vulkan-rt::Refusal::ManagedCopyNotPrivate ManagedCopyNotPrivate { block: BlockId } variant metal2vulkan-rt::Refusal::ManagedCopyOnUnified ManagedCopyOnUnified variant metal2vulkan-rt::Refusal::ManagedTextureBytes ManagedTextureBytes { level: u32, slice: u32 } +variant metal2vulkan-rt::Refusal::MipmapFormat MipmapFormat { pixel_format: PixelFormat } variant metal2vulkan-rt::Refusal::ModifiedRange ModifiedRange { start: u64, length: u64, buffer_length: u64 } variant metal2vulkan-rt::Refusal::NoBufferAtIndex NoBufferAtIndex { index: u32 } variant metal2vulkan-rt::Refusal::NoCommandBuffers NoCommandBuffers @@ -16672,6 +16678,7 @@ variant metal2vulkan::pipeline::PrecisionNote::DeviceArithmetic DeviceArithmetic variant metal2vulkan::pipeline::PrecisionNote::DeviceColorConversion DeviceColorConversion variant metal2vulkan::pipeline::PrecisionNote::DeviceDenormals DeviceDenormals variant metal2vulkan::pipeline::PrecisionNote::DeviceDepthBias DeviceDepthBias +variant metal2vulkan::pipeline::PrecisionNote::DeviceFilteredMipmaps DeviceFilteredMipmaps variant metal2vulkan::pipeline::PrecisionNote::DeviceInterpolation DeviceInterpolation variant metal2vulkan::pipeline::PrecisionNote::DeviceInterpolationOffset DeviceInterpolationOffset variant metal2vulkan::pipeline::PrecisionNote::DeviceNanEncoding DeviceNanEncoding diff --git a/docs/API.md b/docs/API.md index 49454d463..07981d898 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3321,6 +3321,9 @@ bound. above (its blit, or a bilinear filter in float where its blits cannot filter the format), not Apple's: a channel can differ from Metal's where the filtered value lies near a rounding boundary, and wholly where a box averages infinities, NaNs or a float format's extremes. + On `metal2vulkan-rt` it is the static note `PrecisionNote::DeviceFilteredMipmaps` of + `generate_mipmaps` (`BlitCommandEncoder::GENERATE_MIPMAPS_NOTE`), its blit chain alone, on every + device: a format the device's blits cannot filter is `Gap::MipmapFilter`. - `metal2vulkan-degrade-heap-depth-stencil-apart` (precision). `HeapDepthStencilApart`: A depth or stencil texture made in a heap on a device whose driver lays depth and stencil images apart from the memory they are bound to (`DriverFact::DepthStencilImagesLieApart`) that no shadow of the diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index a9609eee8..df0e995cf 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -37,9 +37,9 @@ Columns: | What a call did wrong | 73 | 73 | 0 | 0 | 0 | 0 | 0 | | What a call did wrong, in detail | 174 | 157 | 0 | 0 | 0 | 0 | 0 | | Devices below the new runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 | -| The new runtime's `Refusal` | 58 | 58 | 0 | 0 | 0 | 0 | 0 | +| The new runtime's `Refusal` | 59 | 59 | 0 | 0 | 0 | 0 | 0 | | The new runtime's `Limit` | 10 | 10 | 0 | 0 | 0 | 0 | 0 | -| The new runtime's `Gap` | 24 | 24 | 0 | 0 | 0 | 0 | 0 | +| The new runtime's `Gap` | 25 | 25 | 0 | 0 | 0 | 0 | 0 | ## Totals by basis @@ -55,9 +55,9 @@ Columns: | What a call did wrong | 22 | 3 | 5 | 0 | 18 | 8 | 17 | 0 | | What a call did wrong, in detail | 60 | 26 | 23 | 0 | 39 | 26 | 0 | 0 | | Devices below the new runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 | -| The new runtime's `Refusal` | 16 | 15 | 0 | 0 | 27 | 0 | 0 | 0 | +| The new runtime's `Refusal` | 17 | 15 | 0 | 0 | 27 | 0 | 0 | 0 | | The new runtime's `Limit` | 0 | 0 | 0 | 6 | 4 | 0 | 0 | 0 | -| The new runtime's `Gap` | 0 | 0 | 0 | 0 | 24 | 0 | 0 | 0 | +| The new runtime's `Gap` | 0 | 0 | 0 | 0 | 25 | 0 | 0 | 0 | ## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`) @@ -629,7 +629,7 @@ Columns: | `Committed` | A call on a command buffer already committed | every device (a public call's own check of its arguments) | `metal-documented`: Metal's validation asserts "commit an already committed command buffer", "Completed handler provided after commit call" and "Scheduled handler provided after commit call" | 1: `crates/metal2vulkan-rt/src/command.rs (open)` | `-` | | `InScheduledHandler` | A call a scheduled handler may not make (`CommandBuffer::add_scheduled_handler`) | every device (a public call's own check of its arguments) | `ours`: the consumer's scheduled handlers run on the submit thread, and the one consumer's make none of these calls; a guest's scheduled handler runs in the guest | 1: `crates/metal2vulkan-rt/src/command.rs (not_in_scheduled_handler)` | `-` | | `WaitOnOwnThread` | A wait, in a handler or a listener, for what the runtime thread that runs it would have to do first, so it would never end | every device (a public call's own check of its arguments) | `ours`: no wait of the runtime's hangs by construction | 4: `crates/metal2vulkan-rt/src/command.rs (wait_until_completed)`, `crates/metal2vulkan-rt/src/command.rs (wait_until_scheduled)` (+2) | `-` | -| `OtherDevice` | An event, a buffer, a texture or a pipeline state of another device in an encode call (`CommandBuffer::encode_wait_for_event`,... | every device (a public call's own check of its arguments) | `ours`: an event's semaphore, a buffer's block, a texture's image, a pipeline and a block belong to the `VkDevice` that made them | 23: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/blit.rs (copy_from_buffer_to_buffer)` (+20) | `-` | +| `OtherDevice` | An event, a buffer, a texture or a pipeline state of another device in an encode call (`CommandBuffer::encode_wait_for_event`,... | every device (a public call's own check of its arguments) | `ours`: an event's semaphore, a buffer's block, a texture's image, a pipeline and a block belong to the `VkDevice` that made them | 24: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/blit.rs (copy_from_buffer_to_buffer)` (+21) | `-` | | `NoCommandBuffers` | A queue that may hold no command buffer (`Device::new_command_queue` with a count of 0) | every device (a public call's own check of its arguments) | `ours`: its first `commandBuffer` call would wait forever | 1: `crates/metal2vulkan-rt/src/queue.rs (new_command_queue)` | `-` | | `EncoderOpen` | A second encoder, an encode call, or a commit or enqueue, while an encoder of the command buffer is open | every device (a public call's own check of its arguments) | `metal-documented`: a command buffer has one active encoder at a time, ended by `endEncoding` before another is made or the command buffer is committed | 1: `crates/metal2vulkan-rt/src/command.rs (open)` | `-` | | `NoPipeline` | A dispatch or a draw with no pipeline state set | every device (a public call's own check of its arguments) | `metal-documented`: a compute dispatch needs a compute pipeline state set first, and a draw a render pipeline state | 3: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`, `crates/metal2vulkan-rt/src/render_encoder.rs (draw)` (+1) | `-` | @@ -659,6 +659,7 @@ Columns: | `FillRange` | `BlitCommandEncoder::fill_buffer` of an empty range, or of one past the buffer's end | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `blit_fill_rules.m` in the conformance crate, job m3-max-43573: Metal's validation layer stops both, `range.length(0) must not be 0` and `(range.location + range.length)(68) must be <= [buffer length](64)` | 1: `crates/metal2vulkan-rt/src/blit.rs (fill_range)` | `-` | | `TextureViewRange` | `Texture::new_texture_view` of an empty range of levels or slices, or of one past the texture's | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `texture_view_rules.m` in the conformance crate, job m3-max-43677: Metal's validation layer stops each, `(newLevelRange.location + newLevelRange.length)(4) must be <= [texture mipmapLevelCount](3)`, `newLevelRange.length must not be 0` and `(newSliceRange.location + newSliceRange.length)(4) must be <= (3)` | 1: `crates/metal2vulkan-rt/src/texture.rs (new_texture_view_with_swizzle)` | `-` | | `TextureViewFormat` | `Texture::new_texture_view` of a pixel format Metal does not view the texture as | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `texture_view_rules.m` in the conformance crate, job m3-max-43677: Metal's validation layer stops an `R32Uint` view of an `RGBA8Unorm` texture of `ShaderRead` usage, `Texture View Validation`, and makes it where the usage adds `PixelFormatView`; Apple's `makeTextureView` and `MTLTextureUsage.pixelFormatView` pages state the rest | 1: `crates/metal2vulkan-rt/src/texture.rs (new_texture_view_with_swizzle)` | `-` | +| `MipmapFormat` | `BlitCommandEncoder::generate_mipmaps` of a texture of more than one level whose pixel format is not a colour-renderable, filterable one | every device (a public call's own check of its arguments) | `metal-measured`: Apple's `generateMipmaps(for:)` page: mipmap generation works only for textures with colour-renderable and colour-filterable pixel formats; Metal's API validation stops the others, measured on an Apple M3 Max and an M4 for `metal2vulkan-runtime`'s mipmap plan | 1: `crates/metal2vulkan-rt/src/blit.rs (generate_mipmaps)` | `-` | | `TextureCopyMismatch` | `BlitCommandEncoder::copy_from_texture` between textures of two pixel formats, or of two sample counts | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `blit_copy_format_pairs.m` in the conformance crate: Metal's validation layer stops every pair of two formats it was given, sRGB, integer, float, channel order, depth and compressed pairs among them, with `[sourceTexture pixelFormat](...) must equal [destinationTexture pixelFormat](...)`, and a source of four samples into one of one with `[sourceTexture sampleCount](4) must equal [destinationTexture sampleCount](1)` | 1: `crates/metal2vulkan-rt/src/blit.rs (texture_copy)` | `-` | | `ManagedTextureBytes` | A Managed texture's bytes the device cannot copy in place (`Device::new_managed_texture`) | every device (a public call's own check of its arguments) | `ours`: a buffer-to-image copy reads a place only so laid out, and the consumer's bytes are the place the copy reads | 5: `crates/metal2vulkan-rt/src/texture.rs (check_places)`, `crates/metal2vulkan-rt/src/texture.rs (named)` (+2) | `-` | | `BufferTextureLayout` | A texture over a buffer (`Buffer::new_texture`) whose rows are not a whole number of texels apart or are closer than a row, whose offset is not a... | every device (a public call's own check of its arguments) | `ours`: a linear image and a copy read rows whole texels apart from a texel's start, and texels past the buffer would lie in memory it does not hold | 1: `crates/metal2vulkan-rt/src/texture.rs (check_over)` | `-` | @@ -703,6 +704,7 @@ Columns: | `TextureBuffer` | A texture buffer (`MTLTextureTypeTextureBuffer`) | every device (a public call's own check of its arguments) | `ours`: no texel-buffer array; no replay stream uses one | 2: `crates/metal2vulkan-rt/src/texture.rs (shape, 2 sites)` | `-` | | `CubeArrayTexture` | A cube array texture (`MTLTextureTypeCubeArray`), and so a view of one | every device (a public call's own check of its arguments) | `ours`: no replay stream makes a cube array texture or view; built when one does | 1: `crates/metal2vulkan-rt/src/texture.rs (checked)` | `-` | | `TextureFormat` | A texture of a pixel format the runtime makes no image of on this device for the descriptor's usage | every device (a public call's own check of its arguments) | `ours`: the device's format query, or the identity domains' shaders read every texture through its view alone | 3: `crates/metal2vulkan-rt/src/texture.rs (attachment)`, `crates/metal2vulkan-rt/src/texture.rs (form)` (+1) | `-` | +| `MipmapFilter` | `BlitCommandEncoder::generate_mipmaps` of a texture whose image the device's blits do not filter | every device (a public call's own check of its arguments) | `ours`: the device's format query; the levels are the device's blit chain alone | 1: `crates/metal2vulkan-rt/src/blit.rs (generate_mipmaps)` | `-` | | `CubicSampler` | A sampler state whose minification or magnification filter is cubic (`Device::new_sampler_state`) | every device (a public call's own check of its arguments) | `ours`: the translator's identity domains do not filter bicubically, and Vulkan's cubic filter is not Metal's | 1: `crates/metal2vulkan-rt/src/sampler.rs (new_sampler_state)` | `-` | | `LodClamps` | A sampler state bound with LOD clamps its samples read otherwise through (`ComputeCommandEncoder::set_sampler_state_with_lod_clamps` and the... | every device (a public call's own check of its arguments) | `ours`: no replay stream binds such clamps: every bind-time clamp the streams make reads as its state's own | 1: `crates/metal2vulkan-rt/src/sampler.rs (clamps_at_bind)` | `-` | | `TextureBytes` | `Texture::replace_region`, `Texture::get_bytes` or a blit copy between a buffer and a texture (`BlitCommandEncoder::copy_from_buffer`) of a... | every device (a public call's own check of its arguments) | `ours`: no copy between such an image and bytes is built | 3: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-rt/src/texture.rs (check_places)` (+1) | `-` | @@ -1222,7 +1224,7 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::Committed`: `crates/metal2vulkan-rt/src/command.rs (open)` - `rt:Refusal::InScheduledHandler`: `crates/metal2vulkan-rt/src/command.rs (not_in_scheduled_handler)` - `rt:Refusal::WaitOnOwnThread`: `crates/metal2vulkan-rt/src/command.rs (wait_until_completed)`; `crates/metal2vulkan-rt/src/command.rs (wait_until_scheduled)`; `crates/metal2vulkan-rt/src/event.rs (wait_until_signaled_value)`; `crates/metal2vulkan-rt/src/queue.rs (command_buffer)` -- `rt:Refusal::OtherDevice`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_buffer_to_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-rt/src/blit.rs (fill_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (synchronize_resource)`; `crates/metal2vulkan-rt/src/command.rs (check)`; `crates/metal2vulkan-rt/src/device.rs (release_block)`; `crates/metal2vulkan-rt/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_compute_pipeline_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_sampler_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_texture)`; `crates/metal2vulkan-rt/src/encoder.rs (use_resource, 2 sites)`; `crates/metal2vulkan-rt/src/fence.rs (used_on)`; `crates/metal2vulkan-rt/src/pass.rs (check)`; `crates/metal2vulkan-rt/src/render_encoder.rs (draw)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_buffer)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_depth_stencil_state)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_render_pipeline_state)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_sampler_state)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_texture)`; `crates/metal2vulkan-rt/src/texture.rs (new_managed_texture)` +- `rt:Refusal::OtherDevice`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_buffer_to_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-rt/src/blit.rs (fill_buffer)`; `crates/metal2vulkan-rt/src/blit.rs (generate_mipmaps)`; `crates/metal2vulkan-rt/src/blit.rs (synchronize_resource)`; `crates/metal2vulkan-rt/src/command.rs (check)`; `crates/metal2vulkan-rt/src/device.rs (release_block)`; `crates/metal2vulkan-rt/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_buffer)`; `crates/metal2vulkan-rt/src/encoder.rs (set_compute_pipeline_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_sampler_state)`; `crates/metal2vulkan-rt/src/encoder.rs (set_texture)`; `crates/metal2vulkan-rt/src/encoder.rs (use_resource, 2 sites)`; `crates/metal2vulkan-rt/src/fence.rs (used_on)`; `crates/metal2vulkan-rt/src/pass.rs (check)`; `crates/metal2vulkan-rt/src/render_encoder.rs (draw)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_buffer)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_depth_stencil_state)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_render_pipeline_state)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_sampler_state)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_texture)`; `crates/metal2vulkan-rt/src/texture.rs (new_managed_texture)` - `rt:Refusal::NoCommandBuffers`: `crates/metal2vulkan-rt/src/queue.rs (new_command_queue)` - `rt:Refusal::EncoderOpen`: `crates/metal2vulkan-rt/src/command.rs (open)` - `rt:Refusal::NoPipeline`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`; `crates/metal2vulkan-rt/src/render_encoder.rs (draw)`; `crates/metal2vulkan-rt/src/render_encoder.rs (draw_reaches)` @@ -1252,6 +1254,7 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::FillRange`: `crates/metal2vulkan-rt/src/blit.rs (fill_range)` - `rt:Refusal::TextureViewRange`: `crates/metal2vulkan-rt/src/texture.rs (new_texture_view_with_swizzle)` - `rt:Refusal::TextureViewFormat`: `crates/metal2vulkan-rt/src/texture.rs (new_texture_view_with_swizzle)` +- `rt:Refusal::MipmapFormat`: `crates/metal2vulkan-rt/src/blit.rs (generate_mipmaps)` - `rt:Refusal::TextureCopyMismatch`: `crates/metal2vulkan-rt/src/blit.rs (texture_copy)` - `rt:Refusal::ManagedTextureBytes`: `crates/metal2vulkan-rt/src/texture.rs (check_places)`; `crates/metal2vulkan-rt/src/texture.rs (named)`; `crates/metal2vulkan-rt/src/texture.rs (named_host)`; `crates/metal2vulkan-rt/src/texture.rs (upload_region, 2 sites)` - `rt:Refusal::BufferTextureLayout`: `crates/metal2vulkan-rt/src/texture.rs (check_over)` @@ -1286,6 +1289,7 @@ Each refusal's sites, with the function that builds it. - `rt:Gap::TextureBuffer`: `crates/metal2vulkan-rt/src/texture.rs (shape, 2 sites)` - `rt:Gap::CubeArrayTexture`: `crates/metal2vulkan-rt/src/texture.rs (checked)` - `rt:Gap::TextureFormat`: `crates/metal2vulkan-rt/src/texture.rs (attachment)`; `crates/metal2vulkan-rt/src/texture.rs (form)`; `crates/metal2vulkan-rt/src/texture.rs (plan)` +- `rt:Gap::MipmapFilter`: `crates/metal2vulkan-rt/src/blit.rs (generate_mipmaps)` - `rt:Gap::CubicSampler`: `crates/metal2vulkan-rt/src/sampler.rs (new_sampler_state)` - `rt:Gap::LodClamps`: `crates/metal2vulkan-rt/src/sampler.rs (clamps_at_bind)` - `rt:Gap::TextureBytes`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-rt/src/texture.rs (check_places)`; `crates/metal2vulkan-rt/src/texture.rs (copy)` diff --git a/docs/REPLAY-STREAM.md b/docs/REPLAY-STREAM.md index 474e291c5..41524f65e 100644 --- a/docs/REPLAY-STREAM.md +++ b/docs/REPLAY-STREAM.md @@ -612,10 +612,10 @@ counted from 0), completes the work committed so far, reports as at the stream's whose samples read otherwise than the sampler's own: `skipped_clamped_samplers`), the draws while the slot holds one skipped with them; a bind it takes plays with its clamps; - blit commands that name a skipped object (`skipped_blits`), and by kind: - `synchronizeTexture:slice:level:` (`skipped_texture_syncs`), mipmaps (`skipped_mipmaps`), and - the pieces of a copy from the guest's RAM that are not whole 4-byte words at a 4-byte offset, - into a buffer with no mapping (`skipped_guest_ram_writes`). `optimizeContentsForGPUAccess:`, - a layout hint, plays as nothing. + `synchronizeTexture:slice:level:` (`skipped_texture_syncs`), and the pieces of a copy from + the guest's RAM that are not whole 4-byte words at a 4-byte offset, into a buffer with no + mapping (`skipped_guest_ram_writes`). `optimizeContentsForGPUAccess:`, a layout hint, plays + as nothing, and `generateMipmapsForTexture:` as the runtime's `generate_mipmaps`. A buffer-to-buffer copy plays as the runtime's (`copy_from_buffer_to_buffer`). A copy from the guest's RAM, the recording's plumbing, plays as its pieces' bytes in a Shared staging place of