From b00e7009d74a51552a30ba98113622fc5044a7b5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 May 2024 21:12:04 -0700 Subject: [PATCH] renderer/metal: do not update frames if cells don't change --- src/renderer/Metal.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index b9403c0e3..6c242cf73 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -101,6 +101,11 @@ cells: mtl_cell.Contents, /// If this is true, we do a full cell rebuild on the next frame. cells_rebuild: bool = true, +/// Set to true after rebuildCells is called. This can be used +/// to determine if any possible changes have been made to the +/// cells for the draw call. +cells_rebuilt: bool = false, + /// The current GPU uniform values. uniforms: mtl_shaders.Uniforms, @@ -968,6 +973,12 @@ pub fn updateFrame( pub fn drawFrame(self: *Metal, surface: *apprt.Surface) !void { _ = surface; + // If our cells are not rebuilt, do a no-op draw. This means + // that no possible new data can exist that would warrant a full + // GPU update, our existing drawable is valid. + if (!self.cells_rebuilt) return; + self.cells_rebuilt = false; + // Wait for a frame to be available. const frame = self.gpu_state.nextFrame(); errdefer self.gpu_state.releaseFrame(); @@ -1988,6 +1999,9 @@ fn rebuildCells( // We always mark our rebuild flag as false since we're done. self.cells_rebuild = false; + // Update that our cells rebuilt + self.cells_rebuilt = true; + // Log some things // log.debug("rebuildCells complete cached_runs={}", .{ // self.font_shaper_cache.count(),