use super::*;
impl Default for IncrementalGpuGlyphAtlas {
fn default() -> Self {
let width: u32 = GPU_GLYPH_ATLAS_INITIAL_WIDTH;
let height: u32 = GPU_GLYPH_ATLAS_INITIAL_HEIGHT;
Self {
width,
height,
pixels: vec![0u8; (width as usize).saturating_mul(height as usize)],
cursor_x: GPU_GLYPH_ATLAS_PAD_PX,
cursor_y: GPU_GLYPH_ATLAS_PAD_PX,
shelf_height: 0,
placements: HashMap::new(),
pending_dirty_rects: Vec::new(),
submission_dirty_rects: Vec::new(),
synced_revision: 0,
synced_entry_count: 0,
needs_full_upload: false,
submission_needs_full_upload: true,
total_uploaded_bytes: 0,
}
}
}
impl IncrementalGpuGlyphAtlas {
#[must_use]
pub fn placement(&self, key: GlyphKey) -> Option<GpuGlyphPlacement> {
self.get_placements().get(&key).copied()
}
pub fn insert_or_get(&mut self, key: GlyphKey, glyph: &RasterizedGlyph) -> GpuGlyphPlacement {
if let Some(existing) = self.get_placements().get(&key).copied() {
return existing;
}
let glyph_w: u32 = glyph.get_width();
let glyph_h: u32 = glyph.get_height();
if glyph_w == 0 || glyph_h == 0 {
let empty: GpuGlyphPlacement = GpuGlyphPlacement::new(0, 0, 0, 0, [0, 0, 0, 0]);
let _: Option<GpuGlyphPlacement> = self.get_mut_placements().insert(key, empty);
return empty;
}
if self
.get_cursor_x()
.saturating_add(glyph_w)
.saturating_add(GPU_GLYPH_ATLAS_PAD_PX)
> self.get_width()
{
self.set_cursor_x(GPU_GLYPH_ATLAS_PAD_PX);
let next_y: u32 = self
.get_cursor_y()
.saturating_add(self.get_shelf_height())
.saturating_add(GPU_GLYPH_ATLAS_PAD_PX);
self.set_cursor_y(next_y);
self.set_shelf_height(0);
}
if self
.get_cursor_y()
.saturating_add(glyph_h)
.saturating_add(GPU_GLYPH_ATLAS_PAD_PX)
> self.get_height()
{
let next_h: u32 = (self.get_height().saturating_mul(2)).min(GPU_GLYPH_ATLAS_MAX_DIM);
if next_h > self.get_height() {
self.grow_height(next_h);
} else {
self.reset_shelves();
}
}
let dst_x: u32 = self.get_cursor_x();
let dst_y: u32 = self.get_cursor_y();
let atlas_w: u32 = self.get_width();
let atlas_h: u32 = self.get_height();
let coverage: &[u8] = glyph.get_coverage().as_slice();
let pixel_count: usize = (glyph_w as usize).saturating_mul(glyph_h as usize);
let is_color: bool = pixel_count > 0 && coverage.len() >= pixel_count.saturating_mul(4);
{
let pixels: &mut Vec<u8> = self.get_mut_pixels();
for row_idx in 0..glyph_h {
let dst_row: usize = ((dst_y + row_idx) as usize).saturating_mul(atlas_w as usize);
for col_idx in 0..glyph_w {
let cov: u8 = if is_color {
let src_idx: usize =
((row_idx as usize) * (glyph_w as usize) + (col_idx as usize)) * 4 + 3;
coverage.get(src_idx).copied().unwrap_or(0)
} else {
let src_idx: usize =
(row_idx as usize) * (glyph_w as usize) + (col_idx as usize);
coverage.get(src_idx).copied().unwrap_or(0)
};
let dst_idx: usize = dst_row + ((dst_x + col_idx) as usize);
if let Some(slot) = pixels.get_mut(dst_idx) {
*slot = cov;
}
}
}
}
let uv_rect: [u16; 4] =
encode_glyph_atlas_uv(dst_x, dst_y, glyph_w, glyph_h, atlas_w, atlas_h);
let placement: GpuGlyphPlacement =
GpuGlyphPlacement::new(dst_x, dst_y, glyph_w, glyph_h, uv_rect);
let _: Option<GpuGlyphPlacement> = self.get_mut_placements().insert(key, placement);
self.set_cursor_x(
dst_x
.saturating_add(glyph_w)
.saturating_add(GPU_GLYPH_ATLAS_PAD_PX),
);
self.set_shelf_height(self.get_shelf_height().max(glyph_h));
let dirty: PixelDirtyRect = PixelDirtyRect::new(dst_x, dst_y, glyph_w, glyph_h);
self.get_mut_pending_dirty_rects().push(dirty);
self.get_mut_submission_dirty_rects().push(dirty);
placement
}
pub fn sync_from_glyph_atlas(&mut self, atlas: &GlyphAtlas) -> usize {
let rev: u64 = atlas.get_revision();
let entry_count: usize = atlas.len();
if rev == self.get_synced_revision() && entry_count == self.get_synced_entry_count() {
return 0;
}
if entry_count < self.get_synced_entry_count() {
self.reset_shelves();
}
let mut added: usize = 0;
for (key, glyph) in atlas.get_entries().iter() {
if !self.get_placements().contains_key(key) {
let _: GpuGlyphPlacement = self.insert_or_get(*key, glyph);
added += 1;
}
}
self.set_synced_revision(rev);
self.set_synced_entry_count(entry_count);
added
}
pub fn take_dirty_rects(&mut self) -> Vec<PixelDirtyRect> {
if self.get_needs_full_upload() {
self.set_needs_full_upload(false);
self.get_mut_pending_dirty_rects().clear();
return vec![PixelDirtyRect::new(
0,
0,
self.get_width(),
self.get_height(),
)];
}
take(self.get_mut_pending_dirty_rects())
}
pub fn take_submission_dirty_rects(&mut self) -> Vec<PixelDirtyRect> {
if self.get_submission_needs_full_upload() {
if self.get_placements().is_empty() {
return Vec::new();
}
self.set_submission_needs_full_upload(false);
self.get_mut_submission_dirty_rects().clear();
return vec![PixelDirtyRect::new(
0,
0,
self.get_width(),
self.get_height(),
)];
}
take(self.get_mut_submission_dirty_rects())
}
pub fn flush_to_driver(&mut self, driver: &mut NativeGpuDriver) -> usize {
let dirty_rects: Vec<PixelDirtyRect> = self.take_dirty_rects();
if dirty_rects.is_empty() {
return 0;
}
let atlas_w: u32 = self.get_width();
let atlas_h: u32 = self.get_height();
let row_stride: usize = atlas_w as usize;
let mut uploaded_bytes: usize = 0;
let pixels_slice: &[u8] = self.get_pixels().as_slice();
for rect in dirty_rects.iter() {
let Some(clamped) = rect.clamp_to(atlas_w, atlas_h) else {
continue;
};
let start_offset: usize = (clamped.get_y() as usize)
.saturating_mul(row_stride)
.saturating_add(clamped.get_x() as usize);
if start_offset >= pixels_slice.len() {
continue;
}
let _: bool = driver.upload_texture_dirty_rect(
GpuAtlasPixelFormat::R8Unorm,
0,
(atlas_w, atlas_h),
(
clamped.get_x(),
clamped.get_y(),
clamped.get_width(),
clamped.get_height(),
),
&pixels_slice[start_offset..],
row_stride,
);
uploaded_bytes = uploaded_bytes.saturating_add(clamped.area_pixels());
}
self.set_total_uploaded_bytes(
self.get_total_uploaded_bytes()
.saturating_add(uploaded_bytes as u64),
);
uploaded_bytes
}
fn grow_height(&mut self, next_height: u32) {
let atlas_w: u32 = self.get_width();
let next_len: usize = (atlas_w as usize).saturating_mul(next_height as usize);
self.get_mut_pixels().resize(next_len, 0);
self.set_height(next_height);
self.set_needs_full_upload(true);
self.set_submission_needs_full_upload(true);
for placement in self.get_mut_placements().values_mut() {
let uv: [u16; 4] = encode_glyph_atlas_uv(
placement.get_x(),
placement.get_y(),
placement.get_width(),
placement.get_height(),
atlas_w,
next_height,
);
placement.set_uv_rect(uv);
}
}
fn reset_shelves(&mut self) {
self.get_mut_placements().clear();
self.get_mut_pixels().fill(0);
self.set_cursor_x(GPU_GLYPH_ATLAS_PAD_PX);
self.set_cursor_y(GPU_GLYPH_ATLAS_PAD_PX);
self.set_shelf_height(0);
self.get_mut_pending_dirty_rects().clear();
self.get_mut_submission_dirty_rects().clear();
self.set_needs_full_upload(true);
self.set_submission_needs_full_upload(true);
}
}
impl Default for IncrementalGpuImageAtlas {
fn default() -> Self {
let width: u32 = GPU_IMAGE_ATLAS_INITIAL_WIDTH;
let height: u32 = GPU_IMAGE_ATLAS_INITIAL_HEIGHT;
let byte_len: usize = (width as usize)
.saturating_mul(height as usize)
.saturating_mul(4);
Self {
width,
height,
pixels: vec![0u8; byte_len],
cursor_x: GPU_IMAGE_ATLAS_PAD_PX,
cursor_y: GPU_IMAGE_ATLAS_PAD_PX,
shelf_height: 0,
placements: HashMap::new(),
submission_dirty_rects: Vec::new(),
submission_needs_full_upload: true,
revision: 0,
}
}
}
impl IncrementalGpuImageAtlas {
pub fn begin_frame(&mut self) {
let height_limit: u32 = (self.get_height().saturating_mul(3)) / 4;
if self.get_cursor_y() >= height_limit
&& self.get_height() >= GPU_IMAGE_ATLAS_MAX_DIM
&& self.get_placements().len() > 8
{
self.reset_shelves();
}
}
pub fn insert_or_get(
&mut self,
src_w: u32,
src_h: u32,
rgba_pixels: &[u8],
) -> Option<GpuImagePlacement> {
let required: usize = (src_w as usize)
.saturating_mul(src_h as usize)
.saturating_mul(4);
if src_w == 0 || src_h == 0 || rgba_pixels.len() < required {
return None;
}
let key: u64 = hash_rgba8_image_content(src_w, src_h, &rgba_pixels[..required]);
if let Some(existing) = self.get_placements().get(&key).copied() {
return Some(existing);
}
let pad: u32 = GPU_IMAGE_ATLAS_PAD_PX;
let max_slot_dim: u32 = GPU_IMAGE_ATLAS_MAX_DIM.saturating_sub(pad.saturating_mul(2));
let (pack_w, pack_h): (u32, u32) = if src_w <= max_slot_dim && src_h <= max_slot_dim {
(src_w, src_h)
} else {
let scale_x: f32 = (max_slot_dim as f32) / (src_w as f32);
let scale_y: f32 = (max_slot_dim as f32) / (src_h as f32);
let fit: f32 = scale_x.min(scale_y);
(
((src_w as f32) * fit).floor().max(1.0) as u32,
((src_h as f32) * fit).floor().max(1.0) as u32,
)
};
let need_w: u32 = pack_w.saturating_add(pad.saturating_mul(2));
if need_w > self.get_width() {
let next_w: u32 = need_w.next_power_of_two().min(GPU_IMAGE_ATLAS_MAX_DIM);
self.grow_dimensions(next_w, self.get_height());
}
if self
.get_cursor_x()
.saturating_add(pack_w)
.saturating_add(pad)
> self.get_width()
{
self.set_cursor_x(pad);
let next_y: u32 = self
.get_cursor_y()
.saturating_add(self.get_shelf_height())
.saturating_add(pad.saturating_mul(2));
self.set_cursor_y(next_y);
self.set_shelf_height(0);
}
if self
.get_cursor_y()
.saturating_add(pack_h)
.saturating_add(pad)
> self.get_height()
{
let target_h: u32 = self
.get_cursor_y()
.saturating_add(pack_h)
.saturating_add(pad.saturating_mul(2))
.next_power_of_two()
.min(GPU_IMAGE_ATLAS_MAX_DIM);
if target_h > self.get_height() {
self.grow_dimensions(self.get_width(), target_h);
} else {
self.reset_shelves();
if pack_h.saturating_add(pad.saturating_mul(2)) > self.get_height() {
let exact_h: u32 = pack_h
.saturating_add(pad.saturating_mul(2))
.next_power_of_two()
.min(GPU_IMAGE_ATLAS_MAX_DIM);
self.grow_dimensions(self.get_width(), exact_h);
}
}
}
let dst_x: u32 = self.get_cursor_x();
let dst_y: u32 = self.get_cursor_y();
let atlas_w: u32 = self.get_width();
let atlas_h: u32 = self.get_height();
{
let pixels: &mut Vec<u8> = self.get_mut_pixels();
let atlas_stride: usize = (atlas_w as usize).saturating_mul(4);
let src_stride: usize = (src_w as usize).saturating_mul(4);
if pack_w == src_w && pack_h == src_h {
for row_idx in 0..pack_h {
let src_off: usize = (row_idx as usize).saturating_mul(src_stride);
let dst_off: usize = ((dst_y + row_idx) as usize)
.saturating_mul(atlas_stride)
.saturating_add((dst_x as usize).saturating_mul(4));
let row_bytes: usize = (pack_w as usize).saturating_mul(4);
if src_off + row_bytes <= rgba_pixels.len()
&& dst_off + row_bytes <= pixels.len()
{
pixels[dst_off..(dst_off + row_bytes)]
.copy_from_slice(&rgba_pixels[src_off..(src_off + row_bytes)]);
}
}
} else {
for row_idx in 0..pack_h {
let sy: u32 = (((row_idx as u64) * u64::from(src_h)) / u64::from(pack_h))
.min(u64::from(src_h.saturating_sub(1)))
as u32;
let dst_row_off: usize =
((dst_y + row_idx) as usize).saturating_mul(atlas_stride);
let src_row_off: usize = (sy as usize).saturating_mul(src_stride);
for col_idx in 0..pack_w {
let sx: u32 = (((col_idx as u64) * u64::from(src_w)) / u64::from(pack_w))
.min(u64::from(src_w.saturating_sub(1)))
as u32;
let s_off: usize = src_row_off + (sx as usize) * 4;
let d_off: usize = dst_row_off + ((dst_x + col_idx) as usize) * 4;
if s_off + 4 <= rgba_pixels.len() && d_off + 4 <= pixels.len() {
pixels[d_off..(d_off + 4)]
.copy_from_slice(&rgba_pixels[s_off..(s_off + 4)]);
}
}
}
}
let left_gutter: bool = dst_x > 0;
let right_gutter: bool = dst_x.saturating_add(pack_w) < atlas_w;
for row_idx in 0..pack_h {
let row_base: usize = ((dst_y + row_idx) as usize).saturating_mul(atlas_stride);
if left_gutter {
let src_px: usize = row_base + (dst_x as usize) * 4;
let dst_px: usize = row_base + ((dst_x - 1) as usize) * 4;
if src_px + 4 <= pixels.len() {
let edge: [u8; 4] = [
pixels[src_px],
pixels[src_px + 1],
pixels[src_px + 2],
pixels[src_px + 3],
];
pixels[dst_px..(dst_px + 4)].copy_from_slice(&edge);
}
}
if right_gutter {
let src_px: usize = row_base + ((dst_x + pack_w - 1) as usize) * 4;
let dst_px: usize = row_base + ((dst_x + pack_w) as usize) * 4;
if dst_px + 4 <= pixels.len() {
let edge: [u8; 4] = [
pixels[src_px],
pixels[src_px + 1],
pixels[src_px + 2],
pixels[src_px + 3],
];
pixels[dst_px..(dst_px + 4)].copy_from_slice(&edge);
}
}
}
let copy_x0: u32 = dst_x.saturating_sub(1);
let copy_x1: u32 = dst_x.saturating_add(pack_w).saturating_add(1).min(atlas_w);
let span_bytes: usize = ((copy_x1.saturating_sub(copy_x0)) as usize).saturating_mul(4);
if dst_y > 0 && span_bytes > 0 {
let src_row: usize =
(dst_y as usize).saturating_mul(atlas_stride) + (copy_x0 as usize) * 4;
let dst_row: usize =
((dst_y - 1) as usize).saturating_mul(atlas_stride) + (copy_x0 as usize) * 4;
if src_row + span_bytes <= pixels.len() {
pixels.copy_within(src_row..(src_row + span_bytes), dst_row);
}
}
if dst_y.saturating_add(pack_h) < atlas_h && span_bytes > 0 {
let src_row: usize = ((dst_y + pack_h - 1) as usize).saturating_mul(atlas_stride)
+ (copy_x0 as usize) * 4;
let dst_row: usize = ((dst_y + pack_h) as usize).saturating_mul(atlas_stride)
+ (copy_x0 as usize) * 4;
if dst_row + span_bytes <= pixels.len() {
pixels.copy_within(src_row..(src_row + span_bytes), dst_row);
}
}
}
let uv_rect: [u16; 4] =
encode_glyph_atlas_uv(dst_x, dst_y, pack_w, pack_h, atlas_w, atlas_h);
let placement: GpuImagePlacement =
GpuImagePlacement::new(dst_x, dst_y, pack_w, pack_h, uv_rect);
let _: Option<GpuImagePlacement> = self.get_mut_placements().insert(key, placement);
self.set_cursor_x(
dst_x
.saturating_add(pack_w)
.saturating_add(pad.saturating_mul(2)),
);
self.set_shelf_height(self.get_shelf_height().max(pack_h));
let dirty_x: u32 = dst_x.saturating_sub(1);
let dirty_y: u32 = dst_y.saturating_sub(1);
let dirty_w: u32 = dst_x
.saturating_add(pack_w)
.saturating_add(1)
.min(atlas_w)
.saturating_sub(dirty_x);
let dirty_h: u32 = dst_y
.saturating_add(pack_h)
.saturating_add(1)
.min(atlas_h)
.saturating_sub(dirty_y);
self.get_mut_submission_dirty_rects()
.push(PixelDirtyRect::new(dirty_x, dirty_y, dirty_w, dirty_h));
self.set_revision(self.get_revision().wrapping_add(1));
Some(placement)
}
#[must_use]
pub fn sub_uv_rect(
&self,
placement: GpuImagePlacement,
sheet_w: u32,
sheet_h: u32,
src_rect: Rect,
) -> [u16; 4] {
let sx_scale: f32 = (placement.get_width() as f32) / (sheet_w.max(1) as f32);
let sy_scale: f32 = (placement.get_height() as f32) / (sheet_h.max(1) as f32);
let rx: f32 = (placement.get_x() as f32) + src_rect.get_x().max(0.0) * sx_scale;
let ry: f32 = (placement.get_y() as f32) + src_rect.get_y().max(0.0) * sy_scale;
let rw: f32 = (src_rect.get_width().max(1.0) * sx_scale).min(placement.get_width() as f32);
let rh: f32 =
(src_rect.get_height().max(1.0) * sy_scale).min(placement.get_height() as f32);
let inv_w: f32 = 1.0 / (self.get_width().max(1) as f32);
let inv_h: f32 = 1.0 / (self.get_height().max(1) as f32);
[
(rx * inv_w * 65535.0).round().clamp(0.0, 65535.0) as u16,
(ry * inv_h * 65535.0).round().clamp(0.0, 65535.0) as u16,
((rx + rw) * inv_w * 65535.0).round().clamp(0.0, 65535.0) as u16,
((ry + rh) * inv_h * 65535.0).round().clamp(0.0, 65535.0) as u16,
]
}
pub fn take_submission_dirty_rects(&mut self) -> Vec<PixelDirtyRect> {
if self.get_submission_needs_full_upload() {
if self.get_placements().is_empty() {
return Vec::new();
}
self.set_submission_needs_full_upload(false);
self.get_mut_submission_dirty_rects().clear();
return vec![PixelDirtyRect::new(
0,
0,
self.get_width(),
self.get_height(),
)];
}
take(self.get_mut_submission_dirty_rects())
}
fn grow_dimensions(&mut self, next_width: u32, next_height: u32) {
let old_w: u32 = self.get_width();
let old_h: u32 = self.get_height();
let next_len: usize = (next_width as usize)
.saturating_mul(next_height as usize)
.saturating_mul(4);
let mut next_pixels: Vec<u8> = vec![0u8; next_len];
let old_stride: usize = (old_w as usize).saturating_mul(4);
let new_stride: usize = (next_width as usize).saturating_mul(4);
let copy_rows: u32 = old_h.min(next_height);
let copy_bytes: usize = old_stride.min(new_stride);
{
let old_pixels: &[u8] = self.get_pixels().as_slice();
for row_idx in 0..copy_rows {
let s_off: usize = (row_idx as usize).saturating_mul(old_stride);
let d_off: usize = (row_idx as usize).saturating_mul(new_stride);
if s_off + copy_bytes <= old_pixels.len() && d_off + copy_bytes <= next_pixels.len()
{
next_pixels[d_off..(d_off + copy_bytes)]
.copy_from_slice(&old_pixels[s_off..(s_off + copy_bytes)]);
}
}
}
self.set_width(next_width);
self.set_height(next_height);
self.set_pixels(next_pixels);
self.set_submission_needs_full_upload(true);
for placement in self.get_mut_placements().values_mut() {
let uv: [u16; 4] = encode_glyph_atlas_uv(
placement.get_x(),
placement.get_y(),
placement.get_width(),
placement.get_height(),
next_width,
next_height,
);
placement.set_uv_rect(uv);
}
}
fn reset_shelves(&mut self) {
self.get_mut_placements().clear();
self.get_mut_pixels().fill(0);
self.set_cursor_x(GPU_IMAGE_ATLAS_PAD_PX);
self.set_cursor_y(GPU_IMAGE_ATLAS_PAD_PX);
self.set_shelf_height(0);
self.get_mut_submission_dirty_rects().clear();
self.set_submission_needs_full_upload(true);
self.set_revision(self.get_revision().wrapping_add(1));
}
}
impl Default for RenderGraph {
fn default() -> Self {
Self {
max_frames_in_flight: RENDER_GRAPH_DEFAULT_MAX_IN_FLIGHT,
dirty_coalescer: DirtySpanCoalescer::default(),
gpu_glyph_atlas: IncrementalGpuGlyphAtlas::default(),
last_plan: RenderGraphFramePlan::default(),
last_receipt: RenderGraphExecutionReceipt::default(),
executed_frames: 0,
}
}
}
impl RenderGraphFrameTarget {
#[must_use]
pub fn new(width: u32, height: u32, clear_color: Color) -> Self {
Self {
width,
height,
clear_color,
external_texture_handle: 0,
}
}
#[must_use]
pub fn with_external_texture(mut self, external_texture_handle: usize) -> Self {
self.set_external_texture_handle(external_texture_handle);
self
}
}
impl RenderGraph {
#[must_use]
pub fn plan_frame(
&self,
target: RenderGraphFrameTarget,
counts: RenderGraphPlanCounts,
) -> RenderGraphFramePlan {
let mut passes: Vec<RenderGraphPassKind> = Vec::with_capacity(5);
if counts.get_has_compute_layout() {
passes.push(RenderGraphPassKind::ComputeLayout);
}
if counts.get_dirty_span_count() > 0 || counts.get_atlas_dirty_rect_count() > 0 {
passes.push(RenderGraphPassKind::BlitAndAtlasUpload);
}
if target.get_external_texture_handle() != 0 {
passes.push(RenderGraphPassKind::OffscreenExternalTarget);
}
if counts.get_blur_pass_count() > 0 {
passes.push(RenderGraphPassKind::DualKawaseBackdropBlur);
}
passes.push(RenderGraphPassKind::UberUiDirectAndIndirect);
RenderGraphFramePlan {
passes,
width: target.get_width(),
height: target.get_height(),
dirty_span_count: counts.get_dirty_span_count(),
atlas_dirty_rect_count: counts.get_atlas_dirty_rect_count(),
blur_pass_count: counts
.get_blur_pass_count()
.min(RENDER_GRAPH_MAX_BLUR_PASSES),
external_texture_handle: target.get_external_texture_handle(),
}
}
pub fn execute_frame(
&mut self,
driver: &mut NativeGpuDriver,
target: RenderGraphFrameTarget,
batches: &[GpuBatch],
blur_passes: &[GpuBackdropBlurPass],
compute_work: Option<(&mut GpuComputeLayoutEngine, &GpuComputeSceneInput)>,
) -> Result<RenderGraphExecutionReceipt, PlatformError> {
let width: u32 = target.get_width();
let height: u32 = target.get_height();
let clear_color: Color = target.get_clear_color();
let external_texture_handle: usize = target.get_external_texture_handle();
let dirty_spans_count: usize = if batches.len() == 1 {
self.get_mut_dirty_coalescer()
.diff_and_coalesce(batches[0].get_primitives().as_slice())
.len()
} else {
let mut flat_prims: Vec<GpuPrimitiveInstance> = Vec::new();
for batch in batches.iter() {
flat_prims.extend_from_slice(batch.get_primitives().as_slice());
}
self.get_mut_dirty_coalescer()
.diff_and_coalesce(flat_prims.as_slice())
.len()
};
let dirty_upload_bytes: usize = self.get_dirty_coalescer().get_last_dirty_bytes();
let full_upload_bytes: usize = self.get_dirty_coalescer().get_last_full_bytes();
let pending_atlas_rects: usize = self.get_gpu_glyph_atlas().get_pending_dirty_rects().len()
+ usize::from(self.get_gpu_glyph_atlas().get_needs_full_upload());
let plan_counts: RenderGraphPlanCounts = RenderGraphPlanCounts::new(
compute_work.is_some(),
dirty_spans_count,
pending_atlas_rects,
blur_passes.len(),
);
let plan: RenderGraphFramePlan = self.plan_frame(target, plan_counts);
let observed_completed: u64 = completed_gpu_fence();
let mut gpu_compute_ns: u64 = last_gpu_compute_ns();
let mut draw_calls: usize = 0;
if let Some((compute_engine, compute_scene)) = compute_work {
let comp_res: GpuComputeDispatchResult = compute_engine.dispatch(compute_scene, false);
gpu_compute_ns = comp_res.get_gpu_compute_ns();
draw_calls = draw_calls.saturating_add(comp_res.get_draw_calls());
}
let atlas_upload_bytes: usize = self.get_mut_gpu_glyph_atlas().flush_to_driver(driver);
if external_texture_handle != 0 {
driver.set_external_texture(external_texture_handle);
}
let blur_executed: usize =
if !blur_passes.is_empty() && driver.supports_backdrop_blur_pass() {
driver.execute_dual_kawase_blur_passes(width, height, blur_passes)
} else {
0
};
let ui_draws: usize = driver.submit_batches(width, height, clear_color, batches)?;
draw_calls = draw_calls
.saturating_add(ui_draws)
.saturating_add(blur_executed.saturating_mul(2));
let submitted_fence_id: u64 = submitted_gpu_fence().max(driver.get_submitted_frames());
let gpu_render_ns: u64 = driver.get_last_gpu_exec_ns().max(last_gpu_render_ns());
let receipt: RenderGraphExecutionReceipt = RenderGraphExecutionReceipt {
executed_passes: plan.get_passes().clone(),
submitted_fence_id,
observed_completed_fence_id: observed_completed,
dirty_upload_bytes,
full_upload_bytes,
atlas_upload_bytes,
blur_passes_executed: blur_executed,
draw_calls,
gpu_compute_ns,
gpu_render_ns,
};
self.set_last_plan(plan);
self.set_last_receipt(receipt.clone());
self.set_executed_frames(self.get_executed_frames().wrapping_add(1));
Ok(receipt)
}
}