1/*
2 * Copyright © 2016 Intel Corporation
3 * Copyright © 2019 Google LLC
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef U_FORMAT_VK_H
26#define U_FORMAT_VK_H
27
28#include <vulkan/vulkan_core.h>
29#include "util/format/u_format.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35enum pipe_format
36vk_format_to_pipe_format(enum VkFormat vkformat);
37
38VkImageAspectFlags
39vk_format_aspects(VkFormat format);
40
41static inline bool
42vk_format_is_color(VkFormat format)
43{
44   return vk_format_aspects(format) == VK_IMAGE_ASPECT_COLOR_BIT;
45}
46
47static inline bool
48vk_format_is_depth_or_stencil(VkFormat format)
49{
50   const VkImageAspectFlags aspects = vk_format_aspects(format);
51   return aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
52}
53
54static inline bool
55vk_format_has_depth(VkFormat format)
56{
57   const VkImageAspectFlags aspects = vk_format_aspects(format);
58   return aspects & VK_IMAGE_ASPECT_DEPTH_BIT;
59}
60
61static inline bool
62vk_format_has_stencil(VkFormat format)
63{
64   const VkImageAspectFlags aspects = vk_format_aspects(format);
65   return aspects & VK_IMAGE_ASPECT_STENCIL_BIT;
66}
67
68static inline VkFormat
69vk_format_depth_only(VkFormat format)
70{
71   assert(vk_format_has_depth(format));
72   switch (format) {
73   case VK_FORMAT_D16_UNORM_S8_UINT:
74      return VK_FORMAT_D16_UNORM;
75   case VK_FORMAT_D24_UNORM_S8_UINT:
76      return VK_FORMAT_X8_D24_UNORM_PACK32;
77   case VK_FORMAT_D32_SFLOAT_S8_UINT:
78      return VK_FORMAT_D32_SFLOAT;
79   default:
80      return format;
81   }
82}
83
84static inline VkFormat
85vk_format_stencil_only(VkFormat format)
86{
87   assert(vk_format_has_stencil(format));
88   return VK_FORMAT_S8_UINT;
89}
90
91#ifdef __cplusplus
92}
93#endif
94
95#endif
96