Loading materials and textures
This commit is contained in:
@@ -290,7 +290,14 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
|
||||
|
||||
device_wrapper_ptr.* = .load(device_handle, instance.wrapper.dispatch.vkGetDeviceProcAddr.?);
|
||||
const device = vk.DeviceProxy.init(device_handle, device_wrapper_ptr);
|
||||
errdefer device.destroyDevice(vk_allocator.interface);
|
||||
errdefer device.destroyDevice(&vk_allocator.interface);
|
||||
|
||||
// --- GET QUEUES, CREATE COMMAND POOLS ------------------------------------
|
||||
|
||||
const graphics_queue = try Queue.initAllocation(device, queue_allocations.graphics_queue, false, &vk_allocator.interface);
|
||||
const compute_queue = try Queue.initAllocation(device, queue_allocations.compute_queue, true, &vk_allocator.interface);
|
||||
const transfer_queue = try Queue.initAllocation(device, queue_allocations.transfer_queue, true, &vk_allocator.interface);
|
||||
const presentation_queue = if (maybe_window != null) try Queue.initAllocation(device, queue_allocations.presentation_queue, false, &vk_allocator.interface) else undefined;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -298,7 +305,7 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
|
||||
.mode = if (maybe_window) |window| .{ .surface = .{
|
||||
.window = window,
|
||||
.surface = surface,
|
||||
.presentation_queue = .initAllocation(device, queue_allocations.presentation_queue),
|
||||
.presentation_queue = presentation_queue,
|
||||
} } else .{ .headless = {} },
|
||||
.vk_allocator = vk_allocator,
|
||||
|
||||
@@ -311,15 +318,22 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
|
||||
.memory_types = memory_types,
|
||||
.memory_heaps = memory_heaps,
|
||||
|
||||
.graphics_queue = .initAllocation(device, queue_allocations.graphics_queue),
|
||||
.compute_queue = .initAllocation(device, queue_allocations.compute_queue),
|
||||
.transfer_queue = .initAllocation(device, queue_allocations.transfer_queue),
|
||||
.graphics_queue = graphics_queue,
|
||||
.compute_queue = compute_queue,
|
||||
.transfer_queue = transfer_queue,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Engine) void {
|
||||
const allocator = self.vk_allocator.allocator;
|
||||
|
||||
if (std.meta.activeTag(self.mode) == .surface) {
|
||||
self.mode.surface.presentation_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
}
|
||||
self.transfer_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
self.compute_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
self.graphics_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
|
||||
self.device.destroyDevice(&self.vk_allocator.interface);
|
||||
allocator.destroy(self.device.wrapper);
|
||||
|
||||
@@ -348,13 +362,63 @@ pub fn allocate(self: *const Engine, memory_requirements: vk.MemoryRequirements,
|
||||
return try self.device.allocateMemory(&.{
|
||||
.allocation_size = memory_requirements.size,
|
||||
.memory_type_index = @truncate(i),
|
||||
});
|
||||
}, &self.vk_allocator.interface);
|
||||
}
|
||||
}
|
||||
|
||||
return error.NoSuitableMemoryType;
|
||||
}
|
||||
|
||||
pub fn allocateTransferCommandBuffer(self: *const Engine) !vk.CommandBufferProxy {
|
||||
var command_buffer: vk.CommandBuffer = undefined;
|
||||
try self.device.allocateCommandBuffers(&.{
|
||||
.command_pool = self.transfer_queue.command_pool,
|
||||
.level = .primary,
|
||||
.command_buffer_count = 1,
|
||||
}, @ptrCast(&command_buffer));
|
||||
return .init(command_buffer, self.device.wrapper);
|
||||
}
|
||||
|
||||
pub fn allocateGraphicsCommandBuffer(self: *const Engine) !vk.CommandBufferProxy {
|
||||
var command_buffer: vk.CommandBuffer = undefined;
|
||||
try self.device.allocateCommandBuffers(&.{
|
||||
.command_pool = self.graphics_queue.command_pool,
|
||||
.level = .primary,
|
||||
.command_buffer_count = 1,
|
||||
}, @ptrCast(&command_buffer));
|
||||
return .init(command_buffer, self.device.wrapper);
|
||||
}
|
||||
|
||||
pub fn freeTransferCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy) void {
|
||||
self.device.freeCommandBuffers(self.transfer_queue.command_pool, 1, @ptrCast(&command_buffer));
|
||||
}
|
||||
|
||||
pub fn freeGraphicsCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy) void {
|
||||
self.device.freeCommandBuffers(self.graphics_queue.command_pool, 1, @ptrCast(&command_buffer));
|
||||
}
|
||||
|
||||
pub fn submitTransferCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy, fence: vk.Fence) !void {
|
||||
const submits = [_]vk.SubmitInfo{
|
||||
.{
|
||||
.command_buffer_count = 1,
|
||||
.p_command_buffers = @ptrCast(&command_buffer.handle),
|
||||
},
|
||||
};
|
||||
|
||||
try self.device.queueSubmit(self.transfer_queue.handle, submits.len, &submits, fence);
|
||||
}
|
||||
|
||||
pub fn submitGraphicsCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy, fence: vk.Fence) !void {
|
||||
const submits = [_]vk.SubmitInfo{
|
||||
.{
|
||||
.command_buffer_count = 1,
|
||||
.p_command_buffers = @ptrCast(&command_buffer.handle),
|
||||
},
|
||||
};
|
||||
|
||||
try self.device.queueSubmit(self.graphics_queue.handle, submits.len, &submits, fence);
|
||||
}
|
||||
|
||||
fn debugUtilsMessengerCallback(
|
||||
severity: vk.DebugUtilsMessageSeverityFlagsEXT,
|
||||
message_type: vk.DebugUtilsMessageTypeFlagsEXT,
|
||||
|
||||
Reference in New Issue
Block a user