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
// SPDX-FileCopyrightText: Copyright 2025 Au-Zone Technologies
// SPDX-License-Identifier: Apache-2.0
// Several types defined at the `gl` module root (EglDisplayKind,
// TransferBackend, RegionOfInterest, etc.) are consumed only by the
// Linux-only inner modules (`context`, `processor`, ...). The macOS
// path uses its own `MacosGlProcessor` + `iosurface_import` modules and
// does not touch every shared type, so some appear unused on macOS.
// Rather than fragmenting the type definitions per platform, suppress
// the dead-code lint on non-Linux targets.
// Module layout:
// - `platform/` — cross-platform display/EGL-loader seam (both OSes)
// - Linux-only: `context`, `processor`, `threaded`, `dma_import`,
// `cache`, `resources`, `shaders`, `tests`
// - macOS-only: `iosurface_import`, `macos_processor`
// The macOS processor is parallel to (not a refactor of) the Linux
// threaded processor — see `crates/image/ARCHITECTURE.md` for the
// rationale and the planned convergence story.
// Cfg-agnostic: the float render-path classifier is the single source of
// truth for the "(PixelFormat, DType, TensorMemory) → float path" decision and
// is compiled on every platform so both the Linux and macOS backends share one
// definition (see `crates/image/ARCHITECTURE.md`, review item #4).
// Portable renderer helpers (crop uniforms, …) shared by both platform
// backends. No gbm/IOSurface types; compiled on both.
// Pure decision table for the proto-segmentation render path (upload
// strategy × program × count uniform). No GL types; host-tested
// exhaustively. See `proto_dispatch.rs`.
// Portable GL render lowering (y-flip viewport, source UV, batch chunk planner).
// No platform types; compiled on both platforms, consumed by the converged
// tile/batch renderer. See `render.rs`.
// PixelFormat -> DRM FourCC mapping via the portable `drm_fourcc` crate (NOT
// `gbm`). DRM FourCC is a Linux/DMA-BUF concept, so this lives with the other
// Linux graphics modules; the point is that it carries no `gbm` coupling, so
// `shaders.rs` and the format code no longer pull in `gbm`.
// Engine GL tests, in three tiers (see crates/image/TESTING.md):
// portable — run on Linux AND macOS/ANGLE
// cfg(target_os = "linux") — display probing, PBO/CUDA paths
// cfg(all(linux, dma_test_formats)) — DMA-BUF import/pool specifics
// Per-item cfg gates inside the module select the tier; the mount
// itself is unconditional so the macOS lane runs the portable tier.
pub use probe_egl_displays;
// These are accessed by sibling sub-modules via `super::context::` directly.
// No re-export needed at the mod.rs level.
pub use ;
pub use GLProcessorThreaded;
/// Dynamically-loaded EGL 1.4 instance. The lifetime parameter is
/// `'static` because the underlying `libloading::Library` is intentionally
/// leaked at first load (see `EGL_LIB` in `context.rs` and the equivalent
/// on macOS — drivers may retain internal state past explicit cleanup, so
/// dlclose can SIGBUS on process exit).
///
/// Defined here at the `gl` module root so the `platform/` trait and both
/// platform implementations can name it without dragging in a cross-cfg
/// re-export. The Linux `context.rs` and the macOS `platform/macos.rs`
/// both use this same alias.
pub type Egl =
Instance;
/// Identifies the type of EGL display used for headless OpenGL ES rendering.
///
/// The HAL creates a surfaceless GLES 3.0 context
/// (`EGL_KHR_surfaceless_context` + `EGL_KHR_no_config_context`) and
/// renders exclusively through FBOs backed by EGLImages imported from
/// DMA-buf file descriptors. No window or PBuffer surface is created.
///
/// Displays are probed in priority order: PlatformDevice first (zero
/// external dependencies), then GBM, then Default. Use
/// [`probe_egl_displays`] to discover which are available and
/// [`ImageProcessorConfig::egl_display`](crate::ImageProcessorConfig::egl_display)
/// to override the auto-detection.
///
/// # Display Types
///
/// - **`PlatformDevice`** — Uses `EGL_EXT_device_enumeration` to query
/// available EGL devices via `eglQueryDevicesEXT`, then selects the first
/// device with `eglGetPlatformDisplay(EGL_EXT_platform_device, ...)`.
/// Headless and compositor-free with zero external library dependencies.
/// Works on NVIDIA GPUs and newer Vivante drivers.
///
/// - **`Gbm`** — Opens a DRM render node (e.g. `/dev/dri/renderD128`) and
/// creates a GBM (Generic Buffer Manager) device, then calls
/// `eglGetPlatformDisplay(EGL_PLATFORM_GBM_KHR, gbm_device)`. Requires
/// `libgbm` and a DRM render node. Needed on ARM Mali (i.MX95) and older
/// Vivante drivers that do not expose `EGL_EXT_platform_device`.
///
/// - **`Default`** — Calls `eglGetDisplay(EGL_DEFAULT_DISPLAY)`, letting the
/// EGL implementation choose the display. On Wayland systems this connects
/// to the compositor; on X11 it connects to the X server. May block on
/// headless systems where a compositor is expected but not running.
/// A validated, available EGL display discovered by [`probe_egl_displays`].
/// Tracks which data-transfer method is active for moving pixels
/// between CPU memory and GPU textures/framebuffers.
pub
/// Interpolation mode for int8 proto textures (GL_R8I cannot use GL_LINEAR).
/// A rectangular region of interest expressed as normalised [0, 1] coordinates.
pub