examples: update to new Engine API

This commit is contained in:
iddev5 2022-06-01 12:28:24 +05:30 committed by Stephen Gutekanst
parent 50fe649ab1
commit 03491dfd27
9 changed files with 170 additions and 170 deletions

View file

@ -33,19 +33,19 @@ const Dir = struct {
}; };
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const eye = vec3(5.0, 7.0, 5.0); const eye = vec3(5.0, 7.0, 5.0);
const target = vec3(0.0, 0.0, 0.0); const target = vec3(0.0, 0.0, 0.0);
const size = engine.core.getFramebufferSize(); const size = engine.getFramebufferSize();
const aspect_ratio = @intToFloat(f32, size.width) / @intToFloat(f32, size.height); const aspect_ratio = @intToFloat(f32, size.width) / @intToFloat(f32, size.height);
app.queue = engine.gpu_driver.device.getQueue(); app.queue = engine.device.getQueue();
app.cube = Cube.init(engine); app.cube = Cube.init(engine);
app.light = Light.init(engine); app.light = Light.init(engine);
app.depth = null; app.depth = null;
app.camera = Camera.init(engine.gpu_driver.device, eye, target, vec3(0.0, 1.0, 0.0), aspect_ratio, 45.0, 0.1, 100.0); app.camera = Camera.init(engine.device, eye, target, vec3(0.0, 1.0, 0.0), aspect_ratio, 45.0, 0.1, 100.0);
} }
pub fn deinit(app: *App, _: *mach.Engine) void { pub fn deinit(app: *App, _: *mach.Engine) void {
@ -53,10 +53,10 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| switch (ev.key) { .key_press => |ev| switch (ev.key) {
.q, .escape, .space => engine.core.setShouldClose(true), .q, .escape, .space => engine.setShouldClose(true),
.w, .up => { .w, .up => {
app.keys |= Dir.up; app.keys |= Dir.up;
}, },
@ -108,10 +108,10 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
const light_speed = @floatCast(f32, engine.delta_time * 2.5); const light_speed = @floatCast(f32, engine.delta_time * 2.5);
app.light.update(app.queue, light_speed); app.light.update(app.queue, light_speed);
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
defer back_buffer_view.release(); defer back_buffer_view.release();
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
defer encoder.release(); defer encoder.release();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
@ -168,7 +168,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
defer command.release(); defer command.release();
app.queue.submit(&.{command}); app.queue.submit(&.{command});
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
return true; return true;
} }
@ -179,7 +179,7 @@ pub fn resize(app: *App, engine: *mach.Engine, width: u32, height: u32) !void {
app.depth.?.release(); app.depth.?.release();
} }
// It also recreates the sampler, which is a waste, but for an example it's ok // It also recreates the sampler, which is a waste, but for an example it's ok
app.depth = Texture.depth(engine.gpu_driver.device, width, height); app.depth = Texture.depth(engine.device, width, height);
} }
const Camera = struct { const Camera = struct {
@ -283,7 +283,7 @@ const Cube = struct {
const DISPLACEMENT = vec3u(IPR * SPACING / 2, 0, IPR * SPACING / 2); const DISPLACEMENT = vec3u(IPR * SPACING / 2, 0, IPR * SPACING / 2);
fn init(engine: *mach.Engine) Self { fn init(engine: *mach.Engine) Self {
const device = engine.gpu_driver.device; const device = engine.device;
const texture = Brick.texture(device); const texture = Brick.texture(device);
@ -326,7 +326,7 @@ const Cube = struct {
} }
fn pipeline(engine: *mach.Engine) gpu.RenderPipeline { fn pipeline(engine: *mach.Engine) gpu.RenderPipeline {
const device = engine.gpu_driver.device; const device = engine.device;
const layout_descriptor = gpu.PipelineLayout.Descriptor{ const layout_descriptor = gpu.PipelineLayout.Descriptor{
.bind_group_layouts = &.{ .bind_group_layouts = &.{
@ -358,7 +358,7 @@ const Cube = struct {
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
.blend = &blend, .blend = &blend,
}; };
@ -732,7 +732,7 @@ const Light = struct {
}; };
fn init(engine: *mach.Engine) Self { fn init(engine: *mach.Engine) Self {
const device = engine.gpu_driver.device; const device = engine.device;
const uniform = .{ const uniform = .{
.color = vec3u(1, 1, 1), .color = vec3u(1, 1, 1),
.position = vec3u(3, 7, 2), .position = vec3u(3, 7, 2),
@ -779,7 +779,7 @@ const Light = struct {
} }
fn pipeline(engine: *mach.Engine) gpu.RenderPipeline { fn pipeline(engine: *mach.Engine) gpu.RenderPipeline {
const device = engine.gpu_driver.device; const device = engine.device;
const layout_descriptor = gpu.PipelineLayout.Descriptor{ const layout_descriptor = gpu.PipelineLayout.Descriptor{
.bind_group_layouts = &.{ .bind_group_layouts = &.{
@ -810,7 +810,7 @@ const Light = struct {
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
.blend = &blend, .blend = &blend,
}; };

View file

@ -27,12 +27,12 @@ var sim_params = [_]f32{
}; };
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
const sprite_shader_module = engine.gpu_driver.device.createShaderModule(&.{ const sprite_shader_module = engine.device.createShaderModule(&.{
.label = "sprite shader module", .label = "sprite shader module",
.code = .{ .wgsl = @embedFile("sprite.wgsl") }, .code = .{ .wgsl = @embedFile("sprite.wgsl") },
}); });
const update_sprite_shader_module = engine.gpu_driver.device.createShaderModule(&.{ const update_sprite_shader_module = engine.device.createShaderModule(&.{
.label = "update sprite shader module", .label = "update sprite shader module",
.code = .{ .wgsl = @embedFile("updateSprites.wgsl") }, .code = .{ .wgsl = @embedFile("updateSprites.wgsl") },
}); });
@ -61,7 +61,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const render_pipeline = engine.gpu_driver.device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{ const render_pipeline = engine.device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{
.vertex = .{ .vertex = .{
.module = sprite_shader_module, .module = sprite_shader_module,
.entry_point = "vert_main", .entry_point = "vert_main",
@ -84,12 +84,12 @@ pub fn init(app: *App, engine: *mach.Engine) !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 = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
}, },
} }, } },
}); });
const compute_pipeline = engine.gpu_driver.device.createComputePipeline(&gpu.ComputePipeline.Descriptor{ .compute = gpu.ProgrammableStageDescriptor{ const compute_pipeline = engine.device.createComputePipeline(&gpu.ComputePipeline.Descriptor{ .compute = gpu.ProgrammableStageDescriptor{
.module = update_sprite_shader_module, .module = update_sprite_shader_module,
.entry_point = "main", .entry_point = "main",
} }); } });
@ -99,17 +99,17 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
-0.02, 0.0, 0.02, -0.02, 0.0, 0.02,
}; };
const sprite_vertex_buffer = engine.gpu_driver.device.createBuffer(&gpu.Buffer.Descriptor{ const sprite_vertex_buffer = engine.device.createBuffer(&gpu.Buffer.Descriptor{
.usage = .{ .vertex = true, .copy_dst = true }, .usage = .{ .vertex = true, .copy_dst = true },
.size = vert_buffer_data.len * @sizeOf(f32), .size = vert_buffer_data.len * @sizeOf(f32),
}); });
engine.gpu_driver.device.getQueue().writeBuffer(sprite_vertex_buffer, 0, f32, &vert_buffer_data); engine.device.getQueue().writeBuffer(sprite_vertex_buffer, 0, f32, &vert_buffer_data);
const sim_param_buffer = engine.gpu_driver.device.createBuffer(&gpu.Buffer.Descriptor{ const sim_param_buffer = engine.device.createBuffer(&gpu.Buffer.Descriptor{
.usage = .{ .uniform = true, .copy_dst = true }, .usage = .{ .uniform = true, .copy_dst = true },
.size = sim_params.len * @sizeOf(f32), .size = sim_params.len * @sizeOf(f32),
}); });
engine.gpu_driver.device.getQueue().writeBuffer(sim_param_buffer, 0, f32, &sim_params); engine.device.getQueue().writeBuffer(sim_param_buffer, 0, f32, &sim_params);
var initial_particle_data: [num_particle * 4]f32 = undefined; var initial_particle_data: [num_particle * 4]f32 = undefined;
var rng = std.rand.DefaultPrng.init(0); var rng = std.rand.DefaultPrng.init(0);
@ -126,7 +126,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
var particle_bind_groups: [2]gpu.BindGroup = undefined; var particle_bind_groups: [2]gpu.BindGroup = undefined;
i = 0; i = 0;
while (i < 2) : (i += 1) { while (i < 2) : (i += 1) {
particle_buffers[i] = engine.gpu_driver.device.createBuffer(&gpu.Buffer.Descriptor{ particle_buffers[i] = engine.device.createBuffer(&gpu.Buffer.Descriptor{
.usage = .{ .usage = .{
.vertex = true, .vertex = true,
.copy_dst = true, .copy_dst = true,
@ -134,12 +134,12 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
.size = initial_particle_data.len * @sizeOf(f32), .size = initial_particle_data.len * @sizeOf(f32),
}); });
engine.gpu_driver.device.getQueue().writeBuffer(particle_buffers[i], 0, f32, &initial_particle_data); engine.device.getQueue().writeBuffer(particle_buffers[i], 0, f32, &initial_particle_data);
} }
i = 0; i = 0;
while (i < 2) : (i += 1) { while (i < 2) : (i += 1) {
particle_bind_groups[i] = engine.gpu_driver.device.createBindGroup(&gpu.BindGroup.Descriptor{ .layout = compute_pipeline.getBindGroupLayout(0), .entries = &[_]gpu.BindGroup.Entry{ particle_bind_groups[i] = engine.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(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(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)), gpu.BindGroup.Entry.buffer(2, particle_buffers[(i + 1) % 2], 0, initial_particle_data.len * @sizeOf(f32)),
@ -158,7 +158,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
pub fn deinit(_: *App, _: *mach.Engine) void {} pub fn deinit(_: *App, _: *mach.Engine) void {}
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.resolve_target = null, .resolve_target = null,
@ -172,9 +172,9 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
} }; } };
sim_params[0] = @floatCast(f32, engine.delta_time); sim_params[0] = @floatCast(f32, engine.delta_time);
engine.gpu_driver.device.getQueue().writeBuffer(app.sim_param_buffer, 0, f32, &sim_params); engine.device.getQueue().writeBuffer(app.sim_param_buffer, 0, f32, &sim_params);
const command_encoder = engine.gpu_driver.device.createCommandEncoder(null); const command_encoder = engine.device.createCommandEncoder(null);
{ {
const pass_encoder = command_encoder.beginComputePass(null); const pass_encoder = command_encoder.beginComputePass(null);
pass_encoder.setPipeline(app.compute_pipeline); pass_encoder.setPipeline(app.compute_pipeline);
@ -200,10 +200,10 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
var command = command_encoder.finish(null); var command = command_encoder.finish(null);
command_encoder.release(); command_encoder.release();
engine.gpu_driver.device.getQueue().submit(&.{command}); engine.device.getQueue().submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;

View file

@ -4,8 +4,8 @@
//! We also need a second texture to use on the cube, that after the render pass //! We also need a second texture to use on the cube, that after the render pass
//! needs to copy the other texture. We can't use the same texture since //! needs to copy the other texture. We can't use the same texture since
//! it would interfere with the sincronization on the gpu during the render pass. //! it would interfere with the sincronization on the gpu during the render pass.
//! This demo currently does not work on opengl, because engine.gpu_driver.current_desc.width/height, //! This demo currently does not work on opengl, because engine.current_desc.width/height,
//! are set to 0 after engine.gpu_driver.init() and because webgpu does not implement copyTextureToTexture, //! are set to 0 after engine.init() and because webgpu does not implement copyTextureToTexture,
//! for opengl //! for opengl
const std = @import("std"); const std = @import("std");
@ -41,9 +41,9 @@ bgl: gpu.BindGroupLayout,
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start(); timer = try mach.Timer.start();
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
@ -59,7 +59,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.attributes = &vertex_attributes, .attributes = &vertex_attributes,
}; };
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
@ -77,7 +77,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = &blend, .blend = &blend,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -91,14 +91,14 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
const bgle_buffer = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0); const bgle_buffer = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0);
const bgle_sampler = gpu.BindGroupLayout.Entry.sampler(1, .{ .fragment = true }, .filtering); const bgle_sampler = gpu.BindGroupLayout.Entry.sampler(1, .{ .fragment = true }, .filtering);
const bgle_textureview = gpu.BindGroupLayout.Entry.texture(2, .{ .fragment = true }, .float, .dimension_2d, false); const bgle_textureview = gpu.BindGroupLayout.Entry.texture(2, .{ .fragment = true }, .float, .dimension_2d, false);
const bgl = engine.gpu_driver.device.createBindGroupLayout( const bgl = engine.device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor{ &gpu.BindGroupLayout.Descriptor{
.entries = &.{ bgle_buffer, bgle_sampler, bgle_textureview }, .entries = &.{ bgle_buffer, bgle_sampler, bgle_textureview },
}, },
); );
const bind_group_layouts = [_]gpu.BindGroupLayout{bgl}; const bind_group_layouts = [_]gpu.BindGroupLayout{bgl};
const pipeline_layout = engine.gpu_driver.device.createPipelineLayout(&.{ const pipeline_layout = engine.device.createPipelineLayout(&.{
.bind_group_layouts = &bind_group_layouts, .bind_group_layouts = &bind_group_layouts,
}); });
@ -128,7 +128,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .vertex = true }, .usage = .{ .vertex = true },
.size = @sizeOf(Vertex) * vertices.len, .size = @sizeOf(Vertex) * vertices.len,
.mapped_at_creation = true, .mapped_at_creation = true,
@ -137,44 +137,44 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
std.mem.copy(Vertex, vertex_mapped, vertices[0..]); std.mem.copy(Vertex, vertex_mapped, vertices[0..]);
vertex_buffer.unmap(); vertex_buffer.unmap();
const uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .uniform = true }, .usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(UniformBufferObject), .size = @sizeOf(UniformBufferObject),
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
// The texture to put on the cube // The texture to put on the cube
const cube_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ const cube_texture = engine.device.createTexture(&gpu.Texture.Descriptor{
.usage = .{ .texture_binding = true, .copy_dst = true }, .usage = .{ .texture_binding = true, .copy_dst = true },
.size = .{ .width = engine.gpu_driver.current_desc.width, .height = engine.gpu_driver.current_desc.height }, .size = .{ .width = engine.current_desc.width, .height = engine.current_desc.height },
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
}); });
// The texture on which we render // The texture on which we render
const cube_texture_render = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ const cube_texture_render = engine.device.createTexture(&gpu.Texture.Descriptor{
.usage = .{ .render_attachment = true, .copy_src = true }, .usage = .{ .render_attachment = true, .copy_src = true },
.size = .{ .width = engine.gpu_driver.current_desc.width, .height = engine.gpu_driver.current_desc.height }, .size = .{ .width = engine.current_desc.width, .height = engine.current_desc.height },
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
}); });
const sampler = engine.gpu_driver.device.createSampler(&gpu.Sampler.Descriptor{ const sampler = engine.device.createSampler(&gpu.Sampler.Descriptor{
.mag_filter = .linear, .mag_filter = .linear,
.min_filter = .linear, .min_filter = .linear,
}); });
const cube_texture_view = cube_texture.createView(&gpu.TextureView.Descriptor{ const cube_texture_view = cube_texture.createView(&gpu.TextureView.Descriptor{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.dimension = .dimension_2d, .dimension = .dimension_2d,
.mip_level_count = 1, .mip_level_count = 1,
.array_layer_count = 1, .array_layer_count = 1,
}); });
const cube_texture_view_render = cube_texture_render.createView(&gpu.TextureView.Descriptor{ const cube_texture_view_render = cube_texture_render.createView(&gpu.TextureView.Descriptor{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.dimension = .dimension_2d, .dimension = .dimension_2d,
.mip_level_count = 1, .mip_level_count = 1,
.array_layer_count = 1, .array_layer_count = 1,
}); });
const bind_group = engine.gpu_driver.device.createBindGroup( const bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = bgl, .layout = bgl,
.entries = &.{ .entries = &.{
@ -185,8 +185,8 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
); );
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = engine.gpu_driver.device.getQueue(); app.queue = engine.device.getQueue();
app.vertex_buffer = vertex_buffer; app.vertex_buffer = vertex_buffer;
app.uniform_buffer = uniform_buffer; app.uniform_buffer = uniform_buffer;
app.bind_group = bind_group; app.bind_group = bind_group;
@ -219,18 +219,18 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
engine.core.setShouldClose(true); engine.setShouldClose(true);
}, },
else => {}, else => {},
} }
} }
const cube_view = app.cube_texture_view_render; const cube_view = app.cube_texture_view_render;
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const cube_color_attachment = gpu.RenderPassColorAttachment{ const cube_color_attachment = gpu.RenderPassColorAttachment{
.view = cube_view, .view = cube_view,
@ -256,7 +256,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.stencil_store_op = .none, .stencil_store_op = .none,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const cube_render_pass_info = gpu.RenderPassEncoder.Descriptor{ const cube_render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{cube_color_attachment}, .color_attachments = &.{cube_color_attachment},
.depth_stencil_attachment = &depth_stencil_attachment, .depth_stencil_attachment = &depth_stencil_attachment,
@ -276,7 +276,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
); );
const proj = zm.perspectiveFovRh( const proj = zm.perspectiveFovRh(
(std.math.pi * 2.0 / 5.0), (std.math.pi * 2.0 / 5.0),
@intToFloat(f32, engine.gpu_driver.current_desc.width) / @intToFloat(f32, engine.gpu_driver.current_desc.height), @intToFloat(f32, engine.current_desc.width) / @intToFloat(f32, engine.current_desc.height),
1, 1,
100, 100,
); );
@ -301,7 +301,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
&gpu.ImageCopyTexture{ &gpu.ImageCopyTexture{
.texture = app.cube_texture, .texture = app.cube_texture,
}, },
&.{ .width = engine.gpu_driver.current_desc.width, .height = engine.gpu_driver.current_desc.height }, &.{ .width = engine.current_desc.width, .height = engine.current_desc.height },
); );
const cube_pass = encoder.beginRenderPass(&cube_render_pass_info); const cube_pass = encoder.beginRenderPass(&cube_render_pass_info);
@ -317,7 +317,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;
@ -326,23 +326,23 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
pub fn resize(app: *App, engine: *mach.Engine, width: u32, height: u32) !void { pub fn resize(app: *App, engine: *mach.Engine, width: u32, height: u32) !void {
if (app.depth_texture != null) { if (app.depth_texture != null) {
app.depth_texture.?.release(); app.depth_texture.?.release();
app.depth_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ app.depth_texture = engine.device.createTexture(&gpu.Texture.Descriptor{
.usage = .{ .render_attachment = true }, .usage = .{ .render_attachment = true },
.size = .{ .width = width, .height = height }, .size = .{ .width = width, .height = height },
.format = .depth24_plus, .format = .depth24_plus,
}); });
app.cube_texture.release(); app.cube_texture.release();
app.cube_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ app.cube_texture = engine.device.createTexture(&gpu.Texture.Descriptor{
.usage = .{ .texture_binding = true, .copy_dst = true }, .usage = .{ .texture_binding = true, .copy_dst = true },
.size = .{ .width = width, .height = height }, .size = .{ .width = width, .height = height },
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
}); });
app.cube_texture_render.release(); app.cube_texture_render.release();
app.cube_texture_render = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ app.cube_texture_render = engine.device.createTexture(&gpu.Texture.Descriptor{
.usage = .{ .render_attachment = true, .copy_src = true }, .usage = .{ .render_attachment = true, .copy_src = true },
.size = .{ .width = width, .height = height }, .size = .{ .width = width, .height = height },
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
}); });
app.depth_texture_view.release(); app.depth_texture_view.release();
@ -355,21 +355,21 @@ pub fn resize(app: *App, engine: *mach.Engine, width: u32, height: u32) !void {
app.cube_texture_view.release(); app.cube_texture_view.release();
app.cube_texture_view = app.cube_texture.createView(&gpu.TextureView.Descriptor{ app.cube_texture_view = app.cube_texture.createView(&gpu.TextureView.Descriptor{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.dimension = .dimension_2d, .dimension = .dimension_2d,
.mip_level_count = 1, .mip_level_count = 1,
.array_layer_count = 1, .array_layer_count = 1,
}); });
app.cube_texture_view_render.release(); app.cube_texture_view_render.release();
app.cube_texture_view_render = app.cube_texture_render.createView(&gpu.TextureView.Descriptor{ app.cube_texture_view_render = app.cube_texture_render.createView(&gpu.TextureView.Descriptor{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.dimension = .dimension_2d, .dimension = .dimension_2d,
.mip_level_count = 1, .mip_level_count = 1,
.array_layer_count = 1, .array_layer_count = 1,
}); });
app.bind_group.release(); app.bind_group.release();
app.bind_group = engine.gpu_driver.device.createBindGroup( app.bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = app.bgl, .layout = app.bgl,
.entries = &.{ .entries = &.{
@ -380,7 +380,7 @@ pub fn resize(app: *App, engine: *mach.Engine, width: u32, height: u32) !void {
}, },
); );
} else { } else {
app.depth_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ app.depth_texture = engine.device.createTexture(&gpu.Texture.Descriptor{
.usage = .{ .render_attachment = true }, .usage = .{ .render_attachment = true },
.size = .{ .width = width, .height = height }, .size = .{ .width = width, .height = height },
.format = .depth24_plus, .format = .depth24_plus,

View file

@ -33,16 +33,16 @@ bind_group: gpu.BindGroup,
texture_atlas_data: AtlasRGB8, texture_atlas_data: AtlasRGB8,
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const queue = engine.gpu_driver.device.getQueue(); const queue = engine.device.getQueue();
// TODO: Refactor texture atlas size number // TODO: Refactor texture atlas size number
app.texture_atlas_data = try AtlasRGB8.init(engine.allocator, 1280); app.texture_atlas_data = try AtlasRGB8.init(engine.allocator, 1280);
const atlas_size = gpu.Extent3D{ .width = app.texture_atlas_data.size, .height = app.texture_atlas_data.size }; const atlas_size = gpu.Extent3D{ .width = app.texture_atlas_data.size, .height = app.texture_atlas_data.size };
const atlas_float_size = @intToFloat(f32, app.texture_atlas_data.size); const atlas_float_size = @intToFloat(f32, app.texture_atlas_data.size);
const texture = engine.gpu_driver.device.createTexture(&.{ const texture = engine.device.createTexture(&.{
.size = atlas_size, .size = atlas_size,
.format = .rgba8_unorm, .format = .rgba8_unorm,
.usage = .{ .usage = .{
@ -99,7 +99,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
app.texture_atlas_data.data, app.texture_atlas_data.data,
); );
const wsize = engine.core.getWindowSize(); const wsize = engine.getWindowSize();
const window_width = @intToFloat(f32, wsize.width); const window_width = @intToFloat(f32, wsize.width);
const window_height = @intToFloat(f32, wsize.height); const window_height = @intToFloat(f32, wsize.height);
const triangle_scale = 250; const triangle_scale = 250;
@ -114,12 +114,12 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
// try draw.quad(app, .{ 0, 0 }, .{ 480, 480 }, .{}, .{ .bottom_left = .{ 0, 0 }, .width_and_height = .{ 1, 1 } }); // try draw.quad(app, .{ 0, 0 }, .{ 480, 480 }, .{}, .{ .bottom_left = .{ 0, 0 }, .width_and_height = .{ 1, 1 } });
// try draw.circle(app, .{ window_width / 2, window_height / 2 }, window_height / 2 - 10, .{ 0, 0.5, 0.75, 1.0 }, white_texture_uv_data); // try draw.circle(app, .{ window_width / 2, window_height / 2 }, window_height / 2 - 10, .{ 0, 0.5, 0.75, 1.0 }, white_texture_uv_data);
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
@ -138,7 +138,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = &blend, .blend = &blend,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -153,13 +153,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
const fbgle = gpu.BindGroupLayout.Entry.buffer(1, .{ .fragment = true }, .read_only_storage, true, 0); const fbgle = gpu.BindGroupLayout.Entry.buffer(1, .{ .fragment = true }, .read_only_storage, true, 0);
const sbgle = gpu.BindGroupLayout.Entry.sampler(2, .{ .fragment = true }, .filtering); const sbgle = gpu.BindGroupLayout.Entry.sampler(2, .{ .fragment = true }, .filtering);
const tbgle = gpu.BindGroupLayout.Entry.texture(3, .{ .fragment = true }, .float, .dimension_2d, false); const tbgle = gpu.BindGroupLayout.Entry.texture(3, .{ .fragment = true }, .float, .dimension_2d, false);
const bgl = engine.gpu_driver.device.createBindGroupLayout( const bgl = engine.device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor{ &gpu.BindGroupLayout.Descriptor{
.entries = &.{ vbgle, fbgle, sbgle, tbgle }, .entries = &.{ vbgle, fbgle, sbgle, tbgle },
}, },
); );
const bind_group_layouts = [_]gpu.BindGroupLayout{bgl}; const bind_group_layouts = [_]gpu.BindGroupLayout{bgl};
const pipeline_layout = engine.gpu_driver.device.createPipelineLayout(&.{ const pipeline_layout = engine.device.createPipelineLayout(&.{
.bind_group_layouts = &bind_group_layouts, .bind_group_layouts = &bind_group_layouts,
}); });
@ -185,30 +185,30 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .vertex = true }, .usage = .{ .copy_dst = true, .vertex = true },
.size = @sizeOf(draw.Vertex) * app.vertices.items.len, .size = @sizeOf(draw.Vertex) * app.vertices.items.len,
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const vertex_uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .uniform = true }, .usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(draw.VertexUniform), .size = @sizeOf(draw.VertexUniform),
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const frag_uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const frag_uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .storage = true }, .usage = .{ .copy_dst = true, .storage = true },
.size = @sizeOf(draw.FragUniform) * app.fragment_uniform_list.items.len, .size = @sizeOf(draw.FragUniform) * app.fragment_uniform_list.items.len,
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const sampler = engine.gpu_driver.device.createSampler(&.{ const sampler = engine.device.createSampler(&.{
.mag_filter = .linear, .mag_filter = .linear,
.min_filter = .linear, .min_filter = .linear,
}); });
const bind_group = engine.gpu_driver.device.createBindGroup( const bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = bgl, .layout = bgl,
.entries = &.{ .entries = &.{
@ -220,7 +220,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
); );
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = queue; app.queue = queue;
app.vertex_buffer = vertex_buffer; app.vertex_buffer = vertex_buffer;
app.vertex_uniform_buffer = vertex_uniform_buffer; app.vertex_uniform_buffer = vertex_uniform_buffer;
@ -247,17 +247,17 @@ pub fn deinit(app: *App, engine: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
engine.core.setShouldClose(true); engine.setShouldClose(true);
}, },
else => {}, else => {},
} }
} }
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.resolve_target = null, .resolve_target = null,
@ -266,7 +266,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store, .store_op = .store,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{ const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment}, .color_attachments = &.{color_attachment},
}; };
@ -299,7 +299,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;
@ -324,7 +324,7 @@ pub fn getVertexUniformBufferObject(engine: *mach.Engine) !draw.VertexUniform {
// On e.g. macOS, window size may be 640x480 while framebuffer size may be // On e.g. macOS, window size may be 640x480 while framebuffer size may be
// 1280x960 (subpixels.) Doing this lets us use a pixel, not subpixel, // 1280x960 (subpixels.) Doing this lets us use a pixel, not subpixel,
// coordinate system. // coordinate system.
const window_size = engine.core.getWindowSize(); const window_size = engine.getWindowSize();
const proj = zm.orthographicRh( const proj = zm.orthographicRh(
@intToFloat(f32, window_size.width), @intToFloat(f32, window_size.width),
@intToFloat(f32, window_size.height), @intToFloat(f32, window_size.height),

View file

@ -23,9 +23,9 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start(); timer = try mach.Timer.start();
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
@ -41,13 +41,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.attributes = &vertex_attributes, .attributes = &vertex_attributes,
}; };
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = null, .blend = null,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -59,14 +59,14 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}; };
const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0); const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0);
const bgl = engine.gpu_driver.device.createBindGroupLayout( const bgl = engine.device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor{ &gpu.BindGroupLayout.Descriptor{
.entries = &.{bgle}, .entries = &.{bgle},
}, },
); );
const bind_group_layouts = [_]gpu.BindGroupLayout{bgl}; const bind_group_layouts = [_]gpu.BindGroupLayout{bgl};
const pipeline_layout = engine.gpu_driver.device.createPipelineLayout(&.{ const pipeline_layout = engine.device.createPipelineLayout(&.{
.bind_group_layouts = &bind_group_layouts, .bind_group_layouts = &bind_group_layouts,
}); });
@ -92,7 +92,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .vertex = true }, .usage = .{ .vertex = true },
.size = @sizeOf(Vertex) * vertices.len, .size = @sizeOf(Vertex) * vertices.len,
.mapped_at_creation = true, .mapped_at_creation = true,
@ -105,12 +105,12 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
const y_count = 4; const y_count = 4;
const num_instances = x_count * y_count; const num_instances = x_count * y_count;
const uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .uniform = true }, .usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(UniformBufferObject) * num_instances, .size = @sizeOf(UniformBufferObject) * num_instances,
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const bind_group = engine.gpu_driver.device.createBindGroup( const bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = bgl, .layout = bgl,
.entries = &.{ .entries = &.{
@ -119,8 +119,8 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
); );
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = engine.gpu_driver.device.getQueue(); app.queue = engine.device.getQueue();
app.vertex_buffer = vertex_buffer; app.vertex_buffer = vertex_buffer;
app.uniform_buffer = uniform_buffer; app.uniform_buffer = uniform_buffer;
app.bind_group = bind_group; app.bind_group = bind_group;
@ -138,17 +138,17 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
engine.core.setShouldClose(true); engine.setShouldClose(true);
}, },
else => {}, else => {},
} }
} }
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.resolve_target = null, .resolve_target = null,
@ -157,7 +157,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store, .store_op = .store,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{ const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment}, .color_attachments = &.{color_attachment},
}; };
@ -165,7 +165,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
{ {
const proj = zm.perspectiveFovRh( const proj = zm.perspectiveFovRh(
(std.math.pi / 3.0), (std.math.pi / 3.0),
@intToFloat(f32, engine.gpu_driver.current_desc.width) / @intToFloat(f32, engine.gpu_driver.current_desc.height), @intToFloat(f32, engine.current_desc.width) / @intToFloat(f32, engine.current_desc.height),
10, 10,
30, 30,
); );
@ -205,7 +205,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;

View file

@ -23,9 +23,9 @@ bind_group: gpu.BindGroup,
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start(); timer = try mach.Timer.start();
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
@ -41,7 +41,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.attributes = &vertex_attributes, .attributes = &vertex_attributes,
}; };
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
@ -59,7 +59,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = &blend, .blend = &blend,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -71,14 +71,14 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}; };
const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0); const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0);
const bgl = engine.gpu_driver.device.createBindGroupLayout( const bgl = engine.device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor{ &gpu.BindGroupLayout.Descriptor{
.entries = &.{bgle}, .entries = &.{bgle},
}, },
); );
const bind_group_layouts = [_]gpu.BindGroupLayout{bgl}; const bind_group_layouts = [_]gpu.BindGroupLayout{bgl};
const pipeline_layout = engine.gpu_driver.device.createPipelineLayout(&.{ const pipeline_layout = engine.device.createPipelineLayout(&.{
.bind_group_layouts = &bind_group_layouts, .bind_group_layouts = &bind_group_layouts,
}); });
@ -104,7 +104,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .vertex = true }, .usage = .{ .vertex = true },
.size = @sizeOf(Vertex) * vertices.len, .size = @sizeOf(Vertex) * vertices.len,
.mapped_at_creation = true, .mapped_at_creation = true,
@ -113,12 +113,12 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
std.mem.copy(Vertex, vertex_mapped, vertices[0..]); std.mem.copy(Vertex, vertex_mapped, vertices[0..]);
vertex_buffer.unmap(); vertex_buffer.unmap();
const uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .uniform = true }, .usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(UniformBufferObject), .size = @sizeOf(UniformBufferObject),
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const bind_group = engine.gpu_driver.device.createBindGroup( const bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = bgl, .layout = bgl,
.entries = &.{ .entries = &.{
@ -127,8 +127,8 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
); );
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = engine.gpu_driver.device.getQueue(); app.queue = engine.device.getQueue();
app.vertex_buffer = vertex_buffer; app.vertex_buffer = vertex_buffer;
app.uniform_buffer = uniform_buffer; app.uniform_buffer = uniform_buffer;
app.bind_group = bind_group; app.bind_group = bind_group;
@ -146,17 +146,17 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
engine.core.setShouldClose(true); engine.setShouldClose(true);
}, },
else => {}, else => {},
} }
} }
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.resolve_target = null, .resolve_target = null,
@ -165,7 +165,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store, .store_op = .store,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{ const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment}, .color_attachments = &.{color_attachment},
.depth_stencil_attachment = null, .depth_stencil_attachment = null,
@ -181,7 +181,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
); );
const proj = zm.perspectiveFovRh( const proj = zm.perspectiveFovRh(
(std.math.pi / 4.0), (std.math.pi / 4.0),
@intToFloat(f32, engine.gpu_driver.current_desc.width) / @intToFloat(f32, engine.gpu_driver.current_desc.height), @intToFloat(f32, engine.current_desc.width) / @intToFloat(f32, engine.current_desc.height),
0.1, 0.1,
10, 10,
); );
@ -205,7 +205,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;

