Merge pull request #47640 from BastiaanOlij/fix_vulkan_format

Chose format from supported ones that we support
This commit is contained in:
Rémi Verschelde 2021-04-05 14:55:32 +02:00 committed by GitHub
commit 9e8acb3897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 2 deletions

View File

@ -993,14 +993,37 @@ Error VulkanContext::_initialize_queues(VkSurfaceKHR surface) {
// supported format will be returned.
if (formatCount == 1 && surfFormats[0].format == VK_FORMAT_UNDEFINED) {
format = VK_FORMAT_B8G8R8A8_UNORM;
color_space = surfFormats[0].colorSpace;
} else {
// These should be ordered with the ones we want to use on top and fallback modes further down
// we want an 32bit RGBA unsigned normalised buffer or similar
const VkFormat allowed_formats[] = {
VK_FORMAT_B8G8R8A8_UNORM,
VK_FORMAT_R8G8B8A8_UNORM
};
uint32_t allowed_formats_count = sizeof(allowed_formats) / sizeof(VkFormat);
if (formatCount < 1) {
free(surfFormats);
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "formatCount less than 1");
}
format = surfFormats[0].format;
// Find the first format that we support
format = VK_FORMAT_UNDEFINED;
for (uint32_t af = 0; af < allowed_formats_count && format == VK_FORMAT_UNDEFINED; af++) {
for (uint32_t sf = 0; sf < formatCount && format == VK_FORMAT_UNDEFINED; sf++) {
if (surfFormats[sf].format == allowed_formats[af]) {
format = surfFormats[sf].format;
color_space = surfFormats[sf].colorSpace;
}
}
}
if (format == VK_FORMAT_UNDEFINED) {
free(surfFormats);
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "No usable surface format found.");
}
}
color_space = surfFormats[0].colorSpace;
free(surfFormats);