diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index a49f2f920..5df8896f7 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -512,7 +512,10 @@ degradations! { resolve texture after the pass through a staging buffer"; /// A pass resolves into a texture that cannot be an attachment (its usage lacks /// `RenderTarget`), or a layered pass into a texture whose slices from the resolve slice - /// hold fewer layers than the pass's. + /// hold fewer layers than the pass's, or a pass resolves color into a 3D texture's planes + /// past its first, or into more than one, on a device whose resolve into a 2D view of a + /// 3D image writes its first plane alone (`RuntimeDriverDefect::VolumeResolveFirstPlane`: + /// RADV). ResolveScratch = "resolve-scratch", Performance, "the pass resolves into a scratch image, whose render area is copied into the \ texture after the pass"; @@ -4495,6 +4498,10 @@ impl Device { "a layered pass of {} layers resolves into {} slices of it, the layers that fit", scratch.layers, texture.layers ) + } else if super::resolve::is_volume(texture) && super::resolve::first_plane_only(self) { + "the device's resolve into a 2D view of a 3D image writes its first depth plane, \ + whatever plane the view begins at (RuntimeDriverDefect::VolumeResolveFirstPlane)" + .to_owned() } else { "its image cannot be an attachment: the texture's usage lacks `RenderTarget`" .to_owned() diff --git a/crates/metal2vulkan-runtime/src/driver_defects.rs b/crates/metal2vulkan-runtime/src/driver_defects.rs index d18636e1d..94d30e2a6 100644 --- a/crates/metal2vulkan-runtime/src/driver_defects.rs +++ b/crates/metal2vulkan-runtime/src/driver_defects.rs @@ -100,6 +100,20 @@ pub(super) struct Affected { /// known broken through 26.2.4. Nothing is refused but a memoryless attachment at another /// layer (`resolve.rs`). /// +/// `VolumeResolveFirstPlane`: +/// - Mesa's RADV (`MESA_RADV`): a render pass's color resolve into a 2D view of a 3D image +/// (made `VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT`) whose first layer is depth plane 3 of a +/// 4x4x4 `R8G8B8A8_UNORM` volume wrote plane 0, the volume's first byte holding the resolve, +/// three runs alike at each of two commits, on the Radeon 780M (Phoenix, `deviceID` 0x15bf), +/// where a draw into the same kind of view writes its plane and the validation layer reports +/// nothing (`runtime_lane::view_attachments::a_resolve_writes_the_volume_plane_it_names`). +/// Valid usage: such a view "can be used as a framebuffer attachment that refers only to the +/// specified range of slices" (`VkImageSubresourceRange`), and of a resolve attachment Vulkan +/// refuses only a 3D view (`VUID-VkRenderingAttachmentInfo-resolveImageView-12471`). Nothing is +/// refused: a color resolve into a 3D texture's planes past its first, or into more than one, +/// goes into a scratch image of the pass's layers, copied into the planes after the pass +/// (`resolve.rs`). Every RADV GPU takes the copy until a probe finds it clean. +/// /// `PipelineCacheDataCompiledAtLoad`: /// - MoltenVK (`MOLTENVK`): `vkCreatePipelineCache` with initial data reads each shader module's /// converted MSL back (`MVKPipelineCache::readData`) through @@ -560,6 +574,11 @@ pub(super) const AFFECTED: &[Affected] = &[ driver: DriverId::MESA_LLVMPIPE, clean: &[], }, + Affected { + defect: RuntimeDriverDefect::VolumeResolveFirstPlane, + driver: DriverId::MESA_RADV, + clean: &[], + }, Affected { defect: RuntimeDriverDefect::LazilyAllocatedVolumePlaneViews, driver: DriverId::MOLTENVK, diff --git a/crates/metal2vulkan-runtime/src/resolve.rs b/crates/metal2vulkan-runtime/src/resolve.rs index 9803542fa..dafbf0d3b 100644 --- a/crates/metal2vulkan-runtime/src/resolve.rs +++ b/crates/metal2vulkan-runtime/src/resolve.rs @@ -197,6 +197,13 @@ //! ([`ResolveSource`]), which an instance of no draws, and each resolve after the pass, resolves //! from in its place. A memoryless attachment there, which takes no copy, is not built //! (`NotImplemented(DepthStencilResolve)`). +//! - **A render pass that resolves color into a 3D image's first plane alone** (RADV, +//! `RuntimeDriverDefect::VolumeResolveFirstPlane`): its color resolve into a 2D view of a 3D +//! image writes the image's first depth plane, whatever plane the view begins at. There a +//! resolve into a 3D texture's planes past its first, or into more than one, takes the scratch +//! image, whose layers are copied into the planes after the pass (the copy's depth from the +//! resolve's first plane); a level of the texture reaching past the attachment, whose clear +//! there would be of the planes alone, is not built (`NotImplemented(Render)`). //! - The multisampled attachment of `MultisampleResolve` is stored `DONT_CARE`: Metal leaves its //! texels undefined (the recorded near-equivalent of a `DontCare` store). //! @@ -1162,7 +1169,9 @@ impl Destination { /// `needed` usage, else a scratch image whose render area is copied there after the pass. A /// render pass's depth/stencil resolve (`depth_stencil`) on a device that writes its resolve /// attachment image's first layer and level alone ([`first_subresource_only`]) takes the - /// scratch image where the destination begins at another. + /// scratch image where the destination begins at another, and a color resolve on a device + /// that writes a 3D image's first plane alone ([`first_plane_only`]) where the destination is + /// a 3D texture's planes past its first, or more than one. fn attach( self, maker: &CommandBuffer, @@ -1177,6 +1186,13 @@ impl Destination { // resolved into through a scratch image too, whose overlap with it is copied. let misplaced = depth_stencil && first_subresource_only(device) && !at_first_subresource(&self.target); + // Nor does a color resolve into a 3D texture's planes past its first, or into more than + // one, on a device that writes the image's first plane whatever plane the view begins at + // ([`first_plane_only`]): the scratch image's layers are copied into the planes. + let off_plane = !depth_stencil + && first_plane_only(device) + && is_volume(&self.target) + && (self.target.layer != 0 || self.target.layers != 1); // Nor is a linear image the device renders only where every color attachment is linear // (`linear_attachment.rs`): the pass's are multisampled, never linear. let bound = !depth_stencil && linear_attachment::bound(device, &self.target)?; @@ -1196,6 +1212,7 @@ impl Destination { && self.target.layers == source.layers && self.target.extent == source.extent && !misplaced + && !off_plane && !bound { return Ok(Resolve { @@ -1206,11 +1223,14 @@ impl Destination { clear: None, }); } - // The scratch's copy into a 3D texture's planes, or into a 1D texture, is not built - // (`render_pass::not_2d`). - if !self.usage.contains(ImageUsageFlags::TRANSFER_DST) - || super::render_pass::not_2d(&self.target) - { + // The scratch's copy into a 1D texture is not built, nor into a 3D texture's planes where + // the level reaches past the attachment, whose clear there would be of the plane alone + // (`ResolveCopies`). + let past = + self.target.extent[0] > source.extent[0] || self.target.extent[1] > source.extent[1]; + let copied_into = + !super::render_pass::not_2d(&self.target) || (is_volume(&self.target) && !past); + if !self.usage.contains(ImageUsageFlags::TRANSFER_DST) || !copied_into { return Err(Error::NotImplemented(RuntimeGap::Render)); } // A twin resolve writes the resolve texture's format, so its scratch image is of that @@ -1560,6 +1580,21 @@ fn at_first_subresource(target: &Target) -> bool { target.layer == 0 && target.level == 0 } +/// Whether `device`'s render pass resolves a color attachment into a 2D view of a 3D image's +/// planes by writing the image's first plane, whatever plane the view begins at +/// (`RuntimeDriverDefect::VolumeResolveFirstPlane`). +pub(super) fn first_plane_only(device: &Device) -> bool { + device + .properties() + .driver_defects + .contains(&RuntimeDriverDefect::VolumeResolveFirstPlane) +} + +/// Whether `target` is planes of a 3D texture's image: its layers are the image's depth planes. +pub(super) fn is_volume(target: &Target) -> bool { + (target.texture.image_plan()).is_ok_and(|plan| plan.image_type == ImageType::TYPE_3D) +} + /// The copy a pass's depth/stencil resolves read on a device whose render pass resolves from the /// attachment image's first layer and level ([`first_subresource_only`]), where the pass's /// depth/stencil attachment begins at another: the pass's layers of the attachment, every aspect @@ -1762,15 +1797,35 @@ impl ResolveCopies { clears.push((to.texture.raw_image()?, bits, range)); } if aspect == image_aspects(from.format) { + // Into a 3D texture's planes, the scratch image's layers are the region's depth + // from the first plane (`VUID-VkCopyImageInfo2-srcImage-01791`): the image has + // one layer. + let (dst_subresource, dst_offset, depth) = match is_volume(to) { + true => ( + vk::ImageSubresourceLayers { + aspect_mask: aspect.into(), + mip_level: to.level, + base_array_layer: 0, + layer_count: 1, + }, + vk::Offset3D { + z: i32::try_from(to.layer) + .map_err(|_| internal("a depth plane past i32"))?, + ..vk::Offset3D::default() + }, + count, + ), + false => (layers(to, aspect, count), vk::Offset3D::default(), 1), + }; let region = vk::ImageCopy { src_subresource: layers(from, aspect, count), src_offset: vk::Offset3D::default(), - dst_subresource: layers(to, aspect, count), - dst_offset: vk::Offset3D::default(), + dst_subresource, + dst_offset, extent: vk::Extent3D { width, height, - depth: 1, + depth, }, }; copies.push((from.texture.raw_image()?, to.texture.raw_image()?, region)); diff --git a/crates/metal2vulkan-runtime/src/tests/driver_defects.rs b/crates/metal2vulkan-runtime/src/tests/driver_defects.rs index f78e34bc6..bebddda4d 100644 --- a/crates/metal2vulkan-runtime/src/tests/driver_defects.rs +++ b/crates/metal2vulkan-runtime/src/tests/driver_defects.rs @@ -34,6 +34,7 @@ const TEN_BIT_WORDS: RuntimeDriverDefect = RuntimeDriverDefect::TenBitCodesReadA const UNPINNABLE: RuntimeDriverDefect = RuntimeDriverDefect::UnpinnablePagesBreakHostMemory; const VOLUME_BLITS: RuntimeDriverDefect = RuntimeDriverDefect::VolumeBlitsUnfiltered; const ALIASED_BLITS: RuntimeDriverDefect = RuntimeDriverDefect::AliasedImportBlitsUnordered; +const VOLUME_RESOLVES: RuntimeDriverDefect = RuntimeDriverDefect::VolumeResolveFirstPlane; /// Every committed profile's driver has its defects at every release and GPU but those a probe /// found clean: MoltenVK the multisampled depth/stencil colour copies, the inexact depths past @@ -51,7 +52,8 @@ const ALIASED_BLITS: RuntimeDriverDefect = RuntimeDriverDefect::AliasedImportBli /// rows past its height, the baked samplers lost after a copy and the 10-bit codes its Y′CbCr /// conversion reads as words; /// RADV the multisampled copies that convert float NaNs, the 10-bit codes its Y′CbCr conversion -/// reads as words, and the implicit +/// reads as words, the color resolve into a 3D image's first plane whatever plane its view begins +/// at, and the implicit /// preprocessing after an execution set on every GPU but the 780M (Phoenix's and Hawk Point's), /// measured clean; ANV /// the compressed image's short size, the occlusion count per color output, the pushed @@ -99,9 +101,11 @@ fn the_committed_profiles_drivers_have_their_defects() { } // The 780M, under Phoenix's `deviceID` and Hawk Point's. Some(DriverId::MESA_RADV) if matches!(desc.device_id, 0x15bf | 0x1900) => { - vec![NAN_COPIES, TEN_BIT_WORDS] + vec![NAN_COPIES, TEN_BIT_WORDS, VOLUME_RESOLVES] + } + Some(DriverId::MESA_RADV) => { + vec![NAN_COPIES, PREPROCESS, TEN_BIT_WORDS, VOLUME_RESOLVES] } - Some(DriverId::MESA_RADV) => vec![NAN_COPIES, PREPROCESS, TEN_BIT_WORDS], Some(DriverId::INTEL_OPEN_SOURCE_MESA) => { vec![COMPRESSION, COUNTS, STALE_PUSHES, ALIASED_BLITS] } @@ -211,12 +215,12 @@ fn hawk_points_780m_is_phoenixs_gpu() { assert_eq!(properties.driver_defects, measured.driver_defects); assert_eq!( of(&hawk_point).into_iter().collect::>(), - [NAN_COPIES, TEN_BIT_WORDS] + [NAN_COPIES, TEN_BIT_WORDS, VOLUME_RESOLVES] ); hawk_point.driver_version += 1; assert_eq!( of(&hawk_point).into_iter().collect::>(), - [NAN_COPIES, TEN_BIT_WORDS] + [NAN_COPIES, TEN_BIT_WORDS, VOLUME_RESOLVES] ); let mut neighbour = phoenix; neighbour.device_id = 0x1901; diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 17921fe43..ed604e110 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -1086,6 +1086,12 @@ pub enum RuntimeDriverDefect { /// (`metal2vulkan_runtime::Device::use_host_ram`), it binds it in the chunk's import, which /// the object then waits for, so that every object over a chunk's pages lies in one import. AliasedImportBlitsUnordered, + /// A render pass's color resolve into a 2D view of a 3D image (made + /// `VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT`, the view's layers depth planes of it) writes the + /// image's first depth plane, whatever plane the view begins at. Nothing is refused: the + /// runtime resolves into a scratch image of the pass's layers, copied into the planes the + /// resolve belongs in after the pass. + VolumeResolveFirstPlane, } /// One device capability a refusal can name. diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index c29d0e4cb..1d92ddad0 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -13998,6 +13998,7 @@ variant metal2vulkan::error::RuntimeDriverDefect::TenBitCodesReadAsWords TenBitC variant metal2vulkan::error::RuntimeDriverDefect::TwoPlaneChromaMisplaced TwoPlaneChromaMisplaced variant metal2vulkan::error::RuntimeDriverDefect::UnpinnablePagesBreakHostMemory UnpinnablePagesBreakHostMemory variant metal2vulkan::error::RuntimeDriverDefect::VolumeBlitsUnfiltered VolumeBlitsUnfiltered +variant metal2vulkan::error::RuntimeDriverDefect::VolumeResolveFirstPlane VolumeResolveFirstPlane variant metal2vulkan::error::RuntimeDriverDefect::WaitForAnyObjectLosesASignal WaitForAnyObjectLosesASignal variant metal2vulkan::error::RuntimeInput::AlphaTest AlphaTest variant metal2vulkan::error::RuntimeInput::ColorWrites ColorWrites diff --git a/docs/API.md b/docs/API.md index e096efc8a..0af1e5e15 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1961,7 +1961,9 @@ bound. through a staging buffer. - `metal2vulkan-degrade-resolve-scratch` (performance). `ResolveScratch`: A pass resolves into a texture that cannot be an attachment (its usage lacks `RenderTarget`), or a layered pass into a - texture whose slices from the resolve slice hold fewer layers than the pass's. Cost: the pass + texture whose slices from the resolve slice hold fewer layers than the pass's, or a pass resolves + color into a 3D texture's planes past its first, or into more than one, on a device whose resolve + into a 2D view of a 3D image writes its first plane alone (RADV). Cost: the pass resolves into a scratch image, whose render area is copied into the texture after the pass. - `metal2vulkan-degrade-shader-resolve` (performance). `ShaderResolve`: A multisample color resolve drawn after the pass by the crate-owned resolve: of an extended-range attachment, whose codes no