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:
parent
7f8c279cbc
commit
58600faa0d
7 changed files with 22 additions and 22 deletions
|
|
@ -7,7 +7,7 @@ const objc = @cImport({
|
||||||
@cInclude("objc/message.h");
|
@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) {
|
switch (typ) {
|
||||||
.validation => std.debug.print("gpu: validation error: {s}\n", .{message}),
|
.validation => std.debug.print("gpu: validation error: {s}\n", .{message}),
|
||||||
.out_of_memory => std.debug.print("gpu: out of memory: {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(
|
inline fn requestAdapterCallback(
|
||||||
|
context: *?RequestAdapterResponse,
|
||||||
status: gpu.RequestAdapterStatus,
|
status: gpu.RequestAdapterStatus,
|
||||||
adapter: *gpu.Adapter,
|
adapter: *gpu.Adapter,
|
||||||
message: ?[*:0]const u8,
|
message: ?[*:0]const u8,
|
||||||
context: *?RequestAdapterResponse,
|
|
||||||
) void {
|
) void {
|
||||||
context.* = RequestAdapterResponse{
|
context.* = RequestAdapterResponse{
|
||||||
.status = status,
|
.status = status,
|
||||||
|
|
|
||||||
|
|
@ -75,20 +75,20 @@ pub const Adapter = opaque {
|
||||||
descriptor: ?*const Device.Descriptor,
|
descriptor: ?*const Device.Descriptor,
|
||||||
context: anytype,
|
context: anytype,
|
||||||
comptime callback: fn (
|
comptime callback: fn (
|
||||||
|
ctx: @TypeOf(context),
|
||||||
status: RequestDeviceStatus,
|
status: RequestDeviceStatus,
|
||||||
device: *Device,
|
device: *Device,
|
||||||
message: ?[*:0]const u8,
|
message: ?[*:0]const u8,
|
||||||
ctx: @TypeOf(context),
|
|
||||||
) callconv(.Inline) void,
|
) callconv(.Inline) void,
|
||||||
) void {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
pub fn callback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||||
callback(
|
callback(
|
||||||
|
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||||
status,
|
status,
|
||||||
device,
|
device,
|
||||||
message,
|
message,
|
||||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,12 @@ pub const Buffer = opaque {
|
||||||
offset: usize,
|
offset: usize,
|
||||||
size: usize,
|
size: usize,
|
||||||
context: anytype,
|
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 {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void {
|
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);
|
Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null else context);
|
||||||
|
|
|
||||||
|
|
@ -137,10 +137,10 @@ pub const Device = opaque {
|
||||||
descriptor: *const RenderPipeline.Descriptor,
|
descriptor: *const RenderPipeline.Descriptor,
|
||||||
context: anytype,
|
context: anytype,
|
||||||
comptime callback: fn (
|
comptime callback: fn (
|
||||||
|
ctx: @TypeOf(context),
|
||||||
status: CreatePipelineAsyncStatus,
|
status: CreatePipelineAsyncStatus,
|
||||||
pipeline: *RenderPipeline,
|
pipeline: *RenderPipeline,
|
||||||
message: [*:0]const u8,
|
message: [*:0]const u8,
|
||||||
ctx: @TypeOf(context),
|
|
||||||
) callconv(.Inline) void,
|
) callconv(.Inline) void,
|
||||||
) void {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
|
|
@ -152,10 +152,10 @@ pub const Device = opaque {
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
callback(
|
callback(
|
||||||
|
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||||
status,
|
status,
|
||||||
pipeline,
|
pipeline,
|
||||||
message,
|
message,
|
||||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -221,12 +221,12 @@ pub const Device = opaque {
|
||||||
pub inline fn popErrorScope(
|
pub inline fn popErrorScope(
|
||||||
device: *Device,
|
device: *Device,
|
||||||
context: anytype,
|
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 {
|
) bool {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
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);
|
return Impl.devicePopErrorScope(device, Helper.callback, if (Context == void) null else context);
|
||||||
|
|
@ -240,12 +240,12 @@ pub const Device = opaque {
|
||||||
pub inline fn setDeviceLostCallback(
|
pub inline fn setDeviceLostCallback(
|
||||||
device: *Device,
|
device: *Device,
|
||||||
context: anytype,
|
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 {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
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);
|
Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context);
|
||||||
|
|
@ -259,12 +259,12 @@ pub const Device = opaque {
|
||||||
pub inline fn setLoggingCallback(
|
pub inline fn setLoggingCallback(
|
||||||
device: *Device,
|
device: *Device,
|
||||||
context: anytype,
|
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 {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
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);
|
Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context);
|
||||||
|
|
@ -274,12 +274,12 @@ pub const Device = opaque {
|
||||||
pub inline fn setUncapturedErrorCallback(
|
pub inline fn setUncapturedErrorCallback(
|
||||||
device: *Device,
|
device: *Device,
|
||||||
context: anytype,
|
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 {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
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);
|
Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context);
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ pub const Instance = opaque {
|
||||||
options: ?*const RequestAdapterOptions,
|
options: ?*const RequestAdapterOptions,
|
||||||
context: anytype,
|
context: anytype,
|
||||||
comptime callback: fn (
|
comptime callback: fn (
|
||||||
|
ctx: @TypeOf(context),
|
||||||
status: RequestAdapterStatus,
|
status: RequestAdapterStatus,
|
||||||
adapter: *Adapter,
|
adapter: *Adapter,
|
||||||
message: ?[*:0]const u8,
|
message: ?[*:0]const u8,
|
||||||
ctx: @TypeOf(context),
|
|
||||||
) callconv(.Inline) void,
|
) callconv(.Inline) void,
|
||||||
) void {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
|
|
@ -35,10 +35,10 @@ pub const Instance = opaque {
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
callback(
|
callback(
|
||||||
|
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||||
status,
|
status,
|
||||||
adapter,
|
adapter,
|
||||||
message,
|
message,
|
||||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,12 @@ pub const Queue = opaque {
|
||||||
queue: *Queue,
|
queue: *Queue,
|
||||||
signal_value: u64,
|
signal_value: u64,
|
||||||
context: anytype,
|
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 {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
const Helper = struct {
|
const Helper = struct {
|
||||||
pub fn callback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void {
|
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);
|
Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.callback, if (Context == void) null else context);
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ pub const ShaderModule = opaque {
|
||||||
shader_module: *ShaderModule,
|
shader_module: *ShaderModule,
|
||||||
context: anytype,
|
context: anytype,
|
||||||
comptime callback: fn (
|
comptime callback: fn (
|
||||||
|
ctx: @TypeOf(context),
|
||||||
status: CompilationInfoRequestStatus,
|
status: CompilationInfoRequestStatus,
|
||||||
compilation_info: *const CompilationInfo,
|
compilation_info: *const CompilationInfo,
|
||||||
ctx: @TypeOf(context),
|
|
||||||
) callconv(.Inline) void,
|
) callconv(.Inline) void,
|
||||||
) void {
|
) void {
|
||||||
const Context = @TypeOf(context);
|
const Context = @TypeOf(context);
|
||||||
|
|
@ -44,9 +44,9 @@ pub const ShaderModule = opaque {
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
callback(
|
callback(
|
||||||
|
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||||
status,
|
status,
|
||||||
compilation_info,
|
compilation_info,
|
||||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue