diff --git a/crates/metal2vulkan-runtime/src/tests/extended_range.rs b/crates/metal2vulkan-runtime/src/tests/extended_range.rs index 8fdc27ba2..f104f9e51 100644 --- a/crates/metal2vulkan-runtime/src/tests/extended_range.rs +++ b/crates/metal2vulkan-runtime/src/tests/extended_range.rs @@ -13,7 +13,11 @@ //! - a gather of each component answers its four texels' values, and through the swizzled view //! the component the swizzle names, a `Zero` or `One` lane its constant; //! - a linear sample between four texels answers the value of their codes' mean, within the -//! device's filter. +//! device's filter; +//! - through an argument buffer (`examples/heap_samples`' `hs_sample`, a 2 by 2 `BGRA10_XR` texture +//! at its `half` member and a `BGR10_XR` one at its `float` member), a nearest sample at each +//! texel's centre through a constexpr sampler and through the sampler at slot 0 answers the +//! texel's value, a `half` one within a `half` step. //! //! `llvm-as` assembles the kernels; without it the test skips visibly. @@ -22,11 +26,11 @@ mod on_device { use crate::tests::command::on_device::{each_device, finished, Arena}; use crate::{ ComputePipelineDescriptor, ComputePipelineState, Device, DispatchType, FunctionDescriptor, - HostBytes, IndexClass, Library, PixelFormat, Region, SamplerDescriptor, - SamplerMinMagFilter, SamplerState, StageSource, StorageMode, Texture, TextureDescriptor, - TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage, + HostBytes, IndexClass, Library, PixelFormat, Region, Resource, ResourceUsage, + SamplerDescriptor, SamplerMinMagFilter, SamplerState, StageSource, StorageMode, Texture, + TextureDescriptor, TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage, }; - use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError}; + use metal2vulkan_devtools::{engine_dir, fixtures_dir, llvm_assemble, AssembleError}; /// The texture's width and height. const W: u32 = 4; @@ -97,7 +101,12 @@ mod on_device { /// `BGRA10_XR`'s four 16-bit fields (blue, green, red, alpha from the lowest, each code in the /// top 10 bits) with low bits. fn bytes(format: PixelFormat) -> Vec { - (CODES.iter().enumerate()) + bytes_of(format, &CODES) + } + + /// [`bytes`] of the texels `codes`. + fn bytes_of(format: PixelFormat, codes: &[[u32; 4]]) -> Vec { + (codes.iter().enumerate()) .flat_map(|(i, &[r, g, b, a])| { let odd = i % 2 == 1; match format { @@ -120,13 +129,18 @@ mod on_device { /// The fixture's library, or None where `llvm-as` is missing. fn library() -> Option { - match llvm_assemble(&engine_dir().join("fpv_swizzled_reads.ll")) { + library_at(&engine_dir().join("fpv_swizzled_reads.ll")) + } + + /// The library of the fixture at `path`, or None where `llvm-as` is missing. + fn library_at(path: &std::path::Path) -> Option { + match llvm_assemble(path) { Ok(bitcode) => Some(Library::from_air(&bitcode).expect("the library")), Err(AssembleError::Missing(why)) => { eprintln!("SKIPPED: {why}"); None } - Err(error) => panic!("fpv_swizzled_reads.ll: {error:?}"), + Err(error) => panic!("{}: {error:?}", path.display()), } } @@ -364,4 +378,113 @@ mod on_device { ); }); } + + /// `hs_sample` over a `BGRA10_XR` texture at its argument buffer's `half` member and a + /// `BGR10_XR` one at its `float` member, each 2 by 2 of [`CODES`]' first four texels: each + /// thread samples its texel's centre through the constexpr nearest sampler and through the + /// nearest sampler at slot 0. A `float` answer is the texel's value (lavapipe's + /// [`lavapipe_sample`]), a `half` one within a `half` step of it (the member's handle names the + /// format, `lower::texture::extended_unorm`). + #[test] + fn every_device_samples_extended_range_textures_through_an_argument_buffer() { + let Some(library) = library_at(&fixtures_dir().join("examples/heap_samples.ll")) else { + return; + }; + each_device("extended-range argument buffer", |name, _, device| { + let _textures = (device.grant_indices(IndexClass::Texture, 1, 2)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let _samplers = (device.grant_indices(IndexClass::Sampler, 1, 2)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let nearest = (device.new_sampler_state(&SamplerDescriptor::new(), 1)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let function = library.function("hs_sample").expect("the kernel"); + let descriptor = ComputePipelineDescriptor::new(StageSource::Function( + FunctionDescriptor::new(function), + )); + // The constexpr sampler at index 2, beside the slot's sampler at 1. + let state = (device + .new_compute_pipeline_state(&descriptor, |samplers| Ok(vec![2; samplers.len()]))) + .unwrap_or_else(|error| panic!("{name}: hs_sample: {error}")); + let codes = &CODES[..4]; + let made = |format: PixelFormat, index: u32| { + let texel_bytes = if format == PixelFormat::BGR10XR { 4 } else { 8 }; + let mut d = TextureDescriptor::new(TextureType::Type2D, format, 2, 2); + d.usage = TextureUsage::SHADER_READ; + let texture = (device.new_texture(&d, Some(index))) + .unwrap_or_else(|error| panic!("{name}: {format:?}: {error}")); + let whole = Region { + origin: [0; 3], + size: [2, 2, 1], + }; + let written = bytes_of(format, codes); + let row = 2 * texel_bytes; + (texture.replace_region(whole, 0, 0, HostBytes::from(&written[..]), row, row * 2)) + .unwrap_or_else(|error| panic!("{name}: {format:?}: {error}")); + texture + }; + let h = made(PixelFormat::BGRA10XR, 1); + let f = made(PixelFormat::BGR10XR, 2); + let mut arena = Arena::new(&device); + let held = arena.buffer(); + let out = arena.buffer(); + let ids: Vec = [&h, &f] + .iter() + .flat_map(|t| t.gpu_resource_id().to_bits().to_le_bytes()) + .collect(); + let contents = held.contents().expect("a Shared buffer"); + // SAFETY: the buffer holds 256 bytes, at least the 16 written, and no work is pending. + unsafe { (ids.as_ptr()).copy_to_nonoverlapping(contents.as_ptr(), ids.len()) }; + let queue = device.new_command_queue(1).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = + (command_buffer.compute_command_encoder(DispatchType::Serial)).expect("an encoder"); + encoder + .set_compute_pipeline_state(&state) + .expect("the state"); + encoder + .set_buffer(Some(&held), 0, 0) + .expect("the argument buffer"); + encoder.set_buffer(Some(&out), 0, 1).expect("the output"); + (encoder.set_sampler_state(Some(&nearest), 0)).expect("the sampler"); + for texture in [&h, &f] { + (encoder.use_resource(Resource::Texture(texture), ResourceUsage::READ)) + .expect("a texture"); + } + (encoder.dispatch_threadgroups([1, 1, 1], [2, 2, 1])) + .unwrap_or_else(|error| panic!("{name}: {error}")); + encoder.end_encoding(); + command_buffer.commit().expect("a commit"); + finished(name, &command_buffer); + assert_eq!(command_buffer.error(), None, "{name}"); + let contents = out.contents().expect("a Shared buffer"); + // SAFETY: the dispatch that wrote the buffer finished, and its writes reach the host; + // the buffer holds 256 bytes, the 16 float4s written. + let floats = unsafe { std::slice::from_raw_parts(contents.as_ptr().cast::(), 64) }; + for (i, &c) in codes.iter().enumerate() { + let half = texel(PixelFormat::BGRA10XR, c); + let float = texel(PixelFormat::BGR10XR, c); + let at = + |k: usize| -> [f32; 4] { std::array::from_fn(|j| floats[16 * i + 4 * k + j]) }; + for (k, through) in [(0, "constexpr"), (2, "slot")] { + let got = at(k); + // A `half` step, and an odd texel's low bits (`bytes_of`). + let low = if i % 2 == 1 { LOW_BITS } else { 0.0 }; + let near = (0..4).all(|j| (got[j] - half[j]).abs() <= 1.0 / 1024.0 + low); + assert!( + near, + "{name}: BGRA10_XR half {through} {i}: {got:?} for {half:?}" + ); + // Lavapipe's conversion of the field (`lavapipe_sample`). + let float = match cfg!(m2v_cpu_icd) { + true => lavapipe_sample(PixelFormat::BGR10XR, c), + false => float, + }; + let got = at(k + 1); + assert_eq!(bits(got), bits(float), "{name}: BGR10_XR {through} {i}"); + } + } + drop((command_buffer, queue, state, nearest, h, f)); + println!("{name}: extended-range textures sampled through an argument buffer"); + }); + } } diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index d1e1fd985..14dc79ea4 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -600429185080d6865900ba91d186f4da95335d02dc6170a9ad4821f2bf1da35e +1ab29fff848f010e243b8454d5f31fef65d11daca90b4a1e2f32f8d3917b390e diff --git a/crates/metal2vulkan/src/bind/heap.rs b/crates/metal2vulkan/src/bind/heap.rs index 00a39dd2e..f38c69c38 100644 --- a/crates/metal2vulkan/src/bind/heap.rs +++ b/crates/metal2vulkan/src/bind/heap.rs @@ -246,7 +246,9 @@ fn member_storage_format( shape: &TextureShape, ) -> Result { let TextureShape::Texture { pixel_format, .. } = *shape; - if crate::metal::format::ExtendedRange::of(pixel_format).is_some() { + if crate::metal::format::ExtendedRange::of(pixel_format).is_some() + || crate::metal::format::extended_unorm(pixel_format) + { return Err(BindError::Unsupported(Unsupported::not_implemented( Feature::ArgumentBufferTextures, ))); diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 711e44152..ab53e7bf6 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -60,7 +60,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 2373; +pub const SEMANTICS_VERSION: u32 = 2374; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 609; /// 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 = 2572; +pub const RUNTIME_VERSION: u32 = 2573; /// Writes a digest as lowercase hex. pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result { diff --git a/crates/metal2vulkan/src/lower/stage_io/plan.rs b/crates/metal2vulkan/src/lower/stage_io/plan.rs index d4ce8b99d..e54c8e92a 100644 --- a/crates/metal2vulkan/src/lower/stage_io/plan.rs +++ b/crates/metal2vulkan/src/lower/stage_io/plan.rs @@ -1020,7 +1020,7 @@ fn zeroed_output( } // What Metal stores into an extended-range attachment the pipeline lacks is unmeasured (its // tile holds decoded values, not the raw texel's bytes). - if crate::metal::format::ExtendedRange::of(format).is_some() { + if crate::metal::format::ExtendedRange::of_attachment(format).is_some() { return Err(Unsupported::not_implemented(Feature::Format).into()); } cx.facts.insert(RuntimeFact::ZeroedColor { color, format }); diff --git a/crates/metal2vulkan/src/metal/format/mod.rs b/crates/metal2vulkan/src/metal/format/mod.rs index fae36e5a2..bb4b6d465 100644 --- a/crates/metal2vulkan/src/metal/format/mod.rs +++ b/crates/metal2vulkan/src/metal/format/mod.rs @@ -309,8 +309,11 @@ impl FormatEmulation { } /// One of Apple's extended-range pixel formats, as a texture slot bound in it reads and writes -/// its raw texels. Metal's answers, measured on an Apple M3 Max (macOS 26.7) and an Apple M4 (macOS -/// 27.0.1) alike, every code and channel: +/// its raw texels. A texture of `BGR10_XR` or `BGRA10_XR` is not held so but as the UNORM codes +/// of its bits ([`FormatEmulation::ExtendedRangeUnorm`]); their forms here are a texture buffer's +/// words (`texel_words`) and a color attachment's raw texels +/// (`ExtendedRange::of_attachment`). Metal's answers, measured on an Apple M3 Max (macOS +/// 26.7) and an Apple M4 (macOS 27.0.1) alike, every code and channel: /// /// - **Codes.** A channel's 10-bit code `c` is the value `(c - 384) / 510` correctly rounded to /// `f32`, `[-0.752941, 1.252941]`; an `_sRGB` format's color channel is that value through the @@ -328,12 +331,14 @@ impl FormatEmulation { #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ExtendedRange { - /// `BGR10_XR`, or `BGR10_XR_sRGB` where `srgb`: held as `R32_UINT`. + /// `BGR10_XR_sRGB` where `srgb`, held as `R32_UINT`; `BGR10_XR` (not `srgb`) as a texture + /// buffer's words and a color attachment's raw texels alone. Bgr10 { /// The `_sRGB` twin. srgb: bool, }, - /// `BGRA10_XR`, or `BGRA10_XR_sRGB` where `srgb`: held as `R16G16B16A16_UINT`. + /// `BGRA10_XR_sRGB` where `srgb`, held as `R16G16B16A16_UINT`; `BGRA10_XR` (not `srgb`) as a + /// texture buffer's words and a color attachment's raw texels alone. Bgra10 { /// The `_sRGB` twin. srgb: bool, @@ -400,12 +405,12 @@ pub enum ExtendedRange { } impl ExtendedRange { - /// The extended-range format `pf` is, if it is one held in one image. + /// The extended-range format `pf` is, if it is one held raw in one image: `None` for + /// `BGR10_XR` and `BGRA10_XR`, held as the UNORM codes of their bits + /// ([`FormatEmulation::ExtendedRangeUnorm`]). pub fn of(pf: PixelFormat) -> Option { match pf { - PixelFormat::BGR10XR => Some(ExtendedRange::Bgr10 { srgb: false }), PixelFormat::BGR10XRSRGB => Some(ExtendedRange::Bgr10 { srgb: true }), - PixelFormat::BGRA10XR => Some(ExtendedRange::Bgra10 { srgb: false }), PixelFormat::BGRA10XRSRGB => Some(ExtendedRange::Bgra10 { srgb: true }), PixelFormat::RGB10A82PXR10 => Some(ExtendedRange::Planes { srgb: false }), PixelFormat::RGB10A82PXR10SRGB => Some(ExtendedRange::Planes { srgb: true }), @@ -421,6 +426,20 @@ impl ExtendedRange { } } + /// The form a render pipeline's color attachment of `pf` is held in: [`of`](Self::of)'s, and + /// `BGR10_XR`'s and `BGRA10_XR`'s raw texels (`Bgr10` and `Bgra10`, not `srgb`, through their + /// formats' second candidate). Such a pipeline is made, its function writing the raw texels; + /// a texture of either format is held as the UNORM codes of its bits + /// ([`FormatEmulation::ExtendedRangeUnorm`]), whose render targets are not built: one made + /// with `RenderTarget` usage is refused, so no pass draws into one. + pub(crate) fn of_attachment(pf: PixelFormat) -> Option { + match pf { + PixelFormat::BGR10XR => Some(ExtendedRange::Bgr10 { srgb: false }), + PixelFormat::BGRA10XR => Some(ExtendedRange::Bgra10 { srgb: false }), + _ => ExtendedRange::of(pf), + } + } + /// The unsigned integer format of the texels' bytes, which holds them. pub fn raw_format(self) -> vk::Format { match self { @@ -489,8 +508,8 @@ impl ExtendedRange { } /// Whether Metal's linear mip filter of the form's samples is built as a blend of two levels' - /// samples (`lower::sampler::extended`), measured on an Apple M3 Max: `BGR10_XR`'s and - /// `BGRA10_XR`'s, the padded forms' `R10Unorm_X6` and `RG10Unorm_X12`, and their `_sRGB` + /// samples (`lower::sampler::extended`), measured on an Apple M3 Max: `BGR10_XR_sRGB`'s and + /// `BGRA10_XR_sRGB`'s, the padded forms' `R10Unorm_X6` and `RG10Unorm_X12`, and their `_sRGB` /// twins'. A bfloat form's linear mip filter reads the one level its nearest mip filter reads, /// and a two-plane form's and `RGB10A2Unorm_sRGB`'s (not measured) are refused. pub(crate) fn blends_levels(self) -> bool { @@ -509,10 +528,9 @@ impl ExtendedRange { /// class indices follow (`metal::texel_format::heap_extended_base`): a function decodes such a /// texture's raw texels, read through the heap's unsigned integer array. A heap holds no /// `_sRGB` form (their heap classes are not built) and no two-plane form, which is held in two - /// planes. - pub const HEAP_READ: [ExtendedRange; 7] = [ - ExtendedRange::Bgr10 { srgb: false }, - ExtendedRange::Bgra10 { srgb: false }, + /// planes. A `BGR10_XR` or `BGRA10_XR` texture is an element of the heap's sampled float class + /// ([`FormatEmulation::ExtendedRangeUnorm`]). + pub const HEAP_READ: [ExtendedRange; 5] = [ ExtendedRange::R10X6, ExtendedRange::Rg10X12, ExtendedRange::R16Bfloat, @@ -1361,7 +1379,8 @@ fn make_repr(pf: PixelFormat) -> Repr { // held raw in the integer format of their bytes. // `BGR10_XR` and `BGRA10_XR` in the UNORM format of their bits, whose fields a function // maps to Metal's values ([`FormatEmulation::ExtendedRangeUnorm`]); a color attachment of - // either in its bytes' integer format, raw, as before (their render targets are not built). + // either in its bytes' integer format, raw ([`ExtendedRange::of_attachment`]): their + // render targets are not built. P::BGR10XR => color(vec![ Candidate { format: F::A2R10G10B10_UNORM_PACK32, @@ -1901,6 +1920,18 @@ pub fn ycbcr(pf: PixelFormat) -> bool { ) } +/// Whether `pf` is held as the UNORM codes of its bits +/// ([`FormatEmulation::ExtendedRangeUnorm`]): `BGR10_XR` and `BGRA10_XR`, Apple's extended-range +/// formats that [`ExtendedRange::of`] does not name, whose storage elements and reads in another +/// numeric class are refused as a raw-held form's are. +pub(crate) fn extended_unorm(pf: PixelFormat) -> bool { + matches!( + repr(pf), + Repr::Candidates(_, c) + if c.first().is_some_and(|c| c.emulation == FormatEmulation::ExtendedRangeUnorm) + ) +} + /// Whether Metal completes a function's writes to a texture of `pf` and stores nothing: the /// 4:2:2 formats, the YCbCr formats ([`ycbcr`]) whose chroma is subsampled, 4:2:0 and 4:2:2 (a /// kernel's write leaves both planes' bytes as they were, and Metal's validation stops the @@ -2196,7 +2227,7 @@ pub(crate) fn write_conversion(pf: PixelFormat) -> Option { let h = f(10, true); let hu = |bits| Some(C::HalfUnorm { bits }); let srgb = Some(C::Srgb); - if ExtendedRange::of(pf).is_some() { + if ExtendedRange::of_attachment(pf).is_some() { return Some(WriteConversion::Encoded); } // A two-plane YCbCr attachment a pass renders holds the function's floats diff --git a/crates/metal2vulkan/src/metal/format/tests.rs b/crates/metal2vulkan/src/metal/format/tests.rs index b487dd368..6a917964a 100644 --- a/crates/metal2vulkan/src/metal/format/tests.rs +++ b/crates/metal2vulkan/src/metal/format/tests.rs @@ -146,12 +146,24 @@ fn direct_formats_round_trip() { FormatEmulation::Direct => back.entry(candidates[0].format).or_default().push(pf), FormatEmulation::ExtendedRange => {} // `BGR10_XR`'s and `BGRA10_XR`'s bits in the UNORM format of the same bits, which - // `BGR10A2Unorm` and `RGBA16Unorm` hold directly. + // `BGR10A2Unorm` and `RGBA16Unorm` hold directly; no raw-held form names them but an + // attachment's (their second candidate, raw). FormatEmulation::ExtendedRangeUnorm => { assert!( matches!(pf, PixelFormat::BGR10XR | PixelFormat::BGRA10XR), "{pf:?}" - ) + ); + assert!( + extended_unorm(pf) && ExtendedRange::of(pf).is_none(), + "{pf:?}" + ); + assert!(!crate::metal::texel_format::crosses_classes(pf), "{pf:?}"); + assert!(ExtendedRange::of_attachment(pf).is_some(), "{pf:?}"); + assert_eq!( + candidates.get(1).map(|c| c.emulation), + Some(FormatEmulation::ExtendedRange), + "{pf:?}" + ); } FormatEmulation::RotatedView => assert_eq!(pf, PixelFormat::ARGB8Unorm), FormatEmulation::YCbCr => assert!(ycbcr_format(pf).is_some(), "{pf:?}"), diff --git a/crates/metal2vulkan/src/metal/format/texel_words.rs b/crates/metal2vulkan/src/metal/format/texel_words.rs index f811af294..1c01f1334 100644 --- a/crates/metal2vulkan/src/metal/format/texel_words.rs +++ b/crates/metal2vulkan/src/metal/format/texel_words.rs @@ -74,7 +74,8 @@ pub enum WordLayout { /// unsigned 10-bit float from bit 22, each of a five-bit exponent; alpha reads 1. SmallFloats, /// One of Apple's extended-range formats held in one texel (`ExtendedRange::Bgr10` or - /// `ExtendedRange::Bgra10`), whose codes `metal::format::ExtendedRange` describes. + /// `ExtendedRange::Bgra10`, `BGR10_XR` and `BGRA10_XR` as the forms not `srgb`), whose codes + /// `metal::format::ExtendedRange` describes. Extended(ExtendedRange), } @@ -427,14 +428,13 @@ fn layout(pf: PixelFormat) -> Option<(u32, WordLayout)> { P::RGB9E5Float => (4, WordLayout::SharedExponent), P::RGBA16Unorm => fields(8, [f(0, 16), f(16, 16), f(32, 16), f(48, 16)], Unorm), P::RGBA16Snorm => fields(8, [f(0, 16), f(16, 16), f(32, 16), f(48, 16)], Snorm), - P::BGR10XR | P::BGR10XRSRGB | P::BGRA10XR | P::BGRA10XRSRGB => { - let range = ExtendedRange::of(pf)?; - let bytes = match range { - ExtendedRange::Bgr10 { .. } => 4, - ExtendedRange::Bgra10 { .. } => 8, - _ => return None, - }; - (bytes, WordLayout::Extended(range)) + P::BGR10XR | P::BGR10XRSRGB => { + let srgb = pf == P::BGR10XRSRGB; + (4, WordLayout::Extended(ExtendedRange::Bgr10 { srgb })) + } + P::BGRA10XR | P::BGRA10XRSRGB => { + let srgb = pf == P::BGRA10XRSRGB; + (8, WordLayout::Extended(ExtendedRange::Bgra10 { srgb })) } _ => return None, }) diff --git a/crates/metal2vulkan/src/metal/texel_format.rs b/crates/metal2vulkan/src/metal/texel_format.rs index de1be2ca6..5cdd12771 100644 --- a/crates/metal2vulkan/src/metal/texel_format.rs +++ b/crates/metal2vulkan/src/metal/texel_format.rs @@ -596,13 +596,16 @@ fn heap_layout() -> &'static HeapLayout { /// texture under its cross-class variant, and a heap group's /// read of another class reads it in its own class ([`heap_numeric`]). pub fn crosses_classes(pf: PixelFormat) -> bool { - use crate::metal::format::{is_depth_stencil, sampled_type, ycbcr_format, ExtendedRange}; + use crate::metal::format::{ + extended_unorm, is_depth_stencil, sampled_type, ycbcr_format, ExtendedRange, + }; use crate::pipeline::sym::SampledType; matches!( sampled_type(pf), Some(SampledType::Float | SampledType::Sint | SampledType::Uint) ) && !is_depth_stencil(pf) && ExtendedRange::of(pf).is_none() + && !extended_unorm(pf) && ycbcr_format(pf).is_none() } diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 862f37bc7..24c53bb46 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -556,9 +556,9 @@ pub enum PrecisionNote { MultisamplePosition, /// A filter the module emulates by fetches sums its taps in the device's arithmetic, where /// Metal's sampler has its own datapath: Metal's bicubic filter (every format), and an - /// extended-range texture's linear, 3D and linear-mip-filter samples (`BGR10_XR`, - /// `BGRA10_XR`, `RGB10A8_2P_XR10` and their `_sRGB` twins, the padded forms; read through the - /// slot's `extended_range` variant). The footprint, the + /// extended-range texture's linear, 3D and linear-mip-filter samples (`BGR10_XR_sRGB`, + /// `BGRA10_XR_sRGB`, `RGB10A8_2P_XR10` and its `_sRGB` twin, the padded forms; read through + /// the slot's `extended_range` variant). The footprint, the /// fraction (`1/256` of a texel), the addressing of each tap, the filter each format selects /// (a 32-bit float format's bicubic sample and a level under four texels bilinear), the level /// a mip filter reads, and each format's clamp are Metal's; the arithmetic is the device's: @@ -1540,7 +1540,7 @@ pub enum PrecisionNote { /// stage changes. Validation derives no tolerance from it. UnmeasuredGroupSpeculation, /// An extended-range texture's fragment sample at an implicit level and its sample with - /// explicit gradients (`BGR10_XR`, `BGRA10_XR` and their sRGB twins), which read texels in the + /// explicit gradients (`BGR10_XR_sRGB` and `BGRA10_XR_sRGB`), which read texels in the /// shader on every device: they take Vulkan's level of detail computed in the shader and then /// Metal's level rule (`lower::sampler::level`). Vulkan's level of detail, whose scale factor /// may be approximated, is not Metal's, which is not measured from derivatives. Recorded through diff --git a/crates/metal2vulkan/src/pipeline/color_writes.rs b/crates/metal2vulkan/src/pipeline/color_writes.rs index 70bf6660f..8cb589f29 100644 --- a/crates/metal2vulkan/src/pipeline/color_writes.rs +++ b/crates/metal2vulkan/src/pipeline/color_writes.rs @@ -318,7 +318,7 @@ pub(crate) fn extended_range_colors( .enumerate() .filter_map(|(i, c)| { let c = c.as_ref()?; - let form = metal::format::ExtendedRange::of(c.pixel_format)?; + let form = metal::format::ExtendedRange::of_attachment(c.pixel_format)?; let write = ExtendedRangeColor::new(form, c.blending_enabled).with_rounding(rounding); Some((i as u32, write)) }) @@ -343,7 +343,10 @@ pub(crate) fn merges_extended( ) -> bool { use metal::format::ExtendedRange as X; use metal::ColorWriteMask as M; - let word = matches!(X::of(pf), Some(X::Bgr10 { .. } | X::Planes { .. })); + let word = matches!( + X::of_attachment(pf), + Some(X::Bgr10 { .. } | X::Planes { .. }) + ); let rgb = M::RED.union(M::GREEN).union(M::BLUE); let color = mask & rgb; word && !blended && !color.is_empty() && color != rgb diff --git a/crates/metal2vulkan/src/pipeline/link/graphics.rs b/crates/metal2vulkan/src/pipeline/link/graphics.rs index d8b05eafb..d3f3f48be 100644 --- a/crates/metal2vulkan/src/pipeline/link/graphics.rs +++ b/crates/metal2vulkan/src/pipeline/link/graphics.rs @@ -222,7 +222,7 @@ fn textured_fetches(r: &RenderLinkInputs, fs: Option<&StageInterface>) -> Result if metal::format::rotated_channels(pf) || metal::format::ycbcr_renders(pf) || metal::format::ycbcr_pass_refused(pf) - || ExtendedRange::of(pf).is_some() + || ExtendedRange::of_attachment(pf).is_some() { let refused = Unsupported::not_implemented(Feature::Format); return Err(refused.at_attachment(Attachment::Color(color)).into()); @@ -351,7 +351,7 @@ pub fn graphics_state( let unblendable = r.color_attachments.iter().position(|a| { a.is_some_and(|a| { a.blending_enabled - && ExtendedRange::of(a.pixel_format).is_some_and(ExtendedRange::bfloat) + && ExtendedRange::of_attachment(a.pixel_format).is_some_and(ExtendedRange::bfloat) }) }); if let Some(index) = unblendable { @@ -423,7 +423,7 @@ pub fn graphics_state( // unwritten attachment (the module docs), so its blend changes nothing: it // takes none, nor the blend usage its raw unsigned format lacks (a padded // one's too; a bfloat one's blend is refused above). - let extended = ExtendedRange::of(a.pixel_format); + let extended = ExtendedRange::of_attachment(a.pixel_format); let written_here = written.contains(&(index as u32)); let unwritten_extended = !written_here && extended.is_some(); // An attachment held with its channels rotated takes the function's rotated @@ -864,7 +864,9 @@ fn reads_alpha_to_coverage( } // An extended-range attachment 0 is written as raw texels, whose alpha the coverage cannot // read: what Metal's coverage is there is unmeasured. - if r.color_attachments[0].is_some_and(|a| ExtendedRange::of(a.pixel_format).is_some()) { + if r.color_attachments[0] + .is_some_and(|a| ExtendedRange::of_attachment(a.pixel_format).is_some()) + { let refused = Unsupported::not_implemented(Feature::Format); return Err(refused.at_attachment(Attachment::Color(0)).into()); } diff --git a/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs b/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs index 29898051a..c8239e834 100644 --- a/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs +++ b/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs @@ -97,9 +97,9 @@ fn pipeline_of(pf: PixelFormat, mask: ColorWriteMask, blended: bool) -> RenderLi r } -/// The form `pf` is held in. +/// The form an attachment of `pf` is held in. fn form_of(pf: PixelFormat) -> ExtendedRange { - ExtendedRange::of(pf).expect("an extended-range format") + ExtendedRange::of_attachment(pf).expect("an extended-range format") } fn render(r: &RenderLinkInputs) -> LinkInputs { diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 7e6bd68d6..6af812605 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -79,7 +79,7 @@ assoc-const metal2vulkan::device::OpBits::VOTE pub const VOTE: OpBits assoc-const metal2vulkan::device::ResolveMode::ALL pub const ALL: [ResolveMode; 4] assoc-const metal2vulkan::metal::DataType::ALL pub const ALL: [DataType; 17] assoc-const metal2vulkan::metal::TextureSwizzleChannels::DEFAULT pub const DEFAULT: TextureSwizzleChannels -assoc-const metal2vulkan::metal::format::ExtendedRange::HEAP_READ pub const HEAP_READ: [ExtendedRange; 7] +assoc-const metal2vulkan::metal::format::ExtendedRange::HEAP_READ pub const HEAP_READ: [ExtendedRange; 5] assoc-const metal2vulkan::metal::resource_word::TextureWord::BORDER_TEXELS pub const BORDER_TEXELS: u32 assoc-const metal2vulkan::metal::resource_word::TextureWord::OUT_OF_BOUNDS_ALPHA_ONE pub const OUT_OF_BOUNDS_ALPHA_ONE: u32 assoc-const metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT pub const PIXEL_FORMAT: u32 @@ -247,7 +247,7 @@ assoc-const-value metal2vulkan::device::OpBits::VOTE OpBits(1 <<1) assoc-const-value metal2vulkan::device::ResolveMode::ALL [ResolveMode::SampleZero, ResolveMode::Average, ResolveMode::Min, ResolveMode::Max] assoc-const-value metal2vulkan::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::metal::TextureSwizzleChannels::DEFAULT TextureSwizzleChannels -assoc-const-value metal2vulkan::metal::format::ExtendedRange::HEAP_READ [ExtendedRange::Bgr10 { srgb: false }, ExtendedRange::Bgra10 { srgb: false }, ExtendedRange::R10X6, ExtendedRange::Rg10X12, ExtendedRange::R16Bfloat, ExtendedRange::Rg16Bfloat, ExtendedRange::Rgba16Bfloat] +assoc-const-value metal2vulkan::metal::format::ExtendedRange::HEAP_READ [ExtendedRange::R10X6, ExtendedRange::Rg10X12, ExtendedRange::R16Bfloat, ExtendedRange::Rg16Bfloat, ExtendedRange::Rgba16Bfloat] assoc-const-value metal2vulkan::metal::resource_word::TextureWord::BORDER_TEXELS 0xfff assoc-const-value metal2vulkan::metal::resource_word::TextureWord::OUT_OF_BOUNDS_ALPHA_ONE 1 <<12 assoc-const-value metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT 0xffff <