mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
workaround for x86_64 ABI issue: https://github.com/ziglang/zig/issues/13598
This commit is contained in:
@ -83,6 +83,11 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
|
|
||||||
// Exe
|
// Exe
|
||||||
{
|
{
|
||||||
|
if (target.isDarwin()) {
|
||||||
|
// See the comment in this file
|
||||||
|
exe.addCSourceFile("src/renderer/metal_workaround.c", &.{});
|
||||||
|
}
|
||||||
|
|
||||||
exe.setTarget(target);
|
exe.setTarget(target);
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
exe.addOptions("build_options", exe_options);
|
exe.addOptions("build_options", exe_options);
|
||||||
|
@ -963,10 +963,10 @@ fn syncAtlasTexture(device: objc.Object, atlas: *const Atlas, texture: *objc.Obj
|
|||||||
texture.* = try initAtlasTexture(device, atlas);
|
texture.* = try initAtlasTexture(device, atlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture.msgSend(
|
// Workaround for: https://github.com/ziglang/zig/issues/13598
|
||||||
void,
|
ghostty_metal_replaceregion(
|
||||||
objc.sel("replaceRegion:mipmapLevel:withBytes:bytesPerRow:"),
|
texture.value,
|
||||||
.{
|
objc.sel("replaceRegion:mipmapLevel:withBytes:bytesPerRow:").value,
|
||||||
MTLRegion{
|
MTLRegion{
|
||||||
.origin = .{ .x = 0, .y = 0, .z = 0 },
|
.origin = .{ .x = 0, .y = 0, .z = 0 },
|
||||||
.size = .{
|
.size = .{
|
||||||
@ -978,10 +978,40 @@ fn syncAtlasTexture(device: objc.Object, atlas: *const Atlas, texture: *objc.Obj
|
|||||||
@as(c_ulong, 0),
|
@as(c_ulong, 0),
|
||||||
atlas.data.ptr,
|
atlas.data.ptr,
|
||||||
@as(c_ulong, atlas.format.depth() * atlas.size),
|
@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),
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "c" fn ghostty_metal_replaceregion(
|
||||||
|
objc.c.id,
|
||||||
|
objc.c.SEL,
|
||||||
|
MTLRegion,
|
||||||
|
c_ulong,
|
||||||
|
*anyopaque,
|
||||||
|
c_ulong,
|
||||||
|
) void;
|
||||||
|
|
||||||
/// Initialize the shader library.
|
/// Initialize the shader library.
|
||||||
fn initLibrary(device: objc.Object, data: []const u8) !objc.Object {
|
fn initLibrary(device: objc.Object, data: []const u8) !objc.Object {
|
||||||
const source = try macos.foundation.String.createWithBytes(
|
const source = try macos.foundation.String.createWithBytes(
|
||||||
|
35
src/renderer/metal_workaround.c
Normal file
35
src/renderer/metal_workaround.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Workaround for:
|
||||||
|
// https://github.com/ziglang/zig/issues/13598
|
||||||
|
|
||||||
|
#include <objc/message.h>
|
||||||
|
#include <objc/runtime.h>
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
Reference in New Issue
Block a user