9e189dbc
Clarify row rebuild cache contract
a73x 2026-04-08 19:16
diff --git a/src/main.zig b/src/main.zig index f15c3be..d3b59bc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -750,7 +750,7 @@ test "rebuildRowInstances emits expected instances for a colored glyph row" { atlas.cursorUV(), ); try std.testing.expect(rebuilt); try std.testing.expect(rebuilt.len_changed); try std.testing.expectEqual(@as(usize, 2), cache.instances.items.len); const colors = term.cellColors(row_cells.get(0)); @@ -784,6 +784,8 @@ test "rebuildRowInstances replaces stale cached contents without layout dirtines var cache = RowInstanceCache{}; defer cache.instances.deinit(std.testing.allocator); cache.gpu_offset_instances = 17; cache.gpu_len_instances = 29; try cache.instances.append(std.testing.allocator, .{ .cell_pos = .{ 99.0, 99.0 }, .glyph_size = .{ 1.0, 1.0 }, @@ -817,10 +819,17 @@ test "rebuildRowInstances replaces stale cached contents without layout dirtines atlas.cursorUV(), ); try std.testing.expect(!rebuilt); try std.testing.expect(!rebuilt.len_changed); try std.testing.expectEqual(@as(usize, 2), cache.instances.items.len); try std.testing.expectEqualDeep([2]f32{ 0.0, 0.0 }, cache.instances.items[0].cell_pos); try std.testing.expectEqualDeep([2]f32{ 0.0, 0.0 }, cache.instances.items[1].cell_pos); try std.testing.expectEqualDeep([2]f32{ @floatFromInt(face.cellWidth()), @floatFromInt(face.cellHeight()) }, cache.instances.items[0].glyph_size); try std.testing.expectEqualDeep(term.cellColors(row_cells.get(0)).bg, cache.instances.items[0].fg); try std.testing.expectEqualDeep(term.cellColors(row_cells.get(0)).bg, cache.instances.items[0].bg); try std.testing.expectEqualDeep(term.cellColors(row_cells.get(0)).fg, cache.instances.items[1].fg); try std.testing.expectEqualDeep(term.cellColors(row_cells.get(0)).bg, cache.instances.items[1].bg); try std.testing.expectEqual(@as(u32, 0), cache.gpu_offset_instances); try std.testing.expectEqual(@as(u32, 0), cache.gpu_len_instances); } test "RenderCache resizeRows preserves surviving row caches" { @@ -1011,6 +1020,10 @@ const RowPackResult = struct { cursor_len_instances: u32, }; const RowRebuildResult = struct { len_changed: bool, }; fn repackRowCaches( alloc: std.mem.Allocator, packed_instances: *std.ArrayListUnmanaged(renderer.Instance), @@ -1056,9 +1069,11 @@ fn rebuildRowInstances( baseline: u32, default_bg: [4]f32, bg_uv: font.GlyphUV, ) !bool { ) !RowRebuildResult { const old_len = cache.instances.items.len; cache.instances.clearRetainingCapacity(); cache.gpu_offset_instances = 0; cache.gpu_len_instances = 0; const raw_cells = row_cells.items(.raw); var col_idx: u32 = 0; @@ -1085,7 +1100,9 @@ fn rebuildRowInstances( ); } return markLayoutDirtyOnLenChange(old_len, cache.instances.items.len); return .{ .len_changed = markLayoutDirtyOnLenChange(old_len, cache.instances.items.len), }; } fn markLayoutDirtyOnLenChange(old_len: usize, new_len: usize) bool {