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 ErrorType = @import("enums.zig").ErrorType;
|
||||||
const ErrorFilter = @import("enums.zig").ErrorFilter;
|
const ErrorFilter = @import("enums.zig").ErrorFilter;
|
||||||
const Limits = @import("data.zig").Limits;
|
const Limits = @import("data.zig").Limits;
|
||||||
|
const LoggingType = @import("enums.zig").LoggingType;
|
||||||
const ErrorCallback = @import("structs.zig").ErrorCallback;
|
const ErrorCallback = @import("structs.zig").ErrorCallback;
|
||||||
|
const LoggingCallback = @import("structs.zig").LoggingCallback;
|
||||||
const Queue = @import("Queue.zig");
|
const Queue = @import("Queue.zig");
|
||||||
const ShaderModule = @import("ShaderModule.zig");
|
const ShaderModule = @import("ShaderModule.zig");
|
||||||
const Surface = @import("Surface.zig");
|
const Surface = @import("Surface.zig");
|
||||||
|
|
@ -76,9 +78,7 @@ pub const VTable = struct {
|
||||||
popErrorScope: fn (ptr: *anyopaque, callback: *ErrorCallback) bool,
|
popErrorScope: fn (ptr: *anyopaque, callback: *ErrorCallback) bool,
|
||||||
pushErrorScope: fn (ptr: *anyopaque, filter: ErrorFilter) void,
|
pushErrorScope: fn (ptr: *anyopaque, filter: ErrorFilter) void,
|
||||||
setLostCallback: fn (ptr: *anyopaque, callback: *LostCallback) void,
|
setLostCallback: fn (ptr: *anyopaque, callback: *LostCallback) void,
|
||||||
// TODO: callback
|
setLoggingCallback: fn (ptr: *anyopaque, callback: *LoggingCallback) void,
|
||||||
// setLoggingCallback: fn (ptr: *anyopaque, callback: LoggingCallback) void,
|
|
||||||
// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata);
|
|
||||||
setUncapturedErrorCallback: fn (ptr: *anyopaque, callback: *ErrorCallback) void,
|
setUncapturedErrorCallback: fn (ptr: *anyopaque, callback: *ErrorCallback) void,
|
||||||
tick: fn (ptr: *anyopaque) void,
|
tick: fn (ptr: *anyopaque) void,
|
||||||
};
|
};
|
||||||
|
|
@ -220,6 +220,10 @@ pub inline fn createRenderPipelineAsync(
|
||||||
device.vtable.createRenderPipelineAsync(device.ptr, descriptor, callback);
|
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 {
|
pub inline fn setUncapturedErrorCallback(device: Device, callback: *ErrorCallback) void {
|
||||||
device.vtable.setUncapturedErrorCallback(device.ptr, callback);
|
device.vtable.setUncapturedErrorCallback(device.ptr, callback);
|
||||||
}
|
}
|
||||||
|
|
@ -267,6 +271,8 @@ test {
|
||||||
_ = createRenderBundleEncoder;
|
_ = createRenderBundleEncoder;
|
||||||
_ = createRenderPipeline;
|
_ = createRenderPipeline;
|
||||||
_ = createRenderPipelineAsync;
|
_ = createRenderPipelineAsync;
|
||||||
|
_ = setLoggingCallback;
|
||||||
|
_ = setUncapturedErrorCallback;
|
||||||
_ = tick;
|
_ = tick;
|
||||||
_ = Descriptor;
|
_ = Descriptor;
|
||||||
_ = LostReason;
|
_ = LostReason;
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,12 @@ const PresentMode = @import("enums.zig").PresentMode;
|
||||||
const IndexFormat = @import("enums.zig").IndexFormat;
|
const IndexFormat = @import("enums.zig").IndexFormat;
|
||||||
const ErrorType = @import("enums.zig").ErrorType;
|
const ErrorType = @import("enums.zig").ErrorType;
|
||||||
const ErrorFilter = @import("enums.zig").ErrorFilter;
|
const ErrorFilter = @import("enums.zig").ErrorFilter;
|
||||||
|
const LoggingType = @import("enums.zig").LoggingType;
|
||||||
|
|
||||||
const ImageCopyBuffer = @import("structs.zig").ImageCopyBuffer;
|
const ImageCopyBuffer = @import("structs.zig").ImageCopyBuffer;
|
||||||
const ImageCopyTexture = @import("structs.zig").ImageCopyTexture;
|
const ImageCopyTexture = @import("structs.zig").ImageCopyTexture;
|
||||||
const ErrorCallback = @import("structs.zig").ErrorCallback;
|
const ErrorCallback = @import("structs.zig").ErrorCallback;
|
||||||
|
const LoggingCallback = @import("structs.zig").LoggingCallback;
|
||||||
|
|
||||||
const NativeInstance = @This();
|
const NativeInstance = @This();
|
||||||
|
|
||||||
|
|
@ -723,6 +725,33 @@ const device_vtable = Device.VTable{
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}).setUncapturedErrorCallback,
|
}).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 {
|
.tick = (struct {
|
||||||
pub fn tick(ptr: *anyopaque) void {
|
pub fn tick(ptr: *anyopaque) void {
|
||||||
c.wgpuDeviceTick(@ptrCast(c.WGPUDevice, ptr));
|
c.wgpuDeviceTick(@ptrCast(c.WGPUDevice, ptr));
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ const LoadOp = @import("enums.zig").LoadOp;
|
||||||
const StoreOp = @import("enums.zig").StoreOp;
|
const StoreOp = @import("enums.zig").StoreOp;
|
||||||
const ColorWriteMask = @import("enums.zig").ColorWriteMask;
|
const ColorWriteMask = @import("enums.zig").ColorWriteMask;
|
||||||
const ErrorType = @import("enums.zig").ErrorType;
|
const ErrorType = @import("enums.zig").ErrorType;
|
||||||
|
const LoggingType = @import("enums.zig").LoggingType;
|
||||||
|
|
||||||
pub const MultisampleState = struct {
|
pub const MultisampleState = struct {
|
||||||
count: u32,
|
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 {
|
test {
|
||||||
_ = MultisampleState;
|
_ = MultisampleState;
|
||||||
_ = PrimitiveState;
|
_ = PrimitiveState;
|
||||||
|
|
@ -175,4 +198,5 @@ test {
|
||||||
_ = ImageCopyBuffer;
|
_ = ImageCopyBuffer;
|
||||||
_ = ImageCopyTexture;
|
_ = ImageCopyTexture;
|
||||||
_ = ErrorCallback;
|
_ = ErrorCallback;
|
||||||
|
_ = LoggingCallback;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue