Skip to main content

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    /// Largest single storage buffer binding, bytes.
39    pub max_storage_buffer_bytes: u64,
40    /// Maximum storage-buffer bindings visible to one shader stage.
41    pub max_storage_buffers_per_shader_stage: u32,
42    /// Largest 2-D texture dimension, texels.
43    pub max_texture_dim: u32,
44    /// Largest 3-D texture dimension, texels.
45    pub max_texture_dim_3d: u32,
46    /// `r32float` sampling and storage-write support.
47    pub r32float: TextureFormatCapabilities,
48    /// `rg32float` sampling and storage-write support.
49    pub rg32float: TextureFormatCapabilities,
50    /// `rgba32float` sampling and storage-write support.
51    pub rgba32float: TextureFormatCapabilities,
52}
53
54/// Device ceilings relevant to acceleration-structure allocation.
55#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
56pub struct RayQueryLimits {
57    /// Maximum primitives in one BLAS.
58    pub max_blas_primitives: u32,
59    /// Maximum geometry groups in one BLAS.
60    pub max_blas_geometries: u32,
61    /// Maximum instances in one TLAS.
62    pub max_tlas_instances: u32,
63    /// Maximum acceleration-structure bindings visible to one shader stage.
64    pub max_bindings_per_shader_stage: u32,
65}
66
67impl Capabilities {
68    /// Hardware acceleration-structure traversal is available.
69    ///
70    /// This is a resource capability, not evidence that a renderer has wired
71    /// a complete hardware quality path.
72    #[must_use]
73    pub fn hardware_ray_tracing(&self) -> bool {
74        self.ray_query()
75    }
76
77    /// Hardware acceleration structures and WGSL ray queries are available.
78    #[must_use]
79    pub fn ray_query(&self) -> bool {
80        self.flags.contains(CapabilityFlags::RAY_QUERY)
81    }
82
83    /// Mesh shading is available.
84    #[must_use]
85    pub fn mesh_shaders(&self) -> bool {
86        self.flags.contains(CapabilityFlags::MESH_SHADERS)
87    }
88
89    /// Bindless descriptor arrays are available.
90    #[must_use]
91    pub fn bindless(&self) -> bool {
92        self.flags.contains(CapabilityFlags::BINDLESS)
93    }
94
95    /// GPU timestamp queries are available.
96    #[must_use]
97    pub fn timestamp_queries(&self) -> bool {
98        self.flags.contains(CapabilityFlags::TIMESTAMP_QUERIES)
99    }
100
101    /// Subgroup operations are available.
102    #[must_use]
103    pub fn subgroup_ops(&self) -> bool {
104        self.flags.contains(CapabilityFlags::SUBGROUP_OPS)
105    }
106}
107
108#[cfg(test)]
109#[path = "capabilities_tests.rs"]
110mod tests;