Commit Graph

81 Commits (96d4d67af393d197262fc93b315358d4fd09bf82)

Author SHA1 Message Date
Nathan 96d4d67af3 renderer: skip wakeup-driven drawFrame when animation timer is running
renderCallback (fired on any libghostty wakeup) always called
drawFrame at the end, on top of the 125 FPS animation timer that
runs whenever custom-shader-animation is engaged. Under busy
terminal output the wakeup rate stacks on top of the timer rate,
multiplying the per-frame Wayland commit + GPU submit work on
both threads with no visible benefit (the timer already presents
within DRAW_INTERVAL of the cell rebuild).

When draw_active, the timer is the authoritative present clock —
let renderCallback do updateFrame (cells need rebuilding regardless)
but skip drawFrame and trust the next timer tick to pick up the
new cells. When draw_active is false (no shader animation), wakeups
are the only present trigger so the draw still has to happen here.

Cuts host-thread CPU substantially under high-output scenarios
(seq, yes, log tailing) — bounded total drawFrame rate at the
animation interval instead of summing wakeups + timer ticks.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-25 21:22:27 -05:00
Mike Bommarito 14d9e600ac renderer: skip updateFrame when surface is not visible
renderCallback early-returns while !flags.visible to avoid the
cell rebuild for hidden surfaces (tab switch, minimize, etc.).
The .visible → true mailbox handler now runs updateFrame before
drawFrame so the first frame after re-show isn't stale.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 22:50:03 -04:00
Tobias Kohlbau f661d948a2 renderer: fix draw timer activation
The draw timer should only be activated in case a custom shader
is configured and the option custom-shader-animation is either always
or true. If the timer is kept alive CPU usage spiked enourmously.

Fixes #10667
2026-02-11 17:23:41 +01:00
Mitchell Hashimoto 446b26bb72
renderer: don't ever redraw the inspector. Not your job! 2026-02-01 14:10:33 -08:00
Mitchell Hashimoto f85653414c
renderer: keep a draw timer on when we have an inspector 2026-01-27 09:08:45 -08:00
Mitchell Hashimoto dbfc3eb679
Remove unused imports 2025-11-27 13:37:53 -08:00
Mitchell Hashimoto 880db9fdd0
renderer: hook up search selection match highlighting 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto 6c8ffb5fc1
renderer: receive message with viewport match selections
Doesn't draw yet
2025-11-24 19:55:27 -08:00
Qwerasd 6d5b4a3426 perf: replace `std.debug.assert` with inlined version
See doc comment in `quirks.zig` for reasoning
2025-11-17 12:13:56 -07:00
Mitchell Hashimoto 2daecd94a5
renderer: use terminal color state, remove color messages 2025-10-30 09:52:39 -07:00
Mitchell Hashimoto edb5f7c69d
slow down our cursor timer under valgrind 2025-07-21 07:28:23 -07:00
Qwerasd a802108558 renderer: remove unused surface parameter from updateFrame 2025-06-20 15:49:53 -06:00
Qwerasd b9e35c5970 renderer: uncomment resize message handling
We need this to get info about the padding, even if we do derive the
grid and screen size separately.

In the future this should possibly be changed to a message that only
sends the padding info and nothing else.
2025-06-20 15:18:41 -06:00
Qwerasd 371d62a82c renderer: big rework, graphics API abstraction layers, unified logic
This commit is very large, representing about a month of work with many
interdependent changes that don't separate cleanly in to atomic commits.

The main change here is unifying the renderer logic to a single generic
renderer, implemented on top of an abstraction layer over OpenGL/Metal.

I'll write a more complete summary of the changes in the description of
the PR.
2025-06-20 15:18:41 -06:00
Qwerasd 7cfc906c60 debug: properly set thread names on macOS 2025-06-20 15:18:41 -06:00
Qwerasd 2384bd69cc style: use decl literals
This commit changes a LOT of areas of the code to use decl literals
instead of redundantly referring to the type.

These changes were mostly driven by some regex searches and then manual
adjustment on a case-by-case basis.

I almost certainly missed quite a few places where decl literals could
be used, but this is a good first step in converting things, and other
instances can be addressed when they're discovered.

I tested GLFW+Metal and building the framework on macOS and tested a GTK
build on Linux, so I'm 99% sure I didn't introduce any syntax errors or
other problems with this. (fingers crossed)
2025-05-26 21:50:14 -06:00
Mitchell Hashimoto 0f4d2bb237
Lots of 0.14 changes 2025-03-12 09:55:52 -07:00
Mitchell Hashimoto 7e2286eb8c
Zig 0.14 2025-03-11 14:39:04 -07:00
Mitchell Hashimoto d532a6e260
Update libxev to use dynamic backend, support Linux configurability
Related to #3224

Previously, Ghostty used a static API for async event handling: io_uring
on Linux, kqueue on macOS. This commit changes the backend to be dynamic
on Linux so that epoll will be used if io_uring isn't available, or if
the user explicitly chooses it.

This introduces a new config `async-backend` (default "auto") which can
be set by the user to change the async backend in use. This is a
best-effort setting: if the user requests io_uring but it isn't
available, Ghostty will fall back to something that is and that choice
is up to us.

Basic benchmarking both in libxev and Ghostty (vtebench) show no
noticeable performance differences introducing the dynamic API, nor
choosing epoll over io_uring.
2025-02-21 15:04:37 -08:00
Mitchell Hashimoto a482224da8
renderer: set QoS class of the renderer thread on macOS
This sets the macOS QoS class of the renderer thread. Apple
recommends[1] that all threads should have a QoS class set, and there
are many benefits[2] to that, mainly around power management moreso than
performance I'd expect.

In this commit, I start by setting the QoS class of the renderer thread.
By default, the renderer thread is set to user interactive, because it
is a UI thread after all. But under some conditions we downgrade:

  - If the surface is not visible at all (i.e. another window is fully
    covering it or its minimized), we set the QoS class to utility. This
    is lower than the default, previous QoS and should help macOS
    unschedule the workload or move it to a different core.

  - If the surface is visible but not focused, we set the QoS class to
    user initiated. This is lower than user interactive but higher than
    default. The renderer should remain responsive but not consume as
    much time as it would if it was user interactive.

I'm unable to see any noticable difference in anything from these
changes. Unfortunately it doesn't seem like Apple provides good tools to
play around with this.

We should continue to apply QoS classes to our other threads on macOS.

[1]: https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon?preferredLanguage=occl
[2]: https://blog.xoria.org/macos-tips-threading/
2024-11-26 15:43:35 -08:00
Mitchell Hashimoto b3b5e15e96
renderer/metal: use new size struct 2024-11-14 13:44:05 -08:00
Mitchell Hashimoto 6f62944b9c
renderer: message uses new size struct 2024-11-14 13:34:36 -08:00
Mitchell Hashimoto a436bd0af6
move datastructures to dedicated "datastruct" package 2024-11-07 14:39:10 -08:00
Mitchell Hashimoto 89fadfc202
renderer: fg/bg/cursor change must mark the screen as dirty
Fixes #2372
2024-10-04 06:58:50 -10:00
Mitchell Hashimoto bae12993b3
crash: tag the thread type 2024-09-02 10:02:14 -07:00
Mitchell Hashimoto d499f7795b
input: crash binding can configure which thread to crash 2024-09-02 09:44:35 -07:00
Mitchell Hashimoto 8f477b00da
renderer/termio attach thread local state for crash capture 2024-09-01 14:15:12 -07:00
Qwerasd 900aab10f2 renderer: don't update frame if renderer grid size != terminal size 2024-08-14 22:43:58 -04:00
Qwerasd 7929e0bc09 fix: prevent flicker while shrinking screen by eliminating thread race
Before this fix, if vsync was on the GPU cells buffer could be cleared
for a frame while resizing the terminal down. This was due to the fact
that the surface sent messages for the resize to both the renderer and
the IO thread. If the renderer thread was processed first then the GPU
cells buffer(s) would be cleared and not rebuilt, because the terminal
state would be larger than the GPU cell buffers causing updateFrame to
bail out early, leaving empty cell buffers.

This fixes the problem by changing the origin of the renderer's resize
message to be the IO thread, only after properly updating the terminal
state, to avoid clearing the GPU cells buffers at a time they can't be
successfully rebuilt.
2024-08-14 19:46:24 -04:00
Łukasz Niemier f9be02a20f chore: clean up typos 2024-08-05 13:56:57 +02:00
Mitchell Hashimoto 8fdf6b4b64
renderer: add window-vsync option (defaults to false) 2024-05-05 10:18:15 -07:00
Mitchell Hashimoto ca9689be46
renderer/metal: API to handle macOS display ID changing 2024-05-04 19:40:58 -07:00
Mitchell Hashimoto 0836aa7318
renderer: add comment why we have dead code 2024-05-04 14:50:15 -07:00
Mitchell Hashimoto c56e016ab3
renderer: remove 10ms delay on repaint 2024-05-04 14:50:15 -07:00
Mitchell Hashimoto ac813c9244
renderer/metal: stop/start display link on occlusion 2024-05-04 14:49:50 -07:00
Mitchell Hashimoto a40ffad218
renderer/metal: setup display link 2024-05-04 14:49:49 -07:00
Mitchell Hashimoto fe7ff998c9
renderer: move our constant draw timer up to 120fps
Our renderers can now handle it
2024-05-04 14:49:49 -07:00
Mitchell Hashimoto caaf6a496f
renderer: add draw now async wakeup 2024-05-04 14:49:48 -07:00
Mitchell Hashimoto 506ba854fa
core: font size changes work 2024-04-06 19:33:49 -07:00
Mitchell Hashimoto b8d11e57c9
renderer/Metal: change font size works again 2024-04-06 10:55:58 -07:00
Mitchell Hashimoto e10e45a935
Revert "renderer/metal: free resources when occluded"
This reverts commit b5d543705d.
2024-02-13 21:57:46 -08:00
Mitchell Hashimoto b5d543705d
renderer/metal: free resources when occluded 2024-02-13 20:07:41 -08:00
Mitchell Hashimoto e1908f7cc7
renderer: handle renderer pause/redraw on occlusion 2024-02-13 09:21:04 -08:00
Mitchell Hashimoto adb7958f61
remove tracy usage from all files 2024-01-13 15:06:08 -08:00
Mitchell Hashimoto fc30fdfb2b
renderer: do not free new configuration on change
Fixes #1271
2024-01-09 21:05:27 -08:00
Mitchell Hashimoto 96d33fef20
custom shader animation can be set to "always" to always remain active
Fixes #1225

The `custom-shader-animation` configuration can now be set to "always"
which keeps animation active even if the terminal is unfocused.
2024-01-09 09:21:15 -08:00
Mitchell Hashimoto a64d12d3cb
renderer: animations should stop if config changes them 2023-11-17 21:51:07 -08:00
Mitchell Hashimoto 4742cd308d
renderer: animation timer if we have custom shaders 2023-11-17 21:50:53 -08:00
Mitchell Hashimoto 389712a698
renderer/opengl: switch to new update vs draw 2023-11-17 21:50:34 -08:00
Mitchell Hashimoto 0e92f68228
renderer: separate update frame data from draw 2023-11-17 21:50:34 -08:00