molgfx_gpu/descriptors/texture.rs
1//! Texture descriptors and formats.
2
3/// The formats the engine renders with. A deliberate subset: every format
4/// here is universally supported on the targeted backends, and backends
5/// match on it exhaustively, so growing the set is a deliberate change.
6#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
7pub enum TextureFormat {
8 /// 8-bit RGBA, linear.
9 Rgba8Unorm,
10 /// Signed normalized 8-bit RGBA; compact generated direction fields.
11 Rgba8Snorm,
12 /// 8-bit RGBA, sRGB-encoded.
13 Rgba8UnormSrgb,
14 /// 8-bit BGRA, linear (a common swapchain format).
15 Bgra8Unorm,
16 /// 8-bit BGRA, sRGB-encoded (a common swapchain format).
17 Bgra8UnormSrgb,
18 /// 16-bit float RGBA; the linear HDR working format.
19 Rgba16Float,
20 /// Two 16-bit float channels; compact screen-space motion vectors.
21 Rg16Float,
22 /// Two 32-bit float channels; conservative scalar-volume min/max pairs.
23 Rg32Float,
24 /// Four 32-bit float channels; portable storage fallback for volume bounds.
25 Rgba32Float,
26 /// Single 8-bit channel; ambient-occlusion and masks.
27 R8Unorm,
28 /// Single 32-bit unsigned integer; the entity-id channel.
29 R32Uint,
30 /// Single 32-bit float channel; physical scalar density grids.
31 R32Float,
32 /// 32-bit float depth, used with reversed depth.
33 Depth32Float,
34}
35
36/// Texture dimensionality supported by the portable renderer.
37#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
38pub enum TextureDimension {
39 /// A conventional image or render target.
40 #[default]
41 D2,
42 /// A volumetric scalar field.
43 D3,
44}
45
46impl TextureFormat {
47 /// Whether this is a depth format.
48 #[must_use]
49 pub fn is_depth(self) -> bool {
50 matches!(self, Self::Depth32Float)
51 }
52}
53
54bitflags::bitflags! {
55 /// How a texture may be used.
56 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
57 pub struct TextureUsage: u32 {
58 /// Rendered to as a color or depth attachment.
59 const RENDER_ATTACHMENT = 1;
60 /// Sampled from shaders.
61 const TEXTURE_BINDING = 1 << 1;
62 /// Written from compute as a storage texture.
63 const STORAGE_BINDING = 1 << 2;
64 /// Source of copies.
65 const COPY_SRC = 1 << 3;
66 /// Destination of copies.
67 const COPY_DST = 1 << 4;
68 }
69}
70
71/// Everything needed to create a texture.
72#[derive(Clone, Copy, PartialEq, Eq, Debug)]
73pub struct TextureDesc {
74 /// Debug label.
75 pub label: &'static str,
76 /// Width in texels.
77 pub width: u32,
78 /// Height in texels.
79 pub height: u32,
80 /// Depth in texels; one for 2-D textures.
81 pub depth: u32,
82 /// Whether the texture is 2-D or 3-D.
83 pub dimension: TextureDimension,
84 /// Texel format.
85 pub format: TextureFormat,
86 /// Permitted usages.
87 pub usage: TextureUsage,
88}
89
90/// View parameters; the default views the whole texture.
91#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
92pub struct TextureViewDesc {}
93
94/// One tightly described host-to-texture upload.
95#[derive(Clone, Copy, Debug)]
96pub struct TextureWrite<'a> {
97 /// Destination origin in texels.
98 pub origin: [u32; 3],
99 /// Written extent in texels.
100 pub size: [u32; 3],
101 /// Byte stride between adjacent rows.
102 pub bytes_per_row: u32,
103 /// Rows between adjacent depth slices.
104 pub rows_per_image: u32,
105 /// Borrowed source allocation.
106 pub data: &'a [u8],
107}