gpu-dawn: support compiling with stage2 (-fno-stage1)

This commit is contained in:
PiergiorgioZagaria 2022-06-26 08:46:53 +02:00 committed by Stephen Gutekanst
parent f80161bc72
commit e9bdf86ef9
2 changed files with 59 additions and 50 deletions

View file

@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const glfw = @import("glfw");
const c = @import("c.zig").c;
@ -129,16 +130,24 @@ fn glfwWindowHintsForBackend(backend: c.WGPUBackendType) glfw.Window.Hints {
}
fn discoverAdapter(instance: c.MachDawnNativeInstance, window: glfw.Window, typ: c.WGPUBackendType) !void {
// zig fmt: off
const ProcDecl =
if (builtin.zig_backend == .stage1 or builtin.zig_backend == .other)
fn ([*c]const u8) callconv(.C) ?*anyopaque
else
*const fn ([*c]const u8) callconv(.C) ?*anyopaque;
// zig fmt: on
if (typ == c.WGPUBackendType_OpenGL) {
try glfw.makeContextCurrent(window);
const adapter_options = c.MachDawnNativeAdapterDiscoveryOptions_OpenGL{
.getProc = @ptrCast(fn ([*c]const u8) callconv(.C) ?*anyopaque, glfw.getProcAddress),
.getProc = @ptrCast(ProcDecl, &glfw.getProcAddress),
};
_ = c.machDawnNativeInstance_discoverAdapters(instance, typ, &adapter_options);
} else if (typ == c.WGPUBackendType_OpenGLES) {
try glfw.makeContextCurrent(window);
const adapter_options = c.MachDawnNativeAdapterDiscoveryOptions_OpenGLES{
.getProc = @ptrCast(fn ([*c]const u8) callconv(.C) ?*anyopaque, glfw.getProcAddress),
.getProc = @ptrCast(ProcDecl, &glfw.getProcAddress),
};
_ = c.machDawnNativeInstance_discoverAdapters(instance, typ, &adapter_options);
} else {