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().require_features(GpuFeatures::INDIRECT_FIRST_INSTANCE)
34    }
35
36    fn name() -> &'static str {
37        "IndirectBatchCapability2D (Tier 2)"
38    }
39}
40
41/// Capability for the Bindless (Tier 3) batch renderer.
42///
43/// Requires indirect draw, texture binding arrays, partial binding, and
44/// non-uniform indexing. Also requires elevated `max_binding_array_elements_per_shader_stage`.
45pub struct BindlessBatchCapability2D;
46
47impl RenderCapability for BindlessBatchCapability2D {
48    fn requirements() -> GpuRequirements {
49        GpuRequirements::new()
50            .require_features(
51                GpuFeatures::INDIRECT_FIRST_INSTANCE
52                    | GpuFeatures::TEXTURE_BINDING_ARRAY
53                    | GpuFeatures::PARTIALLY_BOUND_BINDING_ARRAY
54                    | GpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
55            )
56            .with_min_limits(|l| {
57                l.max_binding_array_elements_per_shader_stage = BINDLESS_MAX_TEXTURES;
58            })
59    }
60
61    fn name() -> &'static str {
62        "BindlessBatchCapability2D (Tier 3)"
63    }
64}
65
66/// Capability for auto-detecting the best batch renderer tier.
67///
68/// All features are **requested** (not required), so device creation succeeds
69/// on any hardware. At runtime, [`super::detect_render_tier`] picks the
70/// highest supported tier.
71///
72/// This is the recommended capability for most applications.
73pub struct BestBatchCapability2D;
74
75impl RenderCapability for BestBatchCapability2D {
76    fn requirements() -> GpuRequirements {
77        GpuRequirements::new()
78            .request_features(
79                GpuFeatures::INDIRECT_FIRST_INSTANCE
80                    | GpuFeatures::TEXTURE_BINDING_ARRAY
81                    | GpuFeatures::PARTIALLY_BOUND_BINDING_ARRAY
82                    | GpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
83            )
84            .with_min_limits(|l| {
85                l.max_binding_array_elements_per_shader_stage = BINDLESS_MAX_TEXTURES;
86            })
87    }
88
89    fn name() -> &'static str {
90        "BestBatchCapability2D (auto-detect)"
91    }
92}