diff --git a/crates/metal2vulkan-validation/src/candidate/engine.rs b/crates/metal2vulkan-validation/src/candidate/engine.rs index ecdc9b35d..481f0b7cb 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine.rs @@ -123,7 +123,7 @@ use tables::{function_tables, table_buffers, FunctionTable, TableBuffers}; /// how it decides a match. A change no recorded row can observe (a case kind no earlier executor /// ran, or one it refused) needs no bump; its commit says why. The commit that bumps it says what /// changed; this comment keeps no history. -pub const ENGINE_EXECUTOR_ABI: &str = "vulkan-engine-v202"; +pub const ENGINE_EXECUTOR_ABI: &str = "vulkan-engine-v203"; /// One kernel case in the terms the binder takes: what this executor supports of an /// [`AuthoredCase`] (buffers, device buffer arrays, argument-buffer buffers and textures, command @@ -1393,8 +1393,8 @@ pub struct RuntimeKernel<'a> { /// filled and read back sample by sample, `platform::runtime_multisample`), its own stage's /// buffers, bound textures the runtime makes (`runtime_texture`) and bound samplers, function /// constants and linked functions, its vertex buffers at static strides, its color targets and a -/// depth/stencil attachment of one aspect (a fragment case renders into at least one attachment: -/// the runtime makes no pass without one, `Gap::RenderPass`), the encoder's depth-stencil state, cull mode and winding, and +/// depth/stencil attachment of one aspect, or none (a fragment case's pass of no attachment is +/// the oracle's 1x1 at its samples), the encoder's depth-stencil state, cull mode and winding, and /// one direct or indexed draw of primitives or one patch draw with no patch or control-point index /// buffer (a post-tessellation vertex function's, its factors bound as the tessellation factor /// buffer), observing a buffer, a texture, a color target, the depth/stencil attachment's aspect @@ -1406,7 +1406,7 @@ pub fn runs_render_through_runtime(authored: &AuthoredCase, case: &graphics::Ren vertex, fragment, vertex_buffers, - color_targets, + color_targets: _, depth_stencil, depth_stencil_state: _, render_target_array_length, @@ -1448,7 +1448,6 @@ pub fn runs_render_through_runtime(authored: &AuthoredCase, case: &graphics::Ren }; bound(vertex) && fragment.as_ref().is_none_or(bound) - && (fragment.is_none() || !color_targets.is_empty() || depth_stencil.is_some()) && vertex_buffers.iter().all(|buffer| !buffer.dynamic) && depth_stencil.as_ref().is_none_or(one_aspect) && *render_target_array_length == 0 diff --git a/crates/metal2vulkan-validation/src/candidate/engine/tests.rs b/crates/metal2vulkan-validation/src/candidate/engine/tests.rs index 460d706be..93d4f994b 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine/tests.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine/tests.rs @@ -2255,12 +2255,12 @@ fn a_plain_kernel_case_and_only_one_runs_through_the_runtime() { /// textures and samplers, static vertex strides, color targets, and one direct or indexed draw /// of primitives or one patch draw with no index buffer, observing a buffer, a texture, a color /// target or nothing; and a rasterization-disabled vertex case, which renders into the oracle's -/// sink; a depth/stencil attachment of one aspect, of one sample or more, observed or not; and -/// an attribute buffer's out-of-bounds target. A case with anything else (a depth/stencil -/// attachment of both aspects, layered rendering, a dynamic vertex stride, an argument-buffer -/// member, an explicit imageblock, a fragment pass with no attachment, which the runtime makes no -/// pass of, a patch draw through a patch index buffer, or an index buffer's out-of-bounds target) -/// stays on the executor's own context. +/// sink; a depth/stencil attachment of one aspect, of one sample or more, observed or not; a +/// fragment pass with no attachment, of one sample or more; and an attribute buffer's +/// out-of-bounds target. A case with anything else (a depth/stencil attachment of both aspects, +/// layered rendering, a dynamic vertex stride, an argument-buffer member, an explicit imageblock, +/// a patch draw through a patch index buffer, or an index buffer's out-of-bounds target) stays on +/// the executor's own context. #[test] fn a_plain_draw_and_only_one_runs_through_the_runtime() { use super::graphics::tests::two_stage_case; @@ -2421,6 +2421,16 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() { ..plain.clone() }; assert!(runs_render_through_runtime(&authored, &multisampled)); + // A fragment pass of no attachment, of one sample or more. + for raster_sample_count in [None, Some(4)] { + let attachmentless = RenderCase { + color_targets: BTreeMap::new(), + output: RenderOutput::None, + raster_sample_count, + ..plain.clone() + }; + assert!(runs_render_through_runtime(&authored, &attachmentless)); + } let others = [ RenderCase { depth_stencil: Some(LiteralDepthStencil { @@ -2446,11 +2456,6 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() { }), ..plain.clone() }, - RenderCase { - color_targets: BTreeMap::new(), - output: RenderOutput::None, - ..plain.clone() - }, bounded( OutOfBoundsResource::IndexBuffer, ContainmentForm::IndexBuffer, diff --git a/crates/metal2vulkan-validation/src/candidate/platform/render.rs b/crates/metal2vulkan-validation/src/candidate/platform/render.rs index 18c0360c0..c6c414c27 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/render.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/render.rs @@ -1458,12 +1458,6 @@ impl<'a> Targets<'a> { if let Some([width, height]) = extent { targets.extent = vk::Extent2D { width, height }; } - // A multisampled subpass without attachments. - let attached = graphics.color_attachments.iter().any(Option::is_some) - || targets.depth_stencil.is_some(); - if let (AttachmentTransfer::PerSample { samples }, false) = (transfer, attached) { - multisampled::attachmentless_support(context, samples)?; - } Ok(targets) } diff --git a/crates/metal2vulkan-validation/src/candidate/platform/render/multisampled.rs b/crates/metal2vulkan-validation/src/candidate/platform/render/multisampled.rs index c7c945668..8f52cfe59 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/render/multisampled.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/render/multisampled.rs @@ -663,31 +663,6 @@ fn clear_stencil( recorded } -/// Whether the device rasterizes `samples` samples in a pass without attachments -/// (`framebufferNoAttachmentsSampleCounts`). -pub(super) fn attachmentless_support( - context: &VulkanContext, - samples: u32, -) -> Result<(), ExecutorError> { - // SAFETY: the physical device belongs to the live instance. - let counts = unsafe { - context - .instance - .get_physical_device_properties(context.physical) - } - .limits - .framebuffer_no_attachments_sample_counts; - if counts.contains(sample_flags(samples)?) { - Ok(()) - } else { - Err(NotSupported::NotEnabled(vec![format!( - "framebufferNoAttachmentsSampleCounts with {samples} samples (the device's: {:#b})", - counts.as_raw() - )]) - .into()) - } -} - /// One multisampled attachment image's moves around the pass: every aspect of its format (a /// depth/stencil image's layout covers both), the writes that filled it, and the access and /// layout the pass keeps it in. diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs index f5e34d77b..421de7a4c 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime_render.rs @@ -14,7 +14,8 @@ //! (`runtime_depth`, as the runtime takes no upload of one) or a Shared `Stencil8` written from its //! bytes, loaded and stored by the pass; in a pass of more samples, each attachment a Private //! multisampled texture of the pass's samples, filled and read back sample by sample -//! (`runtime_multisample`), a stencil aspect cleared by the pass to its one value; the oracle's +//! (`runtime_multisample`), a stencil aspect cleared by the pass to its one value; a fragment +//! case of no attachment the oracle's pass of none, 1x1 at the case's samples; the oracle's //! depth-stencil state, stencil //! references, cull mode and winding; one draw, direct, indexed or of patches (its factors a Shared //! buffer bound as the tessellation factor buffer, as the oracle binds them), in one command @@ -143,7 +144,7 @@ fn run( |command_buffer| { let fail = |what: &'static str| move |error: rt::Error| runtime_error(what, error); let mut encoder = command_buffer - .render_command_encoder(&targets.pass()) + .render_command_encoder(&targets.pass(case)) .map_err(fail("the render encoder"))?; encoder .set_render_pipeline_state(&state) @@ -527,10 +528,16 @@ impl Targets { }) } - /// The pass: each attachment loaded and stored, a multisampled stencil aspect cleared to its - /// one value. - fn pass(&self) -> rt::RenderPassDescriptor { + /// The pass of `case`: each attachment loaded and stored, a multisampled stencil aspect + /// cleared to its one value; with no attachment, the oracle's (`metal::platform`) 1x1 area at + /// the case's samples (`renderTargetWidth`, `renderTargetHeight`, `defaultRasterSampleCount`). + fn pass(&self, case: &RenderCase) -> rt::RenderPassDescriptor { let mut pass = rt::RenderPassDescriptor::default(); + if self.textures.is_empty() && self.depth_stencil.is_none() { + pass.render_target_width = 1; + pass.render_target_height = 1; + pass.default_raster_sample_count = case.raster_sample_count.unwrap_or(1); + } for (&index, texture) in &self.textures { let attachment = &mut pass.color_attachments[index as usize]; attachment.texture = Some(texture.clone()); diff --git a/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs b/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs index 2bac953ba..3b57772b3 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs @@ -563,6 +563,76 @@ fn each_sample_of_a_multisampled_target_keeps_its_own_contents() { assert_eq!(run.output, expected, "on the executor's own context"); } +/// A fragment case of no attachment draws into the oracle's 1x1 pass at its samples: +/// `nat_sample` ORs each run's coverage, marked by 0x100, into its sample's word and counts the +/// run 8 words on, so at 1 and at 4 samples each sample runs once and reads its own bit. Through +/// the runtime the pass is `renderTargetWidth` by `renderTargetHeight` at +/// `defaultRasterSampleCount`, and its words are the executor's own. +#[cfg(any(target_os = "linux", target_os = "macos"))] +#[test] +fn a_fragment_pass_of_no_attachment_runs_each_sample_once() { + let fragment = public("engine/coverage_natural.ll"); + for samples in [1u32, 4] { + let mut authored = crate::companion::tests::case( + Stage::Fragment, + "nat_sample", + TextureFormat::Rgba32Float, + ); + authored.render_targets.clear(); + authored.raster_sample_count = (samples > 1).then_some(samples); + authored.buffers.push(crate::case::BufferResource { + binding: 0, + role: crate::case::ResourceRole::InOut, + bytes_b64: None, + initial_bytes_b64: Some(b64(&[0; 64])), + rasterization_rate_map: None, + }); + authored.output = OutputSelection::Buffer { + binding: 0, + offset: 0, + length: 64, + }; + let (case, companion) = with_companion(&authored, &fragment); + let drawn = run( + &case, + RenderLibraries { + vertex: &companion, + fragment: Some(&fragment), + }, + ) + .unwrap(); + let words: Vec = drawn + .output + .as_chunks::<4>() + .0 + .iter() + .map(|word| u32::from_le_bytes(*word)) + .collect(); + for sample in 0..8 { + let ran = sample < samples; + let own = 0x100 | (1 << sample); + let word = words[sample as usize]; + assert_eq!(word & own, if ran { own } else { 0 }, "{samples}: {sample}"); + assert_eq!( + words[8 + sample as usize], + u32::from(ran), + "{samples}: {sample}" + ); + } + #[cfg(target_os = "linux")] + { + assert!(crate::candidate::engine::runs_render_through_runtime( + &authored, &case + )); + let through = run_on_runtime(&case, &fragment, Some(&companion)).unwrap(); + assert_eq!( + through.output, drawn.output, + "{samples} through the runtime" + ); + } + } +} + /// A tessellation case drawn through the render executor's patch path: the factor buffer bound /// where the plan's factor write names it, the probe as the evaluation stage, and the case's cull /// mode. `k7_tess_quad_probe` draws patch 0 over the target's left half and patch 1, its mirror diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index ff6b73c72..2f9123afa 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -505,9 +505,10 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \ runtime device's own translator: the runtime's floor enables no buffer robustness, so a fixed-function vertex fetch past its buffer is checked nowhere and the case is refused as `not_supported{uncontained:unchecked vertex_input}`. A rasterization-disabled vertex case renders - into the oracle's 1x1 `R8Unorm` attachment. Layered rendering, an argument-buffer member, a - patch index buffer, an out-of-bounds target other than an attribute buffer or a fragment pass - with no attachment (the runtime makes no pass without one) keeps the case on the executor's own + into the oracle's 1x1 `R8Unorm` attachment, and a fragment case of no attachment into the + oracle's pass of none: `renderTargetWidth` and `renderTargetHeight` 1, `defaultRasterSampleCount` + the case's samples. Layered rendering, an argument-buffer member, a patch index buffer or an + out-of-bounds target other than an attribute buffer keeps the case on the executor's own context. A vertex buffer's dynamic stride carries `dynamic_vertex_stride` and a fragment function's imageblock `fragment_imageblock`, each the runtime's limit. An indexed draw past its index buffer, which the runtime refuses as Metal's validation does