examples: zig fmt
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
3b86aa08cc
commit
8137f1a914
1 changed files with 42 additions and 50 deletions
|
|
@ -1,6 +1,5 @@
|
|||
/// A port of Austin Eng's "computeBoids" webgpu sample.
|
||||
/// https://github.com/austinEng/webgpu-samples/blob/main/src/sample/computeBoids/main.ts
|
||||
|
||||
const std = @import("std");
|
||||
const mach = @import("mach");
|
||||
const gpu = @import("gpu");
|
||||
|
|
@ -90,23 +89,17 @@ pub fn main() !void {
|
|||
},
|
||||
},
|
||||
},
|
||||
.fragment = &gpu.FragmentState{
|
||||
.module = sprite_shader_module,
|
||||
.entry_point = "frag_main",
|
||||
.targets = &[_]gpu.ColorTargetState{
|
||||
.fragment = &gpu.FragmentState{ .module = sprite_shader_module, .entry_point = "frag_main", .targets = &[_]gpu.ColorTargetState{
|
||||
.{
|
||||
.format = app.swap_chain_format,
|
||||
},
|
||||
}
|
||||
},
|
||||
} },
|
||||
});
|
||||
|
||||
const compute_pipeline = app.device.createComputePipeline(&gpu.ComputePipeline.Descriptor{
|
||||
.compute = gpu.ProgrammableStageDescriptor{
|
||||
const compute_pipeline = app.device.createComputePipeline(&gpu.ComputePipeline.Descriptor{ .compute = gpu.ProgrammableStageDescriptor{
|
||||
.module = update_sprite_shader_module,
|
||||
.entry_point = "main",
|
||||
}
|
||||
});
|
||||
} });
|
||||
|
||||
const vert_buffer_data = [_]f32{
|
||||
-0.01, -0.02, 0.01,
|
||||
|
|
@ -141,7 +134,11 @@ pub fn main() !void {
|
|||
i = 0;
|
||||
while (i < 2) : (i += 1) {
|
||||
particle_buffers[i] = app.device.createBuffer(&gpu.Buffer.Descriptor{
|
||||
.usage = .{.vertex = true, .copy_dst = true, .storage = true, },
|
||||
.usage = .{
|
||||
.vertex = true,
|
||||
.copy_dst = true,
|
||||
.storage = true,
|
||||
},
|
||||
.size = initial_particle_data.len * @sizeOf(f32),
|
||||
});
|
||||
app.device.getQueue().writeBuffer(particle_buffers[i], 0, f32, &initial_particle_data);
|
||||
|
|
@ -149,14 +146,11 @@ pub fn main() !void {
|
|||
|
||||
i = 0;
|
||||
while (i < 2) : (i += 1) {
|
||||
particle_bind_groups[i] = app.device.createBindGroup(&gpu.BindGroup.Descriptor{
|
||||
.layout = compute_pipeline.getBindGroupLayout(0),
|
||||
.entries = &[_]gpu.BindGroup.Entry {
|
||||
particle_bind_groups[i] = app.device.createBindGroup(&gpu.BindGroup.Descriptor{ .layout = compute_pipeline.getBindGroupLayout(0), .entries = &[_]gpu.BindGroup.Entry{
|
||||
gpu.BindGroup.Entry.buffer(0, sim_param_buffer, 0, sim_params.len * @sizeOf(f32)),
|
||||
gpu.BindGroup.Entry.buffer(1, particle_buffers[i], 0, initial_particle_data.len * @sizeOf(f32)),
|
||||
gpu.BindGroup.Entry.buffer(2, particle_buffers[(i + 1) % 2], 0, initial_particle_data.len * @sizeOf(f32)),
|
||||
}
|
||||
});
|
||||
} });
|
||||
}
|
||||
|
||||
ctx.* = FrameParams{
|
||||
|
|
@ -182,11 +176,9 @@ fn frame(app: *App, params: *FrameParams) !void {
|
|||
.store_op = .store,
|
||||
};
|
||||
|
||||
const render_pass_descriptor = gpu.RenderPassEncoder.Descriptor{
|
||||
.color_attachments = &[_]gpu.RenderPassColorAttachment {
|
||||
const render_pass_descriptor = gpu.RenderPassEncoder.Descriptor{ .color_attachments = &[_]gpu.RenderPassColorAttachment{
|
||||
color_attachment,
|
||||
}
|
||||
};
|
||||
} };
|
||||
|
||||
sim_params[0] = @floatCast(f32, app.delta_time);
|
||||
app.device.getQueue().writeBuffer(params.sim_param_buffer, 0, f32, &sim_params);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue