Hold an 8-bit sRGB word's encode and decode to the device's announced conversions in color_writes and word_samples_msaa

On the RTX 5080 Laptop GPU (NVIDIA 615.71.09) the lane's color_writes stored 3,170 of 53,907
R8Unorm_sRGB channels a code from Metal's, and word_samples_msaa's sRGB reads differed from the
transfer by up to 1.88e-3 over 29 reads at 0b556ddfd6. The device renders neither R8_SRGB nor
R8G8_SRGB, so the runtime draws through the word's view (metal::format::WordAttachment::Srgb8):
the fragment encodes through its own Pow, recorded as PrecisionNote::DevicePackConversion, where
Metal encodes through its twelve-bit table; and the device decodes an sRGB sample its own way
(srgb-texel-decode; it rounds its decode of R8_SRGB to a 1/256 step). Both are announced; the lane
held them to Metal's bits. A test bug, not a translation gap.

What:
- color_writes: an 8-bit sRGB word's codes count as the device's conversion where the fragment
  stage records DevicePackConversion; they are printed against Metal's and not held.
- word_samples_msaa: an sRGB word's read is held within 1e-3 of the transfer where the device
  decodes through Metal's own texture unit (VkProperty::MetalSampler, MoltenVK on Apple's GPU) and
  within a code (1/255) elsewhere, where srgb-texel-decode is allowed among the notices.

Verified: in the lane proof runs on the 5080 and the M3 (counts in the series' last commit).
(cherry picked from commit dbc5461c6b96524f6c318a81c078c8f954c4c3c8)
This commit is contained in:
Anees Iqbal committed 2026-11-05 05:10:38 -08:00
1 parent 1ec132c75b
commit 3cfd7f7aa0
2 files changed
+56 -15

No files matched your search

@@ -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<u8>,
/// 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.
@@ -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<float>::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<metal2vulkan::metal::format::WordField>| {
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)),
}