gpu: correctly allow unsetting Device.setUncapturedErrorCallback

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-16 21:29:06 -07:00
parent 612c4420d6
commit 2007542231
4 changed files with 18 additions and 14 deletions

View file

@ -619,7 +619,7 @@ pub const Interface = struct {
);
}
pub inline fn deviceSetUncapturedErrorCallback(device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) void {
pub inline fn deviceSetUncapturedErrorCallback(device: *gpu.Device, callback: ?gpu.ErrorCallback, userdata: ?*anyopaque) void {
procs.deviceSetUncapturedErrorCallback.?(
@ptrCast(c.WGPUDevice, device),
@ptrCast(c.WGPUErrorCallback, callback),

View file

@ -297,19 +297,22 @@ pub const Device = opaque {
Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context);
}
// TODO: presumably callback should be nullable for unsetting
pub inline fn setUncapturedErrorCallback(
device: *Device,
context: anytype,
comptime callback: fn (ctx: @TypeOf(context), typ: ErrorType, message: [*:0]const u8) callconv(.Inline) void,
comptime callback: ?fn (ctx: @TypeOf(context), typ: ErrorType, message: [*:0]const u8) callconv(.Inline) void,
) void {
const Context = @TypeOf(context);
const Helper = struct {
pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message);
}
};
Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context);
if (callback) |cb| {
const Context = @TypeOf(context);
const Helper = struct {
pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message);
}
};
Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context);
} else {
Impl.deviceSetUncapturedErrorCallback(device, null, null);
}
}
pub inline fn tick(device: *Device) void {

View file

@ -112,7 +112,7 @@ pub fn Interface(comptime T: type) type {
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, "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);
assertDecl(T, "deviceTick", fn (device: *gpu.Device) callconv(.Inline) void);
assertDecl(T, "deviceReference", fn (device: *gpu.Device) callconv(.Inline) void);
assertDecl(T, "deviceRelease", fn (device: *gpu.Device) callconv(.Inline) void);
@ -704,8 +704,9 @@ pub fn Export(comptime T: type) type {
T.deviceSetLoggingCallback(device, callback, userdata);
}
// TODO: dawn: callback not marked as nullable in dawn.json but in fact is.
// WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
export fn wgpuDeviceSetUncapturedErrorCallback(device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) void {
export fn wgpuDeviceSetUncapturedErrorCallback(device: *gpu.Device, callback: ?gpu.ErrorCallback, userdata: ?*anyopaque) void {
T.deviceSetUncapturedErrorCallback(device, callback, userdata);
}
@ -1812,7 +1813,7 @@ pub const StubInterface = Interface(struct {
unreachable;
}
pub inline fn deviceSetUncapturedErrorCallback(device: *gpu.Device, callback: gpu.ErrorCallback, userdata: ?*anyopaque) void {
pub inline fn deviceSetUncapturedErrorCallback(device: *gpu.Device, callback: ?gpu.ErrorCallback, userdata: ?*anyopaque) void {
_ = device;
_ = callback;
_ = userdata;

View file

@ -30,7 +30,7 @@ pub const Queue = opaque {
Impl.queueCopyTextureForBrowser(queue, source, destination, copy_size, options);
}
// TODO: presumably callback should be nullable for unsetting
// TODO: dawn: does not allow unsetting this callback to null
pub inline fn onSubmittedWorkDone(
queue: *Queue,
signal_value: u64,