From 311f2967a53520631c9b71c14bd17d014e89d032 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 18 Mar 2022 17:59:06 -0700 Subject: [PATCH] gpu: implement Device.loseForTesting Signed-off-by: Stephen Gutekanst --- gpu/src/Device.zig | 8 ++++++-- gpu/src/NativeInstance.zig | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gpu/src/Device.zig b/gpu/src/Device.zig index 55e20284..701877fb 100644 --- a/gpu/src/Device.zig +++ b/gpu/src/Device.zig @@ -70,8 +70,7 @@ pub const VTable = struct { // TODO: should hasFeature be a helper method? // WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeature feature); injectError: fn (ptr: *anyopaque, type: ErrorType, message: [*:0]const u8) void, - // loseForTesting: fn (ptr: *anyopaque) void, - // WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device); + loseForTesting: fn (ptr: *anyopaque) void, // TODO: callback // popErrorScope: fn (ptr: *anyopaque, callback: ErrorCallback) bool, // WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata); @@ -105,6 +104,10 @@ pub inline fn injectError(device: Device, typ: ErrorType, message: [*:0]const u8 device.vtable.injectError(device.ptr, typ, message); } +pub inline fn loseForTesting(device: Device) void { + device.vtable.loseForTesting(device.ptr); +} + pub inline fn createBindGroup(device: Device, descriptor: *const BindGroup.Descriptor) BindGroup { return device.vtable.createBindGroup(device.ptr, descriptor); } @@ -209,6 +212,7 @@ test { _ = release; _ = getQueue; _ = injectError; + _ = loseForTesting; _ = createBindGroup; _ = createBindGroupLayout; _ = createSampler; diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 378ddabf..0827e4c0 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -327,6 +327,11 @@ const device_vtable = Device.VTable{ c.wgpuDeviceInjectError(@ptrCast(c.WGPUDevice, ptr), @enumToInt(typ), message); } }).injectError, + .loseForTesting = (struct { + pub fn loseForTesting(ptr: *anyopaque) void { + c.wgpuDeviceLoseForTesting(@ptrCast(c.WGPUDevice, ptr)); + } + }).loseForTesting, .createBindGroup = (struct { pub fn createBindGroup(ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup { var few_entries: [16]c.WGPUBindGroupEntry = undefined;