concinnity_engine/device.rs
1//! The rendering backend this build links, behind two entry points that exist
2//! whether or not one is linked.
3//!
4//! A build with no backend feature has no `concinnity-device` in its graph at
5//! all. Both answers the callers need are already part of the contract: backend
6//! construction reports failure by yielding no backend, and an unclassified GPU
7//! is what quality auto-config falls back to.
8
9use crate::gfx::backend::{GpuProfile, RenderBackend};
10use crate::gfx::backend_init::BackendInit;
11
12/// Whether a rendering backend compiles into this build. False leaves the
13/// headless loop as the only one that can run a world.
14pub const AVAILABLE: bool = cfg!(any(backend_metal, backend_dx, backend_vk));
15
16/// Classify the GPU for quality auto-config.
17pub(crate) fn probe_gpu_profile() -> GpuProfile {
18 #[cfg(any(backend_metal, backend_dx, backend_vk))]
19 {
20 concinnity_device::probe_gpu_profile()
21 }
22 #[cfg(not(any(backend_metal, backend_dx, backend_vk)))]
23 {
24 GpuProfile::UNKNOWN
25 }
26}
27
28/// Build the backend the client draws through, or report that there is none.
29pub(crate) fn init_backend(init: BackendInit<'_>) -> Option<Box<dyn RenderBackend>> {
30 #[cfg(any(backend_metal, backend_dx, backend_vk))]
31 {
32 concinnity_device::init_backend(init)
33 }
34 #[cfg(not(any(backend_metal, backend_dx, backend_vk)))]
35 {
36 let _ = init;
37 None
38 }
39}