wgpu::api::surface

Struct Surface

Source
pub struct Surface<'window> {
    pub(crate) inner: DispatchSurface,
    pub(crate) config: Mutex<Option<SurfaceConfiguration>>,
    pub(crate) _handle_source: Option<Box<dyn WindowHandle + 'window>>,
}
Expand description

Handle to a presentable surface.

A Surface represents a platform-specific surface (e.g. a window) onto which rendered images may be presented. A Surface may be created with the function Instance::create_surface.

This type is unique to the Rust API of wgpu. In the WebGPU specification, GPUCanvasContext serves a similar role.

Fields§

§inner: DispatchSurface

Additional surface data returned by [DynContext::instance_create_surface].

§config: Mutex<Option<SurfaceConfiguration>>§_handle_source: Option<Box<dyn WindowHandle + 'window>>

Optionally, keep the source of the handle used for the surface alive.

This is useful for platforms where the surface is created from a window and the surface would become invalid when the window is dropped.

SAFETY: This field must be dropped after all other fields to ensure proper cleanup.

Implementations§

Source§

impl Surface<'_>

Source

pub fn get_capabilities(&self, adapter: &Adapter) -> SurfaceCapabilities

Returns the capabilities of the surface when used with the given adapter.

Returns specified values (see SurfaceCapabilities) if surface is incompatible with the adapter.

Source

pub fn get_default_config( &self, adapter: &Adapter, width: u32, height: u32, ) -> Option<SurfaceConfiguration>

Return a default SurfaceConfiguration from width and height to use for the Surface with this adapter.

Returns None if the surface isn’t supported by this adapter

Source

pub fn configure(&self, device: &Device, config: &SurfaceConfiguration)

Initializes Surface for presentation.

If the surface is already configured, this will wait for the GPU to come idle before recreating the swapchain to prevent race conditions.

§Validation Errors
  • Submissions that happen during the configure may cause the internal wait-for-idle to fail, raising a validation error.
§Panics
  • A old SurfaceTexture is still alive referencing an old surface.
  • Texture format requested is unsupported on the surface.
  • config.width or config.height is zero.
Source

pub fn get_current_texture(&self) -> Result<SurfaceTexture, SurfaceError>

Returns the next texture to be presented by the swapchain for drawing.

In order to present the SurfaceTexture returned by this method, first a Queue::submit needs to be done with some work rendering to this texture. Then SurfaceTexture::present needs to be called.

If a SurfaceTexture referencing this surface is alive when the swapchain is recreated, recreating the swapchain will panic.

Source

pub unsafe fn as_hal<A: HalApi>( &self, ) -> Option<impl Deref<Target = A::Surface> + WasmNotSendSync>

Available on wgpu_core only.

Get the wgpu_hal surface from this Surface.

Find the Api struct corresponding to the active backend in wgpu_hal::api, and pass that struct to the to the A type parameter.

Returns a guard that dereferences to the type of the hal backend which implements A::Surface.

§Errors

This method will return None if:

  • The surface is not from the backend specified by A.
  • The surface is from the webgpu or custom backend.
§Safety
  • The returned resource must not be destroyed unless the guard is the last reference to it and it is not in use by the GPU. The guard and handle may be dropped at any time however.
  • All the safety requirements of wgpu-hal must be upheld.
Source

pub fn as_custom<T: SurfaceInterface>(&self) -> Option<&T>

Available on custom only.

Returns custom implementation of Surface (if custom backend and is internally T)

Trait Implementations§

Source§

impl Debug for Surface<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for Surface<'_>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Surface<'_>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Surface<'_>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Surface<'_>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Surface<'_>

Auto Trait Implementations§

§

impl<'window> !Freeze for Surface<'window>

§

impl<'window> !RefUnwindSafe for Surface<'window>

§

impl<'window> Send for Surface<'window>

§

impl<'window> Sync for Surface<'window>

§

impl<'window> Unpin for Surface<'window>

§

impl<'window> !UnwindSafe for Surface<'window>

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> AsAny for T
where T: 'static,

Source§

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

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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>

Source§

impl<T> CommonTraits for T
where T: AsAny + Any + Debug + WasmNotSendSync,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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