Skip to main content

RenderAttachments

Struct RenderAttachments 

Source
pub struct RenderAttachments {
    color_view: Option<TextureView>,
    depth_stencil_view: Option<TextureView>,
    msaa_view: Option<TextureView>,
}
Expand description

The attachments a frame renders into.

Every view is caller-owned; the set allocates nothing. Build one with Self::from_views.

Fields§

§color_view: Option<TextureView>

The color attachment, or None for a depth-only pass.

§depth_stencil_view: Option<TextureView>

The depth attachment, or None for a pass without depth.

§msaa_view: Option<TextureView>

The multisample attachment the pass draws into, resolved into Self::color_view; None when multisampling is disabled or the pass is depth-only.

Implementations§

Source§

impl RenderAttachments

Source

pub fn from_views( color_view: Option<TextureView>, depth_stencil_view: Option<TextureView>, msaa_view: Option<TextureView>, ) -> Self

Assemble an attachment set entirely from the caller’s views: the color view, the depth-stencil view and an optional multisample view.

A TextureView carries the format it was created with, so the color format is the color view’s own even when it reinterprets its texture — an sRGB view over a non-sRGB swap-chain image, the only way to get correct gamma on the web. Size and sample count are read from the views themselves, so they must agree across views (the caller’s responsibility).

The depth attachment’s transience is read from its texture’s usage: a depth texture created with TextureUsages::TRANSIENT_ATTACHMENT is treated as transient (cleared and discarded within a single pass), any other as persistent (a pass stores into it so a later pass may sample the results).

msaa_view must be None for a non-multisampled pass; when Some, its format and size must match the color view and its sample count must be greater than one.

§Panics

If neither the color nor the depth view is present, or if the multisample view is present without a color view.

Source

pub fn color_view(&self) -> Option<&TextureView>

The color attachment, or None for a depth-only pass.

Source

pub fn msaa_view(&self) -> Option<&TextureView>

The multisample attachment, if any.

Source

pub fn color_format(&self) -> Option<TextureFormat>

The color format the pass renders into, or None for a depth-only pass.

The color view’s own — the MSAA view’s when one is set, since the resolve writes into the color view in that view’s format.

Source

pub fn depth_stencil_format(&self) -> Option<TextureFormat>

The depth format the pass renders into, or None for a pass without depth.

Source

pub fn sample_count(&self) -> u32

The sample count the pass renders with: the MSAA attachment’s when one is set, 1 otherwise.

Source

pub fn surface_key(&self) -> SurfaceKey

The SurfaceKey of the attachments this set owns: their color format, depth format and sample count.

The color format and sample count come from Self::color_format and Self::sample_count, so they always describe the same attachment.

Source

pub fn width(&self) -> u32

The width of the attachments, in pixels.

Taken from whichever attachment is present; they must agree.

Source

pub fn height(&self) -> u32

The height of the attachments, in pixels.

Taken from whichever attachment is present; they must agree.

Source

fn attachment_view(&self) -> Option<&TextureView>

The view the attachment dimensions are read from: the MSAA view when one is set, the color view otherwise, the depth view last.

Source

fn depth_is_transient(&self) -> bool

Whether the depth attachment is transient — created with TextureUsages::TRANSIENT_ATTACHMENT — and so only accepts Clear + Discard within a single pass. false when there is no depth attachment.

Source

pub fn begin_pass<'a>( &'a self, encoder: &'a mut CommandEncoder, color_load: LoadOp<Color>, depth_load: LoadOp<f32>, stencil_load: LoadOp<u32>, ) -> RenderPass<'a>

Begin a render pass over the attachments.

Each *_load value is the load op of its attachment: wgpu::LoadOp::Clear(value) clears it to value, [wgpu::LoadOp::Load] keeps its previous contents. The color attachment discards on store with MSAA (the resolve carries the pixels into the color view) and stores without it (the color view is the attachment). The depth attachment discards after a clear and stores after a load: a transient depth texture (see depth_is_transient) only accepts Clear + Discard, while a persistent depth texture — a shadow map, a preprocessed depth buffer — keeps the results for a later pass to sample. The stencil aspect follows the same rules (the renderer never writes it, so Clear clears it and Load leaves a persistent buffer’s contents alone).

§Panics

If the attachment set has no attachments, if a clear value is given without the matching attachment, or if an existing attachment is given no op.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more