| 1 |
/* |
| 2 |
* Copyright (c) 2025 The Khronos Group Inc. |
| 3 |
* Copyright (c) 2025 Valve Corporation |
| 4 |
* Copyright (c) 2025 LunarG, Inc. |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and/or associated documentation files (the "Materials"), to |
| 8 |
* deal in the Materials without restriction, including without limitation the |
| 9 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 |
* sell copies of the Materials, and to permit persons to whom the Materials are |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice(s) and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Materials. |
| 15 |
* |
| 16 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 |
* |
| 20 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 21 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 22 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 23 |
* USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "vulkan_object_wrappers.h" |
| 28 |
|
| 29 |
#include "platform_wsi.h" |
| 30 |
|
| 31 |
VkExtensionProperties Extension::get() const noexcept { |
| 32 |
VkExtensionProperties props{}; |
| 33 |
extensionName.copy(props.extensionName, VK_MAX_EXTENSION_NAME_SIZE); |
| 34 |
props.specVersion = specVersion; |
| 35 |
return props; |
| 36 |
} |
| 37 |
|
| 38 |
InstanceCreateInfo::InstanceCreateInfo() { |
| 39 |
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
| 40 |
application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 41 |
} |
| 42 |
|
| 43 |
VkInstanceCreateInfo* InstanceCreateInfo::get() noexcept { |
| 44 |
if (fill_in_application_info) { |
| 45 |
application_info.pApplicationName = app_name.c_str(); |
| 46 |
application_info.pEngineName = engine_name.c_str(); |
| 47 |
application_info.applicationVersion = app_version; |
| 48 |
application_info.engineVersion = engine_version; |
| 49 |
application_info.apiVersion = api_version; |
| 50 |
instance_info.pApplicationInfo = &application_info; |
| 51 |
} |
| 52 |
instance_info.flags = flags; |
| 53 |
instance_info.enabledLayerCount = static_cast<uint32_t>(enabled_layers.size()); |
| 54 |
instance_info.ppEnabledLayerNames = enabled_layers.data(); |
| 55 |
instance_info.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions.size()); |
| 56 |
instance_info.ppEnabledExtensionNames = enabled_extensions.data(); |
| 57 |
return &instance_info; |
| 58 |
} |
| 59 |
InstanceCreateInfo& InstanceCreateInfo::set_api_version(uint32_t major, uint32_t minor, uint32_t patch) { |
| 60 |
this->api_version = VK_MAKE_API_VERSION(0, major, minor, patch); |
| 61 |
return *this; |
| 62 |
} |
| 63 |
InstanceCreateInfo& InstanceCreateInfo::setup_WSI(const char* api_selection) { |
| 64 |
add_extensions({"VK_KHR_surface", get_platform_wsi_extension(api_selection)}); |
| 65 |
return *this; |
| 66 |
} |
| 67 |
|
| 68 |
DeviceQueueCreateInfo::DeviceQueueCreateInfo() { queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; } |
| 69 |
DeviceQueueCreateInfo::DeviceQueueCreateInfo(const VkDeviceQueueCreateInfo* create_info) { |
| 70 |
queue_create_info = *create_info; |
| 71 |
for (uint32_t i = 0; i < create_info->queueCount; i++) { |
| 72 |
priorities.push_back(create_info->pQueuePriorities[i]); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
VkDeviceQueueCreateInfo DeviceQueueCreateInfo::get() noexcept { |
| 77 |
queue_create_info.pQueuePriorities = priorities.data(); |
| 78 |
queue_create_info.queueCount = 1; |
| 79 |
queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 80 |
return queue_create_info; |
| 81 |
} |
| 82 |
|
| 83 |
DeviceCreateInfo::DeviceCreateInfo(const VkDeviceCreateInfo* create_info) { |
| 84 |
dev = *create_info; |
| 85 |
for (uint32_t i = 0; i < create_info->enabledExtensionCount; i++) { |
| 86 |
enabled_extensions.push_back(create_info->ppEnabledExtensionNames[i]); |
| 87 |
} |
| 88 |
for (uint32_t i = 0; i < create_info->enabledLayerCount; i++) { |
| 89 |
enabled_layers.push_back(create_info->ppEnabledLayerNames[i]); |
| 90 |
} |
| 91 |
for (uint32_t i = 0; i < create_info->queueCreateInfoCount; i++) { |
| 92 |
device_queue_infos.push_back(create_info->pQueueCreateInfos[i]); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
VkDeviceCreateInfo* DeviceCreateInfo::get() noexcept { |
| 97 |
dev.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 98 |
dev.enabledLayerCount = static_cast<uint32_t>(enabled_layers.size()); |
| 99 |
dev.ppEnabledLayerNames = enabled_layers.data(); |
| 100 |
dev.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions.size()); |
| 101 |
dev.ppEnabledExtensionNames = enabled_extensions.data(); |
| 102 |
uint32_t index = 0; |
| 103 |
for (auto& queue : queue_info_details) { |
| 104 |
queue.queue_create_info.queueFamilyIndex = index++; |
| 105 |
queue.queue_create_info.queueCount = 1; |
| 106 |
device_queue_infos.push_back(queue.get()); |
| 107 |
} |
| 108 |
|
| 109 |
dev.queueCreateInfoCount = static_cast<uint32_t>(device_queue_infos.size()); |
| 110 |
dev.pQueueCreateInfos = device_queue_infos.data(); |
| 111 |
return &dev; |
| 112 |
} |