From 12be06c4af5df36dc63f9e8534c393b853042aa4 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 24 Jun 2023 21:30:54 -0700 Subject: [PATCH] core: temporarily handle device loss internally Signed-off-by: Stephen Gutekanst --- libs/core/src/platform/native/Core.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/core/src/platform/native/Core.zig b/libs/core/src/platform/native/Core.zig index e691cf86..e95005ff 100644 --- a/libs/core/src/platform/native/Core.zig +++ b/libs/core/src/platform/native/Core.zig @@ -63,6 +63,15 @@ const UserPtr = struct { self: *Core, }; +// TODO(core): expose device loss to users, this can happen especially in the web and on mobile +// devices. Users will need to re-upload all assets to the GPU in this event. +fn deviceLostCallback(reason: gpu.Device.LostReason, msg: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { + _ = userdata; + _ = reason; + log.err("mach: device lost: {s}", .{msg}); + @panic("mach: device lost"); +} + pub fn init(core: *Core, allocator: std.mem.Allocator, options: Options) !void { const backend_type = try util.detectBackendType(allocator); @@ -147,6 +156,8 @@ pub fn init(core: *Core, allocator: std.mem.Allocator, options: Options) !void { .required_limits = if (options.required_limits) |limits| @as(?*const gpu.RequiredLimits, &gpu.RequiredLimits{ .limits = limits, }) else null, + .device_lost_callback = &deviceLostCallback, + .device_lost_userdata = null, }) orelse { log.err("failed to create GPU device\n", .{}); std.process.exit(1);