commit 48879993ed11ac676a6c2b719627475e4a920484
parent ab98ceef3563a133a5a8366e6c2f63058789df53
Author: Christian Ermann <christianermann@gmail.com>
Date: Wed, 8 May 2024 19:51:40 -0400
Move buffer and bind group layout definitions to render pipeline
Diffstat:
M | src/main.zig | | | 78 | +++++++++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/src/main.zig b/src/main.zig
@@ -546,43 +546,6 @@ pub const Mesh = struct {
.{ self.offset[0], self.offset[1], self.offset[2], 1 },
} };
}
-
- pub fn bufferLayouts() [3]gpu.VertexBufferLayout {
- const positions = gpu.VertexBufferLayout.init(.{
- .array_stride = @sizeOf(f32x4),
- .step_mode = .vertex,
- .attributes = &.{
- .{ .format = .float32x4, .shader_location = 0, .offset = 0 },
- },
- });
- const normals = gpu.VertexBufferLayout.init(.{
- .array_stride = @sizeOf(f32x4),
- .step_mode = .vertex,
- .attributes = &.{
- .{ .format = .float32x3, .shader_location = 1, .offset = 0 },
- },
- });
- const tex_coords = gpu.VertexBufferLayout.init(.{
- .array_stride = @sizeOf(f32x4),
- .step_mode = .vertex,
- .attributes = &.{
- .{ .format = .float32x3, .shader_location = 2, .offset = 0 },
- },
- });
- return .{ positions, normals, tex_coords };
- }
-
- pub fn bindGroupLayout(device: *gpu.Device) *gpu.BindGroupLayout {
- const descriptor = gpu.BindGroupLayout.Descriptor.init(.{
- .entries = &.{
- gpu.BindGroupLayout.Entry.buffer(0, .{
- .vertex = true,
- .fragment = false,
- }, .read_only_storage, false, 0),
- },
- });
- return device.createBindGroupLayout(&descriptor);
- }
};
const UnlitRenderPipeline = struct {
@@ -610,7 +573,7 @@ const UnlitRenderPipeline = struct {
const vs_module = app.device.createShaderModuleWGSL("default vertex shader", vs);
defer vs_module.release();
- const layouts = Mesh.bufferLayouts();
+ const layouts = UnlitRenderPipeline.bufferLayouts();
const vertex = gpu.VertexState.init(.{
.module = vs_module,
.entry_point = "main",
@@ -637,7 +600,7 @@ const UnlitRenderPipeline = struct {
.targets = &.{color_target},
});
- const bind_group_layout = Mesh.bindGroupLayout(app.device);
+ const bind_group_layout = UnlitRenderPipeline.bindGroupLayout(app.device);
const bind_group_descriptor = gpu.BindGroup.Descriptor.init(.{
.layout = bind_group_layout,
.entries = &.{
@@ -673,6 +636,43 @@ const UnlitRenderPipeline = struct {
};
}
+ fn bufferLayouts() [3]gpu.VertexBufferLayout {
+ const positions = gpu.VertexBufferLayout.init(.{
+ .array_stride = @sizeOf(f32x4),
+ .step_mode = .vertex,
+ .attributes = &.{
+ .{ .format = .float32x4, .shader_location = 0, .offset = 0 },
+ },
+ });
+ const normals = gpu.VertexBufferLayout.init(.{
+ .array_stride = @sizeOf(f32x4),
+ .step_mode = .vertex,
+ .attributes = &.{
+ .{ .format = .float32x3, .shader_location = 1, .offset = 0 },
+ },
+ });
+ const tex_coords = gpu.VertexBufferLayout.init(.{
+ .array_stride = @sizeOf(f32x4),
+ .step_mode = .vertex,
+ .attributes = &.{
+ .{ .format = .float32x3, .shader_location = 2, .offset = 0 },
+ },
+ });
+ return .{ positions, normals, tex_coords };
+ }
+
+ fn bindGroupLayout(device: *gpu.Device) *gpu.BindGroupLayout {
+ const descriptor = gpu.BindGroupLayout.Descriptor.init(.{
+ .entries = &.{
+ gpu.BindGroupLayout.Entry.buffer(0, .{
+ .vertex = true,
+ .fragment = false,
+ }, .read_only_storage, false, 0),
+ },
+ });
+ return device.createBindGroupLayout(&descriptor);
+ }
+
pub fn frame(ptr: *anyopaque, pass: *gpu.RenderPassEncoder) void {
const self: *UnlitRenderPipeline = @ptrCast(@alignCast(ptr));
pass.setPipeline(self.gpu_pipeline);