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 <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-12 00:14:32 -07:00 committed by Stephen Gutekanst
parent 7f8c279cbc
commit 58600faa0d
7 changed files with 22 additions and 22 deletions

View file

@ -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)),
);
}
};

View file

@ -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);

View file

@ -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);

View file

@ -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)),
);
}
};

View file

@ -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);

View file

@ -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)),
);
}
};