Skip to content

Commit

Permalink
Vulkan: Optionally load colorspace extension (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut authored and flibitijibibo committed Aug 6, 2024
1 parent 2e69010 commit 8625b3b
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,10 @@ struct VulkanRenderer
Uint8 outOfDeviceLocalMemoryWarning;
Uint8 outofBARMemoryWarning;

Uint8 supportsDebugUtils;
Uint8 debugMode;
SDL_bool debugMode;
VulkanExtensions supports;
SDL_bool supportsDebugUtils;
SDL_bool supportsColorspace;

VulkanMemoryAllocator *memoryAllocator;
VkPhysicalDeviceMemoryProperties memoryProperties;
Expand Down Expand Up @@ -10665,7 +10666,8 @@ static inline Uint8 SupportsInstanceExtension(
static Uint8 VULKAN_INTERNAL_CheckInstanceExtensions(
const char **requiredExtensions,
Uint32 requiredExtensionsLength,
Uint8 *supportsDebugUtils)
SDL_bool *supportsDebugUtils,
SDL_bool *supportsColorspace)
{
Uint32 extensionCount, i;
VkExtensionProperties *availableExtensions;
Expand Down Expand Up @@ -10698,6 +10700,12 @@ static Uint8 VULKAN_INTERNAL_CheckInstanceExtensions(
availableExtensions,
extensionCount);

/* Also optional and nice to have! */
*supportsColorspace = SupportsInstanceExtension(
VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME,
availableExtensions,
extensionCount);

SDL_free(availableExtensions);
return allExtensionsSupported;
}
Expand Down Expand Up @@ -10814,9 +10822,6 @@ static Uint8 VULKAN_INTERNAL_CreateInstance(
instanceExtensionNames[instanceExtensionCount++] =
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME;

instanceExtensionNames[instanceExtensionCount++] =
VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME;

#ifdef SDL_PLATFORM_APPLE
instanceExtensionNames[instanceExtensionCount++] =
VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME;
Expand All @@ -10826,7 +10831,8 @@ static Uint8 VULKAN_INTERNAL_CreateInstance(
if (!VULKAN_INTERNAL_CheckInstanceExtensions(
instanceExtensionNames,
instanceExtensionCount,
&renderer->supportsDebugUtils)) {
&renderer->supportsDebugUtils,
&renderer->supportsColorspace)) {
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION,
"Required Vulkan instance extensions not supported");
Expand All @@ -10836,7 +10842,7 @@ static Uint8 VULKAN_INTERNAL_CreateInstance(
}

if (renderer->supportsDebugUtils) {
/* Append the debug extension to the end */
/* Append the debug extension */
instanceExtensionNames[instanceExtensionCount++] =
VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
} else {
Expand All @@ -10846,6 +10852,12 @@ static Uint8 VULKAN_INTERNAL_CreateInstance(
VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}

if (renderer->supportsColorspace) {
/* Append colorspace extension */
instanceExtensionNames[instanceExtensionCount++] =
VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME;
}

createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pNext = NULL;
createInfo.flags = createFlags;
Expand Down

0 comments on commit 8625b3b

Please sign in to comment.