diff options
| author | 2020-03-31 20:26:44 -0300 | |
|---|---|---|
| committer | 2020-03-31 21:32:07 -0300 | |
| commit | 151ddcf419bcbe6e914b7cf47698744727671648 (patch) | |
| tree | 4a62a6bc6f6d4741825cd06aa1656468017ef57f /src | |
| parent | Merge pull request #3566 from ReinUsesLisp/vk-wrapper-part1 (diff) | |
| download | yuzu-151ddcf419bcbe6e914b7cf47698744727671648.tar.gz yuzu-151ddcf419bcbe6e914b7cf47698744727671648.tar.xz yuzu-151ddcf419bcbe6e914b7cf47698744727671648.zip | |
renderer_vulkan/wrapper: Add instance handle
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/wrapper.cpp | 70 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/wrapper.h | 17 |
2 files changed, 87 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/wrapper.cpp b/src/video_core/renderer_vulkan/wrapper.cpp index c412b7f20..2e743e926 100644 --- a/src/video_core/renderer_vulkan/wrapper.cpp +++ b/src/video_core/renderer_vulkan/wrapper.cpp | |||
| @@ -339,4 +339,74 @@ VkResult Free(VkDevice device, VkCommandPool handle, Span<VkCommandBuffer> buffe | |||
| 339 | return VK_SUCCESS; | 339 | return VK_SUCCESS; |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | Instance Instance::Create(Span<const char*> layers, Span<const char*> extensions, | ||
| 343 | InstanceDispatch& dld) noexcept { | ||
| 344 | VkApplicationInfo application_info; | ||
| 345 | application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; | ||
| 346 | application_info.pNext = nullptr; | ||
| 347 | application_info.pApplicationName = "yuzu Emulator"; | ||
| 348 | application_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0); | ||
| 349 | application_info.pEngineName = "yuzu Emulator"; | ||
| 350 | application_info.engineVersion = VK_MAKE_VERSION(0, 1, 0); | ||
| 351 | application_info.apiVersion = VK_API_VERSION_1_1; | ||
| 352 | |||
| 353 | VkInstanceCreateInfo ci; | ||
| 354 | ci.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; | ||
| 355 | ci.pNext = nullptr; | ||
| 356 | ci.flags = 0; | ||
| 357 | ci.pApplicationInfo = &application_info; | ||
| 358 | ci.enabledLayerCount = layers.size(); | ||
| 359 | ci.ppEnabledLayerNames = layers.data(); | ||
| 360 | ci.enabledExtensionCount = extensions.size(); | ||
| 361 | ci.ppEnabledExtensionNames = extensions.data(); | ||
| 362 | |||
| 363 | VkInstance instance; | ||
| 364 | if (dld.vkCreateInstance(&ci, nullptr, &instance) != VK_SUCCESS) { | ||
| 365 | // Failed to create the instance. | ||
| 366 | return {}; | ||
| 367 | } | ||
| 368 | if (!Proc(dld.vkDestroyInstance, dld, "vkDestroyInstance", instance)) { | ||
| 369 | // We successfully created an instance but the destroy function couldn't be loaded. | ||
| 370 | // This is a good moment to panic. | ||
| 371 | return {}; | ||
| 372 | } | ||
| 373 | |||
| 374 | return Instance(instance, dld); | ||
| 375 | } | ||
| 376 | |||
| 377 | std::optional<std::vector<VkPhysicalDevice>> Instance::EnumeratePhysicalDevices() { | ||
| 378 | u32 num; | ||
| 379 | if (dld->vkEnumeratePhysicalDevices(handle, &num, nullptr) != VK_SUCCESS) { | ||
| 380 | return std::nullopt; | ||
| 381 | } | ||
| 382 | std::vector<VkPhysicalDevice> physical_devices(num); | ||
| 383 | if (dld->vkEnumeratePhysicalDevices(handle, &num, physical_devices.data()) != VK_SUCCESS) { | ||
| 384 | return std::nullopt; | ||
| 385 | } | ||
| 386 | return physical_devices; | ||
| 387 | } | ||
| 388 | |||
| 389 | DebugCallback Instance::TryCreateDebugCallback( | ||
| 390 | PFN_vkDebugUtilsMessengerCallbackEXT callback) noexcept { | ||
| 391 | VkDebugUtilsMessengerCreateInfoEXT ci; | ||
| 392 | ci.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; | ||
| 393 | ci.pNext = nullptr; | ||
| 394 | ci.flags = 0; | ||
| 395 | ci.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | | ||
| 396 | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | | ||
| 397 | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT | | ||
| 398 | VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT; | ||
| 399 | ci.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | | ||
| 400 | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | | ||
| 401 | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; | ||
| 402 | ci.pfnUserCallback = callback; | ||
| 403 | ci.pUserData = nullptr; | ||
| 404 | |||
| 405 | VkDebugUtilsMessengerEXT messenger; | ||
| 406 | if (dld->vkCreateDebugUtilsMessengerEXT(handle, &ci, nullptr, &messenger) != VK_SUCCESS) { | ||
| 407 | return {}; | ||
| 408 | } | ||
| 409 | return DebugCallback(messenger, handle, *dld); | ||
| 410 | } | ||
| 411 | |||
| 342 | } // namespace Vulkan::vk | 412 | } // namespace Vulkan::vk |
diff --git a/src/video_core/renderer_vulkan/wrapper.h b/src/video_core/renderer_vulkan/wrapper.h index 686c2b9a1..8eb31e77d 100644 --- a/src/video_core/renderer_vulkan/wrapper.h +++ b/src/video_core/renderer_vulkan/wrapper.h | |||
| @@ -542,4 +542,21 @@ using SurfaceKHR = Handle<VkSurfaceKHR, VkInstance, InstanceDispatch>; | |||
| 542 | using DescriptorSets = PoolAllocations<VkDescriptorSet, VkDescriptorPool>; | 542 | using DescriptorSets = PoolAllocations<VkDescriptorSet, VkDescriptorPool>; |
| 543 | using CommandBuffers = PoolAllocations<VkCommandBuffer, VkCommandPool>; | 543 | using CommandBuffers = PoolAllocations<VkCommandBuffer, VkCommandPool>; |
| 544 | 544 | ||
| 545 | /// Vulkan instance owning handle. | ||
| 546 | class Instance : public Handle<VkInstance, NoOwner, InstanceDispatch> { | ||
| 547 | using Handle<VkInstance, NoOwner, InstanceDispatch>::Handle; | ||
| 548 | |||
| 549 | public: | ||
| 550 | /// Creates a Vulkan instance. Use "operator bool" for error handling. | ||
| 551 | static Instance Create(Span<const char*> layers, Span<const char*> extensions, | ||
| 552 | InstanceDispatch& dld) noexcept; | ||
| 553 | |||
| 554 | /// Enumerates physical devices. | ||
| 555 | /// @return Physical devices and an empty handle on failure. | ||
| 556 | std::optional<std::vector<VkPhysicalDevice>> EnumeratePhysicalDevices(); | ||
| 557 | |||
| 558 | /// Tries to create a debug callback messenger. Returns an empty handle on failure. | ||
| 559 | DebugCallback TryCreateDebugCallback(PFN_vkDebugUtilsMessengerCallbackEXT callback) noexcept; | ||
| 560 | }; | ||
| 561 | |||
| 545 | } // namespace Vulkan::vk | 562 | } // namespace Vulkan::vk |