From cd2dc0c2e8e295d733f32d131048a1effc418a70 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 11 Mar 2022 13:22:18 -0700 Subject: [PATCH] gpu: add Device.destroy Signed-off-by: Stephen Gutekanst --- gpu/src/Device.zig | 9 +++++++-- gpu/src/NativeInstance.zig | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gpu/src/Device.zig b/gpu/src/Device.zig index e8145e84..ddcad79a 100644 --- a/gpu/src/Device.zig +++ b/gpu/src/Device.zig @@ -39,7 +39,7 @@ pub const VTable = struct { createShaderModule: fn (ptr: *anyopaque, descriptor: *const ShaderModule.Descriptor) ShaderModule, nativeCreateSwapChain: fn (ptr: *anyopaque, surface: ?Surface, descriptor: *const SwapChain.Descriptor) SwapChain, // WGPU_EXPORT WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor); - // WGPU_EXPORT void wgpuDeviceDestroy(WGPUDevice device); + destroy: fn (ptr: *anyopaque) void, // WGPU_EXPORT size_t wgpuDeviceEnumerateFeatures(WGPUDevice device, WGPUFeature * features); // WGPU_EXPORT bool wgpuDeviceGetLimits(WGPUDevice device, WGPUSupportedLimits * limits); getQueue: fn (ptr: *anyopaque) Queue, @@ -77,6 +77,10 @@ pub inline fn nativeCreateSwapChain(device: Device, surface: ?Surface, descripto return device.vtable.nativeCreateSwapChain(device.ptr, surface, descriptor); } +pub inline fn destroy(device: Device) void { + device.vtable.destroy(device.ptr); +} + // TODO: docs pub const Descriptor = struct { label: ?[*:0]const u8 = null, @@ -90,6 +94,7 @@ test "syntax" { _ = reference; _ = release; _ = createShaderModule; - _ = Descriptor; _ = nativeCreateSwapChain; + _ = destroy; + _ = Descriptor; } diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index a2e9240b..59bfc40f 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -377,6 +377,11 @@ const device_vtable = Device.VTable{ )); } }).nativeCreateSwapChain, + .destroy = (struct { + pub fn destroy(ptr: *anyopaque) void { + c.wgpuDeviceDestroy(@ptrCast(c.WGPUDestroy, ptr)); + } + }).destroy, }; // TODO: maybe make Limits an extern struct that can be cast?