Skip to main content

ResourceKeepAlive

Trait ResourceKeepAlive 

Source
pub trait ResourceKeepAlive:
    MaybeSendSync
    + Debug
    + 'static {
    // Provided methods
    fn mark_consumed(&self) { ... }
    fn as_any(&self) -> Option<&(dyn Any + 'static)> { ... }
}
Expand description

Marker trait for per-variant lifetime anchors carried on GpuResource newtypes.

Producers attach the Arc they already hold (e.g. an Arc over an SDK frame or a pool-slot guard); consumers can clone the Arc cheaply or downcast through their own custom traits when needed.

A named trait rather than a bare Arc<dyn Any + Send + Sync>, so it’s discoverable in rustdoc and so callers can extend it.

§Consumer notification

Self::mark_consumed is invoked by the import path (for example after a D3D11 keyed-mutex acquire) after the consumer-side sync primitive has succeeded. Producer-side anchors that carry a one-shot synchronisation state (a D3D11VA decoder’s keyed-mutex “consumer ack” flag; an SDK decoder’s resource lock) override the default no-op to suppress their fallback Drop-time rebalance.

§Why no blanket impl

A blanket impl<T: Send + Sync + Debug + 'static> ResourceKeepAlive for T {} would spare the common case (a keep-alive that is just an Arc<SdkFrame>) a per-type impl, but per-type override of mark_consumed is incompatible with that blanket — concrete types covered by the blanket cannot then be special-cased without a conflicting implementations error.

Producer-side anchors such as a D3D11VA / D3D12VA decoder’s plane-splitter need exactly such an override, so there is no blanket. Concrete keep-alive types impl ResourceKeepAlive for X {} explicitly — a single line for the default no-op case, an override of mark_consumed for anchors that need it. KeepAlive holders (GpuResource payload fields) never call the method themselves; only the import path does, after a successful strict acquire.

Provided Methods§

Source

fn mark_consumed(&self)

Notification from the import path that the consumer-side sync primitive (e.g. D3D11 keyed-mutex strict AcquireSync(1)) has completed and the consumer’s release-on-drop will close the cycle. Producer-side anchors override this to suppress their fallback Drop-time rebalance.

Default is a no-op: anchors that don’t carry sync state (the common case — most keep-alives are just Arc<SdkFrame> holding a refcount) ignore the call.

Source

fn as_any(&self) -> Option<&(dyn Any + 'static)>

Optional downcast hook so a type-erased KeepAlive can be resolved back to its concrete keep-alive type when a platform-specific post-drop handshake needs it. Default None.

An Android AImage release-fence path is the motivating case: an AHB importer overrides this on its AImage-owning keep-alive and reaches the concrete type behind this erased handle to deposit the exported SYNC_FD release fence, which the AImage’s Drop then hands to AImage_deleteAsync so the BufferQueue slot only returns to the producer once the GPU’s reads have retired.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ResourceKeepAlive for ()

Implementors§