From 7e026b8041d76529b1102f61d229a9d2fa1b7062 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Fri, 22 Jul 2022 02:40:36 -0700 Subject: [PATCH] beautiful nothing --- src/math/vec.zig | 8 ++- src/rendering/vulkan/MainPass.zig | 83 ++++++++++++++++++++++++---- src/rendering/vulkan/framebuffer.zig | 2 + 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/src/math/vec.zig b/src/math/vec.zig index 8b2985a..d1df9a9 100644 --- a/src/math/vec.zig +++ b/src/math/vec.zig @@ -163,7 +163,13 @@ test "vec" { pub const Float4x4 = packed struct { const Self = @This(); - const zero = Self{}; + pub const zero = Self{}; + pub const id = Self{ + .c0 = .{ .x = 1, .y = 0, .z = 0, .w = 0 }, + .c1 = .{ .x = 0, .y = 1, .z = 0, .w = 0 }, + .c2 = .{ .x = 0, .y = 0, .z = 1, .w = 0 }, + .c3 = .{ .x = 0, .y = 0, .z = 0, .w = 1 }, + }; c0: Vec4f = .{}, c1: Vec4f = .{}, diff --git a/src/rendering/vulkan/MainPass.zig b/src/rendering/vulkan/MainPass.zig index 04f922f..5edcce0 100644 --- a/src/rendering/vulkan/MainPass.zig +++ b/src/rendering/vulkan/MainPass.zig @@ -65,7 +65,7 @@ pub fn execute(device: *const Device, swapchain: *Swapchain) !void { // todo: pt_trace convar check try DepthPass.execute(device, swapchain); - OpaquePass.execute(); + try OpaquePass.execute(device, swapchain); // Exposure.execute(); // UIPass.execute(); @@ -85,11 +85,18 @@ const DepthPass = struct { const depth_buffer = Targets.getDepthBuffer(swapchain); var info = RenderPass.Description{ - .src_stage_mask = .{ .early_fragment_tests_bit = true }, - .src_access_mask = .{ .depth_stencil_attachment_read_bit = true }, - .dst_stage_mask = .{ .late_fragment_tests_bit = true }, - .dst_access_mask = .{ .depth_stencil_attachment_write_bit = true }, + .src_stage_mask = .{ .fragment_shader_bit = true }, + .src_access_mask = .{ .shader_read_bit = true }, + .dst_stage_mask = .{ .color_attachment_output_bit = true }, + .dst_access_mask = .{ .color_attachment_write_bit = true }, }; + + //var info = RenderPass.Description{ + // .src_stage_mask = .{ .early_fragment_tests_bit = true }, + // .src_access_mask = .{ .depth_stencil_attachment_read_bit = true }, + // .dst_stage_mask = .{ .late_fragment_tests_bit = true }, + // .dst_access_mask = .{ .depth_stencil_attachment_write_bit = true }, + //}; info.attachments[0] = .{ .format = depth_buffer.format, .layout = .depth_stencil_attachment_optimal, @@ -224,13 +231,21 @@ const OpaquePass = struct { const scene_buffer = Targets.getSceneBuffer(swapchain); const depth_buffer = Targets.getDepthBuffer(swapchain); + var info = RenderPass.Description{ - .src_stage_mask = .{ .late_fragment_tests_bit = true }, - .dst_stage_mask = .{ .early_fragment_tests_bit = true, .color_attachment_output_bit = true }, - .src_access_mask = .{ .depth_stencil_attachment_write_bit = true }, - .dst_access_mask = .{ .depth_stencil_attachment_read_bit = true, .depth_stencil_attachment_write_bit = true }, + .src_stage_mask = .{ .fragment_shader_bit = true }, + .dst_stage_mask = .{ .color_attachment_output_bit = true }, + .src_access_mask = .{ .shader_read_bit = true }, + .dst_access_mask = .{ .color_attachment_write_bit = true }, }; + //var info = RenderPass.Description{ + // .src_stage_mask = .{ .late_fragment_tests_bit = true }, + // .dst_stage_mask = .{ .early_fragment_tests_bit = true, .color_attachment_output_bit = true }, + // .src_access_mask = .{ .depth_stencil_attachment_write_bit = true }, + // .dst_access_mask = .{ .depth_stencil_attachment_read_bit = true, .color_attachment_write_bit = true }, + //}; + info.attachments[0] = .{ .format = depth_buffer.format, .layout = .depth_stencil_attachment_optimal, @@ -384,5 +399,53 @@ const OpaquePass = struct { Bindings.bindBuffer(settings.Bid.Globals.id, .uniform_buffer, s_per_camera_buffer.current(swapchain)); } - pub fn execute() void {} + const pm_opaque_execute = ProfileMark.init("OpaquePass.execute"); + pub fn execute(device: *const Device, swapchain: *Swapchain) !void { + pm_opaque_execute.begin(); + defer pm_opaque_execute.end(); + + var attachments = [_]*Image{ + Targets.getDepthBuffer(swapchain), + Targets.getSceneBuffer(swapchain), + }; + const rect = vk.Rect2D{ + .extent = .{ + .width = attachments[0].width, + .height = attachments[0].height, + }, + .offset = std.mem.zeroes(vk.Offset2D), + }; + const fbuf = try framebuffer.getOrAdd(device, &attachments, rect.extent.width, rect.extent.height); + const cmdbuf = try Command.Buffer.get(.graphics, device); + + _ = try Image.State.depthAttachWrite(device, cmdbuf, attachments[0]); + _ = try Image.State.colorAttachWrite(device, cmdbuf, attachments[1]); + // textable fragsampleall + + cmdbuf.defaultViewport(device, swapchain); + cmdbuf.bindPass(device, swapchain, &s_pass); + const clear_values = [_]vk.ClearValue{ + .{ + .depth_stencil = .{ .depth = 1, .stencil = 0 }, + }, + .{ + .color = .{ .float_32 = .{ 0, 0, 0, 1 } }, + }, + }; + + cmdbuf.beginRenderPass(device, s_render_pass, fbuf, rect, &clear_values); + defer cmdbuf.endRenderPass(device); + + // ITERATE THROUGH ENTITIES AND DRAW THEM FINALLY OMG + + const pc = PushConstants{ + .kLocalToWorld = Float4x4.id, + .kIMc0 = Vec4f{ .x = 1, .y = 0, .z = 0, .w = 0 }, + .kIMc1 = Vec4f{ .x = 0, .y = 1, .z = 0, .w = 0 }, + .kIMc2 = Vec4f{ .x = 0, .y = 0, .z = 1, .w = 0 }, + .kTexInds = Vec4u{}, + }; + + cmdbuf.pushConstants(device, &s_pass, &pc); + } }; diff --git a/src/rendering/vulkan/framebuffer.zig b/src/rendering/vulkan/framebuffer.zig index 43d73dc..c3fe27c 100644 --- a/src/rendering/vulkan/framebuffer.zig +++ b/src/rendering/vulkan/framebuffer.zig @@ -49,6 +49,7 @@ pub fn getOrAdd(device: *const Device, attachments: []*const Image, width: u32, .height = @intCast(u16, height), }; + std.debug.print("# attachments: {}\n\n", .{attachments.len}); for (attachments) |attachment, i| { assert(attachment.view != .null_handle); key.attachments[i] = attachment.view; @@ -57,6 +58,7 @@ pub fn getOrAdd(device: *const Device, attachments: []*const Image, width: u32, const result = s_fbufs.getOrPutAssumeCapacity(key); if (!result.found_existing) { + std.debug.print("new fbuf: att {any} \n\n format {any}\n\n", .{ key.attachments[0..attachments.len], key.formats[0..attachments.len] }); const value = Value{ .handle = try Framebuffer.init(device, key.attachments[0..attachments.len], key.formats[0..attachments.len], key.width, key.height), };