From 9ee2fd6bd2128d96fd1182e5540ad6a776dd91c2 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 13 Nov 2026 20:48:20 -0800 Subject: [PATCH] Tests: separate depth and stencil's unstored pass clears to zero, so a clear is told from a released stencil What: tests::unwritten_parts' separate depth and stencil leg gave both of its passes the stencil clear value MARK (0xA5), the DontCare/DontCare pass too. That pass now clears to 0 where its load is not Clear, and the leg runs on a device of each UnstoredDontCarePolicy (Driver, then Cleared). Why: with the clear value equal to the mark, the test could not tell a released texture's stencil from Metal's clear. A device that clears an unstored DontCare load (clear_reach::UnstoredLoads::Cleared: UnstoredDontCarePolicy:: Cleared, or DriverFact::UnstoredClearNoSlower, the Radeon 780M's) loads the scratch image's stencil as its Clear to the attachment's clear value, Metal's answer, which was MARK: every pixel passed the Equal test and the leg reported "the released texture's mark" on the 780M (pin 82 legs at 86ecc71b54). No released byte was read. Running both policies takes the Cleared form on every device, lavapipe and the XTX included, where the default takes the zero start (7b77851a95). Verified: the Cleared leg with the old clear value fails on lavapipe and passes with 0; lavapipe, XTX and 780M runs of the leg (jobs in the lane's report). --- .../src/tests/unwritten_parts.rs | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/unwritten_parts.rs b/crates/metal2vulkan-runtime/src/tests/unwritten_parts.rs index 6a9ebd2d6..da9248afc 100644 --- a/crates/metal2vulkan-runtime/src/tests/unwritten_parts.rs +++ b/crates/metal2vulkan-runtime/src/tests/unwritten_parts.rs @@ -23,14 +23,15 @@ //! `Depth32Float` texture and a `Private` `Stencil8` one renders through a scratch image of the //! combined format (`depth_stencil_scratch.rs`). One pass clears the stencil to 0xA5 and stores //! it, its textures and scratch image released; a pass of two new textures takes the three -//! parked images and loads its stencil `DontCare`, stores nothing and draws where the stencil -//! is 0xA5: it draws nothing, where the device leaves that load to the driver's `DONT_CARE` -//! (`clear_reach::UnstoredLoads`, lavapipe's, which leaves the image's texels) as where it -//! clears it. +//! parked images and loads its stencil `DontCare` with a clear value of 0, stores nothing and +//! draws where the stencil is 0xA5: it draws nothing, where the device leaves that load to the +//! driver's `DONT_CARE` (`clear_reach::UnstoredLoads`, lavapipe's, which leaves the image's +//! texels) as where it clears it to the clear value, Metal's answer. Run under each +//! `UnstoredDontCarePolicy`, so each device takes both forms. //! //! Printed (`UNWRITTEN-PARTS`): what each read found. -use super::blit_holds::{device, Scratch, WAIT}; +use super::blit_holds::{device, options, Scratch, WAIT}; use super::encoder_holds::library; use crate::{ BlitOption, Buffer, ClearColor, CommandBuffer, CommandBufferStatus, CommandQueue, @@ -38,6 +39,7 @@ use crate::{ PipelineOptions, RenderPassDescriptor, RenderPipelineState, ResourceOptions, Size, StoreAction, Texture, TextureDescriptor, }; +use metal2vulkan::device::UnstoredDontCarePolicy; use metal2vulkan::metal::state::DepthStencilDescriptor; use metal2vulkan::metal::{CompareFunction, PixelFormat, PrimitiveType, TextureUsage}; use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource}; @@ -246,8 +248,10 @@ impl Tools { } /// What a pass into `color`, cleared to zero and stored, beside `depth` and `stencil` loaded - /// with `load` (a `Clear` to 0.5 and [`MARK`]) and stored with `store`, draws over the whole - /// target where the stencil is [`MARK`]. + /// with `load` and stored with `store`, draws over the whole target where the stencil is + /// [`MARK`]: their clear values 0.5 and [`MARK`] where `load` is `Clear`, else 0.5 and 0, so a + /// `DontCare` load the device clears to the clear value (Metal's answer) is told apart from + /// one that reads a released texture's [`MARK`]. fn separate( &self, (depth, stencil): (&Texture, &Texture), @@ -267,7 +271,10 @@ impl Tools { let attachment = &mut pass.stencil_attachment; attachment.texture = Some(stencil.clone()); (attachment.load_action, attachment.store_action) = (load, store); - attachment.clear_stencil = MARK; + attachment.clear_stencil = match load { + LoadAction::Clear => MARK, + _ => 0, + }; let command_buffer = self.queue.command_buffer().unwrap(); let mut encoder = command_buffer.render_command_encoder(&pass).unwrap(); encoder.set_render_pipeline_state(&self.separate).unwrap(); @@ -404,8 +411,21 @@ fn a_tiled_texture_s_later_level_reads_as_a_new_texture_s_never_a_released_textu #[test] fn separate_depth_and_stencil_textures_read_no_released_texture_s_stencil() { + for policy in [ + UnstoredDontCarePolicy::Driver, + UnstoredDontCarePolicy::Cleared, + ] { + separate_released(policy); + } +} + +/// [`separate_depth_and_stencil_textures_read_no_released_texture_s_stencil`] on a device of +/// `policy`. +fn separate_released(policy: UnstoredDontCarePolicy) { let scratch = Scratch::new("unwritten-separate"); - let device = device(&scratch.0); + let mut options = options(&scratch.0); + options.policy.unstored_dont_care_loads = policy; + let device = Device::system_default_with(&options).unwrap(); let tools = Tools::new(&device); let mut descriptor = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false); descriptor.usage = TextureUsage::RENDER_TARGET; @@ -430,12 +450,13 @@ fn separate_depth_and_stencil_textures_read_no_released_texture_s_stencil() { let taken = device.work_counts().object_churn.images_recycled - taken; let drawn = found(&drawn, 0x40); println!( - "UNWRITTEN-PARTS separate stencil on {}: images taken {taken}, draw {drawn}", + "UNWRITTEN-PARTS separate stencil on {} under {policy:?}: images taken {taken}, draw \ + {drawn}", device.name() ); assert_eq!( taken, 3, - "the two textures and the scratch took the parked images" + "{policy:?}: the two textures and the scratch took the parked images" ); - assert_eq!(drawn, "zero"); + assert_eq!(drawn, "zero", "{policy:?}"); }