1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * based in part on radv driver which is:
5 * Copyright © 2016 Red Hat.
6 * Copyright © 2016 Bas Nieuwenhuizen
7 *
8 * Based on u_format.h which is:
9 * Copyright 2009-2010 VMware, Inc.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 */
30
31 #ifndef VK_FORMAT_H
32 #define VK_FORMAT_H
33
34 #include <stdbool.h>
35 #include <util/format/u_format.h>
36 #include <vulkan/util/vk_format.h>
37
38 #include <vulkan/vulkan.h>
39
40 #include "util/u_endian.h"
41
vk_format_is_alpha_on_msb(VkFormat vk_format)42 static inline bool vk_format_is_alpha_on_msb(VkFormat vk_format)
43 {
44 const struct util_format_description *desc =
45 vk_format_description(vk_format);
46
47 return (desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB ||
48 desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) &&
49 #if UTIL_ARCH_BIG_ENDIAN
50 desc->swizzle[3] == PIPE_SWIZZLE_X;
51 #else
52 desc->swizzle[3] == PIPE_SWIZZLE_W;
53 #endif
54 }
55
vk_format_get_channel_width(VkFormat vk_format,uint32_t channel)56 static inline uint vk_format_get_channel_width(VkFormat vk_format,
57 uint32_t channel)
58 {
59 const struct util_format_description *desc =
60 vk_format_description(vk_format);
61
62 return desc->channel[channel].size;
63 }
64
vk_format_has_32bit_component(VkFormat vk_format)65 static inline bool vk_format_has_32bit_component(VkFormat vk_format)
66 {
67 const struct util_format_description *desc =
68 vk_format_description(vk_format);
69
70 for (uint32_t i = 0; i < desc->nr_channels; i++) {
71 if (desc->channel[i].size == 32U)
72 return true;
73 }
74
75 return false;
76 }
77
vk_format_is_normalized(VkFormat vk_format)78 static inline bool vk_format_is_normalized(VkFormat vk_format)
79 {
80 const struct util_format_description *desc =
81 vk_format_description(vk_format);
82
83 for (uint32_t i = 0; i < desc->nr_channels; i++) {
84 if (!desc->channel[i].normalized)
85 return false;
86 }
87
88 return true;
89 }
90
91 #endif /* VK_FORMAT_H */
92