From ef3eed7afb788d90660ea547d0826358330a1a75 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 11 Mar 2022 20:14:58 -0700 Subject: [PATCH] gpu: implement SwapChain.present, SwapChain.getCurrentTextureView Signed-off-by: Stephen Gutekanst --- gpu/src/NativeInstance.zig | 10 ++++++++++ gpu/src/SwapChain.zig | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index dffe534b..ad02d1a5 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -587,6 +587,16 @@ const swap_chain_vtable = SwapChain.VTable{ ); } }).configure, + .getCurrentTextureView = (struct { + pub fn getCurrentTextureView(ptr: *anyopaque) TextureView { + return wrapTextureView(c.wgpuSwapChainGetCurrentTextureView(@ptrCast(c.WGPUSwapChain, ptr))); + } + }).getCurrentTextureView, + .present = (struct { + pub fn present(ptr: *anyopaque) void { + c.wgpuSwapChainPresent(@ptrCast(c.WGPUSwapChain, ptr)); + } + }).present, }; fn wrapTextureView(texture_view: c.WGPUTextureView) TextureView { diff --git a/gpu/src/SwapChain.zig b/gpu/src/SwapChain.zig index f17b7595..e8ac14f8 100644 --- a/gpu/src/SwapChain.zig +++ b/gpu/src/SwapChain.zig @@ -1,5 +1,6 @@ const std = @import("std"); const Texture = @import("Texture.zig"); +const TextureView = @import("TextureView.zig"); const PresentMode = @import("enums.zig").PresentMode; const SwapChain = @This(); @@ -13,9 +14,8 @@ pub const VTable = struct { reference: fn (ptr: *anyopaque) void, release: fn (ptr: *anyopaque) void, configure: fn (ptr: *anyopaque, format: Texture.Format, allowed_usage: Texture.Usage, width: u32, height: u32) void, - // TODO: - // WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain); - // WGPU_EXPORT void wgpuSwapChainPresent(WGPUSwapChain swapChain); + getCurrentTextureView: fn (ptr: *anyopaque) TextureView, + present: fn (ptr: *anyopaque) void, }; pub inline fn reference(swap_chain: SwapChain) void { @@ -26,6 +26,7 @@ pub inline fn release(swap_chain: SwapChain) void { swap_chain.vtable.release(swap_chain.ptr); } +// TODO: remove this and/or prefix with dawn? Seems to be deprecated / not in upstream webgpu.h pub inline fn configure( swap_chain: SwapChain, format: Texture.Format, @@ -36,6 +37,14 @@ pub inline fn configure( swap_chain.vtable.configure(swap_chain.ptr, format, allowed_usage, width, height); } +pub inline fn getCurrentTextureView(swap_chain: SwapChain) TextureView { + return swap_chain.vtable.getCurrentTextureView(swap_chain.ptr); +} + +pub inline fn present(swap_chain: SwapChain) void { + swap_chain.vtable.present(swap_chain.ptr); +} + pub const Descriptor = struct { label: ?[:0]const u8 = null, usage: Texture.Usage,