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/// What the opened device can do beyond the baseline.
25#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
26pub struct Capabilities {
27 /// The boolean capabilities.
28 pub flags: CapabilityFlags,
29 /// Largest single storage buffer binding, bytes.
30 pub max_storage_buffer_bytes: u64,
31 /// Maximum storage-buffer bindings visible to one shader stage.
32 pub max_storage_buffers_per_shader_stage: u32,
33 /// Largest 2-D texture dimension, texels.
34 pub max_texture_dim: u32,
35 /// Largest 3-D texture dimension, texels.
36 pub max_texture_dim_3d: u32,
37}
38
39/// Device ceilings relevant to acceleration-structure allocation.
40#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
41pub struct RayQueryLimits {
42 /// Maximum primitives in one BLAS.
43 pub max_blas_primitives: u32,
44 /// Maximum geometry groups in one BLAS.
45 pub max_blas_geometries: u32,
46 /// Maximum instances in one TLAS.
47 pub max_tlas_instances: u32,
48 /// Maximum acceleration-structure bindings visible to one shader stage.
49 pub max_bindings_per_shader_stage: u32,
50}
51
52impl Capabilities {
53 /// Hardware acceleration-structure traversal is available.
54 ///
55 /// This is a resource capability, not evidence that a renderer has wired
56 /// a complete hardware quality path.
57 #[must_use]
58 pub fn hardware_ray_tracing(&self) -> bool {
59 self.ray_query()
60 }
61
62 /// Hardware acceleration structures and WGSL ray queries are available.
63 #[must_use]
64 pub fn ray_query(&self) -> bool {
65 self.flags.contains(CapabilityFlags::RAY_QUERY)
66 }
67
68 /// Mesh shading is available.
69 #[must_use]
70 pub fn mesh_shaders(&self) -> bool {
71 self.flags.contains(CapabilityFlags::MESH_SHADERS)
72 }
73
74 /// Bindless descriptor arrays are available.
75 #[must_use]
76 pub fn bindless(&self) -> bool {
77 self.flags.contains(CapabilityFlags::BINDLESS)
78 }
79
80 /// GPU timestamp queries are available.
81 #[must_use]
82 pub fn timestamp_queries(&self) -> bool {
83 self.flags.contains(CapabilityFlags::TIMESTAMP_QUERIES)
84 }
85
86 /// Subgroup operations are available.
87 #[must_use]
88 pub fn subgroup_ops(&self) -> bool {
89 self.flags.contains(CapabilityFlags::SUBGROUP_OPS)
90 }
91}
92
93#[cfg(test)]
94#[path = "capabilities_tests.rs"]
95mod tests;