zgpu

git clone git://git.electrosoup.com/zgpu
Log | Files | Refs | Submodules | README

commit a1438671139709c4339234bfb041b2be2656463b
parent 03fd82ba75eb81f0ef56e9c26d33f7e3019a5b0e
Author: Christian Ermann <christianermann@gmail.com>
Date:   Mon, 21 Oct 2024 16:49:24 -0700

Create and release Instance

Diffstat:
Asrc/common.zig | 24++++++++++++++++++++++++
Asrc/instance.zig | 24++++++++++++++++++++++++
Msrc/root.zig | 13+++++--------
3 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/src/common.zig b/src/common.zig @@ -0,0 +1,24 @@ +const c = @cImport({ + @cInclude("webgpu.h"); +}); + +pub const SType = enum(u32) { + invalid = 0x00000000, + surface_descriptor_from_metal_layer = 0x00000001, + surface_descriptor_from_windows_hwnd = 0x00000002, + surface_descriptor_from_xlib_window = 0x00000003, + surface_descriptor_from_canvas_html_selector = 0x00000004, + shader_module_spirv_descriptor = 0x00000005, + shader_module_wgsl_descriptor = 0x00000006, + primitive_depth_clip_control = 0x00000007, + surface_descriptor_from_wayland_surface = 0x00000008, + surface_descriptor_from_android_native_window = 0x00000009, + surface_descriptor_from_xcb_window = 0x0000000A, + render_pass_descriptor_max_draw_count = 0x0000000F, + force_32 = 0x7FFFFFFF, +}; + +pub const ChainedStruct = extern struct { + next: ?*const ChainedStruct, + s_type: SType, +}; diff --git a/src/instance.zig b/src/instance.zig @@ -0,0 +1,24 @@ +const c = @cImport({ + @cInclude("webgpu.h"); +}); + +const ChainedStruct = @import("common.zig").ChainedStruct; + +pub const Instance = opaque { + pub const Descriptor = extern struct { + next_in_chain: ?*const ChainedStruct = null, + }; + + pub fn create(descriptor: ?*const Descriptor) ?*Instance { + return @ptrCast(c.wgpuCreateInstance(@ptrCast(descriptor))); + } + + pub fn release(instance: *Instance) void { + c.wgpuInstanceRelease(@ptrCast(instance)); + } + + // createSurface(...) + // hasWGSLLanguageFeature(...) + // requestAdapter(...) + // reference(...) +}; diff --git a/src/root.zig b/src/root.zig @@ -1,13 +1,10 @@ -//! By convention, root.zig is the root source file when making a library. If -//! you are making an executable, the convention is to delete this file and -//! start with main.zig instead. const std = @import("std"); const testing = std.testing; -export fn add(a: i32, b: i32) i32 { - return a + b; -} +const Instance = @import("instance.zig").Instance; -test "basic add functionality" { - try testing.expect(add(3, 7) == 10); +test "create instance" { + const instance = Instance.create(null); + try testing.expect(instance != null); + instance.?.release(); }