2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * Based on u_format.h which is:
6 * Copyright 2009-2010 Vmware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
31 #include <util/macros.h>
32 #include <util/format/u_format.h>
33 #include <vulkan/util/vk_format.h>
35 #include <vulkan/vulkan.h>
37 static inline const struct util_format_description
*
38 vk_format_description(VkFormat format
)
40 return util_format_description(vk_format_to_pipe_format(format
));
44 * Return bytes per block (not pixel) for the given format.
46 static inline unsigned
47 vk_format_get_blocksize(VkFormat format
)
49 return util_format_get_blocksize(vk_format_to_pipe_format(format
));
52 static inline unsigned
53 vk_format_get_blockwidth(VkFormat format
)
55 return util_format_get_blockwidth(vk_format_to_pipe_format(format
));
58 static inline unsigned
59 vk_format_get_blockheight(VkFormat format
)
61 return util_format_get_blockheight(vk_format_to_pipe_format(format
));
65 vk_format_is_compressed(VkFormat format
)
67 /* this includes 4:2:2 formats, which are compressed formats for vulkan */
68 return vk_format_get_blockwidth(format
) > 1;
72 vk_format_is_depth_or_stencil(VkFormat format
)
74 const struct util_format_description
*desc
= vk_format_description(format
);
76 return util_format_has_depth(desc
) || util_format_has_stencil(desc
);
80 vk_format_has_alpha(VkFormat format
)
82 return util_format_has_alpha(vk_format_to_pipe_format(format
));
86 vk_format_is_int(VkFormat format
)
88 return util_format_is_pure_integer(vk_format_to_pipe_format(format
));
92 vk_format_is_uint(VkFormat format
)
94 return util_format_is_pure_uint(vk_format_to_pipe_format(format
));
98 vk_format_is_sint(VkFormat format
)
100 return util_format_is_pure_sint(vk_format_to_pipe_format(format
));
104 vk_format_is_srgb(VkFormat format
)
106 return util_format_is_srgb(vk_format_to_pipe_format(format
));
110 vk_format_is_unorm(VkFormat format
)
112 return util_format_is_unorm(vk_format_to_pipe_format(format
));
116 vk_format_is_snorm(VkFormat format
)
118 return util_format_is_snorm(vk_format_to_pipe_format(format
));
122 vk_format_is_float(VkFormat format
)
124 return util_format_is_float(vk_format_to_pipe_format(format
));
127 static inline unsigned
128 vk_format_get_component_bits(VkFormat format
,
129 enum util_format_colorspace colorspace
,
133 case VK_FORMAT_G8B8G8R8_422_UNORM
:
134 case VK_FORMAT_B8G8R8G8_422_UNORM
:
135 /* util_format_get_component_bits doesn't return what we want */
141 return util_format_get_component_bits(vk_format_to_pipe_format(format
),
142 colorspace
, component
);
145 static inline unsigned
146 vk_format_get_nr_components(VkFormat format
)
148 return util_format_get_nr_components(vk_format_to_pipe_format(format
));
151 #endif /* VK_FORMAT_H */