Skip to main content

euv_core/render/graph/
struct.rs

1use super::*;
2
3/// Cached glyph placement inside the persistent incremental R8 GPU glyph atlas.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
5pub struct GpuGlyphPlacement {
6    /// Left texel coordinate inside the persistent R8 atlas texture.
7    #[get(type(copy))]
8    pub(crate) x: u32,
9    /// Top texel coordinate inside the persistent R8 atlas texture.
10    #[get(type(copy))]
11    pub(crate) y: u32,
12    /// Glyph coverage bitmap width in texels.
13    #[get(type(copy))]
14    pub(crate) width: u32,
15    /// Glyph coverage bitmap height in texels.
16    #[get(type(copy))]
17    pub(crate) height: u32,
18    /// Pre-encoded normalized UV rectangle `[u0, v0, u1, v1]` in `[0..=65535]`.
19    #[get(type(copy))]
20    pub(crate) uv_rect: [u16; 4],
21}
22
23/// Persistent incremental shelf-packed R8 glyph atlas that tracks newly added glyph dirty sub-rects for GPU upload.
24#[derive(Clone, Data, Debug)]
25pub struct IncrementalGpuGlyphAtlas {
26    /// Backing R8 atlas texture width in texels.
27    #[get(type(copy))]
28    pub(crate) width: u32,
29    /// Backing R8 atlas texture height in texels.
30    #[get(type(copy))]
31    pub(crate) height: u32,
32    /// Backing single-channel R8 pixel storage aligned to `width * height`.
33    pub(crate) pixels: Vec<u8>,
34    /// Current shelf packing X cursor in texels.
35    #[get(type(copy))]
36    pub(crate) cursor_x: u32,
37    /// Current shelf packing Y cursor in texels.
38    #[get(type(copy))]
39    pub(crate) cursor_y: u32,
40    /// Tallest glyph height in the active shelf row.
41    #[get(type(copy))]
42    pub(crate) shelf_height: u32,
43    /// Per-glyph atlas placements indexed by `GlyphKey`.
44    pub(crate) placements: HashMap<GlyphKey, GpuGlyphPlacement>,
45    /// Pending dirty sub-rectangles waiting to upload via `upload_texture_dirty_rect`.
46    pub(crate) pending_dirty_rects: Vec<PixelDirtyRect>,
47    /// Pending dirty sub-rectangles queued exclusively for `GpuFrameSubmission` platform swapchain uploads.
48    pub(crate) submission_dirty_rects: Vec<PixelDirtyRect>,
49    /// Last `GlyphAtlas::revision` synchronized into this GPU atlas.
50    #[get(type(copy))]
51    pub(crate) synced_revision: u64,
52    /// Number of entries synchronized at `synced_revision` to detect evictions/clears.
53    #[get(type(copy))]
54    pub(crate) synced_entry_count: usize,
55    /// True when the backing GPU texture was resized and requires a full upload once.
56    #[get(type(copy))]
57    pub(crate) needs_full_upload: bool,
58    /// True when platform direct-GPU submission still requires an initial or post-resize full atlas upload.
59    #[get(type(copy))]
60    pub(crate) submission_needs_full_upload: bool,
61    /// Cumulative R8 bytes uploaded to the GPU glyph texture across all frames.
62    #[get(type(copy))]
63    pub(crate) total_uploaded_bytes: u64,
64}
65
66/// Cached RGBA8 image placement inside the persistent incremental GPU image atlas.
67#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
68pub struct GpuImagePlacement {
69    /// Left texel coordinate inside the persistent RGBA8 atlas texture.
70    #[get(type(copy))]
71    pub(crate) x: u32,
72    /// Top texel coordinate inside the persistent RGBA8 atlas texture.
73    #[get(type(copy))]
74    pub(crate) y: u32,
75    /// Packed image width in texels.
76    #[get(type(copy))]
77    pub(crate) width: u32,
78    /// Packed image height in texels.
79    #[get(type(copy))]
80    pub(crate) height: u32,
81    /// Pre-encoded normalized UV rectangle `[u0, v0, u1, v1]` in `[0..=65535]`.
82    #[get(type(copy))]
83    pub(crate) uv_rect: [u16; 4],
84}
85
86/// Persistent shelf-packed RGBA8 GPU image atlas with content-hash caching and incremental dirty sub-rectangle tracking.
87#[derive(Clone, Data, Debug)]
88pub struct IncrementalGpuImageAtlas {
89    /// Backing RGBA8 atlas texture width in texels.
90    #[get(type(copy))]
91    pub(crate) width: u32,
92    /// Backing RGBA8 atlas texture height in texels.
93    #[get(type(copy))]
94    pub(crate) height: u32,
95    /// Backing RGBA8 pixel storage aligned to `width * height * 4`.
96    pub(crate) pixels: Vec<u8>,
97    /// Current shelf packing X cursor in texels.
98    #[get(type(copy))]
99    pub(crate) cursor_x: u32,
100    /// Current shelf packing Y cursor in texels.
101    #[get(type(copy))]
102    pub(crate) cursor_y: u32,
103    /// Tallest image height in the active shelf row.
104    #[get(type(copy))]
105    pub(crate) shelf_height: u32,
106    /// Per-image atlas placements indexed by fast content hash.
107    pub(crate) placements: HashMap<u64, GpuImagePlacement>,
108    /// Pending dirty sub-rectangles waiting for direct-GPU platform swapchain upload.
109    pub(crate) submission_dirty_rects: Vec<PixelDirtyRect>,
110    /// True when the backing RGBA8 atlas texture requires a full upload on next submission.
111    #[get(type(copy))]
112    pub(crate) submission_needs_full_upload: bool,
113    /// Monotonic revision incremented whenever image pixels are packed or repacked.
114    #[get(type(copy))]
115    pub(crate) revision: u64,
116}
117
118/// Scheduled render-graph frame plan listing the active passes and resource requirements for one frame.
119#[derive(Clone, Data, Debug, Default, PartialEq)]
120pub struct RenderGraphFramePlan {
121    /// Ordered GPU passes scheduled for execution in this frame.
122    pub(crate) passes: Vec<RenderGraphPassKind>,
123    /// Physical surface width in pixels.
124    #[get(type(copy))]
125    pub(crate) width: u32,
126    /// Physical surface height in pixels.
127    #[get(type(copy))]
128    pub(crate) height: u32,
129    /// Number of coalesced dirty buffer spans scheduled for Pass 1 upload.
130    #[get(type(copy))]
131    pub(crate) dirty_span_count: usize,
132    /// Number of dirty glyph/image atlas rectangles scheduled for Pass 1 upload.
133    #[get(type(copy))]
134    pub(crate) atlas_dirty_rect_count: usize,
135    /// Number of Dual-Kawase blur regions scheduled for Pass 3.
136    #[get(type(copy))]
137    pub(crate) blur_pass_count: usize,
138    /// External GPU texture handle scheduled for Pass 2 (`0` when unused).
139    #[get(type(copy))]
140    pub(crate) external_texture_handle: usize,
141}
142
143/// Execution telemetry receipt returned by `RenderGraph::execute_frame`.
144#[derive(Clone, Data, Debug, Default, PartialEq)]
145pub struct RenderGraphExecutionReceipt {
146    /// Ordered passes actually executed for this frame.
147    pub(crate) executed_passes: Vec<RenderGraphPassKind>,
148    /// Monotonic GPU fence identifier assigned to this submission.
149    #[get(type(copy))]
150    pub(crate) submitted_fence_id: u64,
151    /// Highest completed GPU fence observed without blocking before submission.
152    #[get(type(copy))]
153    pub(crate) observed_completed_fence_id: u64,
154    /// Coalesced primitive bytes uploaded during Pass 1.
155    #[get(type(copy))]
156    pub(crate) dirty_upload_bytes: usize,
157    /// Full uncoalesced primitive byte size for upload-savings measurement.
158    #[get(type(copy))]
159    pub(crate) full_upload_bytes: usize,
160    /// Incremental glyph/image atlas bytes uploaded during Pass 1.
161    #[get(type(copy))]
162    pub(crate) atlas_upload_bytes: usize,
163    /// Number of Dual-Kawase `blur_down` + `blur_up` blur regions executed during Pass 3.
164    #[get(type(copy))]
165    pub(crate) blur_passes_executed: usize,
166    /// Total hardware draw calls executed across Pass 3 and Pass 4.
167    #[get(type(copy))]
168    pub(crate) draw_calls: usize,
169    /// Measured GPU compute duration in nanoseconds (`LAST_GPU_COMPUTE_NS`).
170    #[get(type(copy))]
171    pub(crate) gpu_compute_ns: u64,
172    /// Measured GPU render duration in nanoseconds (`LAST_GPU_RENDER_NS`).
173    #[get(type(copy))]
174    pub(crate) gpu_render_ns: u64,
175}
176
177/// Surface target and auxiliary pass configuration supplied to `RenderGraph::plan_frame` and `RenderGraph::execute_frame`.
178#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
179pub struct RenderGraphFrameTarget {
180    /// Physical surface width in pixels.
181    #[get(type(copy))]
182    pub(crate) width: u32,
183    /// Physical surface height in pixels.
184    #[get(type(copy))]
185    pub(crate) height: u32,
186    /// Surface background clear color.
187    #[get(type(copy))]
188    pub(crate) clear_color: Color,
189    /// Optional external 3D/Fluid GPU texture handle scheduled for Pass 2 (`0` when absent).
190    #[get(type(copy))]
191    pub(crate) external_texture_handle: usize,
192}
193
194/// Pass workload counts supplied to `RenderGraph::plan_frame`.
195#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
196pub struct RenderGraphPlanCounts {
197    /// Whether Pass 0 GPU compute layout is active.
198    #[get(type(copy))]
199    pub(crate) has_compute_layout: bool,
200    /// Number of coalesced dirty primitive spans scheduled for Pass 1.
201    #[get(type(copy))]
202    pub(crate) dirty_span_count: usize,
203    /// Number of dirty glyph/image atlas rectangles scheduled for Pass 1.
204    #[get(type(copy))]
205    pub(crate) atlas_dirty_rect_count: usize,
206    /// Number of Dual-Kawase backdrop blur regions scheduled for Pass 3.
207    #[get(type(copy))]
208    pub(crate) blur_pass_count: usize,
209}
210
211/// Unified render-graph scheduler coordinating Pass 0..4, dirty-span uploads, incremental glyph atlas sync, and pipelined fences.
212#[derive(Clone, Data, Debug)]
213pub struct RenderGraph {
214    /// Configured maximum frames in flight (`2` default for CPU/GPU pipelined overlap).
215    #[get(type(copy))]
216    pub(crate) max_frames_in_flight: u32,
217    /// Coalesced dirty-range uploader for retained 64-byte UI primitives.
218    pub(crate) dirty_coalescer: DirtySpanCoalescer,
219    /// Persistent incremental R8 glyph atlas synchronized via dirty sub-rects.
220    pub(crate) gpu_glyph_atlas: IncrementalGpuGlyphAtlas,
221    /// Most recent scheduled frame plan.
222    pub(crate) last_plan: RenderGraphFramePlan,
223    /// Most recent execution telemetry receipt.
224    pub(crate) last_receipt: RenderGraphExecutionReceipt,
225    /// Cumulative frames executed through this render graph.
226    #[get(type(copy))]
227    pub(crate) executed_frames: u64,
228}