gpu: correctly allow unsetting Device.setLostCallback
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
b28a01d2e8
commit
612c4420d6
3 changed files with 17 additions and 13 deletions
|
|
@ -599,7 +599,7 @@ pub const Interface = struct {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn deviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: ?*anyopaque) void {
|
pub inline fn deviceSetDeviceLostCallback(device: *gpu.Device, callback: ?gpu.Device.LostCallback, userdata: ?*anyopaque) void {
|
||||||
procs.deviceSetDeviceLostCallback.?(
|
procs.deviceSetDeviceLostCallback.?(
|
||||||
@ptrCast(c.WGPUDevice, device),
|
@ptrCast(c.WGPUDevice, device),
|
||||||
@ptrCast(c.WGPUDeviceLostCallback, callback),
|
@ptrCast(c.WGPUDeviceLostCallback, callback),
|
||||||
|
|
|
||||||
|
|
@ -260,19 +260,22 @@ pub const Device = opaque {
|
||||||
Impl.devicePushErrorScope(device, filter);
|
Impl.devicePushErrorScope(device, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: presumably callback should be nullable for unsetting
|
|
||||||
pub inline fn setDeviceLostCallback(
|
pub inline fn setDeviceLostCallback(
|
||||||
device: *Device,
|
device: *Device,
|
||||||
context: anytype,
|
context: anytype,
|
||||||
comptime callback: fn (ctx: @TypeOf(context), reason: LostReason, message: [*:0]const u8) callconv(.Inline) void,
|
comptime callback: ?fn (ctx: @TypeOf(context), reason: LostReason, message: [*:0]const u8) callconv(.Inline) void,
|
||||||
) void {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
if (callback) |cb| {
|
||||||
const Helper = struct {
|
const Context = @TypeOf(context);
|
||||||
pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
const Helper = struct {
|
||||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), reason, message);
|
pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||||
}
|
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), reason, message);
|
||||||
};
|
}
|
||||||
Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context);
|
};
|
||||||
|
Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context);
|
||||||
|
} else {
|
||||||
|
Impl.deviceSetDeviceLostCallback(device, null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn setLabel(device: *Device, label: [*:0]const u8) void {
|
pub inline fn setLabel(device: *Device, label: [*:0]const u8) void {
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ pub fn Interface(comptime T: type) type {
|
||||||
assertDecl(T, "deviceLoseForTesting", fn (device: *gpu.Device) callconv(.Inline) void);
|
assertDecl(T, "deviceLoseForTesting", fn (device: *gpu.Device) callconv(.Inline) void);
|
||||||
assertDecl(T, "devicePopErrorScope", fn (device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) callconv(.Inline) bool);
|
assertDecl(T, "devicePopErrorScope", fn (device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) callconv(.Inline) bool);
|
||||||
assertDecl(T, "devicePushErrorScope", fn (device: *gpu.Device, filter: gpu.ErrorFilter) callconv(.Inline) void);
|
assertDecl(T, "devicePushErrorScope", fn (device: *gpu.Device, filter: gpu.ErrorFilter) callconv(.Inline) void);
|
||||||
assertDecl(T, "deviceSetDeviceLostCallback", fn (device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: ?*anyopaque) callconv(.Inline) void);
|
assertDecl(T, "deviceSetDeviceLostCallback", fn (device: *gpu.Device, callback: ?gpu.Device.LostCallback, userdata: ?*anyopaque) callconv(.Inline) void);
|
||||||
assertDecl(T, "deviceSetLabel", fn (device: *gpu.Device, label: [*:0]const u8) callconv(.Inline) void);
|
assertDecl(T, "deviceSetLabel", fn (device: *gpu.Device, label: [*:0]const u8) callconv(.Inline) void);
|
||||||
assertDecl(T, "deviceSetLoggingCallback", fn (device: *gpu.Device, callback: gpu.LoggingCallback, userdata: ?*anyopaque) callconv(.Inline) void);
|
assertDecl(T, "deviceSetLoggingCallback", fn (device: *gpu.Device, callback: gpu.LoggingCallback, userdata: ?*anyopaque) callconv(.Inline) void);
|
||||||
assertDecl(T, "deviceSetUncapturedErrorCallback", fn (device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) callconv(.Inline) void);
|
assertDecl(T, "deviceSetUncapturedErrorCallback", fn (device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) callconv(.Inline) void);
|
||||||
|
|
@ -688,8 +688,9 @@ pub fn Export(comptime T: type) type {
|
||||||
T.devicePushErrorScope(device, filter);
|
T.devicePushErrorScope(device, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: dawn: callback not marked as nullable in dawn.json but in fact is.
|
||||||
// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata);
|
// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata);
|
||||||
export fn wgpuDeviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: ?*anyopaque) void {
|
export fn wgpuDeviceSetDeviceLostCallback(device: *gpu.Device, callback: ?gpu.Device.LostCallback, userdata: ?*anyopaque) void {
|
||||||
T.deviceSetDeviceLostCallback(device, callback, userdata);
|
T.deviceSetDeviceLostCallback(device, callback, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1791,7 +1792,7 @@ pub const StubInterface = Interface(struct {
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn deviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: ?*anyopaque) void {
|
pub inline fn deviceSetDeviceLostCallback(device: *gpu.Device, callback: ?gpu.Device.LostCallback, userdata: ?*anyopaque) void {
|
||||||
_ = device;
|
_ = device;
|
||||||
_ = callback;
|
_ = callback;
|
||||||
_ = userdata;
|
_ = userdata;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue