From b45ad53a1155574911716fb61b7631b02f96db7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Fri, 9 Jun 2023 09:03:25 +0300 Subject: [PATCH] gpu: make `swapChainGetCurrentTextureView()` return value optional --- libs/gpu/examples/main.zig | 2 +- libs/gpu/src/dawn_impl.zig | 4 ++-- libs/gpu/src/interface.zig | 6 +++--- libs/gpu/src/swap_chain.zig | 2 +- shaderexp/main.zig | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/gpu/examples/main.zig b/libs/gpu/examples/main.zig index 5e79a9a3..9443debd 100644 --- a/libs/gpu/examples/main.zig +++ b/libs/gpu/examples/main.zig @@ -140,7 +140,7 @@ fn frame(params: FrameParams) !void { pl.current_desc = pl.target_desc; } - const back_buffer_view = pl.swap_chain.?.getCurrentTextureView(); + const back_buffer_view = pl.swap_chain.?.getCurrentTextureView().?; const color_attachment = gpu.RenderPassColorAttachment{ .view = back_buffer_view, .resolve_target = null, diff --git a/libs/gpu/src/dawn_impl.zig b/libs/gpu/src/dawn_impl.zig index 2d661466..03019aff 100644 --- a/libs/gpu/src/dawn_impl.zig +++ b/libs/gpu/src/dawn_impl.zig @@ -1157,8 +1157,8 @@ pub const Interface = struct { ); } - pub inline fn swapChainGetCurrentTextureView(swap_chain: *gpu.SwapChain) *gpu.TextureView { - return @ptrCast(*gpu.TextureView, procs.swapChainGetCurrentTextureView.?(@ptrCast(c.WGPUSwapChain, swap_chain))); + pub inline fn swapChainGetCurrentTextureView(swap_chain: *gpu.SwapChain) ?*gpu.TextureView { + return @ptrCast(?*gpu.TextureView, procs.swapChainGetCurrentTextureView.?(@ptrCast(c.WGPUSwapChain, swap_chain))); } pub inline fn swapChainPresent(swap_chain: *gpu.SwapChain) void { diff --git a/libs/gpu/src/interface.zig b/libs/gpu/src/interface.zig index ac665bd0..68621546 100644 --- a/libs/gpu/src/interface.zig +++ b/libs/gpu/src/interface.zig @@ -196,7 +196,7 @@ pub fn Interface(comptime T: type) type { assertDecl(T, "surfaceReference", fn (surface: *gpu.Surface) callconv(.Inline) void); assertDecl(T, "surfaceRelease", fn (surface: *gpu.Surface) callconv(.Inline) void); assertDecl(T, "swapChainConfigure", fn (swap_chain: *gpu.SwapChain, format: gpu.Texture.Format, allowed_usage: gpu.Texture.UsageFlags, width: u32, height: u32) callconv(.Inline) void); - assertDecl(T, "swapChainGetCurrentTextureView", fn (swap_chain: *gpu.SwapChain) callconv(.Inline) *gpu.TextureView); + assertDecl(T, "swapChainGetCurrentTextureView", fn (swap_chain: *gpu.SwapChain) callconv(.Inline) ?*gpu.TextureView); assertDecl(T, "swapChainPresent", fn (swap_chain: *gpu.SwapChain) callconv(.Inline) void); assertDecl(T, "swapChainReference", fn (swap_chain: *gpu.SwapChain) callconv(.Inline) void); assertDecl(T, "swapChainRelease", fn (swap_chain: *gpu.SwapChain) callconv(.Inline) void); @@ -1118,7 +1118,7 @@ pub fn Export(comptime T: type) type { } // WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain); - export fn wgpuSwapChainGetCurrentTextureView(swap_chain: *gpu.SwapChain) *gpu.TextureView { + export fn wgpuSwapChainGetCurrentTextureView(swap_chain: *gpu.SwapChain) ?*gpu.TextureView { return T.swapChainGetCurrentTextureView(swap_chain); } @@ -2342,7 +2342,7 @@ pub const StubInterface = Interface(struct { unreachable; } - pub inline fn swapChainGetCurrentTextureView(swap_chain: *gpu.SwapChain) *gpu.TextureView { + pub inline fn swapChainGetCurrentTextureView(swap_chain: *gpu.SwapChain) ?*gpu.TextureView { _ = swap_chain; unreachable; } diff --git a/libs/gpu/src/swap_chain.zig b/libs/gpu/src/swap_chain.zig index 21e2c3ce..93e24129 100644 --- a/libs/gpu/src/swap_chain.zig +++ b/libs/gpu/src/swap_chain.zig @@ -21,7 +21,7 @@ pub const SwapChain = opaque { Impl.swapChainConfigure(swap_chain, format, allowed_usage, width, height); } - pub inline fn getCurrentTextureView(swap_chain: *SwapChain) *TextureView { + pub inline fn getCurrentTextureView(swap_chain: *SwapChain) ?*TextureView { return Impl.swapChainGetCurrentTextureView(swap_chain); } diff --git a/shaderexp/main.zig b/shaderexp/main.zig index cdf75cc0..978b5b0e 100755 --- a/shaderexp/main.zig +++ b/shaderexp/main.zig @@ -117,7 +117,7 @@ pub fn update(app: *App) !bool { std.log.err("Something went wrong when attempting to stat file: {}\n", .{err}); } - const back_buffer_view = app.core.swapChain().getCurrentTextureView(); + const back_buffer_view = app.core.swapChain().getCurrentTextureView().?; const color_attachment = gpu.RenderPassColorAttachment{ .view = back_buffer_view, .clear_value = std.mem.zeroes(gpu.Color),