compile fixes, more validation errors now
This commit is contained in:
parent
63aff9b1bc
commit
4a63e3131f
|
@ -15,17 +15,17 @@ 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) u32 {
|
pub fn getDesiredWidth(swapchain: *Swapchain) u32 {
|
||||||
getDisplayWidth(swapchain);
|
return getDisplayWidth(swapchain);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDesiredHeight(swapchain: *const Swapchain) u32 {
|
pub fn getDesiredHeight(swapchain: *Swapchain) u32 {
|
||||||
getDisplayHeight(swapchain);
|
return getDisplayHeight(swapchain);
|
||||||
}
|
}
|
||||||
|
|
||||||
var s_targets: Self = undefined;
|
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);
|
errdefer deinit(device);
|
||||||
|
|
||||||
const width = getDesiredWidth(swapchain);
|
const width = getDesiredWidth(swapchain);
|
||||||
|
@ -47,7 +47,7 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
|
||||||
queues.get(.compute).family,
|
queues.get(.compute).family,
|
||||||
};
|
};
|
||||||
|
|
||||||
try Image.init(s, .{
|
try Image.init(s, device, .{
|
||||||
.flags = .{},
|
.flags = .{},
|
||||||
.image_type = .@"2d",
|
.image_type = .@"2d",
|
||||||
.format = .r16g16b16a16_sfloat,
|
.format = .r16g16b16a16_sfloat,
|
||||||
|
@ -73,10 +73,11 @@ pub fn init(device: *const Device, swapchain: *const Swapchain) !void {
|
||||||
.depth_stencil_attachment_bit = true,
|
.depth_stencil_attachment_bit = true,
|
||||||
.sampled_bit = true,
|
.sampled_bit = true,
|
||||||
};
|
};
|
||||||
const queue_family_indices = []u32{
|
const queue_family_indices = [_]u32{
|
||||||
queues.get(.graphics).family,
|
queues.get(.graphics).family,
|
||||||
};
|
};
|
||||||
try Image.init(d, &.{
|
try Image.init(d, device, .{
|
||||||
|
.flags = .{},
|
||||||
.image_type = .@"2d",
|
.image_type = .@"2d",
|
||||||
.format = .x8_d24_unorm_pack32,
|
.format = .x8_d24_unorm_pack32,
|
||||||
.extent = .{
|
.extent = .{
|
||||||
|
@ -86,14 +87,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,21 +117,21 @@ pub fn recreate(device: *const Device) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDisplayWidth(swapchain: *const Swapchain) u32 {
|
pub fn getDisplayWidth(swapchain: *Swapchain) u32 {
|
||||||
swapchain.getBackBuffer().width;
|
return swapchain.getBackBuffer().width;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDisplayHeight(swapchain: *const Swapchain) u32 {
|
pub fn getDisplayHeight(swapchain: *Swapchain) u32 {
|
||||||
swapchain.getBackBuffer().height;
|
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];
|
const img = &s_targets.depth[swapchain.sync_index];
|
||||||
assert(img.handle != .null_handle);
|
assert(img.handle != .null_handle);
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getSceneBuffer(swapchain: *const Swapchain) *Image {
|
pub fn getSceneBuffer(swapchain: *Swapchain) *Image {
|
||||||
var img = &s_targets.scene[swapchain.sync_index];
|
var img = &s_targets.scene[swapchain.sync_index];
|
||||||
assert(img.handle != .null_handle);
|
assert(img.handle != .null_handle);
|
||||||
return img;
|
return img;
|
||||||
|
|
|
@ -33,8 +33,8 @@ pub const Image = struct {
|
||||||
image_type: vk.ImageType,
|
image_type: vk.ImageType,
|
||||||
imported: bool,
|
imported: bool,
|
||||||
|
|
||||||
pub fn init(self: *Self, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
|
pub fn init(self: *Self, device: *const Device, info: vk.ImageCreateInfo, mem_usage: vma.MemoryUsage) !void {
|
||||||
try memory.imageNew(self, info, mem_usage);
|
try memory.imageNew(self, device, info, mem_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *const Self) !void {
|
pub fn release(self: *const Self) !void {
|
||||||
|
|
|
@ -37,10 +37,18 @@ 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: 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();
|
pm_imgnew.begin();
|
||||||
defer pm_imgnew.end();
|
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?
|
// memset needed?
|
||||||
img.image_type = info.image_type;
|
img.image_type = info.image_type;
|
||||||
img.format = info.format;
|
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.array_layers = @intCast(u8, info.array_layers);
|
||||||
img.imported = false;
|
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 = .{
|
.flags = .{
|
||||||
.withinBudget = true,
|
.withinBudget = true,
|
||||||
},
|
},
|
||||||
.usage = mem_usage,
|
.usage = mem_usage,
|
||||||
.pool = getTexturePool(info.usage, mem_usage),
|
.pool = pool,
|
||||||
}, &img.handle, &img.allocation, null);
|
});
|
||||||
errdefer {
|
img.handle = result.image;
|
||||||
std.debug.print("Failed to allocate image:\n", .{});
|
img.allocation = result.allocation;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pm_imagedel = profiler.ProfileMark.init("memory.imageDel");
|
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 {
|
fn getTexturePool(usage: vk.ImageUsageFlags, mem_usage: vma.MemoryUsage) ?vma.Pool {
|
||||||
const pool = switch (mem_usage) {
|
var pool: ?vma.Pool = null;
|
||||||
.gpu_only => {
|
switch (mem_usage) {
|
||||||
if (usage & s_allocator.device_texture_pool.image_usage) {
|
.gpuOnly => {
|
||||||
s_allocator.device_texture_pool.handle;
|
if (s_allocator.device_texture_pool.image_usage) |pool_usage| {
|
||||||
} else {
|
if (usage.intersect(pool_usage).toInt() != 0) {
|
||||||
null;
|
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;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue