blob: 2e3b85a0b6eaa2bbb29d11e1b183aed2975c0f4f [file] [log] [blame]
Mark Lobodzinski288e4f72016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
Mark Lobodzinski288e4f72016-02-02 15:55:36 -07006 * 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 Lobodzinskiddaecf82015-09-22 09:33:21 -060011 *
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070012 * The above copyright notice(s) and this permission notice shall be included
13 * in all copies or substantial portions of the Materials.
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060014 *
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070015 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070017 * 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
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060023 *
Jon Ashburnc5a5d632015-11-03 13:41:23 -070024 * Author: Mark Lobodzinski <mark@lunarg.com>
25 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070026 */
27
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060028#pragma once
29#include <stdbool.h>
Mark Lobodzinskid11c4ee2016-03-15 14:21:59 -060030#include <vector>
31#include "vk_layer_logging.h"
32
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -060033#ifndef WIN32
34#include <strings.h> /* for ffs() */
Courtney Goeltzenleuchter55a1a362015-10-27 11:23:21 -060035#else
36#include <intrin.h> /* for __lzcnt() */
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -060037#endif
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060038
39#ifdef __cplusplus
40extern "C" {
41#endif
42
Jon Ashburn2f42d492016-03-24 08:32:09 -060043#define VK_LAYER_API_VERSION VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION)
Mark Lobodzinskifdd29d92016-01-08 11:07:56 -070044typedef enum VkFormatCompatibilityClass {
Jon Ashburn491a3cd2016-03-08 17:48:44 -070045 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,
Mark Lobodzinskifdd29d92016-01-08 11:07:56 -070066 VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT = 21,
Jon Ashburn491a3cd2016-03-08 17:48:44 -070067 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
Mark Lobodzinskifdd29d92016-01-08 11:07:56 -070091} VkFormatCompatibilityClass;
92
Mark Lobodzinskibc9a9d82016-01-11 14:17:05 -070093typedef enum VkStringErrorFlagBits {
Jon Ashburn491a3cd2016-03-08 17:48:44 -070094 VK_STRING_ERROR_NONE = 0x00000000,
95 VK_STRING_ERROR_LENGTH = 0x00000001,
96 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinskibc9a9d82016-01-11 14:17:05 -070097} VkStringErrorFlagBits;
98typedef VkFlags VkStringErrorFlags;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -070099
Mark Lobodzinski24e75862016-03-17 13:59:51 -0600100void layer_debug_actions(debug_report_data* report_data, std::vector<VkDebugReportCallbackEXT> &logging_callback,
Mark Lobodzinskid11c4ee2016-03-15 14:21:59 -0600101 const VkAllocationCallbacks *pAllocator, const char* layer_identifier);
102
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700103static inline bool vk_format_is_undef(VkFormat format) { return (format == VK_FORMAT_UNDEFINED); }
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600104
Mark Lobodzinskib4092de2015-10-23 14:20:31 -0600105bool vk_format_is_depth_or_stencil(VkFormat format);
106bool vk_format_is_depth_and_stencil(VkFormat format);
107bool vk_format_is_depth_only(VkFormat format);
108bool vk_format_is_stencil_only(VkFormat format);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600109
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700110static inline bool vk_format_is_color(VkFormat format) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700111 return !(vk_format_is_undef(format) || vk_format_is_depth_or_stencil(format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600112}
113
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700114bool vk_format_is_norm(VkFormat format);
115bool vk_format_is_int(VkFormat format);
116bool vk_format_is_sint(VkFormat format);
117bool vk_format_is_uint(VkFormat format);
118bool vk_format_is_float(VkFormat format);
119bool vk_format_is_srgb(VkFormat format);
120bool vk_format_is_compressed(VkFormat format);
121size_t vk_format_get_size(VkFormat format);
122unsigned int vk_format_get_channel_count(VkFormat format);
Mark Lobodzinskifdd29d92016-01-08 11:07:56 -0700123VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700124VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor);
125VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600126
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700127static inline int u_ffs(int val) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600128#ifdef WIN32
Mark Lobodzinskid6729442015-12-16 17:47:28 -0700129 unsigned long bit_pos = 0;
Mike Stroyan2febb862016-01-07 10:05:21 -0700130 if (_BitScanForward(&bit_pos, val) != 0) {
Mark Lobodzinskid6729442015-12-16 17:47:28 -0700131 bit_pos += 1;
132 }
133 return bit_pos;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600134#else
Mark Lobodzinskid6729442015-12-16 17:47:28 -0700135 return ffs(val);
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600136#endif
137}
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600138
139#ifdef __cplusplus
140}
141#endif