mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-14 18:01:58 +00:00
Ref #12034 This commit releases many GPU resources when a surface becomes invisible and rebuilds it on the next draw. I don't say "all" because there are still some things we can improve on (Kitty images). We previously held onto all GPU resources for the lifetime of the surface regardless of its visibility state. This is 3x (for triple-buffering): screen render targets, uniform/cell/custom shader buffers, font textures, and more. Measured on macOS (Metal): | Measurement (1 visible + 20 hidden tabs) | Before | After | |---------------------------------------------|-----------|---------| | Tracked GPU allocations (steady state) | 384.6 MiB | 18.3 MiB | | `MTLDevice.currentAllocatedSize` | 393.3 MiB | 19.7 MiB | | `footprint` IOSurface (dirty) | 309 MB | 15 MB | | Swap chain rebuild on unhide (42 switches) | n/a | avg 0.43 ms, max 0.55 ms | As you can see, importantly, swap chain rebuild is fast: 0.43ms average. That means that the rebuild is imperceptible and happens well within a frame draw time. This is macOS only, but most of the work was in the generic renderer. GTK only needs to call `releaseGpuResources` when it becomes invisible to get the same benefits. I didn't have my VM handy to test this yet so I didn't include it.
70 lines
2.6 KiB
Zig
70 lines
2.6 KiB
Zig
//! "apprt" is the "application runtime" package. This abstracts the
|
|
//! application runtime and lifecycle management such as creating windows,
|
|
//! getting user input (mouse/keyboard), etc.
|
|
//!
|
|
//! This enables compile-time interfaces to be built to swap out the underlying
|
|
//! application runtime. For example: pure macOS Cocoa, GTK+, browser, etc.
|
|
//!
|
|
//! The goal is to have different implementations share as much of the core
|
|
//! logic as possible, and to only reach out to platform-specific implementation
|
|
//! code when absolutely necessary.
|
|
const build_config = @import("build_config.zig");
|
|
|
|
const structs = @import("apprt/structs.zig");
|
|
|
|
pub const action = @import("apprt/action.zig");
|
|
pub const ipc = @import("apprt/ipc.zig");
|
|
pub const gtk = @import("apprt/gtk.zig");
|
|
pub const none = @import("apprt/none.zig");
|
|
pub const browser = @import("apprt/browser.zig");
|
|
pub const embedded = @import("apprt/embedded.zig");
|
|
pub const surface = @import("apprt/surface.zig");
|
|
|
|
pub const Action = action.Action;
|
|
pub const Runtime = @import("apprt/runtime.zig").Runtime;
|
|
pub const Target = action.Target;
|
|
|
|
pub const ContentScale = structs.ContentScale;
|
|
pub const Clipboard = structs.Clipboard;
|
|
pub const ClipboardContent = structs.ClipboardContent;
|
|
pub const ClipboardReadResult = structs.ClipboardReadResult;
|
|
pub const ClipboardRequest = structs.ClipboardRequest;
|
|
pub const ClipboardRequestType = structs.ClipboardRequestType;
|
|
pub const ColorScheme = structs.ColorScheme;
|
|
pub const CursorPos = structs.CursorPos;
|
|
pub const IMEPos = structs.IMEPos;
|
|
pub const Selection = structs.Selection;
|
|
pub const SurfaceSize = structs.SurfaceSize;
|
|
|
|
/// The implementation to use for the app runtime. This is comptime chosen
|
|
/// so that every build has exactly one application runtime implementation.
|
|
/// Note: it is very rare to use Runtime directly; most usage will use
|
|
/// Window or something.
|
|
pub const runtime = switch (build_config.artifact) {
|
|
.exe => switch (build_config.app_runtime) {
|
|
.none => none,
|
|
.gtk => gtk,
|
|
},
|
|
.lib => embedded,
|
|
.wasm_module => browser,
|
|
};
|
|
|
|
pub const App = runtime.App;
|
|
pub const Surface = runtime.Surface;
|
|
|
|
/// True if all GPU operations (drawing, resource creation and
|
|
/// destruction) must happen on the app thread. This is the case
|
|
/// when the graphics context is owned by the app thread (GTK's
|
|
/// GLArea). When false, the render thread performs GPU operations
|
|
/// itself.
|
|
pub const must_draw_from_app_thread =
|
|
@hasDecl(App, "must_draw_from_app_thread") and
|
|
App.must_draw_from_app_thread;
|
|
|
|
test {
|
|
_ = Runtime;
|
|
_ = runtime;
|
|
_ = action;
|
|
_ = structs;
|
|
}
|