euv_core/render/gpu/struct.rs
1use super::*;
2
3/// Probed physical GPU adapter and native shader compilation telemetry.
4#[derive(Clone, Debug, Eq, Getter, New, PartialEq)]
5pub struct GpuAdapterInfo {
6 /// Active graphics backend identifier.
7 #[get(type(copy))]
8 pub(crate) backend: GraphicsBackend,
9 /// Detected physical GPU adapter name (for example `"Apple M3 Max"`).
10 pub(crate) device_name: String,
11 /// True when a real physical OS GPU device/runtime was successfully initialized.
12 #[get(type(copy))]
13 pub(crate) hardware_verified: bool,
14 /// True when the native UI shader (`MSL`/`HLSL`/`GLSL`/`WGSL`) compiled on the host GPU.
15 #[get(type(copy))]
16 pub(crate) shader_compiled: bool,
17}
18
19/// One hardware-fenced staging buffer slot inside `NativeGpuDriver`'s triple-buffered GPU ring.
20#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
21pub struct NativeGpuRingSlot {
22 /// Native OS shared-memory buffer handle (`id<MTLBuffer>` on Apple, `0` when unallocated).
23 #[get(type(copy))]
24 pub(crate) buffer_handle: usize,
25 /// CPU-writable mapped memory address (`[MTLBuffer contents]` on Apple, `0` when unallocated).
26 #[get(type(copy))]
27 pub(crate) contents_ptr: usize,
28 /// Allocated byte capacity of this ring slot buffer.
29 #[get(type(copy))]
30 pub(crate) capacity_bytes: usize,
31 /// Retained in-flight command buffer handle guarding reuse (`id<MTLCommandBuffer>` on Apple).
32 #[get(type(copy))]
33 pub(crate) in_flight_cmd_buffer: usize,
34}
35
36/// Physical OS GPU driver wrapping Metal, D3D12, Vulkan, or WebGL2 with real fenced ring submission and automatic fallback.
37#[derive(Debug, Getter)]
38pub struct NativeGpuDriver {
39 /// Probed physical adapter and shader status.
40 pub(crate) adapter: GpuAdapterInfo,
41 /// Opaque OS GPU device handle (`id<MTLDevice>` on Apple, `0` when fallback).
42 #[get(type(copy))]
43 pub(crate) device_handle: usize,
44 /// Opaque OS GPU command queue handle (`id<MTLCommandQueue>` on Apple, `0` when fallback).
45 #[get(type(copy))]
46 pub(crate) queue_handle: usize,
47 /// Opaque compiled shader library handle (`id<MTLLibrary>` on Apple, `0` when fallback).
48 #[get(type(copy))]
49 pub(crate) library_handle: usize,
50 /// Opaque compiled uber-shader render pipeline handle (`id<MTLRenderPipelineState>` on Apple).
51 #[get(type(copy))]
52 pub(crate) pipeline_handle: usize,
53 /// Opaque compiled Dual-Kawase `BackdropBlur` pipeline handle (`id<MTLRenderPipelineState>` on Apple).
54 #[get(type(copy))]
55 pub(crate) blur_pipeline_handle: usize,
56 /// Attached native presentation layer handle (`CAMetalLayer*` on Apple, `0` when headless).
57 #[get(type(copy))]
58 pub(crate) surface_layer_handle: usize,
59 /// Resident R8Unorm monochrome glyph atlas `MTLTexture` handle (`0` when unallocated).
60 #[get(type(copy))]
61 pub(crate) glyph_r8_texture_handle: usize,
62 /// Resident RGBA8Unorm color glyph atlas `MTLTexture` handle (`0` when unallocated).
63 #[get(type(copy))]
64 pub(crate) glyph_rgba8_texture_handle: usize,
65 /// Resident RGBA8Unorm UI image/sprite `MTLTexture` handle (`0` when unallocated).
66 #[get(type(copy))]
67 pub(crate) image_texture_handle: usize,
68 /// Bound external GPU texture handle (3D game render target or hardware video surface).
69 #[get(type(copy))]
70 pub(crate) external_texture_handle: usize,
71 /// Triple-buffered fenced GPU staging ring slots eliminating CPU/GPU buffer hazards.
72 pub(crate) ring_slots: [NativeGpuRingSlot; GPU_DRIVER_RING_SLOTS],
73 /// Active ring slot cursor cycling `0 -> 1 -> 2 -> 0` across frames.
74 #[get(type(copy))]
75 pub(crate) ring_cursor: usize,
76 /// Persistent grow-only staging handle mirror reflecting the active ring slot.
77 #[get(skip)]
78 pub(crate) staging_buffer_handle: usize,
79 /// Cached CPU-writable contents pointer mirror reflecting the active ring slot.
80 #[get(skip)]
81 pub(crate) staging_contents_ptr: usize,
82 /// Byte capacity mirror reflecting the active ring slot.
83 #[get(skip)]
84 pub(crate) staging_buffer_capacity: usize,
85 /// Total GPU frames submitted through this driver.
86 #[get(type(copy))]
87 pub(crate) submitted_frames: u64,
88 /// Total instanced draw primitives uploaded to the GPU.
89 #[get(type(copy))]
90 pub(crate) uploaded_instances: u64,
91 /// Cumulative instance payload bytes uploaded to the GPU across all frames.
92 #[get(type(copy))]
93 pub(crate) uploaded_bytes: u64,
94 /// Instance payload bytes uploaded during the most recent submitted frame.
95 #[get(type(copy))]
96 pub(crate) last_upload_bytes: usize,
97 /// Number of draw batches submitted during the most recent frame.
98 #[get(type(copy))]
99 pub(crate) last_submitted_batches: usize,
100 /// Number of staging ring slot allocations or grows across the driver's lifetime.
101 #[get(type(copy))]
102 pub(crate) staging_reallocations: u64,
103 /// Most recent hardware presentation timestamp in nanoseconds reported by Metal `addPresentedHandler:`.
104 #[get(type(copy))]
105 pub(crate) last_presented_time_ns: u64,
106 /// Most recent GPU execution duration in nanoseconds (`GPUEndTime - GPUStartTime`).
107 #[get(type(copy))]
108 pub(crate) last_gpu_exec_ns: u64,
109 /// Scratch buffer packing 64-byte `GpuPrimitiveInstance` records when legacy batches lack pre-packed primitives.
110 #[cfg(any(target_os = "macos", target_os = "ios"))]
111 #[get(skip)]
112 pub(crate) scratch_primitives: Vec<GpuPrimitiveInstance>,
113 /// Fallback command recorder active on headless hosts.
114 pub(crate) fallback: RecordingGpuDriver,
115}
116
117/// Retained native GPU device, queue, library, compiled pipelines, and dummy texture handles returned by `probe_native_gpu_full`.
118#[derive(Clone, Debug)]
119pub(crate) struct NativeGpuProbeOutput {
120 /// Probed adapter capabilities and hardware backend descriptor.
121 pub(crate) adapter: GpuAdapterInfo,
122 /// Retained native GPU device handle (`0` when headless).
123 pub(crate) device_handle: usize,
124 /// Retained native GPU command queue handle (`0` when headless).
125 pub(crate) queue_handle: usize,
126 /// Retained compiled native shader library handle (`0` when headless).
127 pub(crate) library_handle: usize,
128 /// Retained cached uber-shader render pipeline handle (`0` when headless).
129 pub(crate) pipeline_handle: usize,
130 /// Retained cached Dual-Kawase blur render pipeline handle (`0` when headless).
131 pub(crate) blur_pipeline_handle: usize,
132 /// Retained 1x1 fallback R8Unorm texture handle (`0` when headless).
133 pub(crate) dummy_r8_tex: usize,
134 /// Retained 1x1 fallback RGBA8Unorm texture handle (`0` when headless).
135 pub(crate) dummy_rgba8_tex: usize,
136}
137
138/// Process-wide cached Objective-C selector pointers for Apple Metal hot-path submission and encoding.
139#[cfg(any(target_os = "macos", target_os = "ios"))]
140#[derive(Clone, Copy, Debug)]
141pub(crate) struct MetalSelectors {
142 /// Cached `retain` selector address.
143 pub(crate) retain: usize,
144 /// Cached `newBufferWithBytes:length:options:` selector address.
145 pub(crate) new_buffer_with_bytes: usize,
146 /// Cached `newBufferWithLength:options:` selector address.
147 pub(crate) new_buffer_with_length: usize,
148 /// Cached `contents` selector address.
149 pub(crate) contents: usize,
150 /// Cached `commandBuffer` selector address.
151 pub(crate) command_buffer: usize,
152 /// Cached `renderCommandEncoderWithDescriptor:` selector address.
153 pub(crate) render_encoder: usize,
154 /// Cached `setRenderPipelineState:` selector address.
155 pub(crate) set_pipeline_state: usize,
156 /// Cached `setVertexBuffer:offset:atIndex:` selector address.
157 pub(crate) set_vertex_buffer: usize,
158 /// Cached `setVertexBytes:length:atIndex:` selector address.
159 pub(crate) set_vertex_bytes: usize,
160 /// Cached `setFragmentTexture:atIndex:` selector address.
161 pub(crate) set_fragment_texture: usize,
162 /// Cached `setScissorRect:` selector address.
163 pub(crate) set_scissor_rect: usize,
164 /// Cached `drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` selector address.
165 pub(crate) draw_primitives_instanced: usize,
166 /// Cached `endEncoding` selector address.
167 pub(crate) end_encoding: usize,
168 /// Cached `presentDrawable:` selector address.
169 pub(crate) present_drawable: usize,
170 /// Cached `addPresentedHandler:` selector address (on `MTLDrawable`).
171 pub(crate) add_presented_handler: usize,
172 /// Cached `addCompletedHandler:` selector address (on `MTLCommandBuffer`).
173 pub(crate) add_completed_handler: usize,
174 /// Cached `presentedTime` selector address (on `MTLDrawable`).
175 pub(crate) presented_time: usize,
176 /// Cached `respondsToSelector:` selector address.
177 pub(crate) responds_to_sel: usize,
178 /// Cached `status` selector address.
179 pub(crate) status: usize,
180 /// Cached `waitUntilCompleted` selector address.
181 pub(crate) wait_until_completed: usize,
182 /// Cached `GPUStartTime` selector address.
183 pub(crate) gpu_start_time: usize,
184 /// Cached `GPUEndTime` selector address.
185 pub(crate) gpu_end_time: usize,
186 /// Cached `nextDrawable` selector address.
187 pub(crate) next_drawable: usize,
188 /// Cached `drawableSize` selector address on `CAMetalLayer`.
189 pub(crate) drawable_size: usize,
190 /// Cached `setDrawableSize:` selector address on `CAMetalLayer`.
191 pub(crate) set_drawable_size: usize,
192 /// Cached `texture` selector address.
193 pub(crate) texture: usize,
194 /// Cached `width` selector address.
195 pub(crate) width: usize,
196 /// Cached `height` selector address.
197 pub(crate) height: usize,
198 /// Cached `renderPassDescriptor` selector address.
199 pub(crate) render_pass_desc: usize,
200 /// Cached `colorAttachments` selector address.
201 pub(crate) color_attachments: usize,
202 /// Cached `objectAtIndexedSubscript:` selector address.
203 pub(crate) object_at_index: usize,
204 /// Cached `setTexture:` selector address.
205 pub(crate) set_texture: usize,
206 /// Cached `setLoadAction:` selector address.
207 pub(crate) set_load_action: usize,
208 /// Cached `setStoreAction:` selector address.
209 pub(crate) set_store_action: usize,
210 /// Cached `setClearColor:` selector address.
211 pub(crate) set_clear_color: usize,
212 /// Cached `replaceRegion:mipmapLevel:withBytes:bytesPerRow:` selector address.
213 pub(crate) replace_region: usize,
214 /// Cached `commit` selector address.
215 pub(crate) commit: usize,
216 /// Cached `release` selector address.
217 pub(crate) release: usize,
218}
219
220/// Process-wide cached Apple Metal runtime pipeline state eliminating redundant 40-180ms shader compiles.
221#[cfg(any(target_os = "macos", target_os = "ios"))]
222#[derive(Clone, Debug)]
223pub(crate) struct MetalSharedPipelineCache {
224 /// Probed physical adapter description and shader compile status.
225 pub(crate) adapter: GpuAdapterInfo,
226 /// Retained `id<MTLDevice>` handle.
227 pub(crate) device: usize,
228 /// Retained `id<MTLCommandQueue>` handle.
229 pub(crate) queue: usize,
230 /// Retained `id<MTLLibrary>` handle.
231 pub(crate) library: usize,
232 /// Retained `id<MTLRenderPipelineState>` handle for the 64-byte uber-shader.
233 pub(crate) pipeline: usize,
234 /// Retained `id<MTLRenderPipelineState>` handle for the Dual-Kawase blur shader.
235 pub(crate) blur_pipeline: usize,
236 /// Retained 1x1 fallback R8Unorm `MTLTexture` bound when glyph atlas is empty.
237 pub(crate) dummy_r8_tex: usize,
238 /// Retained 1x1 fallback RGBA8Unorm `MTLTexture` bound when color/image textures are unbound.
239 pub(crate) dummy_rgba8_tex: usize,
240}
241
242/// CoreGraphics `CGSize` 2D extent ABI struct passed to `CAMetalLayer.setDrawableSize:`.
243#[cfg(any(target_os = "macos", target_os = "ios"))]
244#[repr(C)]
245#[derive(Clone, Copy, Debug, Default)]
246pub(crate) struct MtlCgSize {
247 /// Physical surface width in pixels.
248 pub(crate) width: f64,
249 /// Physical surface height in pixels.
250 pub(crate) height: f64,
251}
252
253/// Metal `MTLOrigin` 3D texel origin ABI struct.
254#[cfg(any(target_os = "macos", target_os = "ios"))]
255#[repr(C)]
256#[derive(Clone, Copy, Debug, Default)]
257pub(crate) struct MtlOrigin {
258 /// Horizontal texel origin.
259 pub(crate) x: usize,
260 /// Vertical texel origin.
261 pub(crate) y: usize,
262 /// Slice depth origin (`0`).
263 pub(crate) z: usize,
264}
265
266/// Metal `MTLSize` 3D texel extent ABI struct.
267#[cfg(any(target_os = "macos", target_os = "ios"))]
268#[repr(C)]
269#[derive(Clone, Copy, Debug, Default)]
270pub(crate) struct MtlSize {
271 /// Extent width in texels.
272 pub(crate) width: usize,
273 /// Extent height in texels.
274 pub(crate) height: usize,
275 /// Extent depth in slices (`1`).
276 pub(crate) depth: usize,
277}
278
279/// Metal `MTLRegion` 3D sub-texture upload rectangle ABI struct.
280#[cfg(any(target_os = "macos", target_os = "ios"))]
281#[repr(C)]
282#[derive(Clone, Copy, Debug, Default)]
283pub(crate) struct MtlRegion {
284 /// Sub-region origin.
285 pub(crate) origin: MtlOrigin,
286 /// Sub-region extent.
287 pub(crate) size: MtlSize,
288}
289
290/// Metal `MTLScissorRect` physical scissor ABI struct.
291#[cfg(any(target_os = "macos", target_os = "ios"))]
292#[repr(C)]
293#[derive(Clone, Copy, Debug, Default)]
294pub(crate) struct MtlScissorRect {
295 /// Left physical pixel edge.
296 pub(crate) x: usize,
297 /// Top physical pixel edge.
298 pub(crate) y: usize,
299 /// Scissor width in physical pixels.
300 pub(crate) width: usize,
301 /// Scissor height in physical pixels.
302 pub(crate) height: usize,
303}
304
305/// Metal `MTLClearColor` RGBA64F clear color ABI struct.
306#[cfg(any(target_os = "macos", target_os = "ios"))]
307#[repr(C)]
308#[derive(Clone, Copy, Debug, Default)]
309pub(crate) struct MtlClearColor {
310 /// Red channel in `[0.0..=1.0]`.
311 pub(crate) red: f64,
312 /// Green channel in `[0.0..=1.0]`.
313 pub(crate) green: f64,
314 /// Blue channel in `[0.0..=1.0]`.
315 pub(crate) blue: f64,
316 /// Alpha channel in `[0.0..=1.0]`.
317 pub(crate) alpha: f64,
318}
319
320/// Objective-C runtime global block descriptor ABI layout.
321#[cfg(any(target_os = "macos", target_os = "ios"))]
322#[repr(C)]
323pub(crate) struct ObjcBlockDescriptor {
324 /// Reserved word (`0`).
325 pub(crate) reserved: usize,
326 /// Byte size of the block struct.
327 pub(crate) size: usize,
328}
329
330/// Objective-C runtime zero-allocation global block ABI struct for Metal `addPresentedHandler:`.
331#[cfg(any(target_os = "macos", target_os = "ios"))]
332#[repr(C)]
333pub(crate) struct ObjcGlobalBlock {
334 /// Pointer to `_NSConcreteGlobalBlock`.
335 pub(crate) isa: *const c_void,
336 /// Block flags (`OBJC_BLOCK_IS_GLOBAL`).
337 pub(crate) flags: i32,
338 /// Reserved flags (`0`).
339 pub(crate) reserved: i32,
340 /// Block invoke C callback `(block, cmd_buffer)`.
341 pub(crate) invoke: unsafe extern "C" fn(*mut c_void, *mut c_void),
342 /// Descriptor pointer.
343 pub(crate) descriptor: *const ObjcBlockDescriptor,
344}
345
346/// Process-wide cached Windows Direct3D 12 probe status eliminating repeated `LoadLibraryA`/`FreeLibrary` thrashing.
347#[cfg(target_os = "windows")]
348#[derive(Clone, Copy, Debug)]
349pub(crate) struct WindowsD3d12ProbeCache {
350 /// True when `d3d12.dll` exports `D3D12CreateDevice`.
351 pub(crate) has_d3d12: bool,
352 /// True when `d3dcompiler_47.dll` exports `D3DCompile`.
353 pub(crate) has_compiler: bool,
354}
355
356/// Process-wide cached Vulkan loader probe status eliminating repeated `dlopen`/`dlclose` thrashing.
357#[cfg(any(target_os = "linux", target_os = "android"))]
358#[derive(Clone, Copy, Debug)]
359pub(crate) struct VulkanProbeCache {
360 /// True when Vulkan loader exports `vkCreateInstance` and `vkEnumeratePhysicalDevices`.
361 pub(crate) available: bool,
362 /// Cached `dlopen` handle kept resident for process lifetime.
363 pub(crate) lib_handle: usize,
364}
365
366/// Physical pixel dirty sub-rectangle used by adaptive GLES 3.0 and Metal texture upload planners.
367#[repr(C)]
368#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
369pub struct PixelDirtyRect {
370 /// Left inclusive pixel coordinate.
371 #[get(type(copy))]
372 pub(crate) x: u32,
373 /// Top inclusive pixel coordinate.
374 #[get(type(copy))]
375 pub(crate) y: u32,
376 /// Sub-rectangle width in pixels.
377 #[get(type(copy))]
378 pub(crate) width: u32,
379 /// Sub-rectangle height in pixels.
380 #[get(type(copy))]
381 pub(crate) height: u32,
382}
383
384/// Selected adaptive texture-upload plan choosing `MultiRect`, `MergedBbox`, `FullFrame`, or `None` by measured byte and driver cost.
385#[derive(Clone, Data, Debug, Default, PartialEq)]
386pub struct AdaptiveUploadPlan {
387 /// Selected upload strategy for this frame.
388 #[get(type(copy))]
389 pub(crate) strategy: MobileUploadStrategy,
390 /// Ordered physical rectangles to upload under `strategy`.
391 pub(crate) rects: Vec<PixelDirtyRect>,
392 /// Total RGBA8 pixel payload bytes transferred under `strategy`.
393 #[get(type(copy))]
394 pub(crate) total_upload_bytes: usize,
395 /// Equivalent RGBA8 payload bytes of the single merged bounding box.
396 #[get(type(copy))]
397 pub(crate) merged_bbox_bytes: usize,
398 /// Equivalent RGBA8 payload bytes of a full-frame texture upload.
399 #[get(type(copy))]
400 pub(crate) full_frame_bytes: usize,
401 /// Estimated total upload cost score (pixel bytes plus per-call driver overhead).
402 #[get(type(copy))]
403 pub(crate) estimated_cost_score: f32,
404}
405
406/// One scissor-bounded instanced draw range inside a compiled `DirectGpuFrameBatch`.
407#[repr(C)]
408#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
409pub struct DirectGpuBatchRange {
410 /// First primitive index inside `DirectGpuFrameBatch::primitives`.
411 #[get(type(copy))]
412 pub(crate) base_instance: u32,
413 /// Number of consecutive 64-byte `GpuPrimitiveInstance` records drawn in this call.
414 #[get(type(copy))]
415 pub(crate) instance_count: u32,
416 /// Physical scissor left coordinate in pixels (top-left origin).
417 #[get(type(copy))]
418 pub(crate) scissor_x: u32,
419 /// Physical scissor top coordinate in pixels (top-left origin).
420 #[get(type(copy))]
421 pub(crate) scissor_y: u32,
422 /// Physical scissor width in pixels.
423 #[get(type(copy))]
424 pub(crate) scissor_w: u32,
425 /// Physical scissor height in pixels.
426 #[get(type(copy))]
427 pub(crate) scissor_h: u32,
428 /// Horizontal retained-layer scroll translation in physical pixels.
429 #[get(type(copy))]
430 pub(crate) scroll_x: f32,
431 /// Vertical retained-layer scroll translation in physical pixels.
432 #[get(type(copy))]
433 pub(crate) scroll_y: f32,
434 /// Bound texture slot discriminant (`0` = default glyph/image textures).
435 #[get(type(copy))]
436 pub(crate) texture_slot: u8,
437 /// Owning retained layer identifier (`0` = root).
438 #[get(type(copy))]
439 pub(crate) layer_id: u8,
440 /// Explicit C-ABI alignment padding bytes.
441 #[get(type(copy))]
442 pub(crate) pad: [u8; 2],
443}
444
445/// Borrowed RGBA8 image or sprite-sheet sub-region queued for frame-level direct-GPU image atlas packing.
446#[derive(Clone, Copy, Debug)]
447pub(crate) struct DirectGpuImageSlice<'a> {
448 /// Full source image width in pixels.
449 pub(crate) src_w: u32,
450 /// Full source image height in pixels.
451 pub(crate) src_h: u32,
452 /// Borrowed RGBA8 pixel bytes (`src_w * src_h * 4`).
453 pub(crate) pixels: &'a [u8],
454 /// Source crop rectangle `(x, y, width, height)` in pixels.
455 pub(crate) crop: PixelDirtyRect,
456}
457
458/// Packed R8 monochrome glyph atlas or RGBA8 image texture sheet ready for direct GLES 3.0 or Metal upload.
459#[derive(Clone, Data, Debug, Default, PartialEq)]
460pub struct DirectGpuAtlasUpload {
461 /// Backing texture width in texels (`0` when no upload is required).
462 #[get(type(copy))]
463 pub(crate) width: u32,
464 /// Backing texture height in texels (`0` when no upload is required).
465 #[get(type(copy))]
466 pub(crate) height: u32,
467 /// Monotonic revision tag avoiding redundant uploads when unchanged.
468 #[get(type(copy))]
469 pub(crate) revision: u64,
470 /// Tightly packed texel payload bytes (`width * height` for R8, `width * height * 4` for RGBA8).
471 pub(crate) pixels: Vec<u8>,
472}
473
474/// Complete direct-GPU frame payload targeting GLES 3.0 `EGLSurface` or Metal `CAMetalDrawable` with zero CPU framebuffer mirror.
475#[derive(Clone, Data, Debug, Default, PartialEq)]
476pub struct DirectGpuFrameBatch {
477 /// Physical surface width in pixels.
478 #[get(type(copy))]
479 pub(crate) viewport_width: u32,
480 /// Physical surface height in pixels.
481 #[get(type(copy))]
482 pub(crate) viewport_height: u32,
483 /// Normalized sRGB clear color `[r, g, b, a]` applied to the native surface.
484 #[get(type(copy))]
485 pub(crate) clear_rgba: [f32; 4],
486 /// Flat tightly packed 64-byte `GpuPrimitiveInstance` array uploaded once per frame.
487 pub(crate) primitives: Vec<GpuPrimitiveInstance>,
488 /// Ordered scissor-bounded draw calls indexing into `primitives`.
489 pub(crate) draw_ranges: Vec<DirectGpuBatchRange>,
490 /// Ordered Dual-Kawase `BackdropBlur` GPU passes for this frame.
491 pub(crate) backdrop_blurs: Vec<GpuBackdropBlurPass>,
492 /// Optional R8 monochrome glyph atlas update when new glyphs were rasterized.
493 pub(crate) glyph_r8_atlas: Option<DirectGpuAtlasUpload>,
494 /// Optional RGBA8 color/image texture sheet update for `Image` / `SharedImage` / `SpriteRegion`.
495 pub(crate) image_rgba8_atlas: Option<DirectGpuAtlasUpload>,
496 /// Total instance + atlas bytes uploaded to GPU memory for this frame.
497 #[get(type(copy))]
498 pub(crate) instance_upload_bytes: usize,
499 /// Always `false` on the direct GPU draw path (zero full-frame CPU RGBA mirror).
500 #[get(type(copy))]
501 pub(crate) cpu_mirror_active: bool,
502 /// Upload strategy tag (`MobileUploadStrategy::DirectGpu`).
503 #[get(type(copy))]
504 pub(crate) upload_strategy: MobileUploadStrategy,
505}
506
507/// GLES 3.0 instanced vertex attribute binding specification matching `GLSL_ES3_UI_VERTEX_SHADER` byte-for-byte.
508#[repr(C)]
509#[derive(Clone, Copy, Debug, Eq, Getter, New, PartialEq)]
510pub struct Gles3InstanceAttribSpec {
511 /// Vertex attribute layout location (`1..=5`).
512 #[get(type(copy))]
513 pub(crate) location: u32,
514 /// Number of scalar components (`2` or `4`).
515 #[get(type(copy))]
516 pub(crate) components: i32,
517 /// True when bound with `glVertexAttribIPointer` (`GL_UNSIGNED_INT`), false for `glVertexAttribPointer` (`GL_FLOAT`).
518 #[get(type(copy))]
519 pub(crate) is_integer: bool,
520 /// Byte offset inside the 64-byte `GpuPrimitiveInstance` struct.
521 #[get(type(copy))]
522 pub(crate) byte_offset: usize,
523 /// Stride in bytes (`64`).
524 #[get(type(copy))]
525 pub(crate) stride: i32,
526}
527
528/// Honest cross-platform mobile presentation telemetry ready to feed into `AdaptiveRenderRouter` and `report-v1` JSON.
529#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
530pub struct MobilePresentTelemetry {
531 /// Currently active presentation path (`GpuDirect`, `GpuUpload`, or `Software`).
532 #[get(type(copy))]
533 pub(crate) active_path: MobilePresentPath,
534 /// Upload strategy executed on the most recent frame.
535 #[get(type(copy))]
536 pub(crate) upload_strategy: MobileUploadStrategy,
537 /// True only when a CPU framebuffer mirror is active (`false` on `GpuDirect`, `true` on `GpuUpload`/`Software`).
538 #[get(type(copy))]
539 pub(crate) cpu_mirror_active: bool,
540 /// Provenance of presentation timestamps (`CompositorMeasured`, `SubmissionProxy`, or `Unobservable`).
541 #[get(type(copy))]
542 pub(crate) timing_source: MobilePresentTimingSource,
543 /// Explicit reason when compositor presentation timing is unobservable (never masked as `0.0`).
544 #[get(type(copy))]
545 pub(crate) unobservable_reason: Option<&'static str>,
546 /// True when executing inside an iOS/Android software simulator rather than physical GPU hardware.
547 #[get(type(copy))]
548 pub(crate) is_simulator: bool,
549 /// Active display refresh rate in Hertz (`60.0`, `90.0`, `120.0`, `144.0`, etc.).
550 #[get(type(copy))]
551 pub(crate) display_mode_hz: f32,
552 /// Total VSync frame callbacks received (`Choreographer.doFrame` or `CADisplayLink`).
553 #[get(type(copy))]
554 pub(crate) frame_callback_count: u64,
555 /// Most recent VSync frame callback timestamp in nanoseconds.
556 #[get(type(copy))]
557 pub(crate) last_callback_timestamp_ns: u64,
558 /// Measured interval between consecutive VSync callbacks in milliseconds (`None` before 2nd callback).
559 #[get(type(copy))]
560 pub(crate) last_callback_interval_ms: Option<f64>,
561 /// Target presentation timestamp in nanoseconds (`CADisplayLink.targetTimestamp` or Choreographer deadline).
562 #[get(type(copy))]
563 pub(crate) last_target_timestamp_ns: Option<u64>,
564 /// Measured compositor presentation timestamp in nanoseconds (`None` when unobservable on simulator).
565 #[get(type(copy))]
566 pub(crate) last_presented_timestamp_ns: Option<u64>,
567 /// Cumulative count of frames actually submitted and presented.
568 #[get(type(copy))]
569 pub(crate) actual_presented_frames: u64,
570 /// Payload bytes uploaded on the most recent frame (instance+atlas on `GpuDirect`; pixel rects on `GpuUpload`/`Software`).
571 #[get(type(copy))]
572 pub(crate) upload_bytes_last_frame: u64,
573 /// Cumulative payload bytes uploaded across the session.
574 #[get(type(copy))]
575 pub(crate) upload_bytes_total: u64,
576 /// Number of 64-byte `GpuPrimitiveInstance` records drawn on the most recent `GpuDirect` frame.
577 #[get(type(copy))]
578 pub(crate) primitive_count_last_frame: u32,
579 /// Number of GPU draw calls emitted on the most recent frame.
580 #[get(type(copy))]
581 pub(crate) draw_calls_last_frame: u32,
582 /// Cumulative count of submission errors (lock/encode/commit failures).
583 #[get(type(copy))]
584 pub(crate) submit_failures: u64,
585 /// Cumulative count of compositor presentation failures (`eglSwapBuffers` / drawable errors).
586 #[get(type(copy))]
587 pub(crate) present_failures: u64,
588 /// Cumulative count of GPU context-loss events (`EGL_CONTEXT_LOST` / Metal device reset).
589 #[get(type(copy))]
590 pub(crate) context_loss_count: u64,
591 /// Count of blank frames actively prevented by retaining the last valid surface frame during failover.
592 #[get(type(copy))]
593 pub(crate) blank_frames_prevented: u64,
594 /// True when the native surface holds a valid previously presented frame.
595 #[get(type(copy))]
596 pub(crate) last_valid_frame_retained: bool,
597}
598
599/// Immediate zero-blank-frame failover state machine for Android EGL/GLES3 and iOS Metal presentation.
600#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
601pub struct MobileFailoverController {
602 /// Currently active presentation path.
603 #[get(type(copy))]
604 pub(crate) active_path: MobilePresentPath,
605 /// Preferred startup presentation path before faults.
606 #[get(type(copy))]
607 pub(crate) preferred_path: MobilePresentPath,
608 /// True once at least one valid frame has been presented to the current window surface.
609 #[get(type(copy))]
610 pub(crate) has_valid_presented_frame: bool,
611 /// True while the OS native window / Metal layer remains attached and valid.
612 #[get(type(copy))]
613 pub(crate) window_valid: bool,
614 /// True when direct GPU uber-shader pipeline is available on this surface.
615 #[get(type(copy))]
616 pub(crate) direct_gpu_available: bool,
617 /// True when texture-upload GPU pipeline is available on this surface.
618 #[get(type(copy))]
619 pub(crate) gpu_upload_available: bool,
620 /// Cumulative context-loss faults observed.
621 #[get(type(copy))]
622 pub(crate) context_loss_count: u64,
623 /// Cumulative blank frames prevented by retaining the last valid frame during fault switchover.
624 #[get(type(copy))]
625 pub(crate) blank_frames_prevented: u64,
626 /// Cumulative immediate fallback path transitions executed without waiting for perf comparisons.
627 #[get(type(copy))]
628 pub(crate) fallback_transitions: u64,
629}