diff options
Diffstat (limited to 'src/host/overlay.zig')
| -rw-r--r-- | src/host/overlay.zig | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/src/host/overlay.zig b/src/host/overlay.zig index 5219a83..ec040e7 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 { @@ -63,7 +111,7 @@ pub fn drawMemory(out: *List, arena: std.mem.Allocator, layout: memory.Layout, s } } -pub fn drawScope(out: *List, arena: std.mem.Allocator, samples: []const f32, rate: u32, canvas: [2]u32) !void { +pub fn drawScope(out: *List, arena: std.mem.Allocator, samples: []const f32, rate: u32, pull: u32, canvas: [2]u32) !void { const green: abi.Color = .{ .r = 105, .g = 245, .b = 160 }; const x = @as(f32, @floatFromInt(canvas[0])) - 526; const top = @as(f32, @floatFromInt(canvas[1])) - 130; @@ -71,7 +119,7 @@ pub fn drawScope(out: *List, arena: std.mem.Allocator, samples: []const f32, rat try out.append(arena, .{ .rect = .{ .dst = .{ .x = x, .y = top, .w = 514, .h = 118 }, .color = .{ .r = 24, .g = 24, .b = 24 } } }); try out.append(arena, .{ .rect = .{ .dst = .{ .x = x + 1, .y = mid, .w = 512, .h = 1 }, .color = .{ .r = 60, .g = 85, .b = 65 } } }); const ms = @as(f32, @floatFromInt(samples.len * 1000)) / @as(f32, @floatFromInt(@max(rate, 1))); - try out.append(arena, .{ .text = .{ .x = x + 8, .y = top + 10, .scale = 1, .color = green, .bytes = try std.fmt.allocPrint(arena, "OUTPUT ch1 / {d:.1}ms / overlay sound to hide", .{ms}) } }); + try out.append(arena, .{ .text = .{ .x = x + 8, .y = top + 10, .scale = 1, .color = green, .bytes = try std.fmt.allocPrint(arena, "OUTPUT ch1 / {d:.1}ms / pull {d} / overlay sound to hide", .{ ms, pull }) } }); for (samples, 0..) |sample, i| { const a = std.math.clamp(if (std.math.isFinite(sample)) sample else 0, -1, 1); const previous = samples[i -| 1]; |
