diff --git a/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/blend8.rs b/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/blend8.rs index 9d6460acd..801418ae2 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/blend8.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/blend8.rs @@ -26,12 +26,18 @@ //! is refused by that capability, which is printed. Through input attachments (lavapipe) the device //! blends; what it announces and how many channels are Metal's is printed. Each draw prints a //! `FETCH-BLEND8` line naming its function and format. +//! +//! Other blends, write masks and the blend color, into `BGRA8Unorm` through each fixture's +//! loaded `half4` and `float4`: source alpha over, the blend color's lerps with one channel of the +//! encoder's color past each end, blue alone stored, and alpha alone stored, against the +//! arithmetic `Blend::unorm8` names for each (EVs FB8-sw2-m3, FB8-bc1-m3, FB8-sc1-m3 and +//! FB8-ao1-m3), each channel the mask leaves out its code; checked as above. use super::{form, library, through_inputs}; -use crate::runtime_lane::buffer_with; use crate::runtime_lane::degrade_notices::counts; use crate::runtime_lane::resolves::{lane_with, quiet, Lane}; use crate::runtime_lane::WAIT; +use crate::runtime_lane::{buffer_with, Messages}; use metal2vulkan::error::Needs; use metal2vulkan::metal::{ BlendFactor, BlendOperation, ColorWriteMask, PixelFormat, PrimitiveType, TextureUsage, @@ -40,8 +46,9 @@ use metal2vulkan::pipeline::{ ColorAttachmentDescriptor, PrecisionNote, RenderPipelineDescriptor, StageSource, }; use metal2vulkan_runtime::{ - BlitOption, ClearColor, Degradation, Error, LoadAction, Origin, PipelineOptions, - RenderPassDescriptor, ResourceOptions, Size, StoreAction, Texture, TextureDescriptor, + BlitOption, ClearColor, Degradation, Error, Library, LoadAction, Origin, PipelineOptions, + RenderPassDescriptor, RenderPipelineState, ResourceOptions, Size, StoreAction, Texture, + TextureDescriptor, }; /// The target's side, as the fixtures'. @@ -261,6 +268,166 @@ fn filled(lane: &Lane, pf: PixelFormat, bytes: &[u8], bpp: u64) -> Texture { texture } +/// A pipeline of `fixture`'s `entry` blending color 0 of `pf` by `blended` (with color 1 of mask +/// none), or `None` where a device fetching through the pixel interlock lacks the format's +/// storage there (printed). +fn pipeline( + lane: &Lane, + (library, fixture): (&Library, &Fixture), + entry: &str, + blended: ColorAttachmentDescriptor, +) -> Option { + let device = lane.device.name(); + let function = |name| { + StageSource::Function( + library + .new_function_with_name(name) + .unwrap() + .function_descriptor(), + ) + }; + let pf = blended.pixel_format; + let mut descriptor = RenderPipelineDescriptor::new(function(fixture.vertex)); + descriptor.fragment = Some(function(entry)); + let mut unwritten = ColorAttachmentDescriptor::new(PixelFormat::RGBA16Float); + unwritten.write_mask = ColorWriteMask::NONE; + descriptor.color_attachments[0] = Some(blended); + descriptor.color_attachments[1] = Some(unwritten); + match lane + .device + .new_render_pipeline_state(&descriptor, &PipelineOptions::default()) + { + Ok(state) => Some(state), + // A format whose storage the device lacks is refused by that capability. + Err(Error::Unsupported(u)) if !through_inputs(lane) && u.needs != Needs::NotImplemented => { + println!("FETCH-BLEND8 {entry} {pf:?} | {device} | refused: {u}"); + None + } + Err(error) => panic!("{entry} into {pf:?} on {device}: {error}"), + } +} + +/// One draw of `state` (whose function returns `output`) over a target of `pf` (`order` the +/// channel of each byte) holding `texels`, the encoder's blend color `color`: the target's bytes +/// after it, and which of [`NOTES`] it announced. +fn draw( + (lane, messages): (&Lane, &Messages), + state: &RenderPipelineState, + (pf, order): (PixelFormat, &[usize]), + (output, texels, sources): (Output, &[[u8; 4]], &[[f64; 4]]), + color: [f32; 4], +) -> (Vec, Vec) { + let kinds = NOTES.map(Degradation::from_precision_note); + let bpp = order.len(); + let bytes: Vec = texels + .iter() + .flat_map(|t| order.iter().map(|&c| t[c])) + .collect(); + let target = filled(lane, pf, &bytes, bpp as u64); + let mut second = TextureDescriptor::texture_2d(PixelFormat::RGBA16Float, SIDE, SIDE, false); + second.usage = TextureUsage::RENDER_TARGET; + second.resource_options = ResourceOptions::private(); + let second = lane.device.new_texture(&second).unwrap(); + let src: Vec = match output { + Output::Float => sources + .iter() + .flat_map(|s| s.map(|v| v as f32)) + .flat_map(f32::to_le_bytes) + .collect(), + Output::Half | Output::Product => sources + .iter() + .flat_map(|s| s.map(half_bits)) + .flat_map(u16::to_le_bytes) + .collect(), + }; + let src = buffer_with(&lane.device, &src).unwrap(); + let mut pass = RenderPassDescriptor::new(); + let attachment = &mut pass.color_attachments[0]; + attachment.texture = Some(target.clone()); + attachment.load_action = LoadAction::Load; + attachment.store_action = StoreAction::Store; + let attachment = &mut pass.color_attachments[1]; + attachment.texture = Some(second); + attachment.load_action = LoadAction::Clear; + attachment.clear_color = ClearColor::new(0.0, 0.0, 0.0, 0.0); + attachment.store_action = StoreAction::DontCare; + let _ = messages.take_notices(); + lane.run(&pass, |_, encoder, _| { + encoder.set_render_pipeline_state(state).unwrap(); + encoder.set_blend_color(color[0], color[1], color[2], color[3]); + encoder.set_fragment_buffer(Some(&src), 0, 0).unwrap(); + encoder + .draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0) + .unwrap(); + }) + .unwrap(); + let announced = counts(&messages.take_notices()); + let noted = kinds + .into_iter() + .filter(|k| announced.contains_key(k)) + .collect(); + ( + lane.read(&target, (0, 0), bpp as u64, BlitOption::None), + noted, + ) +} + +/// The source each pixel's function returns: a load chosen by the fetched alpha, or the first +/// load times the fetched color (each channel's code, a missing color channel 0, a missing alpha +/// one). +fn returned( + output: Output, + order: &[usize], + (i, codes): (usize, [u8; 4]), + sources: &[[f64; 4]], +) -> [f64; 4] { + let fetched: [f64; 4] = std::array::from_fn(|c| match order.contains(&c) { + true => f64::from(codes[c]) / 255.0, + false => f64::from(u8::from(c == 3)), + }); + let chosen = match order.contains(&3) && codes[3] == 0 { + true => i + TEXELS, + false => i, + }; + match output { + Output::Product => std::array::from_fn(|c| h(sources[i][c] * h(fetched[c]))), + _ => sources[chosen], + } +} + +/// Check one draw (the module docs): print its line, assert that a device fetching through the +/// pixel interlock announces none of [`NOTES`], and that every texel is Metal's where none is +/// announced. `wrong` holds each texel that is not: its index, the bytes read and Metal's. +fn checked( + lane: &Lane, + what: (&str, PixelFormat), + noted: &[Degradation], + wrong: &[(usize, Vec, Vec)], +) { + let device = lane.device.name(); + let (entry, pf) = what; + println!( + "FETCH-BLEND8 {entry} {pf:?} | {device} | through {} | Metal's {}/{} texels | announced \ + {noted:?}", + form(lane), + TEXELS - wrong.len(), + TEXELS, + ); + let what = format!("{entry} into {pf:?} on {device}"); + if !through_inputs(lane) { + assert!(noted.is_empty(), "{what}: announced {noted:?}"); + } + if noted.is_empty() { + let shown = &wrong[..wrong.len().min(8)]; + assert!( + wrong.is_empty(), + "{what}: {} of {TEXELS} texels differ from Metal's, first (index, read, Metal's) \ + {shown:?}", + wrong.len() + ); + } +} + /// Each draw's channels are Metal's where it announces none of [`NOTES`], and on a device that /// fetches through the pixel interlock it announces none (the module docs). #[test] @@ -270,23 +437,11 @@ fn a_blended_eight_bit_unorm_fetch_stores_metals_blend() { options.announce_each = kinds.into_iter().collect(); }); let device = lane.device.name(); - let interlock = !through_inputs(&lane); let mut drawn = 0; for fixture in &FIXTURES { let library = library(&lane, fixture.stem); - let function = |name| { - StageSource::Function( - library - .new_function_with_name(name) - .unwrap() - .function_descriptor(), - ) - }; for (pf, order) in FORMATS { for (entry, output) in fixture.cases { - let what = format!("{entry} into {pf:?} on {device}"); - let mut descriptor = RenderPipelineDescriptor::new(function(fixture.vertex)); - descriptor.fragment = Some(function(entry)); let mut blended = ColorAttachmentDescriptor::new(pf); blended.blending_enabled = true; blended.source_rgb_blend_factor = BlendFactor::One; @@ -295,95 +450,17 @@ fn a_blended_eight_bit_unorm_fetch_stores_metals_blend() { blended.source_alpha_blend_factor = BlendFactor::One; blended.destination_alpha_blend_factor = BlendFactor::OneMinusSourceAlpha; blended.alpha_blend_operation = BlendOperation::Add; - let mut unwritten = ColorAttachmentDescriptor::new(PixelFormat::RGBA16Float); - unwritten.write_mask = ColorWriteMask::NONE; - descriptor.color_attachments[0] = Some(blended); - descriptor.color_attachments[1] = Some(unwritten); - let state = match lane - .device - .new_render_pipeline_state(&descriptor, &PipelineOptions::default()) - { - Ok(state) => state, - // A format whose storage the device lacks is refused by that capability. - Err(Error::Unsupported(u)) if interlock && u.needs != Needs::NotImplemented => { - println!("FETCH-BLEND8 {entry} {pf:?} | {device} | refused: {u}"); - continue; - } - Err(error) => panic!("{what}: {error}"), + let Some(state) = pipeline(&lane, (&library, fixture), entry, blended) else { + continue; }; - let bpp = order.len(); let (texels, sources) = data(output); - let bytes: Vec = texels - .iter() - .flat_map(|t| order.iter().map(|&c| t[c])) - .collect(); - let target = filled(&lane, pf, &bytes, bpp as u64); - let mut second = - TextureDescriptor::texture_2d(PixelFormat::RGBA16Float, SIDE, SIDE, false); - second.usage = TextureUsage::RENDER_TARGET; - second.resource_options = ResourceOptions::private(); - let second = lane.device.new_texture(&second).unwrap(); - let src: Vec = match output { - Output::Float => sources - .iter() - .flat_map(|s| s.map(|v| v as f32)) - .flat_map(f32::to_le_bytes) - .collect(), - Output::Half | Output::Product => sources - .iter() - .flat_map(|s| s.map(half_bits)) - .flat_map(u16::to_le_bytes) - .collect(), - }; - let src = buffer_with(&lane.device, &src).unwrap(); - let mut pass = RenderPassDescriptor::new(); - let color = &mut pass.color_attachments[0]; - color.texture = Some(target.clone()); - color.load_action = LoadAction::Load; - color.store_action = StoreAction::Store; - let color = &mut pass.color_attachments[1]; - color.texture = Some(second); - color.load_action = LoadAction::Clear; - color.clear_color = ClearColor::new(0.0, 0.0, 0.0, 0.0); - color.store_action = StoreAction::DontCare; - let _ = messages.take_notices(); - lane.run(&pass, |_, encoder, _| { - encoder.set_render_pipeline_state(&state).unwrap(); - encoder.set_fragment_buffer(Some(&src), 0, 0).unwrap(); - encoder - .draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0) - .unwrap(); - }) - .unwrap(); - let announced = counts(&messages.take_notices()); - let noted: Vec<_> = kinds - .iter() - .filter(|k| announced.contains_key(*k)) - .collect(); - let read = lane.read(&target, (0, 0), bpp as u64, BlitOption::None); - let has_alpha = order.contains(&3); + let data = (output, texels.as_slice(), sources.as_slice()); + let (read, noted) = draw((&lane, &messages), &state, (pf, order), data, [0.0; 4]); + let bpp = order.len(); let mut wrong = Vec::new(); - for i in 0..TEXELS { - let codes = texels[i]; + for (i, &codes) in texels.iter().enumerate() { let got = &read[bpp * i..bpp * i + bpp]; - // The fetched color: each channel's code, a missing color channel 0, a - // missing alpha one. - let fetched: [f64; 4] = std::array::from_fn(|c| match order.contains(&c) { - true => f64::from(codes[c]) / 255.0, - false => f64::from(u8::from(c == 3)), - }); - // A load chosen by the fetched alpha, or the first load times the fetched - // color. - let chosen = match has_alpha && codes[3] == 0 { - true => i + TEXELS, - false => i, - }; - let s: [f64; 4] = match output { - Output::Product => { - std::array::from_fn(|c| h(sources[i][c] * h(fetched[c]))) - } - _ => sources[chosen], - }; + let s = returned(output, order, (i, codes), &sources); let float = output == Output::Float; let want: Vec = order .iter() @@ -393,25 +470,216 @@ fn a_blended_eight_bit_unorm_fetch_stores_metals_blend() { wrong.push((i, got.to_vec(), want)); } } - println!( - "FETCH-BLEND8 {entry} {pf:?} | {device} | through {} | Metal's {}/{} texels \ - | announced {noted:?}", - form(&lane), - TEXELS - wrong.len(), - TEXELS, - ); - if interlock { - assert!(noted.is_empty(), "{what}: announced {noted:?}"); + checked(&lane, (entry, pf), ¬ed, &wrong); + drawn += 1; + } + } + } + assert!(drawn > 0, "no draw on {device}"); + let _ = messages.take_notices(); + quiet(lane, &messages); +} + +/// One lane's operands as Metal's blend reads them, each rounded to the arithmetic's type: the +/// source lane `s` and alpha `sa` clamped, the destination lane `d` and alpha `da` decoded, and +/// the blend color's lane `c` and alpha `ca` clamped. +#[derive(Clone, Copy)] +struct Operands { + s: f64, + sa: f64, + d: f64, + da: f64, + c: f64, + ca: f64, +} + +/// A lane's Metal arithmetic, in `float` where the first flag says so and without fast math +/// where the second does. +type Form = fn((bool, bool), Operands) -> f64; + +/// `x` rounded to `float` where `float`, else to `half`. +fn rounded(float: bool, x: f64) -> f64 { + match float { + true => f64::from(x as f32), + false => h(x), + } +} + +/// `a b + c` rounded once, in `float` where `float`, else in `half` (exact in `f64` over a blend's +/// `half` operands). +fn fused(float: bool, (a, b, c): (f64, f64, f64)) -> f64 { + match float { + true => f64::from((a as f32).mul_add(b as f32, c as f32)), + false => h(a * b + c), + } +} + +/// `x y + z w`, each product rounded, then their sum, in `float` where `float`, else `half`. +fn sum(float: bool, (x, y): (f64, f64), (z, w): (f64, f64)) -> f64 { + rounded(float, rounded(float, x * y) + rounded(float, z * w)) +} + +/// The states [`other_blends_masks_and_the_blend_color_store_metals_blend`] draws: the blend +/// (color factors and operation, then alpha's), the write mask, the encoder's blend color, and +/// the color and alpha lanes' Metal arithmetic (`None` where the mask keeps the lane). +type State = ( + [(BlendFactor, BlendFactor, BlendOperation); 2], + ColorWriteMask, + [f32; 4], + Option
, + Option, +); + +/// Other blends, write masks and the blend color, into `BGRA8Unorm`: Metal's arithmetic (EVs +/// FB8-sw2-m3, FB8-bc1-m3, FB8-sc1-m3 and FB8-ao1-m3, plain Metal on the M3 Max under macOS +/// 27.0.1) is each color lane's and alpha's form `Blend::unorm8` names; a channel the mask leaves +/// out keeps its code. Each draw's channels are Metal's where it announces none of [`NOTES`], and +/// on a device that fetches through the pixel interlock it announces none. +#[test] +fn other_blends_masks_and_the_blend_color_store_metals_blend() { + use BlendFactor as F; + use BlendOperation as O; + let states: [State; 4] = [ + // Source alpha over: the color's source product rounded first, alpha a lerp of the + // source alpha from the destination's. + ( + [ + (F::SourceAlpha, F::OneMinusSourceAlpha, O::Add), + (F::SourceAlpha, F::OneMinusSourceAlpha, O::Add), + ], + ColorWriteMask::ALL, + [0.0; 4], + Some(|(float, safe), l| { + let m = rounded(float, 1.0 - l.sa); + match safe { + false => fused(float, (l.d, m, rounded(float, l.s * l.sa))), + true => sum(float, (l.s, l.sa), (l.d, m)), } - if noted.is_empty() { - let shown = &wrong[..wrong.len().min(8)]; - assert!( - wrong.is_empty(), - "{what}: {} of {TEXELS} texels differ from Metal's, first (index, read, \ - Metal's) {shown:?}", - wrong.len() - ); + }), + Some(|(float, safe), l| match safe { + false => fused(float, (l.sa, rounded(float, l.sa - l.da), l.da)), + true => sum(float, (l.sa, l.sa), (l.da, rounded(float, 1.0 - l.sa))), + }), + ), + // The blend color, one channel past each end: lerps of it under fast math. + ( + [ + (F::BlendColor, F::OneMinusBlendColor, O::Add), + (F::BlendAlpha, F::OneMinusBlendAlpha, O::Add), + ], + ColorWriteMask::ALL, + [0.3, -0.25, 1.5, 0.45], + Some(|(float, safe), l| match safe { + false => fused(float, (l.c, rounded(float, l.s - l.d), l.d)), + true => sum(float, (l.s, l.c), (l.d, rounded(float, 1.0 - l.c))), + }), + Some(|(float, safe), l| match safe { + false => fused(float, (l.ca, rounded(float, l.sa - l.da), l.da)), + true => sum(float, (l.sa, l.ca), (l.da, rounded(float, 1.0 - l.ca))), + }), + ), + // Blue alone stored: a lerp of the source alpha a vector does not take. + ( + [ + (F::OneMinusSourceAlpha, F::SourceAlpha, O::Add), + (F::One, F::Zero, O::Add), + ], + ColorWriteMask::BLUE, + [0.0; 4], + Some(|(float, safe), l| match safe { + false => fused(float, (l.sa, rounded(float, l.d - l.s), l.s)), + true => sum(float, (l.s, rounded(float, 1.0 - l.sa)), (l.d, l.sa)), + }), + None, + ), + // Alpha alone stored: the color channels' destination factor computes one minus the + // destination alpha still, so alpha takes no lerp of it. + ( + [ + (F::Zero, F::OneMinusDestinationAlpha, O::Add), + (F::OneMinusDestinationColor, F::DestinationColor, O::Add), + ], + ColorWriteMask::ALPHA, + [0.0; 4], + None, + Some(|(float, safe), l| { + let m = rounded(float, 1.0 - l.da); + match safe { + false => fused(float, (l.sa, m, rounded(float, l.da * l.da))), + true => sum(float, (l.sa, m), (l.da, l.da)), } + }), + ), + ]; + let kinds = NOTES.map(Degradation::from_precision_note); + let (messages, _cache, lane) = lane_with(|options| { + options.announce_each = kinds.into_iter().collect(); + }); + let device = lane.device.name(); + let (pf, order) = FORMATS[0]; + let mut drawn = 0; + for fixture in &FIXTURES { + let library = library(&lane, fixture.stem); + for &(entry, output) in &fixture.cases[..2] { + for ([color, alpha], mask, bc, color_form, alpha_form) in states { + let mut blended = ColorAttachmentDescriptor::new(pf); + blended.blending_enabled = true; + ( + blended.source_rgb_blend_factor, + blended.destination_rgb_blend_factor, + blended.rgb_blend_operation, + ) = color; + ( + blended.source_alpha_blend_factor, + blended.destination_alpha_blend_factor, + blended.alpha_blend_operation, + ) = alpha; + blended.write_mask = mask; + let Some(state) = pipeline(&lane, (&library, fixture), entry, blended) else { + continue; + }; + let (texels, sources) = data(output); + let data = (output, texels.as_slice(), sources.as_slice()); + let (read, noted) = draw((&lane, &messages), &state, (pf, order), data, bc); + let float = output == Output::Float; + let read_as = |x: f64| rounded(float, clamp01(x)); + let mut wrong = Vec::new(); + for (i, &codes) in texels.iter().enumerate() { + let got = &read[4 * i..4 * i + 4]; + let s = returned(output, order, (i, codes), &sources); + let operands = |c: usize| Operands { + s: read_as(s[c]), + sa: read_as(s[3]), + d: rounded(float, f64::from(codes[c]) / 255.0), + da: rounded(float, f64::from(codes[3]) / 255.0), + c: read_as(f64::from(bc[c])), + ca: read_as(f64::from(bc[3])), + }; + let want: Vec = order + .iter() + .map(|&c| { + let form = if c < 3 { color_form } else { alpha_form }; + let bit = [ + ColorWriteMask::RED, + ColorWriteMask::GREEN, + ColorWriteMask::BLUE, + ColorWriteMask::ALPHA, + ][c]; + match form.filter(|_| mask.contains(bit)) { + Some(form) => { + let v = form((float, fixture.safe), operands(c)); + (clamp01(v) * 255.0 + 0.5).floor() as u8 + } + None => codes[c], + } + }) + .collect(); + if got != want.as_slice() { + wrong.push((i, got.to_vec(), want)); + } + } + let what = format!("{entry} {color:?} {alpha:?} {mask:?} {bc:?}"); + checked(&lane, (&what, pf), ¬ed, &wrong); drawn += 1; } } diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 67e44b06a..150581e8c 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -60,7 +60,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 1754; +pub const SEMANTICS_VERSION: u32 = 1755; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs b/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs index 47a4b410d..b6ae2b715 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range/blend.rs @@ -143,17 +143,35 @@ impl Atom { matches!(self, Atom::Sa | Atom::Da | Atom::Ca | Atom::S1a) } - /// An inner sum's order among its atoms: the source's before the destination's. - fn order(self) -> u8 { - match self { - Atom::S | Atom::Sa | Atom::Sf => 0, - Atom::S1 | Atom::S1a => 1, - Atom::D | Atom::Da => 2, - Atom::C | Atom::Ca => 9, + /// An inner sum's order among its atoms under `scheme`. + fn order(self, scheme: Order) -> u8 { + match (self, scheme) { + (Atom::C | Atom::Ca, _) => 9, + (Atom::S1 | Atom::S1a, _) => 1, + (Atom::S | Atom::Sa | Atom::Sf, Order::Source) => 0, + (Atom::D | Atom::Da, Order::Source) => 2, + (Atom::S | Atom::Sa | Atom::Sf, Order::Destination) => 2, + (Atom::D | Atom::Da, Order::Destination) => 0, + (Atom::Da, Order::Scalar) => 0, + (Atom::D, Order::Scalar) => 1, + (Atom::Sa, Order::Scalar) => 2, + (Atom::S | Atom::Sf, Order::Scalar) => 3, } } } +/// An inner sum's order among its atoms ([`Atom::order`]). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Order { + /// The source's before the destination's. + Source, + /// The destination's before the source's: an 8-bit unorm attachment's blend. + Destination, + /// The destination's before the source's, and each alpha before its lane: an 8-bit unorm + /// attachment's color channel stored alone. + Scalar, +} + /// A factor or operand of a blend lane. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum Node { @@ -355,6 +373,29 @@ fn alpha_rank(f: BlendFactor) -> u8 { } } +/// An 8-bit unorm attachment's factor rank, of a color factor or alpha's where `alpha`, in the +/// arithmetic `arith`: of an added pair, the destination's product is rounded first where the +/// source factor's rank is at least the destination factor's, else the source's (EVs FB8-sw2-m3 +/// and FB8-rnd1-m3). +fn unorm8_rank(f: BlendFactor, alpha: bool, arith: BlendArith) -> u8 { + use BlendFactor as F; + let float = arith == BlendArith::Float; + match f { + F::SourceColor + | F::SourceAlpha + | F::DestinationColor + | F::OneMinusDestinationColor + | F::DestinationAlpha + | F::OneMinusDestinationAlpha => 0, + F::OneMinusSourceColor | F::OneMinusSourceAlpha if alpha && !float => 0, + F::OneMinusSourceColor | F::OneMinusSourceAlpha | F::SourceAlphaSaturated => 1, + F::BlendColor | F::BlendAlpha if float => 1, + F::BlendColor | F::BlendAlpha => 2, + F::OneMinusBlendColor | F::OneMinusBlendAlpha => 3, + _ => 9, + } +} + /// The factor `n` of a format without alpha (`BGR10_XR`, `R16Float`, `RG16Float`): its destination /// alpha is one. fn opaque(n: Node) -> Node { @@ -375,17 +416,21 @@ struct Shared { leaves: Vec, } -/// Whether an inner sum keeps the one-minus node `n`, added with `sign` as its `i`th pair, whole -/// beyond the nodes that always stay whole ([`inner_sum`]): a shared value added second; under a -/// `float4` output's alpha (`float_alpha`), a shared value or leaf added second or first in a -/// difference (`op`), and in a lerp's destination form (`lerp_destination`) a shared value added -/// anywhere. +/// Whether an inner sum keeps the one-minus node `n`, added with `sign` as its `i`th pair (from +/// the destination's product where `destination`), whole beyond the nodes that always stay whole +/// ([`inner_sum`]): a shared value added second; under a `float4` output's alpha +/// (`float_alpha`), a shared value or leaf added second or first in a difference (`op`), and in a +/// lerp's destination form (`lerp_destination`) a shared value added anywhere. An 8-bit unorm +/// attachment's blend (`unorm8`) keeps a shared value added from the destination's product. fn kept_whole( - (n, sign, i): (Node, i8, usize), + (n, sign, i, destination): (Node, i8, usize, bool), shared: &Shared, - (float_alpha, op, lerp_destination): (bool, BlendOperation, bool), + (float_alpha, op, lerp_destination, unorm8): (bool, BlendOperation, bool, bool), ) -> bool { let added = sign > 0; + if unorm8 { + return shared.values.contains(&n) && added && destination; + } if !float_alpha { return shared.values.contains(&n) && added && i > 0; } @@ -394,25 +439,27 @@ fn kept_whole( || (lerp_destination && shared.values.contains(&n) && added) } -/// The summands of `pairs` (each a node and its sign, in the IR's order) as Metal's compiler -/// adds them: each `1 - z` expanded into `1` and `-z` but where it stays one value (a blend -/// color's; an alpha's in a color lane; where `keep` says so, [`kept_whole`]), equal terms -/// merged, and the terms ordered: the constant last, but between the two others where they are -/// not both subtracted, after the one of the lower [`Atom::order`]. Where `half_reads` (a -/// `float4` output's color lanes), the first two summands read an unrounded source lane -/// ([`Atom::Sf`]) beside a splat alpha as `half` ([`Atom::S`]). +/// The summands of `pairs` (each a node, its sign, and whether it comes from the destination's +/// product, in the IR's order) as Metal's compiler adds them: each `1 - z` expanded into `1` and +/// `-z` but where it stays one value (a blend color's; an alpha's in a color lane of a vector +/// class, `scalar` false; where `keep` says so, [`kept_whole`]), equal terms merged, and the terms +/// ordered: the constant last, but between the two others where they are not both subtracted, +/// after the one of the lower [`Atom::order`] under `order`. Where +/// `half_reads` (a `float4` output's color lanes), the first two summands read an unrounded source +/// lane ([`Atom::Sf`]) beside a splat alpha as `half` ([`Atom::S`]). fn inner_sum( - pairs: [(Node, i8); 2], - alpha: bool, - keep: &dyn Fn((Node, i8, usize)) -> bool, + pairs: [(Node, i8, bool); 2], + (scalar, order): (bool, Order), + keep: &dyn Fn((Node, i8, usize, bool)) -> bool, half_reads: bool, ) -> Vec { let mut terms: Vec = Vec::with_capacity(4); - for (i, (n, sign)) in pairs.into_iter().enumerate() { + for (i, (n, sign, destination)) in pairs.into_iter().enumerate() { match n { Node::OneMinus(z) => { - let leaf = - matches!(z, Atom::C | Atom::Ca) || (!alpha && z.splat()) || keep((n, sign, i)); + let leaf = matches!(z, Atom::C | Atom::Ca) + || (!scalar && z.splat()) + || keep((n, sign, i, destination)); if leaf { terms.push((sign, Some(n))); } else { @@ -436,11 +483,11 @@ fn inner_sum( let rest: Vec = merged.iter().copied().filter(|m| m.1.is_some()).collect(); let mut ordered = match (constant, rest.as_slice()) { (Some(one), &[a, b]) if a.0 > 0 || b.0 > 0 => { - let order = |m: Summand| match m.1 { - Some(Node::Atom(x)) => x.order(), + let rank = |m: Summand| match m.1 { + Some(Node::Atom(x)) => x.order(order), _ => 9, }; - match order(b) < order(a) { + match rank(b) < rank(a) { true => vec![b, one, a], false => vec![a, one, b], } @@ -468,14 +515,24 @@ fn raw_term(t: &Term) -> bool { /// The arithmetic of a lane class (alpha where `alpha`) of factors `fs` and `fd` under `op`, /// `shared` the one-minus nodes of the color factors that alpha's sums and lerps take apart, -/// `opaque_` for a format without alpha, and `float` for a `float4` output's. +/// `opaque_` for a format without alpha, `float` for a `float4` output's, in the rules of +/// `family`. `scalar` marks a color class of one channel (an 8-bit unorm attachment's write mask +/// of one color channel), which Metal plans as a scalar: an alpha read there is no splat, but a +/// one minus an alpha that its destination factor is or that alpha's factors compute (`shared`) +/// stays whole in its sums and takes no lerp. fn plan( (fs, fd, op): (BlendFactor, BlendFactor, BlendOperation), - alpha: bool, + (alpha, scalar): (bool, bool), shared: &Shared, - opaque_: bool, - float: bool, + (opaque_, float): (bool, bool), + family: Family, ) -> Result { + let unorm8 = matches!(family, Family::Unorm8(_)); + let order = match (unorm8, scalar) { + (false, _) => Order::Source, + (true, false) => Order::Destination, + (true, true) => Order::Scalar, + }; // A `float4` output's color lanes read their source lane unrounded. let raw = float && !alpha; let float_alpha = float && alpha; @@ -551,20 +608,45 @@ fn plan( let sops = (Node::Atom(s), nfs); let dops = (Node::Atom(da), nfd); let both_orders = |p: (Node, Node)| [(p.0, p.1), (p.1, p.0)]; + // A color channel stored alone keeps whole the one minus an alpha its destination factor is + // and those alpha's factors compute. + let mut alone = shared.values.clone(); + if matches!(nfd, Node::OneMinus(z) if z.splat()) { + alone.push(nfd); + } + let alone = &alone; let keep_in = |lerp_destination: bool| { - move |k: (Node, i8, usize)| kept_whole(k, shared, (float_alpha, op, lerp_destination)) + move |k: (Node, i8, usize, bool)| match scalar { + true => alone.contains(&k.0), + false => kept_whole(k, shared, (float_alpha, op, lerp_destination, unorm8)), + } }; + // An 8-bit unorm attachment's lerp takes the destination's product for `y`'s first. + let mut sides = [(true, (sops, dops)), (false, (dops, sops))]; + if unorm8 { + sides.reverse(); + } if op == BlendOperation::Add { - for (source_side, (yt, zo)) in [(true, (sops, dops)), (false, (dops, sops))] { + for (source_side, (yt, zo)) in sides { for (y, f) in both_orders(yt) { let Node::OneMinus(za) = f else { continue; }; - if shared.values.contains(&f) && za == Atom::Ca { + // No lerp of a one minus the color factors computed (8-bit unorm: the destination + // alpha's too). + if shared.values.contains(&f) && (za == Atom::Ca || (unorm8 && za == Atom::Da)) { continue; } let both = [sops.0, sops.1].contains(&f) && [dops.0, dops.1].contains(&f); - if !alpha && (za.splat() || y == Node::Atom(za) || both) { + if !alpha && !scalar && (za.splat() || y == Node::Atom(za) || both) { + continue; + } + if scalar && (alone.contains(&f) || y == Node::Atom(za) || both) { + continue; + } + // An 8-bit unorm attachment's alpha takes no lerp of the destination alpha beside + // itself or held by both products. + if unorm8 && alpha && za == Atom::Da && (y == Node::Atom(za) || both) { continue; } // A `float4` output's alpha takes no lerp of a one minus the source alpha the @@ -577,7 +659,9 @@ fn plan( let z = Node::Atom(za); if let Some((_, x)) = both_orders(zo).into_iter().find(|&(zj, _)| zj == z) { let keep = keep_in(!source_side); - let inner = inner_sum([(x, 1), (y, -1)], alpha, &keep, raw); + // `x` comes from the other product than `y`. + let pairs = [(x, 1, source_side), (y, -1, !source_side)]; + let inner = inner_sum(pairs, (alpha || scalar, order), &keep, raw); return Ok(Arith::Lerp { y, z, inner }); } } @@ -601,8 +685,8 @@ fn plan( for (zd, y) in both_orders(dops) { if z == zd && !matches!(z, Node::Zero | Node::One) { let pair = match op { - BlendOperation::ReverseSubtract => [(y, pd), (x, ps)], - _ => [(x, ps), (y, pd)], + BlendOperation::ReverseSubtract => [(y, pd, true), (x, ps, false)], + _ => [(x, ps, false), (y, pd, true)], }; // A difference of the destination's products by a splat alpha reads the source // unrounded and rounds its sum. @@ -610,14 +694,14 @@ fn plan( && matches!(x, Node::Atom(_)) && matches!(y, Node::Atom(Atom::Sa | Atom::Da)); if raw && z == Node::Atom(Atom::D) && splat_difference { - let inner = inner_sum(pair, alpha, &keep, false); + let inner = inner_sum(pair, (alpha || scalar, order), &keep, false); return Ok(Arith::Common { z, inner, round_inner: true, }); } - let inner = inner_sum(pair, alpha, &keep, raw); + let inner = inner_sum(pair, (alpha || scalar, order), &keep, raw); return Ok(Arith::Common { z, inner, @@ -635,6 +719,13 @@ fn plan( fused: (ps, st), }; use BlendFactor as F; + if let (Family::Unorm8(arith), BlendOperation::Add) = (family, op) { + let rank = |f| unorm8_rank(f, alpha, arith); + return Ok(match rank(fs) >= rank(fd) { + true => destination_first, + false => source_first, + }); + } Ok(match op { BlendOperation::ReverseSubtract => source_first, BlendOperation::Subtract => destination_first, @@ -750,19 +841,35 @@ fn planned( (float, math): (bool, BlendMath), ) -> Result { let has_alpha = !matches!(form, ExtendedRange::Bgr10 { .. }); - planned_for(eq, (has_alpha, form.srgb(), false), written, (float, math)) + let family = Family::Extended { srgb: form.srgb() }; + planned_for(eq, (has_alpha, family), written, (float, math)) } -/// [`planned`] for a format with an alpha channel where `has_alpha`, an `_sRGB` extended-range -/// form where `srgb`, and a 16-bit float attachment's blend where `sixteen` -/// ([`Blend::half_float`]), which takes fast math's color channels' blend color difference (an -/// extended-range form refuses it). +/// The attachment whose blend Metal's compiler builds, whose forms differ: an extended-range +/// form's (an `_sRGB` one's where `srgb`), a 16-bit float attachment's ([`Blend::half_float`]), or +/// an 8-bit unorm one's in the arithmetic of the output's type ([`Blend::unorm8`]). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Family { + Extended { srgb: bool }, + HalfFloat, + Unorm8(BlendArith), +} + +/// [`planned`] for a format with an alpha channel where `has_alpha`, of `family`: a 16-bit float +/// or 8-bit unorm attachment's blend takes fast math's color channels' blend color difference +/// (an extended-range form refuses it), and an 8-bit unorm one's a write mask of one color +/// channel, which Metal plans as a scalar. fn planned_for( eq: &BlendEquation, - (has_alpha, srgb, sixteen): (bool, bool, bool), + (has_alpha, family): (bool, Family), written: ColorWriteMask, (float, math): (bool, BlendMath), ) -> Result { + let srgb = family == Family::Extended { srgb: true }; + let sixteen = !matches!(family, Family::Extended { .. }); + let unorm8 = matches!(family, Family::Unorm8(_)); + // A zero factor keeps its product without fast math in a 16-bit float attachment's blend. + let keep_zero = family == Family::HalfFloat; let colors = [ ColorWriteMask::RED, ColorWriteMask::GREEN, @@ -783,7 +890,7 @@ fn planned_for( let opaque_ = !has_alpha; let color = match colors { 0 => None, - 1 if fast => return Err(refused(ExtendedRangeBlend::OneColorChannel)), + 1 if fast && !unorm8 => return Err(refused(ExtendedRangeBlend::OneColorChannel)), _ => { let pair = [eq.source_rgb, eq.destination_rgb]; let differs = matches!( @@ -795,9 +902,36 @@ fn planned_for( return Err(refused(ExtendedRangeBlend::ConstantColorDifference)); } let f = (eq.source_rgb, eq.destination_rgb, eq.rgb_operation); + let scalar = unorm8 && colors == 1; + // A color channel stored alone shares the one minus an alpha that alpha's factors + // compute, stored or not. + let mut computed = Shared::default(); + let alpha_factors = !matches!( + eq.alpha_operation, + BlendOperation::Min | BlendOperation::Max + ); + if scalar && has_alpha && alpha_factors { + use BlendFactor as F; + let uses = |f: [F; 2]| { + f.iter() + .any(|f| [eq.source_alpha, eq.destination_alpha].contains(f)) + }; + for (f, z) in [ + ([F::OneMinusSourceAlpha, F::OneMinusSourceColor], Atom::Sa), + ( + [F::OneMinusDestinationAlpha, F::OneMinusDestinationColor], + Atom::Da, + ), + ([F::OneMinusBlendAlpha, F::OneMinusBlendColor], Atom::Ca), + ] { + if uses(f) { + computed.values.push(Node::OneMinus(z)); + } + } + } Some(match math { - BlendMath::Fast => plan(f, false, &Shared::default(), opaque_, float)?, - BlendMath::Rounded => plan_rounded(f, false, (opaque_, sixteen))?, + BlendMath::Fast => plan(f, (false, scalar), &computed, (opaque_, float), family)?, + BlendMath::Rounded => plan_rounded(f, false, (opaque_, keep_zero))?, }) } }; @@ -818,10 +952,45 @@ fn planned_for( if float && uses(BlendFactor::OneMinusDestinationAlpha) { shared.leaves.push(Node::OneMinus(Atom::Da)); } + // An 8-bit unorm attachment's alpha shares what color lanes it stores compute: one + // minus the blend alpha, the source alpha, and the destination alpha (which + // `SourceAlphaSaturated` computes too); with no color channel stored, the one minus + // an alpha the color channels' destination factor is, which Metal computes still. A + // minimum or maximum computes no factor. + if unorm8 { + use BlendFactor as F; + shared = Shared::default(); + let factors = + !matches!(eq.rgb_operation, BlendOperation::Min | BlendOperation::Max); + if colors == 0 && factors { + let z = match eq.destination_rgb { + F::OneMinusBlendAlpha => Some(Atom::Ca), + F::OneMinusSourceAlpha => Some(Atom::Sa), + F::OneMinusDestinationAlpha => Some(Atom::Da), + _ => None, + }; + shared.values = z.map(Node::OneMinus).into_iter().collect(); + } + if colors > 0 && factors { + let minus = [ + (uses(F::OneMinusBlendAlpha), Atom::Ca), + (uses(F::OneMinusSourceAlpha), Atom::Sa), + ( + uses(F::OneMinusDestinationAlpha) || uses(F::SourceAlphaSaturated), + Atom::Da, + ), + ]; + shared.values = minus + .into_iter() + .filter(|&(u, _)| u) + .map(|(_, z)| Node::OneMinus(z)) + .collect(); + } + } let f = (eq.source_alpha, eq.destination_alpha, eq.alpha_operation); Some(match math { - BlendMath::Rounded => plan_rounded(f, true, (opaque_, sixteen))?, - BlendMath::Fast => plan(f, true, &shared, opaque_, float)?, + BlendMath::Rounded => plan_rounded(f, true, (opaque_, keep_zero))?, + BlendMath::Fast => plan(f, (true, false), &shared, (opaque_, float), family)?, }) } }; @@ -955,7 +1124,12 @@ impl Blend { PixelFormat::RG16Float => 2, _ => 4, }; - let b = planned_for(eq, (channels == 4, false, true), written, (false, math))?; + let b = planned_for( + eq, + (channels == 4, Family::HalfFloat), + written, + (false, math), + )?; let b = Blend { negates_one_minus: channels > 1 && math == BlendMath::Fast, ..b @@ -966,39 +1140,82 @@ impl Blend { } } - /// Metal's blend `eq` of a four-lane `half` or `float` output of a module of math `math` into - /// an 8-bit unorm attachment of format `pf` (`R8Unorm`, `RG8Unorm`, `RGBA8Unorm`, - /// `BGRA8Unorm`) storing the channels `written` of four (a channel the format lacks counts as - /// written), computed by [`blend_unorm8`]: the 16-bit float blend's forms in the arithmetic of - /// the output's type ([`Blend::half_float`]), of the output clamped to `[0, 1]` and the - /// destination's code decoded in that type, the result stored by Metal's unorm write. Modelled - /// for premultiplied source-over (`One` over `OneMinusSourceAlpha`, added, for color and - /// alpha) storing every channel of the format, whose fused form (fast math) and rounded form - /// (without) hold Metal's code in every channel (EV FB8-sw1-m3, plain Metal on the M3 Max - /// under macOS 27.0.1, `lower::fragment::fetch`'s module docs); another blend or write mask is - /// not built - /// (`Feature::FramebufferFetch` `NotImplemented`). + /// Metal's blend `eq` of a four-lane output of a module of math `math`, blended in `arith` + /// (the output's type), into an 8-bit unorm attachment of format `pf` (`R8Unorm`, `RG8Unorm`, + /// `RGBA8Unorm`, `BGRA8Unorm`) storing the channels `written` of four (a channel the format + /// lacks counts as written), computed by [`blend_unorm8`] over the output clamped to `[0, 1]` + /// and the destination's code decoded in that type, the result stored by Metal's unorm write. + /// Without fast math the rounded forms (the module docs). Under fast math the 16-bit float + /// blend's forms, but as Metal's compiler builds an 8-bit unorm attachment's blend (EVs + /// FB8-sw2-m3, FB8-rnd1-m3 and FB8-mk1-m3, plain Metal on the M3 Max under macOS 27.0.1, + /// `lower::fragment::fetch`'s module docs): + /// + /// - an inner sum adds the destination's atoms before the source's ([`Atom::order`]); + /// - a lerp takes `y` from the destination's product first, and alpha takes no lerp of the + /// destination alpha beside itself or held by both products; + /// - of an added pair the product rounded first follows [`unorm8_rank`]; + /// - alpha shares the one minus the blend alpha, the source alpha and the destination alpha + /// (`SourceAlphaSaturated`'s too) that stored color lanes compute, and with no color + /// channel stored the one minus an alpha the color channels' destination factor is + /// (EV FB8-ao1-m3), where the color channels' operation is no minimum or maximum, which + /// computes no factor (EV FB8-mm1-m3): it takes no lerp of a shared blend or destination + /// alpha, and its sums keep a shared one minus whole where they add it from the + /// destination's product; + /// - a write mask of one color channel plans that channel as a scalar (EV FB8-sc1-m3): its + /// alpha reads are no splats, but it keeps whole, and takes no lerp of, a one minus an alpha + /// that its destination factor is or that alpha's factors compute, alpha stored or not; its + /// sums add the destination alpha before the destination's lane, then the source alpha + /// before the source's ([`Order::Scalar`]). + /// + /// A factor of the second source is not built (`Feature::FramebufferFetch` `NotImplemented`): + /// its output is not planned beside the storage form's write. Nor, under fast math, is a + /// format without alpha's (`R8Unorm`, `RG8Unorm`) lerp, common factor or contracted pair: Metal + /// sums those in forms of their own, not measured. pub fn unorm8( eq: &BlendEquation, pf: PixelFormat, written: ColorWriteMask, - math: BlendMath, + (math, arith): (BlendMath, BlendArith), ) -> Result { use BlendFactor as F; - let over = |s: BlendFactor, d: BlendFactor, op: BlendOperation| { - (s, d, op) == (F::One, F::OneMinusSourceAlpha, BlendOperation::Add) - }; - let source_over = over(eq.source_rgb, eq.destination_rgb, eq.rgb_operation) - && over(eq.source_alpha, eq.destination_alpha, eq.alpha_operation); let has_alpha = match pf { PixelFormat::R8Unorm | PixelFormat::RG8Unorm => false, PixelFormat::RGBA8Unorm | PixelFormat::BGRA8Unorm => true, _ => return Err(Unsupported::not_implemented(Feature::FramebufferFetch).into()), }; - if !source_over || written != ColorWriteMask::ALL { + let factors = [ + eq.source_rgb, + eq.destination_rgb, + eq.source_alpha, + eq.destination_alpha, + ]; + let second = |f: &BlendFactor| { + matches!( + f, + F::Source1Color + | F::OneMinusSource1Color + | F::Source1Alpha + | F::OneMinusSource1Alpha + ) + }; + if factors.iter().any(second) { return Err(Unsupported::not_implemented(Feature::FramebufferFetch).into()); } - planned_for(eq, (has_alpha, false, false), written, (false, math)) + let family = Family::Unorm8(arith); + let b = planned_for(eq, (has_alpha, family), written, (false, math))?; + // A format without alpha sums its two products in forms of its own (EV FB8-r8-m3): of + // its fast-math forms only a single or fused product, zero, and a minimum or maximum are + // measured. + let measured = |a: &Arith| { + matches!( + a, + Arith::MinMax { .. } | Arith::Zero | Arith::Term { .. } | Arith::Fused { .. } + ) + }; + if !has_alpha && math == BlendMath::Fast && !b.color.iter().all(measured) { + return Err(Unsupported::not_implemented(Feature::FramebufferFetch).into()); + } + Ok(b) } /// Whether every class the blend stores takes a form the 16-bit float sweeps fit in every state @@ -1878,18 +2095,48 @@ pub fn blend_half_float( /// unorm write (`arith::color_write`'s 8-bit unorm rule). Metal clamps the output to `[0, 1]` /// first, a NaN to 0, every lane ([`clamped`]), and reads the destination as its code over 255 /// correctly rounded to the arithmetic's type ([`unorm8_tile_value`]), the value a fetch reads. +/// `color`, the encoder's blend color (a `uvec4` of its `f32`s' bits, `PushField::HalfBlendColor`, +/// where `b` reads it, [`Blend::reads_constant`]), is what `BlendColor` reads, clamped to `[0, 1]` +/// and rounded to `half` in `half` arithmetic (EV FB8-bc1-m3: blend colors past both ends of every +/// channel), and `OneMinusBlendColor` reads the one minus of that read under either math, +/// `h(1 - h(c))` (`f(1 - c)` in `float`; EV FB8-sw2-m3). A NaN blend color, which no probe drew, +/// reads 0. pub fn blend_unorm8( fb: &mut FunctionBuilder<'_>, b: &Blend, arith: BlendArith, (s, texel): (Value, Value), + color: Option, ) -> BResult { + let f = floats(); let s = clamped(fb, s, (0.0, 1.0))?; let d = unorm8_tile_value(fb, texel, arith)?; + let constant = match color { + Some(words) => { + let ft = ty(fb, f)?; + let c = fb.convert(ConvOp::Bitcast, words, ft)?; + let zero = fsplat(fb, f, 0.0)?; + let one = fsplat(fb, f, 1.0)?; + let nan = fb.unary(UnOp::IsNan, c)?; + let c = fb.select(nan, zero, c)?; + let c = fb.glsl(GlslOp::FClamp, &[c, zero, one])?; + let c = match arith { + BlendArith::Half => f32_to_half(fb, f, c, HalfRounding::NearestEven)?, + BlendArith::Float => c, + }; + let m = fb.binary_no_contraction(BinOp::FSub, one, c)?; + let m = match arith { + BlendArith::Half => f32_to_half(fb, f, m, HalfRounding::NearestEven)?, + BlendArith::Float => m, + }; + Some((c, m, c)) + } + None => None, + }; let inputs = Inputs { s, d, - constant: None, + constant, sf: None, math: b.math, s1: None, diff --git a/crates/metal2vulkan/src/lower/arith/tests/blend8.rs b/crates/metal2vulkan/src/lower/arith/tests/blend8.rs index 5006b338c..0ca97bcfa 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/blend8.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/blend8.rs @@ -1,21 +1,28 @@ //! A fetched 8-bit unorm attachment's blend on the interpreter -//! (`extended_range::blend::blend_unorm8`, then the 8-bit unorm rule of `arith::color_write`): -//! premultiplied source-over (one over one minus the source alpha, added, for color and alpha), +//! (`extended_range::blend::blend_unorm8`, then the 8-bit unorm rule of `arith::color_write`), //! of a `half4` or `float4` output, under fast math and without, against Metal's measured //! arithmetic. Metal clamps the output to `[0, 1]` (a NaN to 0), reads the destination's code `c` -//! as `h(c / 255)` (`f(c / 255)` for a `float4` output), blends in the output's type (fast math: -//! `h(fma(d, h(1 - a), s))`; without: `h(s + h(d · h(1 - a)))`; in `float` likewise), and stores -//! the result's code by its unorm write (a NaN 0, clamped, the exact product with 255 rounded to -//! nearest). The function writes that code as `c` times the `f32` nearest `1 / 255`. +//! as `h(c / 255)` (`f(c / 255)` for a `float4` output) and the blend color clamped to `[0, 1]` +//! (as `half` in `half` arithmetic), blends in the output's type, and stores the result's code by +//! its unorm write (a NaN 0, clamped, the exact product with 255 rounded to nearest). The function +//! writes that code as `c` times the `f32` nearest `1 / 255`. //! -//! EV FB8-sw1-m3 (plain Metal on the M3 Max under macOS 27.0.1, our own MSL of the guest's -//! shape, a 4096 x 961 target): every `half` alpha in `[0, 1]` against every destination code of -//! each channel, four source draws per pair (half aimed within four units in the last place of a +//! Premultiplied source-over (one over one minus the source alpha, added, for color and alpha): +//! fast math `h(fma(d, h(1 - a), s))`, without `h(s + h(d · h(1 - a)))`, in `float` likewise. +//! EV FB8-sw1-m3 (plain Metal on the M3 Max under macOS 27.0.1, our own MSL of the guest's shape, +//! a 4096 x 961 target): every `half` alpha in `[0, 1]` against every destination code of each +//! channel, four source draws per pair (half aimed within four units in the last place of a //! code's midpoint, 2% out of range, infinite or NaN), each of `half4` and `float4`, fast and safe: //! this arithmetic gives Metal's code in every one of 63 million channels per variant, into //! `BGRA8Unorm`, and `RGBA8Unorm`, `RG8Unorm` and `R8Unorm` alike. Here every alpha code's `half` //! (or `float`) meets every destination code in some lane, beside sources aimed at the codes' //! midpoints, out of range and NaN, and texels read a unit in the last place off `c / 255`. +//! +//! Other factors, operations, write masks and the blend color: a state of each rule +//! `Blend::unorm8` names (the color's contracted pair and alpha's lerp of source alpha over, the +//! blend color's lerps, a lone color channel's lerp, and alpha alone beside the color channels' +//! destination factor), against the arithmetic the probes measured (EVs FB8-sw2-m3, FB8-bc1-m3, +//! FB8-sc1-m3 and FB8-ao1-m3). use super::*; use crate::lower::arith::extended_range::blend::{blend_unorm8, Blend, BlendArith, BlendMath}; @@ -152,14 +159,14 @@ fn a_fetched_eight_bit_unorm_blend_stores_metals_code() { for math in [BlendMath::Fast, BlendMath::Rounded] { for pf in [PixelFormat::BGRA8Unorm, PixelFormat::R8Unorm] { let what = format!("{arith:?} {math:?} {pf:?}"); - let b = Blend::unorm8(&over, pf, ColorWriteMask::ALL, math) + let b = Blend::unorm8(&over, pf, ColorWriteMask::ALL, (math, arith)) .unwrap_or_else(|e| panic!("{what}: {e:?}")); check( &format!("the fetched 8-bit unorm blend, {what}"), &[f4, f4], f4, &|fb, x| { - let v = blend_unorm8(fb, &b, arith, (x[0], x[1]))?; + let v = blend_unorm8(fb, &b, arith, (x[0], x[1]), None)?; crate::lower::arith::color_write::round(fb, f4, v, &[unorm; 4], None) }, &cases, @@ -188,10 +195,10 @@ fn a_fetched_eight_bit_unorm_blend_stores_metals_code() { } } -/// Another blend of an 8-bit unorm attachment, a write mask that keeps a channel, and another -/// format are not measured: `Blend::unorm8` refuses each `NotImplemented(FramebufferFetch)`. +/// A factor of the second source, in any of the four factors, and another format are not built: +/// `Blend::unorm8` refuses each `NotImplemented(FramebufferFetch)`, under either math. #[test] -fn another_eight_bit_unorm_blend_is_not_built() { +fn a_second_source_or_another_format_is_not_built() { let over = BlendEquation { source_rgb: F::One, destination_rgb: F::OneMinusSourceAlpha, @@ -207,34 +214,301 @@ fn another_eight_bit_unorm_blend_is_not_built() { } _ => false, }; - let math = BlendMath::Fast; - let rgb = ColorWriteMask::RED - .union(ColorWriteMask::GREEN) - .union(ColorWriteMask::BLUE); let cases = [ ( BlendEquation { - source_rgb: F::SourceAlpha, + source_rgb: F::Source1Color, ..over }, PixelFormat::BGRA8Unorm, - ColorWriteMask::ALL, ), ( BlendEquation { - alpha_operation: O::Max, + destination_rgb: F::OneMinusSource1Color, ..over }, PixelFormat::RGBA8Unorm, - ColorWriteMask::ALL, ), - (over, PixelFormat::BGRA8Unorm, rgb), - (over, PixelFormat::RGBA8UnormSRGB, ColorWriteMask::ALL), + ( + BlendEquation { + source_alpha: F::Source1Alpha, + ..over + }, + PixelFormat::RG8Unorm, + ), + ( + BlendEquation { + destination_alpha: F::OneMinusSource1Alpha, + ..over + }, + PixelFormat::R8Unorm, + ), + (over, PixelFormat::RGBA8UnormSRGB), ]; - for (eq, pf, mask) in cases { - assert!( - refused(Blend::unorm8(&eq, pf, mask, math)), - "{eq:?} {pf:?} {mask:?}" - ); + for (eq, pf) in cases { + for math in [BlendMath::Fast, BlendMath::Rounded] { + assert!( + refused(Blend::unorm8( + &eq, + pf, + ColorWriteMask::ALL, + (math, BlendArith::Half) + )), + "{eq:?} {pf:?} {math:?}" + ); + } + } +} + +/// `x` rounded in `arith`: to `half`, nearest even, or to `float`. +fn rounded(arith: BlendArith, x: f64) -> f64 { + match arith { + BlendArith::Half => h(x), + BlendArith::Float => f64::from(x as f32), + } +} + +/// `a b + c` fused, rounded once in `arith` (a product of `half`s and its sum with one are exact +/// in `f64` over a blend's operands). +fn fused(arith: BlendArith, (a, b, c): (f64, f64, f64)) -> f64 { + match arith { + BlendArith::Half => h(a * b + c), + BlendArith::Float => f64::from((a as f32).mul_add(b as f32, c as f32)), + } +} + +/// One lane's operands as Metal's blend reads them: the source lane `s` and alpha `sa` clamped, +/// the destination lane `d` and alpha `da` decoded, and the blend color's lane `c` and alpha `ca` +/// clamped, each rounded to the arithmetic's type. +#[derive(Clone, Copy)] +struct Lane { + s: f64, + sa: f64, + d: f64, + da: f64, + c: f64, + ca: f64, +} + +#[test] +fn the_factor_set_masks_and_blend_color_store_metals_code() { + let f4 = vec(float(32), 4); + let u4 = vec(int(32), 4); + let unorm = Some(ChannelWrite::Unorm { bits: 8 }); + let one_over = 1.0f32 / 255.0; + let colors: [[f32; 4]; 2] = [[0.3, 0.6, 0.9, 0.45], [-0.25, 1.5, 0.321, 0.8]]; + let eq = |(fs, fd, op): (F, F, O), (sa, da, oa): (F, F, O)| BlendEquation { + source_rgb: fs, + destination_rgb: fd, + rgb_operation: op, + source_alpha: sa, + destination_alpha: da, + alpha_operation: oa, + }; + type Form = fn(BlendArith, BlendMath, Lane) -> f64; + // Each state, its format and mask, and the color and alpha lanes' Metal arithmetic (EVs + // FB8-sw2-m3, FB8-bc1-m3, FB8-sc1-m3 and FB8-ao1-m3); `None` where the lane keeps its texel. + let states: [( + BlendEquation, + PixelFormat, + ColorWriteMask, + Option, + Option, + ); 4] = [ + // Source alpha over: the color's source product rounded first; alpha a lerp of the + // source alpha from the destination's. + ( + eq( + (F::SourceAlpha, F::OneMinusSourceAlpha, O::Add), + (F::SourceAlpha, F::OneMinusSourceAlpha, O::Add), + ), + PixelFormat::BGRA8Unorm, + ColorWriteMask::ALL, + Some(|ar, math, l| { + let m = rounded(ar, 1.0 - l.sa); + match math { + BlendMath::Fast => fused(ar, (l.d, m, rounded(ar, l.s * l.sa))), + BlendMath::Rounded => { + rounded(ar, rounded(ar, l.s * l.sa) + rounded(ar, l.d * m)) + } + } + }), + Some(|ar, math, l| { + let m = rounded(ar, 1.0 - l.sa); + match math { + BlendMath::Fast => fused(ar, (l.sa, rounded(ar, l.sa - l.da), l.da)), + BlendMath::Rounded => { + rounded(ar, rounded(ar, l.sa * l.sa) + rounded(ar, l.da * m)) + } + } + }), + ), + // The blend color and its one minus: lerps of it under fast math. + ( + eq( + (F::BlendColor, F::OneMinusBlendColor, O::Add), + (F::BlendAlpha, F::OneMinusBlendAlpha, O::Add), + ), + PixelFormat::RGBA8Unorm, + ColorWriteMask::ALL, + Some(|ar, math, l| match math { + BlendMath::Fast => fused(ar, (l.c, rounded(ar, l.s - l.d), l.d)), + BlendMath::Rounded => { + let m = rounded(ar, 1.0 - l.c); + rounded(ar, rounded(ar, l.s * l.c) + rounded(ar, l.d * m)) + } + }), + Some(|ar, math, l| match math { + BlendMath::Fast => fused(ar, (l.ca, rounded(ar, l.sa - l.da), l.da)), + BlendMath::Rounded => { + let m = rounded(ar, 1.0 - l.ca); + rounded(ar, rounded(ar, l.sa * l.ca) + rounded(ar, l.da * m)) + } + }), + ), + // One color channel stored: a lerp of the source alpha a vector does not take. + ( + eq( + (F::OneMinusSourceAlpha, F::SourceAlpha, O::Add), + (F::One, F::Zero, O::Add), + ), + PixelFormat::BGRA8Unorm, + ColorWriteMask::BLUE, + Some(|ar, math, l| match math { + BlendMath::Fast => fused(ar, (l.sa, rounded(ar, l.d - l.s), l.s)), + BlendMath::Rounded => { + let m = rounded(ar, 1.0 - l.sa); + rounded(ar, rounded(ar, l.s * m) + rounded(ar, l.d * l.sa)) + } + }), + None, + ), + // Alpha alone stored: the color channels' destination factor still computes one minus + // the destination alpha, so alpha takes no lerp of it. + ( + eq( + (F::Zero, F::OneMinusDestinationAlpha, O::Add), + (F::OneMinusDestinationColor, F::DestinationColor, O::Add), + ), + PixelFormat::BGRA8Unorm, + ColorWriteMask::ALPHA, + None, + Some(|ar, math, l| { + let m = rounded(ar, 1.0 - l.da); + match math { + BlendMath::Fast => fused(ar, (l.sa, m, rounded(ar, l.da * l.da))), + BlendMath::Rounded => { + rounded(ar, rounded(ar, l.sa * m) + rounded(ar, l.da * l.da)) + } + } + }), + ), + ]; + for arith in [BlendArith::Half, BlendArith::Float] { + let float = arith == BlendArith::Float; + let mut rng = Rng(0xFAC7_0B1E ^ u64::from(float)); + let mut cases: Vec = Vec::new(); + for bc in colors { + let color: Vec = bc.iter().map(|c| u64::from(c.to_bits())).collect(); + for _ in 0..1500 { + let codes: Vec = (0..4).map(|_| (rng.next() % 256) as u32).collect(); + let a = h(f64::from((rng.next() % 256) as u32) / 255.0); + let s = codes + .iter() + .map(|&c| source(&mut rng, float, (a, c))) + .collect(); + let d = codes.iter().map(|&c| texel(&mut rng, c)).collect(); + cases.push(vec![s, d, color.clone()]); + } + } + for (e, pf, mask, color_form, alpha_form) in states { + for math in [BlendMath::Fast, BlendMath::Rounded] { + let what = format!("{arith:?} {math:?} {pf:?} {mask:?} {e:?}"); + let b = Blend::unorm8(&e, pf, mask, (math, arith)) + .unwrap_or_else(|err| panic!("{what}: {err:?}")); + assert_eq!(b.reads_constant(), pf == PixelFormat::RGBA8Unorm, "{what}"); + check( + &format!("the fetched 8-bit unorm blend, {what}"), + &[f4, f4, u4], + f4, + &|fb, x| { + let color = b.reads_constant().then_some(x[2]); + let v = blend_unorm8(fb, &b, arith, (x[0], x[1]), color)?; + crate::lower::arith::color_write::round(fb, f4, v, &[unorm; 4], None) + }, + &cases, + &|c| { + let code = |l: usize| (f64::from(f32v(c[1][l])) * 255.0).round() as u32; + let read = |x: f64| rounded(arith, clamp01(x)); + let lane = |l: usize| Lane { + s: read(f64::from(f32v(c[0][l]))), + sa: read(f64::from(f32v(c[0][3]))), + d: rounded(arith, f64::from(code(l)) / 255.0), + da: rounded(arith, f64::from(code(3)) / 255.0), + c: read(f64::from(f32v(c[2][l]))), + ca: read(f64::from(f32v(c[2][3]))), + }; + Some( + (0..4) + .map(|l| { + let form = if l < 3 { color_form } else { alpha_form }; + let got = match form { + Some(form) => { + let v = form(arith, math, lane(l)); + (clamp01(v) * 255.0 + 0.5).floor() as u32 + } + None => code(l), + }; + u64::from(((got as f32) * one_over).to_bits()) + }) + .collect(), + ) + }, + false, + ); + } + } + } +} + +/// A format without alpha (`R8Unorm`, `RG8Unorm`) sums its products under fast math in forms of +/// its own (EV FB8-r8-m3): a lerp, common factor or contracted pair is refused +/// `NotImplemented(FramebufferFetch)` there, a fused or single product built, and without fast +/// math every blend is built. +#[test] +fn a_format_without_alpha_builds_only_its_measured_fast_forms() { + let eq = |fs, fd| BlendEquation { + source_rgb: fs, + destination_rgb: fd, + rgb_operation: O::Add, + source_alpha: fs, + destination_alpha: fd, + alpha_operation: O::Add, + }; + // Each blend and whether fast math builds it. + let cases = [ + (eq(F::SourceAlpha, F::OneMinusSourceAlpha), false), + (eq(F::OneMinusSourceAlpha, F::SourceAlpha), false), + (eq(F::DestinationColor, F::OneMinusSourceAlpha), false), + (eq(F::One, F::OneMinusSourceAlpha), true), + (eq(F::Zero, F::SourceColor), true), + (eq(F::BlendColor, F::One), true), + ]; + for pf in [PixelFormat::R8Unorm, PixelFormat::RG8Unorm] { + for (e, fast) in cases { + for math in [BlendMath::Fast, BlendMath::Rounded] { + let built = Blend::unorm8(&e, pf, ColorWriteMask::ALL, (math, BlendArith::Half)); + let what = format!("{pf:?} {math:?} {e:?}"); + match built { + Ok(_) => assert!(fast || math == BlendMath::Rounded, "{what}"), + Err(crate::error::Error::Unsupported(u)) => { + assert!(!fast && math == BlendMath::Fast, "{what}"); + assert_eq!(u.feature, crate::error::Feature::FramebufferFetch, "{what}"); + assert_eq!(u.needs, crate::error::Needs::NotImplemented, "{what}"); + } + Err(e) => panic!("{what}: {e:?}"), + } + } + } } } diff --git a/crates/metal2vulkan/src/lower/fragment/fetch.rs b/crates/metal2vulkan/src/lower/fragment/fetch.rs index e750068d8..9940864f7 100644 --- a/crates/metal2vulkan/src/lower/fragment/fetch.rs +++ b/crates/metal2vulkan/src/lower/fragment/fetch.rs @@ -198,23 +198,27 @@ //! names for the blend alone (`FramebufferFetchInputs::half_blends`; elsewhere it stays a color //! attachment). //! -//! **An 8-bit unorm attachment's blend** (`R8Unorm`, `RG8Unorm`, `RGBA8Unorm`, `BGRA8Unorm`): -//! premultiplied source-over (`One` over `OneMinusSourceAlpha`, added, for color and alpha) of a -//! `half4` or `float4` output, every channel of the format written, the shader computes as Metal -//! does ([`unorm8_blended`]): the write reads the texel at the pixel inside the interlock in Metal's -//! channel order, clamps the output to `[0, 1]` (a NaN to 0), reads each code `c` as `h(c / 255)` -//! (`f(c / 255)` for a `float4` output), blends in the output's type, fused under fast math -//! (`h(fma(d, h(1 - a), s))`) and each step rounded without (`h(s + h(d · h(1 - a)))`), and stores -//! the result's code by Metal's unorm write (`extended_range::Blend::unorm8`, -//! `extended_range::blend::blend_unorm8`). EV FB8-sw1-m3 (plain Metal on the M3 Max under -//! macOS 27.0.1, our own MSL of the guest's shape): every `half` alpha in `[0, 1]` against every -//! code of each channel, four source draws per pair (half aimed within four units in the last -//! place of a code midpoint, 2% out of range, infinite or NaN), `half4` and `float4`, fast and safe -//! math, each of the four formats: Metal's code in every channel. The clamp keeps the output's own -//! arithmetic out of the blend (EV FB8-fold1-m3: products, sums and a regroup over the fetched -//! color, each the model's over the function's value), so the blend is Metal's wherever the module -//! states its math (`HalfOutputPrecision` for one naming none). Another blend, a write mask that -//! keeps a channel, an output of fewer lanes, and a second (index 1) output are not built. +//! **An 8-bit unorm attachment's blend** (`R8Unorm`, `RG8Unorm`, `RGBA8Unorm`, `BGRA8Unorm`) of a +//! `half4` or `float4` output the shader computes as Metal does ([`unorm8_blended`]): the write +//! reads the texel at the pixel inside the interlock in Metal's channel order, clamps the output to +//! `[0, 1]` (a NaN to 0), reads each code `c` as `h(c / 255)` (`f(c / 255)` for a `float4` output) +//! and the blend color clamped to `[0, 1]` (pushed as `PushField::HalfBlendColor`), blends in the +//! output's type in the forms Metal's compiler builds (`extended_range::Blend::unorm8`: fused and +//! regrouped under fast math, each step rounded without), stores the result's code by Metal's unorm +//! write (`extended_range::blend::blend_unorm8`), and keeps the codes of the channels its write +//! mask leaves out. EVs, plain Metal on the M3 Max under macOS 27.0.1: FB8-sw1-m3 (premultiplied +//! source-over, every `half` alpha in `[0, 1]` against every code of each channel, `half4` and +//! `float4`, fast and safe math, each of the four formats: Metal's code in every channel); +//! FB8-sw2-m3 and FB8-rnd1-m3 (every factor and operation pair for color beside source-over alpha +//! and the reverse, the same pair for both, and random pairs, over every destination code times +//! every source alpha code); FB8-mk1-m3, FB8-sc1-m3 and FB8-ao1-m3 (write masks, one color +//! channel and alpha alone among them); FB8-bc1-m3 (blend colors past both ends). The clamp keeps +//! the output's own arithmetic out of the blend (EV FB8-fold1-m3: products, sums and a regroup +//! over the fetched color, each the model's over the function's value), so the blend is Metal's +//! wherever the module states its math (`HalfOutputPrecision` for one naming none). A factor of the +//! second source, a format without alpha's fast-math lerp, common factor or contracted pair +//! (EV FB8-r8-m3: Metal sums those in forms of their own), an output of fewer lanes, and a second +//! (index 1) output are not built. //! //! A blocked attachment is refused under `RequireOrdered` with the blocker's reason (what the //! device lacks, or `NotImplemented`), and read unordered as before under `AcceptUnordered` @@ -291,17 +295,22 @@ pub(crate) fn unorm8_format(pf: crate::metal::PixelFormat) -> bool { } /// Metal's blend `eq` of a format held directly, which the shader computes in the storage form, -/// storing the channels `written` of four under math `math`: an 8-bit unorm attachment's -/// ([`extended_range::Blend::unorm8`]), else a 16-bit float one's -/// ([`extended_range::Blend::half_float`]). +/// storing the channels `written` of four under math `math`: an 8-bit unorm attachment's in +/// `arith` ([`extended_range::Blend::unorm8`]), else a 16-bit float one's +/// ([`extended_range::Blend::half_float`], which takes its arithmetic when it computes). The +/// planning callers pass `BlendArith::Half`: what is refused, what reads the blend color, and the +/// words are the same in either arithmetic. fn direct_blend( eq: &BlendEquation, pf: crate::metal::PixelFormat, written: ColorWriteMask, - math: extended_range::blend::BlendMath, + (math, arith): ( + extended_range::blend::BlendMath, + extended_range::blend::BlendArith, + ), ) -> Result { match unorm8_format(pf) { - true => extended_range::Blend::unorm8(eq, pf, written, math), + true => extended_range::Blend::unorm8(eq, pf, written, (math, arith)), false => extended_range::Blend::half_float(eq, pf, written, math), } } @@ -720,8 +729,8 @@ fn channels(pf: crate::metal::PixelFormat) -> ColorWriteMask { } /// Whether a storage-form write to an attachment of `pf` that keeps some of its channels takes -/// them from the draw (`PushField::StorageKeptChannels`), so that every such write mask compiles -/// alike: every format but an extended-range one, whose kept channels Metal's blend model and +/// them from the draw (`PushField::StorageKeptChannels`), so that the write masks of a class +/// compile alike ([`compiled_write_mask`]): every format but an extended-range one, whose kept channels Metal's blend model and /// encode read (`extended_range::Blend`, `encode_keeping`), and an sRGB one, whose write merges the /// bytes of its `uint` view. pub(crate) fn kept_at_draw(pf: crate::metal::PixelFormat) -> bool { @@ -751,24 +760,41 @@ pub(crate) fn kept_channels( } /// The write mask a fragment function compiles the storage form of an attachment of `pf` under, -/// for the descriptor's `mask` (`FramebufferFetchInputs::of`): where the write takes its kept -/// channels from the draw ([`kept_at_draw`]), the class of `mask` alone (none where it covers -/// none of the format's channels, all where it covers every one, and for a mask covering some, -/// every channel of the format but the first, the one mask that stands for them all), so the -/// write masks of a class share one key and one module; any other format's `mask` as it is. +/// for the descriptor's `mask` (`FramebufferFetchInputs::of`), blended where `blended`: where the +/// write takes its kept channels from the draw ([`kept_at_draw`]), the class of `mask` alone (none +/// where it covers none of the format's channels, all where it covers every one, and for a mask +/// covering some, every channel of the format but the first, the one mask that stands for them +/// all), so the write masks of a class share one key and one module; any other format's `mask` as +/// it is. A blended 8-bit unorm attachment with alpha splits the partial class in three, as +/// Metal's blend forms do (`extended_range::Blend::unorm8`): alpha alone (`ALPHA`), one color +/// channel with or without alpha (`RED` and `ALPHA`), and two or more color channels. pub(crate) fn compiled_write_mask( pf: crate::metal::PixelFormat, mask: ColorWriteMask, + blended: bool, ) -> ColorWriteMask { if !kept_at_draw(pf) || mask.contains(ColorWriteMask::UNSPECIALIZED) { return mask; } let all = channels(pf); let written = all.intersection(mask); + let colors = [ + ColorWriteMask::RED, + ColorWriteMask::GREEN, + ColorWriteMask::BLUE, + ] + .into_iter() + .filter(|&c| written.contains(c)) + .count(); + let unorm8 = blended && unorm8_format(pf) && all.contains(ColorWriteMask::ALPHA); if written.is_empty() { ColorWriteMask::NONE } else if written == all { ColorWriteMask::ALL + } else if unorm8 && colors == 0 { + ColorWriteMask::ALPHA + } else if unorm8 && colors == 1 { + ColorWriteMask::RED.union(ColorWriteMask::ALPHA) } else { all.difference(ColorWriteMask::RED) } @@ -856,15 +882,16 @@ pub(crate) fn storage_form( let half_blend = half_float_format(pf) && attachment.blending_enabled && (!attachment.replaces || kept_zero); // And the blend of an 8-bit unorm attachment where Metal's measured model holds it - // (`extended_range::Blend::unorm8`: premultiplied source-over, every channel stored); its - // other blends stay the gap below. A channel the format lacks counts as written, as [`plan`] - // plans it. + // (`extended_range::Blend::unorm8`: every factor and operation but the second source's, any + // write mask); its other blends stay the gap below. A channel the format lacks counts as + // written, as [`plan`] plans it. let written_of_four = ColorWriteMask::ALL.difference(kept); + let half = extended_range::blend::BlendArith::Half; let unorm8_blend = unorm8_format(pf) && attachment.blending_enabled && !attachment.replaces && attachment.equation.is_some_and(|eq| { - extended_range::Blend::unorm8(&eq, pf, written_of_four, use_.math).is_ok() + extended_range::Blend::unorm8(&eq, pf, written_of_four, (use_.math, half)).is_ok() }); let blend = attachment.equation.filter(|_| { (extended.is_some_and(|e| !e.padded()) || half_blend || unorm8_blend) && stores @@ -875,7 +902,7 @@ pub(crate) fn storage_form( let written = all.intersection(attachment.write_mask); extended_range::Blend::of(&eq, form, written, use_.math) } - None => direct_blend(&eq, pf, written_of_four, use_.math), + None => direct_blend(&eq, pf, written_of_four, (use_.math, half)), }; match planned { Ok(_) => {} @@ -1398,7 +1425,8 @@ pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> { let math = blend_math(cx); let planned = view.blend.map(|eq| { let written = written(view.kept); - direct_blend(&eq, view.pixel_format, written, math) + let half = extended_range::blend::BlendArith::Half; + direct_blend(&eq, view.pixel_format, written, (math, half)) }); let unorm8 = unorm8_format(view.pixel_format); match (planned, blended_output(cx.entry, color)) { @@ -1476,8 +1504,9 @@ pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> { // The blend color as the encoder set it, where Metal's 16-bit float blend reads // it. Where that blend is not Metal's exactly, the function notes it. if let (Some(eq), None) = (view.blend, view.extended) { - let half = - direct_blend(&eq, view.pixel_format, written(view.kept), blend_math(cx)); + let arith = extended_range::blend::BlendArith::Half; + let math = (blend_math(cx), arith); + let half = direct_blend(&eq, view.pixel_format, written(view.kept), math); if half.is_ok_and(|h| h.reads_constant()) { cx.push.insert(PushField::HalfBlendColor); } @@ -1861,7 +1890,8 @@ pub(super) fn words(cx: &SelectCx<'_>, uses: u64, rets: u64) -> u64 { let eq = sc.view.blend?; let kept = self::written(sc.view.kept); let pf = sc.view.pixel_format; - let b = direct_blend(&eq, pf, kept, blend_math(cx)).ok()?; + let half = extended_range::blend::BlendArith::Half; + let b = direct_blend(&eq, pf, kept, (blend_math(cx), half)).ok()?; let unorm8 = match unorm8_format(pf) { true => { let rule = crate::pipeline::lower_inputs::ChannelWrite::Unorm { bits: 8 }; @@ -2385,15 +2415,17 @@ fn half_blended( /// The output `part` of `form` (four `f32` lanes: a `half4` output's `half`s, or a `float4` one's /// `float`s) blended into 8-bit unorm attachment `color` by Metal's blend `eq` -/// (`extended_range::Blend::unorm8`, of the function's math), stored as Metal's unorm write -/// stores it: the texel read first at the invocation's pixel (and sample), inside the interlock, -/// in Metal's channel order ([`read_texel`]: an attachment viewed in its RGBA-order twin has red -/// and blue exchanged, and the write exchanges them back, [`emit_return`]), Metal's arithmetic of -/// the clamped output over the destination's code decoded in the output's -/// type (`extended_range::blend::blend_unorm8`), and the result's code by Metal's 8-bit unorm rule +/// (`extended_range::Blend::unorm8`, of the function's math and the output's type), stored as +/// Metal's unorm write stores it: the texel read first at the invocation's pixel (and sample), +/// inside the interlock, in Metal's channel order ([`read_texel`]: an attachment viewed in its +/// RGBA-order twin has red and blue exchanged, and the write exchanges them back, +/// [`emit_return`]), Metal's arithmetic of the clamped output over the destination's code decoded +/// in the output's type, the blend color from `PushField::HalfBlendColor` where the blend reads it +/// (`extended_range::blend::blend_unorm8`), and the result's code by Metal's 8-bit unorm rule /// (`arith::color_write`'s `ChannelWrite::Unorm`: a NaN 0, clamped, the exact product with 255 -/// rounded to nearest), written as the `f32` the device stores as that code (EV FB8-sw1-m3: Metal's -/// code in every channel, the module docs). +/// rounded to nearest), written as the `f32` the device stores as that code; a channel the write +/// mask keeps takes the texel's after (EVs FB8-sw1-m3 and FB8-sw2-m3: Metal's code in every +/// channel, the module docs). fn unorm8_blended( cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, @@ -2404,16 +2436,23 @@ fn unorm8_blended( ) -> BResult { let math = extended_range::blend::BlendMath::of(cx.entry.compile.fast_math); let (pf, written) = (sc.view.pixel_format, written(sc.view.kept)); - let Ok(b) = direct_blend(&eq, pf, written, math) else { - return Err(cx.fail("an 8-bit unorm blend outside Metal's model")); - }; let arith = match (form.lanes, form.float_fmt()) { (4, Some(FloatFmt::Half)) => extended_range::blend::BlendArith::Half, (4, Some(FloatFmt::F32)) => extended_range::blend::BlendArith::Float, _ => return Err(cx.fail("an 8-bit unorm blend of another output")), }; + let Ok(b) = direct_blend(&eq, pf, written, (math, arith)) else { + return Err(cx.fail("an 8-bit unorm blend outside Metal's model")); + }; let texel = read_texel(cx, fb, color, sc)?; - let v = extended_range::blend::blend_unorm8(fb, &b, arith, (part, texel))?; + let constant = match b.reads_constant() { + true => { + let field = cx.push_field(fb, PushField::HalfBlendColor)?; + Some(fb.composite_extract(field, &[0])?) + } + false => None, + }; + let v = extended_range::blend::blend_unorm8(fb, &b, arith, (part, texel), constant)?; let f4 = form.with(Held::Float(FloatFmt::F32)); let rule = Some(crate::pipeline::lower_inputs::ChannelWrite::Unorm { bits: 8 }); crate::lower::arith::color_write::round(fb, f4, v, &[rule; 4], None) diff --git a/crates/metal2vulkan/src/pipeline/graphics.rs b/crates/metal2vulkan/src/pipeline/graphics.rs index 272ec9800..5699ceb3a 100644 --- a/crates/metal2vulkan/src/pipeline/graphics.rs +++ b/crates/metal2vulkan/src/pipeline/graphics.rs @@ -836,8 +836,9 @@ pub struct StorageAttachmentUse { /// write mask: empty where it does not write the attachment or the mask covers every channel of /// the format, all four where it covers none of them (the write stores nothing), else those of /// the format the mask leaves out. One module serves every write mask that keeps some of a - /// format's channels: the binder writes these into each draw's push bytes, where the function - /// reads them. Nothing for the consumer to do. + /// format's channels (a blended 8-bit unorm attachment with alpha: each of alpha alone, one + /// color channel, and more): the binder writes these into each draw's push bytes, where the + /// function reads them. Nothing for the consumer to do. #[cfg_attr(feature = "serde", serde(default))] pub kept: vk::ColorComponentFlags, } diff --git a/crates/metal2vulkan/src/pipeline/lower_inputs.rs b/crates/metal2vulkan/src/pipeline/lower_inputs.rs index 517ad5038..7ebaf92bf 100644 --- a/crates/metal2vulkan/src/pipeline/lower_inputs.rs +++ b/crates/metal2vulkan/src/pipeline/lower_inputs.rs @@ -1183,6 +1183,7 @@ impl FramebufferFetchInputs { write_mask: crate::lower::fragment::compiled_write_mask( a.pixel_format, a.write_mask, + a.blending_enabled, ), replaces: crate::pipeline::color_writes::replaces(&a), equation: BlendEquation::of(&a), diff --git a/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs b/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs index 012125b16..71e10a523 100644 --- a/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs +++ b/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs @@ -15,8 +15,9 @@ //! RGBA-order twin, the shader exchanging red and blue around the blend), and the guest's whole //! pipeline is made there, color 0 a written storage attachment and no color attachment of the //! subpass, its stages passing L3. Before the shader computed the -//! blend, each was refused `NotImplemented(FramebufferFetch)` at color 0. Another blend, and a -//! write mask that keeps a channel, are refused so still. No GPU is used. +//! blend, each was refused `NotImplemented(FramebufferFetch)` at color 0. Other blends (the blend +//! color's among them) and write masks that keep channels compile the same way; a blend that reads +//! the second source is refused so still. No GPU is used. //! //! `llvm-as` assembles the fixtures; a missing tool skips visibly. @@ -245,43 +246,141 @@ fn a_blended_eight_bit_unorm_fetch_computes_metals_blend() { assert!(anv, "no ANV profile compiled the guest's shape"); } -/// A blend of an 8-bit unorm attachment other than premultiplied source-over, and the guest's -/// blend under a write mask that keeps a channel, are not measured: on every committed profile -/// that orders fetch through the pixel interlock alone each is refused -/// `NotImplemented(FramebufferFetch)` at color 0, as before. +/// Other blends and write masks of an 8-bit unorm attachment: on every committed profile that +/// orders fetch through the pixel interlock alone, each compiles in the storage form with the +/// blend it computes, rounded without fast math, and announces nothing; one reading the blend +/// color pushes it as `half` (`PushField::HalfBlendColor`), and its module passes L3. #[test] -fn another_eight_bit_unorm_fetched_blend_stays_refused() { - let Some(fast) = assembled("fbl_fetch_blend8") else { +fn another_eight_bit_unorm_blend_or_mask_computes_metals_blend() { + let (Some(fast), Some(safe)) = ( + assembled("fbl_fetch_blend8"), + assembled("fbl_fetch_blend8_safe"), + ) else { return; }; + use crate::pipeline::sym::PushField; use BlendFactor as F; - let alpha_over = BlendEquation { - source_rgb: F::SourceAlpha, - ..OVER - }; - let added = BlendEquation { - destination_rgb: F::One, - destination_alpha: F::One, - ..OVER - }; + use BlendOperation as O; + let rgb = ColorWriteMask::RED + .union(ColorWriteMask::GREEN) + .union(ColorWriteMask::BLUE); + // Each blend, its write mask, and whether it reads the blend color. let cases = [ - (alpha_over, ColorWriteMask::ALL), - (added, ColorWriteMask::ALL), ( - OVER, - ColorWriteMask::RED - .union(ColorWriteMask::GREEN) - .union(ColorWriteMask::BLUE), + BlendEquation { + source_rgb: F::SourceAlpha, + ..OVER + }, + ColorWriteMask::ALL, + false, ), + ( + BlendEquation { + destination_rgb: F::One, + destination_alpha: F::One, + ..OVER + }, + ColorWriteMask::ALL, + false, + ), + ( + BlendEquation { + source_rgb: F::BlendColor, + destination_rgb: F::OneMinusBlendAlpha, + rgb_operation: O::ReverseSubtract, + source_alpha: F::DestinationAlpha, + destination_alpha: F::OneMinusSourceColor, + alpha_operation: O::Subtract, + }, + ColorWriteMask::ALL, + true, + ), + ( + BlendEquation { + rgb_operation: O::Max, + alpha_operation: O::Min, + ..OVER + }, + ColorWriteMask::ALL, + false, + ), + (OVER, rgb, false), + (OVER, ColorWriteMask::BLUE, false), + (OVER, ColorWriteMask::ALPHA, false), + ( + BlendEquation { + source_rgb: F::OneMinusDestinationAlpha, + destination_rgb: F::SourceColor, + rgb_operation: O::ReverseSubtract, + ..OVER + }, + ColorWriteMask::GREEN.union(ColorWriteMask::ALPHA), + false, + ), + ]; + let entries = [ + (&fast, "fbl8_over_loaded", false), + (&safe, "fbl8_safe_loaded", true), ]; let mut checked = 0; for (stem, p) in committed_profiles().expect("profiles") { if !crate::lower::fragment::interlock_orders(&p) { continue; } - for (eq, mask) in cases { + for (eq, mask, reads_color) in cases { let inputs = state(&p, PixelFormat::BGRA8Unorm, eq, mask); - let what = format!("{stem} {eq:?} {mask:?}"); + for &(bc, entry, rounded) in &entries { + let what = format!("{stem} {entry} {eq:?} {mask:?}"); + let a = + compile_with(bc, entry, &p, &inputs).unwrap_or_else(|e| panic!("{what}: {e}")); + assert_eq!( + fetched(&a), + Some((true, Some(eq), rounded)), + "{what}: {:?}", + a.facts + ); + for note in NOTES { + assert!(!a.precision.contains(¬e), "{what}: {:?}", a.precision); + } + let pushes = + |field: PushField| a.interface.push.fields.iter().any(|x| x.field == field); + assert_eq!(pushes(PushField::HalfBlendColor), reads_color, "{what}"); + assert!(!pushes(PushField::BlendColor), "{what}"); + link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{what}: L3: {e}")); + checked += 1; + } + } + } + assert!(checked > 0, "no interlock profile took the storage form"); +} + +/// A blend of an 8-bit unorm attachment that reads the second source is not measured: on every +/// committed profile that orders fetch through the pixel interlock alone it is refused +/// `NotImplemented(FramebufferFetch)` at color 0. +#[test] +fn an_eight_bit_unorm_second_source_blend_stays_refused() { + let Some(fast) = assembled("fbl_fetch_blend8") else { + return; + }; + use BlendFactor as F; + let cases = [ + BlendEquation { + source_rgb: F::Source1Color, + ..OVER + }, + BlendEquation { + destination_alpha: F::OneMinusSource1Alpha, + ..OVER + }, + ]; + let mut checked = 0; + for (stem, p) in committed_profiles().expect("profiles") { + if !crate::lower::fragment::interlock_orders(&p) { + continue; + } + for eq in cases { + let inputs = state(&p, PixelFormat::BGRA8Unorm, eq, ColorWriteMask::ALL); + let what = format!("{stem} {eq:?}"); match compile_with(&fast, "fbl8_over_loaded", &p, &inputs) { Err(Error::Unsupported(u)) if u.needs == Needs::NotImplemented => { assert_eq!(u.feature, Feature::FramebufferFetch, "{what}"); diff --git a/crates/metal2vulkan/src/tests/engine_fragment.rs b/crates/metal2vulkan/src/tests/engine_fragment.rs index b2580d5ef..7c75ecc86 100644 --- a/crates/metal2vulkan/src/tests/engine_fragment.rs +++ b/crates/metal2vulkan/src/tests/engine_fragment.rs @@ -474,7 +474,8 @@ fn fetch_state(read: &[u32], formats: &[PixelFormat], blending: bool) -> Lowerin /// the interlock, under its pipeline's state (standalone, the function needs that state); where /// that state blocks the storage form (a blend of a format whose blend the shader does not compute), /// `RequireOrdered` refuses with the blocker and `AcceptUnordered` reads an input attachment -/// unordered with a precision note; a 16-bit float attachment's blend the shader computes. With neither, +/// unordered with a precision note; a 16-bit float or 8-bit unorm attachment's blend the shader +/// computes. With neither, /// `RequireOrdered` refuses naming both and `AcceptUnordered` reads unordered. Every compiled /// module passes L3. #[test] @@ -556,10 +557,14 @@ fn framebuffer_fetch_reads_in_an_ordered_form_where_the_device_has_one() { assert!(!unordered(&a), "{entry} on {stem}"); } // Blending the written color 0 blocks its storage form where the shader computes - // no blend of its format (`RGBA8Unorm`, `R32Float`): refused with that reason, or - // read unordered. A 16-bit float one's blend the shader computes, as Metal's. + // no blend of its format (`R32Float`): refused with that reason, or read + // unordered. A 16-bit float or 8-bit unorm one's blend the shader computes, as + // Metal's. let blended = fetch_state(colors, formats, true); - if formats[0] == PixelFormat::RGBA16Float { + if matches!( + formats[0], + PixelFormat::RGBA16Float | PixelFormat::RGBA8Unorm + ) { for p in [&strict, &lenient] { let a = compile_with(&bc, entry, p, &blended) .unwrap_or_else(|e| panic!("{entry} on {stem}: blended: {e}")); diff --git a/docs/API.md b/docs/API.md index 83bfb30f4..fad24af21 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2301,7 +2301,8 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound. Metal's at the operands' magnitude, 16 at the stored value's under cancellation. Where the output is opaque to the blend and its form fits every measured state, the function's blend is Metal's and records nothing; so does the blend of a fetched 8-bit unorm attachment it computes there - (premultiplied source-over), which Metal reads the output into clamped, folding none of it. + (every factor, operation, write mask and blend color it builds), which Metal reads the output + into clamped, folding none of it. - `metal2vulkan-degrade-device-sampling` (precision). `PrecisionNote::DeviceSampling`: Native device sampling: the module hands a sample, gather or comparison to the device's own sampler where a device whose sampler is not Metal's would emulate Metal's (`SamplingPolicy::NativeDevice`, the diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index a2482b655..c63f9712a 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -323,9 +323,14 @@ driver's. Each is open work. - **A fetched attachment's blend through the pixel interlock (RADV, ANV, NVIDIA, MoltenVK).** No Vulkan blend applies to the storage form's write, so the function computes Metal's blend: an extended-range or 16-bit float attachment's, and an 8-bit unorm one's (`R8Unorm`, `RG8Unorm`, - `RGBA8Unorm`, `BGRA8Unorm`) for premultiplied source-over of a four-lane output storing every - channel. Another blend of an 8-bit unorm attachment, a write mask that keeps one of its - channels, and a blend into any other format are refused (`FramebufferFetch`, `NotImplemented`). + `RGBA8Unorm`, `BGRA8Unorm`) of a four-lane output under any factor, operation, write mask and + blend color. Refused (`FramebufferFetch`, `NotImplemented`): a factor of the second source; under + fast math, a lerp, common factor or contracted pair into `R8Unorm` or `RG8Unorm`, which Metal + sums in forms not measured; and a blend into any other format, `RGB10A2Unorm`, `BGR10A2Unorm`, + `RGBA8Snorm`, `RGBA16Unorm`, `RGBA16Snorm`, `RGBA32Float` and the 8-bit `_sRGB` ones among them. + A source-over survey on the M3 fits the 8-bit model to the 10-bit unorm and 8-bit snorm formats + (with their clamps), and shows the 16-bit norms and `RGBA32Float` blending in `float` even for a + `half4` output; their factor sets are not measured. - **Format-less storage reads on a device without `shaderStorageImageReadWithoutFormat` (ANV).** A fetch through the pixel interlock of a 16-bit packed color attachment (`B5G6R5Unorm`, `A1BGR5Unorm`, `ABGR4Unorm`, `BGR5A1Unorm`), which no SPIR-V format names, is refused diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 4bc390b6a..953e697e7 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -14,7 +14,7 @@ Columns: - `none`: no public API path: malformed or non-Metal input, Apple-private calls, or a cap no valid program of ordinary size meets; - `?`: not assessed yet. -Generated at `d670bf64f`. +Generated at `9962320b9`. ## Totals @@ -84,7 +84,7 @@ Generated at `d670bf64f`. | `PixelSamplerCompare` | A constexpr sampler with pixel coordinates and a compare function, which Apple's compiler rejects ("invalid values combination in sampler... | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:115` | `none`: Apple's compiler rejects it | | `TexelBuffer` | Texture buffers beyond the device's texel-buffer limits | devices without a format's usage; every device (no Vulkan mechanism) | 3: `crates/metal2vulkan/src/bind/instantiate.rs:739`, `crates/metal2vulkan/src/bind/instantiate.rs:745` (+1) | `app`: texture buffers past a device's texel-buffer limits | | `RasterOrderGroups` | Raster order groups without fragment shader interlock | devices without VkFeature::FragmentShaderPixelInterlock; devices without VkFeature::FragmentShaderSampleInterlock; devices without a capability the site computes (`alternatives`); every device (not implemented) | 4: `crates/metal2vulkan/src/device/metal.rs:242`, `crates/metal2vulkan/src/lower/fragment/rog.rs:151` (+2) | `rare`: raster order groups | -| `FramebufferFetch` | Framebuffer fetch without ordered attachment access under `RequireOrdered`, or in a multisampled pipeline (not implemented) | devices short of a Vulkan property the site names; devices without VkFeature::FragmentShaderPixelInterlock; devices without VkFeature::RasterizationOrderColorAttachmentAccess; devices without VkFeature::SampleRateShading; devices without a capability the site computes; devices without a capability the site computes (`alternatives`); devices without a capability the site computes (`c`); devices without a capability the site computes (`capability`); devices without a capability the site computes (`missing`); devices without a format's usage; drivers with a defect; every device (not implemented) | 25: `crates/metal2vulkan-runtime/src/families/features.rs:1007`, `crates/metal2vulkan-runtime/src/framebuffer_fetch.rs:437` (+23) | `system`: programmable blending (framebuffer fetch); macOS 26.6.2's login reaches it (two WindowServer and RenderBox pipelines fetch RGB10A8_2P_XR10 attachments, the consumer's boots) | +| `FramebufferFetch` | Framebuffer fetch without ordered attachment access under `RequireOrdered`, or in a multisampled pipeline (not implemented) | devices short of a Vulkan property the site names; devices without VkFeature::FragmentShaderPixelInterlock; devices without VkFeature::RasterizationOrderColorAttachmentAccess; devices without VkFeature::SampleRateShading; devices without a capability the site computes; devices without a capability the site computes (`alternatives`); devices without a capability the site computes (`c`); devices without a capability the site computes (`capability`); devices without a capability the site computes (`missing`); devices without a format's usage; drivers with a defect; every device (not implemented) | 26: `crates/metal2vulkan-runtime/src/families/features.rs:1007`, `crates/metal2vulkan-runtime/src/framebuffer_fetch.rs:437` (+24) | `system`: programmable blending (framebuffer fetch); macOS 26.6.2's login reaches it (two WindowServer and RenderBox pipelines fetch RGB10A8_2P_XR10 attachments, the consumer's boots) | | `PrimitiveId` | `[[primitive_id]]` in a fragment function | devices without a capability the site computes; every device (not implemented) | 3: `crates/metal2vulkan-runtime/src/families/features.rs:1115`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:2989` (+1) | `rare`: primitive_id on a device without geometry or tessellation shaders, in an indexed draw or behind a mesh function | | `VertexAmplification` | Vertex amplification | devices without VkFeature::Multiview; devices without VkFeature::MultiviewTessellationShader; devices without VkLimit::MaxMultiviewInstanceIndex; devices without a capability the site computes (`needs`); every device (not implemented) | 5: `crates/metal2vulkan/src/bind/graphics.rs:3834`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:1258` (+3) | `rare`: vertex amplification | | `LayeredRendering` | Layered rendering (`render_target_array_index`, `viewport_array_index`) | devices without VkFeature::ImageView2DOn3DImage; devices without VkFeature::MultiViewport; devices without VkFeature::ShaderOutputLayer; devices without VkFeature::ShaderOutputViewportIndex; devices without a capability the site computes (`needs`); every device (not implemented) | 7: `crates/metal2vulkan-runtime/src/render_pass.rs:1557`, `crates/metal2vulkan-runtime/src/render_state.rs:1072` (+5) | `rare`: layered rendering on a device without its features | @@ -152,7 +152,7 @@ Generated at `d670bf64f`. | `IndirectRenderState` | A render state a function sets on an indirect render command (`render_command::set_cull_mode`, `set_front_facing_winding`,... | every device (not implemented) | 1: `crates/metal2vulkan/src/lower/access/encode.rs:567` | `rare`: render state set by a kernel on an indirect command | | `GlobalBuiltinInFragment` | A fragment function's read of a Metal 3.1 program-scope built-in variable that Metal does not lower there | every device (not implemented) | 1: `crates/metal2vulkan/src/lower/select.rs:900` | `rare`: Metal 3.1 global built-ins in fragment functions | | `PrivateRenderState` | A private fixed-function property of Metal's pipeline descriptor (Apple SPI, OpenGL on Metal's) set to a value whose effect the translation has... | every device (not implemented) | 4: `crates/metal2vulkan/src/bind/heap.rs:1280`, `crates/metal2vulkan/src/bind/plan/resources.rs:879` (+2) | `none`: Apple-private pipeline fields of OpenGL on Metal (no public header) | -| `ExtendedRangeBlend` | Metal's blend into an extended-range attachment (`BGRA10_XR`, `BGR10_XR`, `RGB10A8_2P_XR10` and their `_sRGB` twins), which the function computes... | every device (not implemented) | 4: `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:282`, `crates/metal2vulkan/src/lower/fragment/fetch.rs:1436` (+2) | `system`: the parts of a blend into an extended-range (XR10) attachment the measured model does not hold (second-source factors, the color blend color difference, a one-color-channel mask, float4 and sRGB outside the measured forms); the consumer's guests blend RGB10A8_2P_XR10 attachments | +| `ExtendedRangeBlend` | Metal's blend into an extended-range attachment (`BGRA10_XR`, `BGR10_XR`, `RGB10A8_2P_XR10` and their `_sRGB` twins), which the function computes... | every device (not implemented) | 4: `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:300`, `crates/metal2vulkan/src/lower/fragment/fetch.rs:1464` (+2) | `system`: the parts of a blend into an extended-range (XR10) attachment the measured model does not hold (second-source factors, the color blend color difference, a one-color-channel mask, float4 and sRGB outside the measured forms); the consumer's guests blend RGB10A8_2P_XR10 attachments | | `TileReach` | The tiles a render pass's primitives reach, binned on the device ([`tile_reach_module`](crate::bind::tile_reach_module)), on a device without what... | devices short of a Vulkan feature the site names; devices without a capability the site computes (`vec![int64]`); every device (not implemented) | 3: `crates/metal2vulkan/src/bind/tile_reach.rs:272`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:2408` (+1) | `app`: the tiles a pass's draws reach, binned on a device without shaderInt64 | | `CommandPredication` | Metal's private command predication (`encodeStartIf:offset:comparison:referenceValue:` and the rest), whose step module... | devices without buffer device addresses (`addressed_needs`) | 1: `crates/metal2vulkan/src/bind/replay/predication.rs:415` | `none`: Apple-private command predication on a device without buffer device addresses | | `ProgramScopeBinding` | A program-scope buffer binding of MSL 3.2 (macOS 15 and later), `constant T* constant p [[buffer(n)]];` in Apple's `!air.global_bindings` list,... | - | via a helper: 2: `crates/metal2vulkan-air/src/abi/module.rs:77`, `crates/metal2vulkan/src/error/mod.rs:267` | `app`: MSL 3.2 program-scope buffer bindings (macOS 15 and later) | @@ -333,7 +333,7 @@ Each refusal's sites, with the function that builds it. - `feature::BufferRange`: `crates/metal2vulkan-runtime/src/function_table.rs:575 (past_storage_buffer_range)`; `crates/metal2vulkan/src/bind/graphics.rs:3493 (patch_binding)`; `crates/metal2vulkan/src/bind/graphics.rs:3537 (patch_binding)`; `crates/metal2vulkan/src/bind/graphics.rs:3575 (patch_binding)`; `crates/metal2vulkan/src/bind/instantiate.rs:586 (bind_buffers)`; `crates/metal2vulkan/src/lower/access/function_table.rs:226 (select)`; `crates/metal2vulkan/src/lower/access/mod.rs:1162 (place_slots)` - `feature::Int64Arithmetic`: `crates/metal2vulkan/src/lower/arith/legal.rs:582 (check_scalar)`; `crates/metal2vulkan/src/lower/select.rs:1121 (selector_form)` - `feature::Float64Arithmetic`: `crates/metal2vulkan/src/device/metal.rs:230 (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/legal.rs:587 (check_scalar)` -- `feature::Format`: `crates/metal2vulkan-runtime/src/binding_view.rs:146 (binding_view)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:455 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:469 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:526 (pair_unit)`; `crates/metal2vulkan-runtime/src/blit_texture.rs:2024 (through_buffer)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:514 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:578 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:610 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:843 (texture_buffer_texel)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:270 (colour_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:298 (copy_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:344 (copy_unit)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:345 (scratch)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:525 (usable_twin)`; `crates/metal2vulkan-runtime/src/families/features.rs:1598 (read_write_tier)`; `crates/metal2vulkan-runtime/src/families/formats.rs:1640 (sparse_missing)`; `crates/metal2vulkan-runtime/src/families/formats.rs:228 (none)`; `crates/metal2vulkan-runtime/src/families/formats.rs:272 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:292 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:307 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:365 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:404 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:486 (atomic_gap)`; `crates/metal2vulkan-runtime/src/families/formats.rs:520 (lacking)`; `crates/metal2vulkan-runtime/src/families/formats.rs:534 (unsupported)`; `crates/metal2vulkan-runtime/src/image_plan.rs:536 (check_own_memory)`; `crates/metal2vulkan-runtime/src/image_plan.rs:648 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:733 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:846 (plan_held)`; `crates/metal2vulkan-runtime/src/render.rs:6351 (viewing)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1278 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1597 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1675 (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs:945 (check_target)`; `crates/metal2vulkan-runtime/src/resolve.rs:389 (unmodelled_resolve)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:177 (checked_twin)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:205 (plan)`; `crates/metal2vulkan-runtime/src/sample_interleave.rs:296 (interleave_merge)`; `crates/metal2vulkan-runtime/src/shadow.rs:447 (unmerged)`; `crates/metal2vulkan-runtime/src/shadow.rs:454 (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs:1994 (texture_as)`; `crates/metal2vulkan-runtime/src/texture.rs:4253 (two_planes_refused)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1630 (new_heap_texture)`; `crates/metal2vulkan-runtime/src/texture/surface_two_planes.rs:79 (refused)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:115 (converted_storage)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:276 (ycbcr_write_shadow)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:380 (new_render_shadow)`; `crates/metal2vulkan-runtime/src/two_planes.rs:115 (unmeasured)`; `crates/metal2vulkan-runtime/src/view_plan.rs:380 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:393 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:400 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:410 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:420 (check_format)`; `crates/metal2vulkan-runtime/src/ycbcr.rs:272 (refused)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:184 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1712 (extended_sampler)`; `crates/metal2vulkan/src/bind/plan/resources.rs:191 (require_filter_features)`; `crates/metal2vulkan/src/bind/plan/resources.rs:952 (plain_texture)`; `crates/metal2vulkan/src/bind/sample_interleave.rs:304 (finish)`; `crates/metal2vulkan/src/bind/unused_bits.rs:545 (unused_bits_module)`; `crates/metal2vulkan/src/lower/access/tile.rs:1029 (storage_format)`; `crates/metal2vulkan/src/lower/fragment/color.rs:154 (select_param)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1024 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1045 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1051 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1057 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1082 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1264 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1739 (select_output)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1765 (select_output)`; `crates/metal2vulkan/src/lower/sampler/select.rs:1086 (select_extended)`; `crates/metal2vulkan/src/lower/sampler/select.rs:691 (texel_in)`; `crates/metal2vulkan/src/lower/stage_io/extended_color.rs:77 (plan)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2252 (entry)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:842 (zeroed_output)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2280 (select)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2894 (cross_class)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3066 (select_image)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3236 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3273 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3597 (select_write)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1015 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1027 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1033 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:733 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:736 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:747 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:761 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:778 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:802 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:813 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:853 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:888 (atomic_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:897 (atomic_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1523 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1525 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1651 (candidates)`; `crates/metal2vulkan/src/metal/format/mod.rs:2581 (storage_choice_viewed)`; `crates/metal2vulkan/src/metal/format/mod.rs:2599 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2607 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2679 (held_storage_choice)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:1016 (extended_write_mask)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:380 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:488 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:890 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:907 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:450 (rotated_blend)` +- `feature::Format`: `crates/metal2vulkan-runtime/src/binding_view.rs:146 (binding_view)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:455 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:469 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:526 (pair_unit)`; `crates/metal2vulkan-runtime/src/blit_texture.rs:2024 (through_buffer)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:514 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:578 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:610 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:843 (texture_buffer_texel)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:270 (colour_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:298 (copy_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:344 (copy_unit)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:345 (scratch)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:525 (usable_twin)`; `crates/metal2vulkan-runtime/src/families/features.rs:1598 (read_write_tier)`; `crates/metal2vulkan-runtime/src/families/formats.rs:1640 (sparse_missing)`; `crates/metal2vulkan-runtime/src/families/formats.rs:228 (none)`; `crates/metal2vulkan-runtime/src/families/formats.rs:272 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:292 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:307 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:365 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:404 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:486 (atomic_gap)`; `crates/metal2vulkan-runtime/src/families/formats.rs:520 (lacking)`; `crates/metal2vulkan-runtime/src/families/formats.rs:534 (unsupported)`; `crates/metal2vulkan-runtime/src/image_plan.rs:536 (check_own_memory)`; `crates/metal2vulkan-runtime/src/image_plan.rs:648 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:733 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:846 (plan_held)`; `crates/metal2vulkan-runtime/src/render.rs:6351 (viewing)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1278 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1597 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1675 (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs:945 (check_target)`; `crates/metal2vulkan-runtime/src/resolve.rs:389 (unmodelled_resolve)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:177 (checked_twin)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:205 (plan)`; `crates/metal2vulkan-runtime/src/sample_interleave.rs:296 (interleave_merge)`; `crates/metal2vulkan-runtime/src/shadow.rs:447 (unmerged)`; `crates/metal2vulkan-runtime/src/shadow.rs:454 (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs:1994 (texture_as)`; `crates/metal2vulkan-runtime/src/texture.rs:4253 (two_planes_refused)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1630 (new_heap_texture)`; `crates/metal2vulkan-runtime/src/texture/surface_two_planes.rs:79 (refused)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:115 (converted_storage)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:276 (ycbcr_write_shadow)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:380 (new_render_shadow)`; `crates/metal2vulkan-runtime/src/two_planes.rs:115 (unmeasured)`; `crates/metal2vulkan-runtime/src/view_plan.rs:380 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:393 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:400 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:410 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:420 (check_format)`; `crates/metal2vulkan-runtime/src/ycbcr.rs:272 (refused)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:184 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1712 (extended_sampler)`; `crates/metal2vulkan/src/bind/plan/resources.rs:191 (require_filter_features)`; `crates/metal2vulkan/src/bind/plan/resources.rs:952 (plain_texture)`; `crates/metal2vulkan/src/bind/sample_interleave.rs:304 (finish)`; `crates/metal2vulkan/src/bind/unused_bits.rs:545 (unused_bits_module)`; `crates/metal2vulkan/src/lower/access/tile.rs:1029 (storage_format)`; `crates/metal2vulkan/src/lower/fragment/color.rs:154 (select_param)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1051 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1072 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1078 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1084 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1109 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1291 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1768 (select_output)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1794 (select_output)`; `crates/metal2vulkan/src/lower/sampler/select.rs:1086 (select_extended)`; `crates/metal2vulkan/src/lower/sampler/select.rs:691 (texel_in)`; `crates/metal2vulkan/src/lower/stage_io/extended_color.rs:77 (plan)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2252 (entry)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:842 (zeroed_output)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2280 (select)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2894 (cross_class)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3066 (select_image)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3236 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3273 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3597 (select_write)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1015 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1027 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1033 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:733 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:736 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:747 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:761 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:778 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:802 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:813 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:853 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:888 (atomic_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:897 (atomic_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1523 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1525 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1651 (candidates)`; `crates/metal2vulkan/src/metal/format/mod.rs:2581 (storage_choice_viewed)`; `crates/metal2vulkan/src/metal/format/mod.rs:2599 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2607 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2679 (held_storage_choice)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:1016 (extended_write_mask)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:380 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:488 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:890 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:907 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:450 (rotated_blend)` - `feature::DivergentImplicitLod`: `crates/metal2vulkan/src/lower/sampler/select.rs:352 (select_sampling)` - `feature::ImplicitLodOutsideFragment`: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:136 (query_min_level)`; `crates/metal2vulkan/src/lower/sampler/select.rs:229 (query_level_measured)`; `crates/metal2vulkan/src/lower/sampler/select.rs:255 (query_min_level)` - `feature::MinLodClamp`: `crates/metal2vulkan/src/lower/sampler/select.rs:1431 (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs:973 (min_lod)` @@ -349,7 +349,7 @@ Each refusal's sites, with the function that builds it. - `feature::PixelSamplerCompare`: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:115 (lowered)` - `feature::TexelBuffer`: `crates/metal2vulkan/src/bind/instantiate.rs:739 (texel_ranges)`; `crates/metal2vulkan/src/bind/instantiate.rs:745 (texel_ranges)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1112 (plain_texture)` - `feature::RasterOrderGroups`: `crates/metal2vulkan/src/device/metal.rs:242 (unsupported_features)`; `crates/metal2vulkan/src/lower/fragment/rog.rs:151 (mode)`; `crates/metal2vulkan/src/lower/fragment/rog.rs:172 (mode)`; `crates/metal2vulkan/src/lower/fragment/snapshot.rs:158 (finish)` -- `feature::FramebufferFetch`: `crates/metal2vulkan-runtime/src/families/features.rs:1007 (state)`; `crates/metal2vulkan-runtime/src/framebuffer_fetch.rs:437 (ordered)`; `crates/metal2vulkan-runtime/src/render.rs:5176 (next_instance)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:112 (lacks)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:139 (new)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:498 (planes_merge)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:190 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/graphics.rs:1422 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1459 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1478 (plan)`; `crates/metal2vulkan/src/bind/sample_planes.rs:431 (finish)`; `crates/metal2vulkan/src/device/metal.rs:255 (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:996 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:999 (unorm8)`; `crates/metal2vulkan/src/lower/fragment/color.rs:208 (select_param)`; `crates/metal2vulkan/src/lower/fragment/color.rs:257 (unordered)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:196 (not_implemented)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:271 (depth_test_form)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:317 (stencil_test_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1000 (storage_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1037 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1590 (plan_sample)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:692 (not_implemented)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:919 (storage_form)`; `crates/metal2vulkan/src/pipeline/link/fetch.rs:159 (storage_attachments)` +- `feature::FramebufferFetch`: `crates/metal2vulkan-runtime/src/families/features.rs:1007 (state)`; `crates/metal2vulkan-runtime/src/framebuffer_fetch.rs:437 (ordered)`; `crates/metal2vulkan-runtime/src/render.rs:5176 (next_instance)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:112 (lacks)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:139 (new)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:498 (planes_merge)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:190 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/graphics.rs:1422 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1459 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1478 (plan)`; `crates/metal2vulkan/src/bind/sample_planes.rs:431 (finish)`; `crates/metal2vulkan/src/device/metal.rs:255 (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1184 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1202 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1216 (unorm8)`; `crates/metal2vulkan/src/lower/fragment/color.rs:208 (select_param)`; `crates/metal2vulkan/src/lower/fragment/color.rs:257 (unordered)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:196 (not_implemented)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:271 (depth_test_form)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:317 (stencil_test_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1027 (storage_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1064 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1619 (plan_sample)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:701 (not_implemented)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:946 (storage_form)`; `crates/metal2vulkan/src/pipeline/link/fetch.rs:159 (storage_attachments)` - `feature::PrimitiveId`: `crates/metal2vulkan-runtime/src/families/features.rs:1115 (state)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2989 (finish)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:240 (check_primitive_id)` - `feature::VertexAmplification`: `crates/metal2vulkan/src/bind/graphics.rs:3834 (multiview_instances)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1258 (own_index_store)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs:718 (select_param)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:243 (vertex_amplification)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs:228 (control_plan)` - `feature::LayeredRendering`: `crates/metal2vulkan-runtime/src/render_pass.rs:1557 (target)`; `crates/metal2vulkan-runtime/src/render_state.rs:1072 (needs_viewports)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:778 (target_index)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:797 (target_index)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1259 (own_index_store)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs:150 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs:172 (refused)` @@ -417,7 +417,7 @@ Each refusal's sites, with the function that builds it. - `feature::IndirectRenderState`: `crates/metal2vulkan/src/lower/access/encode.rs:567 (select_command)` - `feature::GlobalBuiltinInFragment`: `crates/metal2vulkan/src/lower/select.rs:900 (route_air)` - `feature::PrivateRenderState`: `crates/metal2vulkan/src/bind/heap.rs:1280 (array)`; `crates/metal2vulkan/src/bind/plan/resources.rs:879 (write_rounding)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2812 (mode_rounded_write)`; `crates/metal2vulkan/src/pipeline/private_state.rs:47 (refused)` -- `feature::ExtendedRangeBlend`: `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:282 (refused)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1436 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1439 (plan)`; `crates/metal2vulkan/src/lower/fragment/input_blend.rs:154 (plan)` +- `feature::ExtendedRangeBlend`: `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:300 (refused)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1464 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1467 (plan)`; `crates/metal2vulkan/src/lower/fragment/input_blend.rs:154 (plan)` - `feature::TileReach`: `crates/metal2vulkan/src/bind/tile_reach.rs:272 (tile_reach_module)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2408 (capture)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2434 (capture)` - `feature::CommandPredication`: `crates/metal2vulkan/src/bind/replay/predication.rs:415 (predication_step_module)` - `feature::ProgramScopeBinding`: `crates/metal2vulkan-air/src/abi/module.rs:77 (decode)`; `crates/metal2vulkan/src/error/mod.rs:267 (from)`