Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame^] | 6 | * of this software and/or associated documentation files (the "Materials"), to |
| 7 | * deal in the Materials without restriction, including without limitation the |
| 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | * sell copies of the Materials, and to permit persons to whom the Materials |
| 10 | * are furnished to do so, subject to the following conditions: |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame^] | 12 | * The above copyright notice(s) and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Materials. |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 14 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame^] | 15 | * The Materials are Confidential Information as defined by the Khronos |
| 16 | * Membership Agreement until designated non-confidential by Khronos, at which |
| 17 | * point this condition clause shall be removed. |
| 18 | * |
| 19 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame^] | 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 22 | * |
| 23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 24 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 25 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 26 | * USE OR OTHER DEALINGS IN THE MATERIALS |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 27 | * |
Jon Ashburn | e922f71 | 2015-11-03 13:41:23 -0700 | [diff] [blame] | 28 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 29 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame^] | 30 | */ |
| 31 | |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 32 | #pragma once |
| 33 | #include <stdbool.h> |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 34 | #ifndef WIN32 |
| 35 | #include <strings.h> /* for ffs() */ |
Courtney Goeltzenleuchter | 3698c62 | 2015-10-27 11:23:21 -0600 | [diff] [blame] | 36 | #else |
| 37 | #include <intrin.h> /* for __lzcnt() */ |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 38 | #endif |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
Mark Lobodzinski | adaac9d | 2016-01-08 11:07:56 -0700 | [diff] [blame] | 44 | typedef enum VkFormatCompatibilityClass { |
| 45 | VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT = 0, |
| 46 | VK_FORMAT_COMPATIBILITY_CLASS_8_BIT = 1, |
| 47 | VK_FORMAT_COMPATIBILITY_CLASS_16_BIT = 2, |
| 48 | VK_FORMAT_COMPATIBILITY_CLASS_24_BIT = 3, |
| 49 | VK_FORMAT_COMPATIBILITY_CLASS_32_BIT = 4, |
| 50 | VK_FORMAT_COMPATIBILITY_CLASS_48_BIT = 5, |
| 51 | VK_FORMAT_COMPATIBILITY_CLASS_64_BIT = 6, |
| 52 | VK_FORMAT_COMPATIBILITY_CLASS_96_BIT = 7, |
| 53 | VK_FORMAT_COMPATIBILITY_CLASS_128_BIT = 8, |
| 54 | VK_FORMAT_COMPATIBILITY_CLASS_192_BIT = 9, |
| 55 | VK_FORMAT_COMPATIBILITY_CLASS_256_BIT = 10, |
| 56 | VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT = 11, |
| 57 | VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT = 12, |
| 58 | VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT = 13, |
| 59 | VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT = 14, |
| 60 | VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT = 15, |
| 61 | VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT = 16, |
| 62 | VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT = 17, |
| 63 | VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT = 18, |
| 64 | VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT = 19, |
| 65 | VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT = 20, |
| 66 | VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT = 21, |
| 67 | VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT = 22, |
| 68 | VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT = 23, |
| 69 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT = 24, |
| 70 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT = 25, |
| 71 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT = 26, |
| 72 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT = 27, |
| 73 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT = 28, |
| 74 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT = 29, |
| 75 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT = 20, |
| 76 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT = 31, |
| 77 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT = 32, |
| 78 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT = 33, |
| 79 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT = 34, |
| 80 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT = 35, |
| 81 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT = 36, |
| 82 | VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT = 37, |
| 83 | VK_FORMAT_COMPATIBILITY_CLASS_D16_BIT = 38, |
| 84 | VK_FORMAT_COMPATIBILITY_CLASS_D24_BIT = 39, |
| 85 | VK_FORMAT_COMPATIBILITY_CLASS_D32_BIT = 30, |
| 86 | VK_FORMAT_COMPATIBILITY_CLASS_S8_BIT = 41, |
| 87 | VK_FORMAT_COMPATIBILITY_CLASS_D16S8_BIT = 42, |
| 88 | VK_FORMAT_COMPATIBILITY_CLASS_D24S8_BIT = 43, |
| 89 | VK_FORMAT_COMPATIBILITY_CLASS_D32S8_BIT = 44, |
| 90 | VK_FORMAT_COMPATIBILITY_CLASS_MAX_ENUM = 45 |
| 91 | } VkFormatCompatibilityClass; |
| 92 | |
| 93 | |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 94 | static inline bool vk_format_is_undef(VkFormat format) |
| 95 | { |
| 96 | return (format == VK_FORMAT_UNDEFINED); |
| 97 | } |
| 98 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 99 | bool vk_format_is_depth_or_stencil(VkFormat format); |
| 100 | bool vk_format_is_depth_and_stencil(VkFormat format); |
| 101 | bool vk_format_is_depth_only(VkFormat format); |
| 102 | bool vk_format_is_stencil_only(VkFormat format); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 103 | |
| 104 | static inline bool vk_format_is_color(VkFormat format) |
| 105 | { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 106 | return !(vk_format_is_undef(format) || vk_format_is_depth_or_stencil(format)); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Mark Lobodzinski | adaac9d | 2016-01-08 11:07:56 -0700 | [diff] [blame] | 109 | bool vk_format_is_norm(VkFormat format); |
| 110 | bool vk_format_is_int(VkFormat format); |
| 111 | bool vk_format_is_sint(VkFormat format); |
| 112 | bool vk_format_is_uint(VkFormat format); |
| 113 | bool vk_format_is_float(VkFormat format); |
| 114 | bool vk_format_is_srgb(VkFormat format); |
| 115 | bool vk_format_is_compressed(VkFormat format); |
| 116 | size_t vk_format_get_size(VkFormat format); |
| 117 | unsigned int vk_format_get_channel_count(VkFormat format); |
| 118 | VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format); |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 119 | VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 120 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 121 | static inline int u_ffs(int val) |
| 122 | { |
| 123 | #ifdef WIN32 |
Mark Lobodzinski | 5ddf6c3 | 2015-12-16 17:47:28 -0700 | [diff] [blame] | 124 | unsigned long bit_pos = 0; |
Mike Stroyan | debb984 | 2016-01-07 10:05:21 -0700 | [diff] [blame] | 125 | if (_BitScanForward(&bit_pos, val) != 0) { |
Mark Lobodzinski | 5ddf6c3 | 2015-12-16 17:47:28 -0700 | [diff] [blame] | 126 | bit_pos += 1; |
| 127 | } |
| 128 | return bit_pos; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 129 | #else |
Mark Lobodzinski | 5ddf6c3 | 2015-12-16 17:47:28 -0700 | [diff] [blame] | 130 | return ffs(val); |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 131 | #endif |
| 132 | } |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 133 | |
| 134 | #ifdef __cplusplus |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | |