commit f3728633b9437471650816d0620fd71f8dcb2fb6
parent 8f6bd18943a0e6fac3cfdd22267f63801b829606
Author: Christian Ermann <christian.ermann@joescan.com>
Date: Tue, 15 Jul 2025 19:20:23 -0700
Add bind groups
Diffstat:
10 files changed, 206 insertions(+), 10 deletions(-)
diff --git a/src/wgpu-bindings/bind_group.zig b/src/wgpu-bindings/bind_group.zig
@@ -0,0 +1,27 @@
+const c = @import("c.zig").c;
+const ChainedStruct = @import("common.zig").ChainedStruct;
+const StringView = @import("common.zig").StringView;
+const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
+const Buffer = @import("buffer.zig").Buffer;
+const Sampler = @import("sampler.zig").Sampler;
+const TextureView = @import("texture_view.zig").TextureView;
+
+pub const BindGroup = opaque {
+ pub const Descriptor = extern struct {
+ next: ?*ChainedStruct = null,
+ label: StringView,
+ layout: *BindGroupLayout,
+ entry_count: usize,
+ entries: ?[*]const Entry,
+ };
+
+ pub const Entry = extern struct {
+ next: ?*ChainedStruct = null,
+ binding: u32,
+ buffer: ?*Buffer,
+ offset: u64,
+ size: u64,
+ sampler: ?*Sampler,
+ texture_view: ?*TextureView,
+ };
+};
diff --git a/src/wgpu-bindings/bind_group_layout.zig b/src/wgpu-bindings/bind_group_layout.zig
@@ -5,14 +5,14 @@ const Texture = @import("texture.zig").Texture;
const TextureView = @import("texture_view.zig").TextureView;
pub const BindGroupLayout = opaque {
- const Descriptor = extern struct {
+ pub const Descriptor = extern struct {
next: ?*ChainedStruct = null,
label: StringView,
entry_count: usize,
entries: ?[*]const Entry,
};
- const Entry = extern struct {
+ pub const Entry = extern struct {
next: ?*ChainedStruct = null,
binding: u32,
visibility: ShaderStage,
diff --git a/src/wgpu-bindings/buffer.zig b/src/wgpu-bindings/buffer.zig
@@ -0,0 +1,42 @@
+const c = @import("c.zig").c;
+const ChainedStruct = @import("common.zig").ChainedStruct;
+const StringView = @import("common.zig").StringView;
+
+pub const Buffer = opaque {
+ pub const Descriptor = extern struct {
+ next: ?*const ChainedStruct = null,
+ label: StringView,
+ usage: Usage,
+ size: u64,
+ mapped_at_creation: bool,
+ };
+
+ const Usage = packed struct(u64) {
+ map_read: bool = false,
+ map_write: bool = false,
+ copy_src: bool = false,
+ copy_dst: bool = false,
+ index: bool = false,
+ vertex: bool = false,
+ uniform: bool = false,
+ storage: bool = false,
+ indirect: bool = false,
+ query_resolve: bool = false,
+ _padding: u54 = 0,
+ };
+
+ pub fn unmap(buffer: *Buffer) void {
+ c.wgpuBufferUnmap(@ptrCast(buffer));
+ }
+
+ // destroy
+ // getConstMappedRange
+ // getMapState
+ // getMappedRange
+ // getSize
+ // getUsage
+ // mapAsync
+ // setLabel
+ // addRef
+ // release
+};
diff --git a/src/wgpu-bindings/device.zig b/src/wgpu-bindings/device.zig
@@ -1,14 +1,19 @@
const std = @import("std");
const c = @import("c.zig").c;
+const BindGroup = @import("bind_group.zig").BindGroup;
+const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
+const Buffer = @import("buffer.zig").Buffer;
const CallbackMode = @import("common.zig").CallbackMode;
const ChainedStruct = @import("common.zig").ChainedStruct;
const CommandEncoder = @import("command_encoder.zig").CommandEncoder;
const PipelineLayout = @import("pipeline_layout.zig").PipelineLayout;
const Queue = @import("queue.zig").Queue;
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
+const Sampler = @import("sampler.zig").Sampler;
const ShaderModule = @import("shader_module.zig").ShaderModule;
const StringView = @import("common.zig").StringView;
+const Texture = @import("texture.zig").Texture;
pub const FeatureName = enum(u32) {
undefined = 0x00000000,
@@ -175,18 +180,61 @@ pub const Device = opaque {
));
}
- // createBindGroup
- // createBindGroupLayout
- // createBuffer
+ pub fn createBindGroupLayout(
+ device: *Device,
+ descriptor: *const BindGroupLayout.Descriptor,
+ ) ?*BindGroupLayout {
+ return @ptrCast(c.wgpuDeviceCreateBindGroupLayout(
+ @ptrCast(device),
+ @ptrCast(descriptor),
+ ));
+ }
+
+ pub fn createBindGroup(
+ device: *Device,
+ descriptor: *const BindGroup.Descriptor,
+ ) ?*BindGroup {
+ return @ptrCast(c.wgpuDeviceCreateBindGroup(
+ @ptrCast(device),
+ @ptrCast(descriptor),
+ ));
+ }
+
+ pub fn createBuffer(
+ device: *Device,
+ descriptor: *const Buffer.Descriptor,
+ ) ?*Buffer {
+ return @ptrCast(c.wgpuDeviceCreateBuffer(
+ @ptrCast(device),
+ @ptrCast(descriptor),
+ ));
+ }
+
+ pub fn createSampler(
+ device: *Device,
+ descriptor: *const Sampler.Descriptor,
+ ) ?*Sampler {
+ return @ptrCast(c.wgpuDeviceCreateSampler(
+ @ptrCast(device),
+ @ptrCast(descriptor),
+ ));
+ }
+
+ pub fn createTexture(
+ device: *Device,
+ descriptor: *const Texture.Descriptor,
+ ) ?*Texture {
+ return @ptrCast(c.wgpuDeviceCreateTexture(
+ @ptrCast(device),
+ @ptrCast(descriptor),
+ ));
+ }
+
// createComputePipeline
// createComputePipelineAsync
- // createPipelineLayout
// createQuerySet
// createRenderBundleEncoder
// createRenderPipelineAsync
- // createSampler
- // createShaderModule
- // createTexture
// destroy
// enumerateFeatures
// getLimits
diff --git a/src/wgpu-bindings/main.zig b/src/wgpu-bindings/main.zig
@@ -61,8 +61,10 @@ pub fn main() !void {
.flags = .validation,
.dx12_compiler = .undefined,
.gles3_minor_version = .automatic,
+ .gl_fence_behavior = .normal,
.dxil_path = null,
.dxc_path = null,
+ .dxc_max_shader_model = .dxc_max_shader_model_v6_0,
},
},
.features = .{
diff --git a/src/wgpu-bindings/pipeline_layout.zig b/src/wgpu-bindings/pipeline_layout.zig
@@ -8,7 +8,7 @@ pub const PipelineLayout = opaque {
next: ?*ChainedStruct = null,
label: StringView,
bind_group_layout_count: u64,
- bind_group_layouts: ?*const BindGroupLayout,
+ bind_group_layouts: ?[*]const *BindGroupLayout,
};
pub fn release(pipeline_layout: *PipelineLayout) void {
diff --git a/src/wgpu-bindings/queue.zig b/src/wgpu-bindings/queue.zig
@@ -1,4 +1,5 @@
const c = @import("c.zig").c;
+const Buffer = @import("buffer.zig").Buffer;
const ChainedStruct = @import("common.zig").ChainedStruct;
const CommandBuffer = @import("command_buffer.zig").CommandBuffer;
const StringView = @import("common.zig").StringView;
@@ -21,6 +22,23 @@ pub const Queue = opaque {
);
}
+ pub fn writeBuffer(
+ queue: *Queue,
+ buffer: *Buffer,
+ buffer_offset: u64,
+ data: [*]const u8,
+ size: usize,
+ ) void {
+ c.wgpuQueueWriteBuffer(
+ @ptrCast(queue),
+ @ptrCast(buffer),
+ buffer_offset,
+ @ptrCast(data),
+ size,
+ );
+ }
+
+
// onSubmittedWorkDone
// setLabel
// writeBuffer
diff --git a/src/wgpu-bindings/render_pass.zig b/src/wgpu-bindings/render_pass.zig
@@ -1,6 +1,7 @@
const c = @import("c.zig").c;
const ChainedStruct = @import("common.zig").ChainedStruct;
const Color = @import("common.zig").Color;
+const BindGroup = @import("bind_group.zig").BindGroup;
const LoadOp = @import("common.zig").LoadOp;
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
const StoreOp = @import("common.zig").StoreOp;
@@ -71,6 +72,22 @@ pub const RenderPassEncoder = opaque {
);
}
+ pub fn setBindGroup(
+ encoder: *RenderPassEncoder,
+ group_index: u32,
+ bind_group: *BindGroup,
+ dynamic_offset_count: usize,
+ dynamic_offsets: ?[*]u32,
+ ) void {
+ c.wgpuRenderPassEncoderSetBindGroup(
+ @ptrCast(encoder),
+ group_index,
+ @ptrCast(bind_group),
+ dynamic_offset_count,
+ dynamic_offsets,
+ );
+ }
+
pub fn draw(
encoder: *RenderPassEncoder,
vertex_count: u32,
diff --git a/src/wgpu-bindings/root.zig b/src/wgpu-bindings/root.zig
@@ -37,7 +37,9 @@ pub const RenderPass = render_pass.RenderPass;
pub const RenderPassEncoder = render_pass.RenderPassEncoder;
pub const Adapter = @import("adapter.zig").Adapter;
+pub const BindGroup = @import("bind_group.zig").BindGroup;
pub const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
+pub const Buffer = @import("buffer.zig").Buffer;
pub const CommandBuffer = @import("command_buffer.zig").CommandBuffer;
pub const CommandEncoder = @import("command_encoder.zig").CommandEncoder;
pub const PipelineLayout = @import("pipeline_layout.zig").PipelineLayout;
diff --git a/src/wgpu-bindings/sampler.zig b/src/wgpu-bindings/sampler.zig
@@ -0,0 +1,40 @@
+const c = @import("c.zig").c;
+const ChainedStruct = @import("common.zig").ChainedStruct;
+const CompareFunction = @import("common.zig").CompareFunction;
+const StringView = @import("common.zig").StringView;
+
+pub const AddressMode = enum(u32) {
+ undefined = 0x00000000,
+ clamp_to_edge = 0x00000001,
+ repeat = 0x00000002,
+ mirror_repeat = 0x00000003,
+};
+
+pub const FilterMode = enum(u32) {
+ undefined = 0x00000000,
+ nearest = 0x00000001,
+ linear = 0x00000002,
+};
+
+pub const MipmapFilterMode = enum(u32) {
+ undefined = 0x00000000,
+ nearest = 0x00000001,
+ linear = 0x00000002,
+};
+
+pub const Sampler = opaque {
+ pub const Descriptor = extern struct {
+ next: ?*ChainedStruct = null,
+ label: StringView,
+ address_mode_u: AddressMode,
+ address_mode_v: AddressMode,
+ address_mode_w: AddressMode,
+ mag_filter: FilterMode,
+ min_filter: FilterMode,
+ mipmap_filter: MipmapFilterMode,
+ lod_min_clamp: f32,
+ lod_max_clamp: f32,
+ compare: CompareFunction,
+ max_anisotropy: u16,
+ };
+};