RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
greeter enhancements
oxydizer58f2264b5462
diff --git a/AGENTS.md b/AGENTS.mdindex 2c2e903..9590359 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -198,7 +198,9 @@ panel painting. The key rules:writes nothing under `$HOME` (it disables the GLES2 shader cache), and runs no Xwayland, autostart, IPC,notifications, tray, portal, polkit, services, audio, desktop orexternal-tool globals: skip anything new that owns a bus name, spawns or- writes (`tests/greeter.py`). Secrets stay in mlocked, wiped buffers.+ writes (`tests/greeter.py`). Secrets stay in mlocked, wiped buffers. Boot+ waits for it: every program it builds is an uncached compile, so it builds+ only those it draws with ([readiness](docs/greeter-readiness.md)).* **A crash never unlocks.** `Lock.announce` reports state on`REDIWM_SESSION_FD` first thing in `engage`; `rediwm-session` queues `lock`for a compositor that died locked, and `main.zig` locks before the backenddiff --git a/docs/greeter-readiness.md b/docs/greeter-readiness.mdindex 7c9cc99..bc824bb 100644--- a/docs/greeter-readiness.md+++ b/docs/greeter-readiness.md@@ -52,6 +52,40 @@ password and submit it. The DM tests separately exercise PAM with private teststacks and verify notification sender credentials. Neither substitutes for aphysical/VM libinput, logind and real-PAM login acceptance check.+## Where the time goes++The gate above is not relaxed to go faster: the veil must still have cleared.+What the greeter avoids instead, none of which changes a desktop session:++* The reveal is `greeter_reveal_ms` (150 ms), not `session_reveal` (420 ms).+* It does not hold the reveal for the wallpaper decoder when the account's+ snapshot is what it shows.+* It compiles only the programs it draws with. It has no clients and no glass, so+ neither the external nor the blur program; it has no shader cache (it writes+ nothing to disk), so each would be a full compile on every start.+* It loads the cursor theme per output scale only, not also at scale 1.+* wlroots logs at info: debug is over a thousand lines, four `write`s each.++Measured from spawn to `ready` on ReleaseSafe builds, nested in a private headless+parent on an Intel render node (10 runs, warm page cache): 732 to 405 ms at scale 1,+741 to 427 ms at scale 1.5, and 872 to 400 ms when the wallpaper decoder is slower+than the hold. About 80 ms of the nested figure is frame-callback and+presentation-feedback lag, and it has no DRM, libinput or PAM cost, so it is not a+boot figure.++Costs left outside this code, read from the journal of a hybrid Intel/NVIDIA laptop+under systemd (cold boot / logout back to the greeter):++* The first atomic modeset blocks in the kernel for 1.24-1.34 s (five boots), against+ 3-8 ms once the panel is already driven. wlroots' modesets are blocking.+* The secondary NVIDIA GPU: glvnd loading its EGL vendor, then a multi-GPU renderer,+ about 450 / 150 ms, even with nothing connected to it.+* `pam_systemd` waits for `[email protected]`, which the greeter does not use: about+ 400 / 130 ms. redinit masks it.+* libinput opening every device: about 200 ms, in both cases.++## Comparing builds+Only compare performance after the same readiness gate and input actions passon both builds. Capture the manager's notification timestamp, first presentedframe, and response to keyboard/pointer actions. Logging and diagnostic buildsdiff --git a/src/Input.zig b/src/Input.zigindex abe7ad3..9a1ee35 100644--- a/src/Input.zig+++ b/src/Input.zig@@ -325,7 +325,9 @@ pub fn init(input: *Input, server: *Server) Server.CompositorError!void {errdefer input.request_set_primary_selection.link.remove();input.cursor.attachOutputLayout(server.output_layout);- input.cursor_mgr.load(1) catch return error.XcursorCreateFailed;+ // Parses the whole theme. The greeter loads it per output scale instead+ // (refreshOutputScales), and its only cursor is the default one.+ if (!server.greeter_mode) input.cursor_mgr.load(1) catch return error.XcursorCreateFailed;input.cursor.events.motion.add(&input.cursor_motion);input.cursor.events.motion_absolute.add(&input.cursor_motion_absolute);input.cursor.events.button.add(&input.cursor_button);diff --git a/src/main.zig b/src/main.zigindex 387cbe2..bb38373 100644--- a/src/main.zig+++ b/src/main.zig@@ -18,6 +18,10 @@ const log = std.log.scoped(.compositor);// nested/headless outputs default to 1x (host density is not reliably exposed).const scale_env = "REDIWM_SCALE";+fn isGreeter(argv: []const [*:0]const u8) bool {+ return argv.len >= 2 and std.mem.eql(u8, std.mem.span(argv[1]), "--greeter");+}+pub fn main(init: std.process.Init) void {// Every client, helper and autostart item would inherit root. rediwm-dm// and rediwm-session run the compositor as the logged-in user; seat@@ -38,7 +42,9 @@ pub fn main(init: std.process.Init) void {std.posix.sigaction(.PIPE, &ignore_sigpipe, null);@import("session/activation.zig").setSessionFdInheritance(init.minimal.environ, false);- wlr.log.init(.debug, null);+ // Unbuffered stderr is four writes a line, and wlroots' debug level is over a+ // thousand lines before a login screen that everything is waiting for.+ wlr.log.init(if (isGreeter(init.minimal.args.vector)) .info else .debug, null);// Runs last, on a normal exit only: restarts exec and fatal paths exit.defer if (@import("builtin").mode == .debug) {if (@import("memory").deinit()) log.err("memory leaks reported above", .{});@@ -79,9 +85,10 @@ fn start(init: std.process.Init) !bool {const argv = init.minimal.args.vector;// `rediwm --greeter` is rediwm-dm's greeter: no IPC, no autostart, no// command, and the lock screen stays up until rediwm-dm starts a session.- const greeter = argv.len >= 2 and std.mem.eql(u8, std.mem.span(argv[1]), "--greeter");+ const greeter = isGreeter(argv);// The greeter writes nothing under $HOME, and GLES2 drivers keep a shader- // cache in ~/.cache. Compiling a handful of shaders per start costs little.+ // cache in ~/.cache. So every program it builds is a full compile on each+ // start (tens of ms): it builds only those it draws with (server/setup.zig).if (greeter and setenv("MESA_SHADER_CACHE_DISABLE", "true", 0) != 0) return error.OutOfMemory;var server: Server = undefined;diff --git a/src/reveal.zig b/src/reveal.zigindex 8a60125..b7055d5 100644--- a/src/reveal.zig+++ b/src/reveal.zig@@ -18,6 +18,9 @@ const Reveal = @This();const wallpaper_wait_ms = 150;/// The fade begins by then even if no frame is ever acknowledged.const max_hold_ms = 1000;+/// The greeter rises faster than a desktop (`session_reveal`): the login UI is+/// not operational until its veil has cleared, so this is part of the wait.+const greeter_reveal_ms = 150;const cover_ms = 200;/// Past the cover's own length: a display that stops presenting must not keep/// the greeter from exiting.@@ -73,10 +76,17 @@ pub fn onVisible(self: *Reveal) void {self.visible = true;if (self.phase != .held) return;const server = self.server orelse return;- if (server.wallpaper_loader == null) return self.begin();+ if (server.wallpaper_loader == null or showsAccountWallpaper(server)) return self.begin();self.armTimer(wallpaper_wait_ms);}+/// The greeter draws the account's snapshot over the decoded wallpaper, which+/// then only matters for an account without one: nothing to wait for.+fn showsAccountWallpaper(server: *const Server) bool {+ const lock = server.locker orelse return false;+ return server.greeter_mode and lock.greeter_wallpaper != null;+}+/// The wallpaper decoded (and is on its node) or failed.pub fn onWallpaper(self: *Reveal) void {if (self.phase == .held and self.visible) self.begin();@@ -85,7 +95,11 @@ pub fn onWallpaper(self: *Reveal) void {fn begin(self: *Reveal) void {self.disarmTimer();self.phase = .revealing;- self.fade = .initCurve(1, 0, anim.nowMs(), anim.curveFor(.session_reveal));+ const greeter = if (self.server) |server| server.greeter_mode else false;+ self.fade = .initCurve(1, 0, anim.nowMs(), if (greeter)+ .{ .duration = .{ .ms = greeter_reveal_ms, .ease = .in_out_sine } }+ else+ anim.curveFor(.session_reveal));// Reduced motion keeps a short fade rather than a cut.self.fade.property = .opacity;self.scheduleFrames();diff --git a/src/scene_output.c b/src/scene_output.cindex 98d89f9..47ea6f9 100644--- a/src/scene_output.c+++ b/src/scene_output.c@@ -19,6 +19,9 @@ struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_rendererbool rediwm_output_renderer_enable_shapes(struct rediwm_output_renderer *r) {return rediwm_scene_renderer_enable_shapes(r->pass);}+bool rediwm_output_renderer_enable_external(struct rediwm_output_renderer *r) {+ return rediwm_scene_renderer_enable_external(r->pass);+}bool rediwm_output_renderer_enable_polygons(struct rediwm_output_renderer *r) {return rediwm_scene_renderer_enable_polygons(r->pass);}diff --git a/src/scene_output.h b/src/scene_output.hindex 5976e30..4548de5 100644--- a/src/scene_output.h+++ b/src/scene_output.h@@ -12,6 +12,8 @@ struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_renderer// Builds the programs that draw rounded shapes (see scene_pass.h); false if they// did not build, in which case no window may be given a shape.bool rediwm_output_renderer_enable_shapes(struct rediwm_output_renderer *);+// The program for imported client buffers (see scene_pass.h).+bool rediwm_output_renderer_enable_external(struct rediwm_output_renderer *);// The programs for polygon outlines (see scene_pass.h), built on first request.bool rediwm_output_renderer_enable_polygons(struct rediwm_output_renderer *);// Glass in the pass (stage 5c); requires shapes. False: glass is the surface's own tint.diff --git a/src/scene_output.zig b/src/scene_output.zigindex 397124f..3a84963 100644--- a/src/scene_output.zig+++ b/src/scene_output.zig@@ -11,6 +11,8 @@ pub const Renderer = opaque {pub const create = rediwm_output_renderer_create;extern fn rediwm_output_renderer_enable_shapes(renderer: *Renderer) bool;pub const enableShapes = rediwm_output_renderer_enable_shapes;+ extern fn rediwm_output_renderer_enable_external(renderer: *Renderer) bool;+ pub const enableExternal = rediwm_output_renderer_enable_external;extern fn rediwm_output_renderer_enable_polygons(renderer: *Renderer) bool;pub const enablePolygons = rediwm_output_renderer_enable_polygons;extern fn rediwm_output_renderer_enable_backdrops(renderer: *Renderer) bool;diff --git a/src/scene_pass.c b/src/scene_pass.cindex b22b3e2..772be61 100644--- a/src/scene_pass.c+++ b/src/scene_pass.c@@ -282,8 +282,7 @@ struct rediwm_scene_renderer *rediwm_scene_renderer_create(struct wlr_renderer *// Every draw goes through the shaped programs; one without a shape costs a// uniform branch. A GL program costs the driver 130-150 KiB however small,// so the plain ones are gone (stage 5, D4 of docs/plans/scene-graph-stage5.md).- bool ok = program_init(&r->shaped, 8, shaped_vertex, "uniform sampler2D tex;\n", shaped_fragment) &&- (!r->has_external || program_init(&r->shaped_external, 16, shaped_vertex, ext_prefix, shaped_fragment));+ bool ok = program_init(&r->shaped, 8, shaped_vertex, "uniform sampler2D tex;\n", shaped_fragment);r->has_shapes = r->shapes_tried = ok;if (ok && r->has_vao) {r->gen_vertex_arrays(1, &r->vertex_array);@@ -333,6 +332,18 @@ bool rediwm_scene_renderer_enable_shapes(struct rediwm_scene_renderer *r) {return r->has_shapes;}+bool rediwm_scene_renderer_enable_external(struct rediwm_scene_renderer *r) {+ assert(!r->active);+ if (r->external_tried) return r->external_ok;+ r->external_tried = true;+ if (!r->has_external) return r->external_ok = true;+ struct gl_state state;+ if (!scene_pass_enter(r, &state)) return false;+ r->external_ok = program_init(&r->shaped_external, 16, shaped_vertex, ext_prefix, shaped_fragment);+ scene_pass_leave(r, &state);+ return r->external_ok;+}+// The polygon programs: the shaped ones again with POLY defined (scene_pass.h).bool rediwm_scene_renderer_enable_polygons(struct rediwm_scene_renderer *r) {assert(!r->active);diff --git a/src/scene_pass.h b/src/scene_pass.hindex c4105aa..5763dc0 100644--- a/src/scene_pass.h+++ b/src/scene_pass.h@@ -68,6 +68,11 @@ struct rediwm_pass_shadow {// first shaped draw; later calls return the first result. False when they did not// build: shaped draws then fail the pass at submit, plain drawing is unaffected.bool rediwm_scene_renderer_enable_shapes(struct rediwm_scene_renderer *);+// Builds the program that draws external textures, which only imported client+// buffers are, so a process with no clients (the greeter) skips its compile. Call it+// outside a pass, before the first such draw; later calls return the first result.+// False when it did not build. Without it an external draw fails the pass.+bool rediwm_scene_renderer_enable_external(struct rediwm_scene_renderer *);// Builds the programs that draw a polygon shape (`poly_count` > 0), which are the// shaped ones with the polygon distance compiled in: another 280 KiB or so, so only// on request, outside a pass, before the first such draw. False when they did notdiff --git a/src/scene_pass_internal.h b/src/scene_pass_internal.hindex 6cd308c..8f4827e 100644--- a/src/scene_pass_internal.h+++ b/src/scene_pass_internal.h@@ -56,10 +56,12 @@ struct gl_state {};struct rediwm_scene_renderer {struct wlr_renderer *renderer;- // Rounded-rectangle shapes (stage 4b), built by enable_shapes: one program for+ // Rounded-rectangle shapes (stage 4b), built with the renderer: one program for// a 2D texture, a solid colour and the shape's shadow (they differ in a mode- // uniform, which every fragment of a draw reads the same), one for external.+ // uniform, which every fragment of a draw reads the same). The one for external+ // textures is built by enable_external.struct program shaped, shaped_external;+ bool external_tried, external_ok;// The same, with the polygon distance compiled in (POLY), built on demand by// enable_polygons the first time a theme gives a window or the bar an outline.// Draws of a polygon shape use these; every other draw the programs above,diff --git a/src/scene_pass_test.c b/src/scene_pass_test.cindex 855d2cb..2fa930d 100644--- a/src/scene_pass_test.c+++ b/src/scene_pass_test.c@@ -108,6 +108,8 @@ int main(void) {assert(allocator);struct rediwm_scene_renderer *r = rediwm_scene_renderer_create(renderer);assert(r);+ assert(rediwm_scene_renderer_enable_external(r));+ assert(rediwm_scene_renderer_enable_external(r)); // idempotentstruct wlr_buffer *actual = target(allocator), *expected = target(allocator);parity(r, actual, expected, false);shapes_fail_closed(r, actual);diff --git a/src/server/setup.zig b/src/server/setup.zigindex 1ef3a33..ac93ae4 100644--- a/src/server/setup.zig+++ b/src/server/setup.zig@@ -191,11 +191,14 @@ fn initSession(server: *Server, world_tree: *sn.Tree) CompositorError!void {errdefer explicit_sync.ReadFence.destroy(server.read_fence);// REDIWM_NO_GLASS=1 skips the backdrop blur for A/B frame-cost- // measurements; every glass call already accepts a null engine.- server.glass_engine = if (environ.getPosix("REDIWM_NO_GLASS") != null) null else glass.Engine.create();+ // measurements; every glass call already accepts a null engine. The greeter+ // has no glass and no clients, and each program it skips is a compile the+ // login screen would wait for (no shader cache there: main.zig).+ server.glass_engine = if (greeter or environ.getPosix("REDIWM_NO_GLASS") != null) null else glass.Engine.create();errdefer glass.Engine.destroy(server.glass_engine);server.output_renderer = scene_output_mod.Renderer.create(renderer) orelse return error.RendererInitFailed;errdefer scene_output_mod.Renderer.destroy(server.output_renderer);+ if (!greeter and !server.output_renderer.enableExternal()) return error.RendererInitFailed;log.info("scene renderer: owned GLES2 output pass", .{});// The window shapes: rounded clip, ring and shadow. Built here, before any// window exists. Without them windows are square, with no ring or shadow.