From c4b56b0b3897cd58efddcde22c3cb910b2490ff9 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 16:21:00 -0800 Subject: [PATCH] Fix forward of 60740: the shadow's tile read, and the moved writers' count Job 60740 (clippy and tests of metal2vulkan at 2c728b7b79) failed on two things the shadow's removal left. extended_range::tile_read, Metal's read of a tile holding a `half`, read the shadow's texel alone, so nothing calls it now; it goes with its test (Op::TileRead and a_read_of_the_tile_clamps_as_metals_does) and blend::clamped's mention of it. engine_moved_writers' second test still named the move it no longer loops over; its set of planned states is now keyed by writer and tests, and it expects one move per writer. No version or pin changes: tile_read was never emitted for an unshadowed input, and the runtime pin is unchanged (0260cefd). Verified: nothing yet (a check job is owed). --- .../src/lower/arith/extended_range.rs | 22 -------- .../src/lower/arith/extended_range/blend.rs | 2 +- .../src/lower/arith/extended_range/tests.rs | 55 +------------------ .../src/tests/engine_moved_writers.rs | 12 ++-- 4 files changed, 6 insertions(+), 85 deletions(-) diff --git a/crates/metal2vulkan/src/lower/arith/extended_range.rs b/crates/metal2vulkan/src/lower/arith/extended_range.rs index e2b3ca524..6ef6e90d0 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range.rs @@ -230,28 +230,6 @@ pub fn tile_value(fb: &mut FunctionBuilder<'_>, form: ExtendedRange, raw: Value) narrow::round(fb, halves(), v) } -/// Metal's read of the tile memory of an attachment of `form` that holds `held` (a `vec4` of -/// `f32`, red first, each lane a `half`: what the pass's clear, load or last write left there, -/// the `half` shadow's texel): a fetch's value, and a blend's destination. Its color lanes are -/// clamped to the blend's source range (`BGRA10_XR_sRGB`'s [`SRGB_SOURCE_RANGE`], every other -/// form's [`SOURCE_RANGE`]), alpha to `[0, 1]`, a NaN to the low end (`blend::clamped`, the -/// blend's own clamp of its source), and `BGR10_XR`'s alpha is one: the tile holds what a write -/// wrote, unclamped, and stores its encode, but every read clamps (on an Apple -/// M4: unblended `half` writes past the range, NaNs and the infinities, each read back by a -/// fetch and blended over, for every form; their codes are the writes' own encodes, code 1023 -/// for 2.0 where the read is 1022's value). [`tile_value`] of a texel's codes is such a read -/// already. -pub fn tile_read(fb: &mut FunctionBuilder<'_>, form: ExtendedRange, held: Value) -> BResult { - let read = blend::clamped(fb, held, source_range(form))?; - match form { - ExtendedRange::Bgr10 { .. } => { - let one = fsplat(fb, floats(), 1.0)?; - fb.vector_shuffle(read, one, &[0, 1, 2, 7]) - } - _ => Ok(read), - } -} - pub(crate) use blend_color::{SOURCE_RANGE, SRGB_SOURCE_RANGE}; /// The range Metal clamps a blend's `half` source color to before blending into an attachment diff --git a/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs b/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs index 326a90f23..4d003179d 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs @@ -2001,7 +2001,7 @@ fn signed_product(fb: &mut FunctionBuilder<'_>, f: Form, x: Value, y: Value) -> } /// `s` (a `vec4`) clamped: its color lanes to `(lo, hi)`, alpha to `[0, 1]`, a NaN to the low -/// end. A read of the `half` shadow clamps so too (`super::tile_read`). +/// end. pub(super) fn clamped( fb: &mut FunctionBuilder<'_>, s: Value, diff --git a/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs b/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs index b543b8584..537e293ea 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs @@ -4,9 +4,7 @@ //! Metal's tables. use super::blend::{extended_ranges, native, NativeBlend}; -use super::{ - decode, encode, encode_keeping, tile_read, tile_value, SOURCE_RANGE, SRGB_SOURCE_RANGE, -}; +use super::{decode, encode, encode_keeping, tile_value, SOURCE_RANGE, SRGB_SOURCE_RANGE}; use crate::error::Error; use crate::lower::arith::{FloatFmt, Form, Held}; use crate::lower::stage_io::extended_color::bfloat_output; @@ -51,8 +49,6 @@ enum Op { /// blend color words 8 to 11 (`f32` bits, as the encoder set it), the second source words 12 /// to 15 (`f32` bits). Blend(BlendEquation, ColorWriteMask), - /// Metal's read of a tile holding a `vec4` of `f32` bits ([`tile_read`]). - TileRead, /// A render pass's store of a fragment function's output (`vec4` of `f32` bits, of the /// format, `half` values held as `f32`) to a bfloat attachment of a pipeline at /// `textureWriteRoundingMode` `NearestEven` where the flag is set @@ -156,11 +152,6 @@ fn kernel(form: ExtendedRange, op: Op) -> BResult { let v = tile_value(&mut f, form, x)?; f.convert(ConvOp::Bitcast, v, uvec4)? } - Op::TileRead => { - let held = f.convert(ConvOp::Bitcast, x, vec4)?; - let v = tile_read(&mut f, form, held)?; - f.convert(ConvOp::Bitcast, v, uvec4)? - } Op::Output(nearest_even, fmt) => { let v = f.convert(ConvOp::Bitcast, x, vec4)?; let rounding = match nearest_even { @@ -1214,47 +1205,3 @@ fn bfloat_attachments_store_metals_codes() { } } } - -/// A read of what the tile holds clamps as Metal's does (an Apple M4: unblended -/// `half` writes read back by a fetch): each color lane to the form's source range, a NaN to its -/// low end, the infinities and values past the range to its ends; alpha to `[0, 1]`, a NaN to 0; -/// a subnormal `half` kept; `BGR10_XR`'s alpha one. -#[test] -fn a_read_of_the_tile_clamps_as_metals_does() { - let (n, inf) = (f32::NAN, f32::INFINITY); - let subnormal = crate::float16::f16_bits_to_f32(7); - let written: [[f32; 4]; 5] = [ - [n, -inf, inf, -0.5], - [inf, n, -inf, n], - [-inf, 3.0, n, 2.0], - [10000.0, -3.0, 0.25, inf], - [2.0, -1.0, subnormal, 0.5], - ]; - for form in [ - ExtendedRange::Bgra10 { srgb: false }, - ExtendedRange::Bgra10 { srgb: true }, - ExtendedRange::Bgr10 { srgb: true }, - ExtendedRange::Planes { srgb: false }, - ] { - let (lo, hi) = match form { - ExtendedRange::Bgra10 { srgb: true } => SRGB_SOURCE_RANGE, - _ => SOURCE_RANGE, - }; - let a = |v: f32| match form { - ExtendedRange::Bgr10 { .. } => 1.0, - _ => v, - }; - let want: [[f32; 4]; 5] = [ - [lo, lo, hi, a(0.0)], - [hi, lo, lo, a(0.0)], - [lo, hi, lo, a(1.0)], - [hi, lo, 0.25, a(1.0)], - [hi, lo, subnormal, a(0.5)], - ]; - let lanes: Vec<[u32; 4]> = written.iter().map(|w| w.map(f32::to_bits)).collect(); - let got = run(form, Op::TileRead, &lanes); - for ((w, g), want) in written.iter().zip(&got).zip(&want) { - assert_eq!(*g, want.map(f32::to_bits), "{form:?}: {w:?}"); - } - } -} diff --git a/crates/metal2vulkan/src/tests/engine_moved_writers.rs b/crates/metal2vulkan/src/tests/engine_moved_writers.rs index 83436bc0d..c24599382 100644 --- a/crates/metal2vulkan/src/tests/engine_moved_writers.rs +++ b/crates/metal2vulkan/src/tests/engine_moved_writers.rs @@ -276,7 +276,7 @@ fn a_moved_writer_that_stores_nothing_selects_no_tests() { return; }; let devices = ordering_devices(); - let mut planned = std::collections::BTreeSet::<(&str, String, String)>::new(); + let mut planned = std::collections::BTreeSet::<(&str, String)>::new(); // The states that miss, by kind of miss. let mut misses = std::collections::BTreeMap::<&str, Vec>::new(); let mut states = 0usize; @@ -333,7 +333,7 @@ fn a_moved_writer_that_stores_nothing_selects_no_tests() { Ok(_) => miss("the variant's plan asks for another variant"), Err(_) => miss("the variant's plan refuses the draw"), } - planned.insert((writer, format!("{moved:?}"), format!("{tests:?}"))); + planned.insert((writer, format!("{tests:?}"))); } } } @@ -345,12 +345,8 @@ fn a_moved_writer_that_stores_nothing_selects_no_tests() { eprintln!("{} states: {kind} (first: {})", whats.len(), whats[0]); } assert!(misses.is_empty(), "{misses:#?}"); - // Not vacuous: every writer, move and kind of tests planned on some profile. - assert_eq!( - planned.len(), - WRITERS.len() * 2 * TESTS.len(), - "{planned:?}" - ); + // Not vacuous: every writer and kind of tests planned on some profile. + assert_eq!(planned.len(), WRITERS.len() * TESTS.len(), "{planned:?}"); } /// A writer that declares color 0 as an input it never reads (`smw_unread`, which discards) reads