gpu: correctly allow unsetting Device.setLoggingCallback
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
2007542231
commit
ae5bb78e09
3 changed files with 16 additions and 12 deletions
|
|
@ -611,7 +611,7 @@ pub const Interface = struct {
|
||||||
procs.deviceSetLabel.?(@ptrCast(c.WGPUDevice, device), label);
|
procs.deviceSetLabel.?(@ptrCast(c.WGPUDevice, device), label);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn deviceSetLoggingCallback(device: *gpu.Device, callback: gpu.LoggingCallback, userdata: ?*anyopaque) void {
|
pub inline fn deviceSetLoggingCallback(device: *gpu.Device, callback: ?gpu.LoggingCallback, userdata: ?*anyopaque) void {
|
||||||
procs.deviceSetLoggingCallback.?(
|
procs.deviceSetLoggingCallback.?(
|
||||||
@ptrCast(c.WGPUDevice, device),
|
@ptrCast(c.WGPUDevice, device),
|
||||||
@ptrCast(c.WGPULoggingCallback, callback),
|
@ptrCast(c.WGPULoggingCallback, callback),
|
||||||
|
|
|
||||||
|
|
@ -282,19 +282,22 @@ pub const Device = opaque {
|
||||||
Impl.deviceSetLabel(device, label);
|
Impl.deviceSetLabel(device, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: presumably callback should be nullable for unsetting
|
|
||||||
pub inline fn setLoggingCallback(
|
pub inline fn setLoggingCallback(
|
||||||
device: *Device,
|
device: *Device,
|
||||||
context: anytype,
|
context: anytype,
|
||||||
comptime callback: fn (ctx: @TypeOf(context), typ: LoggingType, message: [*:0]const u8) callconv(.Inline) void,
|
comptime callback: ?fn (ctx: @TypeOf(context), typ: LoggingType, 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(typ: LoggingType, 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)), typ, message);
|
pub fn callback(typ: LoggingType, 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.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context);
|
};
|
||||||
|
Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context);
|
||||||
|
} else {
|
||||||
|
Impl.deviceSetLoggingCallback(device, null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn setUncapturedErrorCallback(
|
pub inline fn setUncapturedErrorCallback(
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ pub fn Interface(comptime T: type) type {
|
||||||
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);
|
||||||
assertDecl(T, "deviceTick", fn (device: *gpu.Device) 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, "deviceReference", fn (device: *gpu.Device) callconv(.Inline) void);
|
||||||
|
|
@ -699,8 +699,9 @@ pub fn Export(comptime T: type) type {
|
||||||
T.deviceSetLabel(device, label);
|
T.deviceSetLabel(device, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: dawn: callback not marked as nullable in dawn.json but in fact is.
|
||||||
// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata);
|
// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata);
|
||||||
export fn wgpuDeviceSetLoggingCallback(device: *gpu.Device, callback: gpu.LoggingCallback, userdata: ?*anyopaque) void {
|
export fn wgpuDeviceSetLoggingCallback(device: *gpu.Device, callback: ?gpu.LoggingCallback, userdata: ?*anyopaque) void {
|
||||||
T.deviceSetLoggingCallback(device, callback, userdata);
|
T.deviceSetLoggingCallback(device, callback, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue