forked from vv/efemra
1
0
Fork 0

more fixes!

This commit is contained in:
Vivianne 2022-07-18 03:50:19 -07:00
parent 4b59b2d387
commit 32bf9e5817
7 changed files with 42 additions and 40 deletions

View File

@ -71,7 +71,7 @@ const DepthPass = struct {
pub fn init(device: *const Device, swapchain: *Swapchain) !void { pub fn init(device: *const Device, swapchain: *Swapchain) !void {
errdefer DepthPass.deinit(); errdefer DepthPass.deinit();
const depth_buffer = swapchain.getDepthBuffer(); const depth_buffer = Targets.getDepthBuffer(swapchain);
var info = RenderPass.Description{ var info = RenderPass.Description{
.src_stage_mask = .{ .early_fragment_tests_bit = true }, .src_stage_mask = .{ .early_fragment_tests_bit = true },
@ -152,7 +152,7 @@ const DepthPass = struct {
const world_to_clip = camera.getWorldToClip(swapchain.getAspect()); const world_to_clip = camera.getWorldToClip(swapchain.getAspect());
const attachments = &[_]*Image{swapchain.getDepthBuffer()}; const attachments = &[_]*Image{Targets.getDepthBuffer(swapchain)};
const rect = vk.Rect2D{ const rect = vk.Rect2D{
.offset = std.mem.zeroes(vk.Offset2D), .offset = std.mem.zeroes(vk.Offset2D),
.extent = .{ .extent = .{

View File

@ -54,6 +54,7 @@ pub fn get(device: *const Device, desc: Description) !vk.RenderPass {
var dst = &attachments[attachment_count]; var dst = &attachments[attachment_count];
dst.format = src.format; dst.format = src.format;
dst.initial_layout = src.layout; dst.initial_layout = src.layout;
dst.final_layout = src.layout;
dst.samples = .{ .@"1_bit" = true }; dst.samples = .{ .@"1_bit" = true };
dst.stencil_load_op = .dont_care; dst.stencil_load_op = .dont_care;
dst.stencil_store_op = .dont_care; dst.stencil_store_op = .dont_care;

View File

@ -11,6 +11,7 @@ const Swapchain = @import("swapchain.zig").Swapchain;
const Context = @import("Context.zig"); const Context = @import("Context.zig");
const MainPass = @import("MainPass.zig"); const MainPass = @import("MainPass.zig");
const Command = @import("Command.zig"); const Command = @import("Command.zig");
const Targets = @import("Targets.zig");
instance: Instance, instance: Instance,
window: Window, window: Window,
@ -19,7 +20,6 @@ swapchain: Swapchain,
// sampler: Sampler, TODO // sampler: Sampler, TODO
// tex_table: TexTable, TODO // tex_table: TexTable, TODO
// bindings: Bindings, TODO // bindings: Bindings, TODO
// targets: Targets, TODO
// mesh_sys: MeshSys, TODO // mesh_sys: MeshSys, TODO
// im_sys: ImSys, TODO // im_sys: ImSys, TODO
@ -55,7 +55,7 @@ pub fn init() !Self {
// try self.sampler.init(); // try self.sampler.init();
// try self.texTable.init(); // try self.texTable.init();
// try self.bindings.init(); // try self.bindings.init();
// try self.targets.init(); try Targets.init(&device, &swapchain);
// try self.meshSys.init(); // try self.meshSys.init();
// try self.imSys.init(); // try self.imSys.init();
try MainPass.init(&device, &swapchain); try MainPass.init(&device, &swapchain);

View File

@ -9,17 +9,17 @@ const Image = @import("image.zig").Image;
const Self = @This(); const Self = @This();
width: i32, width: u32,
height: i32, height: u32,
depth: [settings.resource_sets]Image, depth: [settings.resource_sets]Image,
scene: [settings.resource_sets]Image, scene: [settings.resource_sets]Image,
// TODO: scaled render resolution // TODO: scaled render resolution
pub fn getDesiredWidth(swapchain: *const Swapchain) i32 { pub fn getDesiredWidth(swapchain: *const Swapchain) u32 {
getDisplayWidth(swapchain); getDisplayWidth(swapchain);
} }
pub fn getDesiredHeight(swapchain: *const Swapchain) i32 { pub fn getDesiredHeight(swapchain: *const Swapchain) u32 {
getDisplayHeight(swapchain); getDisplayHeight(swapchain);
} }
@ -42,12 +42,13 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
.transfer_src_bit = true, .transfer_src_bit = true,
.transfer_dst_bit = true, .transfer_dst_bit = true,
}; };
const queue_family_indices = []u32{ const queue_family_indices = [_]u32{
queues.get(.graphics).family, queues.get(.graphics).family,
queues.get(.compute).family, queues.get(.compute).family,
}; };
try Image.init(s, &.{ try Image.init(s, .{
.flags = .{},
.image_type = .@"2d", .image_type = .@"2d",
.format = .r16g16b16a16_sfloat, .format = .r16g16b16a16_sfloat,
.extent = .{ .extent = .{
@ -57,14 +58,14 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
}, },
.mip_levels = 1, .mip_levels = 1,
.array_layers = 1, .array_layers = 1,
.samples = .@"1_bit", .samples = .{ .@"1_bit" = true },
.tiling = .optimal, .tiling = .optimal,
.usage = usage, .usage = usage,
.sharing_mode = .exclusive, .sharing_mode = .exclusive,
.queue_family_index_count = queue_family_indices.len, .queue_family_index_count = queue_family_indices.len,
.p_queue_family_indices = queue_family_indices.ptr, .p_queue_family_indices = &queue_family_indices,
.initial_layout = .@"undefined", .initial_layout = .@"undefined",
}, .gpu_only); }, .gpuOnly);
} }
for (s_targets.depth) |*d| { for (s_targets.depth) |*d| {
@ -115,14 +116,26 @@ pub fn recreate(device: *const Device) void {
} }
} }
pub fn getDisplayWidth(swapchain: *const Swapchain) i32 { pub fn getDisplayWidth(swapchain: *const Swapchain) u32 {
swapchain.getBackBuffer().width; swapchain.getBackBuffer().width;
} }
pub fn getDisplayHeight(swapchain: *const Swapchain) i32 { pub fn getDisplayHeight(swapchain: *const Swapchain) u32 {
swapchain.getBackBuffer().height; swapchain.getBackBuffer().height;
} }
pub fn getDepthBuffer(swapchain: *const Swapchain) *Image {
const img = &s_targets.depth[swapchain.sync_index];
assert(img.handle != .null_handle);
return img;
}
pub fn getSceneBuffer(swapchain: *const Swapchain) *Image {
var img = &s_targets.scene[swapchain.sync_index];
assert(img.handle != .null_handle);
return img;
}
pub fn getRenderWidth() i32 { pub fn getRenderWidth() i32 {
return s_targets.width; return s_targets.width;
} }

View File

@ -33,11 +33,8 @@ pub const Image = struct {
image_type: vk.ImageType, image_type: vk.ImageType,
imported: bool, imported: bool,
pub fn init(info: *const vk.ImageCreateInfo, mem_usage: memory.Usage) !Self { pub fn init(self: *Self, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
const self = Self{}; try memory.imageNew(self, info, mem_usage);
memory.imageNew(self, info, mem_usage);
return self;
} }
pub fn release(self: *const Self) !void { pub fn release(self: *const Self) !void {
@ -249,7 +246,10 @@ pub const Image = struct {
const prev = &img.state; const prev = &img.state;
const prev_queue = queues.get(prev.owner); const prev_queue = queues.get(prev.owner);
const next_queue = queues.get(self.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()); 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()); assert(self.access.intersect(next_queue.access_mask).toInt() == self.access.toInt());
if (prev.substates != null) { if (prev.substates != null) {

View File

@ -37,7 +37,7 @@ pub fn finalize(device: *const Device) !void {
pub fn update() void {} pub fn update() void {}
const pm_imgnew = profiler.ProfileMark.init("memory.imageNew"); const pm_imgnew = profiler.ProfileMark.init("memory.imageNew");
pub fn imageNew(img: *Image, info: *const vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void { pub fn imageNew(img: *Image, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
pm_imgnew.begin(); pm_imgnew.begin();
defer pm_imgnew.end(); defer pm_imgnew.end();
@ -45,17 +45,17 @@ pub fn imageNew(img: *Image, info: *const vk.ImageCreateInfo, mem_usage: vma.Mem
img.image_type = info.image_type; img.image_type = info.image_type;
img.format = info.format; img.format = info.format;
img.state.owner = .graphics; img.state.owner = .graphics;
img.state.stage = 0; img.state.stage = .{};
img.state.layout = info.initial_layout; img.state.layout = info.initial_layout;
img.usage = info.usage; img.usage = info.usage;
img.width = info.extent.width; img.width = @intCast(u16, info.extent.width);
img.height = info.extent.height; img.height = @intCast(u16, info.extent.height);
img.depth = info.extent.depth; img.depth = @intCast(u12, info.extent.depth);
img.mip_levels = info.mip_levels; img.mip_levels = @intCast(u8, info.mip_levels);
img.array_layers = info.array_layers; img.array_layers = @intCast(u8, info.array_layers);
img.imported = false; img.imported = false;
try vma.createImage(s_allocator.handle, info, &.{ try vma.Allocator.createImage(s_allocator.handle, info, &.{
.flags = .{ .flags = .{
.withinBudget = true, .withinBudget = true,
}, },

View File

@ -356,16 +356,4 @@ pub const Swapchain = struct {
assert(img.handle != .null_handle); assert(img.handle != .null_handle);
return img; return img;
} }
pub fn getDepthBuffer(self: *Self) *Image {
var img = &self.images[self.sync_index];
assert(img.handle != .null_handle);
return img;
}
pub fn getSceneBuffer(self: *Self) *Image {
var img = &self.images[self.sync_index];
assert(img.handle != .null_handle);
return img;
}
}; };