pub struct ReadbackWgpuTexture {
inner: WgpuTexture,
aligned_bytes_per_row: usize,
staging_buffer: Buffer,
bytes: Vec<u8>,
pending_rx: Option<Receiver<Result<(), BufferAsyncError>>>,
}Expand description
A WgpuTexture with [wgpu::TextureUsages::COPY_SRC] usage and wrapped with a staging buffer and
a cpu side bytes Vec<T> buffer to read back from the texture.
Fields§
§inner: WgpuTexture§aligned_bytes_per_row: usize§staging_buffer: Buffer§bytes: Vec<u8>§pending_rx: Option<Receiver<Result<(), BufferAsyncError>>>Pending async readback receiver. Present when start_readback has been called
but finish_readback has not yet completed.
Implementations§
Source§impl ReadbackWgpuTexture
impl ReadbackWgpuTexture
pub fn new(ctx: &WgpuContext, desc: &TextureDescriptor<'_>) -> Self
pub fn texture_data(&self) -> &[u8] ⓘ
Sourcepub fn start_readback(&mut self, ctx: &WgpuContext)
pub fn start_readback(&mut self, ctx: &WgpuContext)
Start an async readback: copy texture to staging buffer, submit, and begin mapping.
This is non-blocking. Call finish_readback later to
poll the device and copy the data into the CPU-side buffer.
Sourcepub fn finish_readback(&mut self, ctx: &WgpuContext)
pub fn finish_readback(&mut self, ctx: &WgpuContext)
Finish a pending async readback: poll the device, copy data from the staging buffer into the CPU-side buffer, and unmap.
If no readback is pending, this is a no-op.
Sourcepub fn try_finish_readback(&mut self, ctx: &WgpuContext) -> bool
pub fn try_finish_readback(&mut self, ctx: &WgpuContext) -> bool
Try to finish a pending readback without blocking.
Returns true if completed (or nothing was pending), false if GPU isn’t done yet.
fn copy_staging_to_bytes(&mut self)
Sourcepub fn update_texture_data(&mut self, ctx: &WgpuContext) -> &[u8] ⓘ
pub fn update_texture_data(&mut self, ctx: &WgpuContext) -> &[u8] ⓘ
Synchronous readback: start + finish in one call.
Methods from Deref<Target = Texture>§
pub unsafe fn as_hal<A>(
&self,
) -> Option<impl Deref<Target = <A as Api>::Texture>>where
A: Api,
Available on wgpu_core only.
pub unsafe fn as_hal<A>(
&self,
) -> Option<impl Deref<Target = <A as Api>::Texture>>where
A: Api,
wgpu_core only.Get the [wgpu_hal] texture from this Texture.
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::Texture.
§Types
The returned type depends on the backend:
- [
hal::api::Vulkan] uses [hal::vulkan::Texture] hal::api::Metaluseshal::metal::Texturehal::api::Dx12useshal::dx12::Texture- [
hal::api::Gles] uses [hal::gles::Texture]
§Deadlocks
- The returned guard holds a read-lock on a device-local “destruction”
lock, which will cause all calls to
destroyto block until the guard is released.
§Errors
This method will return None if:
- The texture is not from the backend specified by
A. - The texture is from the
webgpuorcustombackend. - The texture has had [
Self::destroy()] called on it.
§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.
pub fn create_view(
&self,
desc: &TextureViewDescriptor<Option<&str>>,
) -> TextureView
pub fn create_view( &self, desc: &TextureViewDescriptor<Option<&str>>, ) -> TextureView
Creates a view of this texture, specifying an interpretation of its texels and possibly a subset of its layers and mip levels.
Texture views are needed to use a texture as a binding in a [BindGroup]
or as an attachment in a [RenderPass].
pub fn destroy(&self)
pub fn destroy(&self)
Destroy the associated native resources as soon as possible.
pub fn as_image_copy(&self) -> TexelCopyTextureInfo<&Texture>
pub fn as_image_copy(&self) -> TexelCopyTextureInfo<&Texture>
Make an TexelCopyTextureInfo representing the whole texture.
pub fn size(&self) -> Extent3d
pub fn size(&self) -> Extent3d
Returns the size of this Texture.
This is always equal to the size that was specified when creating the texture.
pub fn width(&self) -> u32
pub fn width(&self) -> u32
Returns the width of this Texture.
This is always equal to the size.width that was specified when creating the texture.
pub fn height(&self) -> u32
pub fn height(&self) -> u32
Returns the height of this Texture.
This is always equal to the size.height that was specified when creating the texture.
pub fn depth_or_array_layers(&self) -> u32
pub fn depth_or_array_layers(&self) -> u32
Returns the depth or layer count of this Texture.
This is always equal to the size.depth_or_array_layers that was specified when creating the texture.
pub fn mip_level_count(&self) -> u32
pub fn mip_level_count(&self) -> u32
Returns the mip_level_count of this Texture.
This is always equal to the mip_level_count that was specified when creating the texture.
pub fn sample_count(&self) -> u32
pub fn sample_count(&self) -> u32
Returns the sample_count of this Texture.
This is always equal to the sample_count that was specified when creating the texture.
pub fn dimension(&self) -> TextureDimension
pub fn dimension(&self) -> TextureDimension
Returns the dimension of this Texture.
This is always equal to the dimension that was specified when creating the texture.
pub fn format(&self) -> TextureFormat
pub fn format(&self) -> TextureFormat
Returns the format of this Texture.
This is always equal to the format that was specified when creating the texture.
pub fn usage(&self) -> TextureUsages
pub fn usage(&self) -> TextureUsages
Returns the allowed usages of this Texture.
This is always equal to the usage that was specified when creating the texture.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ReadbackWgpuTexture
impl !RefUnwindSafe for ReadbackWgpuTexture
impl Send for ReadbackWgpuTexture
impl Sync for ReadbackWgpuTexture
impl !Unpin for ReadbackWgpuTexture
impl !UnwindSafe for ReadbackWgpuTexture
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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