gpu: enable void callback contexts
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
1717c684de
commit
79d27b82be
9 changed files with 46 additions and 48 deletions
|
|
@ -159,17 +159,17 @@ pub const RequestDeviceCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, response: RequestDeviceResponse) void,
|
||||
ctx: Context,
|
||||
comptime callback: fn (ctx: Context, response: RequestDeviceResponse) void,
|
||||
) RequestDeviceCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, response: RequestDeviceResponse) void {
|
||||
callback(@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)), response);
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), response);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
@ -177,10 +177,9 @@ pub const RequestDeviceCallback = struct {
|
|||
|
||||
/// A helper which invokes requestDevice and blocks until the device is recieved.
|
||||
pub fn waitForDevice(adapter: Adapter, descriptor: *const Device.Descriptor) RequestDeviceResponse {
|
||||
const Context = RequestDeviceResponse;
|
||||
var response: Context = undefined;
|
||||
var callback = RequestDeviceCallback.init(Context, &response, (struct {
|
||||
pub fn callback(ctx: *Context, callback_response: RequestDeviceResponse) void {
|
||||
var response: RequestDeviceResponse = undefined;
|
||||
var callback = RequestDeviceCallback.init(*RequestDeviceResponse, &response, (struct {
|
||||
pub fn callback(ctx: *RequestDeviceResponse, callback_response: RequestDeviceResponse) void {
|
||||
ctx.* = callback_response;
|
||||
}
|
||||
}).callback);
|
||||
|
|
|
|||
|
|
@ -66,17 +66,17 @@ pub const MapCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, status: MapAsyncStatus) void,
|
||||
ctx: Context,
|
||||
comptime callback: fn (ctx: Context, status: MapAsyncStatus) void,
|
||||
) MapCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, status: MapAsyncStatus) 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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ pub const CreateCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
ctx: Context,
|
||||
comptime callback: fn (
|
||||
ctx: *Context,
|
||||
ctx: Context,
|
||||
status: CreateStatus,
|
||||
pipeline: ComputePipeline,
|
||||
message: [:0]const u8,
|
||||
|
|
@ -73,7 +73,7 @@ pub const CreateCallback = struct {
|
|||
message: [:0]const u8,
|
||||
) void {
|
||||
callback(
|
||||
@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)),
|
||||
@ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)),
|
||||
status,
|
||||
pipeline,
|
||||
message,
|
||||
|
|
@ -82,7 +82,7 @@ pub const CreateCallback = struct {
|
|||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,17 +132,17 @@ pub const LostCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, reason: LostReason, message: [*:0]const u8) void,
|
||||
ctx: Context,
|
||||
comptime callback: fn (ctx: Context, reason: LostReason, message: [*:0]const u8) void,
|
||||
) LostCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, reason: LostReason, message: [*:0]const u8) void {
|
||||
callback(@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)), reason, message);
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), reason, message);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,17 +74,17 @@ pub const RequestAdapterCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, response: RequestAdapterResponse) void,
|
||||
ctx: Context,
|
||||
comptime callback: fn (ctx: Context, response: RequestAdapterResponse) void,
|
||||
) RequestAdapterCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, response: RequestAdapterResponse) void {
|
||||
callback(@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)), response);
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), response);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
@ -92,10 +92,9 @@ pub const RequestAdapterCallback = struct {
|
|||
|
||||
/// A helper which invokes requestAdapter and blocks until the adapter is recieved.
|
||||
pub fn waitForAdapter(interface: Interface, options: *const RequestAdapterOptions) RequestAdapterResponse {
|
||||
const Context = RequestAdapterResponse;
|
||||
var response: Context = undefined;
|
||||
var callback = RequestAdapterCallback.init(Context, &response, (struct {
|
||||
pub fn callback(ctx: *Context, callback_response: RequestAdapterResponse) void {
|
||||
var response: RequestAdapterResponse = undefined;
|
||||
var callback = RequestAdapterCallback.init(*RequestAdapterResponse, &response, (struct {
|
||||
pub fn callback(ctx: *RequestAdapterResponse, callback_response: RequestAdapterResponse) void {
|
||||
ctx.* = callback_response;
|
||||
}
|
||||
}).callback);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ pub const CreateCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
ctx: Context,
|
||||
comptime callback: fn (
|
||||
ctx: *Context,
|
||||
ctx: Context,
|
||||
status: CreateStatus,
|
||||
pipeline: RenderPipeline,
|
||||
message: [:0]const u8,
|
||||
|
|
@ -81,7 +81,7 @@ pub const CreateCallback = struct {
|
|||
message: [:0]const u8,
|
||||
) void {
|
||||
callback(
|
||||
@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)),
|
||||
@ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)),
|
||||
status,
|
||||
pipeline,
|
||||
message,
|
||||
|
|
@ -90,7 +90,7 @@ pub const CreateCallback = struct {
|
|||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,17 +34,17 @@ pub const CompilationInfoCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, status: CompilationInfoRequestStatus, info: *const CompilationInfo) void,
|
||||
ctx: Context,
|
||||
comptime callback: fn (ctx: Context, status: CompilationInfoRequestStatus, info: *const CompilationInfo) void,
|
||||
) CompilationInfoCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, status: CompilationInfoRequestStatus) 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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,17 +144,17 @@ pub const ErrorCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, typ: ErrorType, message: [*:0]const u8) void,
|
||||
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);
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), typ, message);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
@ -166,17 +166,17 @@ pub const LoggingCallback = struct {
|
|||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, typ: LoggingType, message: [*:0]const u8) void,
|
||||
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);
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), typ, message);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_ctx = if (Context == void) undefined else ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue