From 4ed932be0f72825687ada5ab67607f2486fd90d4 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 31 Jul 2022 16:01:40 -0700 Subject: [PATCH] gpu: simplify callback context types Signed-off-by: Stephen Gutekanst --- gpu/src/adapter.zig | 6 +++--- gpu/src/buffer.zig | 6 +++--- gpu/src/device.zig | 36 ++++++++++++++++++------------------ gpu/src/instance.zig | 6 +++--- gpu/src/queue.zig | 6 +++--- gpu/src/shader_module.zig | 6 +++--- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/gpu/src/adapter.zig b/gpu/src/adapter.zig index 7f7f9c19..2ffd594d 100644 --- a/gpu/src/adapter.zig +++ b/gpu/src/adapter.zig @@ -73,15 +73,15 @@ pub const Adapter = opaque { pub inline fn requestDevice( adapter: *Adapter, descriptor: ?*const Device.Descriptor, - comptime Context: type, + context: anytype, comptime callback: fn ( status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, - ctx: Context, + ctx: @TypeOf(context), ) callconv(.Inline) void, - context: Context, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { callback( diff --git a/gpu/src/buffer.zig b/gpu/src/buffer.zig index c3569d91..0c9fe066 100644 --- a/gpu/src/buffer.zig +++ b/gpu/src/buffer.zig @@ -94,10 +94,10 @@ pub const Buffer = opaque { mode: MapModeFlags, offset: usize, size: usize, - comptime Context: type, - comptime callback: fn (status: MapAsyncStatus, ctx: Context) callconv(.Inline) void, - context: Context, + context: anytype, + comptime callback: fn (status: MapAsyncStatus, ctx: @TypeOf(context)) callconv(.Inline) void, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void { callback(status, if (Context == void) {} else @ptrCast(Context, userdata)); diff --git a/gpu/src/device.zig b/gpu/src/device.zig index 69dfa388..6dd9f45d 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -72,15 +72,15 @@ pub const Device = opaque { pub inline fn createComputePipelineAsync( device: *Device, descriptor: *const ComputePipeline.Descriptor, - comptime Context: type, + context: anytype, comptime callback: fn ( status: CreatePipelineAsyncStatus, compute_pipeline: *ComputePipeline, message: [*:0]const u8, - ctx: Context, + ctx: @TypeOf(context), ) callconv(.Inline) void, - context: Context, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback( status: CreatePipelineAsyncStatus, @@ -130,15 +130,15 @@ pub const Device = opaque { pub inline fn createRenderPipelineAsync( device: *Device, descriptor: *const RenderPipeline.Descriptor, - comptime Context: type, + context: anytype, comptime callback: fn ( status: CreatePipelineAsyncStatus, pipeline: *RenderPipeline, message: [*:0]const u8, - ctx: Context, + ctx: @TypeOf(context), ) callconv(.Inline) void, - context: Context, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback( status: CreatePipelineAsyncStatus, @@ -203,10 +203,10 @@ pub const Device = opaque { pub inline fn popErrorScope( device: *Device, - comptime Context: type, - comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, - context: Context, + context: anytype, + comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, ) bool { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { callback(typ, message, if (Context == void) {} else @ptrCast(Context, userdata)); @@ -222,10 +222,10 @@ pub const Device = opaque { // TODO: presumably callback should be nullable for unsetting pub inline fn setDeviceLostCallback( device: *Device, - comptime Context: type, - comptime callback: fn (reason: LostReason, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, - context: Context, + context: anytype, + comptime callback: fn (reason: LostReason, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { callback(reason, message, if (Context == void) {} else @ptrCast(Context, userdata)); @@ -241,10 +241,10 @@ pub const Device = opaque { // TODO: presumably callback should be nullable for unsetting pub inline fn setLoggingCallback( device: *Device, - comptime Context: type, - comptime callback: fn (typ: LoggingType, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, - context: Context, + context: anytype, + comptime callback: fn (typ: LoggingType, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { callback(typ, message, if (Context == void) {} else @ptrCast(Context, userdata)); @@ -256,10 +256,10 @@ pub const Device = opaque { // TODO: presumably callback should be nullable for unsetting pub inline fn setUncapturedErrorCallback( device: *Device, - comptime Context: type, - comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, - context: Context, + context: anytype, + comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { callback(typ, message, if (Context == void) {} else @ptrCast(Context, userdata)); diff --git a/gpu/src/instance.zig b/gpu/src/instance.zig index c9c3595e..a2e88124 100644 --- a/gpu/src/instance.zig +++ b/gpu/src/instance.zig @@ -18,15 +18,15 @@ pub const Instance = opaque { pub inline fn requestAdapter( instance: *Instance, options: *const RequestAdapterOptions, - comptime Context: type, + context: anytype, comptime callback: fn ( status: RequestAdapterStatus, adapter: *Adapter, message: ?[*:0]const u8, - ctx: Context, + ctx: @TypeOf(context), ) callconv(.Inline) void, - context: Context, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback( status: RequestAdapterStatus, diff --git a/gpu/src/queue.zig b/gpu/src/queue.zig index 3c0b08d8..fde709dc 100644 --- a/gpu/src/queue.zig +++ b/gpu/src/queue.zig @@ -33,10 +33,10 @@ pub const Queue = opaque { pub inline fn onSubmittedWorkDone( queue: *Queue, signal_value: u64, - comptime Context: type, - comptime callback: fn (status: WorkDoneStatus, ctx: Context) callconv(.Inline) void, - context: Context, + context: anytype, + comptime callback: fn (status: WorkDoneStatus, ctx: @TypeOf(context)) callconv(.Inline) void, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void { callback(status, if (Context == void) {} else @ptrCast(Context, userdata)); diff --git a/gpu/src/shader_module.zig b/gpu/src/shader_module.zig index 982687b4..98940c4c 100644 --- a/gpu/src/shader_module.zig +++ b/gpu/src/shader_module.zig @@ -23,14 +23,14 @@ pub const ShaderModule = opaque { pub inline fn getCompilationInfo( shader_module: *ShaderModule, - comptime Context: type, + context: anytype, comptime callback: fn ( status: CompilationInfoRequestStatus, compilation_info: *const CompilationInfo, - ctx: Context, + ctx: @TypeOf(context), ) callconv(.Inline) void, - context: Context, ) void { + const Context = @TypeOf(context); const Helper = struct { pub fn callback( status: CompilationInfoRequestStatus,