mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
Avoid calling vulkan functions before the instance has been created
This commit is contained in:
parent
0a80ad3b83
commit
4c85f461b1
1 changed files with 3 additions and 60 deletions
|
@ -61,7 +61,6 @@
|
|||
#endif
|
||||
|
||||
bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface);
|
||||
bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names);
|
||||
|
||||
extern bool ToggleFullscreen;
|
||||
|
||||
|
@ -440,8 +439,9 @@ public:
|
|||
|
||||
VulkanInstanceBuilder builder;
|
||||
builder.DebugLayer(vk_debug);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
builder.RequireExtension(names[i]);
|
||||
builder.RequireExtension(VK_KHR_SURFACE_EXTENSION_NAME); // KHR_surface, required
|
||||
builder.OptionalExtension(VK_EXT_METAL_SURFACE_EXTENSION_NAME); // EXT_metal_surface, optional, preferred
|
||||
builder.OptionalExtension(VK_MVK_MACOS_SURFACE_EXTENSION_NAME); // MVK_macos_surface, optional, deprecated
|
||||
auto vulkanInstance = builder.Create();
|
||||
|
||||
VkSurfaceKHR surfacehandle = nullptr;
|
||||
|
@ -924,63 +924,6 @@ void I_GetVulkanDrawableSize(int *width, int *height)
|
|||
}
|
||||
}
|
||||
|
||||
bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names)
|
||||
{
|
||||
static std::vector<const char*> extensions;
|
||||
|
||||
if (extensions.empty())
|
||||
{
|
||||
uint32_t extensionPropertyCount = 0;
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &extensionPropertyCount, nullptr);
|
||||
|
||||
std::vector<VkExtensionProperties> extensionProperties(extensionPropertyCount);
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &extensionPropertyCount, extensionProperties.data());
|
||||
|
||||
static const char* const EXTENSION_NAMES[] =
|
||||
{
|
||||
VK_KHR_SURFACE_EXTENSION_NAME, // KHR_surface, required
|
||||
VK_EXT_METAL_SURFACE_EXTENSION_NAME, // EXT_metal_surface, optional, preferred
|
||||
VK_MVK_MACOS_SURFACE_EXTENSION_NAME, // MVK_macos_surface, optional, deprecated
|
||||
};
|
||||
|
||||
for (const VkExtensionProperties ¤tProperties : extensionProperties)
|
||||
{
|
||||
for (const char *const extensionName : EXTENSION_NAMES)
|
||||
{
|
||||
if (strcmp(currentProperties.extensionName, extensionName) == 0)
|
||||
{
|
||||
extensions.push_back(extensionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned int extensionCount = static_cast<unsigned int>(extensions.size());
|
||||
assert(extensionCount >= 2); // KHR_surface + at least one of the platform surface extentions
|
||||
|
||||
if (count == nullptr && names == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (names == nullptr)
|
||||
{
|
||||
*count = extensionCount;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool result = *count >= extensionCount;
|
||||
*count = min(*count, extensionCount);
|
||||
|
||||
for (unsigned int i = 0; i < *count; ++i)
|
||||
{
|
||||
names[i] = extensions[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
|
||||
{
|
||||
NSView *const view = CocoaVideo::GetWindow().contentView;
|
||||
|
|
Loading…
Reference in a new issue