diff --git a/crates/metal2vulkan-validation/src/runtime_lane/denormal_word_fetches.rs b/crates/metal2vulkan-validation/src/runtime_lane/denormal_word_fetches.rs index fa4cd3250..2104a77cd 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/denormal_word_fetches.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/denormal_word_fetches.rs @@ -5,22 +5,26 @@ //! its runtime and argument buffer's samplers filter as its constexpr samplers of the same state). //! //! RADV's gathers and nearest samples, NVIDIA's gathers and ANV's nearest samples read such a -//! texel as the zero of its sign; their fetches keep it. The texture is read at texture slot 0 +//! texel as the zero of its sign. Those are the device's own samples, which the stages record +//! (`PrecisionNote::DeviceSampling`): off MoltenVK the lane prints the lanes that differ +//! (`DENORMAL-TEXEL-DIFFERS` lines) without failing. The texture is read at texture slot 0 //! through runtime sampler slot 0, and as the texture an argument buffer holds through runtime //! sampler slot 0, through the sampler the argument buffer holds, and through a constexpr sampler: //! a gather at each interior texel corner reads the four texels around it, in gather order, and a //! nearest sample at each texel centre its texel. The samplers are nearest, without a mip filter, -//! clamped to the edge, normalized: the word states one texel, where the shader fetches. On -//! MoltenVK Metal's own sampler reads them. +//! clamped to the edge, normalized. On MoltenVK (`VkProperty::MetalSampler`) Metal's own sampler +//! reads them, which must keep every texel's bits. use super::argument_linear_samples::kernel; +use super::degrade_notices::counts; use super::depth_compares::{pipeline_of, run_held, Held, Through}; use super::{layer_reported_nothing_at_all, validated_device, Messages, ScratchCache}; use crate::gpu::TEST_DEVICE; use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::device::VkProperty; use metal2vulkan::metal::PixelFormat; use metal2vulkan_devtools::llvm_assemble_text; -use metal2vulkan_runtime::{Region, TextureDescriptor}; +use metal2vulkan_runtime::{Degradation, Region, TextureDescriptor}; /// A constexpr sampler's words: nearest filters, no mip filter, normalized coordinates clamped to /// the edge. @@ -86,6 +90,12 @@ fn denormal_texels_read_through_words_and_heaps_keep_their_bits() { { let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); let name = device.name().to_owned(); + let own = !device + .compile_device() + .profile() + .enabled() + .properties + .contains(&VkProperty::MetalSampler); let texture = device .new_texture(&TextureDescriptor::texture_2d( PixelFormat::R32Float, @@ -180,12 +190,24 @@ fn denormal_texels_read_through_words_and_heaps_keep_their_bits() { } } eprintln!("{name}: {} of {compared} lanes differ", wrong.len()); - assert!( - wrong.is_empty(), - "{name}: {} of {compared} lanes differ:\n{}", - wrong.len(), - wrong.join("\n") + let announced = counts(&messages.take_notices()); + assert_eq!( + announced.contains_key(&Degradation::DeviceSampling), + own, + "{name}: device-sampling exactly where the device's sampler is not Metal's" ); + if own { + for w in &wrong { + eprintln!("DENORMAL-TEXEL-DIFFERS {name}: {w}"); + } + } else { + assert!( + wrong.is_empty(), + "{name}: {} of {compared} lanes differ:\n{}", + wrong.len(), + wrong.join("\n") + ); + } } layer_reported_nothing_at_all(&messages); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/depth_compare_levels.rs b/crates/metal2vulkan-validation/src/runtime_lane/depth_compare_levels.rs index 6883dd891..40ae89857 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/depth_compare_levels.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/depth_compare_levels.rs @@ -15,17 +15,19 @@ //! `equal` against one level's depth at the texture's centre, so its answer is that level's //! weight. The samplers filter nearest under nearest and linear mip filters through clamps of //! whole, half-way and sixty-fourth bounds, and without a mip filter. Metal's own comparison runs -//! through MoltenVK; elsewhere the shader fetches the texel from the level the sampler's word -//! reads (`fetched::FetchLevel::Word`) or a constexpr sampler's snap, and blends a linear mip -//! filter's two levels' comparisons (`compared::blended`). +//! through MoltenVK (`VkProperty::MetalSampler`), which must answer the rule exactly; elsewhere +//! the comparison is the device's, which the stages record (`PrecisionNote::DeviceSampling`) and +//! the lane counts against the rule (`DEPTH-LEVEL-DIFFERS` lines) without failing. +use super::degrade_notices::counts; use super::depth_compares::{argument_kernel, pipeline_of, run_held, Held, Through}; use super::{layer_reported_nothing_at_all, validated_device, Messages, ScratchCache}; use crate::gpu::TEST_DEVICE; use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::device::VkProperty; use metal2vulkan::metal::{CompareFunction, PixelFormat, SamplerMipFilter}; use metal2vulkan_devtools::llvm_assemble_text; -use metal2vulkan_runtime::{Device, Region, SamplerState, Texture, TextureDescriptor}; +use metal2vulkan_runtime::{Degradation, Device, Region, SamplerState, Texture, TextureDescriptor}; /// The texture's side and levels. const SIDE: u64 = 16; @@ -257,7 +259,9 @@ fn sampler(device: &Device, mip: SamplerMipFilter, (min, max): (f32, f32)) -> Sa /// neither) and through an argument buffer's sampler and a runtime sampler of a texture an /// argument buffer holds (at a level) reads the level Metal reads, and every one through a /// constexpr sampler under a nearest or a linear mip filter (at a level, a bias, and neither) -/// reads or blends Metal's levels, on `Depth32Float` and `Depth16Unorm` (module docs). +/// reads or blends Metal's levels, on `Depth32Float` and `Depth16Unorm` (module docs), on a device +/// that samples through Metal's own sampler; elsewhere the stages announce `device-sampling` and +/// the comparisons that differ are printed. #[test] fn comparisons_read_the_level_metal_reads() { let cache = ScratchCache::new().unwrap(); @@ -265,6 +269,12 @@ fn comparisons_read_the_level_metal_reads() { { let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); let name = device.name().to_owned(); + let own = !device + .compile_device() + .profile() + .enabled() + .properties + .contains(&VkProperty::MetalSampler); let levels = lane_levels(); let mut compared = 0usize; let mut wrong = Vec::new(); @@ -337,8 +347,7 @@ fn comparisons_read_the_level_metal_reads() { } } // Constexpr samplers of nearest filters under a nearest and a linear mip filter, their - // clamps `half`s: a nearest one's texel fetched from Metal's level, a linear one's two - // levels' comparisons blended (`compared::blended`). + // clamps `half`s. for (code, mip) in [ (1, SamplerMipFilter::Nearest), (2, SamplerMipFilter::Linear), @@ -363,17 +372,29 @@ fn comparisons_read_the_level_metal_reads() { } } eprintln!("{name}: {} of {compared} comparisons differ", wrong.len()); - assert!( - wrong.is_empty(), - "{name}: {} of {compared} comparisons differ:\n{}", - wrong.len(), - wrong - .iter() - .take(200) - .cloned() - .collect::>() - .join("\n") + let announced = counts(&messages.take_notices()); + assert_eq!( + announced.contains_key(&Degradation::DeviceSampling), + own, + "{name}: device-sampling exactly where the device's sampler is not Metal's" ); + if own { + for w in &wrong { + eprintln!("DEPTH-LEVEL-DIFFERS {name}: {w}"); + } + } else { + assert!( + wrong.is_empty(), + "{name}: {} of {compared} comparisons differ:\n{}", + wrong.len(), + wrong + .iter() + .take(200) + .cloned() + .collect::>() + .join("\n") + ); + } } layer_reported_nothing_at_all(&messages); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/depth_compares.rs b/crates/metal2vulkan-validation/src/runtime_lane/depth_compares.rs index 4d1daac0c..809410a48 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/depth_compares.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/depth_compares.rs @@ -1,7 +1,8 @@ //! A device test of depth comparisons against Metal's measured rule on the device the cfg selects, -//! under the validation layer: the comparisons the shader makes on a device without -//! `VkProperty::MetalSampler` (a nearest comparison's and a comparison gather's; a linear -//! comparison's), and Metal's own through MoltenVK. +//! under the validation layer: Metal's own through MoltenVK (`VkProperty::MetalSampler`), which +//! must answer it exactly; elsewhere the device's own comparisons, which the stages record +//! (`PrecisionNote::DeviceSampling`) and the lane counts against the rule +//! (`DEPTH-COMPARE-DIFFERS` lines) without failing. //! //! Metal compares a `Depth16Unorm` texel against the reference's code: the reference clamped into //! [0, 1] and the exact product with 65535 rounded to the nearest code (the one half-way @@ -31,6 +32,7 @@ //! the eight functions. (A sampler that filters leaves a heap texture's comparison to the device, //! which the module records, so it is not asked here.) +use super::degrade_notices::counts; use super::{ buffer_with, layer_reported_nothing_at_all, read_buffer, validated_device, Messages, ScratchCache, WAIT, @@ -38,12 +40,13 @@ use super::{ use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::device::VkProperty; use metal2vulkan::metal::{CompareFunction, PixelFormat, ResourceUsage, SamplerMinMagFilter}; use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource}; use metal2vulkan_devtools::{engine_dir, llvm_assemble, llvm_assemble_text}; use metal2vulkan_runtime::{ - ComputePipelineState, Device, Error, PipelineOptions, Region, ResourceOptions, SamplerState, - Size, Texture, TextureDescriptor, + ComputePipelineState, Degradation, Device, Error, PipelineOptions, Region, ResourceOptions, + SamplerState, Size, Texture, TextureDescriptor, }; use std::cmp::Ordering; @@ -779,13 +782,15 @@ fn gather_jobs(texels: Texels) -> Jobs<([usize; 4], f32)> { (jobs, want) } -/// Every comparison of a `Depth16Unorm` and a `Depth32Float` texel is Metal's: `sample_compare` -/// through a linear and a nearest sampler at each texel's centre, and `gather_compare` at each -/// inner corner, under `less_equal` and `equal` through constexpr samplers and under each of the -/// eight functions through a runtime sampler; each plain gather states its footprint's four -/// texels in Metal's order. And through an argument buffer that holds the texture: through the -/// constexpr nearest samplers, and through a nearest runtime sampler and a nearest sampler the -/// argument buffer holds under each of the eight functions. +/// On a device that samples through Metal's own sampler, every comparison of a `Depth16Unorm` +/// and a `Depth32Float` texel is Metal's: `sample_compare` through a linear and a nearest sampler +/// at each texel's centre, and `gather_compare` at each inner corner, under `less_equal` and +/// `equal` through constexpr samplers and under each of the eight functions through a runtime +/// sampler; each plain gather states its footprint's four texels in Metal's order. And through an +/// argument buffer that holds the texture: through the constexpr nearest samplers, and through a +/// nearest runtime sampler and a nearest sampler the argument buffer holds under each of the eight +/// functions. Elsewhere the comparisons are the device's: the stages announce `device-sampling`, +/// and the comparisons that differ from Metal's are printed. #[test] fn depth_comparisons_compare_as_metal_does() { let cache = ScratchCache::new().unwrap(); @@ -793,6 +798,12 @@ fn depth_comparisons_compare_as_metal_does() { { let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); let name = device.name().to_owned(); + let own = !device + .compile_device() + .profile() + .enabled() + .properties + .contains(&VkProperty::MetalSampler); let mut compared = 0; let mut wrong = Vec::new(); for texels in [Texels::Unorm16(&CODES), Texels::Float32(&VALUES)] { @@ -805,12 +816,24 @@ fn depth_comparisons_compare_as_metal_does() { compared += n; wrong.extend(w); } - assert!( - wrong.is_empty(), - "{name}: {} of {compared} comparisons differ:\n{}", - wrong.len(), - wrong.join("\n") + let announced = counts(&messages.take_notices()); + assert_eq!( + announced.contains_key(&Degradation::DeviceSampling), + own, + "{name}: device-sampling exactly where the device's sampler is not Metal's" ); + if own { + for w in &wrong { + eprintln!("DEPTH-COMPARE-DIFFERS {name}: {w}"); + } + } else { + assert!( + wrong.is_empty(), + "{name}: {} of {compared} comparisons differ:\n{}", + wrong.len(), + wrong.join("\n") + ); + } } layer_reported_nothing_at_all(&messages); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/depth_texel_reads.rs b/crates/metal2vulkan-validation/src/runtime_lane/depth_texel_reads.rs index de6817813..a2d16967c 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/depth_texel_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/depth_texel_reads.rs @@ -3,13 +3,16 @@ //! reads and samples (nearest) every 16-bit code `c` as `c / 65535` correctly rounded to `float` //! (our own probe: all 65,536 codes, both accesses, the outputs' SHA-256 below), //! where a device that multiplies by the reciprocal answers 512 codes one ulp off (lavapipe, the -//! format scout's `Depth16Unorm` read cell). The kernels are the format scout's (`format_scout.ll`): -//! a 16x16 texture of 256 codes at a time, each code read and sampled at its texel's centre. +//! format scout's `Depth16Unorm` read cell). The module hands back the device's conversion: on +//! MoltenVK, Metal's own; on a device whose texture unit is not Metal's (no +//! `VkProperty::MetalSampler`), the device's, which `PrecisionNote::DeviceTexelConversion` +//! records, and the lane takes a value within one ulp of Metal's there. The kernels are the format +//! scout's (`format_scout.ll`): a 16x16 texture of 256 codes at a time, each code read and sampled +//! at its texel's centre. //! //! The same texture through an argument buffer ([`HEAP`]'s kernels, synthetic AIR written for //! this lane) reads and samples alike: Metal reads a texture an argument buffer holds as the same -//! texture at a slot, and the module converts a heap depth texture's texel by the class its -//! handle carries. +//! texture at a slot. use super::{ buffer_with, layer_reported_nothing_at_all, read_buffer, validated_device, Messages, @@ -19,6 +22,7 @@ use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; use crate::hash::sha256_bytes; use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::device::VkProperty; use metal2vulkan::metal::{PixelFormat, ResourceUsage, SamplerMinMagFilter, TextureUsage}; use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource}; use metal2vulkan_devtools::{engine_dir, llvm_assemble, llvm_assemble_text}; @@ -136,6 +140,14 @@ fn a_depth16_texel_reads_and_samples_as_metal_s_code_over_65535() { { let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); eprintln!("device {}", device.name()); + // The device's conversion, within one ulp of Metal's, where its texture unit is not + // Metal's. + let own = !device + .compile_device() + .profile() + .enabled() + .properties + .contains(&VkProperty::MetalSampler); let scout = llvm_assemble(&engine_dir().join("format_scout.ll")).unwrap(); let scout = device.new_library_with_air(&scout).unwrap(); let heap = device @@ -243,19 +255,22 @@ fn a_depth16_texel_reads_and_samples_as_metal_s_code_over_65535() { .filter_map(|(c, v)| { let v = u32::from_le_bytes([v[0], v[1], v[2], v[3]]); let metal = (c as f32 / 65535.0).to_bits(); - (v != metal).then_some((c as u32, v, metal)) + let near = own && v.abs_diff(metal) <= 1; + (v != metal && !near).then_some((c as u32, v, metal)) }) .collect(); assert!( off.is_empty(), - "{} on {}: {} of 65536 codes not c / 65535 correctly rounded, the first \ - (code, device, Metal): {:x?}", + "{} on {}: {} of 65536 codes not c / 65535 correctly rounded (within one ulp \ + where the device converts), the first (code, device, Metal): {:x?}", what, device.name(), off.len(), &off[..off.len().min(8)] ); - assert_eq!(sha256_bytes(got), METAL, "{what}: Metal's digest"); + if !own { + assert_eq!(sha256_bytes(got), METAL, "{what}: Metal's digest"); + } } } layer_reported_nothing_at_all(&messages); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/half_read_nans.rs b/crates/metal2vulkan-validation/src/runtime_lane/half_read_nans.rs index 05d4618c3..465529bd8 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/half_read_nans.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/half_read_nans.rs @@ -8,8 +8,10 @@ //! read through `access::read` and `access::read_write`, a texture buffer's read, a nearest //! sample and a gather. NVIDIA and RADV hand back the half widened with its NaN's sign and //! payload, ANV every NaN as `0xffc00000`, and lavapipe a signalling NaN quieted (the format -//! scout's rows), so the module converts a one-texel `float` result of a half-float class to -//! Metal's NaN (`lower::texture::float_texel`); MoltenVK's value is Metal's already. +//! scout's rows). The module hands back the device's texel: on MoltenVK, Metal's own; on a device +//! whose texture unit is not Metal's (no `VkProperty::MetalSampler`), the device's NaN, which +//! its precision note records (`PrecisionNote::DeviceTexelConversion`), and the lane takes any NaN +//! for Metal's there. //! //! The kernels are this lane's own AIR: each reads texel `(x, 0)` of an [`N`] by 1 texture whose //! texel `x` holds [`word`]'s channels (a texture buffer's element `x`), samples it at the texel's @@ -22,6 +24,7 @@ use super::degrade_notices::on_device; use super::{buffer_with, read_buffer, WAIT}; use crate::air_library::AirLibrary; use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::device::VkProperty; use metal2vulkan::metal::{ PixelFormat, ResourceUsage, SamplerAddressMode, SamplerMinMagFilter, TextureUsage, }; @@ -396,12 +399,20 @@ fn dispatch( } /// Every access of [`OPS`] to every format of [`FORMATS`] hands back Metal's words: a half-float -/// texel's NaN as `0x7fc00000`, a 32-bit float texel's words as stored. +/// texel's NaN as `0x7fc00000` (a NaN of the device's encoding where its texture unit is not +/// Metal's), a 32-bit float texel's words as stored. #[test] fn half_float_reads_hand_back_metals_nans() { let mut report = Vec::new(); let mut differ_total = 0; on_device(|device, _| { + // The device's texel, a half-float NaN its own, where its texture unit is not Metal's. + let own = !device + .compile_device() + .profile() + .enabled() + .properties + .contains(&VkProperty::MetalSampler); let mut nearest = SamplerDescriptor::new(); nearest.min_filter = SamplerMinMagFilter::Nearest; nearest.mag_filter = SamplerMinMagFilter::Nearest; @@ -417,7 +428,8 @@ fn half_float_reads_hand_back_metals_nans() { for (x, lanes) in got.iter().enumerate() { let want = metal_lanes(f, op, x); for (k, (&g, &w)) in lanes.iter().zip(&want).enumerate() { - if g != w { + let nans = f32::from_bits(g).is_nan() && f32::from_bits(w).is_nan(); + if g != w && !(own && f.half && nans) { differ.push(format!("texel {x} lane {k}: {g:08x} (Metal {w:08x})")); } }