Skip to content

Commit 3260015

Browse files
committed
Fix validation errors: merge Vulkan12 features, lineWidth, GPU idle on shutdown
1 parent 9987efa commit 3260015

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/client/FarHorizonsClient.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ pub const FarHorizonsClient = struct {
566566
profiler.frameMark();
567567
}
568568

569+
// Wait for GPU to finish all submitted work before destroying any resources
570+
self.render_system.waitIdle();
571+
569572
if (self.entity_renderer) |*er| {
570573
er.deinit();
571574
}

src/client/renderer/RenderSystem.zig

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,18 @@ pub const RenderSystem = struct {
444444
logger.info("Vulkan renderer initialized", .{});
445445
}
446446

447-
pub fn shutdown(self: *Self) void {
448-
// Wait for device to finish
447+
/// Wait for the GPU to finish all submitted work.
448+
/// Call before destroying any Vulkan resources outside of RenderSystem.
449+
pub fn waitIdle(self: *Self) void {
449450
if (self.device) |device| {
450451
if (vk.vkDeviceWaitIdle) |wait| {
451452
_ = wait(device);
452453
}
453454
}
455+
}
456+
457+
pub fn shutdown(self: *Self) void {
458+
self.waitIdle();
454459

455460
// Shutdown shader manager
456461
if (self.shader_manager) |*sm| {
@@ -1073,7 +1078,7 @@ pub const RenderSystem = struct {
10731078
const line_offsets = [_]vk.VkDeviceSize{0};
10741079
vkCmdBindVertexBuffers(command_buffer, 0, 1, &line_vertex_buffers, &line_offsets);
10751080

1076-
vkCmdSetLineWidth(command_buffer, 2.0);
1081+
vkCmdSetLineWidth(command_buffer, 1.0);
10771082
vkCmdDraw(command_buffer, self.line_vertex_count, 1, 0, 0);
10781083
}
10791084

@@ -2111,24 +2116,20 @@ pub const RenderSystem = struct {
21112116

21122117
const device_extensions = [_][*:0]const u8{"VK_KHR_swapchain"};
21132118

2114-
// Enable Vulkan 1.2 features (drawIndirectCount for GPU-driven rendering)
2119+
// Enable Vulkan 1.2 features (includes promoted descriptor indexing features)
2120+
// Cannot use VkPhysicalDeviceDescriptorIndexingFeatures alongside this - they conflict
21152121
var vulkan12_features = std.mem.zeroes(vk.VkPhysicalDeviceVulkan12Features);
21162122
vulkan12_features.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
21172123
vulkan12_features.drawIndirectCount = vk.VK_TRUE;
2118-
2119-
// Enable descriptor indexing features for bindless textures (Vulkan 1.2 core)
2120-
var indexing_features = std.mem.zeroes(vk.VkPhysicalDeviceDescriptorIndexingFeatures);
2121-
indexing_features.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES;
2122-
indexing_features.pNext = &vulkan12_features;
2123-
indexing_features.shaderSampledImageArrayNonUniformIndexing = vk.VK_TRUE;
2124-
indexing_features.runtimeDescriptorArray = vk.VK_TRUE;
2125-
indexing_features.descriptorBindingPartiallyBound = vk.VK_TRUE;
2126-
indexing_features.descriptorBindingVariableDescriptorCount = vk.VK_TRUE;
2127-
indexing_features.descriptorBindingSampledImageUpdateAfterBind = vk.VK_TRUE;
2124+
vulkan12_features.shaderSampledImageArrayNonUniformIndexing = vk.VK_TRUE;
2125+
vulkan12_features.runtimeDescriptorArray = vk.VK_TRUE;
2126+
vulkan12_features.descriptorBindingPartiallyBound = vk.VK_TRUE;
2127+
vulkan12_features.descriptorBindingVariableDescriptorCount = vk.VK_TRUE;
2128+
vulkan12_features.descriptorBindingSampledImageUpdateAfterBind = vk.VK_TRUE;
21282129

21292130
var device_features2 = std.mem.zeroes(vk.VkPhysicalDeviceFeatures2);
21302131
device_features2.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
2131-
device_features2.pNext = &indexing_features;
2132+
device_features2.pNext = &vulkan12_features;
21322133

21332134
const create_info = vk.VkDeviceCreateInfo{
21342135
.sType = vk.VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,

0 commit comments

Comments
 (0)