diff --git a/crates/metal2vulkan-runtime/src/d3d11.rs b/crates/metal2vulkan-runtime/src/d3d11.rs index 0e9c9c7d2..7e47079c9 100644 --- a/crates/metal2vulkan-runtime/src/d3d11.rs +++ b/crates/metal2vulkan-runtime/src/d3d11.rs @@ -16,7 +16,7 @@ use crate::hazard::HeapId; use crate::import::ImportHandle; use crate::memory; use crate::surface::{Surface, MAX_PLANES}; -use crate::texture::{size_within, Backing, SurfaceImage, Texture, TextureDescriptor}; +use crate::texture::{plane_within, Backing, SurfaceImage, Texture, TextureDescriptor}; use crate::PixelFormat; use ash::vk; use metal2vulkan::metal::format as formats; @@ -120,7 +120,10 @@ impl Device { /// consumer reported no Direct3D 11 access of it before /// ([`Surface::external_writes_done`]), and the general layout where it did; every later /// acquire names the general layout, the plane being general after rt's own first acquire - /// and release. "First" is the first acquire rt records for the plane. + /// and release. "First" is the first acquire rt records for the plane. The Khronos validation + /// layer does not track this import's layout: on the UHD 630 its 1.4.363.0 reported neither + /// a first acquire from the general layout nor one from the undefined layout, so its silence + /// is no evidence of either. /// /// **Ownership.** Each `vkQueueSubmit2` whose command buffers or uploads use a plane acquires /// it from `VK_QUEUE_FAMILY_EXTERNAL` in a command buffer of rt's own ahead of everything in @@ -315,7 +318,7 @@ impl Device { // external memory handle type). let (_, made) = (import_query(core, format, usage, &list)) .map_err(|_| Error::Limit(Limit::NoImport { handle }))?; - size_within([d.width, d.height, 1], 1, &made)?; + plane_within(d, &made)?; Ok((usage, list)) } diff --git a/crates/metal2vulkan-runtime/src/tests/d3d11.rs b/crates/metal2vulkan-runtime/src/tests/d3d11.rs index b277e2e1f..d1cc51466 100644 --- a/crates/metal2vulkan-runtime/src/tests/d3d11.rs +++ b/crates/metal2vulkan-runtime/src/tests/d3d11.rs @@ -716,7 +716,10 @@ mod on_device { /// that read is picture 3's exactly. On a surface Direct3D 11 draws first, reported by /// `external_writes_done`, every acquire names the general layout, the first included, /// and rt reads picture 1 exactly. The acquires are read from the record the hand-over - /// keeps for the device tests (`Work::acquired`). + /// keeps for the device tests (`Work::acquired`). The Khronos validation layer does not + /// track this import's layout, so it is no check here: on the UHD 630 its 1.4.363.0 + /// reported neither the old form's first acquire from the general layout (job + /// m3-max-76170) nor this form's from the undefined layout (job m3-max-76174). #[test] fn every_device_acquires_a_direct3d_11_plane_from_undefined_only_before_any_access() { each_device("import_d3d11_surface_first_use", |name, _, device| { diff --git a/crates/metal2vulkan-runtime/src/tests/texture.rs b/crates/metal2vulkan-runtime/src/tests/texture.rs index 3da5b978b..7bc758970 100644 --- a/crates/metal2vulkan-runtime/src/tests/texture.rs +++ b/crates/metal2vulkan-runtime/src/tests/texture.rs @@ -37,8 +37,8 @@ //! device. use crate::arrays::Grants; -use crate::error::{Error, Refusal}; -use crate::texture::{combined, components, linear_rounding, shape}; +use crate::error::{Error, Limit, Refusal}; +use crate::texture::{combined, components, linear_rounding, plane_within, shape}; use crate::{IndexClass, PixelFormat, TextureDescriptor, TextureType}; use ash::vk; use metal2vulkan::metal::{TextureSwizzle, TextureSwizzleChannels}; @@ -267,6 +267,45 @@ fn a_views_components_are_the_swizzle_over_the_formats_mapping() { ); } +/// A surface plane is checked against what the image format query answers of its image with its +/// import's handle type (a Direct3D 11 plane's, `d3d11_plane_form`), which can be less than the +/// query without the handle answers: a plane 64 wide where the import answers 63 is +/// `Limit::TextureSize` carrying the import's extent, as is one 32 high where it answers 31; one +/// the import answers exactly passes. The check is the import's answer alone: no card in the lab +/// answers less with the handle than without it. +#[test] +fn a_plane_past_its_import_s_max_extent_is_texture_size() { + let plane = TextureDescriptor::new(TextureType::Type2D, PixelFormat::R8Unorm, 64, 32); + let answer = |width: u32, height: u32| vk::ImageFormatProperties { + max_extent: vk::Extent3D { + width, + height, + depth: 1, + }, + max_array_layers: 2048, + ..vk::ImageFormatProperties::default() + }; + for (max, case) in [([63, 16384], "narrower"), ([16384, 31], "shorter")] { + let refused = plane_within(&plane, &answer(max[0], max[1])).err(); + assert!( + matches!( + refused, + Some(Error::Limit(Limit::TextureSize { + extent: [64, 32, 1], + layers: 1, + max_extent, + max_layers: 2048, + })) if max_extent == [max[0], max[1], 1] + ), + "an import answer {case} than the plane: {refused:?}" + ); + } + assert!( + plane_within(&plane, &answer(64, 32)).is_ok(), + "an import answer of the plane's own extent" + ); +} + #[test] fn a_views_swizzle_reads_its_parents_swizzled_channels() { use TextureSwizzle::{Alpha, Blue, Green, One, Red, Zero}; diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 09bda00b4..f2f909ee3 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -2417,6 +2417,20 @@ pub(crate) fn size_within( Ok(()) } +/// Whether a surface plane of `d`, one 2D layer, is within what the image format query answered +/// of its image with its import's handle type (`import`): a Direct3D 11 plane's +/// (`Device::import_d3d11_surface`, on Windows), whose import can make a smaller image than the +/// query without the handle answers (`VUID-VkImageCreateInfo-extent-02252`). +/// +/// Err: [`Limit::TextureSize`] carrying the import's `maxExtent` where the plane is past it. +#[cfg(any(windows, test))] +pub(crate) fn plane_within( + d: &TextureDescriptor, + import: &vk::ImageFormatProperties, +) -> Result<(), Error> { + size_within([d.width, d.height, 1], 1, import) +} + /// The largest extent of a linear image of `plan`'s format and usage of `shape`'s type, where the /// device makes one; made for memory of the import `handle`, where the device makes one that such /// memory binds at any place: its external query (`VkPhysicalDeviceExternalImageFormatInfo`)