gpu: implement Device.setLoggingCallback
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
a0d28a74b0
commit
e7526a868d
3 changed files with 62 additions and 3 deletions
|
|
@ -10,7 +10,9 @@ const Feature = @import("enums.zig").Feature;
|
|||
const ErrorType = @import("enums.zig").ErrorType;
|
||||
const ErrorFilter = @import("enums.zig").ErrorFilter;
|
||||
const Limits = @import("data.zig").Limits;
|
||||
const LoggingType = @import("enums.zig").LoggingType;
|
||||
const ErrorCallback = @import("structs.zig").ErrorCallback;
|
||||
const LoggingCallback = @import("structs.zig").LoggingCallback;
|
||||
const Queue = @import("Queue.zig");
|
||||
const ShaderModule = @import("ShaderModule.zig");
|
||||
const Surface = @import("Surface.zig");
|
||||
|
|
@ -76,9 +78,7 @@ pub const VTable = struct {
|
|||
popErrorScope: fn (ptr: *anyopaque, callback: *ErrorCallback) bool,
|
||||
pushErrorScope: fn (ptr: *anyopaque, filter: ErrorFilter) void,
|
||||
setLostCallback: fn (ptr: *anyopaque, callback: *LostCallback) void,
|
||||
// TODO: callback
|
||||
// setLoggingCallback: fn (ptr: *anyopaque, callback: LoggingCallback) void,
|
||||
// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata);
|
||||
setLoggingCallback: fn (ptr: *anyopaque, callback: *LoggingCallback) void,
|
||||
setUncapturedErrorCallback: fn (ptr: *anyopaque, callback: *ErrorCallback) void,
|
||||
tick: fn (ptr: *anyopaque) void,
|
||||
};
|
||||
|
|
@ -220,6 +220,10 @@ pub inline fn createRenderPipelineAsync(
|
|||
device.vtable.createRenderPipelineAsync(device.ptr, descriptor, callback);
|
||||
}
|
||||
|
||||
pub inline fn setLoggingCallback(device: Device, callback: *LoggingCallback) void {
|
||||
device.vtable.setLoggingCallback(device.ptr, callback);
|
||||
}
|
||||
|
||||
pub inline fn setUncapturedErrorCallback(device: Device, callback: *ErrorCallback) void {
|
||||
device.vtable.setUncapturedErrorCallback(device.ptr, callback);
|
||||
}
|
||||
|
|
@ -267,6 +271,8 @@ test {
|
|||
_ = createRenderBundleEncoder;
|
||||
_ = createRenderPipeline;
|
||||
_ = createRenderPipelineAsync;
|
||||
_ = setLoggingCallback;
|
||||
_ = setUncapturedErrorCallback;
|
||||
_ = tick;
|
||||
_ = Descriptor;
|
||||
_ = LostReason;
|
||||
|
|
|
|||
|
|
@ -46,10 +46,12 @@ const PresentMode = @import("enums.zig").PresentMode;
|
|||
const IndexFormat = @import("enums.zig").IndexFormat;
|
||||
const ErrorType = @import("enums.zig").ErrorType;
|
||||
const ErrorFilter = @import("enums.zig").ErrorFilter;
|
||||
const LoggingType = @import("enums.zig").LoggingType;
|
||||
|
||||
const ImageCopyBuffer = @import("structs.zig").ImageCopyBuffer;
|
||||
const ImageCopyTexture = @import("structs.zig").ImageCopyTexture;
|
||||
const ErrorCallback = @import("structs.zig").ErrorCallback;
|
||||
const LoggingCallback = @import("structs.zig").LoggingCallback;
|
||||
|
||||
const NativeInstance = @This();
|
||||
|
||||
|
|
@ -723,6 +725,33 @@ const device_vtable = Device.VTable{
|
|||
);
|
||||
}
|
||||
}).setUncapturedErrorCallback,
|
||||
.setLoggingCallback = (struct {
|
||||
pub fn setLoggingCallback(
|
||||
ptr: *anyopaque,
|
||||
callback: *LoggingCallback,
|
||||
) void {
|
||||
const cCallback = (struct {
|
||||
pub fn cCallback(
|
||||
typ: c.WGPULoggingType,
|
||||
message: [*c]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const callback_info = @ptrCast(*LoggingCallback, @alignCast(@alignOf(*LoggingCallback), userdata));
|
||||
callback_info.type_erased_callback(
|
||||
callback_info.type_erased_ctx,
|
||||
@intToEnum(LoggingType, typ),
|
||||
std.mem.span(message),
|
||||
);
|
||||
}
|
||||
}).cCallback;
|
||||
|
||||
return c.wgpuDeviceSetLoggingCallback(
|
||||
@ptrCast(c.WGPUDevice, ptr),
|
||||
cCallback,
|
||||
callback,
|
||||
);
|
||||
}
|
||||
}).setLoggingCallback,
|
||||
.tick = (struct {
|
||||
pub fn tick(ptr: *anyopaque) void {
|
||||
c.wgpuDeviceTick(@ptrCast(c.WGPUDevice, ptr));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ const LoadOp = @import("enums.zig").LoadOp;
|
|||
const StoreOp = @import("enums.zig").StoreOp;
|
||||
const ColorWriteMask = @import("enums.zig").ColorWriteMask;
|
||||
const ErrorType = @import("enums.zig").ErrorType;
|
||||
const LoggingType = @import("enums.zig").LoggingType;
|
||||
|
||||
pub const MultisampleState = struct {
|
||||
count: u32,
|
||||
|
|
@ -159,6 +160,28 @@ pub const ErrorCallback = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub const LoggingCallback = struct {
|
||||
type_erased_ctx: *anyopaque,
|
||||
type_erased_callback: fn (ctx: *anyopaque, typ: LoggingType, message: [*:0]const u8) callconv(.Inline) void,
|
||||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, typ: LoggingType, message: [*:0]const u8) void,
|
||||
) LoggingCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, typ: LoggingType, message: [*:0]const u8) void {
|
||||
callback(@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)), typ, message);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
test {
|
||||
_ = MultisampleState;
|
||||
_ = PrimitiveState;
|
||||
|
|
@ -175,4 +198,5 @@ test {
|
|||
_ = ImageCopyBuffer;
|
||||
_ = ImageCopyTexture;
|
||||
_ = ErrorCallback;
|
||||
_ = LoggingCallback;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue