From 9fe1b0175fca6249b57fd863ad7830480da087c2 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 4 Nov 2026 20:53:55 -0800 Subject: [PATCH] Key the compressed shape's clear route in the extended-range and bfloat clear checks A clear takes Metal's straight route only where nan_clear::keeps_nan_sign holds (render.rs), which the fresh-texture key now makes false on a device that presents a Mac keeping no texture compressed: there a 16 x 16 plain target is not compressed, so it clears through half, as Metal's uncompressed targets do (expected, not measured on such a Mac). Three checks still expected the straight route there and failed on the RTX 5080 Laptop at fd34a10316: - conformance xr-clear-routes-{bgra10xr,bgra10xr-srgb,bgr10xr,bgr10xr-srgb}: divergent at case/plain-16/texels/0..3 alone (15 sites), unlisted, in the replay of job m3-max-120; the baseline replay at 0b556ddfd6 (job m3-max-141) held none of them (its other 908 unlisted gap sites are the same in both runs). ClearRoutes now declares replay::without_compression("plain-16"). - validation runtime_lane::extended_range_targets::clears_take_metal_s_route (15 clears differ, all the 16 x 16 draws-false shape) and runtime_lane::bfloat_targets:: bfloat_clears_take_metal_s_route (11, all that shape), suite job m3-max-124: each now expects ClearRoute::Straight for that shape only where DeviceProperties::lossless_compression holds, else ThroughHalf. docs/API.md's accepted difference says the clear route too, and keeps_nan_sign's doc says it decides the route. Verified on the M3 Max, no device: nextest metal2vulkan-conformance 1011/1011; cargo clippy -D warnings on validation and conformance with --cfg m2v_gpu (all targets, all features); docs/CONFORMANCE-COVERAGE.md re-derives unchanged. UNVERIFIED: none of the three has run with this commit on the 5080 or the M3. (cherry picked from commit 1c042263e5fee942b79fbd30042c2dc9f222b61b) --- .../src/cases/extended_range_targets.rs | 7 +++++++ crates/metal2vulkan-runtime/src/nan_clear.rs | 7 ++++--- .../src/runtime_lane/bfloat_targets.rs | 12 ++++++++++-- .../src/runtime_lane/extended_range_targets.rs | 12 ++++++++++-- docs/API.md | 5 +++-- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/crates/metal2vulkan-conformance/src/cases/extended_range_targets.rs b/crates/metal2vulkan-conformance/src/cases/extended_range_targets.rs index 772b9f738..23beffff6 100644 --- a/crates/metal2vulkan-conformance/src/cases/extended_range_targets.rs +++ b/crates/metal2vulkan-conformance/src/cases/extended_range_targets.rs @@ -1069,6 +1069,13 @@ impl Case for ClearRoutes { named.extend(super::compressed_blits::kept_encoding_notice( self.format.format.as_raw(), )); + // On a venue that presents no texture compression the blit that reads `plain-16` back, + // through the texture the recording's Mac compressed, keeps the device's encoding where + // the recording holds the compressor's canonical one, and the runtime rewrites none + // under the suite's exact policy (`compressed_blits`'s declaration says why). Measured on + // the RTX 5080 Laptop: `case/plain-16/texels/*` alone differ against the recording with + // the key and matched before it. + named.push(crate::replay::without_compression("plain-16")); named } diff --git a/crates/metal2vulkan-runtime/src/nan_clear.rs b/crates/metal2vulkan-runtime/src/nan_clear.rs index 05ab9c30d..97eb9513e 100644 --- a/crates/metal2vulkan-runtime/src/nan_clear.rs +++ b/crates/metal2vulkan-runtime/src/nan_clear.rs @@ -110,9 +110,10 @@ pub(super) fn degrade_nan_clears(device: &Device, layout: &PassLayout, drew: boo } /// Whether Metal's NaN clear of `target`, in a pass with a draw call where `called`, keeps a -/// `half` NaN's sign (the module docs): on a device that presents an Apple silicon Mac's -/// compression (`Device::metal_compresses_textures`; on one that presents a Mac keeping none, as -/// a Mac with an Intel or AMD GPU does, never: expected rather than measured), its texture (a view's first +/// `half` NaN's sign (the module docs), which is also whether its clear takes the straight route +/// (`render.rs`): on a device that presents an Apple silicon Mac's compression +/// (`Device::metal_compresses_textures`; on one that presents a Mac keeping none, as a Mac with +/// an Intel or AMD GPU does, never: expected rather than measured), its texture (a view's first /// texture) is one Metal keeps losslessly compressed (`heap_tiled::metal_compresses`: not over a /// buffer, of no usage Metal keeps uncompressed, optimized contents allowed), the attachment's /// level is 16 texels or more a side, counted in pixels at any sample count, and the pass has no diff --git a/crates/metal2vulkan-validation/src/runtime_lane/bfloat_targets.rs b/crates/metal2vulkan-validation/src/runtime_lane/bfloat_targets.rs index 3de7d0d31..78dbf4a12 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/bfloat_targets.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/bfloat_targets.rs @@ -359,11 +359,19 @@ const M3_CODES: [[u16; 4]; 2] = [ /// (`ClearRoute::Straight`) for a 16 x 16 private target of plain usage in a pass with no draw /// call, and through `half` (`ClearRoute::ThroughHalf`) for an 8 x 8 one, one of `ShaderWrite` or /// `PixelFormatView` usage, and one whose pass draws into another attachment. Every texel of the -/// target is checked. +/// target is checked. On a device that presents a Mac keeping no texture compressed +/// (`DeviceProperties::lossless_compression` false) the 16 x 16 one is not compressed either, so +/// it takes the route of the uncompressed ones, through `half` (`nan_clear::keeps_nan_sign`; +/// expected, not measured on such a Mac). #[test] fn bfloat_clears_take_metal_s_route() { let (messages, _cache, lane) = lane_with(|_| {}); let plain = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ; + // The route of the shape Metal keeps compressed, where the device presents the compression. + let compressed = match lane.device.properties().lossless_compression { + true => ClearRoute::Straight, + false => ClearRoute::ThroughHalf, + }; let library = library(&lane.device).unwrap(); let function = |name: &str| { StageSource::Function( @@ -385,7 +393,7 @@ fn bfloat_clears_take_metal_s_route() { .new_render_pipeline_state(&state, &PipelineOptions::default()) .unwrap_or_else(|e| panic!("{pf:?}: the pipeline: {e}")); for (side, usage, draws, route) in [ - (16, plain, false, ClearRoute::Straight), + (16, plain, false, compressed), (8, plain, false, ClearRoute::ThroughHalf), ( 16, diff --git a/crates/metal2vulkan-validation/src/runtime_lane/extended_range_targets.rs b/crates/metal2vulkan-validation/src/runtime_lane/extended_range_targets.rs index a4bc3e488..a7bba9aff 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/extended_range_targets.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/extended_range_targets.rs @@ -852,11 +852,19 @@ const ROUTE_COLORS: [[f64; 4]; 4] = [ ]; /// A `Clear` of each single-plane extended-range format stores Metal's route's texel in every -/// texel of the target (the module docs). +/// texel of the target (the module docs). On a device that presents a Mac keeping no texture +/// compressed (`DeviceProperties::lossless_compression` false) the 16 x 16 plain target is not +/// compressed either, so it takes the route of the uncompressed ones, through `half` +/// (`nan_clear::keeps_nan_sign`; expected, not measured on such a Mac). #[test] fn clears_take_metal_s_route() { let (messages, _cache, lane) = lane(); let plain = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ; + // The route of the shape Metal keeps compressed, where the device presents the compression. + let compressed = match lane.device.properties().lossless_compression { + true => ClearRoute::Straight, + false => ClearRoute::ThroughHalf, + }; let library = library(&lane.device).unwrap(); let function = |name: &str| { StageSource::Function( @@ -878,7 +886,7 @@ fn clears_take_metal_s_route() { .unwrap_or_else(|e| panic!("{:?}: the pipeline: {e}", f.pf)); let size = texel_size(f.form); for (side, usage, draws, route) in [ - (16, plain, false, ClearRoute::Straight), + (16, plain, false, compressed), (8, plain, false, ClearRoute::ThroughHalf), ( 16, diff --git a/docs/API.md b/docs/API.md index 81921d72d..d1a90966f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4056,8 +4056,9 @@ each item named states the rule in full. both; a `Depth32Float` one never read the released clear. - a GPU blit or fill through any texture keeps its bytes, with no `extended-range-bits-kept`, `device-nan-encoding` or `shared-exponent-kept` note for it and no rewrite under - `ExtendedRangeBlitPolicy::Canonical`, and a `half` NaN clear keeps no sign. Expected, not - measured on such a Mac. + `ExtendedRangeBlitPolicy::Canonical`, and a clear of any texture takes the route of Metal's + uncompressed one, through `half`, so a `half` NaN clear keeps no sign and an extended-range + or bfloat clear rounds as through `half`. Expected, not measured on such a Mac. Metal leaves a new texture's contents undefined, and zero and a released texture's texels are both what such a Mac reads, so this trades no accuracy and no `DevicePolicy` switch fills the