diff --git a/crates/metal2vulkan-validation/src/runtime_lane/color_writes.rs b/crates/metal2vulkan-validation/src/runtime_lane/color_writes.rs index 48da0d5fb..351a7a82f 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/color_writes.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/color_writes.rs @@ -49,7 +49,12 @@ //! snorm channel) the lane holds the device's conversion to Metal's, the measurement of the //! deviation on that device; elsewhere the fragment stage records the device's conversion //! (`PrecisionNote::DeviceColorConversion`), and the lane prints the channels that differ from -//! Metal's without holding them. A word the fragment function encodes is held to Metal's rule. +//! Metal's without holding them. A packed 16-bit word the fragment function encodes is held to +//! Metal's rule; an 8-bit sRGB word's codes are the device's encode (the MSL transfer through its +//! `Pow`, `PrecisionNote::DevicePackConversion`: `metal::format::WordAttachment`), where Metal +//! encodes through its twelve-bit table, so they are printed against Metal's and not held (the +//! RTX 5080, which renders neither `R8_SRGB` nor `R8G8_SRGB`, stored 3,170 of the lane's 53,907 +//! `R8Unorm_sRGB` channels otherwise than Metal, each printed example a code apart). use super::degrade_notices::counts; use super::resolves::{lane, quiet, Lane}; @@ -716,7 +721,8 @@ struct Drawn { stored: Vec, /// Whether the fragment stage records `PrecisionNote::DeviceNanEncoding`. noted: bool, - /// Whether the fragment stage records `PrecisionNote::DeviceColorConversion`: the device's own + /// Whether the fragment stage records `PrecisionNote::DeviceColorConversion`, or + /// `PrecisionNote::DevicePackConversion` for an 8-bit sRGB word it encodes: the device's own /// conversion of the attachment's channels, printed against Metal's and not held to it. converted: bool, } @@ -778,9 +784,13 @@ fn drawn( let noted = fragment .precision_notes .contains(&PrecisionNote::DeviceNanEncoding); - let converted = fragment - .precision_notes - .contains(&PrecisionNote::DeviceColorConversion); + let srgb_word = matches!( + WordAttachment::of(case.pf, device.compile_device().profile()), + Some(WordAttachment::Srgb8 { .. }) + ); + let notes = &fragment.precision_notes; + let converted = notes.contains(&PrecisionNote::DeviceColorConversion) + || (srgb_word && notes.contains(&PrecisionNote::DevicePackConversion)); let pipeline = device .new_render_pipeline_state(&pipeline, &PipelineOptions::default()) .map_err(|e| format!("unsupported: the pipeline ({e})"))?; @@ -827,7 +837,8 @@ fn drawn( } /// Every format, plain and blended, printed against Metal's conversion, and held to it where the -/// fragment stage does not record the device's own conversion (`DeviceColorConversion`). +/// fragment stage does not record the device's own conversion (`DeviceColorConversion`, or +/// `DevicePackConversion` for an 8-bit sRGB word: the module docs). #[test] fn draws_store_metals_codes() { let (messages, _cache, lane) = lane(); @@ -934,8 +945,9 @@ fn draws_store_metals_codes() { /// A packed 16-bit or two-channel 8-bit sRGB format's draw under a write mask of some of its /// channels, over a pass that clears it: each written channel stores Metal's code of the output /// and each kept one the code of the clear (Metal's rule of both), held so where the fragment -/// stage does not record the device's own conversion (`DeviceColorConversion`). A format the device holds but -/// does not render must draw so through the view of its word (`metal::format::WordAttachment`), +/// stage does not record the device's own conversion (`DeviceColorConversion`, or +/// `DevicePackConversion` for an 8-bit sRGB word's encode). A format the device holds but does +/// not render must draw so through the view of its word (`metal::format::WordAttachment`), /// which the fragment function merges into the texel's, in the pixel interlock or over the /// attachment's input attachment on a device that orders fetch through them (lavapipe; an 8-bit /// sRGB word), and says so. diff --git a/crates/metal2vulkan-validation/src/runtime_lane/word_samples_msaa.rs b/crates/metal2vulkan-validation/src/runtime_lane/word_samples_msaa.rs index a5a5e3bdb..2175316d5 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/word_samples_msaa.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/word_samples_msaa.rs @@ -15,7 +15,9 @@ //! attachments (`DeviceOptions::withheld_attachment_formats`), which holds each multisampled //! texture the device renders in its word's format (`image_plan::word_samples`) where the device //! renders the word at the count. Each leg prints which way it held each format. A word's samples -//! are Metal's words, read as Metal reads them, and its resolve, the crate-owned one, is Metal's +//! are Metal's words, read as Metal reads them (an sRGB word's by the device's decode, +//! `srgb-texel-decode`, within a code of the transfer where it is not Metal's: [`read`]), and its +//! resolve, the crate-owned one, is Metal's //! for `R8Unorm_sRGB` and `RGB9E5Float` and within one code of each field of Metal's for the //! packed formats, announced as `word-resolve`. A format the device renders itself stores and //! resolves by the device's own conversions and average, each within one code (an `RGB9E5Float` @@ -29,6 +31,7 @@ use super::{ }; use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; +use metal2vulkan::device::VkProperty; use metal2vulkan::error::Feature; use metal2vulkan::metal::format::{direct_format, WordAttachment}; use metal2vulkan::metal::{ @@ -464,16 +467,27 @@ fn srgb_linear(code: u32) -> f32 { } /// What `texture2d_ms::read` returns for a sample of `pf` holding `word`, as Metal reads it, -/// and how far the device's own read may be from it: a packed field's code over its largest, an -/// sRGB code's linear value (the device's decode), `RGB9E5Float`'s value exactly; a channel the -/// format lacks 0, alpha 1. -fn read(pf: PixelFormat, word: u32) -> ([f32; 4], f32) { +/// and how far the device's own read may be from it: a packed field's code over its largest, +/// `RGB9E5Float`'s value exactly, and an sRGB code's linear value, the device's decode +/// (`PrecisionNote::SrgbTexelDecode`, for which Vulkan sets no precision): within `1e-3` of the +/// transfer where the device decodes through Metal's own texture unit (`metal_sampler`, +/// `VkProperty::MetalSampler`), within a code's `1 / 255` elsewhere (the RTX 5080 rounds its +/// decode of an `R8_SRGB` sample to a `1 / 256` step: 1.88e-3 from the transfer at most over the +/// lane's 29 reads of 0b556ddfd6 that a `1e-3` bound refused); a channel the format lacks 0, +/// alpha 1. +fn read(pf: PixelFormat, word: u32, metal_sampler: bool) -> ([f32; 4], f32) { match WordAttachment::layout(pf).unwrap() { WordAttachment::Rgb9e5 => { let [r, g, b] = shared_exponent(word); ([r, g, b, 1.0], 0.0) } - WordAttachment::Srgb8 { .. } => ([srgb_linear(word & 255), 0.0, 0.0, 1.0], 1e-3), + WordAttachment::Srgb8 { .. } => { + let within = match metal_sampler { + true => 1e-3, + false => 1.0 / 255.0, + }; + ([srgb_linear(word & 255), 0.0, 0.0, 1.0], within) + } w => { let value = |f: Option| { f.map_or(1.0, |f| { @@ -560,6 +574,13 @@ impl Lane { ) } + /// Whether the device decodes sRGB through Metal's own texture unit + /// (`VkProperty::MetalSampler`: MoltenVK on Apple's GPU), so its decode is Metal's. + fn metal_sampler(&self) -> bool { + let profile = self.device.compile_device().profile(); + (profile.enabled().properties).contains(&VkProperty::MetalSampler) + } + /// Whether the device renders `pf` through the view of its word. fn word(&self, pf: PixelFormat) -> bool { WordAttachment::of(pf, self.device.compile_device().profile()).is_some() @@ -781,7 +802,7 @@ impl Lane { "{what}: {at}: word {got:#x} against Metal's {metal:#x}" )); } - let (expected, within) = read(pf, got); + let (expected, within) = read(pf, got, self.metal_sampler()); let far = value .iter() .zip(expected) @@ -922,6 +943,14 @@ fn multisampled_word_formats_store_read_resolve_and_blend_as_metal() { if blended { allowed.insert(Degradation::SamplePlanes); } + // An sRGB word's reads, the device's decode where it is not Metal's. + let srgb = matches!( + WordAttachment::layout(pf), + Some(WordAttachment::Srgb8 { .. }) + ); + if srgb && !lane.metal_sampler() { + allowed.insert(Degradation::SrgbTexelDecode); + } } false => allowed.extend(resolve_kind(&lane.device, samples)), }