mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
iOS: Fix crash on device
This commit is contained in:
@ -209,20 +209,31 @@ pub const GPUState = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn chooseDevice() error{NoMetalDevice}!objc.Object {
|
fn chooseDevice() error{NoMetalDevice}!objc.Object {
|
||||||
const devices = objc.Object.fromId(mtl.MTLCopyAllDevices());
|
|
||||||
defer devices.release();
|
|
||||||
var chosen_device: ?objc.Object = null;
|
var chosen_device: ?objc.Object = null;
|
||||||
var iter = devices.iterate();
|
|
||||||
while (iter.next()) |device| {
|
switch (comptime builtin.os.tag) {
|
||||||
// We want a GPU that’s connected to a display.
|
.macos => {
|
||||||
if (device.getProperty(bool, "isHeadless")) continue;
|
const devices = objc.Object.fromId(mtl.MTLCopyAllDevices());
|
||||||
chosen_device = device;
|
defer devices.release();
|
||||||
// If the user has an eGPU plugged in, they probably want
|
|
||||||
// to use it. Otherwise, integrated GPUs are better for
|
var iter = devices.iterate();
|
||||||
// battery life and thermals.
|
while (iter.next()) |device| {
|
||||||
if (device.getProperty(bool, "isRemovable") or
|
// We want a GPU that’s connected to a display.
|
||||||
device.getProperty(bool, "isLowPower")) break;
|
if (device.getProperty(bool, "isHeadless")) continue;
|
||||||
|
chosen_device = device;
|
||||||
|
// If the user has an eGPU plugged in, they probably want
|
||||||
|
// to use it. Otherwise, integrated GPUs are better for
|
||||||
|
// battery life and thermals.
|
||||||
|
if (device.getProperty(bool, "isRemovable") or
|
||||||
|
device.getProperty(bool, "isLowPower")) break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.ios => {
|
||||||
|
chosen_device = objc.Object.fromId(mtl.MTLCreateSystemDefaultDevice());
|
||||||
|
},
|
||||||
|
else => @compileError("unsupported target for Metal"),
|
||||||
}
|
}
|
||||||
|
|
||||||
const device = chosen_device orelse return error.NoMetalDevice;
|
const device = chosen_device orelse return error.NoMetalDevice;
|
||||||
return device.retain();
|
return device.retain();
|
||||||
}
|
}
|
||||||
|
@ -175,4 +175,8 @@ pub const MTLSize = extern struct {
|
|||||||
depth: c_ulong,
|
depth: c_ulong,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// https://developer.apple.com/documentation/metal/1433367-mtlcopyalldevices
|
||||||
pub extern "c" fn MTLCopyAllDevices() ?*anyopaque;
|
pub extern "c" fn MTLCopyAllDevices() ?*anyopaque;
|
||||||
|
|
||||||
|
/// https://developer.apple.com/documentation/metal/1433401-mtlcreatesystemdefaultdevice
|
||||||
|
pub extern "c" fn MTLCreateSystemDefaultDevice() ?*anyopaque;
|
||||||
|
Reference in New Issue
Block a user