diff --git a/crates/metal2vulkan-runtime/src/clear_reach.rs b/crates/metal2vulkan-runtime/src/clear_reach.rs index 6800f21f2..5552feff0 100644 --- a/crates/metal2vulkan-runtime/src/clear_reach.rs +++ b/crates/metal2vulkan-runtime/src/clear_reach.rs @@ -24,6 +24,12 @@ //! tile holds zero before the draws (a color, every color attachment of the pass) or the //! attachment's clear value (depth, stencil); the tiles no primitive touches keep their texels. //! Which tiles those are depends on where the GPU places the vertices. +//! - **A `DontCare` load** of an attachment the pass does not store (`DontCare`) reads the same +//! wherever a fragment reads it: zero (a color) or the pass's clear value (a stencil), never its +//! earlier texels (an M3 Max, macOS 27.0.1, lane `dont_care_unstored`: an `RG16Float` second +//! color a framebuffer fetch reads and a `Stencil8` a stencil test reads, over 224x128 and +//! 128x128 targets, in a pass whose first draw reaches some tiles and a later one every tile, a +//! pass of the reading draw alone, and a pass of no fetch). //! - A `Load` keeps the texels past the render area, and a `DontCare` store stores nothing. //! //! **The runtime** gives the `Clear` load's answer and the `DontCare` load's near-equivalent, as @@ -44,6 +50,13 @@ //! pass's `tileWidth` and `tileHeight`, which set Metal's grid, as measured), a clear before the //! pass, and loads: every other tile keeps its texels, Metal's answer (a draw writes no pixel //! outside them), and a pass whose draws reach no pixel loads, as one whose draws draw nothing. +//! - A `DontCare`-loaded attachment the pass does not store (but separate depth and stencil +//! textures, and memoryless ones) clears to zero (a color) or its clear value (depth, stencil) +//! in a pass whose draws reach a tile, over the render area: by the load operation of the pass's +//! first instance, or before the pass where that instance leaves it out (as below). Metal's +//! answer wherever a fragment reads it, so no notice: no fragment reads a tile no draw touches. +//! What the pass leaves in it is a `DontCare` store's (`kept_bytes.rs`). In a pass whose draws +//! reach no tile it stays `DontCare`. //! - A `DontCare`-loaded memoryless color attachment clears to zero in a pass whose draws reach a //! tile: Metal's answer in every tile a fragment reads it (an Apple M4), and it is //! never stored, so the answer is exact. @@ -263,8 +276,11 @@ pub(super) fn dont_care_clear(pf: PixelFormat) -> vk::ClearColorValue { /// Give each `DontCare` load of `layout` that the module docs name its answer in a pass of /// `reach`: `Load` where it reaches no tile, else `Clear`, to the format's zero for a color -/// attachment ([`dont_care_clear`]) and to its clear value for depth and stencil. Which attachments took it, and whether the pass took -/// the near-equivalent (its draws reach the tiles their primitives touch): the attachment it +/// attachment ([`dont_care_clear`]) and to its clear value for depth and stencil. One of an +/// attachment the pass does not store takes `Clear` wherever the pass reaches a tile, over its +/// whole render area, by the load operation (the module docs): no fragment reads past the tiles +/// its draws touch, and no texel is kept. Which stored attachments took it, and whether the pass +/// took the near-equivalent (its draws reach the tiles their primitives touch): the attachment it /// names, for the notice. pub(super) fn dont_care_loads(layout: &mut PassLayout, reach: PassReach) -> DontCareLoads { let load = match reach { @@ -293,7 +309,14 @@ pub(super) fn dont_care_loads(layout: &mut PassLayout, reach: PassReach) -> Dont } continue; } - if color.load != LoadAction::DontCare || color.memoryless || !stores(color.store) { + if color.load != LoadAction::DontCare || color.memoryless { + continue; + } + if !stores(color.store) { + if reach != PassReach::Nothing { + color.load = LoadAction::Clear; + color.clear = dont_care_clear(color.target.texture.pixel_format()); + } continue; } color.load = load; @@ -317,7 +340,13 @@ pub(super) fn dont_care_loads(layout: &mut PassLayout, reach: PassReach) -> Dont let Some(aspect) = aspect else { continue; }; - if aspect.load != LoadAction::DontCare || aspect.memoryless || !stores(aspect.store) { + if aspect.load != LoadAction::DontCare || aspect.memoryless { + continue; + } + if !stores(aspect.store) { + if reach != PassReach::Nothing { + aspect.load = LoadAction::Clear; + } continue; } aspect.load = load; diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index f6693f9b5..86c464942 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -835,7 +835,9 @@ degradations! { /// An attachment loaded with `DontCare` and stored, in a pass that draws, is cleared /// before the draws to zero (a color) or its clear value (depth, stencil) over the render /// area and the tiles past it a clear reaches (`clear_reach.rs`), where Metal clears only - /// the tiles a draw's primitives touch and keeps the texels of the others. + /// the tiles a draw's primitives touch and keeps the texels of the others. Not one the + /// pass does not store, which its load operation clears over the render area: Metal's + /// answer wherever a fragment reads it. DontCareLoadTiles = "dont-care-load-tiles", Precision, "the tiles no draw touches hold zero or the clear value where Metal keeps their \ texels"; diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 43fb09fdd..ed18c7c7c 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -4746,7 +4746,9 @@ impl RenderLowering { }; // A `DontCare` load of an attachment the pass stores: loaded in a pass whose draws reach // no tile, else cleared to zero or its clear value, Metal's answer in each tile a draw - // reaches (`clear_reach.rs`), and only in those `tiles` bounds. + // reaches (`clear_reach.rs`), and only in those `tiles` bounds. One the pass does not + // store is cleared over the render area where the draws reach a tile, Metal's answer + // wherever a fragment reads it. let dont_care = clear_reach::dont_care_loads(&mut layout, reach); // The tiles the draws reach, which only those loads' clears read: none made for a pass // without one. @@ -4757,7 +4759,7 @@ impl RenderLowering { if let Some(named) = dont_care.named.clone() { device.degrade(Degradation::DontCareLoadTiles, || { ( - format!("{named} of a render pass, loaded with `DontCare`"), + format!("{named} of a render pass, loaded with `DontCare` and stored"), "Metal clears only the tiles a draw's primitives touch, which depend on where \ the GPU places the vertices" .to_owned(), diff --git a/docs/API.md b/docs/API.md index 6134d4b8c..02e898db6 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2343,7 +2343,11 @@ bound. with `DontCare` and stored, in a pass that draws, is cleared before the draws to zero (a color) or its clear value (depth, stencil) over the render area and the tiles past it a clear reaches, where Metal clears only the tiles a draw's primitives touch and keeps the texels of the others. Cost: - the tiles no draw touches hold zero or the clear value where Metal keeps their texels. + the tiles no draw touches hold zero or the clear value where Metal keeps their texels. An + attachment loaded with `DontCare` that the pass does not store is not announced: in a pass that + draws, the runtime clears it over the render area to zero or its clear value, which is what + Metal's draws read of it wherever they read it (an M3 Max, macOS 27.0.1: a framebuffer fetch of + a second color and a stencil test, in passes split and whole). - `metal2vulkan-degrade-fresh-pattern-zeroed` (precision). `FreshPatternZeroed`: On a device that presents an Apple silicon Mac's compression (`DeviceProperties::lossless_compression`, `MacClass::AppleSilicon`; never on one that presents a Mac with an Intel or AMD GPU, whose new