pub struct WebGpu { /* private fields */ }Expand description
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§
Trait Implementations§
Source§impl Gpu for WebGpu
impl Gpu for WebGpu
Source§fn generate_mipmaps(&mut self, texture: TextureId) -> Result<(), GpuError>
fn generate_mipmaps(&mut self, texture: TextureId) -> Result<(), GpuError>
Draws each level from the one before, in a pass of its own.
Source§fn destroy(&mut self, resource: ResourceId) -> Result<(), GpuError>
fn destroy(&mut self, resource: ResourceId) -> Result<(), GpuError>
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>
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>
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>
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.
fn caps(&self) -> &Caps
Source§fn create_buffer(&mut self, desc: &BufferDesc<'_>) -> Result<BufferId, GpuError>
fn create_buffer(&mut self, desc: &BufferDesc<'_>) -> Result<BufferId, GpuError>
desc, whose contents are undefined until written.Source§fn write_buffer(
&mut self,
buffer: BufferId,
offset: u64,
data: &[u8],
) -> Result<(), GpuError>
fn write_buffer( &mut self, buffer: BufferId, offset: u64, data: &[u8], ) -> Result<(), GpuError>
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>
fn create_texture( &mut self, desc: &TextureDesc<'_>, ) -> Result<TextureId, GpuError>
desc. Fails as validation::check_mips does,
and for a size or format the backend doesn’t make.Source§fn write_texture(
&mut self,
texture: TextureId,
region: TextureRegion,
data: &[u8],
) -> Result<(), GpuError>
fn write_texture( &mut self, texture: TextureId, region: TextureRegion, data: &[u8], ) -> Result<(), GpuError>
data, the region’s texels in rows from the top with no
padding, to region of texture, which is
sampled.fn create_sampler(&mut self, state: SamplerState) -> Result<SamplerId, GpuError>
Source§fn create_shader(&mut self, key: &ShaderKey) -> Result<ShaderId, GpuError>
fn create_shader(&mut self, key: &ShaderKey) -> Result<ShaderId, GpuError>
key. Fails with GpuError::Unsupported
for a program the backend has no source for.Source§fn create_pipeline(
&mut self,
desc: &PipelineDesc<'_>,
) -> Result<PipelineId, GpuError>
fn create_pipeline( &mut self, desc: &PipelineDesc<'_>, ) -> Result<PipelineId, GpuError>
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>
fn create_bindings( &mut self, desc: &BindingsDesc<'_>, ) -> Result<BindingsId, GpuError>
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, or
Vertex where
Caps::binds_vertex_buffers says, 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>
fn create_geometry( &mut self, desc: &GeometryDesc<'_>, ) -> Result<GeometryId, GpuError>
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>
fn begin_pass(&mut self, desc: &PassDesc<'_>) -> Result<(), GpuError>
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>
fn draw(&mut self, draw: &Draw) -> Result<(), GpuError>
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 flush(&mut self, wait: bool) -> Result<(), GpuError>
fn flush(&mut self, wait: bool) -> Result<(), GpuError>
wait, then blocks
until the GPU has finished it, on a backend that can block. Fails
while a pass is open.Source§fn attaches_with_any_color(&self, _depth_stencil: TextureId) -> bool
fn attaches_with_any_color(&self, _depth_stencil: TextureId) -> bool
depth_stencil, a depth attachment,
together with any color attachment of its size. Not where it is an
attachment of a framebuffer made elsewhere, such as a window
surface’s, which a pass draws into only with that framebuffer’s
color.