gpu: implement Device.popErrorScope
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
ec59471765
commit
8df0c70c69
3 changed files with 59 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ 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 ErrorCallback = @import("structs.zig").ErrorCallback;
|
||||||
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");
|
||||||
|
|
@ -72,9 +73,7 @@ pub const VTable = struct {
|
||||||
// WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeature feature);
|
// WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeature feature);
|
||||||
injectError: fn (ptr: *anyopaque, type: ErrorType, message: [*:0]const u8) void,
|
injectError: fn (ptr: *anyopaque, type: ErrorType, message: [*:0]const u8) void,
|
||||||
loseForTesting: fn (ptr: *anyopaque) void,
|
loseForTesting: fn (ptr: *anyopaque) void,
|
||||||
// TODO: callback
|
popErrorScope: fn (ptr: *anyopaque, callback: *ErrorCallback) bool,
|
||||||
// popErrorScope: fn (ptr: *anyopaque, callback: ErrorCallback) bool,
|
|
||||||
// WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
|
||||||
pushErrorScope: fn (ptr: *anyopaque, filter: ErrorFilter) void,
|
pushErrorScope: fn (ptr: *anyopaque, filter: ErrorFilter) void,
|
||||||
// TODO: callback
|
// TODO: callback
|
||||||
// setDeviceLostCallback: fn (ptr: *anyopaque, callback: DeviceLostCallback) void,
|
// setDeviceLostCallback: fn (ptr: *anyopaque, callback: DeviceLostCallback) void,
|
||||||
|
|
@ -108,6 +107,10 @@ pub inline fn loseForTesting(device: Device) void {
|
||||||
device.vtable.loseForTesting(device.ptr);
|
device.vtable.loseForTesting(device.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub inline fn popErrorScope(device: Device, callback: *ErrorCallback) bool {
|
||||||
|
return device.vtable.popErrorScope(device.ptr, callback);
|
||||||
|
}
|
||||||
|
|
||||||
pub inline fn pushErrorScope(device: Device, filter: ErrorFilter) void {
|
pub inline fn pushErrorScope(device: Device, filter: ErrorFilter) void {
|
||||||
device.vtable.pushErrorScope(device.ptr, filter);
|
device.vtable.pushErrorScope(device.ptr, filter);
|
||||||
}
|
}
|
||||||
|
|
@ -217,6 +220,7 @@ test {
|
||||||
_ = getQueue;
|
_ = getQueue;
|
||||||
_ = injectError;
|
_ = injectError;
|
||||||
_ = loseForTesting;
|
_ = loseForTesting;
|
||||||
|
_ = popErrorScope;
|
||||||
_ = createBindGroup;
|
_ = createBindGroup;
|
||||||
_ = pushErrorScope;
|
_ = pushErrorScope;
|
||||||
_ = createBindGroupLayout;
|
_ = createBindGroupLayout;
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ const ErrorFilter = @import("enums.zig").ErrorFilter;
|
||||||
|
|
||||||
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 NativeInstance = @This();
|
const NativeInstance = @This();
|
||||||
|
|
||||||
|
|
@ -333,6 +334,33 @@ const device_vtable = Device.VTable{
|
||||||
c.wgpuDeviceLoseForTesting(@ptrCast(c.WGPUDevice, ptr));
|
c.wgpuDeviceLoseForTesting(@ptrCast(c.WGPUDevice, ptr));
|
||||||
}
|
}
|
||||||
}).loseForTesting,
|
}).loseForTesting,
|
||||||
|
.popErrorScope = (struct {
|
||||||
|
pub fn popErrorScope(
|
||||||
|
ptr: *anyopaque,
|
||||||
|
callback: *ErrorCallback,
|
||||||
|
) bool {
|
||||||
|
const cCallback = (struct {
|
||||||
|
pub fn cCallback(
|
||||||
|
typ: c.WGPUErrorType,
|
||||||
|
message: [*c]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void {
|
||||||
|
const callback_info = @ptrCast(*ErrorCallback, @alignCast(@alignOf(*ErrorCallback), userdata));
|
||||||
|
callback_info.type_erased_callback(
|
||||||
|
callback_info.type_erased_ctx,
|
||||||
|
@intToEnum(ErrorType, typ),
|
||||||
|
std.mem.span(message),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}).cCallback;
|
||||||
|
|
||||||
|
return c.wgpuDevicePopErrorScope(
|
||||||
|
@ptrCast(c.WGPUDevice, ptr),
|
||||||
|
cCallback,
|
||||||
|
callback,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}).popErrorScope,
|
||||||
.createBindGroup = (struct {
|
.createBindGroup = (struct {
|
||||||
pub fn createBindGroup(ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup {
|
pub fn createBindGroup(ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup {
|
||||||
var few_entries: [16]c.WGPUBindGroupEntry = undefined;
|
var few_entries: [16]c.WGPUBindGroupEntry = undefined;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ const RenderPassTimestampLocation = @import("enums.zig").RenderPassTimestampLoca
|
||||||
const LoadOp = @import("enums.zig").LoadOp;
|
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;
|
||||||
|
|
||||||
pub const MultisampleState = struct {
|
pub const MultisampleState = struct {
|
||||||
count: u32,
|
count: u32,
|
||||||
|
|
@ -136,6 +137,28 @@ pub const ImageCopyTexture = struct {
|
||||||
aspect: Texture.Aspect,
|
aspect: Texture.Aspect,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const ErrorCallback = struct {
|
||||||
|
type_erased_ctx: *anyopaque,
|
||||||
|
type_erased_callback: fn (ctx: *anyopaque, typ: ErrorType, message: [*:0]const u8) callconv(.Inline) void,
|
||||||
|
|
||||||
|
pub fn init(
|
||||||
|
comptime Context: type,
|
||||||
|
ctx: *Context,
|
||||||
|
comptime callback: fn (ctx: *Context, typ: ErrorType, message: [*:0]const u8) void,
|
||||||
|
) ErrorCallback {
|
||||||
|
const erased = (struct {
|
||||||
|
pub inline fn erased(type_erased_ctx: *anyopaque, typ: ErrorType, 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;
|
||||||
|
|
@ -151,4 +174,5 @@ test {
|
||||||
_ = FragmentState;
|
_ = FragmentState;
|
||||||
_ = ImageCopyBuffer;
|
_ = ImageCopyBuffer;
|
||||||
_ = ImageCopyTexture;
|
_ = ImageCopyTexture;
|
||||||
|
_ = ErrorCallback;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue