WIP: Vulkan: Workbench #107886

Closed
Jeroen Bakker wants to merge 88 commits from Jeroen-Bakker:vulkan-draw-manager-workbench into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 62 additions and 8 deletions
Showing only changes of commit 4b39e6b258 - Show all commits

View File

@ -30,7 +30,17 @@
/* Set to 0 to allow devices that do not have the required features.
* This allows development on OSX until we really needs these features. */
#define STRICT_REQUIREMENTS 1
#define STRICT_REQUIREMENTS true
/*
* Should we only select surfaces that are known to be compatible. Or should we in case no
* compatible surfaces have been found select the first one.
*
* Currently we also select incompatible surfaces as Vulkan is still experimental. Assuming we get
* reports of color differences between OpenGL and Vulkan to narrow down if there are other
* configurations we need to support.
*/
#define SELECT_COMPATIBLE_SURFACES false
using namespace std;
@ -796,6 +806,49 @@ GHOST_TSuccess GHOST_ContextVK::createGraphicsCommandBuffers()
return GHOST_kSuccess;
}
static bool surfaceFormatSupported(const VkSurfaceFormatKHR &surface_format)
{
if (surface_format.colorSpace != VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
return false;
}
if (surface_format.format == VK_FORMAT_R8G8B8A8_UNORM ||
surface_format.format == VK_FORMAT_B8G8R8A8_UNORM)
{
return true;
}
return false;
}
/**
* Select the surface format that we will use.
*
* We will select any 8bit unorm surface.
*/
static bool selectSurfaceFormat(const VkPhysicalDevice physical_device,
const VkSurfaceKHR surface,
VkSurfaceFormatKHR &r_surfaceFormat)
{
uint32_t format_count;
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &format_count, NULL);
vector<VkSurfaceFormatKHR> formats(format_count);
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &format_count, formats.data());
for (VkSurfaceFormatKHR &format : formats) {
if (surfaceFormatSupported(format)) {
r_surfaceFormat = format;
return true;
}
}
#if !SELECT_COMPATIBLE_SURFACES
r_surfaceFormat = formats[0];
#endif
return false;
}
GHOST_TSuccess GHOST_ContextVK::createSwapchain()
{
assert(vulkan_device.has_value() && vulkan_device->device != VK_NULL_HANDLE);
@ -803,13 +856,14 @@ GHOST_TSuccess GHOST_ContextVK::createSwapchain()
VkPhysicalDevice physical_device = vulkan_device->physical_device;
uint32_t format_count;
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, m_surface, &format_count, NULL);
vector<VkSurfaceFormatKHR> formats(format_count);
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, m_surface, &format_count, formats.data());
/* TODO choose appropriate format. */
VkSurfaceFormatKHR format = formats[0];
VkSurfaceFormatKHR format = {};
#if SELECT_COMPATIBLE_SURFACES
if (!selectSurfaceFormat(physical_device, m_surface, format)) {
return GHOST_kFailure;
}
#else
selectSurfaceFormat(physical_device, m_surface, format);
#endif
VkPresentModeKHR present_mode;
if (!selectPresentMode(physical_device, m_surface, &present_mode)) {