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::{build, geometry};
39pub(crate) use concinnity_host::thread::jobs;
40
41// The job pool as a `RowScheduler`, for the probe bake.
42pub(crate) mod pool_rows;
43
44#[cfg(backend_dx)]
45pub(crate) mod directx;
46#[cfg(backend_metal)]
47pub mod metal;
48#[cfg(backend_vk)]
49pub(crate) mod vulkan;
50// Native Win32 window/input/display-mode layer shared by the HWND-rendering
51// backends (DirectX always; Vulkan on Windows instead of GLFW).
52#[cfg(all(target_os = "windows", any(backend_dx, backend_vk)))]
53pub(crate) mod win32;
54// Native AppKit window/input/display-mode layer shared by the NSView-rendering
55// backends (Metal always; Vulkan on macOS instead of GLFW).
56#[cfg(all(target_os = "macos", any(backend_metal, backend_vk)))]
57pub(crate) mod appkit;
58
59// Disk cache for shader binaries compiled after build time: the built-ins the
60// DirectX and Vulkan backends compile at init, and the Metal raymarch
61// libraries assembled from world-authored SdfVolume fragments (the rest of
62// Metal precompiles into the binary via the toolchain crate).
63pub(crate) mod shader_cache;
64
65// Shared source assembly for the single-source `.slang` shaders every backend
66// draws from.
67#[cfg(any(backend_dx, backend_vk, backend_metal))]
68pub(crate) mod slang_source;
69
70// Disk persistence for driver pipeline blobs (VkPipelineCache, D3D12 pipeline
71// library). Metal needs none: its libraries are precompiled or cached above,
72// and the OS maintains the per-app pipeline binary cache.
73#[cfg(any(backend_dx, backend_vk))]
74pub(crate) mod pipeline_cache;
75
76// Export-time precompilation of the built-in shaders into a bundle's
77// shader-cache/. Backends whose shaders compile at renderer init (DX, VK)
78// declare their compile set as data; `cn export` compiles it here, in-process,
79// with no GPU device. Metal precompiles at build time and needs none of this.
80#[cfg(any(backend_dx, backend_vk))]
81pub mod precompile;
82
83// Test-only probe for the shader compiler the single-source `.slang` shaders
84// need, so the compile checks skip a host without one instead of failing.
85#[cfg(test)]
86mod slangc_gate;
87
88// Cross-backend drift guard for the shared `GpuObjectData` shader fragments.
89// Test-only and backend-agnostic on purpose: the fragments are checked as text,
90// so one build validates all three languages.
91#[cfg(test)]
92mod object_data_layout;
93
94// Reflection-driven layout guard for the `#[repr(C)]` structs the CPU uploads
95// into the single-source `.slang` shaders: the expected offsets come from
96// slangc, per target, rather than from a hand-written number.
97#[cfg(test)]
98mod shader_layout;
99
100// Ownership guard for the explicit backends' resource barriers. Test-only and
101// backend-agnostic for the same reason as the fragment guard above: the call
102// sites are counted as text, so one build audits both explicit backends.
103#[cfg(test)]
104mod barrier_audit;
105
106// The companion guard: `barrier_audit` proves every barrier is classified, this
107// one proves a classified barrier is not redundant with one the graph executor
108// already emits. Same text-scanning rationale, so it also covers DirectX from a
109// macOS build.
110#[cfg(test)]
111mod double_drive_audit;
112
113// Device-memory placement policy shared by the backends' allocators.
114pub(crate) mod suballoc;
115
116mod factory;
117pub use factory::{init_backend, probe_gpu_profile};