rt surface: Device::import_d3d11_surface's signature, refused typed until the import is built

The Windows surface import's public shape, so a consumer can build against it now:
#[cfg(windows)] Device::import_d3d11_surface(&self, planes: &[D3d11Plane<'_>]) ->
Result<Surface, Error>, with D3d11Plane { handle: BorrowedHandle, image_format, descriptor,
index } per plane: the Direct3D 11 texture's shared handle and own format, and the texture rt
makes over it. Until the import is built every call answers the new Gap::D3d11Surface (basis
ours), whose Metal counterpart is a texture over an IOSurface's plane.

A Windows device test holds the refusal for no plane and for one. REFUSALS.md and
api_signatures regenerated; the rt README's surfaces section names the call.
This commit is contained in:
Anees Iqbal committed 2026-11-19 11:48:29 -08:00
1 parent b34027cc16
commit 42993be0bc
8 files changed
+110 -2

No files matched your search

+4
View File
@@ -629,6 +629,10 @@ kernel's write through the buffer is ordered before the next kernel's read throu
the global memory barrier rt records between them. `Surface::buffer`'s doc comment quotes the
sections.
On Windows, `Device::import_d3d11_surface(&[D3d11Plane])` takes a picture's planes the other API
made as Direct3D 11 textures, each by its shared handle, its own format and the texture rt makes
over it. It is not built yet: every call is `Gap::D3d11Surface`.
### Known gaps of memory blocks
- An exported surface takes the copy form, its planes copied at each acquire and release, in
+42
View File
@@ -0,0 +1,42 @@
//! A picture's Direct3D 11 textures as a surface ([`Device::import_d3d11_surface`]), a Windows
//! host's: the planes another API decodes into, shared by their handles. Refused for now.
use crate::device::Device;
use crate::error::{Error, Gap};
use crate::surface::Surface;
use crate::texture::TextureDescriptor;
use crate::PixelFormat;
use std::os::windows::io::BorrowedHandle;
/// No Metal counterpart: one plane of a picture another API made as Direct3D 11 textures
/// ([`Device::import_d3d11_surface`]): the shared texture's handle and its own format, and the
/// texture rt makes over it. Metal's counterpart of the whole is an IOSurface's plane under a
/// texture (`newTextureWithDescriptor:iosurface:plane:`).
#[derive(Clone, Copy, Debug)]
pub struct D3d11Plane<'a> {
/// The shared texture's NT handle, as Vulkan imports a Direct3D 11 texture
/// (`VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT`). The consumer keeps it.
pub handle: BorrowedHandle<'a>,
/// The Direct3D 11 texture's own format: `R8Unorm` or `R16Unorm` for a luma plane,
/// `R16Uint` or `R32Uint` for a chroma plane, which the texture views as two channels.
pub image_format: PixelFormat,
/// The texture rt makes over the plane, as [`PlaneSpec::descriptor`](crate::PlaneSpec):
/// its pixel format is the view's (`R8Unorm`, `RG8Unorm`, `R16Unorm`, `RG16Unorm`).
pub descriptor: TextureDescriptor,
/// The texture's index, as a [`PlaneSpec`](crate::PlaneSpec)'s: with none, the plane is
/// reached through its views alone.
pub index: Option<u32>,
}
impl Device {
/// No Metal counterpart of the call: a picture's planes, Direct3D 11 textures another API
/// made (a video decoder's), as a surface whose planes are textures rt's shaders read, as
/// Metal reads an IOSurface's plane through a texture over it
/// (`newTextureWithDescriptor:iosurface:plane:`). Refused for now: the import is not built,
/// and every call answers [`Gap::D3d11Surface`].
///
/// Err: [`Gap::D3d11Surface`].
pub fn import_d3d11_surface(&self, _planes: &[D3d11Plane<'_>]) -> Result<Surface, Error> {
Err(Error::Unsupported(Gap::D3d11Surface))
}
}
+9
View File
@@ -1052,6 +1052,12 @@ pub enum Gap {
/// The `VkImageUsageFlags` bits the tiling lacks.
missing: u32,
},
/// An import of a picture's Direct3D 11 textures as a surface (`Device::import_d3d11_surface`,
/// a Windows host's): not built yet, so every call refuses. Metal's counterpart is a texture
/// over an IOSurface's plane (`newTextureWithDescriptor:iosurface:plane:`).
///
/// Basis: ours (the import is not built).
D3d11Surface,
/// [`BlitCommandEncoder::copy_from_buffer`](crate::BlitCommandEncoder::copy_from_buffer) or
/// [`BlitCommandEncoder::copy_from_texture_to_buffer`](crate::BlitCommandEncoder::copy_from_texture_to_buffer)
/// whose bytes no copy command in the floor addresses, though Metal takes them: an image's
@@ -1967,6 +1973,9 @@ impl fmt::Display for Gap {
"a surface plane of {pixel_format:?} in place lacks image usage {missing:#x} on \
this device"
),
Gap::D3d11Surface => {
f.write_str("an import of Direct3D 11 textures as a surface is not built")
}
Gap::BufferCopyAlignment {
pixel_format,
offset,
+4
View File
@@ -18,6 +18,8 @@ mod command;
mod complete;
mod copy_out;
mod counters;
#[cfg(windows)]
mod d3d11;
mod depth_stencil;
mod device;
mod encoder;
@@ -63,6 +65,8 @@ pub use block::Block;
pub use buffer::{Buffer, MAX_BUFFER_LENGTH};
pub use command::{CommandBuffer, CommandBufferError, CommandBufferStatus};
pub use counters::{Counters, Gauges, Metrics, SiteAllocations};
#[cfg(windows)]
pub use d3d11::D3d11Plane;
pub use depth_stencil::DepthStencilState;
pub use device::{Device, DeviceOptions, RawDevice};
pub use encoder::{ComputeCommandEncoder, DispatchType, Resource, ResourceUsage};
+39
View File
@@ -0,0 +1,39 @@
//! The Direct3D 11 surface import, a Windows host's: under a device cfg, on every device of the
//! cfg's kind, refused typed for now, for no plane and for a plane.
#[cfg(all(windows, any(m2v_gpu, m2v_cpu_icd)))]
mod on_device {
use crate::tests::command::on_device::each_device;
use crate::{D3d11Plane, Error, Gap, PixelFormat, TextureDescriptor, TextureType};
use std::os::windows::io::AsHandle;
#[test]
fn every_device_refuses_a_d3d11_surface_typed() {
each_device("import_d3d11_surface", |name, _, device| {
// A handle the call borrows and never reads: the test's own executable's.
let file = std::env::current_exe()
.and_then(std::fs::File::open)
.expect("a file");
let plane = D3d11Plane {
handle: file.as_handle(),
image_format: PixelFormat::R8Unorm,
descriptor: TextureDescriptor::new(
TextureType::Type2D,
PixelFormat::R8Unorm,
64,
32,
),
index: None,
};
for planes in [&[][..], &[plane][..]] {
let error = device.import_d3d11_surface(planes).err();
assert!(
matches!(error, Some(Error::Unsupported(Gap::D3d11Surface))),
"{name}: {} planes: {error:?}",
planes.len()
);
}
println!("d3d11: {name}: the surface import refused typed");
});
}
}
+1
View File
@@ -8,6 +8,7 @@ mod command;
mod compute;
mod copy_out;
mod copy_over;
mod d3d11;
mod device;
mod draw;
mod export;
@@ -2296,6 +2296,10 @@ field metal2vulkan-rt::ComputePipelineDescriptor.stage_input pub stage_input: Op
field metal2vulkan-rt::ComputePipelineDescriptor.support_adding_binary_functions pub support_adding_binary_functions: bool
field metal2vulkan-rt::ComputePipelineDescriptor.support_indirect_command_buffers pub support_indirect_command_buffers: bool
field metal2vulkan-rt::ComputePipelineDescriptor.threadgroup_size_is_multiple_of_execution_width pub threadgroup_size_is_multiple_of_execution_width: bool
field metal2vulkan-rt::D3d11Plane.descriptor pub descriptor: TextureDescriptor
field metal2vulkan-rt::D3d11Plane.handle pub handle: BorrowedHandle<'a>
field metal2vulkan-rt::D3d11Plane.image_format pub image_format: PixelFormat
field metal2vulkan-rt::D3d11Plane.index pub index: Option<u32>
field metal2vulkan-rt::DepthStencilDescriptor.back_face_stencil pub back_face_stencil: StencilDescriptor
field metal2vulkan-rt::DepthStencilDescriptor.depth_compare_function pub depth_compare_function: CompareFunction
field metal2vulkan-rt::DepthStencilDescriptor.depth_write_enabled pub depth_write_enabled: bool
@@ -9669,6 +9673,7 @@ method metal2vulkan-rt::Device::grant_indices pub fn grant_indices(&self, class:
method metal2vulkan-rt::Device::has_unified_memory pub fn has_unified_memory(&self) -> bool
method metal2vulkan-rt::Device::heap_buffer_size_and_align pub fn heap_buffer_size_and_align(&self, length: u64, _options: u64) -> SizeAndAlign
method metal2vulkan-rt::Device::heap_texture_size_and_align pub fn heap_texture_size_and_align(&self, descriptor: &TextureDescriptor) -> Result<SizeAndAlign, Error>
method metal2vulkan-rt::Device::import_d3d11_surface pub fn import_d3d11_surface(&self, _planes: &[D3d11Plane<'_>]) -> Result<Surface, Error>
method metal2vulkan-rt::Device::import_dma_buf #[cfg(unix)] pub fn import_dma_buf(&self, fd: std::os::fd::OwnedFd, len: u64, release: Option<Box<dyn FnOnce() + Send>>) -> Result<(Block, u32), Error>
method metal2vulkan-rt::Device::import_host_memory pub unsafe fn import_host_memory(&self, pointer: NonNull<u8>, len: u64, release: Option<Box<dyn FnOnce() + Send>>) -> Result<(Block, u32), Error>
method metal2vulkan-rt::Device::memory_types pub fn memory_types(&self) -> floor::MemoryTypes
@@ -11861,6 +11866,7 @@ struct metal2vulkan-rt::ComputeCommandEncoder pub struct ComputeCommandEncoder
struct metal2vulkan-rt::ComputePipelineDescriptor #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct ComputePipelineDescriptor
struct metal2vulkan-rt::ComputePipelineState #[derive(Clone)] pub struct ComputePipelineState
struct metal2vulkan-rt::Counters #[derive(Clone)] pub struct Counters
struct metal2vulkan-rt::D3d11Plane #[derive(Clone, Copy, Debug)] pub struct D3d11Plane<'a>
struct metal2vulkan-rt::DepthStencilDescriptor #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct DepthStencilDescriptor
struct metal2vulkan-rt::DepthStencilState #[derive(Clone)] pub struct DepthStencilState
struct metal2vulkan-rt::Device #[derive(Clone)] pub struct Device
@@ -13849,6 +13855,7 @@ variant metal2vulkan-rt::ExportHandle::OpaqueWin32 OpaqueWin32
variant metal2vulkan-rt::Gap::BufferCopyAlignment BufferCopyAlignment { pixel_format: PixelFormat, offset: u64, bytes_per_row: u64, bytes_per_image: u64 }
variant metal2vulkan-rt::Gap::CubeArrayTexture CubeArrayTexture
variant metal2vulkan-rt::Gap::CubicSampler CubicSampler
variant metal2vulkan-rt::Gap::D3d11Surface D3d11Surface
variant metal2vulkan-rt::Gap::Draw Draw { kind: DrawKind }
variant metal2vulkan-rt::Gap::FillAlignment FillAlignment { start: u64, end: u64 }
variant metal2vulkan-rt::Gap::FloatDepthUpload FloatDepthUpload { pixel_format: PixelFormat }
Can't render this file because it is too large.
+4 -2
View File
@@ -39,7 +39,7 @@ Columns:
| Devices below the new runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Refusal` | 72 | 72 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Limit` | 16 | 16 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Gap` | 27 | 27 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Gap` | 28 | 28 | 0 | 0 | 0 | 0 | 0 |
## Totals by basis
@@ -57,7 +57,7 @@ Columns:
| Devices below the new runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 |
| The new runtime's `Refusal` | 20 | 16 | 0 | 0 | 36 | 0 | 0 | 0 |
| The new runtime's `Limit` | 0 | 0 | 0 | 12 | 4 | 0 | 0 | 0 |
| The new runtime's `Gap` | 0 | 0 | 0 | 1 | 26 | 0 | 0 | 0 |
| The new runtime's `Gap` | 0 | 0 | 0 | 1 | 27 | 0 | 0 | 0 |
## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`)
@@ -733,6 +733,7 @@ Columns:
| `TextureOverBuffer` | A texture over a buffer (`Buffer::new_texture`) the runtime does not make | every device (a public call's own check of its arguments) | `ours`: the in-place linear image and the copy form take one 2D color image | 4: `crates/metal2vulkan-rt/src/texture.rs (check_over)`, `crates/metal2vulkan-rt/src/texture.rs (make)` (+2) | `-` |
| `HeapTexture` | A heap texture the runtime does not place (`Device::new_heap_texture`, `Device::new_heap_texture_for_views` and `Device::heap_texture_size_and_align`) | every device (a public call's own check of its arguments) | `ours`: heap textures are built for Private heaps of placeable images | 2: `crates/metal2vulkan-rt/src/texture.rs (heap_fit)`, `crates/metal2vulkan-rt/src/texture.rs (heap_source)` | `-` |
| `SurfaceUsage` | A surface plane in place (`Device::new_exported_surface`) whose texture's uses ask an image usage its linear tiling lacks (storage, for one) | at the device's limit | `device`: the image format query of the plane's tiling | 2: `crates/metal2vulkan-rt/src/surface.rs (plane)`, `crates/metal2vulkan-rt/src/texture.rs (surface_texture)` | `-` |
| `D3d11Surface` | An import of a picture's Direct3D 11 textures as a surface (`Device::import_d3d11_surface`, a Windows host's) | every device (a public call's own check of its arguments) | `ours`: the import is not built | 1: `crates/metal2vulkan-rt/src/d3d11.rs (import_d3d11_surface)` | `-` |
| `BufferCopyAlignment` | `BlitCommandEncoder::copy_from_buffer` or `BlitCommandEncoder::copy_from_texture_to_buffer` whose bytes no copy command in the floor addresses,... | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 places a copy's rows in a buffer by a count of texels from an aligned offset; each is built when a replay stream makes one | 1: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)` | `-` |
| `FillAlignment` | `BlitCommandEncoder::fill_buffer` of a range that does not start and end on whole 4-byte words of the bytes shaders reach, which Metal fills byte... | every device (a public call's own check of its arguments) | `ours`: `vkCmdFillBuffer` writes whole words; a byte fill is built when a replay stream makes one | 1: `crates/metal2vulkan-rt/src/blit.rs (fill_range)` | `-` |
| `RenderPipeline` | A render pipeline state of something the runtime does not build yet | every device (a public call's own check of its arguments) | `ours`: the replay streams' render pipelines draw into colour, depth and stencil attachments of one sample, with no tessellation and no framebuffer fetch; each other kind is built when a replay stream makes one | 5: `crates/metal2vulkan-rt/src/render.rs (draw_input)`, `crates/metal2vulkan-rt/src/render.rs (of, 3 sites)` (+1) | `-` |
@@ -1339,6 +1340,7 @@ Each refusal's sites, with the function that builds it.
- `rt:Gap::TextureOverBuffer`: `crates/metal2vulkan-rt/src/texture.rs (check_over)`; `crates/metal2vulkan-rt/src/texture.rs (make)`; `crates/metal2vulkan-rt/src/texture.rs (over_texel)`; `crates/metal2vulkan-rt/src/texture.rs (texture)`
- `rt:Gap::HeapTexture`: `crates/metal2vulkan-rt/src/texture.rs (heap_fit)`; `crates/metal2vulkan-rt/src/texture.rs (heap_source)`
- `rt:Gap::SurfaceUsage`: `crates/metal2vulkan-rt/src/surface.rs (plane)`; `crates/metal2vulkan-rt/src/texture.rs (surface_texture)`
- `rt:Gap::D3d11Surface`: `crates/metal2vulkan-rt/src/d3d11.rs (import_d3d11_surface)`
- `rt:Gap::BufferCopyAlignment`: `crates/metal2vulkan-rt/src/blit.rs (buffer_copy)`
- `rt:Gap::FillAlignment`: `crates/metal2vulkan-rt/src/blit.rs (fill_range)`
- `rt:Gap::RenderPipeline`: `crates/metal2vulkan-rt/src/render.rs (draw_input)`; `crates/metal2vulkan-rt/src/render.rs (of, 3 sites)`; `crates/metal2vulkan-rt/src/render.rs (refuse)`