From e9dcb49328c1d39242fb9bca2f7a469e23b92ad0 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 30 Jul 2022 00:02:25 -0700 Subject: [PATCH] gpu: internalize SwapChain types Signed-off-by: Stephen Gutekanst --- gpu/src/device.zig | 3 +-- gpu/src/interface.zig | 6 +++--- gpu/src/swap_chain.zig | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/gpu/src/device.zig b/gpu/src/device.zig index 600c49a1..504b4f2c 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -13,7 +13,6 @@ const Sampler = @import("sampler.zig").Sampler; const ShaderModule = @import("shader_module.zig").ShaderModule; const Surface = @import("surface.zig").Surface; const SwapChain = @import("swap_chain.zig").SwapChain; -const SwapChainDescriptor = @import("swap_chain.zig").SwapChainDescriptor; const Texture = @import("texture.zig").Texture; const TextureDescriptor = @import("texture.zig").TextureDescriptor; const ChainedStruct = @import("types.zig").ChainedStruct; @@ -113,7 +112,7 @@ pub const Device = opaque { return Impl.deviceCreateShaderModule(device, descriptor); } - pub inline fn createSwapChain(device: *Device, surface: ?*Surface, descriptor: *const SwapChainDescriptor) *SwapChain { + pub inline fn createSwapChain(device: *Device, surface: ?*Surface, descriptor: *const SwapChain.Descriptor) *SwapChain { return Impl.deviceCreateSwapChain(device, surface, descriptor); } diff --git a/gpu/src/interface.zig b/gpu/src/interface.zig index 6c283aa3..d8e921c0 100644 --- a/gpu/src/interface.zig +++ b/gpu/src/interface.zig @@ -95,7 +95,7 @@ pub fn Interface(comptime T: type) type { assertDecl(T, "deviceCreateRenderPipelineAsync", fn (device: *gpu.Device, descriptor: *const gpu.RenderPipeline.Descriptor, callback: gpu.CreateRenderPipelineAsyncCallback, userdata: *anyopaque) callconv(.Inline) void); assertDecl(T, "deviceCreateSampler", fn (device: *gpu.Device, descriptor: ?*const gpu.Sampler.Descriptor) callconv(.Inline) *gpu.Sampler); assertDecl(T, "deviceCreateShaderModule", fn (device: *gpu.Device, descriptor: *const gpu.ShaderModule.Descriptor) callconv(.Inline) *gpu.ShaderModule); - assertDecl(T, "deviceCreateSwapChain", fn (device: *gpu.Device, surface: ?*gpu.Surface, descriptor: *const gpu.SwapChainDescriptor) callconv(.Inline) *gpu.SwapChain); + assertDecl(T, "deviceCreateSwapChain", fn (device: *gpu.Device, surface: ?*gpu.Surface, descriptor: *const gpu.SwapChain.Descriptor) callconv(.Inline) *gpu.SwapChain); assertDecl(T, "deviceCreateTexture", fn (device: *gpu.Device, descriptor: *const gpu.TextureDescriptor) callconv(.Inline) *gpu.Texture); assertDecl(T, "deviceDestroy", fn (device: *gpu.Device) callconv(.Inline) void); assertDecl(T, "deviceEnumerateFeatures", fn (device: *gpu.Device, features: [*]gpu.FeatureName) callconv(.Inline) usize); @@ -629,7 +629,7 @@ pub fn Export(comptime T: type) type { } // WGPU_EXPORT WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface /* nullable */, WGPUSwapChainDescriptor const * descriptor); - export fn wgpuDeviceCreateSwapChain(device: *gpu.Device, surface: ?*gpu.Surface, descriptor: *const gpu.SwapChainDescriptor) *gpu.SwapChain { + export fn wgpuDeviceCreateSwapChain(device: *gpu.Device, surface: ?*gpu.Surface, descriptor: *const gpu.SwapChain.Descriptor) *gpu.SwapChain { return T.deviceCreateSwapChain(device, surface, descriptor); } @@ -1715,7 +1715,7 @@ pub const StubInterface = Interface(struct { unreachable; } - pub inline fn deviceCreateSwapChain(device: *gpu.Device, surface: ?*gpu.Surface, descriptor: *const gpu.SwapChainDescriptor) *gpu.SwapChain { + pub inline fn deviceCreateSwapChain(device: *gpu.Device, surface: ?*gpu.Surface, descriptor: *const gpu.SwapChain.Descriptor) *gpu.SwapChain { _ = device; _ = surface; _ = descriptor; diff --git a/gpu/src/swap_chain.zig b/gpu/src/swap_chain.zig index dd812165..960f04f5 100644 --- a/gpu/src/swap_chain.zig +++ b/gpu/src/swap_chain.zig @@ -7,6 +7,18 @@ const TextureView = @import("texture_view.zig").TextureView; const Impl = @import("interface.zig").Impl; pub const SwapChain = opaque { + pub const Descriptor = extern struct { + next_in_chain: ?*const ChainedStruct = null, + label: ?[*:0]const u8 = null, + usage: TextureUsageFlags, + format: TextureFormat, + width: u32, + height: u32, + present_mode: PresentMode, + /// deprecated + implementation: u64 = 0, + }; + pub inline fn configure(swap_chain: *SwapChain, format: TextureFormat, allowed_usage: TextureUsageFlags, width: u32, height: u32) void { Impl.swapChainConfigure(swap_chain, format, allowed_usage, width, height); } @@ -27,15 +39,3 @@ pub const SwapChain = opaque { Impl.swapChainRelease(swap_chain); } }; - -pub const SwapChainDescriptor = extern struct { - next_in_chain: ?*const ChainedStruct = null, - label: ?[*:0]const u8 = null, - usage: TextureUsageFlags, - format: TextureFormat, - width: u32, - height: u32, - present_mode: PresentMode, - /// deprecated - implementation: u64 = 0, -};