Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
| 4 | // Copyright (c) 2015-2016 Valve Corporation |
| 5 | // Copyright (c) 2015-2016 LunarG, Inc. |
| 6 | // Copyright (c) 2015-2016 Google, Inc. |
| 7 | // |
| 8 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | // you may not use this file except in compliance with the License. |
| 10 | // You may obtain a copy of the License at |
| 11 | // |
| 12 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | // |
| 14 | // Unless required by applicable law or agreed to in writing, software |
| 15 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | // See the License for the specific language governing permissions and |
| 18 | // limitations under the License. |
| 19 | /////////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | #ifndef VKJSON_H_ |
| 22 | #define VKJSON_H_ |
| 23 | |
| 24 | #include <vulkan/vulkan.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include <map> |
| 28 | #include <string> |
| 29 | #include <vector> |
| 30 | |
| 31 | #ifdef WIN32 |
| 32 | #undef min |
| 33 | #undef max |
| 34 | #endif |
| 35 | |
Yiwei Zhang | 59b492c | 2018-10-11 16:26:51 -0700 | [diff] [blame] | 36 | /* |
| 37 | * Annotation to tell clang that we intend to fall through from one case to |
| 38 | * another in a switch. Sourced from android-base/macros.h. |
| 39 | */ |
| 40 | #define FALLTHROUGH_INTENDED [[clang::fallthrough]] |
| 41 | |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 42 | struct VkJsonLayer { |
| 43 | VkLayerProperties properties; |
| 44 | std::vector<VkExtensionProperties> extensions; |
| 45 | }; |
| 46 | |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 47 | struct VkJsonExtDriverProperties { |
| 48 | VkJsonExtDriverProperties() { |
| 49 | reported = false; |
| 50 | memset(&driver_properties_khr, 0, |
| 51 | sizeof(VkPhysicalDeviceDriverPropertiesKHR)); |
| 52 | } |
| 53 | bool reported; |
| 54 | VkPhysicalDeviceDriverPropertiesKHR driver_properties_khr; |
| 55 | }; |
| 56 | |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 57 | struct VkJsonExtVariablePointerFeatures { |
| 58 | VkJsonExtVariablePointerFeatures() { |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 59 | reported = false; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 60 | memset(&variable_pointer_features_khr, 0, |
| 61 | sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR)); |
| 62 | } |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 63 | bool reported; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 64 | VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr; |
| 65 | }; |
| 66 | |
Peiyong Lin | c1b5ffb | 2020-02-27 19:31:51 -0800 | [diff] [blame] | 67 | struct VkJsonExtShaderFloat16Int8Features { |
| 68 | VkJsonExtShaderFloat16Int8Features() { |
| 69 | reported = false; |
| 70 | memset(&shader_float16_int8_features_khr, 0, |
| 71 | sizeof(VkPhysicalDeviceShaderFloat16Int8FeaturesKHR)); |
| 72 | } |
| 73 | bool reported; |
| 74 | VkPhysicalDeviceShaderFloat16Int8FeaturesKHR shader_float16_int8_features_khr; |
| 75 | }; |
| 76 | |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 77 | struct VkJsonCore12 { |
| 78 | VkPhysicalDeviceVulkan12Properties properties; |
| 79 | VkPhysicalDeviceVulkan12Features features; |
| 80 | }; |
| 81 | |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 82 | struct VkJsonCore13 { |
| 83 | VkPhysicalDeviceVulkan13Properties properties; |
| 84 | VkPhysicalDeviceVulkan13Features features; |
| 85 | }; |
| 86 | |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 87 | struct VkJsonCore14 { |
| 88 | VkPhysicalDeviceVulkan14Properties properties; |
| 89 | VkPhysicalDeviceVulkan14Features features; |
| 90 | }; |
| 91 | |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 92 | struct VkJsonDevice { |
| 93 | VkJsonDevice() { |
| 94 | memset(&properties, 0, sizeof(VkPhysicalDeviceProperties)); |
| 95 | memset(&features, 0, sizeof(VkPhysicalDeviceFeatures)); |
| 96 | memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties)); |
| 97 | memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties)); |
| 98 | memset(&point_clipping_properties, 0, |
| 99 | sizeof(VkPhysicalDevicePointClippingProperties)); |
| 100 | memset(&multiview_properties, 0, |
| 101 | sizeof(VkPhysicalDeviceMultiviewProperties)); |
| 102 | memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties)); |
| 103 | memset(&maintenance3_properties, 0, |
| 104 | sizeof(VkPhysicalDeviceMaintenance3Properties)); |
| 105 | memset(&bit16_storage_features, 0, |
| 106 | sizeof(VkPhysicalDevice16BitStorageFeatures)); |
| 107 | memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures)); |
| 108 | memset(&variable_pointer_features, 0, |
| 109 | sizeof(VkPhysicalDeviceVariablePointerFeatures)); |
| 110 | memset(&protected_memory_features, 0, |
| 111 | sizeof(VkPhysicalDeviceProtectedMemoryFeatures)); |
| 112 | memset(&sampler_ycbcr_conversion_features, 0, |
| 113 | sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures)); |
| 114 | memset(&shader_draw_parameter_features, 0, |
| 115 | sizeof(VkPhysicalDeviceShaderDrawParameterFeatures)); |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 116 | memset(&core12, 0, sizeof(VkJsonCore12)); |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 117 | memset(&core13, 0, sizeof(VkJsonCore13)); |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 118 | memset(&core14, 0, sizeof(VkJsonCore14)); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 119 | } |
| 120 | VkPhysicalDeviceProperties properties; |
| 121 | VkPhysicalDeviceFeatures features; |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 122 | VkJsonExtDriverProperties ext_driver_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 123 | VkJsonExtVariablePointerFeatures ext_variable_pointer_features; |
Peiyong Lin | c1b5ffb | 2020-02-27 19:31:51 -0800 | [diff] [blame] | 124 | VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 125 | VkPhysicalDeviceMemoryProperties memory; |
| 126 | std::vector<VkQueueFamilyProperties> queues; |
| 127 | std::vector<VkExtensionProperties> extensions; |
| 128 | std::vector<VkLayerProperties> layers; |
| 129 | std::map<VkFormat, VkFormatProperties> formats; |
| 130 | VkPhysicalDeviceSubgroupProperties subgroup_properties; |
| 131 | VkPhysicalDevicePointClippingProperties point_clipping_properties; |
| 132 | VkPhysicalDeviceMultiviewProperties multiview_properties; |
| 133 | VkPhysicalDeviceIDProperties id_properties; |
| 134 | VkPhysicalDeviceMaintenance3Properties maintenance3_properties; |
| 135 | VkPhysicalDevice16BitStorageFeatures bit16_storage_features; |
| 136 | VkPhysicalDeviceMultiviewFeatures multiview_features; |
| 137 | VkPhysicalDeviceVariablePointerFeatures variable_pointer_features; |
| 138 | VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features; |
| 139 | VkPhysicalDeviceSamplerYcbcrConversionFeatures |
| 140 | sampler_ycbcr_conversion_features; |
| 141 | VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features; |
| 142 | std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties> |
| 143 | external_fence_properties; |
| 144 | std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties> |
| 145 | external_semaphore_properties; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 146 | VkJsonCore12 core12; |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 147 | VkJsonCore13 core13; |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 148 | VkJsonCore14 core14; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | struct VkJsonDeviceGroup { |
| 152 | VkJsonDeviceGroup() { |
| 153 | memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties)); |
| 154 | } |
| 155 | VkPhysicalDeviceGroupProperties properties; |
| 156 | std::vector<uint32_t> device_inds; |
| 157 | }; |
| 158 | |
| 159 | struct VkJsonInstance { |
| 160 | VkJsonInstance() : api_version(0) {} |
| 161 | uint32_t api_version; |
| 162 | std::vector<VkJsonLayer> layers; |
| 163 | std::vector<VkExtensionProperties> extensions; |
| 164 | std::vector<VkJsonDevice> devices; |
| 165 | std::vector<VkJsonDeviceGroup> device_groups; |
| 166 | }; |
| 167 | |
| 168 | VkJsonInstance VkJsonGetInstance(); |
| 169 | std::string VkJsonInstanceToJson(const VkJsonInstance& instance); |
| 170 | bool VkJsonInstanceFromJson(const std::string& json, |
| 171 | VkJsonInstance* instance, |
| 172 | std::string* errors); |
| 173 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 174 | VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 175 | std::string VkJsonDeviceToJson(const VkJsonDevice& device); |
| 176 | bool VkJsonDeviceFromJson(const std::string& json, |
| 177 | VkJsonDevice* device, |
| 178 | std::string* errors); |
| 179 | |
| 180 | std::string VkJsonImageFormatPropertiesToJson( |
| 181 | const VkImageFormatProperties& properties); |
| 182 | bool VkJsonImageFormatPropertiesFromJson(const std::string& json, |
| 183 | VkImageFormatProperties* properties, |
| 184 | std::string* errors); |
| 185 | |
| 186 | // Backward-compatibility aliases |
| 187 | typedef VkJsonDevice VkJsonAllProperties; |
| 188 | inline VkJsonAllProperties VkJsonGetAllProperties( |
| 189 | VkPhysicalDevice physicalDevice) { |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 190 | return VkJsonGetDevice(physicalDevice); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 191 | } |
| 192 | inline std::string VkJsonAllPropertiesToJson( |
| 193 | const VkJsonAllProperties& properties) { |
| 194 | return VkJsonDeviceToJson(properties); |
| 195 | } |
| 196 | inline bool VkJsonAllPropertiesFromJson(const std::string& json, |
| 197 | VkJsonAllProperties* properties, |
| 198 | std::string* errors) { |
| 199 | return VkJsonDeviceFromJson(json, properties, errors); |
| 200 | } |
| 201 | |
| 202 | #endif // VKJSON_H_ |