1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
//! **The L0 GPU lane** (feature `wgpu`) — the extracted shared scaffold the three
//! skin kernels (facett-map `GpuMapRenderer`, facett-map3d `Map3dRenderer`,
//! facett-graph3d `LogoRenderer`) will be re-pointed at in Phase C.
//!
//! All three share the identical `egui_wgpu::CallbackTrait` plumbing: a `*Renderer`
//! stored in `callback_resources`, **installed once** via an `install_renderer`,
//! driven by a paint callback. Phase A extracts:
//!
//! - [`types`] — the bytemuck `Vertex`/`Uniform`/`DrawIndirectArgs` structs +
//! `color32_to_f32` (byte-identical to the skins' copies).
//! - [`buffer`] — the upload-once + **chunking** algorithm (fix #12), verbatim.
//! - [`install_renderer`] — the install-once lifecycle each kernel hand-rolls.
//! - [`CULL_WGSL`] / [`DRAW_WGSL`] — the cull + draw shaders, **byte-identical** to
//! `facett-map/src/gpu/*.wgsl` (do not change their semantics).
//!
//! Nothing in the skins consumes this yet — it is the scaffold for Phase B/C.
/// **wgpu glue for the adapter-selection policy** — `wgpu::AdapterInfo` →
/// [`AdapterFacts`](crate::render::adapter::AdapterFacts), the live selector, the
/// `request_best_adapter` replacement for the naive headless probes, and the
/// `egui_wgpu::WgpuConfiguration` an eframe host installs. See [`adapter_wgpu`].
/// **THE shared instanced graph-cloud renderer** — screen-space emissive node discs
/// + edge filaments as GPU instances, plus the live `egui_wgpu` paint callback and
/// its install-once lifecycle. Consumed by `facett-graph3d` (which re-exports it as
/// `graph_gpu`) AND by the 2-D graph family (`facett-graphpan` / `facett-graphview` /
/// `facett-graphnav`). See [`graphcloud`].
/// **Final-look colour grade** (AgX tonemap + vignette + film grain + CAS sharpen +
/// blue-noise-style dither) as an optional post over the HDR offscreen colour — a
/// new, composable seam that does **not** touch the map3d ACES tonemap. See
/// [`colorgrade`].
/// **GPU label collision + the indirect label draw** (GFX_V2 §3.B item 4) — three
/// compute passes over a fixed spatial grid whose third pass *produces the draw* by
/// `atomicAdd`ing onto a `DrawIndirectArgs`. The collision rule itself lives in
/// [`crate::label_grid`]; the WGSL here is its device transcription. See
/// [`label_collide`].
/// **MSDF text / label rendering** — crisp glowing labels at any zoom from a
/// multi-channel signed-distance-field atlas. See [`msdf`].
/// **The in-GPU pass clock** — TIMESTAMP_QUERY around a lane's encoded passes,
/// resolved through a non-blocking readback ring into the per-lane clock stats
/// (`crate::render::lane::clock_stats_of`). Feature-detected; a device without the
/// feature reports `None`, never `0`. See [`pass_clock`].
/// **OIT — order-independent transparency via per-pixel fragment linked lists**
/// (GFX_V2 §3.C item 7): gather every translucent fragment onto its pixel's list,
/// then sort and composite per pixel in one fullscreen resolve. See [`oit`].
/// **GPU picking — the colour-encoded ID pass** (GFX_V2 §7 item 8): render pickable
/// geometry into an `R32Uint` target where the value IS the [`PickId`](crate::engine::pick::PickId),
/// then read back the texel under the cursor. See [`picking`].
/// **The host lane for GPU picking** — install-once + the one `pick_at` entry point a
/// widget calls to turn a click into a `PickId`. See [`pick_host`].
/// **GPU compute particles** — storage-buffer boids stepped in a compute shader and
/// drawn as soft additive points into the HDR target. See [`particles`].
/// **THE one GPU→CPU readback** — the `map_async` + row-padding dance, spelled once
/// instead of in seventeen hand-rolled copies. See [`readback`].
/// **Scene3D, the GPU lane** — flat quads, screen-width lines and SDF text on world
/// planes, depth-tested in one pass and blitted into egui. See [`scene3d`].
/// **TAA — Halton jitter + a velocity-reprojecting temporal resolve** (GFX_V2 §5
/// item 7): the fix for sub-pixel vector lines shimmering under camera motion, which
/// MSAA cannot solve. See [`taa`].
pub use ;
pub use ;
pub use ;
pub use CloudModelPaintCallback;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// **The shader TEXT lives in [`crate::render::wgsl`]**, which is NOT behind this
/// feature — a `.wgsl` source string needs `include_str!` and nothing else, and
/// keeping it here put the shader-CONTRACT guards (`cull.wgsl` is the shader every
/// road on the map goes through) out of reach of a default `cargo test`. Re-exported
/// so every existing `facett_core::render::gpu::*_WGSL` path still resolves.
pub use crate;
/// **THE RULING: MSAA is not facett's anti-aliasing scheme, and this is the one writer of
/// that.** (Since 2026-09-05 there is exactly ONE multisampled target in the workspace,
/// and it is not there for anti-aliasing — see *The ONE exception* below.)
/// TAA is the 3D anti-aliasing scheme ([`taa`]); the analytic feather in
/// `facett-map/src/gpu/line.wgsl` is the 2D one. Every render pipeline in every facett
/// crate names [`msaa_state()`] and every render target names [`NO_MSAA_SAMPLES`],
/// instead of the 26 + 26 scattered `MultisampleState::default()` / `sample_count: 1`
/// literals that used to state the same thing fifty-two times over.
///
/// # Why not MSAA
///
/// * **Our own shaders already beat it at its own job.** `line.wgsl` extends the
/// geometry by `feather_px` and takes fragment alpha from `coverage_inside(edge_px,
/// feather_px)` — true analytic coverage, resolution-independent, costing no
/// framebuffer. That is the technique the professional GL map renderers use, for the
/// content that dominates a map frame.
/// * **MSAA does not fix what actually looks bad.** A 1 px road at 4× has four coverage
/// steps and still crawls when the camera rotates, because *which* subsamples it
/// covers changes discontinuously. That sentence is in [`taa`]'s own header and is
/// why TAA was written.
/// * **It does not compose with what map3d already runs.** A deferred SSAO G-buffer and
/// a screen-space post stack are exactly the category MSAA is bad for: it multiplies
/// colour+depth bandwidth and breaks screen-space effects.
/// * **And the failure mode is HARD.** `MultisampleState::default()` is `count: 1`. A
/// pipeline left on the default while its target goes to 4× is a wgpu **validation
/// failure**, not a soft downgrade. Fifty-two literals is fifty-two chances to miss
/// one on a path nobody exercises — so if MSAA is ever genuinely wanted, the LAW-5
/// form is to change these two items and let every site follow.
/// * **Two AA schemes composed by accident is worse than either.** facett ships TAA.
///
/// # The ONE exception, and why it does not erode any of the above
///
/// Since lane GG #2 (2026-09-05) the map's offscreen colour+depth pair is **4×** —
/// `facett_map::gpu::MAP_MSAA_SAMPLES` / `map_msaa_state()`, and nothing else in the
/// workspace is. Read the reasons above again and none of them is what it buys: it buys
/// per-sample **DEPTH**, and no other mechanism here can supply that.
///
/// Lane MP-a gave the map its own depth buffer so the declared paint rank could survive
/// being split across tiles. With one depth value per PIXEL, a partially covered edge
/// fragment must choose between compositing and owning the pixel — and it owns it, so the
/// lower-ranked way underneath is depth-rejected rather than blended and what shows is the
/// winner over bare paper. MEASURED on oden / RTX 4090: across a motorway's whole 7 px
/// footprint the frame with a residential beneath it was bit-identical to the frame
/// without. `MAP_MSAA_SAMPLES` carries the numbers.
///
/// Note also what the exception is NOT: 4× alone changes nothing there, and was measured
/// not to. The road shader rasterises its quad one feather wider than the road, so the
/// rasteriser already sees full coverage at exactly those pixels; the coverage lives in
/// the fragment alpha and `line.wgsl` hands it back through `@builtin(sample_mask)`. MSAA
/// is the substrate that makes a sample mask mean something, not the fix.
///
/// It is a second named writer rather than a bump of [`NO_MSAA_SAMPLES`] for the reason
/// this whole item exists: raising the constant would put all fifty-odd sites on 4×,
/// including [`picking`], whose `R32Uint` target cannot be multisampled at all.
///
/// `tests/one_msaa_writer.rs` scans the source tree and fails if a naked
/// `MultisampleState` literal or a bare `sample_count:` reappears outside this file — and
/// pins the exception to one declaration in one file, so it cannot spread.
pub const
/// **The sample count every facett render target is allocated at** — see
/// [`msaa_state()`] for the ruling this encodes. `1` is not a placeholder awaiting a
/// bump: raising it here alone would leave every pipeline on `count: 1` and turn the
/// next frame into a wgpu validation failure.
pub const NO_MSAA_SAMPLES: u32 = 1;
/// **A texture size the device can make**: `w × h` (at least 1 × 1) with each side
/// clamped to `max` (`device.limits().max_texture_dimension_2d`). A pane wider than
/// the limit renders into the clamped target and the blit scales it back over the
/// pane — a softer picture, never a wgpu validation panic. MEASURED 2026-10-16 on loki
/// (RTX 5080, limit 8192): `l0_offscreen_color` asked 10 604 px wide and killed
/// dwarves-ui-gpu.
/// [`clamp_extent`] against `device`'s own limit.
/// **Install-once** lifecycle, generic over the renderer type — the pattern all
/// three skin kernels hand-roll (`install_renderer` in facett-map / facett-map3d /
/// facett-graph3d). If a renderer of type `R` is already in the egui-wgpu
/// `RenderState`'s `callback_resources`, this is a no-op; otherwise `make` builds
/// one (from the device + target format) and inserts it. Hosts call this once at
/// startup so the paint callback can `resources.get::<R>()`.
///
/// Returns `true` if a renderer was newly installed, `false` if one already existed.
///
/// It also **registers the lane** with [`crate::render::lane`] under
/// `std::any::type_name::<R>()`, whether or not this call did the inserting. That is
/// how an About box can say "a GPU lane is installed" without every lane wiring
/// itself up: the one install writer is the one place that knows. A lane that also
/// counts frames declares it next to its own install
/// ([`lane::note_reports_frames`](crate::render::lane::note_reports_frames)).
///
/// It opens NO error scope: a pipeline `make` built invalid goes to the device's
/// uncaptured-error handler. [`install_renderer_checked`] is the same install under a
/// validation scope, with the verdict reported through the lane registry.
/// **[`install_renderer`] under a wgpu VALIDATION error scope** — the same synchronous
/// install-once, plus the device's verdict on everything `make` created.
///
/// `make` builds shader modules, pipelines and buffers, and wgpu does not report an
/// invalid one as a return value: the error goes to the device's uncaptured-error
/// handler (native: a panic; web: a console line and a pane that draws nothing), and
/// [`install_renderer`] opens no scope, so that error had no owner. This pushes
/// `ErrorFilter::Validation`, installs, pops the scope, and routes a captured error to
/// [`lane::note_gpu_error`](crate::render::lane::note_gpu_error) — and UNDOES the
/// install: the renderer leaves `callback_resources` and
/// [`lane::is_installed`](crate::render::lane::is_installed) goes `false`, so the pane's
/// CPU painter draws instead of a pipeline the device refused.
///
/// **Synchronous, never blocking.** Every facett host installs inside eframe's
/// `CreationContext` (facet-wrapped `wasm.rs`, facett-demo `main.rs`,
/// facett-wasm-demo `lib.rs`), which cannot `await`. The popped scope is a future:
///
/// * **native** — wgpu-core resolves it when the scope is popped, so ONE poll with a
/// no-op waker settles it before this returns. Should a backend ever answer
/// `Pending`, the future goes to a detached thread that parks until woken — never
/// the caller's thread, and no `pollster`.
/// * **wasm32** — the browser answers asynchronously, so the verdict is settled on
/// `wasm_bindgen_futures::spawn_local` and lands a few frames later; until then the
/// renderer is installed and draws, exactly as with [`install_renderer`].
///
/// Returns `true` if this call installed the renderer and no refusal is known when it
/// returns (on wasm32 a refusal arrives later — read `lane::is_installed` /
/// `lane::gpu_error`). `false` = it was already installed (`make` never ran), or the
/// device refused it (native).
/// Settle a popped error scope WITHOUT blocking the caller: `Some(on_verdict(..))` when
/// the verdict was ready on the first poll, `None` when it was handed on.
/// Settle a popped error scope WITHOUT blocking the caller — on the browser's event
/// loop; the verdict always lands later, so this always returns `None`.