aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/renderer/metal
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/renderer/metal
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/renderer/metal')
-rw-r--r--vendor/libghostty-vt/src/renderer/metal/IOSurfaceLayer.zig4
-rw-r--r--vendor/libghostty-vt/src/renderer/metal/api.zig9
-rw-r--r--vendor/libghostty-vt/src/renderer/metal/buffer.zig8
-rw-r--r--vendor/libghostty-vt/src/renderer/metal/shaders.zig30
4 files changed, 22 insertions, 29 deletions
diff --git a/vendor/libghostty-vt/src/renderer/metal/IOSurfaceLayer.zig b/vendor/libghostty-vt/src/renderer/metal/IOSurfaceLayer.zig
index 34fbfbed..cd97126a 100644
--- a/vendor/libghostty-vt/src/renderer/metal/IOSurfaceLayer.zig
+++ b/vendor/libghostty-vt/src/renderer/metal/IOSurfaceLayer.zig
@@ -40,6 +40,10 @@ pub fn init() !IOSurfaceLayer {
}
pub fn release(self: *IOSurfaceLayer) void {
+ // The layer may be retained by the view after we release our reference.
+ // Clear the callback first so that a later display pass can't access the
+ // renderer that owned this wrapper after it has been freed.
+ self.setDisplayCallback(null, null);
self.layer.release();
}
diff --git a/vendor/libghostty-vt/src/renderer/metal/api.zig b/vendor/libghostty-vt/src/renderer/metal/api.zig
index a2d8a135..8c195e0f 100644
--- a/vendor/libghostty-vt/src/renderer/metal/api.zig
+++ b/vendor/libghostty-vt/src/renderer/metal/api.zig
@@ -43,9 +43,7 @@ pub const MTLResourceOptions = packed struct(c_ulong) {
/// https://developer.apple.com/documentation/metal/mtlhazardtrackingmode?language=objc
hazard_tracking_mode: HazardTrackingMode = .default,
- _pad: @Type(.{
- .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(c_ulong) - 10 },
- }) = 0,
+ _pad: @Int(.unsigned, @bitSizeOf(c_ulong) - 10) = 0,
pub const CPUCacheMode = enum(u4) {
default = 0,
@@ -366,10 +364,7 @@ pub const MTLTextureUsage = packed struct(c_ulong) {
/// https://developer.apple.com/documentation/metal/mtltextureusage/shaderatomic?language=objc
shader_atomic: bool = false, // TextureUsageShaderAtomic = 32,
- __reserved: @Type(.{ .int = .{
- .signedness = .unsigned,
- .bits = @bitSizeOf(c_ulong) - 6,
- } }) = 0,
+ __reserved: @Int(.unsigned, @bitSizeOf(c_ulong) - 6) = 0,
/// https://developer.apple.com/documentation/metal/mtltextureusage/unknown?language=objc
const unknown: MTLTextureUsage = @bitCast(0); // TextureUsageUnknown = 0,
diff --git a/vendor/libghostty-vt/src/renderer/metal/buffer.zig b/vendor/libghostty-vt/src/renderer/metal/buffer.zig
index f91f89e9..d892da2a 100644
--- a/vendor/libghostty-vt/src/renderer/metal/buffer.zig
+++ b/vendor/libghostty-vt/src/renderer/metal/buffer.zig
@@ -81,12 +81,12 @@ pub fn Buffer(comptime T: type) type {
self.buffer.msgSend(void, objc.sel("release"), .{});
// Allocate a new buffer with enough to hold double what we require.
- const size = req_bytes * 2;
+ self.len = data.len * 2;
self.buffer = self.opts.device.msgSend(
objc.Object,
objc.sel("newBufferWithLength:options:"),
.{
- @as(c_ulong, @intCast(size * @sizeOf(T))),
+ @as(c_ulong, @intCast(self.len * @sizeOf(T))),
self.opts.resource_options,
},
);
@@ -138,12 +138,12 @@ pub fn Buffer(comptime T: type) type {
self.buffer.msgSend(void, objc.sel("release"), .{});
// Allocate a new buffer with enough to hold double what we require.
- const size = req_bytes * 2;
+ self.len = total_len * 2;
self.buffer = self.opts.device.msgSend(
objc.Object,
objc.sel("newBufferWithLength:options:"),
.{
- @as(c_ulong, @intCast(size * @sizeOf(T))),
+ @as(c_ulong, @intCast(self.len * @sizeOf(T))),
self.opts.resource_options,
},
);
diff --git a/vendor/libghostty-vt/src/renderer/metal/shaders.zig b/vendor/libghostty-vt/src/renderer/metal/shaders.zig
index 0be02357..6ae32106 100644
--- a/vendor/libghostty-vt/src/renderer/metal/shaders.zig
+++ b/vendor/libghostty-vt/src/renderer/metal/shaders.zig
@@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
const macos = @import("macos");
const objc = @import("objc");
const math = @import("../../math.zig");
+const global = @import("../../global.zig");
const mtl = @import("api.zig");
const Pipeline = @import("Pipeline.zig");
@@ -76,22 +77,16 @@ const PipelineDescription = struct {
/// We create a type for the pipeline collection based on our desc array.
const PipelineCollection = t: {
- var fields: [pipeline_descs.len]std.builtin.Type.StructField = undefined;
- for (pipeline_descs, 0..) |pipeline, i| {
- fields[i] = .{
- .name = pipeline[0],
- .type = Pipeline,
- .default_value_ptr = null,
- .is_comptime = false,
- .alignment = @alignOf(Pipeline),
- };
+ const StructField = std.builtin.Type.StructField;
+
+ var names: [pipeline_descs.len][]const u8 = undefined;
+ var types = [_]type{Pipeline} ** pipeline_descs.len;
+ var attrs = [_]StructField.Attributes{.{ .@"align" = @alignOf(Pipeline) }} ** pipeline_descs.len;
+
+ for (pipeline_descs, &names) |pipeline, *name| {
+ name.* = pipeline[0];
}
- break :t @Type(.{ .@"struct" = .{
- .layout = .auto,
- .fields = &fields,
- .decls = &.{},
- .is_tuple = false,
- } });
+ break :t @Struct(.auto, null, &names, &types, &attrs);
};
/// This contains the state for the shaders used by the Metal renderer.
@@ -332,7 +327,7 @@ pub const BgImage = extern struct {
/// Initialize the MTLLibrary. A MTLLibrary is a collection of shaders.
fn initLibrary(device: objc.Object) !objc.Object {
- const start = try std.time.Instant.now();
+ const start: std.Io.Timestamp = .now(global.io(), .awake);
const data = try macos.dispatch.Data.create(
@embedFile("ghostty_metallib"),
@@ -352,8 +347,7 @@ fn initLibrary(device: objc.Object) !objc.Object {
);
try checkError(err);
- const end = try std.time.Instant.now();
- log.debug("shader library loaded time={}us", .{end.since(start) / std.time.ns_per_us});
+ log.debug("shader library loaded time={}us", .{start.untilNow(global.io(), .awake).toMicroseconds()});
return library;
}