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