gpu: expose API and begin using in example

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-06 21:38:36 -07:00 committed by Stephen Gutekanst
parent d32be19c8b
commit 8f5e9f89e5
4 changed files with 13 additions and 9 deletions

View file

@ -27,6 +27,7 @@ pub fn build(b: *std.build.Builder) void {
example.setBuildMode(mode);
example.install();
example.linkLibC();
example.addPackagePath("gpu", "src/main.zig");
example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig");
glfw.link(b, example, .{});
gpu_dawn.link(b, example, .{});

View file

@ -1,6 +1,7 @@
const std = @import("std");
const assert = std.debug.assert;
const glfw = @import("glfw");
const gpu = @import("gpu");
const c = @import("c.zig").c;
const objc = @cImport({
@cInclude("objc/message.h");
@ -17,6 +18,7 @@ fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, _: ?*any
}
const Setup = struct {
native_instance: gpu.NativeInstance,
instance: c.WGPUInstance,
backend_type: c.WGPUBackendType,
device: c.WGPUDevice,
@ -97,6 +99,7 @@ pub fn setup(allocator: std.mem.Allocator) !Setup {
c.dawnProcSetProcs(backend_procs);
backend_procs.*.deviceSetUncapturedErrorCallback.?(backend_device, printDeviceError, null);
return Setup{
.native_instance = gpu.NativeInstance.wrap(c.machDawnNativeInstance_get(instance).?),
.instance = c.machDawnNativeInstance_get(instance),
.backend_type = backend_type,
.device = backend_device,

View file

@ -11,9 +11,9 @@ instance: c.WGPUInstance,
vtable: Interface.VTable,
/// Wraps a native WGPUInstance to provide an implementation of the gpu.Interface.
pub fn wrap(instance: c.WGPUInstance) NativeInstance {
pub fn wrap(instance: *anyopaque) NativeInstance {
return .{
.instance = instance,
.instance = @ptrCast(c.WGPUInstance, instance),
.vtable = undefined, // TODO
};
}

View file

@ -16,15 +16,15 @@
//!
//!
const std = @import("std");
const Interface = @import("Interface.zig");
const NativeInstance = @import("NativeInstance.zig");
pub const Interface = @import("Interface.zig");
pub const NativeInstance = @import("NativeInstance.zig");
const Adapter = @import("Adapter.zig");
const Device = @import("Device.zig");
const Surface = @import("Surface.zig");
pub const Adapter = @import("Adapter.zig");
pub const Device = @import("Device.zig");
pub const Surface = @import("Surface.zig");
const FeatureName = @import("feature_name.zig").FeatureName;
const SupportedLimits = @import("supported_limits.zig").SupportedLimits;
pub const FeatureName = @import("feature_name.zig").FeatureName;
pub const SupportedLimits = @import("supported_limits.zig").SupportedLimits;
test "syntax" {
_ = Interface;