diff options
| author | Charles Giessen <charles@lunarg.com> | 2022-02-03 13:55:48 -0700 |
|---|---|---|
| committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2022-03-21 10:51:05 -0600 |
| commit | 7dc2dd560cd0fe02b748c19f22b1d37a9ad28bee (patch) | |
| tree | 9fcf7b791fd326b3ac308bcc9e2e2dbbeb224dfc | |
| parent | 87dd88d2bdc0f212abb66baf185cea0a0d45c2c1 (diff) | |
| download | usermoji-7dc2dd560cd0fe02b748c19f22b1d37a9ad28bee.tar.xz | |
cubepp: Copy cubes swapchain format selection
The differing logic led to vkcube choosing a different swapchain image format
to vkcubepp.
| -rw-r--r-- | cube/cube.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/cube/cube.cpp b/cube/cube.cpp index d72778ba..9001ad5e 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -246,6 +246,7 @@ struct Demo { void update_data_buffer(); bool loadTexture(const char *filename, uint8_t *rgba_data, vk::SubresourceLayout &layout, int32_t &width, int32_t &height); bool memory_type_from_properties(uint32_t typeBits, vk::MemoryPropertyFlags requirements_mask, uint32_t &typeIndex); + vk::SurfaceFormatKHR pick_surface_format(const std::vector<vk::SurfaceFormatKHR> &surface_formats); #if defined(VK_USE_PLATFORM_WIN32_KHR) void run(); @@ -1378,18 +1379,10 @@ void Demo::init_vk_swapchain() { // Get the list of VkFormat's that are supported: auto surface_formats_return = gpu.getSurfaceFormatsKHR(surface); VERIFY(surface_formats_return.result == vk::Result::eSuccess); - auto surface_formats = surface_formats_return.value; - // If the format list includes just one entry of VK_FORMAT_UNDEFINED, - // the surface has no preferred format. Otherwise, at least one - // supported format will be returned. - if (surface_formats.size() == 1 && surface_formats[0].format == vk::Format::eUndefined) { - format = vk::Format::eB8G8R8A8Unorm; - } else { - assert(surface_formats.size() >= 1); - format = surface_formats[0].format; - } - color_space = surface_formats[0].colorSpace; + vk::SurfaceFormatKHR surfaceFormat = pick_surface_format(surface_formats_return.value); + format = surfaceFormat.format; + color_space = surfaceFormat.colorSpace; quit = false; curFrame = 0; @@ -2356,6 +2349,24 @@ bool Demo::memory_type_from_properties(uint32_t typeBits, vk::MemoryPropertyFlag return false; } +vk::SurfaceFormatKHR Demo::pick_surface_format(const std::vector<vk::SurfaceFormatKHR> &surface_formats) { + // Prefer non-SRGB formats... + for (const auto &surface_format : surface_formats) { + const vk::Format format = surface_format.format; + + if (format == vk::Format::eR8G8B8A8Unorm || format == vk::Format::eB8G8R8A8Unorm || + format == vk::Format::eA2B10G10R10UnormPack32 || format == vk::Format::eA2R10G10B10UnormPack32 || + format == vk::Format::eR16G16B16A16Sfloat) { + return surface_format; + } + } + + printf("Can't find our preferred formats... Falling back to first exposed format. Rendering may be incorrect.\n"); + + assert(surface_formats.size() >= 1); + return surface_formats[0]; +} + #if defined(VK_USE_PLATFORM_WIN32_KHR) void Demo::run() { if (!prepared) { |
