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}