The cutover's last mechanical step. The old runtime is deleted, so its name is free: the crate moves to crates/metal2vulkan-runtime, its package is metal2vulkan-runtime and its library metal2vulkan_runtime, and every reference in the tree follows (sources, tests, scripts, CI, generated tables and docs). It is now a published crate, as AGENTS.md said it would be once it took the name: version 0.2.0 with the other two, the translator pinned exactly (=0.2.0, as the translator pins the AIR front end), documentation, keywords and categories, and copies of the repository's four license files, which the published-crates test now holds equal to the root's for three crates. CI packages it with the others. Prose that said it was unpublished, or counted two published crates, says three. AGENTS.md: facts only. The crate table row, the published-crates and version sentences, and the paragraph on the old runtime, whose name the runtime now carries (listed for the owner). Made by one script run on this tip. Verified by the job named in the landing note.
73 lines
3.6 KiB
Rust
73 lines
3.6 KiB
Rust
//! Every read the runtime makes of memory the GPU writes. A guest shader holds raw device
|
|
//! addresses, so any value read here may be forged. Each function bounds what its value can
|
|
//! decide to the reading command buffer's own guest-visible results: it never fails, stalls or
|
|
//! ends anything else, and never indexes host memory with the value. A rule test holds every such
|
|
//! read to this module, and the runtime's README lists the sites.
|
|
|
|
use ash::vk;
|
|
|
|
/// A completed command buffer's two timestamps, from its pair in the device's pools; None where
|
|
/// the driver does not report both available, so the command buffer's GPU times stay 0.
|
|
///
|
|
/// The read does not wait (no `VK_QUERY_RESULT_WAIT_BIT`). A submission the device cancelled at a
|
|
/// reset may still signal its progress value having run nothing, its queries never made
|
|
/// available: a waiting read of them runs until the driver gives up (RADV: twice the kernel's
|
|
/// 60 s compute timeout), and the read without the wait reports no times at once
|
|
/// ("`vkGetQueryPoolResults` may return `VK_NOT_READY` if there are queries in the unavailable
|
|
/// state").
|
|
///
|
|
/// The caller reads a pair only once a host wait of the completion thread has seen its submission's
|
|
/// progress value (with one value pending, a wait with a timeout of 0 on it; with more, that wait
|
|
/// on the value the counter read found). The read has no wait bit, and Vulkan defines a dependency
|
|
/// on the timestamp writes only for a read with `VK_QUERY_RESULT_WAIT_BIT`: the signal says nothing
|
|
/// about the queries' availability, so a pair can read as not available though its submission ran,
|
|
/// as from a driver that makes timestamps available only after the signal (MoltenVK 1.4.2 on an M3
|
|
/// Max did, for most command buffers; it is below the floor). Such a pair leaves the GPU times 0
|
|
/// with no other sign, so the caller counts each pair that reads as not available
|
|
/// (`Metrics::stamps_not_available`), and every play and suite leg reports the count.
|
|
///
|
|
/// Bound: the values only decide that command buffer's `GPUStartTime`, through arithmetic defined
|
|
/// for every value that gives a time no later than its `GPUEndTime`.
|
|
///
|
|
/// # Safety
|
|
///
|
|
/// `pool` is a timestamp pool of `device` with the queries `first` and `first + 1`, which no other
|
|
/// thread resets while it reads.
|
|
pub(crate) unsafe fn timestamps(
|
|
device: &ash::Device,
|
|
pool: vk::QueryPool,
|
|
first: u32,
|
|
) -> Option<(u64, u64)> {
|
|
let mut values = [0_u64; 2];
|
|
// SAFETY: by the caller; `values` holds two 64-bit results.
|
|
let read = unsafe {
|
|
device.get_query_pool_results(pool, first, &mut values, vk::QueryResultFlags::TYPE_64)
|
|
};
|
|
read.ok().map(|()| (values[0], values[1]))
|
|
}
|
|
|
|
/// Copies `runs` (each an offset in `bytes`, one in `staging`, and a length) from a staging buffer
|
|
/// the GPU copied a texture's bytes into, for `Texture::get_bytes`.
|
|
///
|
|
/// Bound: the bytes only reach the caller's buffer as the texture's bytes; the offsets and the
|
|
/// length come from the call's checked region, never from the bytes, and the read does not wait.
|
|
///
|
|
/// # Safety
|
|
///
|
|
/// `staging` maps each run's staging offset plus its length, the copy into it completed and its
|
|
/// writes are visible to the host, and each run's offset plus its length lies in `bytes`.
|
|
pub(crate) unsafe fn texels(
|
|
staging: *const u8,
|
|
bytes: &mut [u8],
|
|
runs: impl Iterator<Item = (usize, usize, usize)>,
|
|
) {
|
|
for (to, from, len) in runs {
|
|
// SAFETY: by the caller.
|
|
unsafe {
|
|
staging
|
|
.add(from)
|
|
.copy_to_nonoverlapping(bytes.as_mut_ptr().add(to), len)
|
|
};
|
|
}
|
|
}
|