summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 10:56:42 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch)
treec344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /src/gui
parentfc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff)
downloadpardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz
pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py. Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home. The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so. The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 537271f1..51ec6bbf 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1,3 +1,5 @@
+const SketchGpu = @import("sketch_gpu");
+const GpuScene = @import("gpu_scene");
const filesystem = @import("../fs.zig");
const std = @import("std");
const builtin = @import("builtin");
@@ -286,6 +288,7 @@ const ImageInstance = extern struct {
const opaque_bg_bit: u32 = 0x2000_0000;
const PreparedImage = struct {
+ premultiplied: bool = false,
place: pardes.Placement,
texture: *c.SDL_GPUTexture,
};
@@ -517,6 +520,11 @@ fn watchThread(fd: c_int, stop: c_int, q: *Queue) void {
}
const Gui = struct {
+ addon_gpu: ?SketchGpu = null,
+ addon_hash: [pardes.MAX_PANES]u64 = @splat(0),
+ addon_serial: [pardes.MAX_PANES]u32 = @splat(0),
+ addon_failed: [pardes.MAX_PANES]u64 = @splat(0),
+ addon_pipeline: ?*c.SDL_GPUGraphicsPipeline = null,
window: *c.SDL_Window,
device: *c.SDL_GPUDevice,
swapchain_format: c.SDL_GPUTextureFormat,
@@ -1229,6 +1237,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
defer g.glyphs.deinit();
defer g.words.deinit(gpa);
defer {
+ if (g.addon_gpu) |*gpu| gpu.deinit();
+ if (g.addon_pipeline) |pipeline_| c.SDL_ReleaseGPUGraphicsPipeline(device, pipeline_);
clearNativeImages(&g);
g.native_images.deinit(gpa);
g.prepared_images.deinit(gpa);
@@ -4378,6 +4388,7 @@ fn prepareNativeImages(
// The pictures are the page's: the other groups float over them.
for (surface.placements.items) |place|
if (texturePlacement(place)) appendPreparedImage(g, gpa, place);
+ prepareAddonGpu(g, gpa, cmd, surface);
groups.items[0].image_start = 0;
groups.items[0].image_count = std.math.cast(u32, g.prepared_images.items.len) orelse return false;
@@ -4425,6 +4436,7 @@ fn drawNativeImagesGpu(
var idx = batch.image_start;
const end = batch.image_start + batch.image_count;
for (g.prepared_images.items[batch.image_start..end]) |prepared| {
+ c.SDL_BindGPUGraphicsPipeline(pass, if (prepared.premultiplied) g.addon_pipeline.? else g.image_pipeline);
const clip = imageScissor(g, prepared.place);
if (clip.w > 0 and clip.h > 0) {
c.SDL_SetGPUScissor(pass, &clip);
@@ -9135,3 +9147,62 @@ test "detached trackpad scrolling keeps fractions local and queues whole rows fo
core.update(client.pending.items[0]);
try std.testing.expectEqual(@as(f32, 1.125), @as(f32, @floatFromInt(core.panes[id].?.scroll() - before)) + g.scroll_lag);
}
+
+/// Render addon scenes to textures on this device, before the page's pass.
+/// The fallback cells remain visible if decoding or pipeline creation fails.
+fn prepareAddonGpu(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, surface: *const pardes.Surface) void {
+ for (surface.gpu_frames, 0..) |maybe, id| {
+ const scratch: GpuScene.abi.Image = @fromBackingInt(@intCast(pardes.MAX_PANES + id + 1));
+ const frame = maybe orelse {
+ if (g.addon_gpu) |*gpu| {
+ gpu.forget(@fromBackingInt(@intCast(id + 1)));
+ gpu.forget(scratch);
+ }
+ g.addon_hash[id] = 0;
+ g.addon_serial[id] = 0;
+ g.addon_failed[id] = 0;
+ continue;
+ };
+ const hash = std.hash.Wyhash.hash(frame.serial, frame.bytes);
+ if (g.addon_failed[id] == hash) continue;
+ if (g.addon_gpu == null) g.addon_gpu = .init(gpa, g.device);
+ const gpu = &g.addon_gpu.?;
+ const target: GpuScene.abi.Image = @fromBackingInt(@intCast(id + 1));
+ if (g.addon_hash[id] != hash or g.addon_serial[id] != frame.serial) {
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var scene = GpuScene.decodeFrame(arena.allocator(), frame.bytes) catch |err| {
+ log.warn("addon GPU scene: {t}", .{err});
+ g.addon_failed[id] = hash;
+ continue;
+ };
+ scene.pass.image = if (scene.post != null) scratch else target;
+ gpu.record(cmd, scene.pass) catch |err| {
+ log.warn("addon GPU render: {t}", .{err});
+ g.addon_failed[id] = hash;
+ continue;
+ };
+ if (scene.post) |post| {
+ gpu.postProcess(cmd, scratch, target, post) catch |err| {
+ log.warn("addon GPU postprocess: {t}", .{err});
+ g.addon_failed[id] = hash;
+ continue;
+ };
+ } else gpu.forget(scratch);
+ g.addon_hash[id] = hash;
+ g.addon_serial[id] = frame.serial;
+ }
+ const out = gpu.output(target) orelse continue;
+ if (g.addon_pipeline == null) {
+ var blend = backgroundLayerBlend();
+ blend.src_color_blendfactor = c.SDL_GPU_BLENDFACTOR_ONE;
+ g.addon_pipeline = makePipeline(g.device, g.swapchain_format, image_vert_spv, image_frag_spv, 1, 1, image_input, blend) catch continue;
+ }
+ g.prepared_images.append(gpa, .{
+ .premultiplied = true,
+ .texture = out.texture,
+ .place = .{ .pane = @intCast(id), .raster = .{ .ptr = undefined, .w = out.width, .h = out.height, .stride = out.width * 4 }, .src = .{ .x = 0, .y = 0, .w = out.width, .h = out.height }, .dst = frame.dst, .key = hash },
+ }) catch {};
+ }
+ if (g.addon_gpu) |*gpu| gpu.endFrame();
+}