From ab71c7fd9310f20537347c38a2fd1fe1b7fa02c7 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 1 Aug 2022 00:52:07 -0700 Subject: [PATCH] gpu: make ShaderModule.Descriptor.next_in_chain type-safe Signed-off-by: Stephen Gutekanst --- gpu/README.md | 6 +----- gpu/src/shader_module.zig | 12 +++++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gpu/README.md b/gpu/README.md index 3509106a..3fcbda33 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -223,8 +223,4 @@ The following are definitive candidates for helpers we haven't implemented yet: * `gpu.RenderBundleEncoder.setBindGroup` (slice param) * `gpu.RenderPassEncoder.executeBundles` (slice param) * `gpu.RenderPassEncoder.setBindGroup` (slice param) - -Descriptors `next_in_chain` extensions could be more type-safe, at least: - -* `gpu.ShaderModule.Descriptor` (WGSL/SPIRV divide simplification) -* Others mentioned after the bug we filed on Dawn was fixed (consult dawn.json now) +* Other `next_in_chain` extensions (look at dawn.json after the bug to get this documented was fixed) diff --git a/gpu/src/shader_module.zig b/gpu/src/shader_module.zig index e30fb2dc..3d14529f 100644 --- a/gpu/src/shader_module.zig +++ b/gpu/src/shader_module.zig @@ -5,19 +5,25 @@ const CompilationInfo = @import("types.zig").CompilationInfo; const Impl = @import("interface.zig").Impl; pub const ShaderModule = opaque { + pub const Extension = extern union { + generic: ?*const ChainedStruct, + spirv_descriptor: ?*const SPIRVDescriptor, + wgsl_descriptor: ?*const WGSLDescriptor, + }; + pub const Descriptor = extern struct { - next_in_chain: ?*const ChainedStruct = null, + next_in_chain: Extension = .{ .generic = null }, label: ?[*:0]const u8 = null, }; pub const SPIRVDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .shader_module_spirv_descriptor }, code_size: u32, code: [*]const u32, }; pub const WGSLDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .shader_module_wgsl_descriptor }, source: [*:0]const u8, };