diff --git a/crates/reims-vgpu-vulkan/src/rt_platform/buffer.rs b/crates/reims-vgpu-vulkan/src/rt_platform/buffer.rs index 074221cc7..fb190956a 100644 --- a/crates/reims-vgpu-vulkan/src/rt_platform/buffer.rs +++ b/crates/reims-vgpu-vulkan/src/rt_platform/buffer.rs @@ -145,12 +145,14 @@ //! refuses their pointer) are //! imported as a copy (`super::copied`), as rt refused nothing: a Shared block of rt's own that //! holds their bytes, which no import makes, so a texture over a buffer in it lies in place where -//! the device's linear image takes the texture, as over any Shared block of rt's. A buffer in the -//! copy's block answers the pages as its `contents`, and a pinned buffer over the pages is a range -//! of the block, as over a dma-buf's ([`KnownBlocks`]); such a pinned buffer holds the copy and -//! syncs it as the copy's own buffer does, its GPU writes dropped where the copy's are. The copy -//! is synced byte by byte: at each commit that uses it the bytes the CPU changed in the pages -//! since they and the copy last agreed are written into the copy, and at each completion of a +//! the device's linear image takes the texture, as over any Shared block of rt's; an image for +//! views in place over one is refused (`RtObj::::new_texture_in_place_for_views`). A +//! buffer in the copy's block answers the pages as its `contents`, and a pinned buffer over the +//! pages is a range of the block, as over a dma-buf's ([`KnownBlocks`]); such a pinned buffer +//! holds the copy and syncs it as the copy's own buffer does, its GPU writes dropped where the +//! copy's are. The copy is synced byte by byte: at each commit that uses it the bytes the CPU +//! changed in the pages since they and the copy last agreed are written into the copy, and at +//! each completion of a //! command buffer whose uses of it can write it, before its completed handlers run or a waiter //! returns, the bytes the GPU changed in the copy are written into the pages where the CPU did not //! change them since, a byte both changed keeping the CPU's. A blit syncs only the byte ranges it @@ -2844,9 +2846,15 @@ impl RtObj { /// no texture made and no copy counted, where rt would make the counted copy, its why the /// copies' cause ([`over_cause_why`]); refused as "recording" while the process records, /// whose stream holds no such make, and as "refused" where rt refuses it otherwise, counted - /// as rt's refusals are. Shaders reach it through its views alone, each at the guest's index: - /// it is never bound to a slot itself, as no guest texture is the image, only its views. A - /// make that copies the bytes under it out and back runs `fence` around that span + /// as rt's refusals are. Refused as "copied", with nothing asked of rt, where the buffer lies + /// in a copy of the host's pages (the module's docs, "A copy at the refusal point"): a command + /// buffer syncs a copy with its pages only through the objects it uses that name the copy + /// from their make (`super::copied`'s `Used`), and a view a retarget moves onto the image + /// from another (`super::texture`'s docs, "Retargets") names what it was made over, so the + /// pages would miss the GPU's writes through such a view, and the view the CPU's writes to + /// the pages. Shaders reach it through its views alone, each at the guest's index: it is + /// never bound to a slot itself, as no guest texture is the image, only its views. A make + /// that copies the bytes under it out and back runs `fence` around that span /// ([`RestoreFence`]), and is refused with the fence's why where `before` refuses. pub fn new_texture_in_place_for_views( &self, @@ -2858,6 +2866,9 @@ impl RtObj { if crate::recorder::on() { return Err("recording"); } + if self.copied.is_some() { + return Err("copied"); + } let sel = "newTextureWithDescriptor:offset:bytesPerRow:"; let d = rt_texture_descriptor(desc).map_err(|_| "descriptor")?; let made = self.made(Some(MemoryFor::Texture)).ok_or("memory")?; @@ -6148,6 +6159,53 @@ mod tests { assert_eq!(read(c.copy, 256), [0x22; 256]); } + /// On the GPU the test holds: an image for views in place over a buffer that lies in a copy of + /// the host's pages whose GPU writes reach them (the import's floor where rt takes neither + /// their pointer nor a dma-buf of theirs) is refused as "copied", with no texture made: its + /// views, and those a retarget moves onto it, would name no copy, so the command buffers that + /// use them would sync none, and the pages would miss the GPU's writes through them and they + /// the CPU's (`RtObj::::new_texture_in_place_for_views`). An IOSurface's shape then + /// takes an image of its own, as for any refusal (reims-vgpu's `surface_cache::shapes`, "In + /// place"). + #[test] + fn an_image_for_views_over_a_merging_copy_is_refused_on_vulkan() { + let platform = RtPlatform::new(); + let device = (platform.system_default_device()).expect("an rt device on the GPU it holds"); + let c = over_a_copy(&device, false); + assert!(!c.drops, "a copy whose GPU writes reach the pages"); + let align = device + .rt() + .minimum_linear_texture_alignment(rt::PixelFormat::BGRA8Unorm); + let pitch = (4 * 64_u64).next_multiple_of(align.expect("BGRA8Unorm's alignment")); + let desc = TextureDesc { + pixel_format: 80, + width: 64, + height: 2, + usage: 0x1, + ..TextureDesc::default() + }; + let mut fence = Unasked; + let made = (c.buffer).new_texture_in_place_for_views(&desc, 0, pitch, &mut fence); + assert_eq!( + made.err(), + Some("copied"), + "no image in place over the copy" + ); + } + + /// A fence no make reaches: each of its calls fails the test. + struct Unasked; + + impl RestoreFence for Unasked { + fn before(&mut self) -> Result<(), &'static str> { + panic!("nothing asked of rt over a copy"); + } + + fn after(&mut self) { + panic!("nothing asked of rt over a copy"); + } + } + /// On the GPU the test holds: the completed handlers of a command buffer whose use of a copy /// can write it are handed on off rt's completion thread (`super::super::command`'s docs, /// "Handed on"): its wait returns once they ran, the copy's bytes merged back first, and those