Home | History | Annotate | Download | only in layers
      1 /* Copyright (c) 2015-2016 The Khronos Group Inc.
      2  * Copyright (c) 2015-2016 Valve Corporation
      3  * Copyright (c) 2015-2016 LunarG, Inc.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a copy
      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:
     11  *
     12  * The above copyright notice(s) and this permission notice shall be included
     13  * in all copies or substantial portions of the Materials.
     14  *
     15  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     18  *
     19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
     20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
     22  * USE OR OTHER DEALINGS IN THE MATERIALS
     23  *
     24  * Author: Mark Lobodzinski <mark (at) lunarg.com>
     25  * Author: Courtney Goeltzenleuchter <courtney (at) LunarG.com>
     26  */
     27 
     28 #pragma once
     29 #include <stdbool.h>
     30 #include <vector>
     31 #include "vk_layer_logging.h"
     32 
     33 #ifndef WIN32
     34 #include <strings.h> /* for ffs() */
     35 #else
     36 #include <intrin.h> /* for __lzcnt() */
     37 #endif
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif
     42 
     43 #define VK_LAYER_API_VERSION (VK_VERSION_MAJOR(1) | VK_VERSION_MINOR(0) | VK_VERSION_PATCH(VK_HEADER_VERSION))
     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 typedef enum VkStringErrorFlagBits {
     94     VK_STRING_ERROR_NONE = 0x00000000,
     95     VK_STRING_ERROR_LENGTH = 0x00000001,
     96     VK_STRING_ERROR_BAD_DATA = 0x00000002,
     97 } VkStringErrorFlagBits;
     98 typedef VkFlags VkStringErrorFlags;
     99 
    100 void layer_debug_actions(debug_report_data* report_data, std::vector<VkDebugReportCallbackEXT> &logging_callback,
    101     const VkAllocationCallbacks *pAllocator, const char* layer_identifier);
    102 
    103 static inline bool vk_format_is_undef(VkFormat format) { return (format == VK_FORMAT_UNDEFINED); }
    104 
    105 bool vk_format_is_depth_or_stencil(VkFormat format);
    106 bool vk_format_is_depth_and_stencil(VkFormat format);
    107 bool vk_format_is_depth_only(VkFormat format);
    108 bool vk_format_is_stencil_only(VkFormat format);
    109 
    110 static inline bool vk_format_is_color(VkFormat format) {
    111     return !(vk_format_is_undef(format) || vk_format_is_depth_or_stencil(format));
    112 }
    113 
    114 bool vk_format_is_norm(VkFormat format);
    115 bool vk_format_is_int(VkFormat format);
    116 bool vk_format_is_sint(VkFormat format);
    117 bool vk_format_is_uint(VkFormat format);
    118 bool vk_format_is_float(VkFormat format);
    119 bool vk_format_is_srgb(VkFormat format);
    120 bool vk_format_is_compressed(VkFormat format);
    121 size_t vk_format_get_size(VkFormat format);
    122 unsigned int vk_format_get_channel_count(VkFormat format);
    123 VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format);
    124 VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor);
    125 VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
    126 
    127 static inline int u_ffs(int val) {
    128 #ifdef WIN32
    129     unsigned long bit_pos = 0;
    130     if (_BitScanForward(&bit_pos, val) != 0) {
    131         bit_pos += 1;
    132     }
    133     return bit_pos;
    134 #else
    135     return ffs(val);
    136 #endif
    137 }
    138 
    139 #ifdef __cplusplus
    140 }
    141 #endif
    142