GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
src/vk/mod.rs (3.5K)
1 //! The toolkit's raw-Vulkan (ash) renderer — the workspace-wide replacement for
2 //! the wgpu backend, grown in cce-designer (milestones 1–3 + cutover) and moved
3 //! here for general use.
4 //!
5 //! `VkRenderer` owns the whole stack: instance (+ validation layers in debug
6 //! builds or with `CCE_VK_VALIDATION=1`), `VK_KHR_wayland_surface`, sRGB
7 //! swapchain (premultiplied alpha, FIFO), gpu-allocator memory, and three
8 //! pipelines compiled from WGSL through naga at startup:
9 //!
10 //! - **2D** (`shader2d.wgsl`): the union of the engine and designer dialects —
11 //! quads with circle clipping, the wavy-blob sentinel, window-corner
12 //! rounding (radius 0 disables), and blur-behind plates (negative alpha)
13 //! sampling the renderer-managed backdrop.
14 //! - **Text** (`glyph.wgsl` + [`TextSpan`]): cosmic-text shaping (a direct dependency since the
15 //! wgpu path retired) + swash rasterization into a self-managed glyph atlas, with
16 //! per-span bounds clipping, rotation, and circle clipping.
17 //! - **3D** (`scene3d.wgsl` + [`SceneDraw`]): handle-based [`Vertex3D`] meshes
18 //! with a depth buffer, rendered into the full-size backdrop image
19 //! (scissored to a pane) and copied beneath the UI pass — the same image is
20 //! the blur-behind source.
21 //!
22 //! A fourth pipeline is built lazily on first use:
23 //!
24 //! - **RT** (`rt.wgsl` + [`RtTriangle`]/[`RtMaterial`]/[`RtCamera`]): the
25 //! tier-1 compute path tracer — CPU-built SAH BVH in storage buffers,
26 //! progressive accumulation, blitted into the backdrop's viewport-pane
27 //! region as a drop-in alternative to the raster 3D pass. Plain compute:
28 //! no `VK_KHR_ray_*` needed.
29 //!
30 //! And beside the pipelines, one seam that is not a pipeline:
31 //!
32 //! - **Compute jobs** ([`ComputeDevice`] + [`Kernel`] + [`Binding`]): upload
33 //! buffers, dispatch a WGSL compute entry point on a headless device, read
34 //! back. The RT pass's machinery with a general face, for consumers with
35 //! arrays to transform (cce-designer's solver operators).
36 //!
37 //! The wgpu↔Vulkan Y-flip is a negative-height viewport (like wgpu-hal), NOT
38 //! naga's ADJUST_COORDINATE_SPACE — a shader-side flip would reverse winding
39 //! and break the 3D pipeline's back-face culling.
40
41 mod compute;
42 mod core;
43 pub mod image;
44 mod renderer;
45 mod rt;
46 #[cfg(test)]
47 mod plate_probe;
48 mod scene;
49 mod text;
50
51 pub use compute::{workgroups, BindKind, Binding, ComputeDevice, Kernel, MAX_BINDINGS};
52 pub use core::{SurfaceLost, SurfaceTarget, VkCore};
53 pub use image::{
54 free_image, recycle_buffer, renderer_epoch, update_pixel_regions, update_pixels,
55 upload_pixels, upload_rgba, upload_rgba_mipmapped, ImageQuad, PixelFormat, Region,
56 };
57 pub use renderer::{Batch2D, Frame2D, PlatePush, VkRenderer, MAX_PLATE_FEATURES};
58 pub(crate) use renderer::present_debug;
59 pub use rt::{PreparedRtScene, RtCamera, RtEnvironment, RtImage, RtImagePixels, RtMaterial, RtOffscreen, RtTriangle};
60 pub use scene::{MeshId, SceneDraw, SceneImage, Vertex3D};
61 pub use text::TextSpan;
62
63 /// Pay the process-wide, window-independent renderer costs up front: the
64 /// shared Vulkan instance (ICD enumeration + driver init), one throwaway
65 /// device (loads the driver's device-level libraries), and unpacking the
66 /// shaders' SPIR-V (compiled by build.rs; naga no longer runs here). For daemon-style processes (cce-cloud) that build a renderer per
67 /// window: called at daemon startup, it moves the multi-second cold-cache hit
68 /// off the first window's critical path.
69 pub fn prewarm() {
70 renderer::shader2d_spirv();
71 renderer::glyph_spirv();
72 renderer::scene3d_spirv();
73 drop(VkCore::new_headless());
74 }