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