From db251d505e734af6b0da5ec5ca3cefc4a2e39c7f Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 8 Nov 2026 23:32:53 -0800 Subject: [PATCH] resolve_rounding: a cleared sRGB resolve takes either code nearest the clear where the passes announce the conversion On the Radeon 780M under RADV (development 1c7a75be62, job m3-max-11026, 2 runs of 2), the 1x clear of RGBA8Unorm_sRGB [0.5, 0.214, 0.0031308, 1.0] stores [bc, 80, 0a, ff]; Metal's is [bc, 7f, 0a, ff]. The 4x clear of the same pass shape resolves to texels other than the 1x clear's, all 4096 of them, the first [bc, 7f, 0a, ff]. 0.214 encodes to 127.47 codes. The device converts a clear its own way, and its 1x and 4x images take different routes to the same value: a code apart, either nearest code, both the device's native conversion. The runtime announces device-color-conversion for such a clear, and rule 1 makes the device's answer the answer. The lane held the 4x resolve to the 1x clear's bytes. It now holds each resolved texel to those bytes, or, where the two passes announced device-color-conversion, to the two codes nearest the clear's value in each channel: the sRGB curve's for a colour channel, alpha as it is. It prints how many texels differ from the 1x clear, the first, how many fall off the nearest codes, and the notices. (cherry picked from commit 9e985f4bb450ebf3f60d32511b9386bd9856950b) --- .../src/runtime_lane/resolve_rounding.rs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/crates/metal2vulkan-validation/src/runtime_lane/resolve_rounding.rs b/crates/metal2vulkan-validation/src/runtime_lane/resolve_rounding.rs index 3e85821c4..72d5f4f67 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/resolve_rounding.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/resolve_rounding.rs @@ -1363,7 +1363,11 @@ fn a_maps_form_pass_resolves_bgra8_as_announced() { /// it, resolves to the clear's codes: the bytes the device's clear of a 1x texture of the format /// stores (Metal's bytes, `renders.rs`' `COLOR_CLEARS`, where its conversion is Metal's, printed), /// as every sample holds the clear, which Metal's rule and the device's average give back, -/// whatever form the device keeps the clear in. +/// whatever form the device keeps the clear in. Where the passes announce +/// `device-color-conversion`, the device converts the clear its own way, which may differ between +/// its 1x and its 4x images (the Radeon 780M under RADV: a 1x clear of 0.214 stores `0x80`, the 4x +/// one resolves to `0x7f`): there each channel of the resolve is one of the two codes nearest the +/// clear's value, the sRGB curve's for a colour channel and the value itself for alpha. #[test] fn cleared_srgb_attachments_resolve_to_the_clear_s_codes() { let (messages, _cache, lane) = lane(); @@ -1412,8 +1416,27 @@ fn cleared_srgb_attachments_resolve_to_the_clear_s_codes() { .unwrap(); assert_eq!(command_buffer.error(), None); }; + messages.take_notices(); clear(&single, None); clear(&msaa, Some(&resolved)); + let notices = super::degrade_notices::counts(&messages.take_notices()); + let converted = notices.contains_key(&Degradation::DeviceColorConversion); + // The clear's value in codes, in the texel's byte order: the sRGB curve's for a colour + // channel, alpha as it is. + let encode = |v: f64| match v <= 0.0031308 { + true => 12.92 * v, + false => 1.055 * v.powf(1.0 / 2.4) - 0.055, + }; + let [r, g, b] = [r, g, b].map(|v| 255.0 * encode(f64::from(v))); + let alpha = 255.0 * f64::from(a); + let exact = match pf { + PixelFormat::BGRA8UnormSRGB => [b, g, r, alpha], + _ => [r, g, b, alpha], + }; + let nearest = |texel: &[u8]| { + (texel.iter().zip(exact)) + .all(|(&code, v)| [v.floor(), v.ceil()].contains(&f64::from(code))) + }; let cleared = super::renders::blit_read(&lane.device, &single, 4); let bytes: [u8; 4] = cleared[..4].try_into().unwrap(); eprintln!( @@ -1425,8 +1448,15 @@ fn cleared_srgb_attachments_resolve_to_the_clear_s_codes() { } ); let read = super::renders::blit_read(&lane.device, &resolved, 4); - let wrong = read.chunks(4).filter(|texel| *texel != bytes).count(); - eprintln!("cleared resolve {pf:?} x4 on {name}: {wrong} texels other than the clear's"); + let other = read.chunks(4).filter(|texel| *texel != bytes).count(); + let wrong = (read.chunks(4)) + .filter(|texel| *texel != bytes && !(converted && nearest(texel))) + .count(); + eprintln!( + "cleared resolve {pf:?} x4 on {name}: {other} texels other than the clear's \ + ({:02x?} first), {wrong} off the codes nearest it; announced {notices:?}", + &read[..4] + ); assert_eq!(wrong, 0, "{pf:?} on {name}: {:02x?}", &read[..4]); } quiet(lane, &messages);