diff --git a/gpu/src/adapter.zig b/gpu/src/adapter.zig index 7bae9fd3..7f7f9c19 100644 --- a/gpu/src/adapter.zig +++ b/gpu/src/adapter.zig @@ -88,11 +88,11 @@ pub const Adapter = opaque { status, device, message, - if (Context == void) {} orelse @ptrCast(Context, userdata), + if (Context == void) {} else @ptrCast(Context, userdata), ); } }; - Impl.adapterRequestDevice(adapter, descriptor, Helper.callback, if (Context == void) null orelse context); + Impl.adapterRequestDevice(adapter, descriptor, Helper.callback, if (Context == void) null else context); } pub inline fn reference(adapter: *Adapter) void { diff --git a/gpu/src/buffer.zig b/gpu/src/buffer.zig index fc87117d..c3569d91 100644 --- a/gpu/src/buffer.zig +++ b/gpu/src/buffer.zig @@ -100,10 +100,10 @@ pub const Buffer = opaque { ) void { const Helper = struct { pub fn callback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void { - callback(status, if (Context == void) {} orelse @ptrCast(Context, userdata)); + callback(status, if (Context == void) {} else @ptrCast(Context, userdata)); } }; - Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null orelse context); + Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null else context); } pub inline fn setLabel(buffer: *Buffer, label: [*:0]const u8) void { diff --git a/gpu/src/device.zig b/gpu/src/device.zig index ce270d03..3991b301 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -20,6 +20,7 @@ const RequiredLimits = @import("types.zig").RequiredLimits; const SupportedLimits = @import("types.zig").SupportedLimits; const ErrorType = @import("types.zig").ErrorType; const ErrorFilter = @import("types.zig").ErrorFilter; +const LoggingType = @import("types.zig").LoggingType; const LoggingCallback = @import("callbacks.zig").LoggingCallback; const ErrorCallback = @import("callbacks.zig").ErrorCallback; const CreateComputePipelineAsyncCallback = @import("callbacks.zig").CreateComputePipelineAsyncCallback; @@ -185,10 +186,16 @@ pub const Device = opaque { // TODO: presumably callback should be nullable for unsetting pub inline fn setLoggingCallback( device: *Device, - callback: LoggingCallback, - userdata: ?*anyopaque, + comptime Context: type, + comptime callback: fn (typ: LoggingType, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, + context: Context, ) void { - Impl.deviceSetLoggingCallback(device, callback, userdata); + const Helper = struct { + pub fn callback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { + callback(typ, message, if (Context == void) {} else @ptrCast(Context, userdata)); + } + }; + Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context); } // TODO: presumably callback should be nullable for unsetting @@ -200,10 +207,10 @@ pub const Device = opaque { ) void { const Helper = struct { pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { - callback(typ, message, if (Context == void) {} orelse @ptrCast(Context, userdata)); + callback(typ, message, if (Context == void) {} else @ptrCast(Context, userdata)); } }; - Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null orelse context); + Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context); } pub inline fn tick(device: *Device) void { diff --git a/gpu/src/instance.zig b/gpu/src/instance.zig index 4ef5961f..c9c3595e 100644 --- a/gpu/src/instance.zig +++ b/gpu/src/instance.zig @@ -38,11 +38,11 @@ pub const Instance = opaque { status, adapter, message, - if (Context == void) {} orelse @ptrCast(Context, userdata), + if (Context == void) {} else @ptrCast(Context, userdata), ); } }; - Impl.instanceRequestAdapter(instance, options, Helper.callback, if (Context == void) null orelse context); + Impl.instanceRequestAdapter(instance, options, Helper.callback, if (Context == void) null else context); } pub inline fn reference(instance: *Instance) void { diff --git a/gpu/src/queue.zig b/gpu/src/queue.zig index 44a792e7..3c0b08d8 100644 --- a/gpu/src/queue.zig +++ b/gpu/src/queue.zig @@ -39,10 +39,10 @@ pub const Queue = opaque { ) void { const Helper = struct { pub fn callback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void { - callback(status, if (Context == void) {} orelse @ptrCast(Context, userdata)); + callback(status, if (Context == void) {} else @ptrCast(Context, userdata)); } }; - Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.callback, if (Context == void) null orelse context); + Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.callback, if (Context == void) null else context); } pub inline fn setLabel(queue: *Queue, label: [*:0]const u8) void { diff --git a/gpu/src/shader_module.zig b/gpu/src/shader_module.zig index c943a8f7..982687b4 100644 --- a/gpu/src/shader_module.zig +++ b/gpu/src/shader_module.zig @@ -40,11 +40,11 @@ pub const ShaderModule = opaque { callback( status, compilation_info, - if (Context == void) {} orelse @ptrCast(Context, userdata), + if (Context == void) {} else @ptrCast(Context, userdata), ); } }; - Impl.shaderModuleGetCompilationInfo(shader_module, Helper.callback, if (Context == void) null orelse context); + Impl.shaderModuleGetCompilationInfo(shader_module, Helper.callback, if (Context == void) null else context); } pub inline fn setLabel(shader_module: *ShaderModule, label: [*:0]const u8) void {