gpu: add getProcAddress

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-24 15:18:13 -07:00 committed by Stephen Gutekanst
parent c0ad349a12
commit 2d6dbd3351
3 changed files with 17 additions and 2 deletions

View file

@ -1,9 +1,11 @@
const Instance = @import("instance.zig").Instance;
const InstanceDescriptor = @import("instance.zig").InstanceDescriptor;
const gpu = @import("main.zig");
/// Verifies that a gpu.Interface implementation exposes the expected function declarations.
pub fn Interface(comptime Impl: type) type {
assertDecl(Impl, "createInstance", fn (descriptor: *const InstanceDescriptor) callconv(.Inline) ?Instance);
assertDecl(Impl, "getProcAddress", fn (device: gpu.Device, proc_name: [*:0]const u8) callconv(.Inline) ?gpu.Proc);
return Impl;
}
@ -21,6 +23,11 @@ pub fn Export(comptime Impl: type) type {
export fn wgpuCreateInstance(descriptor: *const InstanceDescriptor) ?Instance {
return Impl.createInstance(descriptor);
}
// WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName);
export fn getProcAddress(device: gpu.Device, proc_name: [*:0]const u8) ?gpu.Proc {
return Impl.getProcAddress(device, proc_name);
}
};
}
@ -30,6 +37,12 @@ pub const NullInterface = Interface(struct {
_ = descriptor;
return null;
}
pub inline fn getProcAddress(device: gpu.Device, proc_name: [*:0]const u8) ?gpu.Proc {
_ = device;
_ = proc_name;
return null;
}
});
test "null" {