1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2016 Intel Corporation 3bf215546Sopenharmony_ci * Copyright © 2019 Google LLC 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#ifndef U_FORMAT_VK_H 26bf215546Sopenharmony_ci#define U_FORMAT_VK_H 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include <vulkan/vulkan_core.h> 29bf215546Sopenharmony_ci#include "util/format/u_format.h" 30bf215546Sopenharmony_ci#include "util/u_math.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#ifdef __cplusplus 33bf215546Sopenharmony_ciextern "C" { 34bf215546Sopenharmony_ci#endif 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_cienum pipe_format 37bf215546Sopenharmony_civk_format_to_pipe_format(enum VkFormat vkformat); 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ciVkImageAspectFlags 40bf215546Sopenharmony_civk_format_aspects(VkFormat format); 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cistatic inline bool 43bf215546Sopenharmony_civk_format_is_color(VkFormat format) 44bf215546Sopenharmony_ci{ 45bf215546Sopenharmony_ci return vk_format_aspects(format) == VK_IMAGE_ASPECT_COLOR_BIT; 46bf215546Sopenharmony_ci} 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistatic inline bool 49bf215546Sopenharmony_civk_format_is_depth_or_stencil(VkFormat format) 50bf215546Sopenharmony_ci{ 51bf215546Sopenharmony_ci const VkImageAspectFlags aspects = vk_format_aspects(format); 52bf215546Sopenharmony_ci return aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); 53bf215546Sopenharmony_ci} 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_cistatic inline bool 56bf215546Sopenharmony_civk_format_has_depth(VkFormat format) 57bf215546Sopenharmony_ci{ 58bf215546Sopenharmony_ci const VkImageAspectFlags aspects = vk_format_aspects(format); 59bf215546Sopenharmony_ci return aspects & VK_IMAGE_ASPECT_DEPTH_BIT; 60bf215546Sopenharmony_ci} 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_cistatic inline bool 63bf215546Sopenharmony_civk_format_has_stencil(VkFormat format) 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci const VkImageAspectFlags aspects = vk_format_aspects(format); 66bf215546Sopenharmony_ci return aspects & VK_IMAGE_ASPECT_STENCIL_BIT; 67bf215546Sopenharmony_ci} 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_cistatic inline VkFormat 70bf215546Sopenharmony_civk_format_depth_only(VkFormat format) 71bf215546Sopenharmony_ci{ 72bf215546Sopenharmony_ci assert(vk_format_has_depth(format)); 73bf215546Sopenharmony_ci switch (format) { 74bf215546Sopenharmony_ci case VK_FORMAT_D16_UNORM_S8_UINT: 75bf215546Sopenharmony_ci return VK_FORMAT_D16_UNORM; 76bf215546Sopenharmony_ci case VK_FORMAT_D24_UNORM_S8_UINT: 77bf215546Sopenharmony_ci return VK_FORMAT_X8_D24_UNORM_PACK32; 78bf215546Sopenharmony_ci case VK_FORMAT_D32_SFLOAT_S8_UINT: 79bf215546Sopenharmony_ci return VK_FORMAT_D32_SFLOAT; 80bf215546Sopenharmony_ci default: 81bf215546Sopenharmony_ci return format; 82bf215546Sopenharmony_ci } 83bf215546Sopenharmony_ci} 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_cistatic inline VkFormat 86bf215546Sopenharmony_civk_format_stencil_only(VkFormat format) 87bf215546Sopenharmony_ci{ 88bf215546Sopenharmony_ci assert(vk_format_has_stencil(format)); 89bf215546Sopenharmony_ci return VK_FORMAT_S8_UINT; 90bf215546Sopenharmony_ci} 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_civoid vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping, 93bf215546Sopenharmony_ci unsigned char out_swizzle[4]); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_cistatic inline bool 96bf215546Sopenharmony_civk_format_is_int(VkFormat format) 97bf215546Sopenharmony_ci{ 98bf215546Sopenharmony_ci return util_format_is_pure_integer(vk_format_to_pipe_format(format)); 99bf215546Sopenharmony_ci} 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_cistatic inline bool 102bf215546Sopenharmony_civk_format_is_sint(VkFormat format) 103bf215546Sopenharmony_ci{ 104bf215546Sopenharmony_ci return util_format_is_pure_sint(vk_format_to_pipe_format(format)); 105bf215546Sopenharmony_ci} 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_cistatic inline bool 108bf215546Sopenharmony_civk_format_is_uint(VkFormat format) 109bf215546Sopenharmony_ci{ 110bf215546Sopenharmony_ci return util_format_is_pure_uint(vk_format_to_pipe_format(format)); 111bf215546Sopenharmony_ci} 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_cistatic inline bool 114bf215546Sopenharmony_civk_format_is_unorm(VkFormat format) 115bf215546Sopenharmony_ci{ 116bf215546Sopenharmony_ci return util_format_is_unorm(vk_format_to_pipe_format(format)); 117bf215546Sopenharmony_ci} 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_cistatic inline bool 120bf215546Sopenharmony_civk_format_is_snorm(VkFormat format) 121bf215546Sopenharmony_ci{ 122bf215546Sopenharmony_ci return util_format_is_snorm(vk_format_to_pipe_format(format)); 123bf215546Sopenharmony_ci} 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_cistatic inline bool 126bf215546Sopenharmony_civk_format_is_float(VkFormat format) 127bf215546Sopenharmony_ci{ 128bf215546Sopenharmony_ci return util_format_is_float(vk_format_to_pipe_format(format)); 129bf215546Sopenharmony_ci} 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_cistatic inline bool 132bf215546Sopenharmony_civk_format_is_srgb(VkFormat format) 133bf215546Sopenharmony_ci{ 134bf215546Sopenharmony_ci return util_format_is_srgb(vk_format_to_pipe_format(format)); 135bf215546Sopenharmony_ci} 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_cistatic inline unsigned 138bf215546Sopenharmony_civk_format_get_blocksize(VkFormat format) 139bf215546Sopenharmony_ci{ 140bf215546Sopenharmony_ci return util_format_get_blocksize(vk_format_to_pipe_format(format)); 141bf215546Sopenharmony_ci} 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_cistatic inline unsigned 144bf215546Sopenharmony_civk_format_get_blockwidth(VkFormat format) 145bf215546Sopenharmony_ci{ 146bf215546Sopenharmony_ci return util_format_get_blockwidth(vk_format_to_pipe_format(format)); 147bf215546Sopenharmony_ci} 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_cistatic inline unsigned 150bf215546Sopenharmony_civk_format_get_blockheight(VkFormat format) 151bf215546Sopenharmony_ci{ 152bf215546Sopenharmony_ci return util_format_get_blockheight(vk_format_to_pipe_format(format)); 153bf215546Sopenharmony_ci} 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_cistatic inline bool 156bf215546Sopenharmony_civk_format_is_compressed(VkFormat format) 157bf215546Sopenharmony_ci{ 158bf215546Sopenharmony_ci /* this includes 4:2:2 formats, which are compressed formats for vulkan */ 159bf215546Sopenharmony_ci return vk_format_get_blockwidth(format) > 1; 160bf215546Sopenharmony_ci} 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_cistatic inline const struct util_format_description * 163bf215546Sopenharmony_civk_format_description(VkFormat format) 164bf215546Sopenharmony_ci{ 165bf215546Sopenharmony_ci return util_format_description(vk_format_to_pipe_format(format)); 166bf215546Sopenharmony_ci} 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_cistatic inline unsigned 169bf215546Sopenharmony_civk_format_get_component_bits(VkFormat format, enum util_format_colorspace colorspace, 170bf215546Sopenharmony_ci unsigned component) 171bf215546Sopenharmony_ci{ 172bf215546Sopenharmony_ci return util_format_get_component_bits(vk_format_to_pipe_format(format), 173bf215546Sopenharmony_ci colorspace, 174bf215546Sopenharmony_ci component); 175bf215546Sopenharmony_ci} 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_cistatic inline unsigned 178bf215546Sopenharmony_civk_format_get_nr_components(VkFormat format) 179bf215546Sopenharmony_ci{ 180bf215546Sopenharmony_ci return util_format_get_nr_components(vk_format_to_pipe_format(format)); 181bf215546Sopenharmony_ci} 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_cistatic inline bool 184bf215546Sopenharmony_civk_format_has_alpha(VkFormat format) 185bf215546Sopenharmony_ci{ 186bf215546Sopenharmony_ci return util_format_has_alpha(vk_format_to_pipe_format(format)); 187bf215546Sopenharmony_ci} 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_cistatic inline unsigned 190bf215546Sopenharmony_civk_format_get_blocksizebits(VkFormat format) 191bf215546Sopenharmony_ci{ 192bf215546Sopenharmony_ci return util_format_get_blocksizebits(vk_format_to_pipe_format(format)); 193bf215546Sopenharmony_ci} 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_cistatic inline unsigned 196bf215546Sopenharmony_civk_format_get_plane_count(VkFormat format) 197bf215546Sopenharmony_ci{ 198bf215546Sopenharmony_ci return util_format_get_num_planes(vk_format_to_pipe_format(format)); 199bf215546Sopenharmony_ci} 200bf215546Sopenharmony_ci 201bf215546Sopenharmony_ciVkFormat 202bf215546Sopenharmony_civk_format_get_plane_format(VkFormat format, unsigned plane_id); 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ciVkFormat 205bf215546Sopenharmony_civk_format_get_aspect_format(VkFormat format, const VkImageAspectFlags aspect); 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci#ifdef __cplusplus 208bf215546Sopenharmony_ci} 209bf215546Sopenharmony_ci#endif 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_ci#endif 212