diff --git a/Cargo.lock b/Cargo.lock index 68740df9e..9dfb606e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index ce1ce2bd6..0eca58884 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/crates/reims-vgpu-vulkan/src/core/platform/device.rs b/crates/reims-vgpu-vulkan/src/core/platform/device.rs index d14bb517c..651e0dca2 100644 --- a/crates/reims-vgpu-vulkan/src/core/platform/device.rs +++ b/crates/reims-vgpu-vulkan/src/core/platform/device.rs @@ -320,6 +320,10 @@ pub trait GpuDevice: 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; + /// 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; /// 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 diff --git a/crates/reims-vgpu-vulkan/src/core/testkit/impls/device.rs b/crates/reims-vgpu-vulkan/src/core/testkit/impls/device.rs index de6b011dc..fc878fb38 100644 --- a/crates/reims-vgpu-vulkan/src/core/testkit/impls/device.rs +++ b/crates/reims-vgpu-vulkan/src/core/testkit/impls/device.rs @@ -490,6 +490,11 @@ impl GpuDevice for Fk { })) } + fn new_cache_transfer_queue(&self) -> Option<::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 diff --git a/crates/reims-vgpu-vulkan/src/rt_platform/device.rs b/crates/reims-vgpu-vulkan/src/rt_platform/device.rs index d9cef6c3b..2dff0b786 100644 --- a/crates/reims-vgpu-vulkan/src/rt_platform/device.rs +++ b/crates/reims-vgpu-vulkan/src/rt_platform/device.rs @@ -2274,6 +2274,18 @@ impl GpuDevice for RtObj { recorded_answer } + fn new_cache_transfer_queue(&self) -> Option> { + 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] diff --git a/crates/reims-vgpu/src/graphics/decode/surface_cache.rs b/crates/reims-vgpu/src/graphics/decode/surface_cache.rs index 23cb533de..08930e7a0 100644 --- a/crates/reims-vgpu/src/graphics/decode/surface_cache.rs +++ b/crates/reims-vgpu/src/graphics/decode/surface_cache.rs @@ -2634,10 +2634,9 @@ impl CarriedPages { /// The host's transfer queue, on which every copy runs, and the event its fills signal. struct Transfer { - /// 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 Transfer

{ /// A transfer queue and its event, its fills telling `hook`; `None` where the platform makes /// either not. fn new(device: &P::Device, hook: &Arc>) -> RaiseResult> { - 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 {