pub struct GpuImage { /* private fields */ }Expand description
An image living in GPU storage buffers (STORAGE | COPY_SRC, plus MAP_READ on
unified-memory adapters), on the device of the GpuContext that produced it.
Most images are a single buffer: use GpuImage::buffer to bind it in your own
wgpu/WebGPU pipelines, GpuImage::to_texture for an Rgba8Unorm texture, or
download it. Images larger than the adapter’s storage-binding limit are tiled
(GpuImage::is_tiled): GpuImage::tiles lists one buffer per band with its
rectangle in the image (full-width row bands, or full-height column bands for
RGBA8 outputs rotated by 90/270 degrees). download and to_texture reassemble
tiled images.
Buffers come from FlashRaw’s buffer pool and are returned to the pool when the
GpuImage is dropped (large allocations are expensive to recreate). Keep the
GpuImage alive while the GPU may still use them, or take ownership with
GpuImage::into_buffer / GpuImage::into_tiles. A buffer may be larger than
the data it holds.
Implementations§
Source§impl GpuImage
impl GpuImage
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn format(&self) -> GpuPixelFormat
pub fn is_empty(&self) -> bool
Sourcepub fn buffer(&self) -> Option<&Buffer>
pub fn buffer(&self) -> Option<&Buffer>
The storage buffer holding the whole image (row-major, from byte 0), or None
for a tiled image (see GpuImage::tiles). See the type docs for lifetimes.
Sourcepub fn is_tiled(&self) -> bool
pub fn is_tiled(&self) -> bool
The image is split into several buffers (it is larger than one storage binding).
Sourcepub fn tiles(&self) -> &[GpuTile]
pub fn tiles(&self) -> &[GpuTile]
The buffers and the rectangle each one holds (one tile covering the image when untiled). Tiles are disjoint, cover the image, and are ordered by position.
Sourcepub fn into_buffer(self) -> Result<Buffer, GpuImage>
pub fn into_buffer(self) -> Result<Buffer, GpuImage>
Take ownership of the buffer of an untiled image (it will not be recycled). A tiled image is returned unchanged as the error.
Sourcepub fn into_tiles(self) -> Vec<GpuTile>
pub fn into_tiles(self) -> Vec<GpuTile>
Take ownership of all buffers (they will not be recycled).
pub fn device(&self) -> &Device
pub fn queue(&self) -> &Queue
pub fn context(&self) -> &Arc<GpuContext> ⓘ
Sourcepub async fn download_async(&self) -> Result<(HostPixels, f64)>
pub async fn download_async(&self) -> Result<(HostPixels, f64)>
Download to host memory (tiled images are reassembled). Returns the pixels and the wall time in ms.
Sourcepub async fn download_rgb_async(&self) -> Result<(HostPixels, f64)>
pub async fn download_rgb_async(&self) -> Result<(HostPixels, f64)>
Download a 4-channel 16-bit image (the 16-bit develop outputs) as 3-channel RGB: the fourth sample of every pixel is dropped while copying out of the device buffer, so no 4-channel host copy is made. Other images download unchanged.
Sourcepub fn download_rgb(&self) -> Result<(HostPixels, f64)>
pub fn download_rgb(&self) -> Result<(HostPixels, f64)>
Blocking GpuImage::download_rgb_async (native only).
Sourcepub fn download(&self) -> Result<(HostPixels, f64)>
pub fn download(&self) -> Result<(HostPixels, f64)>
Blocking download (native only).
Sourcepub fn to_texture(&self) -> Result<Texture>
pub fn to_texture(&self) -> Result<Texture>
Copy an RGBA8 image (tiled or not) into a new Rgba8Unorm texture (usage
STORAGE_BINDING | TEXTURE_BINDING | COPY_SRC) for sampling/rendering.
The copy is queued; it completes before any later submission on the queue.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for GpuImage
impl !UnwindSafe for GpuImage
impl Freeze for GpuImage
impl Send for GpuImage
impl Sync for GpuImage
impl Unpin for GpuImage
impl UnsafeUnpin for GpuImage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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