Skip to main content

Format

Enum Format 

Source
pub enum Format {
Show 29 variants R8Unorm, Rg8Unorm, Rgba8Unorm, Rgba8UnormSrgb, Bgra8Unorm, Bgra8UnormSrgb, Rgb10a2Unorm, R11g11b10Float, R16Float, Rg16Float, Rgba16Float, R32Float, Rg32Float, Rgba32Float, R32Uint, Rg32Uint, D32Float, D32FloatS8Uint, D24UnormS8Uint, D16Unorm, Bc1RgbaUnorm, Bc1RgbaUnormSrgb, Bc3RgbaUnorm, Bc3RgbaUnormSrgb, Bc4RUnorm, Bc5RgUnorm, Bc6hRgbUfloat, Bc7RgbaUnorm, Bc7RgbaUnormSrgb,
}
Expand description

A texel format.

The set is the intersection of what Vulkan, Metal, DX12 and WebGPU all support without optional features, plus the depth formats the engine actually asks for. Anything that is not universally available (BC on mobile, D24UnormS8Uint on some drivers) is reported through Features or refused at surface/image creation, never silently substituted.

Variants§

§

R8Unorm

Single-channel 8-bit unsigned normalised.

§

Rg8Unorm

Two-channel 8-bit unsigned normalised.

§

Rgba8Unorm

Four-channel 8-bit unsigned normalised, linear.

§

Rgba8UnormSrgb

Four-channel 8-bit unsigned normalised, sRGB-encoded.

§

Bgra8Unorm

Swapchain-native byte order on most desktop platforms, linear.

§

Bgra8UnormSrgb

Swapchain-native byte order on most desktop platforms, sRGB-encoded.

§

Rgb10a2Unorm

Packed 10/10/10/2 unsigned normalised — the usual normal-buffer format.

§

R11g11b10Float

Packed 11/11/10 float — half the bandwidth of Rgba16Float for non-alpha HDR intermediates (bloom chains, light accumulation).

§

R16Float

Single-channel half float.

§

Rg16Float

Two-channel half float — motion vectors, packed BRDF LUTs.

§

Rgba16Float

The engine’s HDR render-target format. Four-channel half float.

§

R32Float

Single-channel 32-bit float.

§

Rg32Float

Two-channel 32-bit float.

§

Rgba32Float

Four-channel 32-bit float — readback and reference targets, not a steady-state render target.

§

R32Uint

Single-channel 32-bit unsigned integer — visibility/ID buffers.

§

Rg32Uint

Two-channel 32-bit unsigned integer.

§

D32Float

The engine’s depth format. 32-bit float depth, reversed-Z.

§

D32FloatS8Uint

32-bit float depth plus 8-bit stencil (padded).

§

D24UnormS8Uint

24-bit unorm depth plus 8-bit stencil. Present on most desktop GPUs but not guaranteed; prefer Format::D32Float.

§

D16Unorm

16-bit unorm depth — shadow maps where precision allows.

§

Bc1RgbaUnorm

BC1 (DXT1) RGB(A1), linear.

§

Bc1RgbaUnormSrgb

BC1 (DXT1) RGB(A1), sRGB.

§

Bc3RgbaUnorm

BC3 (DXT5) RGBA, linear.

§

Bc3RgbaUnormSrgb

BC3 (DXT5) RGBA, sRGB.

§

Bc4RUnorm

BC4 single-channel — roughness/metallic/AO atlases.

§

Bc5RgUnorm

BC5 two-channel — tangent-space normal maps.

§

Bc6hRgbUfloat

BC6H unsigned half float — compressed HDR (environment maps).

§

Bc7RgbaUnorm

BC7 RGBA, linear.

§

Bc7RgbaUnormSrgb

BC7 RGBA, sRGB — the default albedo format.

Implementations§

Source§

impl Format

Source

pub const ALL: &'static [Self]

Every variant, in declaration order.

The seam owns this list so a backend does not keep a second copy of it. That mattered: crcbl-vk’s reverse mapping ends in _ => None, so a format added forward and forgotten in reverse is not a compile error — it is a format its surface_caps silently drops — and the round-trip test that would have caught it was iterating the backend’s own copy of this list, which had the same omission. Iterating ALL ties the two together.

Add a variant above, add it here. Nothing on stable Rust can count an enum’s variants, so this list is hand-maintained; the closest guard is this module’s the_format_table_is_in_declaration_order test, which catches an entry inserted anywhere but the very end.

Source

pub const fn block_size(self) -> u32

Bytes per block. For uncompressed formats a “block” is one texel.

§Not the copy footprint of a depth/stencil format

A combined depth+stencil format has two planes, and a copy names one of them: D32FloatS8Uint reports 8 here (its in-memory element size) while a depth-aspect copy moves 4 bytes per texel and a stencil-aspect copy moves 1. D24UnormS8Uint reports 4 while its stencil aspect is again 1 byte and its depth aspect is, on every API that permits the copy at all, a 4-byte element. Use Format::texel_size when sizing a BufferImageCopy; block_size answers “how wide is one element of this format”, which is the right question for a colour format and only that.

Source

pub const fn texel_size(self, aspect: ImageAspect) -> Option<u32>

Bytes one block of aspect occupies in a buffer during a copy.

This is the number a BufferImageCopy is sized against, and it is not Format::block_size for a combined depth/stencil format — see that method for why. None means the format does not have that aspect, or the aspect set names more than one plane, neither of which a single copy region can describe.

use crcbl_hal::{Format, ImageAspect};

assert_eq!(Format::D32FloatS8Uint.block_size(), 8);
assert_eq!(Format::D32FloatS8Uint.texel_size(ImageAspect::DEPTH), Some(4));
assert_eq!(Format::D32FloatS8Uint.texel_size(ImageAspect::STENCIL), Some(1));
assert_eq!(Format::D32FloatS8Uint.texel_size(ImageAspect::COLOR), None);
assert_eq!(Format::Rgba8Unorm.texel_size(ImageAspect::COLOR), Some(4));
Source

pub const fn block_extent(self) -> (u32, u32)

Block footprint in texels — (1, 1) unless the format is block compressed, in which case (4, 4).

Source

pub const fn is_compressed(self) -> bool

Whether this is a BC-compressed format.

Source

pub const fn has_depth(self) -> bool

Whether the format carries a depth channel.

Source

pub const fn has_stencil(self) -> bool

Whether the format carries a stencil channel.

Source

pub const fn is_depth_stencil(self) -> bool

Whether the format may be used as a depth/stencil attachment rather than a colour one.

Source

pub const fn is_srgb(self) -> bool

Whether sampling this format applies sRGB→linear decode in hardware.

Source

pub const fn is_hdr_capable(self) -> bool

Whether the format stores floating-point components wider than 8 bits — i.e. whether it can hold values outside [0, 1] and is therefore usable as an HDR intermediate.

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Format

Source§

impl Debug for Format

Source§

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

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

impl Eq for Format

Source§

impl Hash for Format

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Format

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Format

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

impl PartialOrd for Format

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Format

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.