| 10 | // --- Begin API Functions --- |
| 11 | |
| 12 | auto daxa_create_instance(daxa_InstanceInfo const * info, daxa_Instance * out_instance) -> daxa_Result |
| 13 | { |
| 14 | auto ret = daxa_ImplInstance{}; |
| 15 | ret.info = *reinterpret_cast<InstanceInfo const *>(info); |
| 16 | ret.engine_name = {ret.info.engine_name.data(), ret.info.engine_name.size()}; |
| 17 | ret.info.engine_name = ret.engine_name; |
| 18 | ret.app_name = {ret.info.app_name.data(), ret.info.app_name.size()}; |
| 19 | ret.info.app_name = ret.app_name; |
| 20 | std::vector<char const *> explicit_extensions{}; |
| 21 | if ((ret.info.flags & InstanceFlagBits::DEBUG_UTILS) != InstanceFlagBits::NONE) |
| 22 | { |
| 23 | explicit_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); |
| 24 | } |
| 25 | |
| 26 | std::vector<char const *> implicit_extensions{}; |
| 27 | implicit_extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 28 | implicit_extensions.push_back("VK_KHR_win32_surface"); |
| 29 | implicit_extensions.push_back("VK_KHR_xlib_surface"); |
| 30 | implicit_extensions.push_back("VK_KHR_wayland_surface"); |
| 31 | implicit_extensions.push_back("VK_EXT_swapchain_colorspace"); |
| 32 | |
| 33 | // Check existence of extensions: |
| 34 | std::vector<VkExtensionProperties> instance_extensions = {}; |
| 35 | uint32_t instance_extension_count = {}; |
| 36 | daxa_Result result = static_cast<daxa_Result>(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, nullptr)); |
| 37 | _DAXA_RETURN_IF_ERROR(result, result); |
| 38 | |
| 39 | instance_extensions.resize(instance_extension_count); |
| 40 | result = static_cast<daxa_Result>(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, instance_extensions.data())); |
| 41 | _DAXA_RETURN_IF_ERROR(result, result); |
| 42 | |
| 43 | std::vector<char const *> enabled_extensions{}; |
| 44 | enabled_extensions.reserve(implicit_extensions.size() + explicit_extensions.size()); |
| 45 | |
| 46 | for (auto const * req_ext : explicit_extensions) |
| 47 | { |
| 48 | bool found = false; |
| 49 | for (auto & instance_extension : instance_extensions) |
| 50 | { |
| 51 | if (std::strcmp(req_ext, instance_extension.extensionName) == 0) |
| 52 | { |
| 53 | found = true; |
| 54 | break; |
| 55 | } |
| 56 | } |
| 57 | if (!found) |
| 58 | { |
| 59 | return DAXA_RESULT_ERROR_EXTENSION_NOT_PRESENT; |
| 60 | } |
| 61 | enabled_extensions.push_back(req_ext); |
| 62 | } |
| 63 | |
| 64 | for (auto const * ext : implicit_extensions) |
| 65 | { |
| 66 | bool found = false; |
| 67 | for (auto & instance_extension : instance_extensions) |
| 68 | { |
| 69 | if (std::strcmp(ext, instance_extension.extensionName) == 0) |