diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-30 22:20:36 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-30 22:20:36 +0200 |
commit | 89ae6838075f3579a85d7824d49a051b90c8ed92 (patch) | |
tree | 6369a8af2bef2929a89c8cceb16aded1bc4941fe /main | |
parent | e02f9fd89b059919baf3a8d8bf8b783470976a27 (diff) |
Vulkan device & queue creation
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/main/main.cpp b/main/main.cpp index 34d0276..e740c36 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -25,8 +25,8 @@ StatusOr<VkInstance> CreateInstance(VulkanApi* vk) };
const char* extensions[]{
- "VK_KHR_surface",
- "VK_KHR_win32_surface",
+ VK_KHR_SURFACE_EXTENSION_NAME,
+ VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
};
// @Todo Select layers & extensions based on config
@@ -104,6 +104,46 @@ StatusOr<uint32_t> FindQueueFamily(VulkanApi* vk, VkPhysicalDevice device) return InternalError("Couldn't find a suitable queue");
}
+StatusOr<VkDevice> CreateDevice(VulkanApi* vk, VkPhysicalDevice gpu, uint32_t queue_family)
+{
+ const float queue_priority = 1.0F;
+
+ VkDeviceQueueCreateInfo queue_create_info{
+ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ .pNext = nullptr,
+ .flags = 0,
+ .queueFamilyIndex = queue_family,
+ .queueCount = 1,
+ .pQueuePriorities = &queue_priority,
+ };
+
+ const char* extensions[]{
+ VK_KHR_SWAPCHAIN_EXTENSION_NAME,
+ };
+
+ VkDeviceCreateInfo create_info{
+ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ .pNext = nullptr,
+ .flags = 0,
+ .queueCreateInfoCount = 1,
+ .pQueueCreateInfos = &queue_create_info,
+ .enabledLayerCount = 0,
+ .ppEnabledLayerNames = nullptr,
+ .enabledExtensionCount = ArraySize(extensions),
+ .ppEnabledExtensionNames = extensions,
+ .pEnabledFeatures = nullptr,
+ };
+
+ VkDevice device = VK_NULL_HANDLE;
+ VkResult res = vk->CreateDevice(gpu, &create_info, kVkAlloc, &device);
+ if (res != VK_SUCCESS)
+ {
+ return InternalError("vkCreateDeviceFailed");
+ }
+
+ return device;
+}
+
Status InitializeVulkan(ApiRegistry* api_registry)
{
RegisterVulkanLoaderApi(api_registry);
@@ -147,11 +187,26 @@ Status InitializeVulkan(ApiRegistry* api_registry) StatusOr<uint32_t> s = FindQueueFamily(vk, physical_device);
if (!s.ok()) { return s.status(); }
queue_family = s.value();
+ log_api->LogInfo("Vulkan queue family: $", queue_family);
+ }
+
+ VkDevice device = VK_NULL_HANDLE;
+ {
+ StatusOr<VkDevice> s = CreateDevice(vk, physical_device, queue_family);
+ if (!s.ok()) { return s.status(); }
+ device = s.value();
+ log_api->LogInfo("Vulkan device created");
}
- log_api->LogInfo("Vulkan queue family: $", queue_family);
+ loader_api->LoadDevice(vk, device);
+ VkQueue queue = VK_NULL_HANDLE;
+ vk->GetDeviceQueue(device, queue_family, 0, &queue);
+ Ensures(queue != VK_NULL_HANDLE);
+
+ vk->DestroyDevice(device, kVkAlloc);
vk->DestroyInstance(instance, kVkAlloc);
+
return {};
}
|