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 `texture` selector address.
189 pub(crate) texture: usize,
190 /// Cached `width` selector address.
191 pub(crate) width: usize,
192 /// Cached `height` selector address.
193 pub(crate) height: usize,
194 /// Cached `renderPassDescriptor` selector address.
195 pub(crate) render_pass_desc: usize,
196 /// Cached `colorAttachments` selector address.
197 pub(crate) color_attachments: usize,
198 /// Cached `objectAtIndexedSubscript:` selector address.
199 pub(crate) object_at_index: usize,
200 /// Cached `setTexture:` selector address.
201 pub(crate) set_texture: usize,
202 /// Cached `setLoadAction:` selector address.
203 pub(crate) set_load_action: usize,
204 /// Cached `setStoreAction:` selector address.
205 pub(crate) set_store_action: usize,
206 /// Cached `setClearColor:` selector address.
207 pub(crate) set_clear_color: usize,
208 /// Cached `replaceRegion:mipmapLevel:withBytes:bytesPerRow:` selector address.
209 pub(crate) replace_region: usize,
210 /// Cached `commit` selector address.
211 pub(crate) commit: usize,
212 /// Cached `release` selector address.
213 pub(crate) release: usize,
214}
215
216/// Process-wide cached Apple Metal runtime pipeline state eliminating redundant 40-180ms shader compiles.
217#[cfg(any(target_os = "macos", target_os = "ios"))]
218#[derive(Clone, Debug)]
219pub(crate) struct MetalSharedPipelineCache {
220 /// Probed physical adapter description and shader compile status.
221 pub(crate) adapter: GpuAdapterInfo,
222 /// Retained `id<MTLDevice>` handle.
223 pub(crate) device: usize,
224 /// Retained `id<MTLCommandQueue>` handle.
225 pub(crate) queue: usize,
226 /// Retained `id<MTLLibrary>` handle.
227 pub(crate) library: usize,
228 /// Retained `id<MTLRenderPipelineState>` handle for the 64-byte uber-shader.
229 pub(crate) pipeline: usize,
230 /// Retained `id<MTLRenderPipelineState>` handle for the Dual-Kawase blur shader.
231 pub(crate) blur_pipeline: usize,
232 /// Retained 1x1 fallback R8Unorm `MTLTexture` bound when glyph atlas is empty.
233 pub(crate) dummy_r8_tex: usize,
234 /// Retained 1x1 fallback RGBA8Unorm `MTLTexture` bound when color/image textures are unbound.
235 pub(crate) dummy_rgba8_tex: usize,
236}
237
238/// Metal `MTLOrigin` 3D texel origin ABI struct.
239#[cfg(any(target_os = "macos", target_os = "ios"))]
240#[repr(C)]
241#[derive(Clone, Copy, Debug, Default)]
242pub(crate) struct MtlOrigin {
243 /// Horizontal texel origin.
244 pub(crate) x: usize,
245 /// Vertical texel origin.
246 pub(crate) y: usize,
247 /// Slice depth origin (`0`).
248 pub(crate) z: usize,
249}
250
251/// Metal `MTLSize` 3D texel extent ABI struct.
252#[cfg(any(target_os = "macos", target_os = "ios"))]
253#[repr(C)]
254#[derive(Clone, Copy, Debug, Default)]
255pub(crate) struct MtlSize {
256 /// Extent width in texels.
257 pub(crate) width: usize,
258 /// Extent height in texels.
259 pub(crate) height: usize,
260 /// Extent depth in slices (`1`).
261 pub(crate) depth: usize,
262}
263
264/// Metal `MTLRegion` 3D sub-texture upload rectangle ABI struct.
265#[cfg(any(target_os = "macos", target_os = "ios"))]
266#[repr(C)]
267#[derive(Clone, Copy, Debug, Default)]
268pub(crate) struct MtlRegion {
269 /// Sub-region origin.
270 pub(crate) origin: MtlOrigin,
271 /// Sub-region extent.
272 pub(crate) size: MtlSize,
273}
274
275/// Metal `MTLScissorRect` physical scissor ABI struct.
276#[cfg(any(target_os = "macos", target_os = "ios"))]
277#[repr(C)]
278#[derive(Clone, Copy, Debug, Default)]
279pub(crate) struct MtlScissorRect {
280 /// Left physical pixel edge.
281 pub(crate) x: usize,
282 /// Top physical pixel edge.
283 pub(crate) y: usize,
284 /// Scissor width in physical pixels.
285 pub(crate) width: usize,
286 /// Scissor height in physical pixels.
287 pub(crate) height: usize,
288}
289
290/// Metal `MTLClearColor` RGBA64F clear color ABI struct.
291#[cfg(any(target_os = "macos", target_os = "ios"))]
292#[repr(C)]
293#[derive(Clone, Copy, Debug, Default)]
294pub(crate) struct MtlClearColor {
295 /// Red channel in `[0.0..=1.0]`.
296 pub(crate) red: f64,
297 /// Green channel in `[0.0..=1.0]`.
298 pub(crate) green: f64,
299 /// Blue channel in `[0.0..=1.0]`.
300 pub(crate) blue: f64,
301 /// Alpha channel in `[0.0..=1.0]`.
302 pub(crate) alpha: f64,
303}
304
305/// Objective-C runtime global block descriptor ABI layout.
306#[cfg(any(target_os = "macos", target_os = "ios"))]
307#[repr(C)]
308pub(crate) struct ObjcBlockDescriptor {
309 /// Reserved word (`0`).
310 pub(crate) reserved: usize,
311 /// Byte size of the block struct.
312 pub(crate) size: usize,
313}
314
315/// Objective-C runtime zero-allocation global block ABI struct for Metal `addPresentedHandler:`.
316#[cfg(any(target_os = "macos", target_os = "ios"))]
317#[repr(C)]
318pub(crate) struct ObjcGlobalBlock {
319 /// Pointer to `_NSConcreteGlobalBlock`.
320 pub(crate) isa: *const c_void,
321 /// Block flags (`OBJC_BLOCK_IS_GLOBAL`).
322 pub(crate) flags: i32,
323 /// Reserved flags (`0`).
324 pub(crate) reserved: i32,
325 /// Block invoke C callback `(block, cmd_buffer)`.
326 pub(crate) invoke: unsafe extern "C" fn(*mut c_void, *mut c_void),
327 /// Descriptor pointer.
328 pub(crate) descriptor: *const ObjcBlockDescriptor,
329}
330
331/// Process-wide cached Windows Direct3D 12 probe status eliminating repeated `LoadLibraryA`/`FreeLibrary` thrashing.
332#[cfg(target_os = "windows")]
333#[derive(Clone, Copy, Debug)]
334pub(crate) struct WindowsD3d12ProbeCache {
335 /// True when `d3d12.dll` exports `D3D12CreateDevice`.
336 pub(crate) has_d3d12: bool,
337 /// True when `d3dcompiler_47.dll` exports `D3DCompile`.
338 pub(crate) has_compiler: bool,
339}
340
341/// Process-wide cached Vulkan loader probe status eliminating repeated `dlopen`/`dlclose` thrashing.
342#[cfg(any(target_os = "linux", target_os = "android"))]
343#[derive(Clone, Copy, Debug)]
344pub(crate) struct VulkanProbeCache {
345 /// True when Vulkan loader exports `vkCreateInstance` and `vkEnumeratePhysicalDevices`.
346 pub(crate) available: bool,
347 /// Cached `dlopen` handle kept resident for process lifetime.
348 pub(crate) lib_handle: usize,
349}
350
351/// Physical pixel dirty sub-rectangle used by adaptive GLES 3.0 and Metal texture upload planners.
352#[repr(C)]
353#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
354pub struct PixelDirtyRect {
355 /// Left inclusive pixel coordinate.
356 #[get(type(copy))]
357 pub(crate) x: u32,
358 /// Top inclusive pixel coordinate.
359 #[get(type(copy))]
360 pub(crate) y: u32,
361 /// Sub-rectangle width in pixels.
362 #[get(type(copy))]
363 pub(crate) width: u32,
364 /// Sub-rectangle height in pixels.
365 #[get(type(copy))]
366 pub(crate) height: u32,
367}
368
369/// Selected adaptive texture-upload plan choosing `MultiRect`, `MergedBbox`, `FullFrame`, or `None` by measured byte and driver cost.
370#[derive(Clone, Data, Debug, Default, PartialEq)]
371pub struct AdaptiveUploadPlan {
372 /// Selected upload strategy for this frame.
373 #[get(type(copy))]
374 pub(crate) strategy: MobileUploadStrategy,
375 /// Ordered physical rectangles to upload under `strategy`.
376 pub(crate) rects: Vec<PixelDirtyRect>,
377 /// Total RGBA8 pixel payload bytes transferred under `strategy`.
378 #[get(type(copy))]
379 pub(crate) total_upload_bytes: usize,
380 /// Equivalent RGBA8 payload bytes of the single merged bounding box.
381 #[get(type(copy))]
382 pub(crate) merged_bbox_bytes: usize,
383 /// Equivalent RGBA8 payload bytes of a full-frame texture upload.
384 #[get(type(copy))]
385 pub(crate) full_frame_bytes: usize,
386 /// Estimated total upload cost score (pixel bytes plus per-call driver overhead).
387 #[get(type(copy))]
388 pub(crate) estimated_cost_score: f32,
389}
390
391/// One scissor-bounded instanced draw range inside a compiled `DirectGpuFrameBatch`.
392#[repr(C)]
393#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
394pub struct DirectGpuBatchRange {
395 /// First primitive index inside `DirectGpuFrameBatch::primitives`.
396 #[get(type(copy))]
397 pub(crate) base_instance: u32,
398 /// Number of consecutive 64-byte `GpuPrimitiveInstance` records drawn in this call.
399 #[get(type(copy))]
400 pub(crate) instance_count: u32,
401 /// Physical scissor left coordinate in pixels (top-left origin).
402 #[get(type(copy))]
403 pub(crate) scissor_x: u32,
404 /// Physical scissor top coordinate in pixels (top-left origin).
405 #[get(type(copy))]
406 pub(crate) scissor_y: u32,
407 /// Physical scissor width in pixels.
408 #[get(type(copy))]
409 pub(crate) scissor_w: u32,
410 /// Physical scissor height in pixels.
411 #[get(type(copy))]
412 pub(crate) scissor_h: u32,
413 /// Horizontal retained-layer scroll translation in physical pixels.
414 #[get(type(copy))]
415 pub(crate) scroll_x: f32,
416 /// Vertical retained-layer scroll translation in physical pixels.
417 #[get(type(copy))]
418 pub(crate) scroll_y: f32,
419 /// Bound texture slot discriminant (`0` = default glyph/image textures).
420 #[get(type(copy))]
421 pub(crate) texture_slot: u8,
422 /// Owning retained layer identifier (`0` = root).
423 #[get(type(copy))]
424 pub(crate) layer_id: u8,
425 /// Explicit C-ABI alignment padding bytes.
426 #[get(type(copy))]
427 pub(crate) pad: [u8; 2],
428}
429
430/// Borrowed RGBA8 image or sprite-sheet sub-region queued for frame-level direct-GPU image atlas packing.
431#[derive(Clone, Copy, Debug)]
432pub(crate) struct DirectGpuImageSlice<'a> {
433 /// Full source image width in pixels.
434 pub(crate) src_w: u32,
435 /// Full source image height in pixels.
436 pub(crate) src_h: u32,
437 /// Borrowed RGBA8 pixel bytes (`src_w * src_h * 4`).
438 pub(crate) pixels: &'a [u8],
439 /// Source crop rectangle `(x, y, width, height)` in pixels.
440 pub(crate) crop: PixelDirtyRect,
441}
442
443/// Packed R8 monochrome glyph atlas or RGBA8 image texture sheet ready for direct GLES 3.0 or Metal upload.
444#[derive(Clone, Data, Debug, Default, PartialEq)]
445pub struct DirectGpuAtlasUpload {
446 /// Backing texture width in texels (`0` when no upload is required).
447 #[get(type(copy))]
448 pub(crate) width: u32,
449 /// Backing texture height in texels (`0` when no upload is required).
450 #[get(type(copy))]
451 pub(crate) height: u32,
452 /// Monotonic revision tag avoiding redundant uploads when unchanged.
453 #[get(type(copy))]
454 pub(crate) revision: u64,
455 /// Tightly packed texel payload bytes (`width * height` for R8, `width * height * 4` for RGBA8).
456 pub(crate) pixels: Vec<u8>,
457}
458
459/// Complete direct-GPU frame payload targeting GLES 3.0 `EGLSurface` or Metal `CAMetalDrawable` with zero CPU framebuffer mirror.
460#[derive(Clone, Data, Debug, Default, PartialEq)]
461pub struct DirectGpuFrameBatch {
462 /// Physical surface width in pixels.
463 #[get(type(copy))]
464 pub(crate) viewport_width: u32,
465 /// Physical surface height in pixels.
466 #[get(type(copy))]
467 pub(crate) viewport_height: u32,
468 /// Normalized sRGB clear color `[r, g, b, a]` applied to the native surface.
469 #[get(type(copy))]
470 pub(crate) clear_rgba: [f32; 4],
471 /// Flat tightly packed 64-byte `GpuPrimitiveInstance` array uploaded once per frame.
472 pub(crate) primitives: Vec<GpuPrimitiveInstance>,
473 /// Ordered scissor-bounded draw calls indexing into `primitives`.
474 pub(crate) draw_ranges: Vec<DirectGpuBatchRange>,
475 /// Ordered Dual-Kawase `BackdropBlur` GPU passes for this frame.
476 pub(crate) backdrop_blurs: Vec<GpuBackdropBlurPass>,
477 /// Optional R8 monochrome glyph atlas update when new glyphs were rasterized.
478 pub(crate) glyph_r8_atlas: Option<DirectGpuAtlasUpload>,
479 /// Optional RGBA8 color/image texture sheet update for `Image` / `SharedImage` / `SpriteRegion`.
480 pub(crate) image_rgba8_atlas: Option<DirectGpuAtlasUpload>,
481 /// Total instance + atlas bytes uploaded to GPU memory for this frame.
482 #[get(type(copy))]
483 pub(crate) instance_upload_bytes: usize,
484 /// Always `false` on the direct GPU draw path (zero full-frame CPU RGBA mirror).
485 #[get(type(copy))]
486 pub(crate) cpu_mirror_active: bool,
487 /// Upload strategy tag (`MobileUploadStrategy::DirectGpu`).
488 #[get(type(copy))]
489 pub(crate) upload_strategy: MobileUploadStrategy,
490}
491
492/// GLES 3.0 instanced vertex attribute binding specification matching `GLSL_ES3_UI_VERTEX_SHADER` byte-for-byte.
493#[repr(C)]
494#[derive(Clone, Copy, Debug, Eq, Getter, New, PartialEq)]
495pub struct Gles3InstanceAttribSpec {
496 /// Vertex attribute layout location (`1..=5`).
497 #[get(type(copy))]
498 pub(crate) location: u32,
499 /// Number of scalar components (`2` or `4`).
500 #[get(type(copy))]
501 pub(crate) components: i32,
502 /// True when bound with `glVertexAttribIPointer` (`GL_UNSIGNED_INT`), false for `glVertexAttribPointer` (`GL_FLOAT`).
503 #[get(type(copy))]
504 pub(crate) is_integer: bool,
505 /// Byte offset inside the 64-byte `GpuPrimitiveInstance` struct.
506 #[get(type(copy))]
507 pub(crate) byte_offset: usize,
508 /// Stride in bytes (`64`).
509 #[get(type(copy))]
510 pub(crate) stride: i32,
511}
512
513/// Honest cross-platform mobile presentation telemetry ready to feed into `AdaptiveRenderRouter` and `report-v1` JSON.
514#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
515pub struct MobilePresentTelemetry {
516 /// Currently active presentation path (`GpuDirect`, `GpuUpload`, or `Software`).
517 #[get(type(copy))]
518 pub(crate) active_path: MobilePresentPath,
519 /// Upload strategy executed on the most recent frame.
520 #[get(type(copy))]
521 pub(crate) upload_strategy: MobileUploadStrategy,
522 /// True only when a CPU framebuffer mirror is active (`false` on `GpuDirect`, `true` on `GpuUpload`/`Software`).
523 #[get(type(copy))]
524 pub(crate) cpu_mirror_active: bool,
525 /// Provenance of presentation timestamps (`CompositorMeasured`, `SubmissionProxy`, or `Unobservable`).
526 #[get(type(copy))]
527 pub(crate) timing_source: MobilePresentTimingSource,
528 /// Explicit reason when compositor presentation timing is unobservable (never masked as `0.0`).
529 #[get(type(copy))]
530 pub(crate) unobservable_reason: Option<&'static str>,
531 /// True when executing inside an iOS/Android software simulator rather than physical GPU hardware.
532 #[get(type(copy))]
533 pub(crate) is_simulator: bool,
534 /// Active display refresh rate in Hertz (`60.0`, `90.0`, `120.0`, `144.0`, etc.).
535 #[get(type(copy))]
536 pub(crate) display_mode_hz: f32,
537 /// Total VSync frame callbacks received (`Choreographer.doFrame` or `CADisplayLink`).
538 #[get(type(copy))]
539 pub(crate) frame_callback_count: u64,
540 /// Most recent VSync frame callback timestamp in nanoseconds.
541 #[get(type(copy))]
542 pub(crate) last_callback_timestamp_ns: u64,
543 /// Measured interval between consecutive VSync callbacks in milliseconds (`None` before 2nd callback).
544 #[get(type(copy))]
545 pub(crate) last_callback_interval_ms: Option<f64>,
546 /// Target presentation timestamp in nanoseconds (`CADisplayLink.targetTimestamp` or Choreographer deadline).
547 #[get(type(copy))]
548 pub(crate) last_target_timestamp_ns: Option<u64>,
549 /// Measured compositor presentation timestamp in nanoseconds (`None` when unobservable on simulator).
550 #[get(type(copy))]
551 pub(crate) last_presented_timestamp_ns: Option<u64>,
552 /// Cumulative count of frames actually submitted and presented.
553 #[get(type(copy))]
554 pub(crate) actual_presented_frames: u64,
555 /// Payload bytes uploaded on the most recent frame (instance+atlas on `GpuDirect`; pixel rects on `GpuUpload`/`Software`).
556 #[get(type(copy))]
557 pub(crate) upload_bytes_last_frame: u64,
558 /// Cumulative payload bytes uploaded across the session.
559 #[get(type(copy))]
560 pub(crate) upload_bytes_total: u64,
561 /// Number of 64-byte `GpuPrimitiveInstance` records drawn on the most recent `GpuDirect` frame.
562 #[get(type(copy))]
563 pub(crate) primitive_count_last_frame: u32,
564 /// Number of GPU draw calls emitted on the most recent frame.
565 #[get(type(copy))]
566 pub(crate) draw_calls_last_frame: u32,
567 /// Cumulative count of submission errors (lock/encode/commit failures).
568 #[get(type(copy))]
569 pub(crate) submit_failures: u64,
570 /// Cumulative count of compositor presentation failures (`eglSwapBuffers` / drawable errors).
571 #[get(type(copy))]
572 pub(crate) present_failures: u64,
573 /// Cumulative count of GPU context-loss events (`EGL_CONTEXT_LOST` / Metal device reset).
574 #[get(type(copy))]
575 pub(crate) context_loss_count: u64,
576 /// Count of blank frames actively prevented by retaining the last valid surface frame during failover.
577 #[get(type(copy))]
578 pub(crate) blank_frames_prevented: u64,
579 /// True when the native surface holds a valid previously presented frame.
580 #[get(type(copy))]
581 pub(crate) last_valid_frame_retained: bool,
582}
583
584/// Immediate zero-blank-frame failover state machine for Android EGL/GLES3 and iOS Metal presentation.
585#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
586pub struct MobileFailoverController {
587 /// Currently active presentation path.
588 #[get(type(copy))]
589 pub(crate) active_path: MobilePresentPath,
590 /// Preferred startup presentation path before faults.
591 #[get(type(copy))]
592 pub(crate) preferred_path: MobilePresentPath,
593 /// True once at least one valid frame has been presented to the current window surface.
594 #[get(type(copy))]
595 pub(crate) has_valid_presented_frame: bool,
596 /// True while the OS native window / Metal layer remains attached and valid.
597 #[get(type(copy))]
598 pub(crate) window_valid: bool,
599 /// True when direct GPU uber-shader pipeline is available on this surface.
600 #[get(type(copy))]
601 pub(crate) direct_gpu_available: bool,
602 /// True when texture-upload GPU pipeline is available on this surface.
603 #[get(type(copy))]
604 pub(crate) gpu_upload_available: bool,
605 /// Cumulative context-loss faults observed.
606 #[get(type(copy))]
607 pub(crate) context_loss_count: u64,
608 /// Cumulative blank frames prevented by retaining the last valid frame during fault switchover.
609 #[get(type(copy))]
610 pub(crate) blank_frames_prevented: u64,
611 /// Cumulative immediate fallback path transitions executed without waiting for perf comparisons.
612 #[get(type(copy))]
613 pub(crate) fallback_transitions: u64,
614}