Skip to main content

RenderPassDescriptorCache

Struct RenderPassDescriptorCache 

Source
pub struct RenderPassDescriptorCache { /* private fields */ }
Expand description

OPT 34: persistent render-pass descriptor and its inner attachments, reused across begin_render_pass_full calls.

§Why

begin_render_pass_full historically allocated a fresh descriptor Object, a colorAttachments Array, and one inner color_attachment Object (plus an optional clearValue Object) on every frame, then ran 8-15 Reflect::set calls to populate them. WebGPU re-validates the descriptor each call, but the JS-side Object / Array allocations and the per-property Reflect::set crossings are pure overhead — only the clearValue and (rarely) view / loadOp / storeOp fields change between frames.

§What we cache

  • The top-level descriptor Object (the one passed to beginRenderPass).
  • The colorAttachments Array (always exactly one element — we keep the same Array reference and mutate its slot 0 in place).
  • The inner color attachment Object (slot 0 of colorAttachments).
  • The clearValue Object (the {r, g, b, a} dictionary that is the actual per-frame mutating field).
  • Last-applied loadOp / storeOp string slices, to detect when the caller switched ops and the cached descriptor must be rebuilt (rare; WebGPU does not hot-swap ops every frame).
  • Last-applied depth-stencil shape (present / absent), to detect when the depth-stencil shape changes.

§Invalidation

The cache is invalidated (rebuilt from scratch) when any of:

  • load_op changes between calls,
  • store_op changes between calls,
  • the depth-stencil shape changes (None → Some / Some → None),
  • the resolve-target shape changes (MSAA on/off).

view / resolveTarget / clearValue are refreshed on every call (the swap-chain view expires after each presented frame, so caching it across frames silently invalidates every subsequent render pass).

These are all &'static str (they come from WEBGPU_*_OP_* constants), so invalidation is a pointer-compare.

Clone is derived so the parent WebGpuRenderer’s Data derive (which adds a Clone bound on every field) keeps compiling; js_sys::Object and js_sys::Array both derive Clone, so the derived Clone impl just clones the inner JS-side references (cheap, no JS allocation).

Trait Implementations§

Source§

impl Clone for RenderPassDescriptorCache

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RenderPassDescriptorCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more