good but wrong teardown order; device wait idle
This commit is contained in:
@@ -2,11 +2,105 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const vk = @import("vk");
|
||||
const nu = @import("../nu.zig");
|
||||
const au = @import("Render/au.zig");
|
||||
const Render = @import("Render.zig");
|
||||
const Window = @import("Window.zig");
|
||||
|
||||
pub fn init(alloc: std.mem.Allocator) !void {
|
||||
_ = alloc;
|
||||
const im = @import("cimgui");
|
||||
|
||||
pub fn loader_wrapper(procname: [*c]const u8, _: ?*anyopaque) callconv(.C) vk.PfnVoidFunction {
|
||||
return au.glfwGetInstanceProcAddress(au.I.handle, procname);
|
||||
}
|
||||
|
||||
var ctx: *im.c.ImGuiContext = undefined;
|
||||
var descriptor_pool: vk.DescriptorPool = undefined;
|
||||
|
||||
pub fn init() !void {
|
||||
ctx = im.c.igCreateContext(null) orelse {
|
||||
return error.igCreateContextFailed;
|
||||
};
|
||||
errdefer im.c.igDestroyContext(ctx);
|
||||
|
||||
if (!im.c.ImGui_ImplVulkan_LoadFunctions(loader_wrapper, null)) {
|
||||
return error.igVulkanLoadFunctionsFailed;
|
||||
}
|
||||
|
||||
if (!im.c.ImGui_ImplGlfw_InitForVulkan(@ptrCast(Window.handle), true)) {
|
||||
return error.igGlfwInitFailed;
|
||||
}
|
||||
errdefer im.c.ImGui_ImplGlfw_Shutdown();
|
||||
|
||||
descriptor_pool = try au.D.createDescriptorPool(&vk.DescriptorPoolCreateInfo{
|
||||
.flags = .{ .free_descriptor_set_bit = true },
|
||||
.pool_size_count = 1,
|
||||
.p_pool_sizes = &.{vk.DescriptorPoolSize{
|
||||
.descriptor_count = 32,
|
||||
.type = .combined_image_sampler,
|
||||
}},
|
||||
.max_sets = 32,
|
||||
}, null);
|
||||
errdefer au.D.destroyDescriptorPool(descriptor_pool, null);
|
||||
|
||||
if (im.c.ImGui_ImplVulkan_Init(@constCast(&im.c.ImGui_ImplVulkan_InitInfo{
|
||||
.Instance = @ptrFromInt(@intFromEnum(au.I.handle)),
|
||||
.PhysicalDevice = @ptrFromInt(@intFromEnum(au.device_config.pdev)),
|
||||
.Device = @ptrFromInt(@intFromEnum(au.D.handle)),
|
||||
.QueueFamily = au.device_config.family,
|
||||
.Queue = @ptrFromInt(@intFromEnum(au.Q.handle)),
|
||||
.DescriptorPool = @ptrFromInt(@intFromEnum(descriptor_pool)),
|
||||
.RenderPass = null,
|
||||
.MinImageCount = 2,
|
||||
.ImageCount = @intCast(nu.options.render.frames_in_flight),
|
||||
.PipelineRenderingCreateInfo = @bitCast(vk.PipelineRenderingCreateInfo{
|
||||
.view_mask = 0,
|
||||
.depth_attachment_format = .undefined,
|
||||
.stencil_attachment_format = .undefined,
|
||||
.color_attachment_count = 1,
|
||||
.p_color_attachment_formats = &.{au.device_config.format.format},
|
||||
}),
|
||||
.MSAASamples = 0,
|
||||
.PipelineCache = null,
|
||||
.Subpass = 0,
|
||||
.UseDynamicRendering = true,
|
||||
.Allocator = null,
|
||||
})) != true) {
|
||||
return error.igVulkanInitFailed;
|
||||
}
|
||||
errdefer im.c.ImGui_ImplVulkan_Shutdown();
|
||||
|
||||
if (!im.c.ImGui_ImplVulkan_CreateFontsTexture()) {
|
||||
return error.igVulkanFontTextureFailed;
|
||||
}
|
||||
|
||||
try Render.add_present_callback(present);
|
||||
errdefer Render.remove_present_callback(present);
|
||||
}
|
||||
|
||||
pub fn frame() void {
|
||||
im.c.ImGui_ImplGlfw_NewFrame();
|
||||
im.c.ImGui_ImplVulkan_NewFrame();
|
||||
im.c.igNewFrame();
|
||||
|
||||
im.c.igShowDemoWindow(null);
|
||||
|
||||
im.c.igEndFrame();
|
||||
im.c.igRender();
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
Render.remove_present_callback(present);
|
||||
im.c.ImGui_ImplVulkan_Shutdown();
|
||||
au.D.destroyDescriptorPool(descriptor_pool, null);
|
||||
im.c.ImGui_ImplGlfw_Shutdown();
|
||||
im.c.igDestroyContext(ctx);
|
||||
}
|
||||
|
||||
pub fn present(cmd: au.CommandBufferProxy) void {
|
||||
im.c.ImGui_ImplVulkan_RenderDrawData(
|
||||
im.c.igGetDrawData(),
|
||||
@ptrFromInt(@intFromEnum(cmd.handle)),
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user