From 2814854d1639d7be03f11b137ab53da1a759a540 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Tue, 19 Jul 2022 02:06:00 -0700 Subject: [PATCH] fix a bunch of runtime errors. now I have to create the pipeline! --- src/rendering/vulkan/Command.zig | 6 +----- src/rendering/vulkan/framebuffer.zig | 8 ++++---- src/rendering/vulkan/image.zig | 9 +-------- src/rendering/vulkan/memory.zig | 20 ++++++++++---------- src/rendering/vulkan/queues.zig | 5 +++++ 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/rendering/vulkan/Command.zig b/src/rendering/vulkan/Command.zig index 3deae2a..b61d369 100644 --- a/src/rendering/vulkan/Command.zig +++ b/src/rendering/vulkan/Command.zig @@ -137,7 +137,7 @@ pub const Buffer = struct { const GetError = Buffer.InitError || DeviceDispatch.BeginCommandBufferError; pub fn get(queue_id: queues.QueueId, device: *const Device) GetError!*Buffer { - var ctx = Context.context; + var ctx = &Context.context; var cmd = &ctx.cur_cmd_buf[@enumToInt(queue_id)]; if (cmd.handle == .null_handle) { try cmd.init(device, queues.get(queue_id)); @@ -322,10 +322,6 @@ pub const Buffer = struct { pm_buffer_submit.begin(); defer pm_buffer_submit.end(); - _ = wait_sema; - _ = signal_sema; - _ = wait_mask; - assert(self.began); assert(!self.ended); assert(!self.submitted); diff --git a/src/rendering/vulkan/framebuffer.zig b/src/rendering/vulkan/framebuffer.zig index 611a7ba..43d73dc 100644 --- a/src/rendering/vulkan/framebuffer.zig +++ b/src/rendering/vulkan/framebuffer.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const assert = std.debug.assert; const vk = @import("vulkan"); const Image = @import("image.zig").Image; const RenderPass = @import("RenderPass.zig"); @@ -49,10 +50,9 @@ pub fn getOrAdd(device: *const Device, attachments: []*const Image, width: u32, }; for (attachments) |attachment, i| { - if (attachment.view != .null_handle) { - key.attachments[i] = attachment.view; - key.formats[i] = attachment.format; - } + assert(attachment.view != .null_handle); + key.attachments[i] = attachment.view; + key.formats[i] = attachment.format; } const result = s_fbufs.getOrPutAssumeCapacity(key); diff --git a/src/rendering/vulkan/image.zig b/src/rendering/vulkan/image.zig index c5aaa9c..3522388 100644 --- a/src/rendering/vulkan/image.zig +++ b/src/rendering/vulkan/image.zig @@ -247,9 +247,7 @@ pub const Image = struct { const prev_queue = queues.get(prev.owner); const next_queue = queues.get(self.owner); - std.debug.print("stage: {}\n\n stage_mask: {}\n", .{ self.stage, next_queue.stage_mask }); assert(self.stage.intersect(next_queue.stage_mask).toInt() == self.stage.toInt()); - std.debug.print("access: {}\n\n access_mask: {}\n", .{ self.access, next_queue.access_mask }); assert(self.access.intersect(next_queue.access_mask).toInt() == self.access.toInt()); if (prev.substates != null) { @@ -260,7 +258,6 @@ pub const Image = struct { .layout = self.layout, }, 0, img.array_layers, 0, img.mip_levels); assert(img.state.substates == null); - std.debug.print("substates\n", .{}); return inserted_barrier; } @@ -303,9 +300,7 @@ pub const Image = struct { assert(!dst_cmd.queue_transfer_src); dst_cmd.queue_transfer_dst = true; device.dispatch.cmdPipelineBarrier(dst_cmd.handle, prev.stage, self.stage, .{}, 0, undefined, 0, undefined, 1, @ptrCast([*]const vk.ImageMemoryBarrier, &barrier)); - std.debug.print("prev: {},\n\nself: {}\n\n", .{ prev, self }); prev.* = self.*; - std.debug.print("AFTERWARDS prev: {},\n\nself: {}\n\n", .{ prev, self }); inserted_barrier = true; } else { const layout_change = prev.layout != self.layout; @@ -336,9 +331,7 @@ pub const Image = struct { }, }; device.dispatch.cmdPipelineBarrier(cmd.handle, prev.stage, self.stage, .{}, 0, undefined, 0, undefined, 1, @ptrCast([*]const vk.ImageMemoryBarrier, &barrier)); - std.debug.print("prev: {},\n\nself: {}\n\n", .{ prev, self }); prev.* = self.*; - std.debug.print("AFTERWARDS prev: {},\n\nself: {}\n\n", .{ prev, self }); inserted_barrier = true; } else { // no data hazard, append usage state @@ -719,7 +712,7 @@ pub const Image = struct { pub fn infoToViewInfo(info: *const vk.ImageCreateInfo) !vk.ImageViewCreateInfo { // anything but transfer usage needs a view const viewless: vk.ImageUsageFlags = .{ .transfer_src_bit = true, .transfer_dst_bit = true }; - if (!info.usage.contains(viewless)) { + if (info.usage.intersect(viewless.complement()).toInt() != 0) { return vk.ImageViewCreateInfo{ .flags = .{}, .format = info.format, diff --git a/src/rendering/vulkan/memory.zig b/src/rendering/vulkan/memory.zig index 071eddb..ec2bbd5 100644 --- a/src/rendering/vulkan/memory.zig +++ b/src/rendering/vulkan/memory.zig @@ -9,7 +9,7 @@ const settings = @import("settings.zig"); const queues = @import("queues.zig"); const vma = @import("vma"); const profiler = @import("../../common/profiler.zig"); -const Image = @import("image.zig").Image; +const image = @import("image.zig"); var s_allocator: Allocator = undefined; @@ -37,7 +37,7 @@ pub fn finalize(device: *const Device) !void { pub fn update() void {} const pm_imgnew = profiler.ProfileMark.init("memory.imageNew"); -pub fn imageNew(img: *Image, device: *const Device, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void { +pub fn imageNew(img: *image.Image, device: *const Device, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void { pm_imgnew.begin(); defer pm_imgnew.end(); @@ -63,8 +63,6 @@ pub fn imageNew(img: *Image, device: *const Device, info: vk.ImageCreateInfo, me img.array_layers = @intCast(u8, info.array_layers); img.imported = false; - std.debug.print("gettextpool img info {}\n", .{info.usage}); - const pool = getTexturePool(info.usage, mem_usage) orelse return error.NoPoolForImage; const result = try vma.Allocator.createImage(s_allocator.handle, info, .{ @@ -76,10 +74,14 @@ pub fn imageNew(img: *Image, device: *const Device, info: vk.ImageCreateInfo, me }); img.handle = result.image; img.allocation = result.allocation; + + var view_info = try image.infoToViewInfo(&info); + view_info.image = img.handle; + img.view = try device.dispatch.createImageView(device.handle, &view_info, null); } const pm_imagedel = profiler.ProfileMark.init("memory.imageDel"); -pub fn imageDel(img: *const Image, device: *const Device) void { +pub fn imageDel(img: *const image.Image, device: *const Device) void { pm_imagedel.begin(); defer pm_imagedel.end(); @@ -100,8 +102,6 @@ fn getTexturePool(usage: vk.ImageUsageFlags, mem_usage: vma.MemoryUsage) ?vma.Po else => {}, } - std.debug.print("usage in getTexturePool {}\n", .{usage}); - const attachment_usage: vk.ImageUsageFlags = .{ .color_attachment_bit = true, .depth_stencil_attachment_bit = true }; std.debug.assert(pool != null or usage.intersect(attachment_usage).toInt() != 0); @@ -260,9 +260,9 @@ pub const Releasable = struct { .buffer => |buffer| { allocator.handle.destroyBuffer(buffer.handle, buffer.allocation); }, - .image => |image| { - device.dispatch.destroyImageView(device.handle, image.view, null); - allocator.handle.destroyImage(image.handle, image.allocation); + .image => |img| { + device.dispatch.destroyImageView(device.handle, img.view, null); + allocator.handle.destroyImage(img.handle, img.allocation); }, .image_view => |image_view| { device.dispatch.destroyImageView(device.handle, image_view, null); diff --git a/src/rendering/vulkan/queues.zig b/src/rendering/vulkan/queues.zig index 2e6cfe0..3d2bfa9 100644 --- a/src/rendering/vulkan/queues.zig +++ b/src/rendering/vulkan/queues.zig @@ -52,6 +52,8 @@ const graphics_access: vk.AccessFlags = .{ .shader_write_bit = true, .color_attachment_read_bit = true, .color_attachment_write_bit = true, + .depth_stencil_attachment_read_bit = true, + .depth_stencil_attachment_write_bit = true, .conditional_rendering_read_bit_ext = true, .acceleration_structure_read_bit_khr = true, .acceleration_structure_write_bit_khr = true, @@ -289,7 +291,10 @@ pub const Queue = struct { pub fn init(device: *const Device, support: *const Support, id: usize) !Self { const family = support.families[id] orelse unreachable; // fix this silliness const index = support.indices[id]; + assert(family >= 0); + assert(device.handle != .null_handle); const handle = device.dispatch.getDeviceQueue(device.handle, family, @enumToInt(index)); + assert(handle != .null_handle); var self = Self{ .family = family,