Skip to main content

astrelis_render/batched/
capability.rs

1//! Render capability types for the batched renderer tiers.
2//!
3//! Each struct represents a specific tier's GPU requirements.
4//! Use [`BestBatchCapability2D`] for auto-detection with graceful degradation.
5
6use crate::capability::{GpuRequirements, RenderCapability};
7use crate::features::GpuFeatures;
8
9use super::BINDLESS_MAX_TEXTURES;
10
11/// Capability for the Direct (Tier 1) batch renderer.
12///
13/// No special GPU features required — works on all hardware.
14pub struct DirectBatchCapability2D;
15
16impl RenderCapability for DirectBatchCapability2D {
17    fn requirements() -> GpuRequirements {
18        GpuRequirements::none()
19    }
20
21    fn name() -> &'static str {
22        "DirectBatchCapability2D (Tier 1)"
23    }
24}
25
26/// Capability for the Indirect (Tier 2) batch renderer.
27///
28/// Requires `INDIRECT_FIRST_INSTANCE` for `multi_draw_indirect()` with per-instance offsets.
29pub struct IndirectBatchCapability2D;
30
31impl RenderCapability for IndirectBatchCapability2D {
32    fn requirements() -> GpuRequirements {
33        GpuRequirements::new()
34            .require_features(GpuFeatures::INDIRECT_FIRST_INSTANCE)
35    }
36
37    fn name() -> &'static str {
38        "IndirectBatchCapability2D (Tier 2)"
39    }
40}
41
42/// Capability for the Bindless (Tier 3) batch renderer.
43///
44/// Requires indirect draw, texture binding arrays, partial binding, and
45/// non-uniform indexing. Also requires elevated `max_binding_array_elements_per_shader_stage`.
46pub struct BindlessBatchCapability2D;
47
48impl RenderCapability for BindlessBatchCapability2D {
49    fn requirements() -> GpuRequirements {
50        GpuRequirements::new()
51            .require_features(
52                GpuFeatures::INDIRECT_FIRST_INSTANCE
53                    | GpuFeatures::TEXTURE_BINDING_ARRAY
54                    | GpuFeatures::PARTIALLY_BOUND_BINDING_ARRAY
55                    | GpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
56            )
57            .with_min_limits(|l| {
58                l.max_binding_array_elements_per_shader_stage = BINDLESS_MAX_TEXTURES;
59            })
60    }
61
62    fn name() -> &'static str {
63        "BindlessBatchCapability2D (Tier 3)"
64    }
65}
66
67/// Capability for auto-detecting the best batch renderer tier.
68///
69/// All features are **requested** (not required), so device creation succeeds
70/// on any hardware. At runtime, [`super::detect_render_tier`] picks the
71/// highest supported tier.
72///
73/// This is the recommended capability for most applications.
74pub struct BestBatchCapability2D;
75
76impl RenderCapability for BestBatchCapability2D {
77    fn requirements() -> GpuRequirements {
78        GpuRequirements::new()
79            .request_features(
80                GpuFeatures::INDIRECT_FIRST_INSTANCE
81                    | GpuFeatures::TEXTURE_BINDING_ARRAY
82                    | GpuFeatures::PARTIALLY_BOUND_BINDING_ARRAY
83                    | GpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
84            )
85            .with_min_limits(|l| {
86                l.max_binding_array_elements_per_shader_stage = BINDLESS_MAX_TEXTURES;
87            })
88    }
89
90    fn name() -> &'static str {
91        "BestBatchCapability2D (auto-detect)"
92    }
93}