From c669ef7246753a862b0e14028a0b008341d583c9 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 22 Nov 2026 07:43:16 -0800 Subject: [PATCH] rt: a Direct3D 11 plane's image lists every format its texture views as, where the import query takes the list What: import_d3d11_surface's plane image listed only its own format and the descriptor's (and none where they are equal), so a view in any other format Metal takes of the plane's texture (an R8Uint view of an R8Unorm plane with PixelFormatView usage) was Gap::TextureView of SurfacePixelFormat on every Windows device. The image now lists its own format, the descriptor's and the formats the descriptor's texture lists for views of another format, MUTABLE, kept where vkGetPhysicalDeviceImageFormatProperties2 answers that list importable with the image's usage; else the list it had, and such a view stays the typed gap. The usage is still decided with the old list, so a plane the import took before is made as before where the device refuses the longer list. texture.rs is unchanged. The import query is one function (d3d11::import_query) that the product and the new Windows test both call. Why: a consumer boot on the UHD 630 met 14 SurfacePixelFormat refusals of swizzled views changing a surface plane's pixel format. Tests: tests/d3d11.rs, every_device_views_a_direct3d_11_plane_in_another_format_where_its_import_lists_it (m2v_gpu, Windows): both planes with PixelFormatView usage take a swizzled view in another format of their class (R8Uint, RG8Uint) exactly where the import query takes the full list, else the typed gap, and it prints the query's answer with the full list and with each other format alone beside the image's own. tests/surface.rs, every_device_views_a_surface_plane_in_another_format_through_a_swizzle: an exported surface's R8Unorm luma with PixelFormatView usage takes a swizzled R8Uint view, through which rt's writes read back exactly through the plane. Docs: the import's doc comment, TextureViewKind::SurfacePixelFormat's doc (which counted no such view; it now covers both surface kinds), and the rt README's Direct3D 11 surfaces paragraph. REFUSALS.md regenerated: unchanged. No public item changed. Not claimed: the Direct3D 11 path has not run on a card. Whether a Windows driver's import query takes the longer list is unknown until the Windows test runs; the bug row stays open. --- crates/metal2vulkan-runtime/README.md | 14 +- crates/metal2vulkan-runtime/src/d3d11.rs | 124 ++++++++++----- crates/metal2vulkan-runtime/src/error.rs | 9 +- .../metal2vulkan-runtime/src/tests/d3d11.rs | 112 +++++++++++++- .../metal2vulkan-runtime/src/tests/surface.rs | 142 +++++++++++++++++- 5 files changed, 349 insertions(+), 52 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 34f0e2792..81a8256d2 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -875,11 +875,17 @@ On Windows, `Device::import_d3d11_surface(&[D3d11Plane])` takes a picture's plan made as Direct3D 11 textures, each by its NT handle (`IDXGIResource1::CreateSharedHandle`), its own format and the texture rt makes over it, and returns a `Surface` whose planes rt's shaders read and write in place. Each plane is an optimal image of the Direct3D 11 texture's format, of -the descriptor's width and height, mutable and listing the descriptor's format where the two -differ (a chroma plane of `R16Uint` under an `RG8Unorm` texture, the same bytes per texel in -Metal's same view class), on a dedicated import of its handle, counted in +the descriptor's width and height, on a dedicated import of its handle, counted in `Gauges::surface_imports`. Its usage is each of sampled, rendered, copied and storage that the -import offers and the descriptor's format holds. The consumer keeps and closes the handles. +import offers and the descriptor's format holds. The image is mutable where it lists more than +its own format. It lists its own format, the descriptor's (a chroma plane of `R16Uint` under an +`RG8Unorm` texture, the same bytes per texel in Metal's same view class) and the formats the +texture lists for views of another format (with `PixelFormatView` usage, those Metal views it as, +such as an `R8Uint` view of an `R8Unorm` plane), where the import query +(`vkGetPhysicalDeviceImageFormatProperties2`) takes that list with the image's usage. Where it +does not, the image lists its own format and the descriptor's where they differ, and a view of a +format it does not list is `Gap::TextureView` of `TextureViewKind::SurfacePixelFormat`. The +consumer keeps and closes the handles. The import submits nothing and waits for nothing. Vulkan 1.4's section 12.5.2 says "When images created with external memory handle types listed in the external image implied layouts table are diff --git a/crates/metal2vulkan-runtime/src/d3d11.rs b/crates/metal2vulkan-runtime/src/d3d11.rs index 2e1020579..997e871da 100644 --- a/crates/metal2vulkan-runtime/src/d3d11.rs +++ b/crates/metal2vulkan-runtime/src/d3d11.rs @@ -61,13 +61,23 @@ impl Device { /// made (a video decoder's, or a draw's), as a surface whose planes are textures rt's shaders /// read and write in place, as Metal reads an IOSurface's plane through a texture over it /// (`newTextureWithDescriptor:iosurface:plane:`). Each plane is its own texture and its own - /// handle: an optimal image of the plane's [`image_format`](D3d11Plane::image_format), - /// mutable, listing it and the descriptor's format, on a dedicated import of the handle - /// (`VkImportMemoryWin32HandleInfoKHR`, `VkMemoryDedicatedAllocateInfo`) into the first - /// device-local type that the handle's properties (`vkGetMemoryWin32HandlePropertiesKHR`) and - /// the image's requirements both list, else the first both list. The plane's texture is in the - /// descriptor's format, a view of the image's. Each import counts in - /// [`Gauges::surface_imports`](crate::Gauges::surface_imports) while its texture lives. + /// handle: an optimal image of the plane's [`image_format`](D3d11Plane::image_format), on a + /// dedicated import of the handle (`VkImportMemoryWin32HandleInfoKHR`, + /// `VkMemoryDedicatedAllocateInfo`) into the first device-local type that the handle's + /// properties (`vkGetMemoryWin32HandlePropertiesKHR`) and the image's requirements both list, + /// else the first both list. The plane's texture is in the descriptor's format, a view of the + /// image's. Each import counts in [`Gauges::surface_imports`](crate::Gauges::surface_imports) + /// while its texture lives. + /// + /// **Views of another format.** The image is mutable where it lists more than its own + /// format. It lists its own format, the descriptor's and those the descriptor's texture + /// lists for views of another format + /// ([`Texture::new_texture_view`](crate::Texture::new_texture_view): its sRGB sibling, and + /// with `PixelFormatView` usage the formats Metal views it as) where the import query + /// (`vkGetPhysicalDeviceImageFormatProperties2`) takes that list with the image's usage. + /// Where it does not, the image lists its own format and the descriptor's where they differ, + /// and a view of a format it does not list is [`Gap::TextureView`] of + /// [`TextureViewKind::SurfacePixelFormat`](crate::TextureViewKind::SurfacePixelFormat). /// /// **Layout.** The call makes no submission and waits for nothing: no move out of the /// undefined layout comes before a plane's first use. Vulkan 1.4, section 12.5.2 (Image @@ -170,10 +180,13 @@ impl Device { })); } let (format, view) = (image_plan.format, plan.format); - let list: Vec = match format == view { + // The image's own format and the descriptor's, where they differ: the list the usage is + // decided with. + let pair: Vec = match format == view { true => Vec::new(), false => vec![format, view], }; + let full = plane_list(format, view, &plan.view_formats); let (instance, physical) = (core.instance.vk(), core.physical); let mut view_features = vk::FormatProperties2::default(); // SAFETY: `physical` is `instance`'s. @@ -192,45 +205,23 @@ impl Device { }; held.contains(feature) }; - let imports = |usage: vk::ImageUsageFlags| { - let mut external = - vk::PhysicalDeviceExternalImageFormatInfo::default().handle_type(HANDLE); - let mut listed = vk::ImageFormatListCreateInfo::default().view_formats(&list); - let mut info = vk::PhysicalDeviceImageFormatInfo2::default() - .format(format) - .ty(vk::ImageType::TYPE_2D) - .tiling(vk::ImageTiling::OPTIMAL) - .usage(usage) - .push_next(&mut external); - if !list.is_empty() { - info = info - .flags(vk::ImageCreateFlags::MUTABLE_FORMAT) - .push_next(&mut listed); - } - let mut external_out = vk::ExternalImageFormatProperties::default(); - let mut out = vk::ImageFormatProperties2::default().push_next(&mut external_out); - // SAFETY: `physical` is `instance`'s, and the handle's extension is enabled. - let answer = unsafe { - instance.get_physical_device_image_format_properties2(physical, &info, &mut out) - }; - let features = external_out - .external_memory_properties - .external_memory_features; - answer.is_ok() && features.contains(vk::ExternalMemoryFeatureFlags::IMPORTABLE) + let imports = |usage: vk::ImageUsageFlags, list: &[vk::Format]| { + (import_query(core, format, usage, list)) + .is_ok_and(|features| features.contains(vk::ExternalMemoryFeatureFlags::IMPORTABLE)) }; let wanted = WANTED | plan.usage; let usage = (0..32) .map(|bit| vk::ImageUsageFlags::from_raw(1u32 << bit)) - .filter(|&bit| wanted.contains(bit) && holds(bit) && imports(bit)) + .filter(|&bit| wanted.contains(bit) && holds(bit) && imports(bit, &pair)) .fold(vk::ImageUsageFlags::empty(), |all, bit| all | bit); - if usage.is_empty() || !imports(usage) { + if usage.is_empty() || !imports(usage, &pair) { return Err(Error::Limit(Limit::NoImport { handle })); } // With the feedback usage where the plane asks it and the import offers it with the // rest, so a draw reads it as an attachment of its own pass through the loop; else // through its shadow. let looped = usage | vk::ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT; - let usage = match plan.looped && imports(looped) { + let usage = match plan.looped && imports(looped, &pair) { true => looped, false => usage, }; @@ -241,6 +232,13 @@ impl Device { missing: missing.as_raw(), })); } + // Every format the plane's texture views as, where the import takes that list with the + // usage; else the pair, and a view of a format the pair does not list is refused at + // the view (`TextureViewKind::SurfacePixelFormat`). + let list = match full.len() > pair.len() && imports(usage, &full) { + true => full, + false => pair, + }; let device = &core.device; let mut external = vk::ExternalMemoryImageCreateInfo::default().handle_types(HANDLE); let mut listed = vk::ImageFormatListCreateInfo::default().view_formats(&list); @@ -349,3 +347,57 @@ impl Device { }) } } + +/// The formats a plane's image lists where the import takes them: its own `format`, the +/// descriptor's `view`, and `view_formats`, which the descriptor's texture lists for views of +/// another format (its own first), each once. Empty where that is the image's own format alone: +/// the image is then not mutable. +pub(crate) fn plane_list( + format: vk::Format, + view: vk::Format, + view_formats: &[vk::Format], +) -> Vec { + let mut list = vec![format]; + for &listed in [view].iter().chain(view_formats) { + if !list.contains(&listed) { + list.push(listed); + } + } + if list.len() == 1 { + list.clear(); + } + list +} + +/// What `vkGetPhysicalDeviceImageFormatProperties2` answers of an optimal 2D image of `format` +/// and `usage` imported from a Direct3D 11 texture, mutable and listing `list` where it is not +/// empty: the handle's external memory features, or the query's error. +pub(crate) fn import_query( + core: &Core, + format: vk::Format, + usage: vk::ImageUsageFlags, + list: &[vk::Format], +) -> Result { + let (instance, physical) = (core.instance.vk(), core.physical); + let mut external = vk::PhysicalDeviceExternalImageFormatInfo::default().handle_type(HANDLE); + let mut listed = vk::ImageFormatListCreateInfo::default().view_formats(list); + let mut info = vk::PhysicalDeviceImageFormatInfo2::default() + .format(format) + .ty(vk::ImageType::TYPE_2D) + .tiling(vk::ImageTiling::OPTIMAL) + .usage(usage) + .push_next(&mut external); + if !list.is_empty() { + info = info + .flags(vk::ImageCreateFlags::MUTABLE_FORMAT) + .push_next(&mut listed); + } + let mut external_out = vk::ExternalImageFormatProperties::default(); + let mut out = vk::ImageFormatProperties2::default().push_next(&mut external_out); + // SAFETY: `physical` is `instance`'s, and the handle's extension is enabled (the caller holds + // the device's `VK_KHR_external_memory_win32`). + unsafe { instance.get_physical_device_image_format_properties2(physical, &info, &mut out) }?; + Ok(external_out + .external_memory_properties + .external_memory_features) +} diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 768f233d7..1cd68d99b 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -1877,10 +1877,11 @@ pub enum TextureViewKind { /// Another pixel format Metal takes that the texture's image does not list: the device holds /// it in no viewed form of the image format's compatibility class. PixelFormat, - /// Another pixel format Metal takes that a surface plane's image in place does not list - /// ([`Device::new_exported_surface`](crate::Device::new_exported_surface)): the device's - /// linear image does not hold that format. None was counted: reims's pl8rt boot makes 0 - /// views of another format over its surface textures. + /// Another pixel format Metal takes that a surface plane's image does not list: in place + /// ([`Device::new_exported_surface`](crate::Device::new_exported_surface)), the device's + /// linear image does not sample that format or its export does not take the list; over a + /// Direct3D 11 texture (`Device::import_d3d11_surface`, on Windows), the import does not take + /// the list of every format the plane's texture views as. SurfacePixelFormat, /// Another texture type than the casts built /// ([`Texture::new_texture_view`](crate::Texture::new_texture_view)). diff --git a/crates/metal2vulkan-runtime/src/tests/d3d11.rs b/crates/metal2vulkan-runtime/src/tests/d3d11.rs index c2ed70561..1a6f230c8 100644 --- a/crates/metal2vulkan-runtime/src/tests/d3d11.rs +++ b/crates/metal2vulkan-runtime/src/tests/d3d11.rs @@ -11,7 +11,10 @@ //! write did not reach, fails. Then rt writes picture 3 into the planes by a blit and releases //! them, and Direct3D 11 reads picture 3 exactly through staging copies (`CopyResource`, `Map`). //! While the surface lives, the surface imports gauge holds its two planes; it has no buffer and -//! no export handle. +//! no export handle. The same planes made with `PixelFormatView` usage take a swizzled view in +//! another format of their class (`R8Uint` of the luma, `RG8Uint` of the chroma) exactly where +//! the import query takes the list of every format the plane's texture views as, else the view +//! is `Gap::TextureView` of `SurfacePixelFormat`; the query's answers are printed. #[cfg(all(windows, any(m2v_gpu, m2v_cpu_icd)))] mod on_device { @@ -92,10 +95,12 @@ mod on_device { #[cfg(m2v_gpu)] mod picture { use super::d3d::{self, D3d, SharedTexture}; + use crate::d3d11::{import_query, plane_list}; use crate::tests::command::on_device::{each_device, finished, within}; use crate::{ - BufferLayout, D3d11Plane, Device, Error, Gap, MemoryClass, PixelFormat, Surface, - TextureDescriptor, TexturePlace, TextureType, + BufferLayout, D3d11Plane, Device, Error, Gap, IndexClass, MemoryClass, PixelFormat, + Surface, TextureDescriptor, TexturePlace, TextureSwizzle, TextureSwizzleChannels, + TextureType, TextureUsage, TextureViewKind, }; use ash::vk; use std::os::windows::io::AsHandle; @@ -358,6 +363,107 @@ mod on_device { }); } + /// Each plane made with `ShaderRead` and `PixelFormatView` usage, reached through its views + /// alone, then a swizzled view of it in another format of its class (`R8Uint` of the luma, + /// `RG8Uint` of the chroma): made, in that format, exactly where the import query takes, + /// with the image's usage, the list of every format the plane's texture views as; else + /// `Gap::TextureView` of `SurfacePixelFormat`. Printed for each plane: the query's answer + /// with that list, and with each of its other formats alone beside the image's own. + #[test] + fn every_device_views_a_direct3d_11_plane_in_another_format_where_its_import_lists_it() { + each_device("import_d3d11_surface_views", |name, _, device| { + let luid = luid(&device).unwrap_or_else(|| panic!("{name}: no valid LUID")); + let d3d = D3d::on_luid(luid) + .unwrap_or_else(|| panic!("{name}: no DXGI adapter of LUID {luid:02x?}")); + let textures = PLANES + .each_ref() + .map(|p| d3d.shared_texture(p.width, p.height, p.dxgi)); + let descriptors = PLANES.each_ref().map(|p| { + let mut d = + TextureDescriptor::new(TextureType::Type2D, p.view, p.width, p.height); + d.usage = TextureUsage::SHADER_READ | TextureUsage::PIXEL_FORMAT_VIEW; + d + }); + let planes: Vec> = (textures.iter().zip(&PLANES)) + .zip(&descriptors) + .map(|((texture, plane), descriptor)| D3d11Plane { + handle: texture.handle.as_handle(), + image_format: plane.image, + descriptor: *descriptor, + index: None, + }) + .collect(); + let surface = (device.import_d3d11_surface(&planes)) + .unwrap_or_else(|error| panic!("{name}: the import: {error}")); + let first = IndexClass::Texture.range().start; + let _grant = + (device.grant_indices(IndexClass::Texture, first, 2)).expect("a grant"); + let swizzle = TextureSwizzleChannels { + red: TextureSwizzle::Red, + green: TextureSwizzle::Red, + blue: TextureSwizzle::Red, + alpha: TextureSwizzle::One, + }; + // Each view's format, and its index. + let views = [ + (PixelFormat::R8Uint, first), + (PixelFormat::RG8Uint, first + 1), + ]; + for ((texture, plane), (d, (view, at))) in + (surface.planes().iter().zip(&PLANES)).zip(descriptors.iter().zip(views)) + { + let plan = device.plane_plan(d).expect("the plane's plan"); + let mut own = *d; + own.pixel_format = plane.image; + let format = device.plane_plan(&own).expect("the image's plan").format; + let usage = texture.image_usage(); + let full = plane_list(format, plan.format, &plan.view_formats); + let answer = + |list: &[vk::Format]| import_query(device.core(), format, usage, list); + let takes = (answer(&full)).is_ok_and(|features| { + features.contains(vk::ExternalMemoryFeatureFlags::IMPORTABLE) + }); + let alone: Vec = (full.iter().filter(|&&listed| listed != format)) + .map(|&listed| format!("{listed:?} {:?}", answer(&[format, listed]))) + .collect(); + let made = texture.new_texture_view_with_swizzle( + view, + TextureType::Type2D, + 0..1, + 0..1, + swizzle, + Some(at), + ); + let label = format!("{name}: {:?} as {:?}", plane.image, plane.view); + match takes { + true => { + let made = made.unwrap_or_else(|error| { + panic!("{label}: the {view:?} view, the list imported: {error}") + }); + assert_eq!(made.descriptor().pixel_format, view, "{label}"); + } + false => assert!( + matches!( + made.as_ref().err(), + Some(Error::Unsupported(Gap::TextureView { + kind: TextureViewKind::SurfacePixelFormat, + })) + ), + "{label}: the {view:?} view, the list refused: {:?}", + made.err() + ), + } + println!( + "d3d11-views: {label}: image {format:?}, usage {usage:?}; the import query \ + with the list {full:?}: {:?}; with each other format alone beside \ + {format:?}: {}; the swizzled {view:?} view made: {takes}", + answer(&full), + alone.join(", "), + ); + } + }); + } + /// The gauges a Direct3D 11 surface counts in, which its free brings back: surface /// imports, their bytes, textures. fn import_gauges(device: &Device) -> [u64; 3] { diff --git a/crates/metal2vulkan-runtime/src/tests/surface.rs b/crates/metal2vulkan-runtime/src/tests/surface.rs index bc44fbf59..e30555459 100644 --- a/crates/metal2vulkan-runtime/src/tests/surface.rs +++ b/crates/metal2vulkan-runtime/src/tests/surface.rs @@ -23,7 +23,9 @@ //! plane 0 through a view: its texels exact, and in place one barrier more than a control whose //! first kernel writes a buffer of its own, the ordering a resource outside the surface's unit //! would not take. The memory type the export names, with its flags, the make's wall time per -//! surface, and whether the device's buffers import a dma-buf are printed. +//! surface, and whether the device's buffers import a dma-buf are printed. A luma plane of +//! `PixelFormatView` usage takes a swizzled `R8Uint` view, through which rt's writes read back +//! exactly through the plane's own texture. //! //! The second device stands in for the other API, as in the export tests: a device of another //! instance cannot run under the validation layer. @@ -35,10 +37,11 @@ mod on_device { use crate::tests::devices_of_the_cfgs_kind; use crate::{ BufferLayout, ClearColor, CommandQueue, ComputePipelineDescriptor, ComputePipelineState, - Device, DispatchType, ExportHandle, FunctionDescriptor, IndexClass, Library, LoadAction, - MemoryClass, PixelFormat, PlaneLayout, PlaneSpec, RenderPassDescriptor, StageSource, - Surface, SurfaceCopy, SurfaceExport, SurfaceForm, SurfaceSpec, TextureDescriptor, - TexturePlace, TextureType, TextureUsage, + Device, DispatchType, Error, ExportHandle, FunctionDescriptor, Gap, IndexClass, Library, + LoadAction, MemoryClass, PixelFormat, PlaneLayout, PlaneSpec, RenderPassDescriptor, + StageSource, Surface, SurfaceCopy, SurfaceExport, SurfaceForm, SurfaceSpec, + TextureDescriptor, TexturePlace, TextureSwizzle, TextureSwizzleChannels, TextureType, + TextureUsage, TextureViewKind, }; use ash::vk; use metal2vulkan_devtools::{fixtures_dir, llvm_assemble, AssembleError}; @@ -1346,6 +1349,135 @@ mod on_device { }); } + /// A plane's texture viewed in another format of its own list, through a swizzle: for each + /// row the device exports, on the 1080p picture, a surface whose luma's texture has + /// `ShaderRead` and `PixelFormatView` usage, reached through its views alone, then a swizzled + /// `R8Uint` view of the luma (red in every colour channel, alpha one). The view is made, in + /// `R8Uint`; only in place may a device answer `Gap::TextureView` of `SurfacePixelFormat` + /// instead, where its linear image samples no other format of the luma's list or its export + /// does not take that list. Where the view is made, bytes rt writes into the luma through it + /// read back exactly through the luma's own texture. Printed: the form and the view's answer. + #[test] + fn every_device_views_a_surface_plane_in_another_format_through_a_swizzle() { + each_device("surface_views", |name, _, device| { + let queue = device.new_command_queue(1).expect("a queue"); + let (picture, planes) = &PICTURES[0]; + let luma = planes[0]; + let len = luma.row() * u64::from(luma.height); + let (_from_block, from) = shared(&device, len); + let (_out_block, out) = shared(&device, len); + fill(&from, |bytes| { + for (i, byte) in bytes.iter_mut().enumerate() { + *byte = (i * 37 + 11) as u8; + } + }); + let first = IndexClass::Texture.range().start; + let _grant = (device.grant_indices(IndexClass::Texture, first, 1)).expect("a grant"); + let swizzle = TextureSwizzleChannels { + red: TextureSwizzle::Red, + green: TextureSwizzle::Red, + blue: TextureSwizzle::Red, + alpha: TextureSwizzle::One, + }; + for row in &ROWS { + let handle = row.handle; + let foreign = device + .extensions() + .iter() + .any(|n| n.as_c_str() == ash::ext::queue_family_foreign::NAME); + let label = format!("{name}: {} {handle:?} {picture}", row.name); + if !device.core().exports.offers(handle) || (handle.foreign() && !foreign) { + println!("surface-views: {label}: not exported"); + continue; + } + let specs = [0, 1].map(|i| { + let p = planes[i]; + let mut descriptor = + TextureDescriptor::new(TextureType::Type2D, p.format, p.width, p.height); + descriptor.usage = match i { + 0 => TextureUsage::SHADER_READ | TextureUsage::PIXEL_FORMAT_VIEW, + _ => TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, + }; + PlaneSpec { + descriptor, + index: None, + rows_below: row.rows_below(planes)[i], + } + }); + let spec = SurfaceSpec { + handle, + pitch_multiple: row.pitch_multiple, + start_multiple: row.start_multiple, + planes: &specs, + }; + let (surface, export) = (device.new_exported_surface(&spec)) + .unwrap_or_else(|error| panic!("{label}: {error}")); + let form = export.form; + let view = surface.planes()[0].new_texture_view_with_swizzle( + PixelFormat::R8Uint, + TextureType::Type2D, + 0..1, + 0..1, + swizzle, + Some(first), + ); + let view = match view { + Ok(view) => view, + Err(Error::Unsupported(Gap::TextureView { + kind: TextureViewKind::SurfacePixelFormat, + })) if matches!(form, SurfaceForm::InPlace) => { + println!( + "surface-views: {label}: form {form:?}: the swizzled R8Uint view of \ + the R8Unorm plane refused: SurfacePixelFormat" + ); + continue; + } + Err(error) => { + panic!("{label}: form {form:?}: the swizzled R8Uint view: {error}") + } + }; + assert_eq!( + view.descriptor().pixel_format, + PixelFormat::R8Uint, + "{label}" + ); + fill(&out, |bytes| bytes.fill(0)); + let layout = BufferLayout { + offset: 0, + bytes_per_row: luma.row(), + bytes_per_image: 0, + }; + let size = [luma.width, luma.height, 1]; + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = command_buffer.blit_command_encoder().expect("an encoder"); + (encoder.copy_from_buffer(&from, layout, size, &view, TexturePlace::default())) + .unwrap_or_else(|error| panic!("{label}: the write through the view: {error}")); + (encoder.copy_from_texture_to_buffer( + &surface.planes()[0], + TexturePlace::default(), + size, + &out, + layout, + )) + .unwrap_or_else(|error| panic!("{label}: the read through the plane: {error}")); + encoder.end_encoding(); + command_buffer.commit().expect("a commit"); + finished(&label, &command_buffer); + assert_eq!(command_buffer.error(), None, "{label}"); + assert!( + bytes_of(&out) == bytes_of(&from), + "{label}: the bytes written through the view, read through the plane" + ); + println!( + "surface-views: {label}: form {form:?}: the swizzled R8Uint view of the \ + R8Unorm plane made; {len} bytes written through it read back exactly through \ + the plane" + ); + drop((view, surface)); + } + }); + } + /// The handles and multiples the busy-queue timing makes a surface of, where the device /// exports the handle: the product's VA-API row and its NVIDIA row. #[cfg(unix)]