From 58600faa0d446d5c71a60fde292b5f87d1aecbc6 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 12 Aug 2022 00:14:32 -0700 Subject: [PATCH] gpu: make ctx parameters in callbacks always first This matches the order of context parameters always being first in the Zig stdlib with e.g. sorting and similar places where a context parameter exists. Signed-off-by: Stephen Gutekanst --- gpu/examples/sample_utils.zig | 4 ++-- gpu/src/adapter.zig | 4 ++-- gpu/src/buffer.zig | 4 ++-- gpu/src/device.zig | 20 ++++++++++---------- gpu/src/instance.zig | 4 ++-- gpu/src/queue.zig | 4 ++-- gpu/src/shader_module.zig | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gpu/examples/sample_utils.zig b/gpu/examples/sample_utils.zig index 6429474c..6f2d05de 100644 --- a/gpu/examples/sample_utils.zig +++ b/gpu/examples/sample_utils.zig @@ -7,7 +7,7 @@ const objc = @cImport({ @cInclude("objc/message.h"); }); -inline fn printUnhandledErrorCallback(typ: gpu.ErrorType, message: [*:0]const u8, _: void) void { +inline fn printUnhandledErrorCallback(_: void, typ: gpu.ErrorType, message: [*:0]const u8) void { switch (typ) { .validation => std.debug.print("gpu: validation error: {s}\n", .{message}), .out_of_memory => std.debug.print("gpu: out of memory: {s}\n", .{message}), @@ -61,10 +61,10 @@ const RequestAdapterResponse = struct { }; inline fn requestAdapterCallback( + context: *?RequestAdapterResponse, status: gpu.RequestAdapterStatus, adapter: *gpu.Adapter, message: ?[*:0]const u8, - context: *?RequestAdapterResponse, ) void { context.* = RequestAdapterResponse{ .status = status, diff --git a/gpu/src/adapter.zig b/gpu/src/adapter.zig index 87de1222..211dc5bd 100644 --- a/gpu/src/adapter.zig +++ b/gpu/src/adapter.zig @@ -75,20 +75,20 @@ pub const Adapter = opaque { descriptor: ?*const Device.Descriptor, context: anytype, comptime callback: fn ( + ctx: @TypeOf(context), status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, - ctx: @TypeOf(context), ) callconv(.Inline) void, ) 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( + if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), status, device, message, - if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), ); } }; diff --git a/gpu/src/buffer.zig b/gpu/src/buffer.zig index ef14dec0..ca06250b 100644 --- a/gpu/src/buffer.zig +++ b/gpu/src/buffer.zig @@ -117,12 +117,12 @@ pub const Buffer = opaque { offset: usize, size: usize, context: anytype, - comptime callback: fn (status: MapAsyncStatus, ctx: @TypeOf(context)) callconv(.Inline) void, + comptime callback: fn (ctx: @TypeOf(context), status: MapAsyncStatus) 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, @alignCast(@alignOf(std.meta.Child(Context)), userdata))); + callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), status); } }; Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null else context); diff --git a/gpu/src/device.zig b/gpu/src/device.zig index b49f3151..08a3f036 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -137,10 +137,10 @@ pub const Device = opaque { descriptor: *const RenderPipeline.Descriptor, context: anytype, comptime callback: fn ( + ctx: @TypeOf(context), status: CreatePipelineAsyncStatus, pipeline: *RenderPipeline, message: [*:0]const u8, - ctx: @TypeOf(context), ) callconv(.Inline) void, ) void { const Context = @TypeOf(context); @@ -152,10 +152,10 @@ pub const Device = opaque { userdata: ?*anyopaque, ) callconv(.C) void { callback( + if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), status, pipeline, message, - if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), ); } }; @@ -221,12 +221,12 @@ pub const Device = opaque { pub inline fn popErrorScope( device: *Device, context: anytype, - comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, + comptime callback: fn (ctx: @TypeOf(context), typ: ErrorType, message: [*:0]const u8) 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, @alignCast(@alignOf(std.meta.Child(Context)), userdata))); + callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message); } }; return Impl.devicePopErrorScope(device, Helper.callback, if (Context == void) null else context); @@ -240,12 +240,12 @@ pub const Device = opaque { pub inline fn setDeviceLostCallback( device: *Device, context: anytype, - comptime callback: fn (reason: LostReason, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, + comptime callback: fn (ctx: @TypeOf(context), reason: LostReason, message: [*:0]const u8) 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, @alignCast(@alignOf(std.meta.Child(Context)), userdata))); + callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), reason, message); } }; Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context); @@ -259,12 +259,12 @@ pub const Device = opaque { pub inline fn setLoggingCallback( device: *Device, context: anytype, - comptime callback: fn (typ: LoggingType, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, + comptime callback: fn (ctx: @TypeOf(context), typ: LoggingType, message: [*:0]const u8) 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, @alignCast(@alignOf(std.meta.Child(Context)), userdata))); + callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message); } }; Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context); @@ -274,12 +274,12 @@ pub const Device = opaque { pub inline fn setUncapturedErrorCallback( device: *Device, context: anytype, - comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: @TypeOf(context)) callconv(.Inline) void, + comptime callback: fn (ctx: @TypeOf(context), typ: ErrorType, message: [*:0]const u8) 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, @alignCast(@alignOf(std.meta.Child(Context)), userdata))); + callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message); } }; Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context); diff --git a/gpu/src/instance.zig b/gpu/src/instance.zig index efc42137..f45d4b9b 100644 --- a/gpu/src/instance.zig +++ b/gpu/src/instance.zig @@ -20,10 +20,10 @@ pub const Instance = opaque { options: ?*const RequestAdapterOptions, context: anytype, comptime callback: fn ( + ctx: @TypeOf(context), status: RequestAdapterStatus, adapter: *Adapter, message: ?[*:0]const u8, - ctx: @TypeOf(context), ) callconv(.Inline) void, ) void { const Context = @TypeOf(context); @@ -35,10 +35,10 @@ pub const Instance = opaque { userdata: ?*anyopaque, ) callconv(.C) void { callback( + if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), status, adapter, message, - if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), ); } }; diff --git a/gpu/src/queue.zig b/gpu/src/queue.zig index 0da6c7df..9fd26ec1 100644 --- a/gpu/src/queue.zig +++ b/gpu/src/queue.zig @@ -35,12 +35,12 @@ pub const Queue = opaque { queue: *Queue, signal_value: u64, context: anytype, - comptime callback: fn (status: WorkDoneStatus, ctx: @TypeOf(context)) callconv(.Inline) void, + comptime callback: fn (ctx: @TypeOf(context), status: WorkDoneStatus) 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, @alignCast(@alignOf(std.meta.Child(Context)), userdata))); + callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), status); } }; Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.callback, if (Context == void) null else context); diff --git a/gpu/src/shader_module.zig b/gpu/src/shader_module.zig index 3d14529f..b2fd7561 100644 --- a/gpu/src/shader_module.zig +++ b/gpu/src/shader_module.zig @@ -31,9 +31,9 @@ pub const ShaderModule = opaque { shader_module: *ShaderModule, context: anytype, comptime callback: fn ( + ctx: @TypeOf(context), status: CompilationInfoRequestStatus, compilation_info: *const CompilationInfo, - ctx: @TypeOf(context), ) callconv(.Inline) void, ) void { const Context = @TypeOf(context); @@ -44,9 +44,9 @@ pub const ShaderModule = opaque { userdata: ?*anyopaque, ) callconv(.C) void { callback( + if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), status, compilation_info, - if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), ); } };