diff --git a/crates/metal2vulkan-runtime/src/arrays.rs b/crates/metal2vulkan-runtime/src/arrays.rs index d202bc837..921a60b33 100644 --- a/crates/metal2vulkan-runtime/src/arrays.rs +++ b/crates/metal2vulkan-runtime/src/arrays.rs @@ -32,8 +32,7 @@ //! face: the translator samples the cube view there at the texel's centre and the read's level //! (docs/RESOURCE-ID.md). The device writes every element once at creation ([`Arrays::new`]). //! -//! The sampled-texture array holds 196,608 elements. Where the device reads attachments through -//! textures (`floor::Capabilities::attachment_reads`), element `i + 65,536` is texture `i`'s second +//! The sampled-texture array holds 196,608 elements. Element `i + 65,536` is texture `i`'s second //! element, which a draw pushes in place of the texture's own while it reads an attachment of its //! pass through the texture (`crate::render_encoder`). Through the attachment feedback loop it is //! the texture's sampled view in the feedback layout, written with element `i` for a texture whose @@ -363,9 +362,6 @@ pub(crate) struct Arrays { pub(crate) plain: vk::Sampler, /// The default sampler of the comparison array. pub(crate) compare: vk::Sampler, - /// Whether the sampled-texture array's second elements hold views: the device reads - /// attachments. - seconds: bool, pub(crate) grants: Mutex, /// The sampler each sampler array's element at each index holds, plain, comparison and /// integer texture, and its unnormalized twin ([`TWIN`]), as last written: a default, or a @@ -375,9 +371,8 @@ pub(crate) struct Arrays { } impl Arrays { - /// Makes set 1 and writes every element its default; with `seconds`, the sampled-texture - /// array's second elements hold views. With `buffers`, set 0's layout holds a kernel's - /// storage buffers ([`buffer_bindings`]); without, it is empty. + /// Makes set 1 and writes every element its default. With `buffers`, set 0's layout holds a + /// kernel's storage buffers ([`buffer_bindings`]); without, it is empty. /// /// # Safety /// @@ -386,11 +381,11 @@ impl Arrays { pub(crate) unsafe fn new( device: &ash::Device, counters: &Counters, - (seconds, buffers): (bool, bool), + buffers: bool, ) -> Result { let mut made = Made::default(); // SAFETY: the caller's contract; what was made is destroyed where a later step fails. - let arrays = unsafe { made.make(device, counters, (seconds, buffers)) }; + let arrays = unsafe { made.make(device, counters, buffers) }; if arrays.is_err() { // SAFETY: nothing else holds what was made. unsafe { made.destroy(device, counters) }; @@ -459,7 +454,7 @@ impl Arrays { let storage = storage.or(displaced.then(vk::ImageView::null)); let second = match looped { Some(view) => Some((view, vk::ImageLayout::ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT)), - None => (displaced && self.seconds).then(|| { + None => displaced.then(|| { ( vk::ImageView::null(), vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, @@ -509,8 +504,7 @@ impl Arrays { self.write_texels(device, index, views); if displaced { let null = vk::ImageView::null(); - let second = - (self.seconds).then_some((null, vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)); + let second = Some((null, vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)); self.write_texture(device, index, None, Some(null), second); self.write_level_zero(device, index, None); } @@ -1094,7 +1088,7 @@ impl Made { &mut self, device: &ash::Device, counters: &Counters, - (seconds, buffers): (bool, bool), + buffers: bool, ) -> Result { let bindings = buffer_bindings(); let first = vk::DescriptorSetLayoutCreateInfo::default().bindings(if buffers { @@ -1186,7 +1180,6 @@ impl Made { set, plain, compare, - seconds, grants: Mutex::new(Grants::new()), samplers: Mutex::new( vec![[plain, compare, plain, plain]; SAMPLER_ELEMENTS as usize].into_boxed_slice(), diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 9df023206..087aee10d 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -282,10 +282,6 @@ pub(crate) struct Core { /// caches, where device creation enabled it (`floor::Capabilities::indirect_commands`); an /// indirect command buffer is refused without them. pub(crate) indirect: Option, - /// A draw may read an attachment of its own pass through a texture - /// (`floor::Capabilities::attachment_reads`): through the feedback loop where `feedback_loop` - /// holds, else through a copy of the image into its shadow (`crate::shadow`). - pub(crate) attachment_reads: bool, /// Device creation enabled `linearColorAttachment` (`VK_NV_linear_color_attachment`, where /// the device lists it): an opaque handle's surface plane whose format's `LINEAR` tiling /// renders through `VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV` alone lies in place @@ -928,7 +924,6 @@ impl Device { feedback_loop: capabilities.feedback_loop, fault, indirect, - attachment_reads: capabilities.attachment_reads, linear_attachments: (capabilities.features.linear_attachment).linear_color_attachment == vk::TRUE, resolve_modes, @@ -1677,9 +1672,7 @@ unsafe fn objects( // SAFETY: the device is live. let made = unsafe { Done::new(device) }.and_then(|mut done| { // SAFETY: the device is live, with the floor's features. - let arrays = match unsafe { - Arrays::new(device, counters, (capabilities.attachment_reads, buffers)) - } { + let arrays = match unsafe { Arrays::new(device, counters, buffers) } { Ok(arrays) => arrays, Err(error) => { // SAFETY: the completion objects are unused. diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 076a191ea..311e964e3 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -2109,13 +2109,12 @@ pub enum DrawKind { /// ([`RenderCommandEncoder::set_render_pipeline_state`](crate::RenderCommandEncoder::set_render_pipeline_state)). AttachmentFormats, /// A draw that binds a texture whose image the pass renders, where neither the attachment - /// feedback loop nor a copy into the image's shadow reads it: on a device without the - /// attachment reads (`floor::Capabilities::attachment_reads`), from the vertex function at the + /// feedback loop nor a copy into the image's shadow reads it: from the vertex function at the /// rendered level and layer, written, of a depth or stencil attachment, of an image the device /// takes neither the feedback usage nor a shadow for (its format's image, or in place over a - /// buffer its linear image), or of an image two attachments of the pass render; through a shadow, which holds - /// one layer, an attachment of a layered pass or a 3D texture's depth plane; and on any - /// device, a surface plane the pass renders in its stand-in, an optimal image of the + /// buffer its linear image), or of an image two attachments of the pass render; through a + /// shadow, which holds one layer, an attachment of a layered pass or a 3D texture's depth + /// plane; and a surface plane the pass renders in its stand-in, an optimal image of the /// runtime's that holds what the pass renders until its end copies it into the plane (a plane /// whose format the device's `LINEAR` tiling renders only beside other such planes, in a pass /// that sets another attachment beside it or resolves into it). diff --git a/crates/metal2vulkan-runtime/src/floor.rs b/crates/metal2vulkan-runtime/src/floor.rs index 8c06cf01e..1a67047c9 100644 --- a/crates/metal2vulkan-runtime/src/floor.rs +++ b/crates/metal2vulkan-runtime/src/floor.rs @@ -146,10 +146,9 @@ const _: () = { /// The device extension of the attachment feedback loop (`VK_EXT_attachment_feedback_loop_layout`), /// through which a draw reads, through a texture, an attachment its own pass renders (Metal's /// texture read of a render target): its layout, its image usage and its pipeline flag, which every -/// render pipeline takes. Device creation enables it, with its feature, where the device reads -/// attachments (`Capabilities::attachment_reads`), lists it and reports the feature, and not -/// otherwise. A device that reads attachments without it reads through a copy of the image -/// (`Capabilities::feedback_loop`). +/// render pipeline takes. Device creation enables it, with its feature, where the device lists it +/// and reports the feature, and not otherwise. A device without it reads attachments through a +/// copy of the image (`Capabilities::feedback_loop`). pub const ATTACHMENT_READ_EXTENSIONS: &[&CStr] = &[ash::ext::attachment_feedback_loop_layout::NAME]; /// The device extension of a sampler's border colour through a view's component mapping @@ -1140,12 +1139,13 @@ pub struct Capabilities { /// takes the offset as its own `Offset` operand. Where it is false, the sample branches over /// the offset's values, each branch with its value as `ConstOffset`. pub texel_offset_operand: bool, - /// The device's descriptor limits hold the sampled-texture array's second elements, which the - /// floor's do on every device: a draw may read, through a texture, an attachment its own pass - /// renders, as Metal reads a render target. It reads through the attachment feedback loop where - /// [`feedback_loop`](Self::feedback_loop) holds, and through a copy of the image otherwise. + /// Always true: the floor's descriptor limits hold the sampled-texture array's second + /// elements, so a draw may read, through a texture, an attachment its own pass renders on + /// every device, as Metal reads a render target. It reads through the attachment feedback loop + /// where [`feedback_loop`](Self::feedback_loop) holds, and through a copy of the image + /// otherwise. Kept for the consumers that report it; the runtime reads it nowhere. pub attachment_reads: bool, - /// The attachment reads hold, and so does the attachment-read feature, with + /// The attachment-read feature holds, with /// [`ATTACHMENT_READ_EXTENSIONS`]: a draw reads an attachment through the attachment feedback /// loop, the feedback layout its image moves to and the colour flag the pipelines of a state /// whose functions can read a texture take. @@ -1518,8 +1518,7 @@ pub(crate) fn decide(device: &Queried) -> Result { // level-0 elements (`arrays::SAMPLED_ELEMENTS`): every device that meets it reads // attachments. let attachment_reads = true; - let feedback_loop = attachment_reads - && ATTACHMENT_READ_EXTENSIONS.iter().all(|&name| listed(name)) + let feedback_loop = ATTACHMENT_READ_EXTENSIONS.iter().all(|&name| listed(name)) && (ATTACHMENT_READS.iter()).all(|feature| *(feature.field)(&mut reported) == vk::TRUE); if feedback_loop { for feature in ATTACHMENT_READS { diff --git a/crates/metal2vulkan-runtime/src/render_encoder.rs b/crates/metal2vulkan-runtime/src/render_encoder.rs index 4a1870e94..106ccfaea 100644 --- a/crates/metal2vulkan-runtime/src/render_encoder.rs +++ b/crates/metal2vulkan-runtime/src/render_encoder.rs @@ -22,9 +22,9 @@ //! buffer's device copy, `crate::over`), recording the copy between. A memory barrier after no //! such draw records nothing: everything before the pass is ordered before it. //! -//! A draw may read an attachment of its own pass through a texture, as Metal reads a render target -//! (`floor::Capabilities::attachment_reads`): through the attachment feedback loop where the -//! device has it, else through a copy. Its image is a colour render target not in place over a +//! A draw may read an attachment of its own pass through a texture, as Metal reads a render target, +//! on every device: through the attachment feedback loop where the device has it, else through a +//! copy. Its image is a colour render target not in place over a //! buffer, whose home is general where it has a storage view, shader-read-only where shaders read //! it, else the attachment layout. An attachment renders at home general or attachment, and a move //! to the feedback layout and back is from and to its home. @@ -3663,7 +3663,6 @@ impl RenderCommandEncoder { /// [`DrawKind::FetchedAttachment`] for a colour attachment the fragment function cannot read /// through its texture. fn attachment_reads(&self, draws: &Draws) -> Result { - let core = &*self.core; let drawn = self.drawn(draws); let tables = &self.tables; let mut found = AttachmentReads { @@ -3699,8 +3698,7 @@ impl RenderCommandEncoder { if !reaches && !moved { continue; } - let readable = core.attachment_reads - && texture.attachment_reads() + let readable = texture.attachment_reads() && !access.writes() && (table == FRAGMENT || !reaches) && rendered.next().is_none(); @@ -3770,8 +3768,7 @@ impl RenderCommandEncoder { } _ => false, }; - let readable = core.attachment_reads - && shaped + let readable = shaped && target.stand_in.is_none() && texture.attachment_reads() && texture.base() == [a.level, a.layer] diff --git a/crates/metal2vulkan-runtime/src/tests/draw.rs b/crates/metal2vulkan-runtime/src/tests/draw.rs index 2e59888e5..f533ece4c 100644 --- a/crates/metal2vulkan-runtime/src/tests/draw.rs +++ b/crates/metal2vulkan-runtime/src/tests/draw.rs @@ -3326,9 +3326,7 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { /// clear colour, and the one after the memory barrier copies what it reads into the shadow, /// each between two barriers of their own, and the memory barrier records nothing. Either way /// the rendering ends and begins again twice (`Metrics::rendering_interrupts`); the - /// copies, their bytes and the live shadows are printed. A device without the - /// attachment reads refuses the draw, `Gap::Draw { AttachmentRead }`, and records nothing for - /// it. + /// copies, their bytes and the live shadows are printed. #[test] fn every_device_reads_its_attachment_through_a_texture_after_a_memory_barrier() { let Some(library) = examples() else { @@ -3340,7 +3338,6 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { each_device("attachment_reads", |name, _, device| { (device.grant_indices(IndexClass::Texture, 4096, 4)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let looped = device.core().feedback_loop; let plain = state(name, &device, &plain); let mut buffers = Buffers::new(&device); @@ -3376,23 +3373,7 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { draw(encoder.set_fragment_texture(Some(&color), 0)); draw(encoder.set_render_pipeline_state(&reading)); // The pass's first read of its attachment: the clear's black, and none added. - let moved = encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0); - if !reads { - assert_eq!( - format!("{moved:?}"), - format!( - "{:?}", - Err::<(), _>(Error::Unsupported(Gap::Draw { - kind: DrawKind::AttachmentRead - })) - ), - "{name} {case}: a device without the attachment reads" - ); - encoder.end_encoding(); - run(name, &command_buffer); - continue; - } - draw(moved); + draw(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); // Blue over every pixel, then the barrier, then each pixel read plus green. draw(encoder.set_render_pipeline_state(&plain)); draw(encoder.draw_primitives(PrimitiveType::Triangle, 3, 3, 1, 0)); @@ -3490,16 +3471,15 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { "{name} {case}: every pixel blue read plus green" ); } - match (reads, looped) { - (true, true) => println!( + match looped { + true => println!( "{name}: an attachment read after a memory barrier, at its own pixel and at \ another, through the feedback loop" ), - (true, false) => println!( + false => println!( "{name}: an attachment read after a memory barrier, at its own pixel and at \ another, through copies into its shadow" ), - (false, _) => println!("{name}: no attachment reads; the reading draw refused"), } }); } @@ -3525,10 +3505,6 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { let plain = descriptor(&library, "colored_fragment", PixelFormat::RGBA8Unorm); let own = descriptor(&library, "own_pixel_fragment", PixelFormat::RGBA8Unorm); each_device("loop_flags", |name, _, device| { - if !device.core().attachment_reads { - println!("{name}: no attachment reads"); - return; - } let looped = device.core().feedback_loop; (device.grant_indices(IndexClass::Texture, 4096, 4)) .unwrap_or_else(|error| panic!("{name}: {error}")); @@ -3745,10 +3721,6 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { let plain = descriptor(&library, "colored_fragment", PixelFormat::RGBA8Unorm); let own = descriptor(&library, "own_pixel_fragment", PixelFormat::RGBA8Unorm); each_device("attachment_clear", |name, _, device| { - if !device.core().attachment_reads { - println!("{name}: no attachment reads"); - return; - } (device.grant_indices(IndexClass::Texture, 4096, 4)) .unwrap_or_else(|error| panic!("{name}: {error}")); let looped = device.core().feedback_loop; @@ -3835,10 +3807,6 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { }; let d = descriptor(&library, "first_level_fragment", PixelFormat::RGBA8Unorm); each_device("attachment_levels", |name, _, device| { - if !device.core().attachment_reads { - println!("{name}: no attachment reads"); - return; - } let looped = device.core().feedback_loop; let counters = device.counters(); let before = counters.metrics(); diff --git a/crates/metal2vulkan-runtime/src/tests/fetch.rs b/crates/metal2vulkan-runtime/src/tests/fetch.rs index cb57c0804..66649c217 100644 --- a/crates/metal2vulkan-runtime/src/tests/fetch.rs +++ b/crates/metal2vulkan-runtime/src/tests/fetch.rs @@ -3,8 +3,7 @@ //! it, which Metal orders draw after draw, so the target holds that function applied N times. //! The fetch reads the attachment's texture at the fragment's own pixel: through the attachment //! feedback loop, one barrier before each fetching draw after the first, or through the image's -//! shadow, one copy before each. Both forms are counted, and a device without the attachment -//! reads refuses the draw. +//! shadow, one copy before each. Both forms are counted. #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod on_device { @@ -212,8 +211,7 @@ mod on_device { /// `c * 3^N + (k + 1)(3^N - 1) / 2` in channel `k`, exact only where each draw read what the /// one before it wrote. Through the loop, a pass of N draws records N - 1 barriers more than /// a pass of one and counts N draws through the loop; through the shadow, N - 1 copies of the - /// target more, each between two barriers. A device without the attachment reads refuses the - /// first draw, `Gap::Draw { FetchedAttachment }`. + /// target more, each between two barriers. #[test] fn every_device_orders_each_fetching_draw_after_the_draws_before_it() { let Some(d) = fetching( @@ -226,7 +224,6 @@ mod on_device { each_device("fetch", |name, _, device| { (device.grant_indices(IndexClass::Texture, 4096, DRAWS.len() as u32)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let looped = device.core().feedback_loop; let state = state(name, &device, &d); let queue = device.new_command_queue(4).expect("a queue"); @@ -241,19 +238,6 @@ mod on_device { let color = readable(&device, PixelFormat::RGBA32Uint, 1, 4096 + at as u32); let (drew, counted) = pass_of((name, &device, &queue), &state, &color, clear, draws); - if !reads { - assert_eq!( - format!("{drew:?}"), - format!( - "{:?}", - Err::<(), _>(Error::Unsupported(Gap::Draw { - kind: DrawKind::FetchedAttachment - })) - ), - "{name}: a device without the attachment reads" - ); - continue; - } drew.unwrap_or_else(|error| panic!("{name}: {draws} draws: {error}")); let three = 3u32.pow(draws); let want: Vec = (0..SIDE * SIDE) @@ -268,10 +252,6 @@ mod on_device { assert_eq!(read(&color, 16), want, "{name}: {draws} draws, every texel"); counts.push(counted); } - if !reads { - println!("{name}: no attachment reads; the fetching draw refused"); - return; - } let draws = DRAWS[1]; let (want, loop_reads) = more(looped, draws, 16); assert_eq!( @@ -320,8 +300,7 @@ mod on_device { /// lowered at the first such pass's `set_render_pipeline_state` and kept in the device's /// bounded map of contents: lowered once over the passes, the map at a cap of 1 holding 1. A /// pass that renders slice 1 of the array, or both its slices, is - /// `Gap::Draw { FetchedAttachment }`, as every array is on a device without the attachment - /// reads. + /// `Gap::Draw { FetchedAttachment }`. #[test] fn every_device_fetches_the_first_slice_of_a_2d_array_rendering_one_layer() { let Some(d) = fetching( @@ -338,7 +317,6 @@ mod on_device { let counters = device.counters(); let lowered = || counters.metrics().translations; let entries = || counters.gauges().kernel_entries; - let reads = device.core().attachment_reads; let state = state(name, &device, &d); assert_eq!(entries(), 1, "{name}: the state's content"); let queue = device.new_command_queue(4).expect("a queue"); @@ -384,14 +362,6 @@ mod on_device { clear, draws, ); - if !reads { - assert!( - refused(&drew), - "{name}: a device without the attachment reads: {drew:?}" - ); - println!("fetch-array: {name}: no attachment reads; the fetching draw refused"); - return; - } drew.unwrap_or_else(|error| { panic!("{name}: one slice, layered, {draws} draws: {error}") }); @@ -491,8 +461,7 @@ mod on_device { /// buffer at its pitch, through the feedback loop where its linear image took the feedback /// usage, else through its shadow, counted as on a texture of its own image. The `RGBA32Uint` /// target is `SIDE` a side, its rows the texels rounded up to the device's linear alignment - /// answer; each device prints whether it lies in place and its form. A device without the - /// attachment reads refuses the first draw, `Gap::Draw { FetchedAttachment }`. + /// answer; each device prints whether it lies in place and its form. #[test] fn every_device_fetches_a_target_over_a_buffer_in_place() { const AT: u64 = 65_536; @@ -506,7 +475,6 @@ mod on_device { each_device("fetch_over", |name, _, device| { (device.grant_indices(IndexClass::Texture, 4096, DRAWS.len() as u32)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let state = state(name, &device, &d); let queue = device.new_command_queue(4).expect("a queue"); let clear = ClearColor { @@ -540,21 +508,6 @@ mod on_device { (looped, in_place) = (color.looped(), color.copied_over().is_none()); let (drew, counted) = pass_of((name, &device, &queue), &state, &color, clear, draws); - if !reads { - assert_eq!( - format!("{drew:?}"), - format!( - "{:?}", - Err::<(), _>(Error::Unsupported(Gap::Draw { - kind: DrawKind::FetchedAttachment - })) - ), - "{name}: a device without the attachment reads" - ); - drop((color, buffer)); - (device.release_block(block)).unwrap_or_else(|error| panic!("{name}: {error}")); - continue; - } drew.unwrap_or_else(|error| panic!("{name}: {draws} draws: {error}")); let contents = buffer.contents().expect("a Shared buffer"); // SAFETY: the buffer is alive, `rows` bytes long, and no GPU work uses it. @@ -572,10 +525,6 @@ mod on_device { drop((color, buffer)); (device.release_block(block)).unwrap_or_else(|error| panic!("{name}: {error}")); } - if !reads { - println!("fetch-over: {name}: no attachment reads; the fetching draw refused"); - return; - } let draws = DRAWS[1]; let (want, loop_reads) = more(looped, draws, 16); assert_eq!( @@ -625,7 +574,6 @@ mod on_device { let first = IndexClass::Texture.range().start; let _grant = (device.grant_indices(IndexClass::Texture, first, 1)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let state = state(name, &device, &d); let queue = device.new_command_queue(4).expect("a queue"); let clear = ClearColor { @@ -666,7 +614,7 @@ mod on_device { // the loop; in the copy form the plane is a texture over a buffer. let in_place = export.form == SurfaceForm::InPlace; let looped = plane.looped(); - let readable = reads && plane.attachment_reads(); + let readable = plane.attachment_reads(); println!( "fetch-surface: {label}: form {:?}, pitch {}, the feedback usage in place \ {}, read through {}", @@ -756,8 +704,8 @@ mod on_device { /// over N draws, exact, through the feedback loop where the device's image format query /// offers the sampled and feedback usages beside the colour usage (printed), its home the /// attachment layout, else through the image's shadow, counted as on a shader-read target. A - /// device without the attachment reads, or whose query offers no such image, refuses the - /// first draw, `Gap::Draw { FetchedAttachment }`. + /// device whose query offers no such image refuses the first draw, + /// `Gap::Draw { FetchedAttachment }`. #[test] fn every_device_fetches_a_target_made_for_rendering_alone() { use ash::vk; @@ -771,7 +719,6 @@ mod on_device { each_device("fetch_render_target", |name, _, device| { (device.grant_indices(IndexClass::Texture, 4096, DRAWS.len() as u32)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let feedback = device.core().feedback_loop; // The feedback usage is the loop's extension's, so only a device with the loop is // asked it (`VUID-VkPhysicalDeviceImageFormatInfo2-usage-parameter`); the answer is @@ -790,7 +737,7 @@ mod on_device { .usage(usage); let offered = device.core().image_format_properties(&info).is_some(); println!( - "fetch-render-target: {name}: attachment reads {reads}, feedback loop {feedback}; \ + "fetch-render-target: {name}: feedback loop {feedback}; \ R32G32B32A32_UINT optimal 2D with transfer, sampled and colour usage{}: {}", if feedback { " and the feedback usage" @@ -822,8 +769,8 @@ mod on_device { .unwrap_or_else(|error| panic!("{name}: {error}")); assert_eq!(color.gpu_resource_id().index, index, "{name}: its index"); looped = color.looped(); - let readable = reads && color.attachment_reads(); - if reads && feedback && offered { + let readable = color.attachment_reads(); + if feedback && offered { assert!(looped, "{name}: the image takes the feedback usage"); } let (drew, counted) = @@ -886,8 +833,8 @@ mod on_device { /// target is: `exf_fetch_count` over N draws, exact, through the feedback loop where the /// device's image format query offers the feedback usage beside the storage, sampled and /// colour usages (printed), else through the image's shadow, counted as on a shader-read - /// target. A device without the attachment reads, or whose query offers no such image, - /// refuses the first draw, `Gap::Draw { FetchedAttachment }`. + /// target. A device whose query offers no such image refuses the first draw, + /// `Gap::Draw { FetchedAttachment }`. #[test] fn every_device_fetches_a_target_made_for_shader_writes() { use ash::vk; @@ -911,7 +858,6 @@ mod on_device { let count = (usages.len() * DRAWS.len()) as u32; (device.grant_indices(IndexClass::Texture, 4096, count)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let feedback = device.core().feedback_loop; // The feedback usage is the loop's extension's, so only a device with the loop is // asked it (`VUID-VkPhysicalDeviceImageFormatInfo2-usage-parameter`); the answer is @@ -931,7 +877,7 @@ mod on_device { .usage(usage); let offered = device.core().image_format_properties(&info).is_some(); println!( - "fetch-storage: {name}: attachment reads {reads}, feedback loop {feedback}; \ + "fetch-storage: {name}: feedback loop {feedback}; \ R32G32B32A32_UINT optimal 2D with transfer, sampled, storage and colour usage{}: \ {}", if feedback { @@ -972,8 +918,8 @@ mod on_device { "{label}: the image has a storage view, its home general" ); looped = color.looped(); - readable = reads && color.attachment_reads(); - if reads && feedback && offered { + readable = color.attachment_reads(); + if feedback && offered { // Through the loop where the query offers the feedback usage beside the // storage usage (an unknown usage's image also lists its view formats). assert!(looped, "{label}: the image takes the feedback usage"); @@ -1052,8 +998,7 @@ mod on_device { /// draw covers the target: each texel below the diagonal reads alpha 204/255, each above it /// 51/255, one on it either, and red, green and blue 0. A device that holds the format's alpha /// in red (no `A8_UNORM` image) reads the attachment through the texture's element, whose view - /// presents Metal's channels; the line names how the device holds the format. A device - /// without the attachment reads refuses the fetching draw, `Gap::Draw { FetchedAttachment }`. + /// presents Metal's channels; the line names how the device holds the format. #[test] fn every_device_fetches_an_a8unorm_attachment_as_metals_alpha() { use crate::ColorAttachmentDescriptor; @@ -1080,7 +1025,6 @@ mod on_device { each_device("fetch_a8", |name, _, device| { (device.grant_indices(IndexClass::Texture, 4096, 1)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let usage = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ; let held = formats::vk_format( PixelFormat::A8Unorm, @@ -1120,20 +1064,6 @@ mod on_device { let drew = encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0); encoder.end_encoding(); run(name, &command_buffer); - if !reads { - assert_eq!( - format!("{drew:?}"), - format!( - "{:?}", - Err::<(), _>(Error::Unsupported(Gap::Draw { - kind: DrawKind::FetchedAttachment - })) - ), - "{name}: a device without the attachment reads" - ); - println!("fetch-a8: {name}: no attachment reads; the fetching draw refused"); - return; - } drew.unwrap_or_else(|error| panic!("{name}: the fetching draw: {error}")); let contents = out.contents().expect("a Shared buffer"); // SAFETY: the buffer is alive, `16 * texels` bytes long, and no GPU work uses it. diff --git a/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs b/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs index 5d0d0c52d..1e0e15e43 100644 --- a/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs +++ b/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs @@ -61,13 +61,8 @@ mod on_device { held.fragment = Some(function("rd_entry_fragment")); held.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm)); each_device("held_loop_reads", |name, _, device| { - let core = device.core(); - let (reads, looped) = (core.attachment_reads, core.feedback_loop); - println!("{name}: attachment reads {reads}, feedback loop {looped}"); - if !reads { - println!("{name}: SKIPPED: the device reads no attachment through a texture"); - return; - } + let looped = device.core().feedback_loop; + println!("{name}: feedback loop {looped}"); let _grants = [ (IndexClass::Texture, TEXTURE, 2), (IndexClass::Sampler, SAMPLER, 1), @@ -205,10 +200,6 @@ mod on_device { held.fragment = Some(function("rd_entry_fragment")); held.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm)); each_device("held_read_walks", |name, _, device| { - if !device.core().attachment_reads { - println!("{name}: SKIPPED: the device reads no attachment through a texture"); - return; - } let _grants = [ (IndexClass::Texture, TEXTURE, 1), (IndexClass::Sampler, SAMPLER, 1), diff --git a/crates/metal2vulkan-runtime/src/tests/over_reads.rs b/crates/metal2vulkan-runtime/src/tests/over_reads.rs index c10015fc3..151eb8171 100644 --- a/crates/metal2vulkan-runtime/src/tests/over_reads.rs +++ b/crates/metal2vulkan-runtime/src/tests/over_reads.rs @@ -16,9 +16,9 @@ mod on_device { use crate::tests::draw::on_device::{descriptor, examples, floats, run, state, Buffers, BLUE}; use crate::texture::TextureObject; use crate::{ - Buffer, DrawKind, Error, Gap, IndexClass, LoadAction, MemoryClass, PixelFormat, - PrimitiveType, RenderPassDescriptor, StorageMode, StoreAction, TextureDescriptor, - TextureType, TextureUsage, + Buffer, Error, IndexClass, LoadAction, MemoryClass, PixelFormat, PrimitiveType, + RenderPassDescriptor, StorageMode, StoreAction, TextureDescriptor, TextureType, + TextureUsage, }; /// The target's rows. @@ -44,14 +44,13 @@ mod on_device { /// pitch, the rest of the buffer the sentinel: a pass that clears it to black draws, reading /// the target at its own pixel and at the first texel, then blue over it, then, after a /// memory barrier, each pixel read plus green. Each texel is then blue plus green in the - /// buffer at its pitch, and every other byte of the buffer the sentinel. In place on a - /// device that reads attachments, both reading draws read it through the feedback loop + /// buffer at its pitch, and every other byte of the buffer the sentinel. In place, both + /// reading draws read it through the feedback loop /// (`Metrics::attachment_loop_reads` grows by 2, nothing copied) or through its shadow (the /// first draw clears the shadow, the one after the barrier copies the target into it: /// `Metrics::attachment_read_copies` grows by 1); a device without the loop takes the /// shadow. Where the device lays the target in a copy, the target reads as any texture of an - /// image of its own; a device without the attachment reads refuses the reading draw, - /// `Gap::Draw { AttachmentRead }`. Each device prints which. + /// image of its own. Each device prints which. #[test] fn every_device_reads_its_target_over_a_buffer_in_place_through_a_texture() { let Some(library) = examples() else { @@ -61,7 +60,7 @@ mod on_device { let own = descriptor(&library, "own_pixel_fragment", PixelFormat::RGBA8Unorm); let first = descriptor(&library, "first_texel_fragment", PixelFormat::RGBA8Unorm); each_device("over_reads", |name, _, device| { - let (reads, looped) = (device.core().attachment_reads, device.core().feedback_loop); + let looped = device.core().feedback_loop; (device.grant_indices(IndexClass::Texture, 4096, 2)) .unwrap_or_else(|error| panic!("{name}: {error}")); let answer = (device.minimum_linear_texture_alignment(PixelFormat::RGBA8Unorm)) @@ -129,26 +128,7 @@ mod on_device { draw(encoder.set_fragment_texture(Some(&color), 0)); draw(encoder.set_render_pipeline_state(&reading)); // The pass's first read of its target: the clear's black, and none added. - let moved = encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0); - if !reads { - assert_eq!( - format!("{moved:?}"), - format!( - "{:?}", - Err::<(), _>(Error::Unsupported(Gap::Draw { - kind: DrawKind::AttachmentRead - })) - ), - "{name} {case}: a device without the attachment reads" - ); - encoder.end_encoding(); - run(name, &command_buffer); - println!("over_reads: {name} {case}: no attachment reads; the draw refused"); - drop((color, command_buffer, buffer)); - (device.release_block(block)).unwrap_or_else(|error| panic!("{name}: {error}")); - continue; - } - draw(moved); + draw(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); // Blue over every pixel, then the barrier, then each pixel read plus green. draw(encoder.set_render_pipeline_state(&plain)); draw(encoder.draw_primitives(PrimitiveType::Triangle, 3, 3, 1, 0)); diff --git a/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs b/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs index 2e130a17f..2858831e3 100644 --- a/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs +++ b/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs @@ -1094,22 +1094,14 @@ declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) /// every texel then holds the clear's complement. Then a pass that loads it draws the pattern /// over it and, after a memory barrier, samples it the same way: every texel then holds the /// pattern's complement. After each pass the target is copied out and sampled by a kernel, - /// every texel compared. A device without attachment reads, which refuses such a draw typed, - /// says so and runs none. + /// every texel compared. #[test] fn every_device_samples_its_attachment_in_its_own_pass_at_icon_size_every_texel() { let Some(libraries) = libraries() else { return; }; each_device("real_size_attachment_loops", |name, _, device| { - let (reads, looped) = { - let core = device.core(); - (core.attachment_reads, core.feedback_loop) - }; - if !reads { - println!("real-size: {name}: no attachment reads; the loop cells not run"); - return; - } + let looped = device.core().feedback_loop; let reading = Reading::new(name, &device, &libraries); let own = &libraries.1; let first = IndexClass::Texture.range().start; diff --git a/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs b/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs index a4027e806..7e4f6edc7 100644 --- a/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs +++ b/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs @@ -1303,21 +1303,13 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a /// centre and writes the complement of what it read (attachment 1's red and green twice). /// After each pass attachment 0's texture is copied out, attachment 0 sampled, and the /// 256x256 texture downloaded into a Private buffer and read out of it, every texel compared. - /// A device without attachment reads, which refuses such a draw typed, says so and runs none. #[test] fn every_device_samples_both_targets_of_a_two_target_pass_in_it_every_texel() { let Some((packed, floats, own)) = libraries() else { return; }; each_device("real_size_two_target_loops", |name, _, device| { - let (reads, looped) = { - let core = device.core(); - (core.attachment_reads, core.feedback_loop) - }; - if !reads { - println!("real-size: {name}: no attachment reads; the two-target cells not run"); - return; - } + let looped = device.core().feedback_loop; let readers = Readers::new(name, &device, &packed); let sample = kernel(name, &device, &floats, "float_sample"); let first = IndexClass::Texture.range().start; @@ -1792,22 +1784,14 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a /// after a memory barrier samples the view, its own attachment, at each pixel's centre over /// the whole of it, writing the complement of what it read: every texel then holds the /// pattern's complement inside the rectangle and the pattern outside. Copied out by a blit - /// and sampled through the view, every texel compared. A device without attachment reads, - /// which refuses such a draw typed, says so and runs none. + /// and sampled through the view, every texel compared. #[test] fn every_device_samples_a_screen_through_its_view_in_its_own_pass_every_texel() { let Some((packed, _, own)) = libraries() else { return; }; each_device("real_size_screens", |name, _, device| { - let (reads, looped) = { - let core = device.core(); - (core.attachment_reads, core.feedback_loop) - }; - if !reads { - println!("real-size: {name}: no attachment reads; the screen cells not run"); - return; - } + let looped = device.core().feedback_loop; let readers = Readers::new(name, &device, &packed); let first = IndexClass::Texture.range().start; let count = 2 * SCREENS.len() as u32; diff --git a/crates/metal2vulkan-runtime/src/tests/visibility.rs b/crates/metal2vulkan-runtime/src/tests/visibility.rs index a80fa5347..24cceef12 100644 --- a/crates/metal2vulkan-runtime/src/tests/visibility.rs +++ b/crates/metal2vulkan-runtime/src/tests/visibility.rs @@ -485,8 +485,7 @@ mod on_device { /// While a mode's query counts the draws, a draw that reads its pass's attachment through a /// texture, which ends the rendering first (a move to the feedback layout, or a copy into the /// attachment's shadow), is refused and counted; after the next mode set it draws, ending the - /// rendering before its query begins. A device without the attachment reads refuses the read - /// as `DrawKind::AttachmentRead` in either place. + /// rendering before its query begins. #[test] fn every_device_refuses_an_attachment_read_while_a_mode_counts() { let Some(library) = examples() else { @@ -497,7 +496,6 @@ mod on_device { each_device("visibility_attachment_read", |name, _, device| { (device.grant_indices(IndexClass::Texture, 4096, 1)) .unwrap_or_else(|error| panic!("{name}: {error}")); - let reads = device.core().attachment_reads; let plain = state(name, &device, &plain); let own = state(name, &device, &own); let mut buffers = Buffers::new(&device); @@ -524,24 +522,18 @@ mod on_device { let read = |e: &mut RenderCommandEncoder| { text(e.draw_primitives(PrimitiveType::Triangle, WHOLE, 3, 1, 0)) }; - let want = match reads { - true => gap(DrawKind::VisibilityResultInterrupt), - false => gap(DrawKind::AttachmentRead), - }; + let want = gap(DrawKind::VisibilityResultInterrupt); assert_eq!(read(&mut e), want, "{name}: a read while the query counts"); ok(e.set_visibility_result_mode(counting, 8)); - let want = match reads { - true => text(Ok(())), - false => gap(DrawKind::AttachmentRead), - }; - assert_eq!(read(&mut e), want, "{name}: a read before the query begins"); + assert_eq!( + read(&mut e), + text(Ok(())), + "{name}: a read before the query begins" + ); e.end_encoding(); run(name, &command_buffer); let refusals = counters.metrics().visibility_interrupts_refused - before; - let (count, words_want) = match reads { - true => (1, [64, 64]), - false => (0, [64, 0]), - }; + let (count, words_want) = (1, [64, 64]); assert_eq!(refusals, count, "{name}: the refusals counted"); assert_eq!(words(&visibility, 2), words_want, "{name}: the words"); println!("{name}: an attachment read refused while a mode counted, run before one"); diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index b8e37cd21..5c14284b4 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -2618,14 +2618,13 @@ impl Plan { /// Whether a draw may read an attachment of its own pass through a texture of the plan, where /// its image takes the feedback usage or a shadow: a colour render target, read by shaders or - /// not, with a storage view or not, on a device that reads attachments, as Metal reads any - /// render target. Vulkan's feedback layout asks the attachment and sampled usages beside the - /// feedback usage (`VUID-VkImageMemoryBarrier2-srcQueueFamilyIndex-07006`) and bars none, the - /// storage usage included; in it the image is only rendered and sampled. A target not read - /// takes the sampled usage for the reads alone (`plan`). - fn reads_attachments(&self, core: &Core) -> bool { - core.attachment_reads - && self.sampled.is_some() + /// not, with a storage view or not, as Metal reads any render target. Vulkan's feedback layout + /// asks the attachment and sampled usages beside the feedback usage + /// (`VUID-VkImageMemoryBarrier2-srcQueueFamilyIndex-07006`) and bars none, the storage usage + /// included; in it the image is only rendered and sampled. A target not read takes the sampled + /// usage for the reads alone (`plan`). + fn reads_attachments(&self) -> bool { + self.sampled.is_some() && self.usage.contains(vk::ImageUsageFlags::COLOR_ATTACHMENT) && self.aspects == vk::ImageAspectFlags::COLOR } @@ -3398,10 +3397,10 @@ fn planned( false => vk::ImageCreateFlags::empty(), }; // A draw may read an attachment of its own pass through such a texture - // (`crate::render_encoder`), where the device reads attachments: in the feedback layout where - // it has the attachment feedback loop, else through a copy into the image's shadow. The image - // takes the sampled usage for it where shaders do not read the texture. - let mut attachment_reads = plan.reads_attachments(core); + // (`crate::render_encoder`): in the feedback layout where the device has the attachment + // feedback loop, else through a copy into the image's shadow. The image takes the sampled + // usage for it where shaders do not read the texture. + let mut attachment_reads = plan.reads_attachments(); let looped = attachment_reads && core.feedback_loop; let mut image_usage = plan.usage; if attachment_reads { @@ -8076,7 +8075,7 @@ impl Device { Ok(crate::surface::PlanePlan { format: plan.format, usage: plan.linear_usage(), - looped: plan.reads_attachments(self.core()) && self.core().feedback_loop, + looped: plan.reads_attachments() && self.core().feedback_loop, view_formats: plan.view_formats.clone(), texel, }) @@ -8157,15 +8156,13 @@ impl Device { let looped = made .usage .contains(vk::ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT); - let shadowing = (!looped - && plan.reads_attachments(core) - && plan.shadow_offered(core, &shape)) - .then(|| { - Box::new(Shadowing { - made: (d, shape, plan.shadow()), - shadow: Mutex::new(None), - }) - }); + let shadowing = (!looped && plan.reads_attachments() && plan.shadow_offered(core, &shape)) + .then(|| { + Box::new(Shadowing { + made: (d, shape, plan.shadow()), + shadow: Mutex::new(None), + }) + }); let image = Arc::new(Image { core: Arc::clone(core), image: made.image,