compile fixes, more validation errors now
This commit is contained in:
parent
63aff9b1bc
commit
4a63e3131f
3 changed files with 51 additions and 40 deletions
|
@ -15,17 +15,17 @@ depth: [settings.resource_sets]Image,
|
|||
scene: [settings.resource_sets]Image,
|
||||
|
||||
// TODO: scaled render resolution
|
||||
pub fn getDesiredWidth(swapchain: *const Swapchain) u32 {
|
||||
getDisplayWidth(swapchain);
|
||||
pub fn getDesiredWidth(swapchain: *Swapchain) u32 {
|
||||
return getDisplayWidth(swapchain);
|
||||
}
|
||||
|
||||
pub fn getDesiredHeight(swapchain: *const Swapchain) u32 {
|
||||
getDisplayHeight(swapchain);
|
||||
pub fn getDesiredHeight(swapchain: *Swapchain) u32 {
|
||||
return getDisplayHeight(swapchain);
|
||||
}
|
||||
|
||||
var s_targets: Self = undefined;
|
||||
|
||||
pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
|
||||
pub fn init(device: *const Device, swapchain: *Swapchain) !void {
|
||||
errdefer deinit(device);
|
||||
|
||||
const width = getDesiredWidth(swapchain);
|
||||
|
@ -47,7 +47,7 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
|
|||
queues.get(.compute).family,
|
||||
};
|
||||
|
||||
try Image.init(s, .{
|
||||
try Image.init(s, device, .{
|
||||
.flags = .{},
|
||||
.image_type = .@"2d",
|
||||
.format = .r16g16b16a16_sfloat,
|
||||
|
@ -73,10 +73,11 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
|
|||
.depth_stencil_attachment_bit = true,
|
||||
.sampled_bit = true,
|
||||
};
|
||||
const queue_family_indices = []u32{
|
||||
const queue_family_indices = [_]u32{
|
||||
queues.get(.graphics).family,
|
||||
};
|
||||
try Image.init(d, &.{
|
||||
try Image.init(d, device, .{
|
||||
.flags = .{},
|
||||
.image_type = .@"2d",
|
||||
.format = .x8_d24_unorm_pack32,
|
||||
.extent = .{
|
||||
|
@ -86,14 +87,14 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
|
|||
},
|
||||
.mip_levels = 1,
|
||||
.array_layers = 1,
|
||||
.samples = .@"1_bit",
|
||||
.samples = .{ .@"1_bit" = true },
|
||||
.tiling = .optimal,
|
||||
.usage = usage,
|
||||
.sharing_mode = .exclusive,
|
||||
.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",
|
||||
}, .gpu_only);
|
||||
}, .gpuOnly);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,21 +117,21 @@ pub fn recreate(device: *const Device) void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn getDisplayWidth(swapchain: *const Swapchain) u32 {
|
||||
swapchain.getBackBuffer().width;
|
||||
pub fn getDisplayWidth(swapchain: *Swapchain) u32 {
|
||||
return swapchain.getBackBuffer().width;
|
||||
}
|
||||
|
||||
pub fn getDisplayHeight(swapchain: *const Swapchain) u32 {
|
||||
swapchain.getBackBuffer().height;
|
||||
pub fn getDisplayHeight(swapchain: *Swapchain) u32 {
|
||||
return swapchain.getBackBuffer().height;
|
||||
}
|
||||
|
||||
pub fn getDepthBuffer(swapchain: *const Swapchain) *Image {
|
||||
pub fn getDepthBuffer(swapchain: *Swapchain) *Image {
|
||||
const img = &s_targets.depth[swapchain.sync_index];
|
||||
assert(img.handle != .null_handle);
|
||||
return img;
|
||||
}
|
||||
|
||||
pub fn getSceneBuffer(swapchain: *const Swapchain) *Image {
|
||||
pub fn getSceneBuffer(swapchain: *Swapchain) *Image {
|
||||
var img = &s_targets.scene[swapchain.sync_index];
|
||||
assert(img.handle != .null_handle);
|
||||
return img;
|
||||
|
|
|
@ -33,8 +33,8 @@ pub const Image = struct {
|
|||
image_type: vk.ImageType,
|
||||
imported: bool,
|
||||
|
||||
pub fn init(self: *Self, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
|
||||
try memory.imageNew(self, info, mem_usage);
|
||||
pub fn init(self: *Self, device: *const Device, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
|
||||
try memory.imageNew(self, device, info, mem_usage);
|
||||
}
|
||||
|
||||
pub fn release(self: *const Self) !void {
|
||||
|
|
|
@ -37,10 +37,18 @@ pub fn finalize(device: *const Device) !void {
|
|||
pub fn update() void {}
|
||||
|
||||
const pm_imgnew = profiler.ProfileMark.init("memory.imageNew");
|
||||
pub fn imageNew(img: *Image, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
|
||||
pub fn imageNew(img: *Image, device: *const Device, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
|
||||
pm_imgnew.begin();
|
||||
defer pm_imgnew.end();
|
||||
|
||||
errdefer |err| {
|
||||
std.debug.print("Failed to allocate image: {}\n", .{err});
|
||||
std.debug.print("Size: {} x {} x {}\n", .{ info.extent.width, info.extent.height, info.extent.depth });
|
||||
std.debug.print("Mip Levels: {}\n", .{info.mip_levels});
|
||||
std.debug.print("Array Layers: {}\n", .{info.array_layers});
|
||||
imageDel(img, device);
|
||||
}
|
||||
|
||||
// memset needed?
|
||||
img.image_type = info.image_type;
|
||||
img.format = info.format;
|
||||
|
@ -55,20 +63,19 @@ pub fn imageNew(img: *Image, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsag
|
|||
img.array_layers = @intCast(u8, info.array_layers);
|
||||
img.imported = false;
|
||||
|
||||
try vma.Allocator.createImage(s_allocator.handle, info, &.{
|
||||
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, .{
|
||||
.flags = .{
|
||||
.withinBudget = true,
|
||||
},
|
||||
.usage = mem_usage,
|
||||
.pool = getTexturePool(info.usage, mem_usage),
|
||||
}, &img.handle, &img.allocation, null);
|
||||
errdefer {
|
||||
std.debug.print("Failed to allocate image:\n", .{});
|
||||
std.debug.print("Size: {} x {} x {}\n", .{ info.extent.width, info.extent.height, info.extent.depth });
|
||||
std.debug.print("Mip Levels: {}\n", .{info.mip_levels});
|
||||
std.debug.print("Array Layers: {}\n", .{info.array_layers});
|
||||
imageDel(img);
|
||||
}
|
||||
.pool = pool,
|
||||
});
|
||||
img.handle = result.image;
|
||||
img.allocation = result.allocation;
|
||||
}
|
||||
|
||||
const pm_imagedel = profiler.ProfileMark.init("memory.imageDel");
|
||||
|
@ -81,20 +88,23 @@ pub fn imageDel(img: *const Image, device: *const Device) void {
|
|||
}
|
||||
|
||||
fn getTexturePool(usage: vk.ImageUsageFlags, mem_usage: vma.MemoryUsage) ?vma.Pool {
|
||||
const pool = switch (mem_usage) {
|
||||
.gpu_only => {
|
||||
if (usage & s_allocator.device_texture_pool.image_usage) {
|
||||
s_allocator.device_texture_pool.handle;
|
||||
} else {
|
||||
null;
|
||||
var pool: ?vma.Pool = null;
|
||||
switch (mem_usage) {
|
||||
.gpuOnly => {
|
||||
if (s_allocator.device_texture_pool.image_usage) |pool_usage| {
|
||||
if (usage.intersect(pool_usage).toInt() != 0) {
|
||||
pool = s_allocator.device_texture_pool.handle;
|
||||
}
|
||||
}
|
||||
},
|
||||
else => null,
|
||||
};
|
||||
else => {},
|
||||
}
|
||||
|
||||
const attachment_usage: vk.ImageUsageFlags = .color_attachment_bit | .depth_stencil_attachment_bit;
|
||||
std.debug.print("usage in getTexturePool {}\n", .{usage});
|
||||
|
||||
std.debug.assert(pool != null || (usage & attachment_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);
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue