diff --git a/gpu/src/Adapter.zig b/gpu/src/Adapter.zig index ef54bfc8..25f35d4e 100644 --- a/gpu/src/Adapter.zig +++ b/gpu/src/Adapter.zig @@ -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); diff --git a/gpu/src/Buffer.zig b/gpu/src/Buffer.zig index 8aeeb009..479780f8 100644 --- a/gpu/src/Buffer.zig +++ b/gpu/src/Buffer.zig @@ -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, }; } diff --git a/gpu/src/ComputePipeline.zig b/gpu/src/ComputePipeline.zig index 9a90a8c3..7d842034 100644 --- a/gpu/src/ComputePipeline.zig +++ b/gpu/src/ComputePipeline.zig @@ -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, }; } diff --git a/gpu/src/Device.zig b/gpu/src/Device.zig index cb0dc156..a8dd9378 100644 --- a/gpu/src/Device.zig +++ b/gpu/src/Device.zig @@ -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, }; } diff --git a/gpu/src/Interface.zig b/gpu/src/Interface.zig index 69abe367..b6a7f28f 100644 --- a/gpu/src/Interface.zig +++ b/gpu/src/Interface.zig @@ -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); diff --git a/gpu/src/Queue.zig b/gpu/src/Queue.zig index 6fd640a5..da1e7028 100644 --- a/gpu/src/Queue.zig +++ b/gpu/src/Queue.zig @@ -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, }; } diff --git a/gpu/src/RenderPipeline.zig b/gpu/src/RenderPipeline.zig index a9e3a7c4..08a77f37 100644 --- a/gpu/src/RenderPipeline.zig +++ b/gpu/src/RenderPipeline.zig @@ -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, }; } diff --git a/gpu/src/ShaderModule.zig b/gpu/src/ShaderModule.zig index 1c15b673..65b883da 100644 --- a/gpu/src/ShaderModule.zig +++ b/gpu/src/ShaderModule.zig @@ -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, }; } diff --git a/gpu/src/structs.zig b/gpu/src/structs.zig index 4fd79f7e..5267f54d 100644 --- a/gpu/src/structs.zig +++ b/gpu/src/structs.zig @@ -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, }; }