Skip to main content

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