diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 782755672..566524ebf 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1129,10 +1129,18 @@ made, with no lock, and never rewritten for layouts. takes the ID: the new object writes its elements (a texture with no storage view writes its storage element null where it took the index from another, so nothing stale answers there), and the earlier object's going, at its release or once its command buffers retire, touches - neither the index nor its elements. No work in flight may read a displaced object through the - index: the program's duty, as it is Metal's, which the runtime does not check. A released one - it may: a texture's index, elements, views and image, a texture view's views, and a sampler - state's index and device samplers go once every command buffer committed before the release + neither the index nor its elements. Taking an index that a released object still holds for a + command buffer not yet retired writes elements that work in flight may use, a write Vulkan does + not define (an element of these bindings may change while a command buffer that uses the set is + pending only where no shader invocation uses it). Not asking for one is the consumer's duty, not + the program's: Metal hands a released ID out again at once (seen on a Radeon Pro 5300M), so a + program can be given the ID of an object that work in flight still reads. A consumer keeps a + released ID back from the program until every command buffer committed before the release has + retired. The runtime does not check it, and does not refuse the placement: from that retirement + until the vacate below, the index is still the released object's and a placement is defined; + the displaced form is for that window. Work in flight may read a released object that still + holds its index: a texture's index, elements, views and image, a texture view's views, and a + sampler state's index and device samplers go once every command buffer committed before the release has retired, at once where none is in flight, so that work reads them as they were (`Gauges::releases_waiting` counts what waits). Metal leaves that read undefined: a program that released textures a frame in flight still sampled finished every run with no command buffer @@ -1144,7 +1152,7 @@ made, with no lock, and never rewritten for layouts. work in flight: equal create infos share the device's `VkSampler`s, the arrays keep the samplers last written at each index, and an element that holds its sampler already is not written, so the placement changes no descriptor that pending work reads (`Metrics::sampler_element_writes` counts the elements - written). A different sampler state stays the program's duty. + written). A different sampler state stays the consumer's duty. Making one at an index not granted is `Refusal::IndicesNotGranted`. Where nothing took it, the index is free again once its owner's last handle is gone, and with it the last command buffer that used it: at once where nothing was in flight then, and otherwise once every command buffer diff --git a/crates/metal2vulkan-runtime/src/arrays.rs b/crates/metal2vulkan-runtime/src/arrays.rs index cd4dfd683..a324a5e63 100644 --- a/crates/metal2vulkan-runtime/src/arrays.rs +++ b/crates/metal2vulkan-runtime/src/arrays.rs @@ -335,8 +335,8 @@ impl Arrays { /// /// Each view is live and of the device, of an image in that layout whenever work uses it, /// `looped` only where the set was made with the second elements and the image has the - /// feedback usage, and no work in flight reads a displaced texture through the index (the - /// program's duty, as it is Metal's). + /// feedback usage, and where it displaces, no work in flight uses the index's elements (the + /// consumer's duty: Vulkan does not define that write). pub(crate) unsafe fn place_texture( &self, device: &ash::Device, @@ -512,8 +512,9 @@ impl Arrays { /// /// # Safety /// - /// Each sampler is live and of the device whenever work uses it, and no work in flight reads - /// a displaced object through the index. + /// Each sampler is live and of the device whenever work uses it, and where it displaces, no + /// work in flight uses an element it writes (the consumer's duty: Vulkan does not define that + /// write). pub(crate) unsafe fn place_samplers( &self, device: &ash::Device, @@ -538,7 +539,8 @@ impl Arrays { /// # Safety /// /// No pending work uses an element of `added`, each sampler is live and of the device - /// whenever work uses it, and no work in flight reads a displaced object through the index. + /// whenever work uses it, and where it displaces, no work in flight uses an element it + /// writes (the consumer's duty: Vulkan does not define that write). pub(crate) unsafe fn hold_samplers( &self, device: &ash::Device, diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index c78a8cba8..79bc15837 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -923,9 +923,12 @@ impl Device { /// buffer not yet retired still holds, is taken at once, as Metal's later texture at a /// resource ID takes the ID: the new texture owns the index and its elements from then, and /// the earlier one's going, at its release or once its command buffers retire, touches - /// neither. No work in flight may read a displaced texture through the index (the program's - /// duty, as it is Metal's; nothing checks it). A released one it may: its index, elements, - /// views and image go once every command buffer committed before the release retired + /// neither. Work in flight must not use the index's elements then: Vulkan does not define + /// that write. Keeping it away is the consumer's duty, not the program's, as Metal hands a + /// released ID out again at once (seen on a Radeon Pro 5300M): a consumer keeps a released ID + /// back from the program until every command buffer committed before the release has retired. + /// Nothing checks it. Work in flight may read a released texture that still holds its index: + /// its index, elements, views and image go once every command buffer committed before the release retired /// ([`Gauges::releases_waiting`](crate::Gauges::releases_waiting)), the index then on the /// block-maker thread's next pass, so that work reads it as it was. Metal leaves that read /// undefined: a program that released textures a frame in flight still sampled finished every diff --git a/docs/REPLAY-STREAM.md b/docs/REPLAY-STREAM.md index 6a803bb13..fe06044b9 100644 --- a/docs/REPLAY-STREAM.md +++ b/docs/REPLAY-STREAM.md @@ -227,8 +227,8 @@ and the (name id, value) answer pairs. it, as Metal's later texture at an ID takes the ID: the earlier object's release leaves the index. A placement at an index waits first for the commits of the command buffers that named an object while it held the index, live or released since, to retire (their completed handlers have run, which the runtime runs once it - has let go of what they held): Metal leaves it to the program never to take an element from - under work that runs, and the program's own timing kept that. An object named after a later + has let go of what they held): the runtime leaves it to its consumer never to write an + element that work in flight may use. An object named after a later one took its index holds it no more: the index is the later one's, and that naming owes it nothing. Where the runtime refuses a named index (it lies outside the object's class), the object takes the lowest free one, and the report counts it. A constexpr sampler, which the stream names diff --git a/docs/RESOURCE-ID.md b/docs/RESOURCE-ID.md index 875c43107..92b504201 100644 --- a/docs/RESOURCE-ID.md +++ b/docs/RESOURCE-ID.md @@ -38,8 +38,12 @@ the program released that work in flight still holds, writes its elements and ow once; where the earlier texture had a storage element and the later has none, the later one writes that element null, so nothing stale answers there. The earlier object's release, and its teardown once its work retires, touch neither the index nor its elements; the owner's empties -them. The rule rests on the duty Metal puts on a program: no work in flight reads a displaced or -released object through that ID. The runtime does not check it. +them. Vulkan does not define that write where work in flight uses the element. Keeping it away is +the consumer's duty, not the program's: Metal hands a released ID out again at once (seen on a +Radeon Pro 5300M), so a consumer keeps a released ID back from the program until every command +buffer committed before the release has retired. The runtime does not check it, and does not refuse +the placement: between that retirement and the index's vacate the placement is defined, and the +displaced form is for that window. ## The arrays