View file

@ -26,9 +26,9 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start(); timer = try mach.Timer.start();
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
@ -44,7 +44,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.attributes = &vertex_attributes, .attributes = &vertex_attributes,
}; };
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
@ -62,7 +62,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = &blend, .blend = &blend,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -96,9 +96,9 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.cull_mode = .back, .cull_mode = .back,
}, },
}; };
const pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); const pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .vertex = true }, .usage = .{ .vertex = true },
.size = @sizeOf(Vertex) * vertices.len, .size = @sizeOf(Vertex) * vertices.len,
.mapped_at_creation = true, .mapped_at_creation = true,
@ -108,14 +108,14 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
vertex_buffer.unmap(); vertex_buffer.unmap();
// Create a sampler with linear filtering for smooth interpolation. // Create a sampler with linear filtering for smooth interpolation.
const sampler = engine.gpu_driver.device.createSampler(&.{ const sampler = engine.device.createSampler(&.{
.mag_filter = .linear, .mag_filter = .linear,
.min_filter = .linear, .min_filter = .linear,
}); });
const queue = engine.gpu_driver.device.getQueue(); const queue = engine.device.getQueue();
const img = try zigimg.Image.fromMemory(engine.allocator, @embedFile("../assets/gotta-go-fast.png")); const img = try zigimg.Image.fromMemory(engine.allocator, @embedFile("../assets/gotta-go-fast.png"));
const img_size = gpu.Extent3D{ .width = @intCast(u32, img.width), .height = @intCast(u32, img.height) }; const img_size = gpu.Extent3D{ .width = @intCast(u32, img.width), .height = @intCast(u32, img.height) };
const cube_texture = engine.gpu_driver.device.createTexture(&.{ const cube_texture = engine.device.createTexture(&.{
.size = img_size, .size = img_size,
.format = .rgba8_unorm, .format = .rgba8_unorm,
.usage = .{ .usage = .{
@ -138,13 +138,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
else => @panic("unsupported image color format"), else => @panic("unsupported image color format"),
} }
const uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .uniform = true }, .usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(UniformBufferObject), .size = @sizeOf(UniformBufferObject),
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const bind_group = engine.gpu_driver.device.createBindGroup( const bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = pipeline.getBindGroupLayout(0), .layout = pipeline.getBindGroupLayout(0),
.entries = &.{ .entries = &.{
@ -176,17 +176,17 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
engine.core.setShouldClose(true); engine.setShouldClose(true);
}, },
else => {}, else => {},
} }
} }
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.clear_value = .{ .r = 0.5, .g = 0.5, .b = 0.5, .a = 0.0 }, .clear_value = .{ .r = 0.5, .g = 0.5, .b = 0.5, .a = 0.0 },
@ -194,7 +194,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store, .store_op = .store,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{ const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment}, .color_attachments = &.{color_attachment},
.depth_stencil_attachment = &.{ .depth_stencil_attachment = &.{
@ -215,7 +215,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
); );
const proj = zm.perspectiveFovRh( const proj = zm.perspectiveFovRh(
(std.math.pi / 4.0), (std.math.pi / 4.0),
@intToFloat(f32, engine.gpu_driver.current_desc.width) / @intToFloat(f32, engine.gpu_driver.current_desc.height), @intToFloat(f32, engine.current_desc.width) / @intToFloat(f32, engine.current_desc.height),
0.1, 0.1,
10, 10,
); );
@ -239,7 +239,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;
@ -251,7 +251,7 @@ pub fn resize(app: *App, engine: *mach.Engine, width: u32, height: u32) !void {
app.depth_texture.?.release(); app.depth_texture.?.release();
app.depth_texture_view.release(); app.depth_texture_view.release();
} }
app.depth_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{ app.depth_texture = engine.device.createTexture(&gpu.Texture.Descriptor{
.size = gpu.Extent3D{ .size = gpu.Extent3D{
.width = width, .width = width,
.height = height, .height = height,

View file

@ -8,12 +8,12 @@ pipeline: gpu.RenderPipeline,
queue: gpu.Queue, queue: gpu.Queue,
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
@ -32,7 +32,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = &blend, .blend = &blend,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -64,8 +64,8 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = engine.gpu_driver.device.getQueue(); app.queue = engine.device.getQueue();
vs_module.release(); vs_module.release();
fs_module.release(); fs_module.release();
@ -74,7 +74,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
pub fn deinit(_: *App, _: *mach.Engine) void {} pub fn deinit(_: *App, _: *mach.Engine) void {}
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.resolve_target = null, .resolve_target = null,
@ -83,7 +83,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store, .store_op = .store,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{ const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment}, .color_attachments = &.{color_attachment},
.depth_stencil_attachment = null, .depth_stencil_attachment = null,
@ -99,7 +99,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;

View file

@ -24,9 +24,9 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void { pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start(); timer = try mach.Timer.start();
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null }); try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{ const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader", .label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") }, .code = .{ .wgsl = @embedFile("vert.wgsl") },
}); });
@ -42,7 +42,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.attributes = &vertex_attributes, .attributes = &vertex_attributes,
}; };
const fs_module = engine.gpu_driver.device.createShaderModule(&.{ const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader", .label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") }, .code = .{ .wgsl = @embedFile("frag.wgsl") },
}); });
@ -60,7 +60,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const color_target = gpu.ColorTargetState{ const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format, .format = engine.swap_chain_format,
.blend = &blend, .blend = &blend,
.write_mask = gpu.ColorWriteMask.all, .write_mask = gpu.ColorWriteMask.all,
}; };
@ -72,14 +72,14 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}; };
const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0); const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0);
const bgl = engine.gpu_driver.device.createBindGroupLayout( const bgl = engine.device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor{ &gpu.BindGroupLayout.Descriptor{
.entries = &.{bgle}, .entries = &.{bgle},
}, },
); );
const bind_group_layouts = [_]gpu.BindGroupLayout{bgl}; const bind_group_layouts = [_]gpu.BindGroupLayout{bgl};
const pipeline_layout = engine.gpu_driver.device.createPipelineLayout(&.{ const pipeline_layout = engine.device.createPipelineLayout(&.{
.bind_group_layouts = &bind_group_layouts, .bind_group_layouts = &bind_group_layouts,
}); });
@ -105,9 +105,9 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
}; };
const queue = engine.gpu_driver.device.getQueue(); const queue = engine.device.getQueue();
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{ const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .vertex = true }, .usage = .{ .vertex = true },
.size = @sizeOf(Vertex) * vertices.len, .size = @sizeOf(Vertex) * vertices.len,
.mapped_at_creation = true, .mapped_at_creation = true,
@ -118,13 +118,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
// uniformBindGroup offset must be 256-byte aligned // uniformBindGroup offset must be 256-byte aligned
const uniform_offset = 256; const uniform_offset = 256;
const uniform_buffer = engine.gpu_driver.device.createBuffer(&.{ const uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .uniform = true, .copy_dst = true }, .usage = .{ .uniform = true, .copy_dst = true },
.size = @sizeOf(UniformBufferObject) + uniform_offset, .size = @sizeOf(UniformBufferObject) + uniform_offset,
.mapped_at_creation = false, .mapped_at_creation = false,
}); });
const bind_group1 = engine.gpu_driver.device.createBindGroup( const bind_group1 = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = bgl, .layout = bgl,
.entries = &.{ .entries = &.{
@ -133,7 +133,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
); );
const bind_group2 = engine.gpu_driver.device.createBindGroup( const bind_group2 = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{ &gpu.BindGroup.Descriptor{
.layout = bgl, .layout = bgl,
.entries = &.{ .entries = &.{
@ -142,7 +142,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}, },
); );
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor); app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = queue; app.queue = queue;
app.vertex_buffer = vertex_buffer; app.vertex_buffer = vertex_buffer;
app.uniform_buffer = uniform_buffer; app.uniform_buffer = uniform_buffer;
@ -163,17 +163,17 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
} }
pub fn update(app: *App, engine: *mach.Engine) !bool { pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| { while (engine.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
engine.core.setShouldClose(true); engine.setShouldClose(true);
}, },
else => {}, else => {},
} }
} }
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView(); const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{ const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view, .view = back_buffer_view,
.resolve_target = null, .resolve_target = null,
@ -182,7 +182,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store, .store_op = .store,
}; };
const encoder = engine.gpu_driver.device.createCommandEncoder(null); const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{ const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment}, .color_attachments = &.{color_attachment},
.depth_stencil_attachment = null, .depth_stencil_attachment = null,
@ -201,7 +201,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
); );
const proj = zm.perspectiveFovRh( const proj = zm.perspectiveFovRh(
(2.0 * std.math.pi / 5.0), (2.0 * std.math.pi / 5.0),
@intToFloat(f32, engine.gpu_driver.current_desc.width) / @intToFloat(f32, engine.gpu_driver.current_desc.height), @intToFloat(f32, engine.current_desc.width) / @intToFloat(f32, engine.current_desc.height),
1, 1,
100, 100,
); );
@ -237,7 +237,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command}); app.queue.submit(&.{command});
command.release(); command.release();
engine.gpu_driver.swap_chain.?.present(); engine.swap_chain.?.present();
back_buffer_view.release(); back_buffer_view.release();
return true; return true;