summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:01:02 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit30a603341e3b23da6e5ab5995b060c8e4ec52242 (patch)
tree9a24941b147a5265e6b0726285e9501cd7b61c6d /src/gui/gui.zig
parentafc60e735274b0de5423ac375a9ea582f64b516f (diff)
downloadpardes-30a603341e3b23da6e5ab5995b060c8e4ec52242.tar.gz
pardes-30a603341e3b23da6e5ab5995b060c8e4ec52242.zip
test: the GPU move's gates, sharper: a window the harness starts runs under PARDES_TEST_WRAP when it names a command (perf stat, a script), given the window's argv, its binary made absolute; a test window's series keeps its frames as PAM (P7 RGB_ALPHA), so the corpus sees the alpha a blend writes (latest.ppm and every other capture stay RGB); the corpus adds a translucent addon picture, test/veil.zig (zig build veil: a GPU pass that clears to half alpha and draws nothing), for the addon pipeline's colour factor, which the snake's opaque picture never showed; the snake's window ends with its pane gone and at rest, so it ends having drawn as many frames every run
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index a67602e8..cc43d8b6 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -5830,10 +5830,10 @@ fn captureFrame(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, t
const mapped = c.SDL_MapGPUTransferBuffer(g.device, xfer, false) orelse return error.GpuMap;
defer c.SDL_UnmapGPUTransferBuffer(g.device, xfer);
const pixels: [*]const u8 = @ptrCast(mapped);
- try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, "latest");
+ try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, "latest", false);
var name: [24]u8 = undefined;
// unreachable below: "frame-" and a u32 fit 24
- if (g.capture_series) try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, std.fmt.bufPrint(&name, "frame-{d:0>5}", .{g.captured}) catch unreachable);
+ if (g.capture_series) try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, std.fmt.bufPrint(&name, "frame-{d:0>5}", .{g.captured}) catch unreachable, true);
g.captured +%= 1;
}
@@ -5863,7 +5863,10 @@ fn writeTestStatus(g: *const Gui, core: *const pardes.Pardes, presented: bool) v
_ = libc.rename(tmp_path, final_path);
}
-fn writeCapturePpm(g: *Gui, gpa: std.mem.Allocator, pixels: []const u8, width: u32, height: u32, name: []const u8) !void {
+/// `<name>.ppm`, RGB; with `alpha`, `<name>.pam` (P7 RGB_ALPHA) instead: a
+/// series keeps the alpha a blend writes, which the window's transparency
+/// shows and an RGB capture cannot.
+fn writeCapturePpm(g: *Gui, gpa: std.mem.Allocator, pixels: []const u8, width: u32, height: u32, name: []const u8, alpha: bool) !void {
// A latency trace times frames, and an 8 MB file write per frame would
// stall the loop it is timing.
if (g.capture_dir.len == 0 or latency_fd >= 0) return;
@@ -5877,27 +5880,33 @@ fn writeCapturePpm(g: *Gui, gpa: std.mem.Allocator, pixels: []const u8, width: u
var tmp_buf: [4096]u8 = undefined;
var final_buf: [4096]u8 = undefined;
- const tmp_path = std.fmt.bufPrintSentinel(&tmp_buf, "{s}/{s}.ppm.tmp", .{ g.capture_dir, name }, 0) catch return error.CapturePathTooLong;
- const final_path = std.fmt.bufPrintSentinel(&final_buf, "{s}/{s}.ppm", .{ g.capture_dir, name }, 0) catch return error.CapturePathTooLong;
+ const ext = if (alpha) "pam" else "ppm";
+ const tmp_path = std.fmt.bufPrintSentinel(&tmp_buf, "{s}/{s}.{s}.tmp", .{ g.capture_dir, name, ext }, 0) catch return error.CapturePathTooLong;
+ const final_path = std.fmt.bufPrintSentinel(&final_buf, "{s}/{s}.{s}", .{ g.capture_dir, name, ext }, 0) catch return error.CapturePathTooLong;
const fd = libc.open(tmp_path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o644));
if (fd < 0) return error.CaptureWriteFailed;
defer _ = libc.close(fd);
- var header: [64]u8 = undefined;
- const hdr = std.fmt.bufPrint(&header, "P6\n{d} {d}\n255\n", .{ width, height }) catch unreachable; // two u32s fit 64
+ var header: [96]u8 = undefined;
+ const hdr = if (alpha)
+ std.fmt.bufPrint(&header, "P7\nWIDTH {d}\nHEIGHT {d}\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", .{ width, height }) catch unreachable // two u32s fit 96
+ else
+ std.fmt.bufPrint(&header, "P6\n{d} {d}\n255\n", .{ width, height }) catch unreachable; // two u32s fit 96
_ = host_io.writeFd(fd, hdr);
- const row_rgb = try gpa.alloc(u8, @as(usize, width) * 3);
+ const depth: usize = if (alpha) 4 else 3;
+ const row_rgb = try gpa.alloc(u8, @as(usize, width) * depth);
defer gpa.free(row_rgb);
for (0..height) |row| {
const src = pixels[row * width * 4 ..][0 .. @as(usize, width) * 4];
for (0..width) |x| {
const si = x * 4;
- const di = x * 3;
+ const di = x * depth;
row_rgb[di + 0] = src[si + if (bgr) @as(usize, 2) else 0];
row_rgb[di + 1] = src[si + 1];
row_rgb[di + 2] = src[si + if (bgr) @as(usize, 0) else 2];
+ if (alpha) row_rgb[di + 3] = src[si + 3];
}
_ = host_io.writeFd(fd, row_rgb);
}