From e7c92ed0055e7995f518a44f6321a24edf1ff482 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 21:14:11 -0800 Subject: [PATCH] Fix forward of cca476549f: a one-sample depth/stencil attachment takes no texture index Family G made a one-sample depth or stencil attachment through the runtime at a texture index of the run's grant. The runtime gives an index exactly where shaders reach a texture (Device::new_texture): a depth or stencil target of RenderTarget usage alone is not reached, and an index given to one is refused (Refusal::TextureIndex, "a texture no shader reaches takes no index"). Every routed case with such an attachment failed at the make: public c5749a970e (match before) and one private case (mismatch before) in the family G proofs (m3-max-61598, 61611). The attachment is now made at no index, and the grant counts the color targets alone. Correction of cca476549f's message. It expected 18 one-aspect cases to run through the runtime. 2 do, the depth-only ones. The 16 stencil-only cases' fragment functions all write [[stencil]], which the runtime refuses at creation (its README's known gaps of render pipeline states, "a fragment function's stencil output"), so they are recorded as not_supported{device_capability_missing:StencilExport}. The device test a_fragment_case_writes_its_depth_and_stencil_attachment drew both aspects through the runtime under fragment_depth_stencil, whose stencil output the runtime refuses, and so could not pass on Linux. Its runtime arm now draws each aspect alone as the executor's own context draws it: depth under sample_rate_depth (0.125 at one sample) and stencil under fragment_no_writes (the state's reference replaces it), equal to the executor's own run. It also checks that fragment_depth_stencil through the runtime is a typed StencilExport refusal. Without the fix, both drawn arms fail at the make. Verified: cargo fmt. The compile gate and the device test on lavapipe follow as potluck jobs. --- .../src/candidate/platform/runtime_render.rs | 30 +++---- .../src/candidate/tests/engine_render.rs | 90 +++++++++++++------ 2 files changed, 73 insertions(+), 47 deletions(-) diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs index 37322144a..c923278a5 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs @@ -409,24 +409,16 @@ impl Targets { _grant: grant, }); } - let aspects = usize::from(case.depth_stencil.is_some()); - let (grant, mut at) = runtime_textures::texture_indices( + let (grant, at) = runtime_textures::texture_indices( device, indices, - case.color_targets.len() + aspects, + case.color_targets.len(), &runtime_error, )?; let depth_stencil = case .depth_stencil .as_ref() - .map(|authored| { - let index = at.next().ok_or_else(|| { - ExecutorError::Failed( - "no texture index for the depth/stencil attachment".into(), - ) - })?; - DepthStencil::make(device, device_type, authored, index) - }) + .map(|authored| DepthStencil::make(device, device_type, authored)) .transpose()?; let mut textures = BTreeMap::new(); for ((&index, target), at) in case.color_targets.iter().zip(at) { @@ -548,19 +540,18 @@ impl Targets { } impl DepthStencil { - /// `authored`'s one aspect at texture index `at` of the run's grant: a `Depth32Float` filled - /// with its depths by a draw (`runtime_depth`), or a `Stencil8` written from its bytes. + /// `authored`'s one aspect: a `Depth32Float` filled with its depths by a draw + /// (`runtime_depth`), or a `Stencil8` written from its bytes. fn make( device: &rt::Device, device_type: DeviceType, authored: &LiteralDepthStencil, - at: u32, ) -> Result { let [width, height] = authored.dimensions; let what = "the depth/stencil attachment"; match (&authored.depth, &authored.stencil) { (Some(depths), None) => { - let texture = aspect(device, rt::PixelFormat::Depth32Float, [width, height], at)?; + let texture = aspect(device, rt::PixelFormat::Depth32Float, [width, height])?; let fill = runtime_depth::Fill { texture: texture.clone(), level: 0, @@ -576,7 +567,7 @@ impl DepthStencil { }) } (None, Some(stencil)) => { - let texture = aspect(device, rt::PixelFormat::Stencil8, [width, height], at)?; + let texture = aspect(device, rt::PixelFormat::Stencil8, [width, height])?; texture .replace_region( whole([width, height]), @@ -600,19 +591,18 @@ impl DepthStencil { } } -/// A Shared 2D depth or stencil attachment of `format` and `extent` at texture index `at` of the -/// run's grant. +/// A Shared 2D depth or stencil attachment of `format` and `extent`, at no texture index: shaders +/// neither read nor write it, and the runtime gives such a target none (`Refusal::TextureIndex`). fn aspect( device: &rt::Device, format: rt::PixelFormat, [width, height]: [u32; 2], - at: u32, ) -> Result { let mut descriptor = rt::TextureDescriptor::new(rt::TextureType::Type2D, format, width, height); descriptor.usage = rt::TextureUsage::RENDER_TARGET; descriptor.storage_mode = rt::StorageMode::Shared; device - .new_texture(&descriptor, Some(at)) + .new_texture(&descriptor, None) .map_err(|error| runtime_error("the depth/stencil attachment", error)) } diff --git a/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs b/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs index 5f855b68f..d13001066 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs @@ -334,41 +334,77 @@ fn a_fragment_case_writes_its_depth_and_stencil_attachment() { Some(metal2vulkan::bind::StatusReport::default()) ); } - // Through the runtime, each aspect alone: an attachment of both is the oracle's two - // textures, which the runtime renders into in no one pass. + // Through the runtime, each aspect alone, as the executor's own context draws it: depth under + // `sample_rate_depth` (an eighth at one sample), stencil under `fragment_no_writes` (the state's + // reference replaces it). Neither takes a texture index: shaders neither read nor + // write it. An attachment of both is the oracle's two textures, which the runtime renders + // into in no one pass; a fragment function's stencil output, `fragment_depth_stencil`'s, it + // refuses at creation (its README's known gaps of render pipeline states). #[cfg(target_os = "linux")] { - for (depth, output, expected) in [ - ( - true, - OutputSelection::Depth { - origin: [0, 0], - dimensions: [1, 1], - }, - 0.5f32.to_le_bytes().to_vec(), - ), - ( - false, - OutputSelection::Stencil { - origin: [0, 0], - dimensions: [1, 1], - }, - vec![7], - ), - ] { - authored.depth_stencil = Some(crate::case::DepthStencilResource { + let depth_stencil = |of_depth: bool| { + Some(crate::case::DepthStencilResource { dimensions: [1, 1], - initial_depth_b64: depth.then(|| b64(&1.0f32.to_le_bytes())), - initial_stencil_b64: (!depth).then(|| b64(&[0xab])), + initial_depth_b64: of_depth.then(|| b64(&1.0f32.to_le_bytes())), + initial_stencil_b64: (!of_depth).then(|| b64(&[0xab])), state: None, - }); + }) + }; + let depth = OutputSelection::Depth { + origin: [0, 0], + dimensions: [1, 1], + }; + let stencil = OutputSelection::Stencil { + origin: [0, 0], + dimensions: [1, 1], + }; + let attachmentless = + metal2vulkan_devtools::llvm_assemble_text(crate::case::ATTACHMENTLESS_FRAGMENT_AIR) + .expect("llvm-as on the device lane"); + for (own, entry, aspect, output) in [ + ( + public("engine/sample_rate.ll"), + "sample_rate_depth", + true, + depth, + ), + (attachmentless, "fragment_no_writes", false, stencil.clone()), + ] { + let mut authored = + crate::companion::tests::case(Stage::Fragment, entry, TextureFormat::Rgba32Float); + authored.render_targets.clear(); + authored.depth_stencil = depth_stencil(aspect); authored.output = output; - let (case, companion) = with_companion(&authored, &fragment); + let (case, companion) = with_companion(&authored, &own); assert!(crate::candidate::engine::runs_render_through_runtime( &authored, &case )); - let through = run_on_runtime(&case, &fragment, Some(&companion)).unwrap(); - assert_eq!(through.output, expected, "{:?}", authored.output); + let drawn = run( + &case, + RenderLibraries { + vertex: &companion, + fragment: Some(&own), + }, + ) + .unwrap(); + let through = run_on_runtime(&case, &own, Some(&companion)).unwrap(); + assert_eq!(through.output, drawn.output, "{entry}"); + if aspect { + assert_eq!(through.output, 0.125f32.to_le_bytes().to_vec()); + } + } + authored.depth_stencil = depth_stencil(false); + authored.output = stencil; + let (case, companion) = with_companion(&authored, &fragment); + assert!(crate::candidate::engine::runs_render_through_runtime( + &authored, &case + )); + match run_on_runtime(&case, &fragment, Some(&companion)) { + Err(error @ ExecutorError::NotSupported(_)) => { + assert!(error.to_string().contains("StencilExport"), "{error}") + } + Err(error) => panic!("{error}"), + Ok(run) => panic!("a stencil output ran through the runtime: {:?}", run.output), } } }