Skip to main content

GpuImage

Struct GpuImage 

Source
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

Source

pub fn width(&self) -> u32

Source

pub fn height(&self) -> u32

Source

pub fn channels(&self) -> u32

Samples per pixel (1 for CFA/mono, 3 for RGB, 4 for RGBA8).

Source

pub fn format(&self) -> GpuPixelFormat

Source

pub fn len(&self) -> usize

Number of samples (width * height * channels; bytes for RGBA8).

Source

pub fn is_empty(&self) -> bool

Source

pub fn byte_len(&self) -> usize

Bytes of image data (buffers may be larger).

Source

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.

Source

pub fn is_tiled(&self) -> bool

The image is split into several buffers (it is larger than one storage binding).

Source

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.

Source

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.

Source

pub fn into_tiles(self) -> Vec<GpuTile>

Take ownership of all buffers (they will not be recycled).

Source

pub fn device(&self) -> &Device

Source

pub fn queue(&self) -> &Queue

Source

pub fn context(&self) -> &Arc<GpuContext> ⓘ

Source

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.

Source

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.

Source

pub fn download_rgb(&self) -> Result<(HostPixels, f64)>

Blocking GpuImage::download_rgb_async (native only).

Source

pub fn download(&self) -> Result<(HostPixels, f64)>

Blocking download (native only).

Source

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§

Source§

impl Debug for GpuImage

Source§

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

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

impl Drop for GpuImage

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl PartialEq for GpuImage

Identity semantics: two GpuImages are equal when they are the same buffers.

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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