gpu: enable void callback contexts

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-19 00:41:00 -07:00 committed by Stephen Gutekanst
parent 1717c684de
commit 79d27b82be
9 changed files with 46 additions and 48 deletions

View file

@ -83,17 +83,17 @@ pub const WorkDoneCallback = struct {
pub fn init(
comptime Context: type,
ctx: *Context,
comptime callback: fn (ctx: *Context, status: WorkDoneStatus) void,
ctx: Context,
comptime callback: fn (ctx: Context, status: WorkDoneStatus) void,
) WorkDoneCallback {
const erased = (struct {
pub inline fn erased(type_erased_ctx: *anyopaque, status: WorkDoneStatus) void {
callback(@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)), status);
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), status);
}
}).erased;
return .{
.type_erased_ctx = ctx,
.type_erased_ctx = if (Context == void) undefined else ctx,
.type_erased_callback = erased,
};
}