mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
renderer/metal: load shaders from precompiled lib
This commit is contained in:
8
pkg/macos/dispatch.zig
Normal file
8
pkg/macos/dispatch.zig
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub const c = @import("dispatch/c.zig");
|
||||||
|
pub const data = @import("dispatch/data.zig");
|
||||||
|
pub const queue = @import("dispatch/queue.zig");
|
||||||
|
pub const Data = data.Data;
|
||||||
|
|
||||||
|
test {
|
||||||
|
@import("std").testing.refAllDecls(@This());
|
||||||
|
}
|
3
pkg/macos/dispatch/c.zig
Normal file
3
pkg/macos/dispatch/c.zig
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub usingnamespace @cImport({
|
||||||
|
@cInclude("dispatch/dispatch.h");
|
||||||
|
});
|
31
pkg/macos/dispatch/data.zig
Normal file
31
pkg/macos/dispatch/data.zig
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const foundation = @import("../foundation.zig");
|
||||||
|
const c = @import("c.zig");
|
||||||
|
|
||||||
|
pub const Data = opaque {
|
||||||
|
pub const DESTRUCTOR_DEFAULT = c.DISPATCH_DATA_DESTRUCTOR_DEFAULT;
|
||||||
|
|
||||||
|
pub fn create(
|
||||||
|
data: []const u8,
|
||||||
|
queue: ?*anyopaque,
|
||||||
|
destructor: ?*anyopaque,
|
||||||
|
) !*Data {
|
||||||
|
return dispatch_data_create(
|
||||||
|
data.ptr,
|
||||||
|
data.len,
|
||||||
|
queue,
|
||||||
|
destructor,
|
||||||
|
) orelse return error.OutOfMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn release(data: *Data) void {
|
||||||
|
foundation.c.CFRelease(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "c" fn dispatch_data_create(
|
||||||
|
data: [*]const u8,
|
||||||
|
len: usize,
|
||||||
|
queue: ?*anyopaque,
|
||||||
|
destructor: ?*anyopaque,
|
||||||
|
) ?*Data;
|
8
pkg/macos/dispatch/queue.zig
Normal file
8
pkg/macos/dispatch/queue.zig
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const c = @import("c.zig");
|
||||||
|
|
||||||
|
pub const Queue = *anyopaque; // dispatch_queue_t
|
||||||
|
|
||||||
|
pub fn getMain() Queue {
|
||||||
|
return c.dispatch_get_main_queue().?;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
pub const foundation = @import("foundation.zig");
|
pub const foundation = @import("foundation.zig");
|
||||||
pub const animation = @import("animation.zig");
|
pub const animation = @import("animation.zig");
|
||||||
|
pub const dispatch = @import("dispatch.zig");
|
||||||
pub const graphics = @import("graphics.zig");
|
pub const graphics = @import("graphics.zig");
|
||||||
pub const os = @import("os.zig");
|
pub const os = @import("os.zig");
|
||||||
pub const text = @import("text.zig");
|
pub const text = @import("text.zig");
|
||||||
|
@ -156,27 +156,29 @@ pub const PostUniforms = extern struct {
|
|||||||
|
|
||||||
/// Initialize the MTLLibrary. A MTLLibrary is a collection of shaders.
|
/// Initialize the MTLLibrary. A MTLLibrary is a collection of shaders.
|
||||||
fn initLibrary(device: objc.Object) !objc.Object {
|
fn initLibrary(device: objc.Object) !objc.Object {
|
||||||
// Hardcoded since this file isn't meant to be reusable.
|
const start = try std.time.Instant.now();
|
||||||
const data = @embedFile("../shaders/cell.metal");
|
|
||||||
const source = try macos.foundation.String.createWithBytes(
|
const data = try macos.dispatch.Data.create(
|
||||||
data,
|
@embedFile("../shaders/Ghostty.metallib"),
|
||||||
.utf8,
|
macos.dispatch.queue.getMain(),
|
||||||
false,
|
macos.dispatch.Data.DESTRUCTOR_DEFAULT,
|
||||||
);
|
);
|
||||||
defer source.release();
|
defer data.release();
|
||||||
|
|
||||||
var err: ?*anyopaque = null;
|
var err: ?*anyopaque = null;
|
||||||
const library = device.msgSend(
|
const library = device.msgSend(
|
||||||
objc.Object,
|
objc.Object,
|
||||||
objc.sel("newLibraryWithSource:options:error:"),
|
objc.sel("newLibraryWithData:error:"),
|
||||||
.{
|
.{
|
||||||
source,
|
data,
|
||||||
@as(?*anyopaque, null),
|
|
||||||
&err,
|
&err,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
try checkError(err);
|
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});
|
||||||
|
|
||||||
return library;
|
return library;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user