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