gpu: improve compatibility with self-hosted compiler
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
8ec53c7446
commit
ca028ea038
6 changed files with 145 additions and 60 deletions
|
|
@ -236,18 +236,31 @@ pub const AutoReleasePool = if (!@import("builtin").target.isDarwin()) opaque {
|
||||||
pub fn msgSend(obj: anytype, sel_name: [:0]const u8, args: anytype, comptime ReturnType: type) ReturnType {
|
pub fn msgSend(obj: anytype, sel_name: [:0]const u8, args: anytype, comptime ReturnType: type) ReturnType {
|
||||||
const args_meta = @typeInfo(@TypeOf(args)).Struct.fields;
|
const args_meta = @typeInfo(@TypeOf(args)).Struct.fields;
|
||||||
|
|
||||||
const FnType = switch (args_meta.len) {
|
const FnType = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
switch (args_meta.len) {
|
||||||
0 => fn (@TypeOf(obj), objc.SEL) callconv(.C) ReturnType,
|
0 => fn (@TypeOf(obj), objc.SEL) callconv(.C) ReturnType,
|
||||||
1 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type) callconv(.C) ReturnType,
|
1 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type) callconv(.C) ReturnType,
|
||||||
2 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type) callconv(.C) ReturnType,
|
2 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type) callconv(.C) ReturnType,
|
||||||
3 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type, args_meta[2].field_type) callconv(.C) ReturnType,
|
3 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type, args_meta[2].field_type) callconv(.C) ReturnType,
|
||||||
4 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type, args_meta[2].field_type, args_meta[3].field_type) callconv(.C) ReturnType,
|
4 => fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type, args_meta[2].field_type, args_meta[3].field_type) callconv(.C) ReturnType,
|
||||||
else => @compileError("Unsupported number of args"),
|
else => @compileError("Unsupported number of args"),
|
||||||
|
}
|
||||||
|
else
|
||||||
|
switch (args_meta.len) {
|
||||||
|
0 => *const fn (@TypeOf(obj), objc.SEL) callconv(.C) ReturnType,
|
||||||
|
1 => *const fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type) callconv(.C) ReturnType,
|
||||||
|
2 => *const fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type) callconv(.C) ReturnType,
|
||||||
|
3 => *const fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type, args_meta[2].field_type) callconv(.C) ReturnType,
|
||||||
|
4 => *const fn (@TypeOf(obj), objc.SEL, args_meta[0].field_type, args_meta[1].field_type, args_meta[2].field_type, args_meta[3].field_type) callconv(.C) ReturnType,
|
||||||
|
else => @compileError("Unsupported number of args"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: func is a var because making it const causes a compile error which I believe is a compiler bug
|
// NOTE: func is a var because making it const causes a compile error which I believe is a compiler bug
|
||||||
var func = @ptrCast(FnType, objc.objc_msgSend);
|
var func = if (@import("builtin").zig_backend == .stage1)
|
||||||
const sel = objc.sel_getUid(sel_name);
|
@ptrCast(FnType, objc.objc_msgSend)
|
||||||
|
else
|
||||||
|
@ptrCast(FnType, &objc.objc_msgSend);
|
||||||
|
const sel = objc.sel_getUid(@ptrCast([*c]const u8, sel_name));
|
||||||
|
|
||||||
return @call(.{}, func, .{ obj, sel } ++ args);
|
return @call(.{}, func, .{ obj, sel } ++ args);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ const MapModeFlags = @import("types.zig").MapModeFlags;
|
||||||
const Impl = @import("interface.zig").Impl;
|
const Impl = @import("interface.zig").Impl;
|
||||||
|
|
||||||
pub const Buffer = opaque {
|
pub const Buffer = opaque {
|
||||||
pub const MapCallback = fn (status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void;
|
pub const MapCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void;
|
||||||
|
|
||||||
pub const BindingType = enum(u32) {
|
pub const BindingType = enum(u32) {
|
||||||
undef = 0x00000000,
|
undef = 0x00000000,
|
||||||
|
|
|
||||||
|
|
@ -10,48 +10,101 @@ const Adapter = @import("adapter.zig").Adapter;
|
||||||
const ComputePipeline = @import("compute_pipeline.zig").ComputePipeline;
|
const ComputePipeline = @import("compute_pipeline.zig").ComputePipeline;
|
||||||
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
|
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
|
||||||
|
|
||||||
pub const CompilationInfoCallback = fn (
|
pub const CompilationInfoCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
status: CompilationInfoRequestStatus,
|
status: CompilationInfoRequestStatus,
|
||||||
compilation_info: *const CompilationInfo,
|
compilation_info: *const CompilationInfo,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
status: CompilationInfoRequestStatus,
|
||||||
|
compilation_info: *const CompilationInfo,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
||||||
pub const ErrorCallback = fn (
|
pub const ErrorCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
typ: ErrorType,
|
typ: ErrorType,
|
||||||
message: [*:0]const u8,
|
message: [*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
typ: ErrorType,
|
||||||
|
message: [*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
||||||
pub const LoggingCallback = fn (
|
pub const LoggingCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
typ: LoggingType,
|
typ: LoggingType,
|
||||||
message: [*:0]const u8,
|
message: [*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
typ: LoggingType,
|
||||||
|
message: [*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
||||||
pub const RequestDeviceCallback = fn (
|
pub const RequestDeviceCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
status: RequestDeviceStatus,
|
status: RequestDeviceStatus,
|
||||||
device: *Device,
|
device: *Device,
|
||||||
message: ?[*:0]const u8,
|
message: ?[*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
status: RequestDeviceStatus,
|
||||||
|
device: *Device,
|
||||||
|
message: ?[*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
||||||
pub const RequestAdapterCallback = fn (
|
pub const RequestAdapterCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
status: RequestAdapterStatus,
|
status: RequestAdapterStatus,
|
||||||
adapter: *Adapter,
|
adapter: *Adapter,
|
||||||
message: ?[*:0]const u8,
|
message: ?[*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
status: RequestAdapterStatus,
|
||||||
|
adapter: *Adapter,
|
||||||
|
message: ?[*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
||||||
pub const CreateComputePipelineAsyncCallback = fn (
|
pub const CreateComputePipelineAsyncCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
status: CreatePipelineAsyncStatus,
|
status: CreatePipelineAsyncStatus,
|
||||||
compute_pipeline: *ComputePipeline,
|
compute_pipeline: *ComputePipeline,
|
||||||
message: [*:0]const u8,
|
message: [*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
status: CreatePipelineAsyncStatus,
|
||||||
|
compute_pipeline: *ComputePipeline,
|
||||||
|
message: [*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
||||||
pub const CreateRenderPipelineAsyncCallback = fn (
|
pub const CreateRenderPipelineAsyncCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
status: CreatePipelineAsyncStatus,
|
status: CreatePipelineAsyncStatus,
|
||||||
pipeline: *RenderPipeline,
|
pipeline: *RenderPipeline,
|
||||||
message: [*:0]const u8,
|
message: [*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
|
status: CreatePipelineAsyncStatus,
|
||||||
|
pipeline: *RenderPipeline,
|
||||||
|
message: [*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,14 @@ const Impl = @import("interface.zig").Impl;
|
||||||
const dawn = @import("dawn.zig");
|
const dawn = @import("dawn.zig");
|
||||||
|
|
||||||
pub const Device = opaque {
|
pub const Device = opaque {
|
||||||
pub const LostCallback = fn (
|
pub const LostCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
|
reason: LostReason,
|
||||||
|
message: [*:0]const u8,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
reason: LostReason,
|
reason: LostReason,
|
||||||
message: [*:0]const u8,
|
message: [*:0]const u8,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,13 @@ const CopyTextureForBrowserOptions = @import("types.zig").CopyTextureForBrowserO
|
||||||
const Impl = @import("interface.zig").Impl;
|
const Impl = @import("interface.zig").Impl;
|
||||||
|
|
||||||
pub const Queue = opaque {
|
pub const Queue = opaque {
|
||||||
pub const WorkDoneCallback = fn (
|
pub const WorkDoneCallback = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn (
|
||||||
|
status: WorkDoneStatus,
|
||||||
|
userdata: ?*anyopaque,
|
||||||
|
) callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn (
|
||||||
status: WorkDoneStatus,
|
status: WorkDoneStatus,
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
) callconv(.C) void;
|
) callconv(.C) void;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,10 @@ pub const whole_size = 0xffffffffffffffff;
|
||||||
|
|
||||||
/// Generic function pointer type, used for returning API function pointers. Must be
|
/// Generic function pointer type, used for returning API function pointers. Must be
|
||||||
/// cast to the right `fn (...) callconv(.C) T` type before use.
|
/// cast to the right `fn (...) callconv(.C) T` type before use.
|
||||||
pub const Proc = fn () callconv(.C) void;
|
pub const Proc = if (@import("builtin").zig_backend == .stage1)
|
||||||
|
fn () callconv(.C) void
|
||||||
|
else
|
||||||
|
*const fn () callconv(.C) void;
|
||||||
|
|
||||||
pub const ComputePassTimestampWrite = extern struct {
|
pub const ComputePassTimestampWrite = extern struct {
|
||||||
query_set: *QuerySet,
|
query_set: *QuerySet,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue