Skip to main content

concinnity_device/
lib.rs

1//! The device backends. The proprietary, hardware-facing renderers - Metal
2//! (macOS), DirectX 12 (Windows), Vulkan (Windows/Linux) - plus the shared native
3//! Win32 window/input layer. At most one backend compiles per build, resolved by
4//! build.rs from the backend features into a single backend_* cfg; a build that
5//! names none compiles no GPU code at all. Depends on concinnity-core, whose
6//! `render` module holds the RenderBackend/SceneControl trait seam these
7//! implement plus the render-prep feeding it; owns no gameplay, ECS-runtime,
8//! audio, or physics. The client drives these through a
9//! `Box<dyn RenderBackend>` obtained from `init_backend`, never naming a concrete
10//! context type.
11
12// Bridge so the backends' historical `crate::gfx::<X>` paths resolve: the GPU
13// data layouts, render math, and CPU kernels (`concinnity_core::gfx`) plus the
14// render-prep modules (`concinnity_core::render`). Each
15// backend consumes a different subset and one backend compiles per build, so a
16// portion of these re-exports is unused on any given build - suppress it
17// crate-wide rather than gate every item per backend.
18#[expect(
19    unused_imports,
20    reason = "one backend compiles per build, so each consumes only a subset of these re-exports"
21)]
22pub(crate) mod gfx {
23    pub(crate) use concinnity_core::gfx::{
24        auto_exposure, frustum, image_decode, lod, mesh_payload, morph_targets, profile,
25        render_types, rt_reflections, ssao, ssgi, ssr,
26    };
27    pub(crate) use concinnity_core::render::{
28        backend, backend_init, csm, decal, display_mode, draw_slot, error, fullscreen, hdr_output,
29        input, keymap, lights, ltc, mipmap, parallel_ctx, particles, planar_reflection,
30        reflection_probe, render_graph, rt_geom, rt_refit, rt_topology, scene_flow, shadow_bias,
31        shadow_schedule, skinned_pool, slot_rewrites, spot_shadow, transparent, volumetric_fog,
32    };
33}
34
35// Asset data types, the runtime build helpers, and the mesh/chunk geometry the
36// backends reach by their historical `crate::` paths, plus the shared rayon job
37// pool.
38#[cfg(any(backend_metal, backend_dx, backend_vk))]
39pub(crate) use concinnity_core::components;
40#[cfg(any(backend_metal, backend_dx, backend_vk))]
41pub(crate) use concinnity_core::{bake, geometry};
42#[cfg(any(backend_metal, backend_dx, backend_vk))]
43pub(crate) use concinnity_host::thread::jobs;
44
45#[cfg(backend_dx)]
46pub(crate) mod directx;
47#[cfg(backend_metal)]
48pub mod metal;
49#[cfg(backend_vk)]
50pub(crate) mod vulkan;
51// Native Win32 window/input/display-mode layer shared by the HWND-rendering
52// backends (DirectX always; Vulkan on Windows instead of GLFW).
53#[cfg(all(target_os = "windows", any(backend_dx, backend_vk)))]
54pub(crate) mod win32;
55// Native AppKit window/input/display-mode layer shared by the NSView-rendering
56// backends (Metal always; Vulkan on macOS instead of GLFW).
57#[cfg(all(target_os = "macos", any(backend_metal, backend_vk)))]
58pub(crate) mod appkit;
59
60// The runtime cache segment both caches below write into, and the checkpoints
61// at which it reaches disk.
62#[cfg(any(backend_metal, backend_dx, backend_vk))]
63pub(crate) mod runtime_cache;
64
65// Disk cache for shader binaries compiled after build time: the built-ins the
66// DirectX and Vulkan backends compile at init, and the Metal raymarch
67// libraries assembled from world-authored SdfVolume fragments (the rest of
68// Metal precompiles into the binary via the toolchain crate).
69#[cfg(any(backend_metal, backend_dx, backend_vk))]
70pub(crate) mod shader_cache;
71
72// Scratch directory for the shader compilers that work on files.
73#[cfg(any(backend_dx, backend_vk, backend_metal))]
74pub(crate) mod compiler_work;
75
76// Shared source assembly for the single-source `.slang` shaders every backend
77// draws from.
78#[cfg(any(backend_dx, backend_vk, backend_metal))]
79pub(crate) mod raymarch_source;
80pub(crate) mod slang_source;
81pub(crate) mod surface_source;
82
83// Disk persistence for driver pipeline blobs (VkPipelineCache, D3D12 pipeline
84// library). Metal needs none: its libraries are precompiled or cached above,
85// and the OS maintains the per-app pipeline binary cache.
86#[cfg(any(backend_dx, backend_vk))]
87pub(crate) mod pipeline_cache;
88
89// Export-time precompilation of the built-in shaders into the cache segment a
90// bundle ships. Backends whose shaders compile at renderer init (DX, VK)
91// declare their compile set as data; `cn export` compiles it here, in-process,
92// with no GPU device. Metal precompiles at build time and needs none of this.
93#[cfg(any(backend_dx, backend_vk))]
94pub mod precompile;
95
96// Test-only probe for the shader compiler the single-source `.slang` shaders
97// need, so the compile checks skip a host without one instead of failing. Only
98// a backend has shaders to compile.
99#[cfg(all(test, any(backend_metal, backend_dx, backend_vk)))]
100mod slangc_gate;
101
102// Reflection-driven layout guard for the `#[repr(C)]` structs the CPU uploads
103// into the single-source `.slang` shaders: the expected offsets come from
104// slangc, per target, rather than from a hand-written number. Reads the source
105// assembly a backend brings with it, so a build with none has nothing to check.
106#[cfg(all(test, any(backend_metal, backend_dx, backend_vk)))]
107mod shader_layout;
108
109// Ownership guard for the explicit backends' resource barriers. Test-only and
110// backend-agnostic for the same reason as the fragment guard above: the call
111// sites are counted as text, so one build audits both explicit backends.
112#[cfg(test)]
113mod barrier_audit;
114
115// The companion guard: `barrier_audit` proves every barrier is classified, this
116// one proves a classified barrier is not redundant with one the graph executor
117// already emits. Same text-scanning rationale, so it also covers DirectX from a
118// macOS build.
119#[cfg(test)]
120mod double_drive_audit;
121
122// Device-memory placement policy shared by the backends' allocators.
123#[cfg(any(backend_metal, backend_dx, backend_vk))]
124pub(crate) mod suballoc;
125
126mod factory;
127pub use factory::{init_backend, probe_gpu_profile};