blob: 98107ff17d661511313a38fc8b0d9e7b02d0ce82 [file] [log] [blame]
Dave Houlton59a20702017-02-02 17:26:23 -07001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016 *
Jon Ashburne922f712015-11-03 13:41:23 -070017 * Author: Mark Lobodzinski <mark@lunarg.com>
18 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Dave Houlton59a20702017-02-02 17:26:23 -070019 * Author: Dave Houlton <daveh@lunarg.com>
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070020 */
21
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060022#pragma once
23#include <stdbool.h>
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -060024#include <vector>
25#include "vk_layer_logging.h"
26
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060027#ifndef WIN32
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070028#include <strings.h> // For ffs()
Courtney Goeltzenleuchter3698c622015-10-27 11:23:21 -060029#else
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070030#include <intrin.h> // For __lzcnt()
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060031#endif
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060032
33#ifdef __cplusplus
34extern "C" {
35#endif
36
Jon Ashburnd883d812016-03-24 08:32:09 -060037#define VK_LAYER_API_VERSION VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION)
Mark Lobodzinskiadaac9d2016-01-08 11:07:56 -070038typedef enum VkFormatCompatibilityClass {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070039 VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT = 0,
40 VK_FORMAT_COMPATIBILITY_CLASS_8_BIT = 1,
41 VK_FORMAT_COMPATIBILITY_CLASS_16_BIT = 2,
42 VK_FORMAT_COMPATIBILITY_CLASS_24_BIT = 3,
43 VK_FORMAT_COMPATIBILITY_CLASS_32_BIT = 4,
44 VK_FORMAT_COMPATIBILITY_CLASS_48_BIT = 5,
45 VK_FORMAT_COMPATIBILITY_CLASS_64_BIT = 6,
46 VK_FORMAT_COMPATIBILITY_CLASS_96_BIT = 7,
47 VK_FORMAT_COMPATIBILITY_CLASS_128_BIT = 8,
48 VK_FORMAT_COMPATIBILITY_CLASS_192_BIT = 9,
49 VK_FORMAT_COMPATIBILITY_CLASS_256_BIT = 10,
50 VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT = 11,
51 VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT = 12,
52 VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT = 13,
53 VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT = 14,
54 VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT = 15,
55 VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT = 16,
56 VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT = 17,
57 VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT = 18,
58 VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT = 19,
59 VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT = 20,
Mark Lobodzinskiadaac9d2016-01-08 11:07:56 -070060 VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT = 21,
Jon Ashburn5484e0c2016-03-08 17:48:44 -070061 VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT = 22,
62 VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT = 23,
63 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT = 24,
64 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT = 25,
65 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT = 26,
66 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT = 27,
67 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT = 28,
68 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT = 29,
69 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT = 20,
70 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT = 31,
71 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT = 32,
72 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT = 33,
73 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT = 34,
74 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT = 35,
75 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT = 36,
76 VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT = 37,
77 VK_FORMAT_COMPATIBILITY_CLASS_D16_BIT = 38,
78 VK_FORMAT_COMPATIBILITY_CLASS_D24_BIT = 39,
79 VK_FORMAT_COMPATIBILITY_CLASS_D32_BIT = 30,
80 VK_FORMAT_COMPATIBILITY_CLASS_S8_BIT = 41,
81 VK_FORMAT_COMPATIBILITY_CLASS_D16S8_BIT = 42,
82 VK_FORMAT_COMPATIBILITY_CLASS_D24S8_BIT = 43,
83 VK_FORMAT_COMPATIBILITY_CLASS_D32S8_BIT = 44,
84 VK_FORMAT_COMPATIBILITY_CLASS_MAX_ENUM = 45
Mark Lobodzinskiadaac9d2016-01-08 11:07:56 -070085} VkFormatCompatibilityClass;
86
Mark Lobodzinskia9f33492016-01-11 14:17:05 -070087typedef enum VkStringErrorFlagBits {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070088 VK_STRING_ERROR_NONE = 0x00000000,
89 VK_STRING_ERROR_LENGTH = 0x00000001,
90 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinskia9f33492016-01-11 14:17:05 -070091} VkStringErrorFlagBits;
92typedef VkFlags VkStringErrorFlags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070093
Mike Stroyana551bc02016-09-28 09:42:28 -060094VK_LAYER_EXPORT void layer_debug_actions(debug_report_data *report_data, std::vector<VkDebugReportCallbackEXT> &logging_callback,
95 const VkAllocationCallbacks *pAllocator, const char *layer_identifier);
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -060096
Jon Ashburn5484e0c2016-03-08 17:48:44 -070097static inline bool vk_format_is_undef(VkFormat format) { return (format == VK_FORMAT_UNDEFINED); }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060098
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060099bool vk_format_is_depth_or_stencil(VkFormat format);
100bool vk_format_is_depth_and_stencil(VkFormat format);
101bool vk_format_is_depth_only(VkFormat format);
102bool vk_format_is_stencil_only(VkFormat format);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600103
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700104static inline bool vk_format_is_color(VkFormat format) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700105 return !(vk_format_is_undef(format) || vk_format_is_depth_or_stencil(format));
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600106}
107
Dave Houlton59a20702017-02-02 17:26:23 -0700108static inline bool vk_format_has_depth(VkFormat format) {
109 return (vk_format_is_depth_only(format) || vk_format_is_depth_and_stencil(format));
110}
111
112static inline bool vk_format_has_stencil(VkFormat format) {
113 return (vk_format_is_stencil_only(format) || vk_format_is_depth_and_stencil(format));
114}
115
Mark Lobodzinski39d2cad2017-03-01 16:09:07 -0700116VK_LAYER_EXPORT bool vk_format_is_compressed_ETC2_EAC(VkFormat format);
117VK_LAYER_EXPORT bool vk_format_is_compressed_ASTC_LDR(VkFormat format);
118VK_LAYER_EXPORT bool vk_format_is_compressed_BC(VkFormat format);
Mike Stroyana551bc02016-09-28 09:42:28 -0600119VK_LAYER_EXPORT bool vk_format_is_norm(VkFormat format);
Arda Coskunsesdbd69742017-02-25 11:34:37 -0700120VK_LAYER_EXPORT bool vk_format_is_unorm(VkFormat format);
121VK_LAYER_EXPORT bool vk_format_is_snorm(VkFormat format);
Mike Stroyana551bc02016-09-28 09:42:28 -0600122VK_LAYER_EXPORT bool vk_format_is_int(VkFormat format);
123VK_LAYER_EXPORT bool vk_format_is_sint(VkFormat format);
124VK_LAYER_EXPORT bool vk_format_is_uint(VkFormat format);
125VK_LAYER_EXPORT bool vk_format_is_float(VkFormat format);
126VK_LAYER_EXPORT bool vk_format_is_srgb(VkFormat format);
Arda Coskunsesdbd69742017-02-25 11:34:37 -0700127VK_LAYER_EXPORT bool vk_format_is_uscaled(VkFormat format);
128VK_LAYER_EXPORT bool vk_format_is_sscaled(VkFormat format);
Mike Stroyana551bc02016-09-28 09:42:28 -0600129VK_LAYER_EXPORT bool vk_format_is_compressed(VkFormat format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -0700130VK_LAYER_EXPORT VkExtent3D vk_format_compressed_texel_block_extents(VkFormat format);
Mike Stroyana551bc02016-09-28 09:42:28 -0600131VK_LAYER_EXPORT size_t vk_format_get_size(VkFormat format);
132VK_LAYER_EXPORT unsigned int vk_format_get_channel_count(VkFormat format);
133VK_LAYER_EXPORT VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format);
134VK_LAYER_EXPORT VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor);
135VK_LAYER_EXPORT VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
136VK_LAYER_EXPORT bool white_list(const char *item, const char *whitelist);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600137
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700138static inline int u_ffs(int val) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600139#ifdef WIN32
Mark Lobodzinski5ddf6c32015-12-16 17:47:28 -0700140 unsigned long bit_pos = 0;
Mike Stroyandebb9842016-01-07 10:05:21 -0700141 if (_BitScanForward(&bit_pos, val) != 0) {
Mark Lobodzinski5ddf6c32015-12-16 17:47:28 -0700142 bit_pos += 1;
143 }
144 return bit_pos;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600145#else
Mark Lobodzinski5ddf6c32015-12-16 17:47:28 -0700146 return ffs(val);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600147#endif
148}
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600149
150#ifdef __cplusplus
151}
152#endif