Skip to content

Commit

Permalink
Make the first Kope sample work via Vulkan
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 10, 2025
1 parent a7b220f commit a140b1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,11 @@ void kinc_g5_internal_init_window(int window_index, int depthBufferBits, int ste
void kinc_g5_internal_destroy_window(int window_index) {
struct vk_window *window = &vk_ctx.windows[window_index];
VkSwapchainKHR swapchain = cleanup_swapchain(window_index);
#ifndef KOPE
destroy_render_target_pass(window);
vk.fpDestroySwapchainKHR(vk_ctx.device, swapchain, NULL);
vk.fpDestroySurfaceKHR(vk_ctx.instance, window->surface, NULL);
#endif
}

bool kinc_window_vsynced(int window) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct kope_vulkan_command_list {
VkDevice device;
VkCommandPool command_pool;
VkCommandBuffer command_buffer;
VkFence fence;
bool presenting;
} kope_vulkan_command_list;

Expand Down
26 changes: 25 additions & 1 deletion Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,14 @@ void kope_vulkan_device_create_command_list(kope_g5_device *device, kope_g5_comm
list->vulkan.command_pool = device->vulkan.command_pool;
list->vulkan.presenting = false;

const VkFenceCreateInfo fence_create_info = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
};

vkCreateFence(device->vulkan.device, &fence_create_info, NULL, &list->vulkan.fence);

const VkCommandBufferAllocateInfo allocate_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = NULL,
Expand Down Expand Up @@ -861,7 +869,7 @@ void kope_vulkan_device_execute_command_list(kope_g5_device *device, kope_g5_com
submit_info.pWaitSemaphores = get_framebuffer_available_semaphore();
}

VkResult result = vkQueueSubmit(device->vulkan.queue, 1, &submit_info, VK_NULL_HANDLE);
VkResult result = vkQueueSubmit(device->vulkan.queue, 1, &submit_info, list->vulkan.fence);
assert(result == VK_SUCCESS);

if (list->vulkan.presenting) {
Expand All @@ -886,6 +894,22 @@ void kope_vulkan_device_execute_command_list(kope_g5_device *device, kope_g5_com
assert(result == VK_SUCCESS);
}
}

// TODO: Use multiple command buffers to avoid waits
result = vkWaitForFences(device->vulkan.device, 1, &list->vulkan.fence, VK_TRUE, UINT64_MAX);
assert(result == VK_SUCCESS);

result = vkResetFences(device->vulkan.device, 1, &list->vulkan.fence);
assert(result == VK_SUCCESS);

const VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = NULL,
.flags = 0,
.pInheritanceInfo = NULL,
};

vkBeginCommandBuffer(list->vulkan.command_buffer, &begin_info);
}

void kope_vulkan_device_wait_until_idle(kope_g5_device *device) {}
Expand Down

0 comments on commit a140b1b

Please sign in to comment.