From f537d7aab1560bc02df6350c78c0c9a319331a98 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 1 Jul 2023 15:14:24 -0700 Subject: [PATCH] renderer: remove metal workaround, this caused crashes on x86_64 And it now works. --- build.zig | 5 --- src/renderer/Metal.zig | 61 +++++++++------------------------ src/renderer/metal_workaround.c | 35 ------------------- 3 files changed, 17 insertions(+), 84 deletions(-) delete mode 100644 src/renderer/metal_workaround.c diff --git a/build.zig b/build.zig index 03374692f..400872fbc 100644 --- a/build.zig +++ b/build.zig @@ -213,11 +213,6 @@ pub fn build(b: *std.Build) !void { { exe.addOptions("build_options", exe_options); - if (target.isDarwin()) { - // See the comment in this file - exe.addCSourceFile("src/renderer/metal_workaround.c", &.{}); - } - // Add the shared dependencies _ = try addDeps(b, exe, static); diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 760a2813b..9a704db01 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -1176,55 +1176,28 @@ fn syncAtlasTexture(device: objc.Object, atlas: *const font.Atlas, texture: *obj texture.* = try initAtlasTexture(device, atlas); } - // Workaround for: https://github.com/ziglang/zig/issues/13598 - ghostty_metal_replaceregion( - texture.value, - objc.sel("replaceRegion:mipmapLevel:withBytes:bytesPerRow:").value, - MTLRegion{ - .origin = .{ .x = 0, .y = 0, .z = 0 }, - .size = .{ - .width = @intCast(atlas.size), - .height = @intCast(atlas.size), - .depth = 1, - }, - }, - 0, - atlas.data.ptr, - @as(c_ulong, atlas.format.depth() * atlas.size), - ); - // Once the above linked issue is fixed, this is what we actually // want to do: // - // texture.msgSend( - // void, - // objc.sel("replaceRegion:mipmapLevel:withBytes:bytesPerRow:"), - // .{ - // MTLRegion{ - // .origin = .{ .x = 0, .y = 0, .z = 0 }, - // .size = .{ - // .width = @intCast(c_ulong, atlas.size), - // .height = @intCast(c_ulong, atlas.size), - // .depth = 1, - // }, - // }, - // @as(c_ulong, 0), - // atlas.data.ptr, - // @as(c_ulong, atlas.format.depth() * atlas.size), - // }, - // ); - + texture.msgSend( + void, + objc.sel("replaceRegion:mipmapLevel:withBytes:bytesPerRow:"), + .{ + MTLRegion{ + .origin = .{ .x = 0, .y = 0, .z = 0 }, + .size = .{ + .width = @intCast(atlas.size), + .height = @intCast(atlas.size), + .depth = 1, + }, + }, + @as(c_ulong, 0), + atlas.data.ptr, + @as(c_ulong, atlas.format.depth() * atlas.size), + }, + ); } -extern "c" fn ghostty_metal_replaceregion( - objc.c.id, - objc.c.SEL, - MTLRegion, - c_ulong, - *anyopaque, - c_ulong, -) void; - /// Initialize the shader library. fn initLibrary(device: objc.Object, data: []const u8) !objc.Object { const source = try macos.foundation.String.createWithBytes( diff --git a/src/renderer/metal_workaround.c b/src/renderer/metal_workaround.c deleted file mode 100644 index 018fbe61b..000000000 --- a/src/renderer/metal_workaround.c +++ /dev/null @@ -1,35 +0,0 @@ -// Workaround for: -// https://github.com/ziglang/zig/issues/13598 - -#include -#include - -// From Metal.h -typedef struct Origin { - unsigned long x; - unsigned long y; - unsigned long z; -} Origin; - -typedef struct Size { - unsigned long width; - unsigned long height; - unsigned long depth; -} Size; - -typedef struct MTLRegion { - Origin origin; - Size size; -} MTLRegion; - -void ghostty_metal_replaceregion( - id target, - SEL sel, - MTLRegion region, - unsigned long offset, - void *ptr, - unsigned long len -) { - void (*replaceRegion)(id, SEL, MTLRegion, unsigned long, void *, unsigned long) = (void (*)(id, SEL, MTLRegion, unsigned long, void *, unsigned long)) objc_msgSend; - replaceRegion(target, sel, region, offset, ptr, len); -}