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), } } }