Skip to content

Commit aa9e886

Browse files
committed
vulkan: format_info: do not use std::array
The metadata array was actually positionally indexed, which was error prone. Use rather switch - the advantage is that also a warning is issued if some enum member not handled and also solves the above.
1 parent dec438c commit aa9e886

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

src/video_display/vulkan/vulkan_transfer_image.hpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Bela <492789@mail.muni.cz>
44
*/
55
/*
6-
* Copyright (c) 2021-2023 CESNET, z. s. p. o.
6+
* Copyright (c) 2021-2025 CESNET, zajmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -61,7 +61,6 @@ struct ImageDescription;
6161
namespace vulkan_display_detail {
6262

6363
struct FormatInfo{
64-
vulkan_display::Format format;
6564
vk::Format buffer_format;
6665
std::string conversion_shader = "";
6766
vk::Format conversion_image_format{};
@@ -72,22 +71,29 @@ inline const FormatInfo& format_info(vulkan_display::Format format){
7271
using F = vulkan_display::Format;
7372
using VkF = vk::Format;
7473

75-
static std::array<FormatInfo, 11> format_infos = {{
76-
{F::uninitialized, VkF::eUndefined, },
77-
{F::RGBA8, VkF::eR8G8B8A8Unorm, },
78-
{F::RGB8, VkF::eR8G8B8Srgb, },
79-
{F::UYVY8_422, VkF::eB8G8R8G8422Unorm, },
80-
{F::UYVY8_422_conv, VkF::eR8G8B8A8Unorm, {"UYVY8_conv"}, VkF::eR8G8B8A8Unorm},
81-
{F::YUYV8_422, VkF::eG8B8G8R8422Unorm, },
82-
{F::YUYV16_422, VkF::eG16B16G16R16422Unorm, },
83-
{F::UYVA16_422_conv, VkF::eR16G16B16A16Uint, {"UYVA16_conv"}, VkF::eR16G16B16A16Sfloat},
84-
{F::RGB10A2_conv, VkF::eR8G8B8A8Uint, {"RGB10A2_conv"}, VkF::eA2B10G10R10UnormPack32},
85-
{F::RGB16, VkF::eR16G16B16Unorm },
86-
}};
87-
88-
auto& result = format_infos[static_cast<size_t>(format)];
89-
assert(result.format == format);
90-
return result;
74+
static FormatInfo uninitialized = { VkF::eUndefined, };
75+
static FormatInfo RGBA8 = { VkF::eR8G8B8A8Unorm, };
76+
static FormatInfo RGB8 = { VkF::eR8G8B8Srgb, };
77+
static FormatInfo UYVY8_422 = { VkF::eB8G8R8G8422Unorm, };
78+
static FormatInfo UYVY8_422_conv = { VkF::eR8G8B8A8Unorm, {"UYVY8_conv"}, VkF::eR8G8B8A8Unorm};
79+
static FormatInfo YUYV8_422 = { VkF::eG8B8G8R8422Unorm, };
80+
static FormatInfo YUYV16_422 = { VkF::eG16B16G16R16422Unorm, };
81+
static FormatInfo UYVA16_422_conv = { VkF::eR16G16B16A16Uint, {"UYVA16_conv"}, VkF::eR16G16B16A16Sfloat};
82+
static FormatInfo RGB10A2_conv = { VkF::eR8G8B8A8Uint, {"RGB10A2_conv"}, VkF::eA2B10G10R10UnormPack32};
83+
static FormatInfo RGB16 = { VkF::eR16G16B16Unorm };
84+
switch (format) {
85+
case F::uninitialized: return uninitialized;
86+
case F::RGBA8: return RGBA8;
87+
case F::RGB8: return RGB8;
88+
case F::UYVY8_422: return UYVY8_422;
89+
case F::UYVY8_422_conv: return UYVY8_422_conv;
90+
case F::YUYV8_422: return YUYV8_422;
91+
case F::YUYV16_422: return YUYV16_422;
92+
case F::UYVA16_422_conv: return UYVA16_422_conv;
93+
case F::RGB10A2_conv: return RGB10A2_conv;
94+
case F::RGB16: return RGB16;
95+
};
96+
abort();
9197
}
9298

9399
vk::Extent2D get_buffer_size(const vulkan_display::ImageDescription& description);

0 commit comments

Comments
 (0)