gpu: correct implementation initialization

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-31 00:11:31 -07:00 committed by Stephen Gutekanst
parent a468c51ad4
commit 2a39ff8f7e
2 changed files with 5 additions and 6 deletions

View file

@ -10,10 +10,9 @@ var procs: c.DawnProcTable = undefined;
/// A Dawn implementation of the gpu.Interface, which merely directs calls to the Dawn proc table.
///
/// Before use, it must be `.init()`ialized in order to set the global proc table.
pub const Interface = gpu.Interface(struct {
pub fn init() @This() {
pub const Interface = struct {
pub fn init() void {
procs = c.machDawnGetProcTable();
return @This(){};
}
pub inline fn createInstance(descriptor: ?*const gpu.Instance.Descriptor) ?*gpu.Instance {
@ -1200,7 +1199,7 @@ pub const Interface = gpu.Interface(struct {
pub inline fn textureViewRelease(texture_view: *gpu.TextureView) void {
procs.textureViewRelease.?(@ptrCast(c.WGPUTextureView, texture_view));
}
});
};
test "dawn_impl" {
_ = gpu.Export(Interface);

View file

@ -9,8 +9,8 @@ pub const Impl = blk: {
break :blk StubInterface;
} else {
const root = @import("root");
if (!@hasField(root, "GPUInterface")) @compileError("expected to find `pub const GPUInterface = T;` in root file");
_ = gpu.Interface(@TypeOf(root.GPUInterface)); // verify the type
if (!@hasDecl(root, "GPUInterface")) @compileError("expected to find `pub const GPUInterface = T;` in root file");
_ = gpu.Interface(root.GPUInterface); // verify the type
break :blk root.GPUInterface;
}
};