Skip to main content

WebGpu

Struct WebGpu 

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

A Gpu on a WebGPU Device.

A shader’s groups are WebGPU bind groups, made with the bindings. globalIndex is a dynamic offset into a table of indices. Draws record into a pass of the frame’s command encoder at once, setting only what changed since the draw before.

Small buffers share larger ones, so that buffers made together sit together, their writes join one copy, and a frame that remakes many small buffers makes few wgpu buffers. Writes are gathered and copied into place ahead of the next flush’s commands.

On a browser’s WebGPU, a create_* call returns before the browser validates it, so a rejected descriptor reaches the device’s uncaptured-error callback instead of the call’s result.

Implementations§

Source§

impl WebGpu

Source

pub fn new(device: &Device) -> WebGpu

Source

pub fn import_texture(&mut self, texture: &Texture) -> TextureId

Takes a texture made elsewhere, such as a surface’s frame, as a texture of this backend. Destroying it drops this backend’s reference.

Trait Implementations§

Source§

impl Gpu for WebGpu

Source§

fn destroy(&mut self, resource: ResourceId)

Drops this backend’s references: wgpu keeps a resource while bindings, geometry or recorded commands hold it.

Source§

fn lend(&mut self, f: &mut dyn FnMut(&mut dyn Any)) -> Result<(), GpuError>

Lends the open pass, or the frame’s command encoder. A pass that a custom layer draws into has a color attachment.

Source§

fn read_texture( &mut self, texture: TextureId, region: TextureRegion, ) -> Result<ReadbackId, GpuError>

Copies into a buffer that is mapped once the copy is done: the last readback’s where it’s as big, else a new one.

Source§

fn take_readback( &mut self, readback: ReadbackId, wait: bool, ) -> Result<Option<Vec<u8>>, GpuError>

Polls the device for the map, or on a browser leaves it to the browser’s event loop, which can’t wait.

Source§

fn caps(&self) -> &Caps

Source§

fn create_buffer(&mut self, desc: &BufferDesc<'_>) -> Result<BufferId, GpuError>

Makes a buffer of desc, whose contents are undefined until written.
Source§

fn write_buffer( &mut self, buffer: BufferId, offset: u64, data: &[u8], ) -> Result<(), GpuError>

Writes data at offset bytes into buffer. offset and the length of data are multiples of 4.
Source§

fn create_texture( &mut self, desc: &TextureDesc<'_>, ) -> Result<TextureId, GpuError>

Source§

fn write_texture( &mut self, texture: TextureId, region: TextureRegion, data: &[u8], ) -> Result<(), GpuError>

Writes data, the region’s texels in rows from the top with no padding, to region of texture, which is sampled.
Source§

fn create_sampler( &mut self, state: &SamplerState, ) -> Result<SamplerId, GpuError>

Source§

fn create_shader(&mut self, key: &ShaderKey) -> Result<ShaderId, GpuError>

Compiles the program of key.
Source§

fn create_pipeline( &mut self, desc: &PipelineDesc<'_>, ) -> Result<PipelineId, GpuError>

Makes a pipeline of desc’s shader and state. Fails with GpuError::Unsupported for a primitive the backend doesn’t draw.
Source§

fn create_bindings( &mut self, desc: &BindingsDesc<'_>, ) -> Result<BindingsId, GpuError>

Makes the bindings of desc’s entries that its shader reads. Fails as validation::check_bindings does: for an entry of a buffer of another usage than Uniform or Storage, a range outside its buffer or at an offset the backend doesn’t align, a texture that isn’t sampled, two entries of one id, or a buffer or texture the shader reads and no entry binds.
Source§

fn create_geometry( &mut self, desc: &GeometryDesc<'_>, ) -> Result<GeometryId, GpuError>

Makes geometry of desc’s buffers. Fails as validation::check_geometry does: for a buffer of another usage than Vertex or the index buffer’s Index, an offset past a buffer’s end, or a buffer for each layout but not one.
Source§

fn begin_pass(&mut self, desc: &PassDesc<'_>) -> Result<(), GpuError>

Begins a pass over desc’s attachments, which are render targets of one size, a color one and a depth one, at least one of them. Fails while a pass is open.
Source§

fn draw(&mut self, draw: &Draw) -> Result<(), GpuError>

Draws draw into the open pass. Fails, drawing nothing, outside a pass, for a pipeline of other target formats than the pass’s attachments, for bindings or geometry made for another shader or vertex layouts than the pipeline’s, for indices or instances past the geometry’s buffers, and for a global index past the elements of the storage buffers the bindings bind. The contents of the indices are the caller’s to keep inside the vertex buffers.
Source§

fn end_pass(&mut self) -> Result<(), GpuError>

Ends the open pass, storing its attachments.
Source§

fn flush(&mut self, wait: bool) -> Result<(), GpuError>

Sends the work recorded so far to the GPU; with wait, then blocks until the GPU has finished it, on a backend that can block. Fails while a pass is open.

Auto Trait Implementations§

§

impl !RefUnwindSafe for WebGpu

§

impl !UnwindSafe for WebGpu

§

impl Forget for WebGpu

§

impl Freeze for WebGpu

§

impl Move for WebGpu

§

impl Send for WebGpu

§

impl Sync for WebGpu

§

impl Unpin for WebGpu

§

impl UnsafeUnpin for WebGpu

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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