diff options
Diffstat (limited to 'src/host/overlay.zig')
| -rw-r--r-- | src/host/overlay.zig | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/host/overlay.zig b/src/host/overlay.zig index 5219a83..e1fc45d 100644 --- a/src/host/overlay.zig +++ b/src/host/overlay.zig @@ -4,10 +4,58 @@ const std = @import("std"); const abi = @import("abi"); const memory = @import("memory.zig"); const fields = @import("fields.zig"); +const Timing = @import("Timing.zig"); +const gfx = @import("gfx.zig"); +pub const TimingAtlas = @import("TimingAtlas.zig"); const List = std.ArrayList(abi.Command); const shown_bytes = 0x100; +pub fn drawTiming(painter: *gfx.Painter, timing: *Timing, canvas: [2]u32, atlas: TimingAtlas) !void { + var batch: TimingAtlas.Batch = .{ .atlas = atlas }; + const reference: f64 = if (timing.metric == .frame) 1000.0 / 60.0 else 1; + var ceiling = reference * 1.25; + for (0..timing.graph_count) |i| ceiling = @max(ceiling, Timing.ms(Timing.value(timing.graphAt(i), timing.metric)) * 1.1); + if (timing.dirty or ceiling != timing.ceiling) { + timing.ceiling = ceiling; + timing.setLabel(3, "8 frames/peak / 0..{d:.2} ms / line {d:.2}", .{ ceiling, reference }); + } + if (timing.dirty) { + timing.cached = .{ timing.stats(.frame), timing.stats(.work) }; + timing.setLabel(0, "TIMING / {t} / stats: {d} frames / ms", .{ timing.metric, timing.count }); + for (timing.cached, 0..) |s, i| timing.setLabel(i + 1, "{s} avg {d:.3} p90 {d:.3} p99 {d:.3}", .{ if (i == 0) "Frame" else "Work ", s.mean, s.p90, s.p99 }); + timing.dirty = false; + } + const width = @min(@as(f32, @floatFromInt(canvas[0])), 480); + const scale = width / 480; + const x = @as(f32, @floatFromInt(canvas[0])) - width; + const green: abi.Color = .{ .r = 105, .g = 245, .b = 160 }; + const muted: abi.Color = .{ .r = 165, .g = 180, .b = 195 }; + try batch.rect(.{ .x = x, .y = 0, .w = width, .h = 200 * scale }, .{ .r = 20, .g = 25, .b = 32 }); + for (0..4) |i| { + const y: f32 = switch (i) { + 0 => 8, + 1 => 30, + 2 => 48, + else => 70, + }; + try batch.text(timing.label(i), x + 12 * scale, y * scale, scale, if (i == 0) green else if (i == 3) muted else .white); + } + const left = x + 12 * scale; + const bottom = 170 * scale; + const height = 78 * scale; + const step = 456 * scale / Timing.capacity; + const line_y = bottom - height * @as(f32, @floatCast(reference / ceiling)); + try batch.rect(.{ .x = left, .y = line_y, .w = 456 * scale, .h = 1 }, muted); + for (0..timing.graph_count) |i| { + const value = Timing.ms(Timing.value(timing.graphAt(i), timing.metric)); + const h = @max(1, height * @as(f32, @floatCast(value / ceiling))); + try batch.rect(.{ .x = left + @as(f32, @floatFromInt(Timing.capacity - timing.graph_count + i)) * step, .y = bottom - h, .w = step, .h = h }, green); + } + try batch.text("Frame includes present / Work stops before it", left, 180 * scale, scale, muted); + batch.draw(painter); +} + /// Each field hashes its path into a dark shade; bytes it owns wear the same /// shade in the hex view below, and padding stays gray. fn shade(path: []const u8) abi.Color { |
