molgfx_gpu/capabilities.rs
1//! Device capability flags.
2//!
3//! The renderer branches on these flags, never on backend identity. Every
4//! capability buys speed or a quality ceiling, never correctness: for each
5//! flag there is a fallback path that renders the same content.
6
7bitflags::bitflags! {
8 /// The boolean capabilities, as one word.
9 #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
10 pub struct CapabilityFlags: u32 {
11 /// Hardware acceleration structures and WGSL ray queries.
12 const RAY_QUERY = 1;
13 /// Mesh shading pipeline.
14 const MESH_SHADERS = 1 << 1;
15 /// Unbounded descriptor arrays.
16 const BINDLESS = 1 << 2;
17 /// GPU timestamp queries for profiling.
18 const TIMESTAMP_QUERIES = 1 << 3;
19 /// Subgroup (wave/warp) operations in compute.
20 const SUBGROUP_OPS = 1 << 4;
21 }
22}
23
24/// Renderer-relevant usage support for one texture format.
25#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
26pub struct TextureFormatCapabilities {
27 /// The format may be bound as a sampled texture.
28 pub sampled: bool,
29 /// The format may be bound as a write-only storage texture.
30 pub storage_write: bool,
31}
32
33/// What the opened device can do beyond the baseline.
34#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
35pub struct Capabilities {
36 /// The boolean capabilities.
37 pub flags: CapabilityFlags,
38 /// Required byte alignment for a uniform-buffer binding offset.
39 pub min_uniform_buffer_offset_alignment: u32,
40 /// Largest single storage buffer binding, bytes.
41 pub max_storage_buffer_bytes: u64,
42 /// Maximum storage-buffer bindings visible to one shader stage.
43 pub max_storage_buffers_per_shader_stage: u32,
44 /// Largest 2-D texture dimension, texels.
45 pub max_texture_dim: u32,
46 /// Largest 3-D texture dimension, texels.
47 pub max_texture_dim_3d: u32,
48 /// `r32float` sampling and storage-write support.
49 pub r32float: TextureFormatCapabilities,
50 /// `rg32float` sampling and storage-write support.
51 pub rg32float: TextureFormatCapabilities,
52 /// `rgba32float` sampling and storage-write support.
53 pub rgba32float: TextureFormatCapabilities,
54}
55
56/// Device ceilings relevant to acceleration-structure allocation.
57#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
58pub struct RayQueryLimits {
59 /// Maximum primitives in one BLAS.
60 pub max_blas_primitives: u32,
61 /// Maximum geometry groups in one BLAS.
62 pub max_blas_geometries: u32,
63 /// Maximum instances in one TLAS.
64 pub max_tlas_instances: u32,
65 /// Maximum acceleration-structure bindings visible to one shader stage.
66 pub max_bindings_per_shader_stage: u32,
67}
68
69impl Capabilities {
70 /// Hardware acceleration-structure traversal is available.
71 ///
72 /// This is a resource capability, not evidence that a renderer has wired
73 /// a complete hardware quality path.
74 #[must_use]
75 pub fn hardware_ray_tracing(&self) -> bool {
76 self.ray_query()
77 }
78
79 /// Hardware acceleration structures and WGSL ray queries are available.
80 #[must_use]
81 pub fn ray_query(&self) -> bool {
82 self.flags.contains(CapabilityFlags::RAY_QUERY)
83 }
84
85 /// Mesh shading is available.
86 #[must_use]
87 pub fn mesh_shaders(&self) -> bool {
88 self.flags.contains(CapabilityFlags::MESH_SHADERS)
89 }
90
91 /// Bindless descriptor arrays are available.
92 #[must_use]
93 pub fn bindless(&self) -> bool {
94 self.flags.contains(CapabilityFlags::BINDLESS)
95 }
96
97 /// GPU timestamp queries are available.
98 #[must_use]
99 pub fn timestamp_queries(&self) -> bool {
100 self.flags.contains(CapabilityFlags::TIMESTAMP_QUERIES)
101 }
102
103 /// Subgroup operations are available.
104 #[must_use]
105 pub fn subgroup_ops(&self) -> bool {
106 self.flags.contains(CapabilityFlags::SUBGROUP_OPS)
107 }
108}
109
110#[cfg(test)]
111#[path = "capabilities_tests.rs"]
112mod tests;