Merge pull request #8 from liuyaxuan123457-ctrl/fix/iosurface-transfer-recording
Queue Runtime Alpha / alpha (push) Waiting to run

Prevent IOSurface cache fills from waiting on their own uncommitted copies
This commit is contained in:
千川白浪 authored and GitHub committed 2026-12-05 14:07:43 +08:00
commit b7df96f018
6 files changed
+80 -10

No files matched your search

Generated
+3 -3
View File
@@ -213,7 +213,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "metal2vulkan"
version = "0.2.0"
source = "git+https://github.com/reims-go/metal2vulkan?rev=1dd4e970c0562c73bd3eba12cd15999bb035e019#1dd4e970c0562c73bd3eba12cd15999bb035e019"
source = "git+https://github.com/reims-go/metal2vulkan?rev=8fd7fb5d9cf2df9164b121995b63187f95a3a191#8fd7fb5d9cf2df9164b121995b63187f95a3a191"
dependencies = [
"ash",
"metal2vulkan-air",
@@ -224,7 +224,7 @@ dependencies = [
[[package]]
name = "metal2vulkan-air"
version = "0.2.0"
source = "git+https://github.com/reims-go/metal2vulkan?rev=1dd4e970c0562c73bd3eba12cd15999bb035e019#1dd4e970c0562c73bd3eba12cd15999bb035e019"
source = "git+https://github.com/reims-go/metal2vulkan?rev=8fd7fb5d9cf2df9164b121995b63187f95a3a191#8fd7fb5d9cf2df9164b121995b63187f95a3a191"
dependencies = [
"sha2 0.11.1",
]
@@ -232,7 +232,7 @@ dependencies = [
[[package]]
name = "metal2vulkan-runtime"
version = "0.2.0"
source = "git+https://github.com/reims-go/metal2vulkan?rev=1dd4e970c0562c73bd3eba12cd15999bb035e019#1dd4e970c0562c73bd3eba12cd15999bb035e019"
source = "git+https://github.com/reims-go/metal2vulkan?rev=8fd7fb5d9cf2df9164b121995b63187f95a3a191#8fd7fb5d9cf2df9164b121995b63187f95a3a191"
dependencies = [
"ash",
"libc",
+2 -2
View File
@@ -33,11 +33,11 @@ reims-vgpu-graphics = { path = "crates/reims-vgpu-graphics" }
reims-vgpu-video = { path = "crates/reims-vgpu-video" }
# metal2vulkan's Metal types, for the Metal enums and descriptor values the runtime's calls take,
# from metal2vulkan's public repository at the commit both name.
metal2vulkan = { git = "https://github.com/reims-go/metal2vulkan", rev = "1dd4e970c0562c73bd3eba12cd15999bb035e019" }
metal2vulkan = { git = "https://github.com/reims-go/metal2vulkan", rev = "8fd7fb5d9cf2df9164b121995b63187f95a3a191" }
# The Vulkan platform's runtime (architecture D1), metal2vulkan-runtime: a Metal-shaped API on
# Vulkan, one path for every device, under reims-vgpu-vulkan's `rt_platform` and `seam` and
# reims-vgpu's `pool::rt_blocks`.
metal2vulkan-runtime = { git = "https://github.com/reims-go/metal2vulkan", rev = "1dd4e970c0562c73bd3eba12cd15999bb035e019" }
metal2vulkan-runtime = { git = "https://github.com/reims-go/metal2vulkan", rev = "8fd7fb5d9cf2df9164b121995b63187f95a3a191" }
# The hashes of the Vulkan platform's metallib sources (reims-vgpu-vulkan/build.rs).
sha2 = "0.10.9"
# A display window's swapchain on Linux (reims-vgpu-vulkan/src/swapchain.rs), at the runtime's
@@ -320,6 +320,10 @@ pub trait GpuDevice<P: Platform>: Handle {
/// queue between command queues answers `new_command_queue`'s queue. Never nil-checked; a raise
/// inside it dies at the call, as one inside `newCommandQueue` does.
fn new_command_queue_unshared(&self) -> Option<P::CommandQueue>;
/// The private IOSurface copy FIFO. A cache transaction may record all its copies before
/// it can publish any of them. Allocating a command buffer here must not wait for a
/// previously recorded copy to retire. GPU execution still follows queue order.
fn new_cache_transfer_queue(&self) -> Option<P::CommandQueue>;
/// No Metal counterpart: how many times the platform recovered the device's GPU so far, its
/// lost device made again behind the same device object (the Vulkan platform's runtime makes
/// a new `VkDevice`, `device-recovered`). The textures, pipelines and pooled buffers made
@@ -490,6 +490,11 @@ impl GpuDevice<FakePlatform> for Fk<kind::Device> {
}))
}
fn new_cache_transfer_queue(&self) -> Option<<FakePlatform as Platform>::CommandQueue> {
// Fake queues allocate independent handles immediately.
self.new_command_queue_unshared()
}
/// Unlogged, as the property the platform answers it from: [`World::copy_guest_ram`].
///
/// [`World::copy_guest_ram`]: crate::core::testkit::objects::World::copy_guest_ram
@@ -2274,6 +2274,18 @@ impl GpuDevice<RtPlatform> for RtObj<RtDevice> {
recorded_answer
}
fn new_cache_transfer_queue(&self) -> Option<RtObj<RtQueue>> {
let call = crate::recorder::rec_call!("m2v.newCacheTransferQueue", self);
let queue = crate::recorder::run(|| {
Some(RtObj::new(RtQueue::new(
self.rt.new_host_batch_queue(),
self.clone_ref(),
)))
});
crate::recorder::rec_done!(call, queue);
queue
}
/// No: rt copies no guest RAM by its host addresses.
fn copies_guest_ram(&self) -> bool {
false
@@ -3164,6 +3176,56 @@ mod tests {
use crate::core::platform::device::relaying_gaps;
use crate::core::platform::values::{OptionSet, TextureDesc};
#[test]
fn a_cache_transfer_batch_publishes_its_bytes_to_a_waiting_queue() {
use crate::core::platform::command::{CommandBuffer as _, CommandQueue as _};
let platform = RtPlatform::new();
let device = platform.system_default_device().expect("a Vulkan device");
let copies = device.new_cache_transfer_queue().expect("cache transfers");
let consumer = device.new_command_queue().expect("a guest queue");
let shared = || {
device
.new_buffer_of_length(OnFault::Return, 16, 0)
.unwrap()
.unwrap()
};
let (source, destination) = (shared(), shared());
let filled = device.rt().new_event().unwrap();
let done = device.rt().new_shared_event().unwrap();
let mut batch = Vec::new();
for value in 1..=3 {
let copy = copies.command_buffer(OnFault::Return).unwrap().unwrap();
let mut blit = copy.rt().blit_command_encoder().unwrap();
blit.fill_buffer(source.rt(), 0..16, value).unwrap();
blit.end_encoding();
copy.rt()
.encode_signal_event(&filled, u64::from(value))
.unwrap();
batch.push(copy);
}
let read = consumer.command_buffer(OnFault::Return).unwrap().unwrap();
read.rt().encode_wait_for_event(&filled, 3).unwrap();
let mut blit = read.rt().blit_command_encoder().unwrap();
blit.copy_from_buffer_to_buffer(source.rt(), 0, destination.rt(), 0, 16)
.unwrap();
blit.end_encoding();
read.rt().encode_signal_event(done.as_event(), 1).unwrap();
read.commit(OnFault::Return).unwrap();
for copy in batch {
copy.commit(OnFault::Return).unwrap();
}
assert!(
done.wait_until_signaled_value(1, std::time::Duration::from_secs(10))
.unwrap()
);
let at = destination.rt().contents().expect("shared storage");
// SAFETY: the GPU signal covers the final copy, the allocation is 16 bytes and kept
// alive by destination, and there are no further writers.
let bytes = unsafe { std::slice::from_raw_parts(at.as_ptr(), 16) };
assert_eq!(bytes, &[3; 16]);
}
/// The options a device is opened with carry the helper's memory ceiling on this host, the
/// one a memory breach is kept under.
#[test]
@@ -2634,10 +2634,9 @@ impl CarriedPages {
/// The host's transfer queue, on which every copy runs, and the event its fills signal.
struct Transfer<P: Platform> {
/// Unshared ([`new_command_queue_unshared`]): a present of a surface waits for its fill, and
/// a frame drawn from a cache for the fill before it ([`FillWait`]).
///
/// [`new_command_queue_unshared`]: reims_vgpu_vulkan::core::platform::device::GpuDevice::new_command_queue_unshared
/// Private copy FIFO. A transaction can prepare all of its fills under the cache lock and
/// publish them in order after unlocking. Presents and consumers wait for their fill
/// ([`FillWait`]).
queue: P::CommandQueue,
/// The early copies behind writers that hold no video encoder
/// ([`SurfaceCaches::early_copies`]), apart from the fills, so neither waits behind the
@@ -2659,7 +2658,7 @@ impl<P: Platform> Transfer<P> {
/// A transfer queue and its event, its fills telling `hook`; `None` where the platform makes
/// either not.
fn new(device: &P::Device, hook: &Arc<OnceLock<FillHook>>) -> RaiseResult<Option<Self>> {
let Some(queue) = device.new_command_queue_unshared() else {
let Some(queue) = device.new_cache_transfer_queue() else {
return Ok(None);
};
let Some(event) = device.new_event(ON)? else {