GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
src/vk/mod.rs (3.3K)
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 mod scene;
47 mod text;
48
49 pub use compute::{workgroups, BindKind, Binding, ComputeDevice, Kernel, MAX_BINDINGS};
50 pub use core::VkCore;
51 pub use image::{
52 free_image, recycle_buffer, renderer_epoch, update_pixels, upload_pixels, upload_rgba, ImageQuad,
53 PixelFormat,
54 };
55 pub use renderer::{Batch2D, Frame2D, PlatePush, VkRenderer, MAX_PLATE_FEATURES};
56 pub use rt::{RtCamera, RtMaterial, RtOffscreen, RtTriangle};
57 pub use scene::{MeshId, SceneDraw, Vertex3D};
58 pub use text::TextSpan;
59
60 /// Pay the process-wide, window-independent renderer costs up front: the
61 /// shared Vulkan instance (ICD enumeration + driver init), one throwaway
62 /// device (loads the driver's device-level libraries), and the naga WGSL
63 /// compiles. For daemon-style processes (cce-cloud) that build a renderer per
64 /// window: called at daemon startup, it moves the multi-second cold-cache hit
65 /// off the first window's critical path.
66 pub fn prewarm() {
67 renderer::shader2d_spirv();
68 renderer::glyph_spirv();
69 renderer::scene3d_spirv();
70 drop(VkCore::new_headless());
71 }