gpu: make Device.setLoggingCallback friendlier

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-31 13:30:51 -07:00 committed by Stephen Gutekanst
parent 6f2f7056b7
commit 29cd383f0e
6 changed files with 22 additions and 15 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {