Replay: the stand-in for the other API is Linux's and macOS's; the validation crate's clippy for Windows passes
The validation crate builds for x86_64-pc-windows-gnullvm (with llvm-mingw for the bundled SQLite, as win-cross.sh builds command-replay for the Windows play), and its clippy there (job m3-max-78094 at abf7b8f873, plain and under --cfg m2v_gpu) reported the stand-in: its writes wait under the crate's bounded fence waits (gpu::wait::vulkan), which the crate keeps to Linux and macOS, and its empty extension list for an NT handle did not type-check. Rather than a Windows form of the fence wait, the stand-in is Linux's and macOS's alone: its import is fd-only, and on any other host StandIn::new says why it is absent, so each landing is counted unwritten with that reason and the play goes on (the S1 ruling's handling of a stand-in that cannot be made). The NT-handle import, which no build compiled, is gone, and so is the device test's Windows arm: the test, under the layer through candidate::validated, is Linux's and macOS's. A plane's rows are the caller's tuple. The same clippy reported lib-test code that predates the exported surfaces and never compiled for Windows: build_support_tests.rs hex-encoded through crate::hash (not on Windows; now sha2's own lower-hex), and gpu/wait.rs's tests of the fence and Metal waits' own endings, which Windows lacks (now gated as those variants are). docs/REPLAY-STREAM.md section 10 says the stand-in is Linux's and macOS's and what Windows counts.
This commit is contained in:
1 parent
b111f209ec
commit
ca370da605
7 files changed
+169
-154
No files matched your search
@@ -17,7 +17,7 @@ fn write(root: &Path, path: &str, text: &str) {
|
||||
}
|
||||
|
||||
fn fingerprint(root: &Path) -> String {
|
||||
crate::hash::hex_encode(product_hash(root).finalize())
|
||||
format!("{:x}", product_hash(root).finalize())
|
||||
}
|
||||
|
||||
fn files(root: &Path) -> BTreeSet<PathBuf> {
|
||||
|
||||
@@ -534,6 +534,7 @@ pub mod metal {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[cfg(not(windows))]
|
||||
use std::path::PathBuf;
|
||||
|
||||
struct Fake {
|
||||
@@ -579,6 +580,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn completion_passes_and_ordinary_failure_is_an_error() {
|
||||
let timeout = Duration::from_millis(250);
|
||||
let mut completed = Fake::new(WaitOutcome::Completed);
|
||||
@@ -623,6 +625,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn an_unresolved_wait_is_a_hang() {
|
||||
let mut unresolved = Fake::new(WaitOutcome::Unresolved("fence status unknown".into()));
|
||||
let Verdict::Hang(record) = judge(
|
||||
@@ -652,6 +655,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn fault_status_is_a_suspected_fault() {
|
||||
let mut faulted = Fake::new(WaitOutcome::SuspectedFault("page fault".into()));
|
||||
let Verdict::Fault(record) = judge(
|
||||
@@ -667,6 +671,7 @@ mod tests {
|
||||
assert_eq!(record.case_id, None);
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn scratch_tripwire() -> (crate::ScratchDir, PathBuf) {
|
||||
let scratch = crate::ScratchDir::new("gpu-wait").unwrap();
|
||||
let path = scratch.path().join("m2v-gpu.hang");
|
||||
@@ -674,6 +679,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn gpu_incidents_write_the_tripwire_and_cpu_incidents_do_not() {
|
||||
let mut faulted = Fake::new(WaitOutcome::SuspectedFault("VK_ERROR_DEVICE_LOST".into()));
|
||||
for (backend, writes) in [
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
//! them (`videos`); the surfaces whose making a submission carried; the pictures landed; and the
|
||||
//! CPU's calls on such a texture, whose submissions the backend does not see.
|
||||
|
||||
use super::standin::{Rows, StandIn};
|
||||
use super::standin::StandIn;
|
||||
use super::videos::VideoHandle;
|
||||
use super::{failed, unaddressed, NewRuntime, Object};
|
||||
use crate::replay::args::{arg, list, refuse, uint, Fields};
|
||||
@@ -33,6 +33,10 @@ use crate::replay::value::Value;
|
||||
use metal2vulkan_runtime as rt;
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
|
||||
/// One plane's rows for the stand-in to write: the plane's first byte and row pitch in the memory,
|
||||
/// the bytes of a row, and the picture's bytes of the plane, rows packed.
|
||||
pub(super) type Rows<'a> = (u64, u64, u64, &'a [u8]);
|
||||
|
||||
/// The counters of what the runtime's hand-overs follow from (`handover`).
|
||||
pub(in crate::replay) const PARTS: &str = "handover_parts";
|
||||
pub(in crate::replay) const MAKINGS: &str = "handover_makings";
|
||||
@@ -474,12 +478,7 @@ impl NewRuntime {
|
||||
);
|
||||
return Err(refuse(call, why));
|
||||
}
|
||||
rows.push(Rows {
|
||||
offset: layout.offset,
|
||||
pitch: layout.row_pitch,
|
||||
row,
|
||||
bytes,
|
||||
});
|
||||
rows.push((layout.offset, layout.row_pitch, row, bytes));
|
||||
}
|
||||
Some(rows)
|
||||
}
|
||||
@@ -502,7 +501,7 @@ impl NewRuntime {
|
||||
c.bytes += rows
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(|r| r.bytes.len() as u64)
|
||||
.map(|&(_, _, _, bytes)| bytes.len() as u64)
|
||||
.sum::<u64>();
|
||||
}
|
||||
Ok(false) => c.patterned += 1,
|
||||
|
||||
@@ -23,7 +23,60 @@ pub(super) mod places;
|
||||
mod prepass;
|
||||
mod render;
|
||||
pub(super) mod second;
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
mod standin;
|
||||
/// No stand-in for the other API that writes an exported surface's pictures where the crate has no
|
||||
/// bounded fence wait (`crate::gpu::wait::vulkan`, Linux's and macOS's), which the stand-in's
|
||||
/// writes take: [`StandIn::new`](standin::StandIn::new) says so, and each landing is counted
|
||||
/// unwritten with that reason (`exported`).
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
mod standin {
|
||||
use super::exported::Rows;
|
||||
use super::videos::VideoHandle;
|
||||
use crate::gpu::wait::SubmissionBackend;
|
||||
use metal2vulkan_runtime as rt;
|
||||
|
||||
/// No stand-in is made here.
|
||||
pub(super) struct StandIn(std::convert::Infallible);
|
||||
|
||||
impl StandIn {
|
||||
pub(super) fn new(
|
||||
_runtime: &rt::Device,
|
||||
_backend: SubmissionBackend,
|
||||
) -> Result<Self, String> {
|
||||
Err(
|
||||
"none on this host: its writes wait under the validation crate's bounded fence \
|
||||
waits, which only Linux and macOS have"
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn import(
|
||||
&mut self,
|
||||
_surface: u64,
|
||||
_handle: VideoHandle,
|
||||
_export: &rt::Export,
|
||||
) -> Result<(), String> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub(super) fn imported(&self, _surface: u64) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub(super) fn write(&mut self, _surface: u64, _planes: &[Rows<'_>]) -> Result<(), String> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub(super) fn fill(&mut self, _surface: u64, _byte: u8) -> Result<(), String> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub(super) fn forget(&mut self, _surface: u64) {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
}
|
||||
mod states;
|
||||
mod surfaces;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -11,35 +11,29 @@
|
||||
//! memory outside every queue of the runtime's, so the runtime's commands see them only through
|
||||
//! its hand-over of the memory.
|
||||
//!
|
||||
//! The module is Linux's and macOS's (the handles are fds): its writes wait under the crate's
|
||||
//! bounded fence waits (`crate::gpu::wait::vulkan`), which those hosts alone have. Elsewhere the
|
||||
//! backend's stand-in is the absent one (`super::standin` there), which says why.
|
||||
//!
|
||||
//! An opaque handle is imported at the size and memory type it was exported with, as Vulkan asks
|
||||
//! of an import of the API's own opaque payload, and in an allocation dedicated to the buffer only
|
||||
//! where the driver requires one; a dma-buf, into a memory type its fd's query lists, dedicated to
|
||||
//! the buffer. The device holds a handle of the runtime's device, so the instance it lives on
|
||||
//! outlives it, and frees its imports and itself before that handle goes.
|
||||
//!
|
||||
//! On Linux and macOS the device keeps its loader word as the candidate's context does
|
||||
//! The device keeps its loader word as the candidate's context does
|
||||
//! (`candidate`'s `LoaderWord`): recorded as `vkCreateDevice` returns it, and put back before each
|
||||
//! call the loader serves itself (`vkGetDeviceQueue`, `vkAllocateCommandBuffers`,
|
||||
//! `vkDestroyDevice`), which a driver that writes over it while reporting a message would fault.
|
||||
|
||||
use super::exported::Rows;
|
||||
use super::videos::VideoHandle;
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use crate::candidate::LoaderWord;
|
||||
use crate::gpu::wait::{self, SubmissionBackend};
|
||||
use ash::vk;
|
||||
use metal2vulkan_runtime as rt;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// One plane's rows to write: where they go in the memory, and the picture's bytes of them, rows
|
||||
/// packed.
|
||||
pub(super) struct Rows<'a> {
|
||||
pub(super) offset: u64,
|
||||
pub(super) pitch: u64,
|
||||
/// The bytes of a row.
|
||||
pub(super) row: u64,
|
||||
pub(super) bytes: &'a [u8],
|
||||
}
|
||||
|
||||
/// The stand-in's buffer over one surface's memory.
|
||||
struct Import {
|
||||
buffer: vk::Buffer,
|
||||
@@ -59,7 +53,6 @@ struct Staging {
|
||||
pub(super) struct StandIn {
|
||||
device: ash::Device,
|
||||
/// The device's loader word (the module's docs).
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
word: LoaderWord,
|
||||
queue: vk::Queue,
|
||||
family: u32,
|
||||
@@ -67,7 +60,6 @@ pub(super) struct StandIn {
|
||||
command: vk::CommandBuffer,
|
||||
fence: vk::Fence,
|
||||
types: vk::PhysicalDeviceMemoryProperties,
|
||||
#[cfg(unix)]
|
||||
fds: ash::khr::external_memory_fd::Device,
|
||||
staging: Option<Staging>,
|
||||
/// Each surface's import, by the surface's stream id.
|
||||
@@ -81,19 +73,20 @@ pub(super) struct StandIn {
|
||||
/// `VK_EXT_queue_family_foreign`'s family: a dma-buf's other API.
|
||||
const FOREIGN: u32 = vk::QUEUE_FAMILY_FOREIGN_EXT;
|
||||
|
||||
fn handle_type(handle: VideoHandle) -> vk::ExternalMemoryHandleTypeFlags {
|
||||
/// The handle type of an fd `handle`; Err for an NT handle, which no surface of these hosts has
|
||||
/// (`exported` refuses one before it is made).
|
||||
fn handle_type(handle: VideoHandle) -> Result<vk::ExternalMemoryHandleTypeFlags, String> {
|
||||
match handle {
|
||||
VideoHandle::DmaBuf => vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT,
|
||||
VideoHandle::OpaqueFd => vk::ExternalMemoryHandleTypeFlags::OPAQUE_FD,
|
||||
VideoHandle::OpaqueWin32 => vk::ExternalMemoryHandleTypeFlags::OPAQUE_WIN32,
|
||||
VideoHandle::DmaBuf => Ok(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT),
|
||||
VideoHandle::OpaqueFd => Ok(vk::ExternalMemoryHandleTypeFlags::OPAQUE_FD),
|
||||
VideoHandle::OpaqueWin32 => Err("an NT handle, which the stand-in imports none of".into()),
|
||||
}
|
||||
}
|
||||
|
||||
impl StandIn {
|
||||
/// The stand-in on `runtime`'s instance and physical device: a device of one queue of the
|
||||
/// first family that copies, with the external-memory extensions of the host's handles that
|
||||
/// the physical device offers. Err where it offers no fd's (an NT handle's on Windows) or the
|
||||
/// device cannot be made.
|
||||
/// first family that copies, with the external-memory extensions of fds that the physical
|
||||
/// device offers. Err where it offers no fd's or the device cannot be made.
|
||||
#[expect(
|
||||
clippy::disallowed_methods,
|
||||
reason = "the stand-in's own device: its queue as vkCreateDevice returns it, its command \
|
||||
@@ -114,16 +107,11 @@ impl StandIn {
|
||||
let offers = |name: &std::ffi::CStr| {
|
||||
(offered.iter()).any(|e| e.extension_name_as_c_str().is_ok_and(|n| n == name))
|
||||
};
|
||||
#[cfg(unix)]
|
||||
let (needed, optional) = (
|
||||
ash::khr::external_memory_fd::NAME,
|
||||
[
|
||||
ash::ext::external_memory_dma_buf::NAME,
|
||||
ash::ext::queue_family_foreign::NAME,
|
||||
],
|
||||
);
|
||||
#[cfg(windows)]
|
||||
let (needed, optional) = (ash::khr::external_memory_win32::NAME, []);
|
||||
let needed = ash::khr::external_memory_fd::NAME;
|
||||
let optional = [
|
||||
ash::ext::external_memory_dma_buf::NAME,
|
||||
ash::ext::queue_family_foreign::NAME,
|
||||
];
|
||||
if !offers(needed) {
|
||||
return Err(format!("the device offers no {needed:?}"));
|
||||
}
|
||||
@@ -142,12 +130,10 @@ impl StandIn {
|
||||
let device = unsafe { instance.create_device(physical, &info, None) }
|
||||
.map_err(|error| format!("vkCreateDevice: {error}"))?;
|
||||
// SAFETY: the loader just returned the handle; the stand-in destroys it last.
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
let word = unsafe { LoaderWord::of_device(device.handle()) };
|
||||
let word_back = || {
|
||||
// SAFETY: the device is live, and only this thread calls the loader with it.
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
let _ = unsafe { word.restore() };
|
||||
unsafe { word.restore() };
|
||||
};
|
||||
// SAFETY: the device is new, and its one queue of `family` exists; nothing has reported
|
||||
// on the device since its word was recorded.
|
||||
@@ -194,10 +180,8 @@ impl StandIn {
|
||||
// SAFETY: as above.
|
||||
let types = unsafe { instance.get_physical_device_memory_properties(physical) };
|
||||
Ok(StandIn {
|
||||
#[cfg(unix)]
|
||||
fds: ash::khr::external_memory_fd::Device::new(instance, &device),
|
||||
device,
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
word,
|
||||
queue,
|
||||
family,
|
||||
@@ -226,7 +210,7 @@ impl StandIn {
|
||||
handle: VideoHandle,
|
||||
export: &rt::Export,
|
||||
) -> Result<(), String> {
|
||||
let kind = handle_type(handle);
|
||||
let kind = handle_type(handle)?;
|
||||
let len = export.size;
|
||||
let mut external = vk::ExternalMemoryBufferCreateInfo::default().handle_types(kind);
|
||||
let info = vk::BufferCreateInfo::default()
|
||||
@@ -237,7 +221,7 @@ impl StandIn {
|
||||
// SAFETY: the device is live; the buffer's handle type is one its extensions import.
|
||||
let buffer = unsafe { self.device.create_buffer(&info, None) }
|
||||
.map_err(|error| format!("the import's vkCreateBuffer: {error}"))?;
|
||||
let memory = self.import_memory(buffer, handle, export);
|
||||
let memory = self.import_memory(buffer, handle, kind, export);
|
||||
let memory = match memory {
|
||||
Ok(memory) => memory,
|
||||
Err(why) => {
|
||||
@@ -270,13 +254,15 @@ impl StandIn {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The memory of `export`'s import for `buffer` (the module's docs).
|
||||
/// The memory of `export`'s import, an fd of `kind`, for `buffer` (the module's docs).
|
||||
fn import_memory(
|
||||
&self,
|
||||
buffer: vk::Buffer,
|
||||
handle: VideoHandle,
|
||||
kind: vk::ExternalMemoryHandleTypeFlags,
|
||||
export: &rt::Export,
|
||||
) -> Result<vk::DeviceMemory, String> {
|
||||
use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd};
|
||||
let mut dedicated_needs = vk::MemoryDedicatedRequirements::default();
|
||||
let mut needs2 = vk::MemoryRequirements2::default().push_next(&mut dedicated_needs);
|
||||
let asked = vk::BufferMemoryRequirementsInfo2::default().buffer(buffer);
|
||||
@@ -293,72 +279,49 @@ impl StandIn {
|
||||
needs.size, export.size
|
||||
));
|
||||
}
|
||||
let dedicated = required || !opaque;
|
||||
let mut dedicated_info = vk::MemoryDedicatedAllocateInfo::default().buffer(buffer);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd};
|
||||
let (size, index) = match handle {
|
||||
VideoHandle::DmaBuf => {
|
||||
let mut properties = vk::MemoryFdPropertiesKHR::default();
|
||||
// SAFETY: the fd is a dma-buf the runtime's device exported.
|
||||
unsafe {
|
||||
self.fds.get_memory_fd_properties(
|
||||
handle_type(handle),
|
||||
export.handle.as_raw_fd(),
|
||||
&mut properties,
|
||||
)
|
||||
}
|
||||
.map_err(|error| format!("vkGetMemoryFdPropertiesKHR: {error}"))?;
|
||||
let bits = properties.memory_type_bits & needs.memory_type_bits;
|
||||
let index = match bits & (1 << export.memory_type) {
|
||||
0 if bits == 0 => return Err("no memory type takes the dma-buf".into()),
|
||||
0 => bits.trailing_zeros(),
|
||||
_ => export.memory_type,
|
||||
};
|
||||
(export.size.max(needs.size), index)
|
||||
let (size, index) = match opaque {
|
||||
true => (export.size, export.memory_type),
|
||||
false => {
|
||||
let mut properties = vk::MemoryFdPropertiesKHR::default();
|
||||
// SAFETY: the fd is a dma-buf the runtime's device exported.
|
||||
unsafe {
|
||||
(self.fds).get_memory_fd_properties(
|
||||
kind,
|
||||
export.handle.as_raw_fd(),
|
||||
&mut properties,
|
||||
)
|
||||
}
|
||||
_ => (export.size, export.memory_type),
|
||||
};
|
||||
let fd = (export.handle.try_clone())
|
||||
.map_err(|error| format!("a new fd of the export: {error}"))?
|
||||
.into_raw_fd();
|
||||
let mut import = vk::ImportMemoryFdInfoKHR::default()
|
||||
.handle_type(handle_type(handle))
|
||||
.fd(fd);
|
||||
let mut info = vk::MemoryAllocateInfo::default()
|
||||
.allocation_size(size)
|
||||
.memory_type_index(index)
|
||||
.push_next(&mut import);
|
||||
if dedicated {
|
||||
info = info.push_next(&mut dedicated_info);
|
||||
.map_err(|error| format!("vkGetMemoryFdPropertiesKHR: {error}"))?;
|
||||
let bits = properties.memory_type_bits & needs.memory_type_bits;
|
||||
let index = match bits & (1 << export.memory_type) {
|
||||
0 if bits == 0 => return Err("no memory type takes the dma-buf".into()),
|
||||
0 => bits.trailing_zeros(),
|
||||
_ => export.memory_type,
|
||||
};
|
||||
(export.size.max(needs.size), index)
|
||||
}
|
||||
// SAFETY: an import of the fd, of the type and size the module's docs name; a
|
||||
// successful import owns the fd, a failed one leaves it the caller's.
|
||||
unsafe { self.device.allocate_memory(&info, None) }.map_err(|error| {
|
||||
// SAFETY: the fd is ours again, and nothing else holds it.
|
||||
drop(unsafe { OwnedFd::from_raw_fd(fd) });
|
||||
format!("the import's vkAllocateMemory: {error}")
|
||||
})
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
let mut import = vk::ImportMemoryWin32HandleInfoKHR::default()
|
||||
.handle_type(handle_type(handle))
|
||||
.handle(export.handle.as_raw_handle() as vk::HANDLE);
|
||||
let mut info = vk::MemoryAllocateInfo::default()
|
||||
.allocation_size(export.size)
|
||||
.memory_type_index(export.memory_type)
|
||||
.push_next(&mut import);
|
||||
if dedicated {
|
||||
info = info.push_next(&mut dedicated_info);
|
||||
}
|
||||
// SAFETY: an import of the NT handle, which stays the export's, at the size and type
|
||||
// it was exported with.
|
||||
unsafe { self.device.allocate_memory(&info, None) }
|
||||
.map_err(|error| format!("the import's vkAllocateMemory: {error}"))
|
||||
};
|
||||
let fd = (export.handle.try_clone())
|
||||
.map_err(|error| format!("a new fd of the export: {error}"))?
|
||||
.into_raw_fd();
|
||||
let mut import = vk::ImportMemoryFdInfoKHR::default()
|
||||
.handle_type(kind)
|
||||
.fd(fd);
|
||||
let mut dedicated_info = vk::MemoryDedicatedAllocateInfo::default().buffer(buffer);
|
||||
let mut info = vk::MemoryAllocateInfo::default()
|
||||
.allocation_size(size)
|
||||
.memory_type_index(index)
|
||||
.push_next(&mut import);
|
||||
if required || !opaque {
|
||||
info = info.push_next(&mut dedicated_info);
|
||||
}
|
||||
// SAFETY: an import of the fd, of the type and size the module's docs name; a successful
|
||||
// import owns the fd, a failed one leaves it the caller's.
|
||||
unsafe { self.device.allocate_memory(&info, None) }.map_err(|error| {
|
||||
// SAFETY: the fd is ours again, and nothing else holds it.
|
||||
drop(unsafe { OwnedFd::from_raw_fd(fd) });
|
||||
format!("the import's vkAllocateMemory: {error}")
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether surface `surface` has an import.
|
||||
@@ -431,7 +394,10 @@ impl StandIn {
|
||||
/// Writes `planes`' rows into surface `surface`'s memory, then releases it to its handle's
|
||||
/// queue family, and waits for that work.
|
||||
pub(super) fn write(&mut self, surface: u64, planes: &[Rows<'_>]) -> Result<(), String> {
|
||||
let len: u64 = planes.iter().map(|p| p.bytes.len() as u64).sum();
|
||||
let len: u64 = planes
|
||||
.iter()
|
||||
.map(|&(_, _, _, bytes)| bytes.len() as u64)
|
||||
.sum();
|
||||
let (staging, memory) = self.staging(len.max(4))?;
|
||||
let flags = vk::MemoryMapFlags::empty();
|
||||
// SAFETY: the memory is host-visible and unmapped, and no command uses it: each write
|
||||
@@ -441,22 +407,18 @@ impl StandIn {
|
||||
.cast::<u8>();
|
||||
let mut regions = Vec::new();
|
||||
let mut at = 0u64;
|
||||
for plane in planes {
|
||||
for &(offset, pitch, row, bytes) in planes {
|
||||
// SAFETY: the mapping is at least `len` bytes long.
|
||||
unsafe {
|
||||
std::ptr::copy_nonoverlapping(
|
||||
plane.bytes.as_ptr(),
|
||||
mapped.add(at as usize),
|
||||
plane.bytes.len(),
|
||||
);
|
||||
std::ptr::copy_nonoverlapping(bytes.as_ptr(), mapped.add(at as usize), bytes.len());
|
||||
}
|
||||
let rows = plane.bytes.len() as u64 / plane.row.max(1);
|
||||
let rows = bytes.len() as u64 / row.max(1);
|
||||
regions.extend((0..rows).map(|y| vk::BufferCopy {
|
||||
src_offset: at + y * plane.row,
|
||||
dst_offset: plane.offset + y * plane.pitch,
|
||||
size: plane.row,
|
||||
src_offset: at + y * row,
|
||||
dst_offset: offset + y * pitch,
|
||||
size: row,
|
||||
}));
|
||||
at += plane.bytes.len() as u64;
|
||||
at += bytes.len() as u64;
|
||||
}
|
||||
// SAFETY: the memory is mapped; its coherent type needs no flush.
|
||||
unsafe { self.device.unmap_memory(memory) };
|
||||
@@ -577,8 +539,7 @@ impl Drop for StandIn {
|
||||
}
|
||||
self.device.destroy_fence(self.fence, None);
|
||||
self.device.destroy_command_pool(self.pool, None);
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
let _ = self.word.restore();
|
||||
self.word.restore();
|
||||
self.device.destroy_device(None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@
|
||||
//! Private target, read back through a blit, green at every texel, and covering nothing.
|
||||
//! - A layered pass plays as the runtime builds it, not skipped: a draw renders the layer its
|
||||
//! vertex function selects, the clear covers the other, and a blit and a dump read both slices.
|
||||
//! - The exported-surface snippet (`snippets::video_surfaces`) plays for each handle the host
|
||||
//! has: where the runtime makes the surface, each of its three frames reads back the picture the
|
||||
//! - The exported-surface snippet (`snippets::video_surfaces`) plays for each fd handle, on Linux
|
||||
//! and macOS (the stand-in's hosts), under the validation layer: where the runtime makes the surface, each of its three frames reads back the picture the
|
||||
//! stand-in for the other API wrote (its checks match our bytes), and each frame's hand-overs
|
||||
//! (`external_acquires`, `external_releases`) are what the runtime's documented contract gives
|
||||
//! for the frame's records; where the device exports no such handle, the refusal is counted.
|
||||
@@ -135,8 +135,8 @@
|
||||
|
||||
use crate::gpu::{self, DeviceType};
|
||||
use crate::replay::{
|
||||
video_surfaces, Backend, CommandBufferList, NewRuntime, PlayError, Player, ReadCopy, Report,
|
||||
StreamReader, StreamWriter, Value, VideoHandle, VIDEO_PICTURES, WAIT_COMPLETED,
|
||||
Backend, CommandBufferList, NewRuntime, PlayError, Player, ReadCopy, Report, StreamReader,
|
||||
StreamWriter, Value, WAIT_COMPLETED,
|
||||
};
|
||||
use crate::ScratchDir;
|
||||
use metal2vulkan_devtools::metallib::{metallib, wrap, MtlbFunction};
|
||||
@@ -4082,6 +4082,7 @@ fn a_video_surface_is_waited_for_at_its_ready_point_once() {
|
||||
|
||||
/// The validation tools `device`'s physical device lists as active (`VK_LAYER_KHRONOS_validation`
|
||||
/// where the loader found it).
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
fn validation_tools(device: &metal2vulkan_runtime::Device) -> usize {
|
||||
use ash::vk;
|
||||
let raw = device.raw();
|
||||
@@ -4106,18 +4107,17 @@ fn validation_tools(device: &metal2vulkan_runtime::Device) -> usize {
|
||||
/// API wrote it, and the runtime's reads see it through the hand-over), and every frame's
|
||||
/// acquires and releases are what the runtime's documented contract gives for the frame's
|
||||
/// records (the report's `hand-over` line); where the device exports no such handle, the
|
||||
/// refusal is counted and the handle passed over. Each frame's numbers are printed. On Linux and
|
||||
/// macOS each play runs under the Khronos validation layer, as the candidate runs do
|
||||
/// (`candidate::validated`): the device lists it as an active tool, and any message it logs, the
|
||||
/// stand-in's device's among them (it lives on the runtime's instance), fails the test.
|
||||
/// refusal is counted and the handle passed over. Each frame's numbers are printed. Each play runs
|
||||
/// under the Khronos validation layer, as the candidate runs do (`candidate::validated`): the
|
||||
/// device lists it as an active tool, and any message it logs, the stand-in's device's among them
|
||||
/// (it lives on the runtime's instance), fails the test. Linux's and macOS's: the stand-in is
|
||||
/// theirs alone (`new_runtime::standin`).
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[test]
|
||||
fn an_exported_surface_hands_each_picture_over_as_the_runtime_s_contract_says() {
|
||||
#[cfg(unix)]
|
||||
let handles = [VideoHandle::DmaBuf, VideoHandle::OpaqueFd];
|
||||
#[cfg(windows)]
|
||||
let handles = [VideoHandle::OpaqueWin32];
|
||||
use crate::replay::{video_surfaces, VideoHandle, VIDEO_PICTURES};
|
||||
let mut made = 0;
|
||||
for handle in handles {
|
||||
for handle in [VideoHandle::DmaBuf, VideoHandle::OpaqueFd] {
|
||||
let name = format!("video-handover-{}", handle.name());
|
||||
let dir = ScratchDir::new(&name).unwrap();
|
||||
let path = written(&dir, |w| video_surfaces(w, handle));
|
||||
@@ -4128,16 +4128,10 @@ fn an_exported_surface_hands_each_picture_over_as_the_runtime_s_contract_says()
|
||||
let (report, lines, ()) = play_on(device, &name, &path, |_| ());
|
||||
(report, lines, tools)
|
||||
};
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
let (report, lines) = {
|
||||
let ((report, lines, tools), messages) = crate::candidate::validated(played);
|
||||
assert!(tools > 0, "{name}: the device lists no validation tool");
|
||||
assert_eq!(messages, None, "{name}: the validation layer's messages");
|
||||
eprintln!("REPLAY {name} validation tools {tools}, no layer message");
|
||||
(report, lines)
|
||||
};
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
let (report, lines, _) = played();
|
||||
let ((report, lines, tools), messages) = crate::candidate::validated(played);
|
||||
assert!(tools > 0, "{name}: the device lists no validation tool");
|
||||
assert_eq!(messages, None, "{name}: the validation layer's messages");
|
||||
eprintln!("REPLAY {name} validation tools {tools}, no layer message");
|
||||
let total = &report.total.executed;
|
||||
if total["exported_surfaces_refused"] > 0 {
|
||||
assert_eq!(total["exported_surfaces_refused"], 1, "{lines:?}");
|
||||
|
||||
@@ -989,12 +989,14 @@ contract (below) where the surface is made, and each check matches where the sta
|
||||
a skipped object, counted by its reason; a handle this host has none of (an NT handle on Unix,
|
||||
an fd on Windows) stops the play, which `--video-handle` avoids. At `m2v.exportSurface` the
|
||||
player waits for the surface's ready point (`Surface::wait_until_ready`). The other API that
|
||||
wrote the pictures where the stream was recorded is not there on replay, so a Vulkan device of
|
||||
the player's own, on the runtime's instance and physical device, stands in for it: at the
|
||||
surface's first export it imports the handle as one buffer over the whole memory (an opaque
|
||||
handle at the size and memory type it was exported with, in an allocation dedicated to the
|
||||
buffer only where the driver requires one; a dma-buf into a memory type its fd's query lists,
|
||||
dedicated). At `m2v.surfaceWritesDone` the player first waits for every committed command
|
||||
wrote the pictures where the stream was recorded is not there on replay, so on Linux and macOS
|
||||
a Vulkan device of the player's own, on the runtime's instance and physical device, stands in
|
||||
for it: at the surface's first export it imports the handle, an fd, as one buffer over the whole
|
||||
memory (an opaque fd at the size and memory type it was exported with, in an allocation
|
||||
dedicated to the buffer only where the driver requires one; a dma-buf into a memory type its
|
||||
fd's query lists, dedicated). On Windows nothing stands in for it: the stand-in's writes wait
|
||||
under the validation crate's bounded fence waits, which only Linux and macOS have, so there
|
||||
each landing is counted unwritten with that reason. At `m2v.surfaceWritesDone` the player first waits for every committed command
|
||||
buffer that can complete, as the other API writes a picture after the work before it; then the
|
||||
stand-in copies each plane's rows into the memory at the play's layout (`SurfaceExport::planes`:
|
||||
each plane's first byte and row pitch), or, where the record holds no bytes, fills the whole
|
||||
|
||||
Reference in new issue
Block a user