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
impl Format
Sourcepub const ALL: &'static [Self]
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.
Sourcepub const fn block_size(self) -> u32
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.
Sourcepub const fn texel_size(self, aspect: ImageAspect) -> Option<u32>
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));Sourcepub const fn block_extent(self) -> (u32, u32)
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).
Sourcepub const fn is_compressed(self) -> bool
pub const fn is_compressed(self) -> bool
Whether this is a BC-compressed format.
Sourcepub const fn has_stencil(self) -> bool
pub const fn has_stencil(self) -> bool
Whether the format carries a stencil channel.
Sourcepub const fn is_depth_stencil(self) -> bool
pub const fn is_depth_stencil(self) -> bool
Whether the format may be used as a depth/stencil attachment rather than a colour one.
Sourcepub const fn is_srgb(self) -> bool
pub const fn is_srgb(self) -> bool
Whether sampling this format applies sRGB→linear decode in hardware.
Sourcepub const fn is_hdr_capable(self) -> bool
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.