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