pub struct VkSlotRelease { /* private fields */ }Expand description
Consumer→producer slot-release back-pressure carrier.
Pairs a per-slot Arc<AtomicU64> “gate” with a value the consumer
is expected to publish into it once the consumer has finished reading
from the producer’s slot. Used by ring-pool producers (e.g. an
FFmpeg-Vulkan intermediate ring, SDK exporters) to prevent
overwriting a slot the consumer’s GPU is still sampling — without
this gate, a fast producer (a hardware decoder feeding a
high-frame-rate wgpu render loop, say) cycles back to a slot while the
consumer’s compute / blit shader is still reading the same
VkDeviceMemory through its imported VkImage, triggering a
write-after-read hazard that surfaces as a GPU fault
(VK_ERROR_DEVICE_LOST on the producer’s next vkQueueSubmit2).
§Protocol
- Producer publishes carrier for frame
Nwith slotK. Carrier holdsVkSlotRelease { gate: G_prev, value: V_prev }— the PREVIOUS frame’s gate + value, NOT this frame’s. - Consumer’s import path registers a wgpu
wgpu::Queue::on_submitted_work_donecallback that storesvalueintogate(release ordering). The callback’s snapshot captures every queued submit up to the registration point — which by usage contract includes the user’s frameN-1render submission (because the user is expected to submit each frame’s work between consecutive decode→import calls). The callback therefore fires only after the user’s frameN-1render has retired on the GPU, at which point the slot is no longer being sampled and is safe to reuse. - Producer’s pool, before reusing slot
K_previn frameN+1(cycle 2 of its ring), CPU-waits forG_prev.load(Acquire) >= V_prev. Steady-state this is a zero-cost atomic load (the callback has already fired); under tail-latency or stalled-consumer conditions the producer yields until the consumer catches up — proper back-pressure rather than blind overwrite.
§Why ARC, not a sender / channel?
Arc<AtomicU64> is the minimal primitive that satisfies the
requirement: lock-free store from the wgpu polling thread’s callback +
lock-free load from the producer thread’s pre-write check, with
release/acquire ordering establishing the necessary happens-before
edge. No allocation per frame, no channel-send overhead, no per-frame
mutex contention. Clone is one refcount bump.
§Usage contract
This carrier is only meaningful when the user follows the “submit each frame’s render between consecutive decodes” pattern (which is the standard video-playback loop). Batched / out-of-order rendering would register the callback before the relevant render submit, firing the gate too early and re-enabling the race. Producers that publish this carrier therefore assume the standard loop; mis-use would corrupt rendered output but not crash — the QFOT acquire still gates per-Vulkan-spec memory visibility.
§Lifetime
The producer owns the long-lived per-slot Arc<AtomicU64> (one per
pool slot, allocated once at pool init). Each per-frame carrier
clones that Arc cheaply. The consumer’s on_submitted_work_done
closure captures its own Arc clone; once the closure runs (or the
queue is torn down with the closure unrun), the closure’s Arc drops
and the count returns to producer-only. No cyclic ownership.
Implementations§
Source§impl VkSlotRelease
impl VkSlotRelease
Sourcepub fn new(gate: Arc<AtomicU64>, value: u64) -> Self
pub fn new(gate: Arc<AtomicU64>, value: u64) -> Self
Construct from a producer-owned gate Arc and the value the consumer should publish once its prior-frame render retires.
Sourcepub fn gate(&self) -> &Arc<AtomicU64> ⓘ
pub fn gate(&self) -> &Arc<AtomicU64> ⓘ
Borrow the gate Arc (for cloning into a callback closure).
Sourcepub fn value(&self) -> u64
pub fn value(&self) -> u64
The value the consumer must store into Self::gate when its
prior-frame render has retired. Producer-side reuse logic CPU-waits
for gate.load(Acquire) >= value before overwriting the
associated slot.
Sourcepub fn release_now(&self)
pub fn release_now(&self)
Convenience helper for consumers that don’t need a delayed
on_submitted_work_done registration — stores value into
gate with release ordering immediately.