diff options
author | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-05-03 23:31:02 +1000 |
---|---|---|
committer | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-05-03 23:31:02 +1000 |
commit | 8aad3ce06da4c8e9d2e41b39607640a5e9c7ded7 (patch) | |
tree | b64203b7ca39b6978519525a4c2918f834c60849 /src | |
parent | aed7d1b7ac340c19656059c9cbd94aff40952f83 (diff) |
get present queue
Diffstat (limited to 'src')
-rw-r--r-- | src/renderer/backends/backend_vulkan.c | 67 | ||||
-rw-r--r-- | src/renderer/backends/backend_vulkan.h | 17 | ||||
-rw-r--r-- | src/renderer/backends/vulkan_helpers.h | 12 |
3 files changed, 70 insertions, 26 deletions
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c index c21a6b9..900b592 100644 --- a/src/renderer/backends/backend_vulkan.c +++ b/src/renderer/backends/backend_vulkan.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <glfw3.h> #include <stdlib.h> #include <vulkan/vk_platform.h> @@ -163,7 +164,11 @@ bool gpu_backend_init(const char* window_name, GLFWwindow* window) { return true; } -void gpu_backend_shutdown() { arena_free_storage(&context.temp_arena); } +void gpu_backend_shutdown() { + arena_free_storage(&context.temp_arena); + vkDestroySurfaceKHR(context.instance, context.surface, context.allocator); + vkDestroyInstance(context.instance, context.allocator); +} bool gpu_device_create(gpu_device* out_device) { // First things first store this poitner from the renderer @@ -214,8 +219,18 @@ bool gpu_swapchain_create(gpu_swapchain* out_swapchain) { VkPresentModeKHR present_mode = VK_PRESENT_MODE_FIFO_KHR; // guaranteed to be implemented VkSwapchainCreateInfoKHR swapchain_create_info = { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR }; + swapchain_create_info.surface = context.surface; + swapchain_create_info.minImageCount = 2; + // TODO: image_ fields + swapchain_create_info.queueFamilyIndexCount = 0; + swapchain_create_info.pQueueFamilyIndices = 0; + + // TODO: preTransform + swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + swapchain_create_info.presentMode = present_mode; - // swapchain_create_info.minImageCount = + swapchain_create_info.clipped = VK_TRUE; + swapchain_create_info.oldSwapchain = 0; VK_CHECK(vkCreateSwapchainKHR(context.device->logical_device, &swapchain_create_info, context.allocator, &out_swapchain->handle)); @@ -434,7 +449,7 @@ bool is_physical_device_suitable(VkPhysicalDevice device) { queue_family_indices indices = find_queue_families(device); - return indices.has_graphics; + return indices.has_graphics && indices.has_present; } queue_family_indices find_queue_families(VkPhysicalDevice device) { @@ -447,12 +462,19 @@ queue_family_indices find_queue_families(VkPhysicalDevice device) { arena_alloc(&context.temp_arena, queue_family_count * sizeof(VkQueueFamilyProperties)); vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, queue_families); - for (u32 queue_i = 0; queue_i < queue_family_count; queue_i++) { + for (u32 q_fam_i = 0; q_fam_i < queue_family_count; q_fam_i++) { // Graphics queue - if (queue_families[queue_i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { - indices.graphics_queue_index = queue_i; + if (queue_families[q_fam_i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { + indices.graphics_family_index = q_fam_i; indices.has_graphics = true; } + + VkBool32 present_support = false; + vkGetPhysicalDeviceSurfaceSupportKHR(device, q_fam_i, context.surface, &present_support); + if (present_support) { + indices.present_family_index = q_fam_i; + indices.has_present = true; + } } return indices; @@ -461,13 +483,22 @@ queue_family_indices find_queue_families(VkPhysicalDevice device) { bool create_logical_device(gpu_device* out_device) { queue_family_indices indices = find_queue_families(out_device->physical_device); + // Queues f32 prio_one = 1.0; - VkDeviceQueueCreateInfo queue_create_info = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO }; - queue_create_info.queueFamilyIndex = indices.graphics_queue_index; - queue_create_info.queueCount = 1; - queue_create_info.pQueuePriorities = &prio_one; - queue_create_info.flags = 0; - queue_create_info.pNext = 0; + VkDeviceQueueCreateInfo queue_create_infos[2] = { 0 }; + queue_create_infos[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queue_create_infos[0].queueFamilyIndex = indices.graphics_family_index; + queue_create_infos[0].queueCount = 1; + queue_create_infos[0].pQueuePriorities = &prio_one; + queue_create_infos[0].flags = 0; + queue_create_infos[0].pNext = 0; + + queue_create_infos[1].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queue_create_infos[1].queueFamilyIndex = indices.present_family_index; + queue_create_infos[1].queueCount = 1; + queue_create_infos[1].pQueuePriorities = &prio_one; + queue_create_infos[1].flags = 0; + queue_create_infos[1].pNext = 0; // Features VkPhysicalDeviceFeatures device_features = { 0 }; @@ -475,8 +506,8 @@ bool create_logical_device(gpu_device* out_device) { // Device itself VkDeviceCreateInfo device_create_info = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO }; - device_create_info.queueCreateInfoCount = 1; - device_create_info.pQueueCreateInfos = &queue_create_info; + device_create_info.queueCreateInfoCount = 2; + device_create_info.pQueueCreateInfos = queue_create_infos; device_create_info.pEnabledFeatures = &device_features; device_create_info.enabledExtensionCount = 1; const char* extension_names = VK_KHR_SWAPCHAIN_EXTENSION_NAME; @@ -494,5 +525,13 @@ bool create_logical_device(gpu_device* out_device) { } TRACE("Logical device created"); + context.device->queue_family_indicies = indices; + + // Retrieve queue handles + vkGetDeviceQueue(context.device->logical_device, indices.graphics_family_index, 0, + &context.device->graphics_queue); + vkGetDeviceQueue(context.device->logical_device, indices.present_family_index, 0, + &context.device->present_queue); + return true; }
\ No newline at end of file diff --git a/src/renderer/backends/backend_vulkan.h b/src/renderer/backends/backend_vulkan.h index 9802311..8c6b772 100644 --- a/src/renderer/backends/backend_vulkan.h +++ b/src/renderer/backends/backend_vulkan.h @@ -5,6 +5,7 @@ #include "defines.h" #include "ral.h" +// #include "vulkan_helpers.h" #define GPU_SWAPCHAIN_IMG_COUNT 2 @@ -14,6 +15,17 @@ Conventions: - Vulkan specific data goes at the top, followed by our internal data */ +typedef struct queue_family_indices { + u32 graphics_family_index; + u32 present_family_index; + u32 compute_family_index; + u32 transfer_family_index; + bool has_graphics; + bool has_present; + bool has_compute; + bool has_transfer; +} queue_family_indices; + typedef struct gpu_swapchain { VkSwapchainKHR handle; } gpu_swapchain; @@ -25,6 +37,11 @@ typedef struct gpu_device { VkPhysicalDeviceProperties properties; VkPhysicalDeviceFeatures features; VkPhysicalDeviceMemoryProperties memory; + queue_family_indices queue_family_indicies; + VkQueue graphics_queue; + VkQueue present_queue; + VkQueue compute_queue; + VkQueue transfer_queue; VkCommandPool pool; } gpu_device; diff --git a/src/renderer/backends/vulkan_helpers.h b/src/renderer/backends/vulkan_helpers.h index baff4e7..d91b4a9 100644 --- a/src/renderer/backends/vulkan_helpers.h +++ b/src/renderer/backends/vulkan_helpers.h @@ -1,6 +1,5 @@ #pragma once -#include <assert.h> #include <vulkan/vulkan.h> #include <vulkan/vulkan_core.h> @@ -30,17 +29,6 @@ static void plat_get_required_extension_names(cstr_darray* extensions) { // TODO: typedef struct vk_debugger {} vk_debugger; -typedef struct queue_family_indices { - u32 graphics_queue_index; - u32 present_queue_index; - u32 compute_queue_index; - u32 transfer_queue_index; - bool has_graphics; - bool has_present; - bool has_compute; - bool has_transfer; -} queue_family_indices; - typedef struct vulkan_physical_device_requirements { bool graphics; bool present; |