summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Output.zig23
-rw-r--r--src/ShaderBuild.zig427
-rw-r--r--src/builtins.zig27
-rw-r--r--src/config.zig229
-rw-r--r--src/effect_sources.zig98
-rw-r--r--src/exec.zig4
-rw-r--r--src/file_watch.zig13
-rw-r--r--src/fs.zig5
-rw-r--r--src/gui/Post.zig653
-rw-r--r--src/gui/gui.zig191
-rw-r--r--src/main.zig1
-rw-r--r--src/pardes.zig15
-rw-r--r--src/tape.zig2
13 files changed, 30 insertions, 1658 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 5a774d33..3c04aff8 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -9,7 +9,6 @@ const Pardes = pardes.Pardes;
const modal = @import("modal.zig");
const limits = @import("memory.zig").limits;
const builtins = @import("builtins.zig");
-const effect_sources = @import("effect_sources.zig");
const build_options = @import("pardes_config");
const lsp = @import("lsp/lsp.zig");
const look = @import("look.zig");
@@ -1022,28 +1021,6 @@ pub fn openChangelog(p: *Pardes, id: usize) !void {
return openRead(p, id, .{ .cmd = .Changelog }, "", content);
}
-pub fn openEffectCode(p: *Pardes, id: usize, argument: []const u8) !void {
- const name = std.mem.trim(u8, argument, " \t\r\n");
- const setting = config.Runtime.find(name) orelse return error.UnknownEffect;
- switch (setting.action) {
- .transition, .scene => {},
- else => return error.NotAnEffect,
- }
- if (!setting.enabled(builtins.viewCapabilities(p))) return error.EffectUnavailable;
- // Without -Dembed-sources the paths would name nothing this build can open.
- if (!limits.embedded_sources) return error.EffectUnavailable;
- const paths = effect_sources.forSetting(setting) orelse
- return error.EffectUnavailable;
-
- var out: std.Io.Writer.Allocating = .init(p.gpa);
- errdefer out.deinit();
- try out.writer.print("EffectCode {s} ({s})\n", .{ setting.word, @tagName(effect_sources.backend) });
- try out.writer.writeByte('\n');
- for (paths) |path| try out.writer.print("/virtual/{s}\n", .{path});
- const content = try out.toOwnedSlice();
- return openRead(p, id, .{ .cmd = .EffectCode }, setting.word, content);
-}
-
pub fn openErrors(p: *Pardes, id: usize, content: []u8) !void {
return openRead(p, id, .errors, "", content);
}
diff --git a/src/ShaderBuild.zig b/src/ShaderBuild.zig
deleted file mode 100644
index 74ec6826..00000000
--- a/src/ShaderBuild.zig
+++ /dev/null
@@ -1,427 +0,0 @@
-//! The post chain's Shadertoy files as SPIR-V (docs/render-pipeline.md §6),
-//! for the window that holds the core, which makes its pipelines from them.
-//! A window attached to a session elsewhere compiles none: it runs the
-//! bundled passes alone.
-//!
-//! Each file compiles behind the prefix by the build's own glslc invocation,
-//! on a thread of its own and never on the frame path, when it joins the
-//! chain and again whenever a save changes its bytes: the files' directories
-//! are watched (file_watch.watchShaders) and a change there has every file
-//! read and hashed, an unchanged one compiling nothing. A compile that fails
-//! keeps the last good SPIR-V and is said once, and glslc missing is said
-//! once for good.
-const std = @import("std");
-const libc = std.c;
-const pardes = @import("pardes.zig");
-const file_watch = @import("file_watch.zig");
-
-const Build = @This();
-const Chain = pardes.config.Runtime.Post;
-const Scene = pardes.config.Runtime.Scene;
-pub const max = Chain.max;
-
-const prefix = @embedFile("post-prefix.glsl");
-
-/// A pass as a shell draws it: a bundled scene at its level, or a file with
-/// its last good SPIR-V (empty until a compile succeeds), whose `revision`
-/// moves each time that SPIR-V does. Slices borrow the build's storage
-/// until its next change.
-pub const Pass = struct {
- scene: ?Scene = null,
- level: u8 = 0,
- path: []const u8 = &.{},
- spirv: []const u8 = &.{},
- revision: u32 = 0,
- /// It moves on its own (reads the clock or the frame count), so the
- /// chain redraws while idle; a still pass draws only with a new frame.
- animated: bool = false,
-};
-
-/// The bundled passes that move on their own: the CRT's hum and dither.
-pub fn sceneAnimated(scene: Scene) bool {
- return scene == .crt;
-}
-
-/// Whether a Shadertoy source moves on its own: it reads the time
-/// (iTime, iTimeDelta and the times of a cursor move or a focus change),
-/// the frame count or the date. A mention in a comment counts too.
-pub fn readsTime(source: []const u8) bool {
- for ([_][]const u8{ "iTime", "iFrame", "iDate" }) |name| if (std.mem.indexOf(u8, source, name) != null) return true;
- return false;
-}
-
-/// Who to wake when a compile is done: the host's loop.
-pub const Wake = ?*const fn (?*anyopaque) void;
-
-const File = struct {
- path: []u8 = &.{},
- /// The hash of the source last compiled, good or not: the same bytes
- /// saved again compile nothing and say nothing twice.
- source: ?u64 = null,
- spirv: []u8 = &.{},
- revision: u32 = 0,
- animated: bool = false,
- /// Wants a compile: new to the chain, or its directory changed.
- stale: bool = true,
-};
-
-const Result = union(enum) {
- none,
- unchanged,
- missing,
- failed: struct { text: []u8, source: u64 },
- spirv: struct { bytes: []u8, source: u64, animated: bool },
-};
-
-/// One compile of the stale files, a task of its own: `deinit` cancels it
-/// (glslc's wait is a cancelation point) rather than waiting out a glslc.
-const Job = struct {
- io: std.Io,
- gpa: std.mem.Allocator,
- wake: Wake,
- paths: [max][]u8 = @splat(&.{}),
- known: [max]?u64 = @splat(null),
- results: [max]Result = @splat(.none),
- len: usize = 0,
- done: std.atomic.Value(bool) = .init(false),
- /// Set before the cancel: the files after the one it stopped are not
- /// compiled either (a cancel is said once, to the wait it lands in).
- stop: std.atomic.Value(bool) = .init(false),
- future: std.Io.Future(void) = undefined,
-};
-
-files: [max]File = @splat(.{}),
-len: usize = 0,
-/// The chain generation `files` follow; null before the first.
-generation: ?u32 = null,
-/// Moves whenever what `view` gives does: the chain or a file's SPIR-V.
-revision: u32 = 0,
-job: ?*Job = null,
-missing_said: bool = false,
-
-/// Brings the files to the chain the core holds, watches their directories,
-/// takes in a finished compile and starts the next. Each loop step, off the
-/// frame path. True when a compile was taken in: what it said wants a frame.
-pub fn sync(b: *Build, gpa: std.mem.Allocator, io: std.Io, core: *pardes.Pardes, fd: c_int, watches: *file_watch.Table, wake: Wake) bool {
- var collected = false;
- if (b.job) |job| {
- if (!job.done.load(.acquire)) return false;
- job.future.await(job.io);
- b.job = null;
- b.collect(gpa, core, job);
- collected = true;
- }
- const chain = &core.settings.post;
- if (b.generation != chain.generation) {
- b.generation = chain.generation;
- b.revision +%= 1;
- var next: [max]File = @splat(.{});
- var len: usize = 0;
- var paths: [max][]const u8 = undefined;
- for (chain.list()) |entry| {
- if (entry.scene != null) continue;
- next[len] = for (b.files[0..b.len]) |*file| {
- if (!std.mem.eql(u8, file.path, entry.path.get())) continue;
- const kept = file.*;
- file.* = .{};
- break kept;
- } else .{ .path = gpa.dupe(u8, entry.path.get()) catch continue };
- paths[len] = next[len].path;
- len += 1;
- }
- for (b.files[0..b.len]) |file| free(gpa, file);
- b.files = next;
- b.len = len;
- var bufs: [max][4096]u8 = undefined;
- var expanded: [max][]const u8 = undefined;
- for (paths[0..len], 0..) |path, i| expanded[i] = pardes.filesystem.expandHome(path, &bufs[i]);
- file_watch.watchShaders(fd, watches, expanded[0..len]);
- }
- var stale = false;
- for (b.files[0..b.len]) |file| stale = stale or file.stale;
- if (!stale) return collected;
- const job = gpa.create(Job) catch return collected;
- job.* = .{ .io = io, .gpa = gpa, .wake = wake };
- for (b.files[0..b.len]) |*file| {
- if (!file.stale) continue;
- job.paths[job.len] = gpa.dupe(u8, file.path) catch continue;
- job.known[job.len] = file.source;
- job.len += 1;
- file.stale = false;
- }
- job.future = io.concurrent(compile, .{job}) catch {
- for (job.paths[0..job.len]) |path| gpa.free(path);
- gpa.destroy(job);
- return collected;
- };
- b.job = job;
- return collected;
-}
-
-/// A watched directory changed: every file is read again at the next sync.
-pub fn recheck(b: *Build) void {
- for (b.files[0..b.len]) |*file| file.stale = true;
-}
-
-/// The chain as passes, in its order.
-pub fn view(b: *const Build, chain: *const Chain, out: *[max]Pass) []const Pass {
- for (chain.list(), 0..) |entry, i| {
- out[i] = if (entry.scene) |scene| .{ .scene = scene, .level = entry.level, .animated = sceneAnimated(scene) } else for (b.files[0..b.len]) |file| {
- if (std.mem.eql(u8, file.path, entry.path.get())) break .{ .path = file.path, .spirv = file.spirv, .revision = file.revision, .animated = file.animated };
- } else .{ .path = entry.path.get() };
- }
- return out[0..chain.len];
-}
-
-pub fn deinit(b: *Build, gpa: std.mem.Allocator, fd: c_int, watches: *file_watch.Table) void {
- if (b.job) |job| {
- job.stop.store(true, .release);
- job.future.cancel(job.io);
- freeJob(gpa, job);
- }
- for (b.files[0..b.len]) |file| free(gpa, file);
- b.len = 0;
- file_watch.watchShaders(fd, watches, &.{});
-}
-
-fn free(gpa: std.mem.Allocator, file: File) void {
- gpa.free(file.path);
- gpa.free(file.spirv);
-}
-
-fn freeJob(gpa: std.mem.Allocator, job: *Job) void {
- for (job.paths[0..job.len], job.results[0..job.len]) |path, result| {
- gpa.free(path);
- switch (result) {
- .spirv => |r| gpa.free(r.bytes),
- .failed => |r| gpa.free(r.text),
- .none, .unchanged, .missing => {},
- }
- }
- gpa.destroy(job);
-}
-
-fn collect(b: *Build, gpa: std.mem.Allocator, core: *pardes.Pardes, job: *Job) void {
- defer gpa.destroy(job);
- for (job.paths[0..job.len], job.results[0..job.len]) |path, result| {
- defer gpa.free(path);
- const file = for (b.files[0..b.len]) |*file| {
- if (std.mem.eql(u8, file.path, path)) break file;
- } else null;
- var buf: [512]u8 = undefined;
- switch (result) {
- .none, .unchanged => {},
- .missing => if (!b.missing_said) {
- b.missing_said = true;
- core.setMessage(core.active, "Shader: glslc is not on PATH, so Shadertoy files do not run (Crt does)");
- },
- .failed => |r| {
- defer gpa.free(r.text);
- if (file) |f| f.source = r.source;
- // glslc's first line says where: in the file's own lines.
- const first = std.mem.sliceTo(r.text, '\n');
- core.setMessage(core.active, std.fmt.bufPrint(&buf, "Shader {s}: {s}", .{ path, first[0..@min(first.len, 400)] }) catch "Shader: compile failed");
- },
- .spirv => |r| {
- const f = file orelse {
- gpa.free(r.bytes);
- continue;
- };
- gpa.free(f.spirv);
- f.spirv = r.bytes;
- f.source = r.source;
- f.animated = r.animated;
- f.revision +%= 1;
- b.revision +%= 1;
- },
- }
- }
-}
-
-/// The compile thread: each file behind the prefix, through glslc with the
-/// build's own flags (build.zig compileGlsl), source on stdin, SPIR-V on
-/// stdout.
-fn compile(job: *Job) void {
- for (job.paths[0..job.len], 0..) |path, i| {
- if (job.stop.load(.acquire)) break;
- job.results[i] = compileOne(job.gpa, job.io, path, job.known[i]);
- }
- job.done.store(true, .release);
- if (job.wake) |wake| wake(null);
-}
-
-fn compileOne(gpa: std.mem.Allocator, io: std.Io, path: []const u8, known: ?u64) Result {
- var home_buf: [4096]u8 = undefined;
- // Not fs.zig's readFile: that hands the core's turn over for the read,
- // a turn this thread never holds.
- const body = std.Io.Dir.cwd().readFileAlloc(io, pardes.filesystem.expandHome(path, &home_buf), gpa, .limited(1 << 20)) catch |err|
- return .{ .failed = .{ .text = std.fmt.allocPrint(gpa, "cannot read it ({t})", .{err}) catch return .none, .source = 0 } };
- defer gpa.free(body);
- const source = std.hash.Wyhash.hash(0, body);
- if (known == source) return .unchanged;
- // The prefix and the file go to glslc on its stdin: no file of ours is
- // written anywhere. std's spawn does every allocation before fork and
- // searches PATH on the stack after it (Io/Threaded.zig spawnPosix,
- // posixExecv), so a child forked from this thread cannot wedge on a
- // lock another thread held (the forkShell hazard).
- var child = std.process.spawn(io, .{
- .argv = &.{ "glslc", "-fshader-stage=fragment", "-o", "-", "-" },
- .stdin = .pipe,
- .stdout = .pipe,
- .stderr = .pipe,
- }) catch |err| return switch (err) {
- error.FileNotFound => .missing,
- else => .{ .failed = .{ .text = std.fmt.allocPrint(gpa, "glslc did not run ({t})", .{err}) catch return .none, .source = source } },
- };
- defer child.kill(io);
- // glslc reads all of its input before it writes a byte, so writing it
- // first cannot deadlock against a full output pipe.
- {
- var stdin = child.stdin.?;
- child.stdin = null;
- defer stdin.close(io);
- var buf: [4096]u8 = undefined;
- var writer = stdin.writer(io, &buf);
- writer.interface.writeAll(prefix) catch {};
- writer.interface.writeAll(body) catch {};
- writer.interface.flush() catch {};
- }
- var streams: std.Io.File.MultiReader.Buffer(2) = undefined;
- var reader: std.Io.File.MultiReader = undefined;
- reader.init(gpa, io, streams.toStreams(), &.{ child.stdout.?, child.stderr.? });
- defer reader.deinit();
- const failed = struct {
- fn of(a: std.mem.Allocator, text: []const u8, hash: u64) Result {
- return .{ .failed = .{ .text = a.dupe(u8, text) catch return .none, .source = hash } };
- }
- }.of;
- while (reader.fill(64, .none)) |_| {
- if (reader.reader(0).buffered().len > 16 << 20 or reader.reader(1).buffered().len > 64 << 10)
- return failed(gpa, "glslc said too much", source);
- } else |err| switch (err) {
- error.EndOfStream => {},
- else => return failed(gpa, "reading glslc failed", source),
- }
- const term = child.wait(io) catch return failed(gpa, "glslc did not finish", source);
- const clean = switch (term) {
- .exited => |code| code == 0,
- else => false,
- };
- if (clean) return .{ .spirv = .{ .bytes = reader.toOwnedSlice(0) catch return .none, .source = source, .animated = readsTime(body) } };
- const said = reader.toOwnedSlice(1) catch return .none;
- // glslc calls its input <stdin>; the file is what a person knows.
- defer gpa.free(said);
- const named = std.mem.replaceOwned(u8, gpa, said, "<stdin>", path) catch return failed(gpa, "glslc failed", source);
- return .{ .failed = .{ .text = named, .source = source } };
-}
-
-test "ghostty's test shaders compile behind the prefix, and its invalid one fails with glslc's words" {
- const gpa = std.testing.allocator;
- const io = std.testing.io;
- // ghostty's own test shaders, from its package in zig-pkg.
- var pkg = std.Io.Dir.cwd().openDir(io, "zig-pkg", .{ .iterate = true }) catch return error.SkipZigTest;
- defer pkg.close(io);
- var it = pkg.iterate();
- const ghostty = while (it.next(io) catch null) |entry| {
- if (std.mem.startsWith(u8, entry.name, "ghostty-")) break entry.name;
- } else return error.SkipZigTest;
- var buf: [512]u8 = undefined;
- for ([_][]const u8{ "crt", "focus", "invalid" }) |name| {
- const path = try std.fmt.bufPrint(&buf, "zig-pkg/{s}/src/renderer/shaders/test_shadertoy_{s}.glsl", .{ ghostty, name });
- switch (compileOne(gpa, io, path, null)) {
- .missing => return error.SkipZigTest, // no glslc here
- .spirv => |r| {
- defer gpa.free(r.bytes);
- try std.testing.expect(!std.mem.eql(u8, name, "invalid"));
- // SPIR-V's magic number, little-endian.
- try std.testing.expectEqual(@as(u32, 0x07230203), std.mem.readInt(u32, r.bytes[0..4], .little));
- // The same bytes again compile nothing.
- try std.testing.expectEqual(Result.unchanged, compileOne(gpa, io, path, r.source));
- },
- .failed => |r| {
- defer gpa.free(r.text);
- try std.testing.expectEqualStrings("invalid", name);
- // Named by the file, not by glslc's <stdin>.
- try std.testing.expect(std.mem.indexOf(u8, r.text, path) != null);
- try std.testing.expect(std.mem.indexOf(u8, r.text, "<stdin>") == null);
- },
- .none, .unchanged => return error.TestUnexpectedResult,
- }
- }
-}
-
-test "a save that changes a file compiles it again, a failed one keeps the last good SPIR-V and is said once" {
- const gpa = std.testing.allocator;
- const io = std.testing.io;
- const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
- defer core.deinit();
- _ = try core.newShell(1, "");
- const pane = core.panes[core.active].?;
- var tmp = std.testing.tmpDir(.{});
- defer tmp.cleanup();
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(io, &dir_buf)];
- var path_buf: [4200]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "{s}/wave.glsl", .{dir});
- const good = "void mainImage(out vec4 o, in vec2 p) { o = texture(iChannel0, p / iResolution.xy); }\n";
- try tmp.dir.writeFile(io, .{ .sub_path = "wave.glsl", .data = good });
- try std.testing.expect(core.settings.post.set(null, path, true));
-
- const fd = file_watch.init(true);
- defer if (fd >= 0) {
- _ = libc.close(fd);
- };
- var watches: file_watch.Table = @splat(null);
- var b: Build = .{};
- defer b.deinit(gpa, fd, &watches);
- const settle = struct {
- fn run(build: *Build, c: *pardes.Pardes, f: c_int, w: *file_watch.Table) void {
- _ = build.sync(std.testing.allocator, std.testing.io, c, f, w, null);
- while (build.job) |job| {
- job.future.await(std.testing.io);
- job.done.store(true, .release);
- _ = build.sync(std.testing.allocator, std.testing.io, c, f, w, null);
- }
- }
- }.run;
- settle(&b, core, fd, &watches);
- if (b.missing_said) return error.SkipZigTest; // no glslc here
- var out: [max]Pass = undefined;
- const first = b.view(&core.settings.post, &out)[0];
- try std.testing.expect(first.spirv.len != 0);
- if (file_watch.supported) try std.testing.expect(watches[file_watch.shader_slot] != null);
-
- // Unchanged bytes: nothing moves.
- const at = b.revision;
- b.recheck();
- settle(&b, core, fd, &watches);
- try std.testing.expectEqual(at, b.revision);
-
- // A bad save: the last good SPIR-V stays, the error is said, and the
- // same bad bytes again say nothing more.
- try tmp.dir.writeFile(io, .{ .sub_path = "wave.glsl", .data = "void mainImage(" });
- pane.msg_len = 0;
- b.recheck();
- settle(&b, core, fd, &watches);
- try std.testing.expectEqual(at, b.revision);
- try std.testing.expect(std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Shader "));
- pane.msg_len = 0;
- b.recheck();
- settle(&b, core, fd, &watches);
- try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
-
- // A good save again: new SPIR-V, a new revision.
- try tmp.dir.writeFile(io, .{ .sub_path = "wave.glsl", .data = "// saved again\n" ++ good });
- b.recheck();
- settle(&b, core, fd, &watches);
- const second = b.view(&core.settings.post, &out)[0];
- try std.testing.expect(second.revision != first.revision and b.revision != at);
-}
-
-test "a pass animates when it reads the clock or the frame count, and only the CRT of the bundled ones" {
- try std.testing.expect(readsTime("o = vec4(sin(iTime));"));
- try std.testing.expect(readsTime("float f = float(iFrame % 64);"));
- try std.testing.expect(readsTime("x = iTimeCursorChange;"));
- try std.testing.expect(!readsTime("o = texture(iChannel0, p / iResolution.xy);"));
- for (std.enums.values(Scene)) |scene| try std.testing.expectEqual(scene == .crt, sceneAnimated(scene));
-}
diff --git a/src/builtins.zig b/src/builtins.zig
index 0295130d..c7b427f5 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -18,7 +18,6 @@ const limits = @import("memory.zig").limits;
pub const frontend: config.Runtime.Capabilities = .{
.font_picker = pardes.font_picker,
.panel_transitions = true,
- .scene_shaders = pardes.platform == .gui or pardes.platform == .macos,
// The tty's font belongs to its emulator.
.tagline_font_size = pardes.platform != .tui,
.window_opacity = pardes.platform == .gui or pardes.platform == .macos,
@@ -35,8 +34,8 @@ pub const frontend: config.Runtime.Capabilities = .{
/// its own frontend does (`viewCapabilities`), so a terminal's replica of a
/// window's session steps as the window's own does, and back.
pub const desktop = pardes.platform == .tui or pardes.platform == .gui;
-const window_capabilities: config.Runtime.Capabilities = .{ .font_picker = true, .panel_transitions = true, .scene_shaders = true, .tagline_font_size = true, .window_opacity = true, .window_blur = false, .ligatures = true, .lift = true };
-const terminal_capabilities: config.Runtime.Capabilities = .{ .font_picker = false, .panel_transitions = true, .scene_shaders = false, .tagline_font_size = false, .window_opacity = false, .window_blur = false, .ligatures = false, .lift = false };
+const window_capabilities: config.Runtime.Capabilities = .{ .font_picker = true, .panel_transitions = true, .tagline_font_size = true, .window_opacity = true, .window_blur = false, .ligatures = true, .lift = true };
+const terminal_capabilities: config.Runtime.Capabilities = .{ .font_picker = false, .panel_transitions = true, .tagline_font_size = false, .window_opacity = false, .window_blur = false, .ligatures = false, .lift = false };
/// The words this build has: a desktop build's are the window's.
pub const capabilities: config.Runtime.Capabilities = if (desktop) window_capabilities else frontend;
@@ -245,8 +244,8 @@ pub const registry = struct {
if (@backingInt(b) == i) return switch (setting.action) {
// a switch flips bare, a choice steps, and DumpDir and Shell bare
// are the default
- .toggle, .transition, .scene, .dump_dir, .choice, .lift, .shader_animation, .motion, .shell => false,
- .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .shader, .inactive_dim, .grip_width => true,
+ .toggle, .transition, .dump_dir, .choice, .lift, .motion, .shell => false,
+ .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .inactive_dim, .grip_width => true,
// bare, it says the current value (exec.applySettingBuiltin)
.tab, .callstack_depth, .search_rows => false,
};
@@ -277,14 +276,12 @@ pub const registry = struct {
}
};
-test "capabilities exactly gate setting and effect-source builtins" {
+test "capabilities exactly gate setting builtins" {
const Builtin = registry.Builtin();
for (config.Runtime.settings) |setting| {
const registered = std.meta.stringToEnum(Builtin, setting.word) != null;
try std.testing.expectEqual(setting.enabled(capabilities), registered);
}
- const effect_code_registered = std.meta.stringToEnum(Builtin, "EffectCode") != null;
- try std.testing.expectEqual(EffectCode.enabled, effect_code_registered);
}
test "a builtin's scope is the pane unless it says session, and every setting is the session's" {
@@ -1635,20 +1632,6 @@ pub const Changelog = struct {
}
};
-/// Open the source of a panel transition or post shader, by name.
-pub const EffectCode = struct {
- pub const scope: Scope = .session;
- pub const takes_arg = true;
- pub const requires_arg = true;
- pub const enabled = capabilities.panel_transitions or capabilities.scene_shaders;
- pub const gui_only = true;
- pub const output: OutputTraits = .{ .name = config.effect_code_buffer };
- pub fn run(c: Ctx) void {
- panes.Output.openEffectCode(c.p, c.id, c.arg orelse return) catch |err|
- c.p.reportError(c.id, "effect code", err);
- }
-};
-
/// An optional SDL workspace-tag companion; never consumes input or text cells.
pub const Pet = struct {
pub const scope: Scope = .session;
diff --git a/src/config.zig b/src/config.zig
index b12630e9..9394f912 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -193,15 +193,6 @@ pub const leader_path = paths: {
table.set(.PanelScramble, "ar");
table.set(.PanelType, "at");
}
- if (builtins.capabilities.scene_shaders) {
- table.set(.Crt, "tr");
- table.set(.Bloom, null);
- table.set(.Vignette, null);
- table.set(.Grain, null);
- table.set(.Shader, null);
- table.set(.ShaderAnimation, null);
- }
- if (builtins.EffectCode.enabled) table.set(.EffectCode, null);
if (builtins.TreeContext.enabled) table.set(.TreeContext, null);
table.set(.ThemeFile, null);
table.set(.DumpThemes, null);
@@ -544,7 +535,6 @@ pub const pipe_marker = " |";
pub const search_buffer = "+Search";
pub const help_buffer = "+Help";
pub const dump_config_buffer = "+DumpConfig";
-pub const effect_code_buffer = "+EffectCode";
pub const jumps_buffer = "+Jumps";
pub const preview_buffer = "+Preview";
pub const unsaved_buffer = "+Unsaved";
@@ -825,12 +815,6 @@ pub const Runtime = struct {
} = .{},
panel_transition: animation.Transition = .off,
- /// The post chain (docs/render-pipeline.md §6), in the order it runs.
- post: Post = .{},
- /// When the chain redraws on its own, past the frames it post-processes:
- /// never, while the window has the focus, or always (ghostty's
- /// custom-shader-animation).
- shader_animation: ShaderAnimation = .on,
/// What a terminal's shell pages through (host_io.ChildEnv): `pardes`,
/// PAGER and GIT_PAGER set to `pardes -`, a +Pager pane, where the
/// user's environment set neither; `off`, the environment as it is.
@@ -860,7 +844,6 @@ pub const Runtime = struct {
/// +Preview with): it never resizes itself after.
search_rows: u16 = 8,
- pub const ShaderAnimation = enum { off, on, always };
pub const Pager = enum { pardes, off };
pub const TermImages = enum { real, petscii };
pub const JumpScope = enum { file, all };
@@ -879,81 +862,6 @@ pub const Runtime = struct {
/// sets 35), not so much that they stop being worth reading.
pub const auto_dim: u8 = 30;
- /// Each pass the bundled Crt or a Shadertoy file.
- pub const Post = struct {
- pub const max = 8;
- pub const Entry = struct {
- scene: ?Scene = null,
- path: Text(limits.host_path_cap) = .{},
- /// A bundled pass's strength, 1 to `max_level`; 0 for a file.
- level: u8 = 0,
- };
- pub const max_level = 3;
- /// What `on` and a bare word turn a bundled pass on at.
- pub const default_level = 2;
- entries: [max]Entry = @splat(.{}),
- len: u8 = 0,
- /// Bumped on every change: a shell compiles the chain again when it
- /// moves.
- generation: u32 = 0,
-
- pub fn list(post: *const Post) []const Entry {
- return post.entries[0..post.len];
- }
-
- pub fn has(post: *const Post, scene: Scene) bool {
- return post.level(scene) != 0;
- }
-
- /// A bundled pass's level; 0 when it is not in the chain.
- pub fn level(post: *const Post, scene: Scene) u8 {
- for (post.list()) |entry| if (entry.scene == scene) return entry.level;
- return 0;
- }
-
- /// Sets a bundled pass's level: 0 takes it out, anything else puts it
- /// in at the end or changes it where it is.
- pub fn setLevel(post: *Post, scene: Scene, to: u8) bool {
- std.debug.assert(to <= max_level);
- if (to == 0) return post.set(scene, "", false);
- for (post.entries[0..post.len]) |*entry| if (entry.scene == scene) {
- if (entry.level != to) post.generation +%= 1;
- entry.level = to;
- return true;
- };
- if (!post.set(scene, "", true)) return false;
- post.entries[post.len - 1].level = to;
- return true;
- }
-
- /// Puts the pass in the chain, at its end, or takes it out; `want`
- /// null flips it. False when the chain is full or the path too long.
- pub fn set(post: *Post, scene: ?Scene, path: []const u8, want: ?bool) bool {
- const at: ?usize = for (post.list(), 0..) |entry, i| {
- if (entry.scene == scene and std.mem.eql(u8, entry.path.get(), path)) break i;
- } else null;
- const on = want orelse (at == null);
- if (on == (at != null)) return true;
- post.generation +%= 1;
- if (at) |i| {
- std.mem.copyForwards(Entry, post.entries[i .. post.len - 1], post.entries[i + 1 .. post.len]);
- post.len -= 1;
- return true;
- }
- if (post.len == max) return false;
- post.entries[post.len] = .{ .scene = scene };
- if (!post.entries[post.len].path.set(path)) return false;
- post.len += 1;
- return true;
- }
-
- pub fn clear(post: *Post) void {
- if (post.len == 0) return;
- post.len = 0;
- post.generation +%= 1;
- }
- };
-
pub const tagline_percent_min: u8 = 1;
pub const tagline_percent_max: u8 = 100;
@@ -1012,7 +920,6 @@ pub const Runtime = struct {
pub const Capabilities = struct {
font_picker: bool,
panel_transitions: bool,
- scene_shaders: bool,
tagline_font_size: bool,
window_opacity: bool = false,
window_blur: bool = false,
@@ -1028,9 +935,6 @@ pub const Runtime = struct {
pub const MessageTime = enum { linger, fall, dissolve };
pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, pager_color, verbose, message_animation, ligatures, cursor_blink, selection_glow, hover_glow, occlusion, parallax, jump_trail, chip_shadow, thumb_flash, program_esc };
- /// A bundled post pass, a Shadertoy file in shaders/post/: the CRT, and
- /// G4's bloom, vignette and grain (docs/effects.md).
- pub const Scene = enum { crt, bloom, vignette, grain };
pub const Action = union(enum) {
toggle: Toggle,
@@ -1053,11 +957,6 @@ pub const Runtime = struct {
callstack_depth,
search_rows,
transition: animation.Transition,
- scene: Scene,
- /// A Shadertoy file into the post chain or out of it; `off` empties
- /// it of files.
- shader,
- shader_animation,
choice: Choice,
};
@@ -1084,7 +983,6 @@ pub const Runtime = struct {
.window_opacity => .window_opacity,
.window_blur => .window_blur,
.transition => .panel_transitions,
- .scene, .shader, .shader_animation => .scene_shaders,
.lift, .grip_width => .lift,
.toggle => |field| switch (field) {
.ligatures => .ligatures,
@@ -1141,12 +1039,6 @@ pub const Runtime = struct {
.{ .word = "PanelCurtain", .action = .{ .transition = .curtain }, .doc = "Panes open and close like a curtain, on or off." },
.{ .word = "PanelScramble", .action = .{ .transition = .scramble }, .doc = "Panes open and close through scrambled text, on or off." },
.{ .word = "PanelType", .action = .{ .transition = .typewriter }, .doc = "Panes type themselves in as they open, on or off." },
- .{ .word = "Crt", .action = .{ .scene = .crt }, .doc = "The bundled CRT post pass over the window, on or off." },
- .{ .word = "Bloom", .action = .{ .scene = .bloom }, .doc = "The brightest ink glows a little: a level, 0 (off) through 3." },
- .{ .word = "Vignette", .action = .{ .scene = .vignette }, .doc = "The window's corners fall into shade: a level, 0 (off) through 3." },
- .{ .word = "Grain", .action = .{ .scene = .grain }, .doc = "The page takes a fine, still grain, like paper: a level, 0 (off) through 3." },
- .{ .word = "Shader", .action = .shader, .doc = "A Shadertoy file into the post chain, or out of it, compiled again when saved; off empties the chain." },
- .{ .word = "ShaderAnimation", .action = .shader_animation, .doc = "When the post chain animates on its own: off, on (while focused) or always." },
.{ .word = "Pager", .action = .{ .choice = .pager }, .doc = "What a terminal's commands page through: pardes, a +Pager pane (pardes -), or off, the environment's own; for terminals started after it." },
.{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." },
.{ .word = "TermImages", .action = .{ .choice = .term_images }, .doc = "How a new terminal draws its program's kitty graphics: real, as pixels where it can, or petscii, as glyph art." },
@@ -1191,12 +1083,6 @@ pub const Runtime = struct {
if (actionCount(.{ .transition = effect }) != expected)
@compileError("non-off panel transition must occur exactly once: " ++ @tagName(effect));
}
- for (std.enums.values(Scene)) |effect| {
- if (actionCount(.{ .scene = effect }) != 1)
- @compileError("scene effect must occur exactly once: " ++ @tagName(effect));
- }
- if (actionCount(.shader) != 1 or actionCount(.shader_animation) != 1)
- @compileError("Shader and ShaderAnimation must each occur exactly once");
}
pub fn apply(state: *Runtime, setting: Setting, argument: ?[]const u8) bool {
@@ -1254,35 +1140,6 @@ pub const Runtime = struct {
state.panel_transition = .off;
}
},
- .scene => |effect| {
- // A level, 0 (off) to 3; `on` is the default level, `off` 0,
- // and bare flips between the two.
- const text = std.mem.trim(u8, argument orelse "", " \t\r\n");
- const to: u8 = if (text.len == 0)
- (if (state.post.has(effect)) 0 else Post.default_level)
- else if (std.mem.eql(u8, text, "on"))
- Post.default_level
- else if (std.mem.eql(u8, text, "off"))
- 0
- else
- std.fmt.parseInt(u8, text, 10) catch return false;
- if (to > Post.max_level) return false;
- return state.post.setLevel(effect, to);
- },
- .shader => {
- const path = std.mem.trim(u8, argument orelse return false, " \t\r\n");
- if (path.len == 0) return false;
- if (std.mem.eql(u8, path, "off")) {
- var i: usize = 0;
- while (i < state.post.len) {
- const entry = state.post.entries[i];
- if (entry.scene == null) _ = state.post.set(null, entry.path.get(), false) else i += 1;
- }
- return true;
- }
- return state.post.set(null, path, null);
- },
- .shader_animation => state.shader_animation = stepped(ShaderAnimation, state.shader_animation, argument) orelse return false,
// Bare, it steps to the next word, as a tag word should.
.choice => |which| switch (which) {
inline else => |field| {
@@ -1328,8 +1185,6 @@ pub const Runtime = struct {
},
.lift => "on, " ++ comptime words.of(LiftStyle),
.motion => comptime words.of(animation.Motion.Flavour),
- .scene => std.fmt.comptimePrint("on, off, 0-{d}", .{Post.max_level}),
- .shader_animation => comptime words.of(ShaderAnimation),
else => null,
};
}
@@ -1347,7 +1202,6 @@ pub const Runtime = struct {
.message_ms => std.fmt.comptimePrint("0-{d} (milliseconds)", .{message_ms_max}),
.shell => "a path of at most 255 bytes; bare, $SHELL, else /bin/sh",
.dump_dir => std.fmt.comptimePrint("an absolute or ~ path of at most {d} bytes, to a directory that may be written; bare, the default", .{limits.host_path_cap}),
- .shader => "a Shadertoy file's path, or off",
.font => "a name or path, :8 to :72 after it (Mono:14)",
else => null,
};
@@ -1463,19 +1317,6 @@ pub const Runtime = struct {
.tagline_size => try out.print("{s} {d}\n", .{ setting.word, state.font.tagline_percent }),
// Each a switch of its own, the one in use on.
.transition => |transition| try out.print("{s} {s}\n", .{ setting.word, onOff(state.panel_transition == transition) }),
- .scene => |effect| {
- const level = state.post.level(effect);
- if (level == 0) try out.print("{s} off\n", .{setting.word}) else try out.print("{s} {d}\n", .{ setting.word, level });
- },
- .shader => {
- var files: usize = 0;
- for (state.post.list()) |entry| if (entry.scene == null) {
- try out.print("{s} {s}\n", .{ setting.word, entry.path.get() });
- files += 1;
- };
- if (files == 0) try out.print("{s} off\n", .{setting.word});
- },
- .shader_animation => try out.print("{s} {s}\n", .{ setting.word, @tagName(state.shader_animation) }),
.choice => |which| switch (which) {
inline else => |field| try out.print("{s} {s}\n", .{ setting.word, @tagName(@field(state, @tagName(field))) }),
},
@@ -1517,7 +1358,7 @@ pub const Runtime = struct {
try out.print("# Pet: {s}\n", .{@tagName(state.pet)});
}
- test "panel and scene effects flip bare and are set by on and off" {
+ test "panel effects flip bare and are set by on and off" {
var state: Runtime = .{};
const slide = findAction(.{ .transition = .slide }).?;
const zoom = findAction(.{ .transition = .zoom }).?;
@@ -1530,10 +1371,6 @@ pub const Runtime = struct {
try std.testing.expect(apply(&state, slide, null));
try std.testing.expectEqual(animation.Transition.off, state.panel_transition);
try std.testing.expect(!apply(&state, slide, "yes"));
- const scene = findAction(.{ .scene = std.enums.values(Scene)[0] }).?;
- try std.testing.expect(apply(&state, scene, "on"));
- try std.testing.expect(apply(&state, scene, "on"));
- try std.testing.expect(state.post.has(std.enums.values(Scene)[0]));
}
test "a toggle flips when bare and sets when told on or off" {
@@ -1569,53 +1406,6 @@ pub const Runtime = struct {
try std.testing.expectEqual(animation.Transition.ascii, state.panel_transition);
try std.testing.expect(apply(&state, find("PanelAscii").?, null));
try std.testing.expectEqual(animation.Transition.off, state.panel_transition);
- try std.testing.expect(apply(&state, find("Crt").?, null));
- try std.testing.expect(state.post.has(.crt));
- }
-
- test "the post chain runs in the order its passes were put in, and Shader off empties it of files" {
- var state: Runtime = .{};
- try std.testing.expect(apply(&state, find("Shader").?, " ~/a.glsl\n"));
- try std.testing.expect(apply(&state, find("Crt").?, "on"));
- try std.testing.expect(apply(&state, find("Shader").?, "/b.glsl"));
- const chain = state.post.list();
- try std.testing.expectEqual(@as(usize, 3), chain.len);
- try std.testing.expectEqualStrings("~/a.glsl", chain[0].path.get());
- try std.testing.expectEqual(Scene.crt, chain[1].scene.?);
- try std.testing.expectEqualStrings("/b.glsl", chain[2].path.get());
- const moved = state.post.generation;
- // A file named again leaves; the others keep their order.
- try std.testing.expect(apply(&state, find("Shader").?, "~/a.glsl"));
- try std.testing.expect(state.post.generation != moved);
- try std.testing.expectEqual(Scene.crt, state.post.list()[0].scene.?);
- try std.testing.expect(apply(&state, find("Shader").?, "off"));
- try std.testing.expectEqual(@as(usize, 1), state.post.len);
- try std.testing.expect(!apply(&state, find("Shader").?, null));
- try std.testing.expect(apply(&state, find("ShaderAnimation").?, "always"));
- try std.testing.expectEqual(ShaderAnimation.always, state.shader_animation);
- try std.testing.expect(!apply(&state, find("ShaderAnimation").?, "sometimes"));
- }
-
- test "a bundled pass takes a level: on is the default, 0 and off take it out, and the old words still flip" {
- var state: Runtime = .{};
- const crt = find("Crt").?;
- try std.testing.expect(apply(&state, crt, "on"));
- try std.testing.expectEqual(@as(u8, Post.default_level), state.post.level(.crt));
- try std.testing.expect(apply(&state, find("Shader").?, "/after.glsl"));
- const moved = state.post.generation;
- try std.testing.expect(apply(&state, crt, "3"));
- try std.testing.expectEqual(@as(u8, 3), state.post.level(.crt));
- // A new level keeps its place in the chain.
- try std.testing.expectEqual(Scene.crt, state.post.list()[0].scene.?);
- try std.testing.expect(state.post.generation != moved);
- try std.testing.expect(!apply(&state, crt, "4"));
- try std.testing.expect(!apply(&state, crt, "loud"));
- try std.testing.expect(apply(&state, crt, "0"));
- try std.testing.expect(!state.post.has(.crt));
- try std.testing.expect(apply(&state, crt, null));
- try std.testing.expectEqual(@as(u8, Post.default_level), state.post.level(.crt));
- try std.testing.expect(apply(&state, crt, "off"));
- try std.testing.expectEqual(@as(u8, 0), state.post.level(.crt));
}
test "Lift takes a style, on is auto, and bare flips it off and back to auto" {
@@ -1732,7 +1522,6 @@ pub const Runtime = struct {
.capabilities = .{
.font_picker = true,
.panel_transitions = true,
- .scene_shaders = true,
.tagline_font_size = true,
.window_opacity = true,
.window_blur = true,
@@ -1742,13 +1531,12 @@ pub const Runtime = struct {
.state = &state,
};
const values = [_][2][]const u8{
- .{ "TaglineSize", "73" }, .{ "WindowOpacity", "85" }, .{ "WindowBlur", "40" },
- .{ "MessageLinger", "1500" }, .{ "MessageFall", "1500" }, .{ "MessageDissolve", "1500" },
- .{ "DumpDir", "~/dumps" }, .{ "Crt", "3" }, .{ "Shader", "~/crt.glsl" },
- .{ "ShaderAnimation", "always" }, .{ "TermImages", "petscii" }, .{ "JumpScope", "all" },
- .{ "SearchPlace", "column" }, .{ "SearchPane", "new" }, .{ "Lift", "rim" },
- .{ "Motion", "playful" }, .{ "InactiveDim", "35" }, .{ "GripWidth", "200" },
- .{ "CallstackDepth", "16" }, .{ "Tab", "8" }, .{ "SearchRows", "12" },
+ .{ "TaglineSize", "73" }, .{ "WindowOpacity", "85" }, .{ "WindowBlur", "40" },
+ .{ "MessageLinger", "1500" }, .{ "MessageFall", "1500" }, .{ "MessageDissolve", "1500" },
+ .{ "DumpDir", "~/dumps" }, .{ "TermImages", "petscii" }, .{ "JumpScope", "all" },
+ .{ "SearchPlace", "column" }, .{ "SearchPane", "new" }, .{ "Lift", "rim" },
+ .{ "Motion", "playful" }, .{ "InactiveDim", "35" }, .{ "GripWidth", "200" },
+ .{ "CallstackDepth", "16" }, .{ "Tab", "8" }, .{ "SearchRows", "12" },
};
for (values) |v| try std.testing.expect(apply(&state, find(v[0]).?, v[1]));
try std.testing.expect(state.font.requested_name.set("Wanted Mono"));
@@ -1785,7 +1573,6 @@ pub const Runtime = struct {
defaults_context.capabilities = .{
.font_picker = false,
.panel_transitions = true,
- .scene_shaders = false,
.tagline_font_size = false,
};
defaults_context.state = &defaults;
@@ -1793,7 +1580,7 @@ pub const Runtime = struct {
try writeReport(&out, defaults_context);
const defaults_report = storage[0..out.end];
// A setting this shell does not have reads so, as a comment.
- for ([_][]const u8{ "# WindowOpacity unsupported\n", "# WindowBlur unsupported\n", "# Font unsupported\n", "# Crt unsupported\n", "# TaglineSize unsupported\n", "# Ligatures unsupported\n" }) |expected|
+ for ([_][]const u8{ "# WindowOpacity unsupported\n", "# WindowBlur unsupported\n", "# Font unsupported\n", "# TaglineSize unsupported\n", "# Ligatures unsupported\n" }) |expected|
try std.testing.expect(std.mem.indexOf(u8, defaults_report, expected) != null);
try std.testing.expect(std.mem.indexOf(u8, defaults_report, "Font in use") == null);
// Every line before the blank one is a ctl word and its value, or a
diff --git a/src/effect_sources.zig b/src/effect_sources.zig
deleted file mode 100644
index 39d86a1d..00000000
--- a/src/effect_sources.zig
+++ /dev/null
@@ -1,98 +0,0 @@
-const std = @import("std");
-const build_config = @import("pardes_config");
-const config = @import("config.zig");
-const filesystem = @import("fs.zig");
-
-const shader_dir = "shaders/";
-const ui_vertex_path = shader_dir ++ "ui.vert.glsl";
-const ui_fragment_path = shader_dir ++ "ui.frag.glsl";
-const image_vertex_path = shader_dir ++ "image.vert.glsl";
-const image_fragment_path = shader_dir ++ "image.frag.glsl";
-const post_vertex_path = shader_dir ++ "post.vert.glsl";
-// The bundled post pass as compiled: the prefix and the pass together.
-const post_crt_path = shader_dir ++ "post-crt.frag.glsl";
-const post_bloom_path = shader_dir ++ "post-bloom.frag.glsl";
-const post_vignette_path = shader_dir ++ "post-vignette.frag.glsl";
-const post_grain_path = shader_dir ++ "post-grain.frag.glsl";
-const bloom_down_path = shader_dir ++ "bloom-down.frag.glsl";
-const bloom_up_path = shader_dir ++ "bloom-up.frag.glsl";
-
-pub const Backend = @TypeOf(build_config.platform);
-pub const backend: Backend = build_config.platform;
-
-pub const files = switch (backend) {
- .tui => [_]filesystem.Source{
- .{ .path = "src/tui/panel_compositor.zig", .contents = @embedFile("tui/panel_compositor.zig") },
- },
- .gui => [_]filesystem.Source{
- .{ .path = "src/gui/gui.zig", .contents = @embedFile("gui/gui.zig") },
- .{ .path = "src/gui/Post.zig", .contents = @embedFile("gui/Post.zig") },
- .{ .path = ui_vertex_path, .contents = @embedFile("effect-source-ui.vert.glsl") },
- .{ .path = ui_fragment_path, .contents = @embedFile("effect-source-ui.frag.glsl") },
- .{ .path = image_vertex_path, .contents = @embedFile("effect-source-image.vert.glsl") },
- .{ .path = image_fragment_path, .contents = @embedFile("effect-source-image.frag.glsl") },
- .{ .path = post_vertex_path, .contents = @embedFile("effect-source-post.vert.glsl") },
- .{ .path = post_crt_path, .contents = @embedFile("effect-source-post-crt.frag.glsl") },
- .{ .path = post_bloom_path, .contents = @embedFile("effect-source-post-bloom.frag.glsl") },
- .{ .path = post_vignette_path, .contents = @embedFile("effect-source-post-vignette.frag.glsl") },
- .{ .path = post_grain_path, .contents = @embedFile("effect-source-post-grain.frag.glsl") },
- .{ .path = bloom_down_path, .contents = @embedFile("effect-source-bloom-down.frag.glsl") },
- .{ .path = bloom_up_path, .contents = @embedFile("effect-source-bloom-up.frag.glsl") },
- },
- .macos => [_]filesystem.Source{
- .{ .path = "src/macos/Sources/PardesView.swift", .contents = @embedFile("macos/Sources/PardesView.swift") },
- .{ .path = "src/macos/Sources/ScenePostprocessor.swift", .contents = @embedFile("macos/Sources/ScenePostprocessor.swift") },
- .{ .path = "shaders/crt.ci.metal", .contents = @embedFile("effect-source-crt.ci.metal") },
- },
-};
-
-pub fn forSetting(setting: config.Runtime.Setting) ?[]const []const u8 {
- return switch (setting.action) {
- .transition => switch (backend) {
- .tui => &.{ "src/layout.zig", "src/pardes.zig", "src/tui/panel_compositor.zig" },
- .gui => &.{ "src/layout.zig", "src/pardes.zig", "src/gui/gui.zig", ui_vertex_path, ui_fragment_path, image_vertex_path, image_fragment_path },
- .macos => &.{ "src/layout.zig", "src/pardes.zig", "src/macos/Sources/PardesView.swift", "src/macos/Sources/ScenePostprocessor.swift", "shaders/crt.ci.metal" },
- },
- .scene => |effect| switch (backend) {
- .gui => switch (effect) {
- .crt => &.{ "src/gui/Post.zig", "src/gui/gui.zig", post_vertex_path, post_crt_path },
- .bloom => &.{ "src/gui/Post.zig", "src/gui/gui.zig", post_vertex_path, bloom_down_path, bloom_up_path, post_bloom_path },
- .vignette => &.{ "src/gui/Post.zig", "src/gui/gui.zig", post_vertex_path, post_vignette_path },
- .grain => &.{ "src/gui/Post.zig", "src/gui/gui.zig", post_vertex_path, post_grain_path },
- },
- .macos => &.{ "src/macos/Sources/PardesView.swift", "src/macos/Sources/ScenePostprocessor.swift", "shaders/crt.ci.metal" },
- .tui => null,
- },
- else => null,
- };
-}
-
-test "EffectCode paths resolve uniquely to this backend's archived inputs" {
- if (!@import("memory.zig").limits.embedded_sources) return error.SkipZigTest;
- for (config.Runtime.settings) |setting| {
- const available = switch (setting.action) {
- .transition => backend == .tui or backend == .gui or backend == .macos,
- .scene => backend == .gui or backend == .macos,
- else => false,
- };
- const paths = forSetting(setting);
- try std.testing.expectEqual(available, paths != null);
- if (paths) |listed| for (listed, 0..) |path, i| {
- const bytes = filesystem.sourceBytes(path) orelse return error.MissingEffectSource;
- try std.testing.expect(bytes.len > 0);
- for (listed[0..i]) |previous| try std.testing.expect(!std.mem.eql(u8, path, previous));
- };
- }
- for (files) |file| {
- const archived = filesystem.sourceBytes(file.path) orelse return error.MissingEffectSource;
- try std.testing.expectEqualStrings(file.contents, archived);
- var matches: usize = 0;
- for (filesystem.sources) |source| if (std.mem.eql(u8, source.path, file.path)) {
- matches += 1;
- };
- try std.testing.expectEqual(@as(usize, 1), matches);
- }
- try std.testing.expectEqual(backend == .tui, filesystem.sourceBytes("src/tui/panel_compositor.zig") != null);
- try std.testing.expectEqual(backend == .gui, filesystem.sourceBytes("src/gui/gui.zig") != null);
- try std.testing.expectEqual(backend == .macos, filesystem.sourceBytes("src/macos/Sources/PardesView.swift") != null);
-}
diff --git a/src/exec.zig b/src/exec.zig
index 0c559382..b258549e 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -302,11 +302,11 @@ pub fn withArg(p: *Pardes, txt: []const u8, arg: ?[]const u8) []const u8 {
const a = std.mem.trim(u8, arg orelse return txt, " \t\r\n");
if (a.len == 0) return txt;
const t = std.mem.trim(u8, txt, " \t\r\n");
- // A switch (Verbose, PanelSlide, Crt) clicked with some other text
+ // A switch (Verbose, PanelSlide) clicked with some other text
// selected flips, as it does bare: only `on` or `off` is an argument
// for it. What a ctl write gives it is checked strictly instead.
if (config.Runtime.find(commandText(t))) |setting| switch (setting.action) {
- .toggle, .transition, .scene => if (!std.mem.eql(u8, a, "on") and !std.mem.eql(u8, a, "off")) return txt,
+ .toggle, .transition => if (!std.mem.eql(u8, a, "on") and !std.mem.eql(u8, a, "off")) return txt,
else => {},
};
return std.fmt.allocPrint(p.scratch.allocator(), "{s} {s}", .{ t, a }) catch txt;
diff --git a/src/file_watch.zig b/src/file_watch.zig
index ea8115bc..a75383e1 100644
--- a/src/file_watch.zig
+++ b/src/file_watch.zig
@@ -71,11 +71,7 @@ pub const Watch = struct {
/// Sharing the table also shares directory descriptors correctly when a user
/// happens to open that .zon as an ordinary document.
pub const theme_slot = pardes.MAX_PANES;
-/// After it, one slot a post chain file (ShaderBuild.zig): marked only so
-/// a save there wakes the host, which has the files read again; no
-/// generation of theirs is kept here.
-pub const shader_slot = theme_slot + 1;
-pub const Table = [shader_slot + pardes.config.Runtime.Post.max]?Watch;
+pub const Table = [theme_slot + 1]?Watch;
/// Whether this OS has a watcher at all. Off it every entry point below
/// returns the inert answer: `watchPane` installs nothing, so `watches` stays
@@ -424,13 +420,6 @@ pub fn unwatchAll(fd: c_int, watches: *Table) void {
for (0..pardes.MAX_PANES) |id| watchPane(fd, watches, @intCast(id), null, 0, .{ .text = 0 });
}
-/// Mark the post chain files' directories, one slot each, dropping the
-/// marks of files no longer in it.
-pub fn watchShaders(fd: c_int, watches: *Table, paths: []const []const u8) void {
- for (0..pardes.config.Runtime.Post.max) |i|
- watchPane(fd, watches, shader_slot + i, if (i < paths.len) paths[i] else null, 0, .{ .text = 0 });
-}
-
/// Reconcile one marked pane. A true result requests an immediate second pass:
/// the PDF pathname changed between the stat before MuPDF reopened it and the
/// stat after, so committing either identity would lose a generation.
diff --git a/src/fs.zig b/src/fs.zig
index ae614cd7..4afc17bd 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -35,10 +35,7 @@ pub const os_node: u64 = 1 << 62;
pub const name_capacity: usize = 255;
pub const Source = struct { path: []const u8, contents: []const u8 };
-pub const sources: []const Source = if (limits.embedded_sources)
- &(source_files ++ @import("effect_sources.zig").files)
-else
- &.{};
+pub const sources: []const Source = if (limits.embedded_sources) &source_files else &.{};
const source_files = [_]Source{
.{ .path = "src/pardes.zig", .contents = @embedFile("pardes.zig") },
.{ .path = "src/panes.zig", .contents = @embedFile("panes.zig") },
diff --git a/src/gui/Post.zig b/src/gui/Post.zig
deleted file mode 100644
index 19b10c52..00000000
--- a/src/gui/Post.zig
+++ /dev/null
@@ -1,653 +0,0 @@
-//! The post chain (docs/render-pipeline.md §6): Shadertoy passes over the
-//! finished frame, each reading the one before it (the frame first) and the
-//! last one writing the window. A pass is the bundled Crt (shaders/post/,
-//! compiled with the build) or a user's file (Shader <path>), whose SPIR-V
-//! comes from ShaderBuild.zig, compiled by this process (a window attached
-//! to a session elsewhere runs the bundled passes alone). A file whose
-//! compile fails keeps its last good pipeline.
-//!
-//! The uniforms are ghostty's (Uniforms), so a shader written for ghostty runs
-//! here. Their clock is the shell's and moves only when the chain draws:
-//! with a frame of the core's, or on its own while ShaderAnimation asks for
-//! it (redraw level A, §5.5: the chain alone, over the retained frame).
-const std = @import("std");
-const libc = std.c;
-const ghostty_vt = @import("ghostty-vt");
-const pardes = @import("../pardes.zig");
-const gui = @import("gui.zig");
-const c = gui.c;
-
-const Post = @This();
-const Scene = pardes.config.Runtime.Scene;
-const Chain = pardes.config.Runtime.Post;
-const Pipeline = c.SDL_GPUGraphicsPipeline;
-pub const max = Chain.max;
-
-const prefix = @embedFile("post-prefix.glsl");
-const Built = @import("../ShaderBuild.zig").Pass;
-const vert_spv = @embedFile("post.vert.spv");
-const bundled_spv = std.EnumArray(Scene, []const u8).init(.{
- .crt = @embedFile("post-crt.frag.spv"),
- .bloom = @embedFile("post-bloom.frag.spv"),
- .vignette = @embedFile("post-vignette.frag.spv"),
- .grain = @embedFile("post-grain.frag.spv"),
-});
-const bloom_down_spv = @embedFile("bloom-down.frag.spv");
-const bloom_up_spv = @embedFile("bloom-up.frag.spv");
-/// Bloom's steps below the frame, at levels 1 to 3: a half, a quarter, ...
-const bloom_steps = [_]u8{ 3, 4, 5 };
-const bloom_format = c.SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT;
-/// Every pass writes its target whole: no blending.
-const no_blend = std.mem.zeroes(c.SDL_GPUColorTargetBlendState);
-
-/// pardes's own block (shaders/post/prefix.glsl PardesPost), std140.
-pub const Own = extern struct {
- opaque_window: f32 = 1,
- level: f32 = 0,
- scale: f32 = 1,
- cap: f32 = 0,
- spare_count: f32 = 0,
- _pad: [3]f32 = @splat(0),
- spare: [max_spare][4]f32 = @splat(@splat(0)),
-};
-pub const max_spare = 32;
-
-/// ghostty's Shadertoy uniform block, member for member in the GLSL block's
-/// order and std140 layout (shaders/post/prefix.glsl). Filled by the GLSL
-/// names: ghostty's own Zig mirror calls the second-to-last slot
-/// selection_background, so there the two selection colours arrive swapped
-/// (docs §6, open point 1); here each is what its GLSL name says.
-pub const Uniforms = extern struct {
- resolution: [3]f32 align(16) = .{ 0, 0, 1 },
- time: f32 align(4) = 0,
- time_delta: f32 align(4) = 0,
- frame_rate: f32 align(4) = 60,
- frame: i32 align(4) = 0,
- channel_time: [4][4]f32 align(16) = @splat(@splat(0)),
- channel_resolution: [4][4]f32 align(16) = @splat(@splat(0)),
- mouse: [4]f32 align(16) = @splat(0),
- date: [4]f32 align(16) = @splat(0),
- sample_rate: f32 align(4) = 44100,
- current_cursor: [4]f32 align(16) = @splat(0),
- previous_cursor: [4]f32 align(16) = @splat(0),
- current_cursor_color: [4]f32 align(16) = @splat(0),
- previous_cursor_color: [4]f32 align(16) = @splat(0),
- current_cursor_style: i32 align(4) = 0,
- previous_cursor_style: i32 align(4) = 0,
- cursor_visible: i32 align(4) = 0,
- cursor_change_time: f32 align(4) = 0,
- time_focus: f32 align(4) = 0,
- focus: i32 align(4) = 1,
- palette: [256][4]f32 align(16) = @splat(@splat(0)),
- background_color: [4]f32 align(16) = @splat(0),
- foreground_color: [4]f32 align(16) = @splat(0),
- cursor_color: [4]f32 align(16) = @splat(0),
- cursor_text: [4]f32 align(16) = @splat(0),
- selection_foreground_color: [4]f32 align(16) = @splat(0),
- selection_background_color: [4]f32 align(16) = @splat(0),
-};
-
-pub const Pass = struct {
- scene: ?Scene = null,
- /// A bundled pass's strength (pardesLevel); 0 for a file.
- level: u8 = 0,
- /// A user's file, owned; empty for a bundled pass.
- path: []u8 = &.{},
- pipeline: ?*Pipeline = null,
- /// The SPIR-V revision `pipeline` was made from (ShaderBuild.Pass).
- revision: u32 = 0,
- /// It moves on its own (ShaderBuild.Pass).
- animated: bool = false,
-};
-
-passes: [max]Pass = @splat(.{}),
-len: usize = 0,
-/// The chain key `passes` follow (sync); null before the first.
-key: ?u32 = null,
-bundled: std.EnumArray(Scene, ?*Pipeline) = .initFill(null),
-ping: [2]?*c.SDL_GPUTexture = .{ null, null },
-ping_w: u32 = 0,
-ping_h: u32 = 0,
-uniforms: Uniforms = .{},
-/// The display's density, for a pass whose pattern is in logical pixels
-/// (pardesScale); the shell sets it.
-scale: f32 = 1,
-/// What a bundled pass may do on this theme (pardesCap), each scene's, and
-/// the rectangles every bundled pass leaves alone (pardesSpare): both from
-/// the last frame described.
-caps: std.EnumArray(Scene, f32) = .initFill(0),
-spare: [max_spare][4]f32 = @splat(@splat(0)),
-spare_len: usize = 0,
-/// Bloom's float chain, a half the frame and down, and its two steps.
-bloom_tex: [bloom_steps[bloom_steps.len - 1]]?*c.SDL_GPUTexture = @splat(null),
-bloom_w: u32 = 0,
-bloom_h: u32 = 0,
-bloom_down: ?*Pipeline = null,
-bloom_up: ?*Pipeline = null,
-started_ns: ?u64 = null,
-last_ns: u64 = 0,
-
-/// Brings the passes to the chain a shell was given (ShaderBuild.zig: a
-/// local core's, or an attached session's over the wire), whose `key` moves
-/// whenever the chain or a file's SPIR-V does. A file whose SPIR-V has not
-/// moved keeps its pipeline; one the GPU refuses keeps its last, and is said
-/// to `core`, or logged where there is none. Each loop step, off the frame
-/// path.
-pub fn sync(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice, format: c.SDL_GPUTextureFormat, chain: []const Built, key: u32, core: ?*pardes.Pardes) void {
- if (post.key == key) return;
- post.key = key;
- var next: [max]Pass = @splat(.{});
- for (chain, 0..) |entry, i| {
- if (entry.scene) |scene| {
- if (post.bundled.get(scene) == null) post.bundled.set(scene, gui.makePipeline(device, format, vert_spv, bundled_spv.get(scene), if (scene == .bloom) 2 else 1, 4, null, no_blend) catch null);
- if (scene == .bloom and post.bloom_down == null) {
- post.bloom_down = gui.makePipeline(device, bloom_format, vert_spv, bloom_down_spv, 1, 1, null, no_blend) catch null;
- post.bloom_up = gui.makePipeline(device, bloom_format, vert_spv, bloom_up_spv, 1, 1, null, no_blend) catch null;
- }
- next[i] = .{ .scene = scene, .level = entry.level, .pipeline = post.bundled.get(scene), .animated = entry.animated };
- continue;
- }
- // A file already in the chain keeps its pipeline and its path.
- for (post.passes[0..post.len]) |*pass| {
- if (pass.scene != null or !std.mem.eql(u8, pass.path, entry.path)) continue;
- next[i] = pass.*;
- pass.* = .{};
- break;
- } else next[i] = .{ .path = gpa.dupe(u8, entry.path) catch &.{} };
- const pass = &next[i];
- pass.animated = entry.animated;
- if (pass.revision == entry.revision or entry.spirv.len == 0) continue;
- pass.revision = entry.revision;
- const made = gui.makePipeline(device, format, vert_spv, entry.spirv, 1, 4, null, no_blend) catch {
- var buf: [512]u8 = undefined;
- const text = std.fmt.bufPrint(&buf, "Shader {s}: the GPU refused it", .{entry.path}) catch "Shader: the GPU refused it";
- if (core) |p| p.setMessage(p.active, text) else std.log.err("{s}", .{text});
- continue;
- };
- if (pass.pipeline) |old| c.SDL_ReleaseGPUGraphicsPipeline(device, old);
- pass.pipeline = made;
- }
- for (post.passes[0..post.len]) |pass| {
- if (pass.scene == null) if (pass.pipeline) |pipeline| c.SDL_ReleaseGPUGraphicsPipeline(device, pipeline);
- gpa.free(pass.path);
- }
- post.passes = next;
- post.len = chain.len;
- // An emptied chain's clock starts again with the next pass put in it.
- if (post.len == 0) {
- post.started_ns = null;
- post.last_ns = 0;
- post.uniforms.frame = 0;
- }
-}
-
-/// A pass is ready to draw.
-pub fn ready(post: *const Post) bool {
- for (post.passes[0..post.len]) |pass| if (pass.pipeline != null) return true;
- return false;
-}
-
-/// The chain redraws on its own (level A) as ShaderAnimation says.
-/// Only a pass that moves on its own (ShaderBuild.Pass.animated) asks for
-/// frames while idle: a still one (Bloom, Vignette, Grain, a file that reads
-/// no clock) is drawn again only with a frame of the core's.
-pub fn animating(post: *const Post, mode: pardes.config.Runtime.ShaderAnimation) bool {
- const moving = for (post.passes[0..post.len]) |pass| {
- if (pass.pipeline != null and pass.animated) break true;
- } else false;
- return moving and switch (mode) {
- .off => false,
- .on => post.uniforms.focus != 0,
- .always => true,
- };
-}
-
-/// What a frame of the core's tells the passes: where its cursor is drawn
-/// and in what, and the theme's colours.
-pub const Frame = struct {
- pub const Cursor = struct { x0: f32, y0: f32, x1: f32, y1: f32, rgb: [3]u8, text: [3]u8, bar: bool };
- cursor: ?Cursor,
- /// What a bundled pass leaves alone, in framebuffer pixels: the tags,
- /// grips and notices (and the cursor, added here).
- spare: []const [4]f32 = &.{},
- background: [3]u8,
- foreground: [3]u8,
- selection_foreground: [3]u8,
- selection_background: [3]u8,
-};
-
-fn rgba(rgb: [3]u8) [4]f32 {
- return .{ @as(f32, @floatFromInt(rgb[0])) / 255, @as(f32, @floatFromInt(rgb[1])) / 255, @as(f32, @floatFromInt(rgb[2])) / 255, 1 };
-}
-
-/// Takes in a frame of the core's. The cursor's rectangle is (left, BOTTOM
-/// edge, width, height) in framebuffer pixels, y down; a move or a new
-/// colour makes the old one the previous and stamps the change.
-pub fn describe(post: *Post, frame: Frame) void {
- const u = &post.uniforms;
- post.caps = capsOf(frame);
- post.spare_len = 0;
- for (frame.spare) |rect| post.addSpare(rect);
- if (frame.cursor) |cursor| post.addSpare(.{ cursor.x0, cursor.y0, cursor.x1, cursor.y1 });
- u.background_color = rgba(frame.background);
- u.foreground_color = rgba(frame.foreground);
- u.selection_foreground_color = rgba(frame.selection_foreground);
- u.selection_background_color = rgba(frame.selection_background);
- if (u.palette[1][3] == 0) for (&u.palette, 0..) |*slot, i| {
- const color = ghostty_vt.color.default[i];
- slot.* = rgba(.{ color.r, color.g, color.b });
- };
- u.cursor_visible = @intFromBool(frame.cursor != null);
- const cursor = frame.cursor orelse return;
- const rect: [4]f32 = .{ cursor.x0, cursor.y1, cursor.x1 - cursor.x0, cursor.y1 - cursor.y0 };
- const style: i32 = if (cursor.bar) 2 else 0;
- const color = rgba(cursor.rgb);
- u.cursor_color = color;
- u.cursor_text = rgba(cursor.text);
- if (std.meta.eql(rect, u.current_cursor) and std.meta.eql(color, u.current_cursor_color) and style == u.current_cursor_style) return;
- u.previous_cursor = u.current_cursor;
- u.previous_cursor_color = u.current_cursor_color;
- u.previous_cursor_style = u.current_cursor_style;
- u.current_cursor = rect;
- u.current_cursor_color = color;
- u.current_cursor_style = style;
- u.cursor_change_time = u.time;
-}
-
-/// A rectangle a bundled pass leaves alone; past `max_spare` the last one
-/// grows to cover the rest (sparing more, never less).
-fn addSpare(post: *Post, rect: [4]f32) void {
- if (rect[2] <= rect[0] or rect[3] <= rect[1]) return;
- if (post.spare_len < max_spare) {
- post.spare[post.spare_len] = rect;
- post.spare_len += 1;
- return;
- }
- const last = &post.spare[max_spare - 1];
- last.* = .{ @min(last[0], rect[0]), @min(last[1], rect[1]), @max(last[2], rect[2]), @max(last[3], rect[3]) };
-}
-
-/// sRGB's relative luminance (WCAG) and a pair's contrast.
-fn luminance(rgb: [3]f32) f32 {
- var sum: f32 = 0;
- for (rgb, [3]f32{ 0.2126, 0.7152, 0.0722 }) |v, weight|
- sum += weight * (if (v <= 0.04045) v / 12.92 else std.math.pow(f32, (v + 0.055) / 1.055, 2.4));
- return sum;
-}
-fn contrastOf(a: f32, b: f32) f32 {
- return (@max(a, b) + 0.05) / (@min(a, b) + 0.05);
-}
-fn unit(rgb: [3]u8) [3]f32 {
- return .{ @as(f32, @floatFromInt(rgb[0])) / 255, @as(f32, @floatFromInt(rgb[1])) / 255, @as(f32, @floatFromInt(rgb[2])) / 255 };
-}
-
-/// Each bundled pass's ceiling on this theme (pardesCap, docs/effects.md):
-/// the most it may do while the text on the page, and the selection's text
-/// on its own ground, keep min(their contrast, 4.5). Bloom adds light to
-/// both of a pair (linear, as a share of full white); a vignette darkens
-/// both (a share); grain moves the page alone, either way (sRGB units).
-pub fn capsOf(frame: Frame) std.EnumArray(Scene, f32) {
- const pairs = [_][2][3]f32{ .{ unit(frame.foreground), unit(frame.background) }, .{ unit(frame.selection_foreground), unit(frame.selection_background) } };
- var bloom: f32 = 1;
- for (pairs) |pair| {
- const a = luminance(pair[0]);
- const b = luminance(pair[1]);
- const light = @max(a, b);
- const dark = @min(a, b);
- const target = @min(contrastOf(a, b), 4.5);
- // (light + e + .05) / (dark + e + .05) >= target
- bloom = @min(bloom, @max(0, (light + 0.05 - target * (dark + 0.05)) / @max(target - 1, 1e-3)));
- }
- // A vignette darkens both of a pair as a lift's shadow does.
- const shade = @min(gui.shadowCeiling(frame.foreground, frame.background), gui.shadowCeiling(frame.selection_foreground, frame.selection_background));
- // Grain: the largest step off the page, up and down, that keeps the text
- // on it at its contrast or 4.5 (searched in 1/1020 steps up to 8/255).
- const ink = luminance(unit(frame.foreground));
- const page = unit(frame.background);
- const target = @min(contrastOf(ink, luminance(page)), 4.5);
- var grain: f32 = 0;
- var step: f32 = 0.25 / 255.0;
- while (step <= 8.0 / 255.0) : (step += 0.25 / 255.0) {
- var up = page;
- var down = page;
- for (&up, &down) |*u, *d| {
- u.* = @min(1, u.* + step);
- d.* = @max(0, d.* - step);
- }
- if (contrastOf(ink, luminance(up)) < target - 1e-4 or contrastOf(ink, luminance(down)) < target - 1e-4) break;
- grain = step;
- }
- var caps: std.EnumArray(Scene, f32) = .initFill(1);
- caps.set(.bloom, bloom);
- caps.set(.vignette, shade);
- caps.set(.grain, grain);
- return caps;
-}
-
-test "no bundled pass at its ceiling takes a native theme's text or selection below its contrast or 4.5" {
- for (pardes.themes[0..pardes.colors.native_count]) |*theme| {
- const frame: Frame = .{ .cursor = null, .background = theme.bg orelse .{ 18, 18, 18 }, .foreground = theme.fg orelse .{ 204, 204, 204 }, .selection_foreground = theme.sel_fg, .selection_background = theme.sel_bg };
- const caps = capsOf(frame);
- for ([_][2][3]u8{ .{ frame.foreground, frame.background }, .{ frame.selection_foreground, frame.selection_background } }, 0..) |pair, i| {
- const a = luminance(unit(pair[0]));
- const b = luminance(unit(pair[1]));
- const target = @min(contrastOf(a, b), 4.5) - 1e-3;
- // Bloom at its ceiling, over both.
- const e = @min(caps.get(.bloom), 0.05);
- try std.testing.expect(contrastOf(a + e, b + e) >= target);
- // The vignette at its ceiling, over both.
- const k = 1 - @min(caps.get(.vignette), 0.28);
- try std.testing.expect(contrastOf(a * k, b * k) >= target);
- // Grain moves the page alone.
- if (i == 0) {
- var up = unit(pair[1]);
- for (&up) |*v| v.* = @min(1, v.* + caps.get(.grain));
- try std.testing.expect(contrastOf(a, luminance(up)) >= target);
- }
- }
- }
-}
-
-/// The window gained or lost the focus.
-pub fn focus(post: *Post, focused: bool) void {
- if (focused and post.uniforms.focus == 0) post.uniforms.time_focus = post.uniforms.time;
- post.uniforms.focus = @intFromBool(focused);
-}
-
-/// The pointer, in framebuffer pixels: Shadertoy's iMouse, xy where it is,
-/// zw where the last press was, negative once released.
-pub fn mouse(post: *Post, x: f32, y: f32, press: ?bool) void {
- const m = &post.uniforms.mouse;
- m[0] = x;
- m[1] = y;
- if (press) |down| {
- if (down) {
- m[2] = x;
- m[3] = y;
- } else {
- m[2] = -@abs(m[2]);
- m[3] = -@abs(m[3]);
- }
- }
-}
-
-/// Runs the passes over `source`, the finished frame, into `target`: each
-/// reads the one before, the ones between write two ping-pong textures that
-/// start cleared, and iTime and iFrame move by this one draw.
-pub fn draw(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer, sampler: *c.SDL_GPUSampler, format: c.SDL_GPUTextureFormat, source: *c.SDL_GPUTexture, target: *c.SDL_GPUTexture, w: u32, h: u32, now_ns: u64, opaque_window: bool) !void {
- var live: usize = 0;
- for (post.passes[0..post.len]) |pass| live += @intFromBool(pass.pipeline != null);
- if (live == 0) return;
- if (live > 1 and (post.ping[0] == null or post.ping_w != w or post.ping_h != h)) {
- for (&post.ping) |*texture| {
- if (texture.*) |old| c.SDL_ReleaseGPUTexture(device, old);
- texture.* = gui.texture2d(device, format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER, w, h) orelse return error.GpuCreate;
- }
- post.ping_w = w;
- post.ping_h = h;
- }
- const u = &post.uniforms;
- const started = post.started_ns orelse now_ns;
- post.started_ns = started;
- const elapsed = @as(f64, @floatFromInt(now_ns -| started)) / std.time.ns_per_s;
- const delta: f32 = if (post.last_ns == 0) 0 else @floatCast(@as(f64, @floatFromInt(now_ns -| post.last_ns)) / std.time.ns_per_s);
- post.last_ns = now_ns;
- u.time = @floatCast(elapsed);
- u.time_delta = delta;
- u.frame_rate = if (delta > 0) 1 / delta else 60;
- u.resolution = .{ @floatFromInt(w), @floatFromInt(h), 1 };
- u.channel_resolution[0] = .{ @floatFromInt(w), @floatFromInt(h), 1, 0 };
- // UTC: the year, the month from 0, the day, the second of the day.
- var wall: libc.timespec = undefined;
- if (libc.clock_gettime(.REALTIME, &wall) != 0) wall.sec = 0;
- const epoch: std.time.epoch.EpochSeconds = .{ .secs = @intCast(@max(0, wall.sec)) };
- const day = epoch.getEpochDay().calculateYearDay();
- const month = day.calculateMonthDay();
- u.date = .{ @floatFromInt(day.year), @floatFromInt(month.month.numeric() - 1), @floatFromInt(month.day_index + 1), @floatFromInt(epoch.getDaySeconds().secs) };
-
- var input = source;
- var index: usize = 0;
- for (post.passes[0..post.len]) |pass| {
- const pipeline = pass.pipeline orelse continue;
- index += 1;
- const last = index == live;
- const output = if (last) target else post.ping[index % 2].?;
- var info = std.mem.zeroes(c.SDL_GPUColorTargetInfo);
- info.texture = output;
- info.load_op = if (last) c.SDL_GPU_LOADOP_DONT_CARE else c.SDL_GPU_LOADOP_CLEAR;
- info.store_op = c.SDL_GPU_STOREOP_STORE;
- // Bloom's glow first, from this pass's input, at half size and down.
- // A chain that could not be made adds no glow, and the pass is the
- // frame as it was.
- const glow = if (pass.scene == .bloom) post.bloomChain(device, cmd, sampler, input, w, h, pass.level) catch null else null;
- const pass_rp = c.SDL_BeginGPURenderPass(cmd, &info, 1, null);
- c.SDL_BindGPUGraphicsPipeline(pass_rp, pipeline);
- const bindings = [2]c.SDL_GPUTextureSamplerBinding{ .{ .texture = input, .sampler = sampler }, .{ .texture = glow orelse input, .sampler = sampler } };
- c.SDL_BindGPUFragmentSamplers(pass_rp, 0, &bindings, if (pass.scene == .bloom) 2 else 1);
- pushUniforms(cmd, u);
- var own: Own = .{
- .opaque_window = @floatFromInt(@intFromBool(opaque_window)),
- .level = @floatFromInt(pass.level),
- .scale = post.scale,
- // A user's file has no ceiling of ours, and no spared rectangles.
- .cap = if (pass.scene) |scene| (if (scene == .bloom and glow == null) 0 else post.caps.get(scene)) else 1,
- .spare_count = if (pass.scene != null) @floatFromInt(post.spare_len) else 0,
- };
- if (pass.scene != null) @memcpy(own.spare[0..post.spare_len], post.spare[0..post.spare_len]);
- c.SDL_PushGPUFragmentUniformData(cmd, 3, &own, @sizeOf(Own));
- c.SDL_DrawGPUPrimitives(pass_rp, 3, 1, 0, 0);
- c.SDL_EndGPURenderPass(pass_rp);
- input = output;
- }
- u.frame +%= 1;
-}
-
-/// ghostty's block as the prefix cuts it (SDL GPU binds at most 4 KiB of a
-/// block): the globals up to the palette, the palette, the colours after it,
-/// each a slice of the one struct, at set 3 bindings 0 to 2.
-fn pushUniforms(cmd: *c.SDL_GPUCommandBuffer, u: *const Uniforms) void {
- const bytes = std.mem.asBytes(u);
- const palette = @offsetOf(Uniforms, "palette");
- const colors = @offsetOf(Uniforms, "background_color");
- c.SDL_PushGPUFragmentUniformData(cmd, 0, bytes.ptr, @intCast(palette));
- c.SDL_PushGPUFragmentUniformData(cmd, 1, bytes.ptr + palette, @intCast(colors - palette));
- c.SDL_PushGPUFragmentUniformData(cmd, 2, bytes.ptr + colors, @intCast(@sizeOf(Uniforms) - colors));
-}
-
-test "each slice of the uniforms fits the 4 KiB SDL GPU binds of a block" {
- try std.testing.expect(@offsetOf(Uniforms, "palette") <= 4096);
- try std.testing.expect(@offsetOf(Uniforms, "background_color") - @offsetOf(Uniforms, "palette") <= 4096);
- try std.testing.expect(@sizeOf(Uniforms) - @offsetOf(Uniforms, "background_color") <= 4096);
- try std.testing.expect(@sizeOf(Own) <= 4096);
-}
-
-/// Bloom's glow of `input` (w x h): a bright pass and dual Kawase steps
-/// down to 1/2^n of the frame and back up to a half, in float textures;
-/// the half-size result, for the composite (shaders/post/bloom.glsl).
-fn bloomChain(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer, sampler: *c.SDL_GPUSampler, input: *c.SDL_GPUTexture, w: u32, h: u32, level: u8) !*c.SDL_GPUTexture {
- const down = post.bloom_down orelse return error.GpuCreate;
- const up = post.bloom_up orelse return error.GpuCreate;
- const steps = bloom_steps[std.math.clamp(level, 1, 3) - 1];
- if (post.bloom_tex[0] == null or post.bloom_w != w or post.bloom_h != h) {
- for (&post.bloom_tex, 0..) |*texture, i| {
- if (texture.*) |old| c.SDL_ReleaseGPUTexture(device, old);
- texture.* = gui.texture2d(device, bloom_format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER, @max(1, w >> @intCast(i + 1)), @max(1, h >> @intCast(i + 1))) orelse return error.GpuCreate;
- }
- post.bloom_w = w;
- post.bloom_h = h;
- }
- const Step = extern struct { texels: [4]f32, pass: [4]f32 };
- const size = struct {
- fn of(full: u32, i: usize) f32 {
- return @floatFromInt(if (i == 0) full else @max(1, full >> @intCast(i)));
- }
- };
- // Down: the frame (0) to 1, 1 to 2, ...; the first through the bright
- // pass (a channel's linear peak over 0.6 to 0.75, by level).
- const threshold: f32 = switch (std.math.clamp(level, 1, 3)) {
- 1 => 0.75,
- 2 => 0.7,
- else => 0.6,
- };
- // Only what is brighter than the page glows: on a light page, where the
- // ground itself would pass, nothing does.
- const page_peak = peak: {
- var peak: f32 = 0;
- for (post.uniforms.background_color[0..3]) |v| peak = @max(peak, if (v <= 0.04045) v / 12.92 else std.math.pow(f32, (v + 0.055) / 1.055, 2.4));
- break :peak peak;
- };
- for (0..steps) |i| {
- const from = if (i == 0) input else post.bloom_tex[i - 1].?;
- const to = post.bloom_tex[i].?;
- const params: Step = .{
- .texels = .{ 1 / size.of(w, i), 1 / size.of(h, i), 1 / size.of(w, i + 1), 1 / size.of(h, i + 1) },
- .pass = .{ if (i == 0) @max(threshold, page_peak + 0.15) else 0, 0.25, 0, 0 },
- };
- bloomStep(cmd, down, sampler, from, to, &params, @sizeOf(Step));
- }
- // Up: each level into the one above it, back to the half.
- var i: usize = steps - 1;
- while (i > 0) : (i -= 1) {
- const params: Step = .{
- .texels = .{ 1 / size.of(w, i + 1), 1 / size.of(h, i + 1), 1 / size.of(w, i), 1 / size.of(h, i) },
- .pass = @splat(0),
- };
- bloomStep(cmd, up, sampler, post.bloom_tex[i].?, post.bloom_tex[i - 1].?, &params, @sizeOf(Step));
- }
- return post.bloom_tex[0].?;
-}
-
-fn bloomStep(cmd: *c.SDL_GPUCommandBuffer, pipeline: *Pipeline, sampler: *c.SDL_GPUSampler, from: *c.SDL_GPUTexture, to: *c.SDL_GPUTexture, params: *const anyopaque, len: u32) void {
- var info = std.mem.zeroes(c.SDL_GPUColorTargetInfo);
- info.texture = to;
- info.load_op = c.SDL_GPU_LOADOP_DONT_CARE;
- info.store_op = c.SDL_GPU_STOREOP_STORE;
- const rp = c.SDL_BeginGPURenderPass(cmd, &info, 1, null);
- c.SDL_BindGPUGraphicsPipeline(rp, pipeline);
- const binding = c.SDL_GPUTextureSamplerBinding{ .texture = from, .sampler = sampler };
- c.SDL_BindGPUFragmentSamplers(rp, 0, &binding, 1);
- c.SDL_PushGPUFragmentUniformData(cmd, 0, params, len);
- c.SDL_DrawGPUPrimitives(rp, 3, 1, 0, 0);
- c.SDL_EndGPURenderPass(rp);
-}
-
-pub fn deinit(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice) void {
- for (post.bloom_tex) |texture| if (texture) |t| c.SDL_ReleaseGPUTexture(device, t);
- for ([_]?*Pipeline{ post.bloom_down, post.bloom_up }) |pipeline| if (pipeline) |p| c.SDL_ReleaseGPUGraphicsPipeline(device, p);
- for (post.passes[0..post.len]) |pass| {
- if (pass.scene == null) if (pass.pipeline) |pipeline| c.SDL_ReleaseGPUGraphicsPipeline(device, pipeline);
- gpa.free(pass.path);
- }
- for (post.bundled.values) |pipeline| if (pipeline) |p| c.SDL_ReleaseGPUGraphicsPipeline(device, p);
- for (post.ping) |texture| if (texture) |t| c.SDL_ReleaseGPUTexture(device, t);
-}
-
-/// ghostty 1.4.0's Uniforms (src/renderer/shadertoy.zig), copied: the offsets
-/// ours must match. Its last two names are swapped against its own GLSL.
-const GhosttyUniforms = extern struct {
- resolution: [3]f32 align(16),
- time: f32 align(4),
- time_delta: f32 align(4),
- frame_rate: f32 align(4),
- frame: i32 align(4),
- channel_time: [4][4]f32 align(16),
- channel_resolution: [4][4]f32 align(16),
- mouse: [4]f32 align(16),
- date: [4]f32 align(16),
- sample_rate: f32 align(4),
- current_cursor: [4]f32 align(16),
- previous_cursor: [4]f32 align(16),
- current_cursor_color: [4]f32 align(16),
- previous_cursor_color: [4]f32 align(16),
- current_cursor_style: i32 align(4),
- previous_cursor_style: i32 align(4),
- cursor_visible: i32 align(4),
- cursor_change_time: f32 align(4),
- time_focus: f32 align(4),
- focus: i32 align(4),
- palette: [256][4]f32 align(16),
- background_color: [4]f32 align(16),
- foreground_color: [4]f32 align(16),
- cursor_color: [4]f32 align(16),
- cursor_text: [4]f32 align(16),
- selection_background_color: [4]f32 align(16),
- selection_foreground_color: [4]f32 align(16),
-};
-
-test "the uniform block is ghostty's, offset for offset, and the prefix names it in that order" {
- const ours = @typeInfo(Uniforms).@"struct";
- const theirs = @typeInfo(GhosttyUniforms).@"struct";
- try std.testing.expectEqual(theirs.field_names.len, ours.field_names.len);
- try std.testing.expectEqual(@sizeOf(GhosttyUniforms), @sizeOf(Uniforms));
- inline for (ours.field_names, ours.field_types, theirs.field_names, theirs.field_types) |a, a_type, b, b_type| {
- try std.testing.expectEqual(@offsetOf(GhosttyUniforms, b), @offsetOf(Uniforms, a));
- try std.testing.expectEqual(b_type, a_type);
- }
- // By NAME: iSelectionForegroundColor sits where ghostty's Zig says
- // selection_background, which is where its GLSL puts the foreground.
- try std.testing.expectEqual(@offsetOf(GhosttyUniforms, "selection_background_color"), @offsetOf(Uniforms, "selection_foreground_color"));
- // The prefix's block, member by member, in ghostty's GLSL names and types.
- const glsl = [_]struct { []const u8, []const u8 }{
- .{ "vec3", "iResolution" }, .{ "float", "iTime" }, .{ "float", "iTimeDelta" },
- .{ "float", "iFrameRate" }, .{ "int", "iFrame" }, .{ "float", "iChannelTime[4]" },
- .{ "vec3", "iChannelResolution[4]" }, .{ "vec4", "iMouse" }, .{ "vec4", "iDate" },
- .{ "float", "iSampleRate" }, .{ "vec4", "iCurrentCursor" }, .{ "vec4", "iPreviousCursor" },
- .{ "vec4", "iCurrentCursorColor" }, .{ "vec4", "iPreviousCursorColor" }, .{ "int", "iCurrentCursorStyle" },
- .{ "int", "iPreviousCursorStyle" }, .{ "int", "iCursorVisible" }, .{ "float", "iTimeCursorChange" },
- .{ "float", "iTimeFocus" }, .{ "int", "iFocus" }, .{ "vec3", "iPalette[256]" },
- .{ "vec3", "iBackgroundColor" }, .{ "vec3", "iForegroundColor" }, .{ "vec3", "iCursorColor" },
- .{ "vec3", "iCursorText" }, .{ "vec3", "iSelectionForegroundColor" }, .{ "vec3", "iSelectionBackgroundColor" },
- };
- try std.testing.expectEqual(ours.field_names.len, glsl.len);
- // Its three blocks (Globals, Palette, Colors) read as one, in order.
- const start = std.mem.indexOf(u8, prefix, "uniform Globals {").?;
- const end = std.mem.indexOf(u8, prefix, "uniform PardesPost {").?;
- var lines = std.mem.tokenizeScalar(u8, prefix[start..end], '\n');
- var n: usize = 0;
- while (lines.next()) |line| {
- if (!std.mem.startsWith(u8, line, " uniform ")) continue;
- var words = std.mem.tokenizeAny(u8, line, " ;");
- try std.testing.expectEqualStrings("uniform", words.next().?);
- try std.testing.expectEqualStrings(glsl[n][0], words.next().?);
- try std.testing.expectEqualStrings(glsl[n][1], words.next().?);
- n += 1;
- }
- try std.testing.expectEqual(glsl.len, n);
- // Each block starts where its first member is in the one struct.
- try std.testing.expect(std.mem.indexOf(u8, prefix, "uniform Palette {\n uniform vec3 iPalette[256];\n};") != null);
-}
-
-test "a moved cursor becomes the previous one, stamped with the time of the move" {
- var post: Post = .{};
- const frame: Frame = .{ .cursor = .{ .x0 = 10, .y0 = 20, .x1 = 11, .y1 = 40, .rgb = .{ 255, 0, 0 }, .text = .{ 0, 0, 0 }, .bar = true }, .background = .{ 0, 0, 0 }, .foreground = .{ 255, 255, 255 }, .selection_foreground = .{ 1, 2, 3 }, .selection_background = .{ 4, 5, 6 } };
- post.uniforms.time = 1.5;
- post.describe(frame);
- // Left, BOTTOM edge, width, height, in framebuffer pixels, y down.
- try std.testing.expectEqual([4]f32{ 10, 40, 1, 20 }, post.uniforms.current_cursor);
- try std.testing.expectEqual(@as(i32, 2), post.uniforms.current_cursor_style);
- try std.testing.expectEqual(@as(f32, 1.5), post.uniforms.cursor_change_time);
- post.uniforms.time = 2;
- post.describe(frame);
- try std.testing.expectEqual(@as(f32, 1.5), post.uniforms.cursor_change_time);
- var moved = frame;
- moved.cursor.?.x0 = 20;
- moved.cursor.?.x1 = 21;
- post.describe(moved);
- try std.testing.expectEqual([4]f32{ 10, 40, 1, 20 }, post.uniforms.previous_cursor);
- try std.testing.expectEqual(@as(f32, 2), post.uniforms.cursor_change_time);
- try std.testing.expectEqual([4]f32{ 1.0 / 255.0, 2.0 / 255.0, 3.0 / 255.0, 1 }, post.uniforms.selection_foreground_color);
-}
-
-test "a still pass asks for no idle frames; one that reads the clock does" {
- var post: Post = .{};
- const fake: *Pipeline = @ptrFromInt(0x1000);
- post.passes[0] = .{ .scene = .bloom, .level = 2, .pipeline = fake };
- post.len = 1;
- try std.testing.expect(!post.animating(.on) and !post.animating(.always));
- post.passes[1] = .{ .scene = .crt, .level = 2, .pipeline = fake, .animated = true };
- post.len = 2;
- try std.testing.expect(post.animating(.on) and post.animating(.always) and !post.animating(.off));
- // Unfocused, `on` rests.
- post.uniforms.focus = 0;
- try std.testing.expect(!post.animating(.on) and post.animating(.always));
-}
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 28f5e695..2c2f53c4 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -12,9 +12,7 @@ const config = @import("../config.zig");
const look = @import("../look.zig");
const message = pardes.Messages.Message;
const file_watch = @import("../file_watch.zig");
-const ShaderBuild = @import("../ShaderBuild.zig");
const deck = @import("deck.zig");
-const Post = @import("Post.zig");
const pet = @import("pet.zig");
const fonts = @import("../fonts.zig"); // the fallback faces
const selection_pipe = @import("../selection_pipe.zig");
@@ -806,7 +804,7 @@ const Pty = struct {
const Queue = host_io.Inbox;
/// Wakes a blocking SDL_WaitEventTimeout from another thread: a push to
-/// the queue, a link's message, a post chain's compile done (ShaderBuild).
+/// the queue, a link's message.
fn sdlWake(_: ?*anyopaque) void {
var sev = std.mem.zeroes(c.SDL_Event);
sev.type = c.SDL_EVENT_USER;
@@ -1181,13 +1179,6 @@ const Gui = struct {
blink_due: bool = false,
no_blink: bool = false,
cursor_quad_alpha: f32 = 0,
- scene_tex: ?*c.SDL_GPUTexture = null,
- scene_tex_w: u32 = 0,
- scene_tex_h: u32 = 0,
- scene_failures: u8 = 0,
- scene_target_failed: bool = false,
- /// The post chain, run over the frame in scene_tex.
- post: Post = .{},
pointer_present: bool = false,
arrow_cursor: ?*c.SDL_Cursor = null,
link_cursor: ?*c.SDL_Cursor = null,
@@ -1237,8 +1228,8 @@ const Gui = struct {
};
/// The Gui's fields that are each window's own, one a view (views.zig):
-/// the window and its presenting, its scroll and glide, its scene and post
-/// chain, its pointer, its blink, its images as presented, its capture. The
+/// the window and its presenting, its scroll and glide, its pointer, its
+/// blink, its images as presented, its capture. The
/// device, the atlas, the font and the pipelines are every window's. The
/// Gui holds the live window's; the others wait in `Shell.windows`.
const window_fields = [_][:0]const u8{
@@ -1247,8 +1238,7 @@ const window_fields = [_][:0]const u8{
"scroll_body_h", "scroll_held_px", "scroll_col", "scroll_row", "scroll_delta",
"scroll_lag", "scroll_edge", "scroll_edge_len", "scroll_notch", "program_wheel",
"glide", "pace_ns", "sel_glow", "hover_glow", "frame_arrival_ns",
- "blink_due", "cursor_quad_alpha", "scene_tex", "scene_tex_w", "scene_tex_h",
- "scene_failures", "scene_target_failed", "post", "pointer_present", "pointer_shape",
+ "blink_due", "cursor_quad_alpha", "pointer_present", "pointer_shape",
"pointer_cell", "presented_images", "prepared_images", "touch",
"live_ctrl", "live_alt", "applied_window_opacity", "capture_tex", "capture_tex_w",
"capture_tex_h", "capture_xfer", "capture_xfer_size", "captured", "capture_dir",
@@ -1288,10 +1278,8 @@ fn freshWindow(g: *Gui) void {
/// What a window held of its own let go (closeWindow lets the window go).
fn releaseWindowParts(g: *Gui, gpa: std.mem.Allocator) void {
- if (g.scene_tex) |texture| c.SDL_ReleaseGPUTexture(g.device, texture);
if (g.capture_tex) |texture| c.SDL_ReleaseGPUTexture(g.device, texture);
if (g.capture_xfer) |transfer| c.SDL_ReleaseGPUTransferBuffer(g.device, transfer);
- g.post.deinit(gpa, g.device);
g.glide.deinit(gpa);
gpa.free(g.scroll_edge);
g.presented_images.deinit(gpa);
@@ -1903,7 +1891,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
if (g.vxfer) |transfer| c.SDL_ReleaseGPUTransferBuffer(device, transfer);
if (g.image_vbuf) |buffer| c.SDL_ReleaseGPUBuffer(device, buffer);
if (g.image_vxfer) |transfer| c.SDL_ReleaseGPUTransferBuffer(device, transfer);
- if (g.scene_tex) |texture| c.SDL_ReleaseGPUTexture(device, texture);
if (g.capture_tex) |texture| c.SDL_ReleaseGPUTexture(device, texture);
if (g.capture_xfer) |transfer| c.SDL_ReleaseGPUTransferBuffer(device, transfer);
if (g.gamepad) |pad| c.SDL_CloseGamepad(pad);
@@ -1920,7 +1907,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
g.prepared_images.deinit(gpa);
g.cover.deinit(gpa);
g.decor.deinit(gpa);
- g.post.deinit(gpa, device);
}
defer c.SDL_ReleaseGPUGraphicsPipeline(device, image_pipeline);
defer if (g.font_bytes.len != 0) gpa.free(g.font_bytes); // set by Font, if it ran
@@ -2082,7 +2068,6 @@ fn localSession(
.test_hz = if (std.c.getenv("PARDES_TEST_HZ")) |hz| @max(1, std.fmt.parseInt(u64, std.mem.span(hz), 10) catch 60) else 60,
};
defer shell.shutdownPtys();
- defer shell.shaders.deinit(gpa, inotify_fd, &watches);
// A virtual clock never blinks: goldens and feel series hold still.
g.no_blink = shell.test_clock != null;
frame_probe = &core.frames;
@@ -2388,7 +2373,6 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
.test_mode = test_mode,
.remote = &client,
};
- defer shell.shaders.deinit(gpa, -1, &watches);
g.no_blink = test_mode;
defer g.hit_core = null;
_ = c.SDL_StartTextInput(g.window);
@@ -2421,10 +2405,6 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
while (!link.quit) {
core.frames.period_ns = refreshNs(g);
syncLigatures(g, core);
- {
- var passes: [Post.max]ShaderBuild.Pass = undefined;
- g.post.sync(gpa, g.device, g.swapchain_format, shell.shaders.view(&core.settings.post, &passes), shell.shaders.revision, core);
- }
var own: OwnView = .{ .g = g, .in = &in, .s = &shell, .pointer = drew };
r.within(&own, OwnView.run);
client.feed();
@@ -2859,16 +2839,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
},
else => {},
}
- // What the post chain sees of the pointer and the focus.
switch (sev.type) {
- c.SDL_EVENT_MOUSE_MOTION => {
- const at = windowPointToPixels(windowGeometry(g.window), sev.motion.x, sev.motion.y);
- g.post.mouse(at.x, at.y, null);
- },
- c.SDL_EVENT_MOUSE_BUTTON_DOWN, c.SDL_EVENT_MOUSE_BUTTON_UP => {
- const at = windowPointToPixels(windowGeometry(g.window), sev.button.x, sev.button.y);
- g.post.mouse(at.x, at.y, sev.button.down);
- },
c.SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED => {
updateDisplayScale(g.window);
// Underlines are drawn into the glyphs a logical pixel thick.
@@ -2877,8 +2848,6 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
r.link.dirty = true;
} else in.core.needs_frame = true;
},
- c.SDL_EVENT_WINDOW_FOCUS_GAINED => g.post.focus(true),
- c.SDL_EVENT_WINDOW_FOCUS_LOST => g.post.focus(false),
else => {},
}
switch (sev.type) {
@@ -3216,10 +3185,9 @@ test "tagline pointer mapping retains physical grips and carries logical text co
try std.testing.expectEqual(pardes.TagKind.workspace, topbar.tag_hit.?.kind);
}
-test "a click at the window's corner lands in the corner cell with a post chain on" {
+test "a click at the window's corner lands in the corner cell" {
const core = try pardes.Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
defer core.deinit();
- try std.testing.expect(core.settings.post.set(.crt, "", true));
var g = testGui(10, 20, 6, 12);
const geometry: WindowGeometry = .{ .window_w = 400, .window_h = 240, .pixel_w = 800, .pixel_h = 480 };
const last = mouseCellWithGeometry(&g, core, 399.9, 239.9, geometry);
@@ -3230,9 +3198,6 @@ test "a click at the window's corner lands in the corner cell with a post chain
try std.testing.expectEqual(@as(u16, 0), first.row);
}
-/// Where a window point lands: the cell drawn under it. Input is identity:
-/// no post pass moves a pixel (the bundled Crt has no barrel), so a click
-/// is exactly where it looks.
/// A wheel turned over grid cell `mc` (SDL's sign: up positive): the
/// part of dispatch after the pointer is placed, so a test can turn it.
fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
@@ -3448,8 +3413,6 @@ const Shell = struct {
pipe_tasks: *PipeTasks,
inotify_fd: c_int,
watches: *file_watch.Table,
- /// The post chain's files as SPIR-V.
- shaders: ShaderBuild = .{},
threads_ok: bool = false,
test_mode: bool = false,
feed: StdinFeed = .{},
@@ -3901,7 +3864,6 @@ const Shell = struct {
.window => if (s.gui != null) s.openAnotherWindow(null) else s.openTheWindow(),
.adopted => |a| s.adoptions.adoptShell(s.core, a.pid, a.fd),
};
- if (check_files) s.shaders.recheck();
if (check_files and file_watch.reloadChanged(s.core, s.io, s.gpa, s.watches))
s.queue.push(.files_changed);
}
@@ -3931,20 +3893,14 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
// shell's queue raises for a terminal's output, a completion, a file
// system request. What the shell moves or times itself polls every
// frame: a smooth scroll, a gamepad's sticks, the test stdin feed,
- // a post chain that moves on its own (ShaderAnimation), a present
- // to retry. A minimized window sleeps through the core's animation
+ // a present to retry. A minimized window sleeps through the core's animation
// too: nothing shows it, and it is caught up at once when the window
// is back.
- const polls = g.scroll_lag != 0 or g.scroll_delta != 0 or g.scroll_notch != 0 or g.glide.moving() or g.gamepad != null or s.test_mode or core.needs_frame or
- g.post.animating(core.settings.shader_animation);
+ const polls = g.scroll_lag != 0 or g.scroll_delta != 0 or g.scroll_notch != 0 or g.glide.moving() or g.gamepad != null or s.test_mode or core.needs_frame;
const minimized = !s.test_mode and c.SDL_GetWindowFlags(g.window) & (c.SDL_WINDOW_MINIMIZED | c.SDL_WINDOW_OCCLUDED) != 0;
// A latency trace is fed on stdin, whose poll below paces the loop:
// waiting here too would make every tick cost two frames.
- // A chain that moves on its own wakes once a display refresh.
- const poll_ms: c_int = if (g.post.animating(core.settings.shader_animation))
- @intCast(@max(1, refreshNs(g) / std.time.ns_per_ms))
- else
- 16;
+ const poll_ms: c_int = 16;
const waited: c_int = if (latency_fd >= 0) 0 else if (minimized) -1 else if (timeout_ms != 0) @min(@as(c_int, @intCast(@min(timeout_ms, std.math.maxInt(c_int)))), if (polls) poll_ms else std.math.maxInt(c_int)) else if (polls) poll_ms else -1;
// The cursor's blink is the shell's to time (Chrome.cursor_idle_ms):
// a frame a loop through an edge, else a wake at the next one; none
@@ -4161,17 +4117,7 @@ fn pollFrame(ctx: ?*anyopaque) void {
const geom = windowCells(g);
if (updateCoreResize(core, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) resetScroll(g);
stepScroll(g, core, s.gpa);
- _ = s.shaders.sync(s.gpa, s.io, core, s.inotify_fd, s.watches, sdlWake);
- {
- var passes: [Post.max]ShaderBuild.Pass = undefined;
- g.post.sync(s.gpa, g.device, g.swapchain_format, s.shaders.view(&core.settings.post, &passes), s.shaders.revision, core);
- }
if (s.test_mode) writeTestStatus(g, core, s.presented);
- // Between the core's frames, a chain that moves on its own redraws
- // alone, once a refresh of the display the window is on (a millisecond
- // early is on time: the wait that paces it is in whole milliseconds).
- if (g.post.animating(core.settings.shader_animation) and !core.needs_frame and s.presented and
- c.SDL_GetTicksNS() -| g.post.last_ns + std.time.ns_per_ms >= refreshNs(g)) redrawPost(g, s.gpa);
// A blink edge: the last frame again, the cursor's alpha moved on.
if (g.blink_due and !core.needs_frame and s.presented) if (s.surface) |frame| {
g.blink_due = false;
@@ -4350,8 +4296,6 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
const frame = surface;
s.surface = frame;
g.frame_arrival_ns = monoNs();
- const scene_requested = g.post.ready();
- if (!scene_requested) g.scene_failures = 0;
s.presented = renderFrame(g, s.gpa, core, frame) catch |err| blk: {
log.err("render: {t}", .{err});
break :blk false;
@@ -4360,16 +4304,6 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
// the next event. A few retries only: a minimized window never gets one.
s.skipped_presents = if (s.presented) 0 else s.skipped_presents +| 1;
if (!s.presented and s.skipped_presents <= 3) core.present_skipped = true;
- if (g.scene_target_failed) {
- g.scene_failures +|= 1;
- log.err("scene target unavailable (attempt {d}/3)", .{g.scene_failures});
- if (g.scene_failures >= 3) {
- // ponytail: a client's window keeps asking (its core is the
- // session's to change).
- if (s.remote == null) core.disableSceneEffects();
- g.scene_failures = 0;
- }
- } else if (scene_requested and s.presented) g.scene_failures = 0;
}
fn postPresent(ctx: ?*anyopaque) void {
@@ -5852,7 +5786,6 @@ fn renderFrame(
};
if (cursor) |value| _ = c.SDL_SetCursor(value);
}
- g.scene_target_failed = false;
g.words.memo = .{}; // positional, and this frame's cells are new
const cmd = c.SDL_AcquireGPUCommandBuffer(g.device) orelse return false;
var command_consumed = false;
@@ -5870,15 +5803,6 @@ fn renderFrame(
const win_w: f32 = @floatFromInt(sw);
const win_h: f32 = @floatFromInt(sh);
- // The post chain runs from the scene texture, over a local frame or an
- // attached session's alike.
- var scene_on = g.post.ready();
- if (scene_on) ensureSceneTexture(g, sw, sh) catch {
- g.scene_target_failed = true;
- scene_on = false;
- };
- const scene: *c.SDL_GPUTexture = if (scene_on) g.scene_tex.? else target;
-
// The frame's CPU side: groups, decor, cover and every instance, up to
// their upload.
const build_zone = tracy.zone(@src(), "gui frame build");
@@ -5962,7 +5886,7 @@ fn renderFrame(
const page = chrome.page orelse bg_default;
const background_opacity = backgroundOpacity(g.applied_window_opacity);
var color_target = std.mem.zeroes(c.SDL_GPUColorTargetInfo);
- color_target.texture = scene;
+ color_target.texture = target;
color_target.clear_color = .{
.r = @as(f32, @floatFromInt(page[0])) / 255.0 * background_opacity,
.g = @as(f32, @floatFromInt(page[1])) / 255.0 * background_opacity,
@@ -6276,25 +6200,6 @@ fn renderFrame(
drawOverlayGpu(g, cmd, rp, overlay_count);
c.SDL_EndGPURenderPass(rp);
- if (scene_on) {
- var boxes: [max_cursors]CursorBox = undefined;
- const cursors = if (cursors_shown) cursorBoxes(g, surface, layout, win_h, &boxes) else 0;
- var spare: [Post.max_spare][4]f32 = undefined;
- g.post.describe(.{
- .cursor = if (cursors > 0) boxes[0] else null,
- .spare = spare[0..postSpare(surface, layout, &spare)],
- .background = chrome.page orelse bg_default,
- .foreground = chrome.fg orelse fg_default,
- .selection_foreground = core.theme().sel_fg,
- .selection_background = core.theme().sel_bg,
- });
- const chain_zone = tracy.zone(@src(), "post chain");
- defer chain_zone.end();
- g.post.scale = display_scale;
- g.post.draw(g.device, cmd, g.linear_sampler, g.swapchain_format, g.scene_tex.?, target, sw, sh, c.SDL_GetTicksNS(), background_opacity >= 1) catch {
- g.scene_target_failed = true;
- };
- }
command_consumed = true;
const shown = try finishFrame(g, gpa, cmd, frame_target, if (groups.tracks != 0) groups.items[1].track.?.frame else null);
if (shown and groups.tracks == 0) rememberPresentedImages(g, gpa, surface);
@@ -6340,26 +6245,6 @@ fn finishFrame(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, ta
return c.SDL_SubmitGPUCommandBuffer(cmd);
}
-/// Redraw level A (docs §5.5): the post chain alone, over the frame the core
-/// last drew, for a pass that moves on its own. No core render, no cell.
-fn redrawPost(g: *Gui, gpa: std.mem.Allocator) void {
- const scene = g.scene_tex orelse return;
- const cmd = c.SDL_AcquireGPUCommandBuffer(g.device) orelse return;
- const target = (acquireTarget(g, cmd, g.scene_tex_w, g.scene_tex_h) catch null) orelse {
- _ = c.SDL_SubmitGPUCommandBuffer(cmd);
- return;
- };
- // A window the retained frame no longer fits waits for the core's.
- if (target.w != g.scene_tex_w or target.h != g.scene_tex_h) {
- _ = c.SDL_SubmitGPUCommandBuffer(cmd);
- return;
- }
- const zone = tracy.zone(@src(), "post chain redraw");
- g.post.draw(g.device, cmd, g.linear_sampler, g.swapchain_format, scene, target.texture, target.w, target.h, c.SDL_GetTicksNS(), backgroundOpacity(g.applied_window_opacity) >= 1) catch {};
- zone.end();
- _ = finishFrame(g, gpa, cmd, target, null) catch {};
-}
-
const ResolvedCell = struct {
slot: Slot,
fg: [3]u8,
@@ -8105,15 +7990,6 @@ pub fn texture2d(device: *c.SDL_GPUDevice, format: c.SDL_GPUTextureFormat, usage
return c.SDL_CreateGPUTexture(device, &info);
}
-fn ensureSceneTexture(g: *Gui, width: u32, height: u32) !void {
- if (g.scene_tex != null and g.scene_tex_w == width and g.scene_tex_h == height) return;
- const next = texture2d(g.device, g.swapchain_format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height) orelse return error.GpuCreate;
- if (g.scene_tex) |texture| c.SDL_ReleaseGPUTexture(g.device, texture);
- g.scene_tex = next;
- g.scene_tex_w = width;
- g.scene_tex_h = height;
-}
-
fn ensureCaptureTexture(g: *Gui, width: u32, height: u32) !void {
if (g.capture_tex != null and g.capture_tex_w == width and g.capture_tex_h == height) return;
const next = texture2d(g.device, g.swapchain_format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, width, height) orelse return error.GpuCreate;
@@ -9925,47 +9801,7 @@ test "a body tells its first line, and lapis's dots under it move a quarter as f
try std.testing.expectEqual(@as(f32, 0), decor.parallaxAt(900, 10));
}
-/// What a bundled post pass leaves alone (Post.Frame.spare), in window
-/// pixels: every tag with its grip, the column and workspace tags, and the
-/// notices, the chrome the focus indicators live in. A grip, the gap after
-/// it and the tag beside it are one rectangle; past the list's end the last
-/// grows to cover the rest.
-fn postSpare(surface: *const pardes.Surface, layout: CellLayout, out: *[Post.max_spare][4]f32) usize {
- var n: usize = 0;
- for (surface.regionList()) |region| {
- switch (region.kind) {
- .grip, .tag, .notice, .column_grip, .column_tag, .workspace_tag => {},
- else => continue,
- }
- if (region.rect.w == 0 or region.rect.h == 0) continue;
- const rect: [4]f32 = .{
- @as(f32, @floatFromInt(region.rect.x)) * layout.w,
- @as(f32, @floatFromInt(region.rect.y)) * layout.h,
- @as(f32, @floatFromInt(region.rect.x + region.rect.w)) * layout.w,
- @as(f32, @floatFromInt(region.rect.y + region.rect.h)) * layout.h,
- };
- const joined = for (out[0..n]) |*other| {
- // The same rows, a gap cell or two apart (a grip, the gap after
- // it, its tag): one band.
- const gap = 2 * layout.w + 0.5;
- if (other[1] == rect[1] and other[3] == rect[3] and rect[0] <= other[2] + gap and other[0] <= rect[2] + gap) {
- other.* = .{ @min(other[0], rect[0]), rect[1], @max(other[2], rect[2]), rect[3] };
- break true;
- }
- } else false;
- if (joined) continue;
- if (n == out.len) {
- const last = &out[n - 1];
- last.* = .{ @min(last[0], rect[0]), @min(last[1], rect[1]), @max(last[2], rect[2]), @max(last[3], rect[3]) };
- continue;
- }
- out[n] = rect;
- n += 1;
- }
- return n;
-}
-
-const CursorBox = Post.Frame.Cursor;
+const CursorBox = struct { x0: f32, y0: f32, x1: f32, y1: f32, rgb: [3]u8, bar: bool };
const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS;
/// Where the frame draws the focused caret, its top in grid rows: from its
@@ -9996,7 +9832,6 @@ fn caretRide(g: *const Gui, surface: *const pardes.Surface) f32 {
/// is an eighth of its cell wide, a block the whole cell.
fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout, win_h: f32, out: *[max_cursors]CursorBox) usize {
const chrome = &surface.chrome;
- const page = chrome.page orelse bg_default;
var n: usize = 0;
if (surface.cursor) |cursor| {
if (cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerIn(surface.bodyLayers(), cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) {
@@ -10006,7 +9841,7 @@ fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout
const height = std.math.clamp(if (role == .tagline) @as(f32, @floatFromInt(g.tagline_height)) else layout.h, 1.0, layout.h);
const x0 = @as(f32, @floatFromInt(cursor.x)) * layout.w;
const y0 = @as(f32, @floatFromInt(cursor.y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(cursor.y, win_h, @intFromFloat(layout.h), @intFromFloat(height))));
- out[n] = .{ .x0 = x0, .y0 = y0, .x1 = x0 + if (cursor.bar) @max(dp(1), width / 8.0) else width, .y1 = y0 + height, .rgb = cursorColor(chrome, cell, role), .text = page, .bar = cursor.bar };
+ out[n] = .{ .x0 = x0, .y0 = y0, .x1 = x0 + if (cursor.bar) @max(dp(1), width / 8.0) else width, .y1 = y0 + height, .rgb = cursorColor(chrome, cell, role), .bar = cursor.bar };
n += 1;
}
}
@@ -10023,7 +9858,7 @@ fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout
const width: f32 = if (role == .tagline) @floatFromInt(g.tagline_width) else layout.w;
const x = left + @as(f32, @floatFromInt(cursor.x)) * width;
const cell = &layer.cells[@as(usize, cursor.y) * layer.cols + cursor.x];
- out[n] = .{ .x0 = x, .y0 = top, .x1 = x + if (cursor.bar) @max(dp(1), width / 8) else width, .y1 = @min(bottom, top + height), .rgb = cursorColor(chrome, cell, role), .text = page, .bar = cursor.bar };
+ out[n] = .{ .x0 = x, .y0 = top, .x1 = x + if (cursor.bar) @max(dp(1), width / 8) else width, .y1 = @min(bottom, top + height), .rgb = cursorColor(chrome, cell, role), .bar = cursor.bar };
n += 1;
}
for (surface.tagLayers()) |*layer| {
@@ -10034,7 +9869,7 @@ fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout
const span = layer.caretSpan(cursor.x, layout.w, width, if (cursor.bar) @max(dp(1), width / 8) else width);
const y = layer.viewport.y + cursor.y;
const top = @as(f32, @floatFromInt(y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(y, win_h, g.cell_h, g.tagline_height)));
- out[n] = .{ .x0 = span[0], .y0 = top, .x1 = span[1], .y1 = top + @as(f32, @floatFromInt(g.tagline_height)), .rgb = cursorColor(chrome, &layer.cells[@as(usize, cursor.y) * layer.cols + cursor.x], .tagline), .text = page, .bar = cursor.bar };
+ out[n] = .{ .x0 = span[0], .y0 = top, .x1 = span[1], .y1 = top + @as(f32, @floatFromInt(g.tagline_height)), .rgb = cursorColor(chrome, &layer.cells[@as(usize, cursor.y) * layer.cols + cursor.x], .tagline), .bar = cursor.bar };
n += 1;
}
return n;
diff --git a/src/main.zig b/src/main.zig
index 4a3fbe8d..777673bf 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1082,7 +1082,6 @@ test {
_ = @import("locations.zig");
_ = @import("fs.zig");
_ = @import("wire.zig");
- _ = @import("ShaderBuild.zig");
_ = @import("vaxis_input.zig");
_ = @import("daemon.zig");
_ = @import("9p_io.zig");
diff --git a/src/pardes.zig b/src/pardes.zig
index db5c0c25..415424b3 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -603,13 +603,6 @@ test "startup config runs builtin lines in order and isolates bad lines" {
};
}
-test "a post chain keeps no core clock running: the shell animates it" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- try std.testing.expect(p.settings.post.set(.crt, "", true));
- try std.testing.expect(!p.animationActive());
-}
-
test "topbar hover highlights exactly the executable word" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 });
defer p.deinit();
@@ -6759,14 +6752,6 @@ pub const Pardes = struct {
look.cancelLookHover(p);
}
- /// A native post pass proved unavailable: the chain is emptied, which
- /// DumpConfig then reports.
- pub fn disableSceneEffects(p: *Pardes) void {
- const taped = tape.enter(p, .disable_scene_effects);
- defer tape.leave(p, taped);
- p.settings.post.clear();
- }
-
/// The window's answer to a WindowOpacity: done, or `failure` says why
/// not, `applied` the opacity it keeps.
pub fn windowOpacityDone(p: *Pardes, applied: u8, failure: ?[]const u8) void {
diff --git a/src/tape.zig b/src/tape.zig
index 3723537e..380cf14e 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -75,7 +75,6 @@ pub const Input = union(enum) {
observe_font: Font,
acknowledge_font: Font,
reject_font,
- disable_scene_effects,
window_opacity_done: struct { applied: u8, failure: ?[]const u8 },
pub const Font = struct { name: []const u8, size: u16, unit: pardes.config.Runtime.FontSizeUnit };
@@ -632,7 +631,6 @@ pub const Tape = struct {
.observe_font => |f| _ = p.observeFont(f.name, f.size, f.unit),
.acknowledge_font => |f| _ = p.acknowledgeFont(f.name, f.size, f.unit),
.reject_font => p.rejectFont(),
- .disable_scene_effects => p.disableSceneEffects(),
.window_opacity_done => |w| p.windowOpacityDone(w.applied, w.failure),
}
t.finishInput();