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 | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 36 | struct VkJsonLayer { |
| 37 | VkLayerProperties properties; |
| 38 | std::vector<VkExtensionProperties> extensions; |
| 39 | }; |
| 40 | |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 41 | struct VkJsonExtDriverProperties { |
| 42 | VkJsonExtDriverProperties() { |
| 43 | reported = false; |
| 44 | memset(&driver_properties_khr, 0, |
| 45 | sizeof(VkPhysicalDeviceDriverPropertiesKHR)); |
| 46 | } |
| 47 | bool reported; |
| 48 | VkPhysicalDeviceDriverPropertiesKHR driver_properties_khr; |
| 49 | }; |
| 50 | |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 51 | struct VkJsonExtVariablePointerFeatures { |
| 52 | VkJsonExtVariablePointerFeatures() { |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 53 | reported = false; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 54 | memset(&variable_pointer_features_khr, 0, |
| 55 | sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR)); |
| 56 | } |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 57 | bool reported; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 58 | VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr; |
| 59 | }; |
| 60 | |
Nikita Gupta | 5acad43 | 2025-02-08 11:53:54 +0000 | [diff] [blame] | 61 | struct VkJsonExtImage2DViewOf3DFeatures { |
| 62 | VkJsonExtImage2DViewOf3DFeatures() { |
| 63 | reported = false; |
| 64 | memset(&image_2D_view_of_3D_features_EXT, 0, |
| 65 | sizeof(VkPhysicalDeviceImage2DViewOf3DFeaturesEXT)); |
| 66 | } |
| 67 | bool reported; |
| 68 | VkPhysicalDeviceImage2DViewOf3DFeaturesEXT image_2D_view_of_3D_features_EXT; |
| 69 | }; |
| 70 | |
Peiyong Lin | c1b5ffb | 2020-02-27 19:31:51 -0800 | [diff] [blame] | 71 | struct VkJsonExtShaderFloat16Int8Features { |
| 72 | VkJsonExtShaderFloat16Int8Features() { |
| 73 | reported = false; |
| 74 | memset(&shader_float16_int8_features_khr, 0, |
| 75 | sizeof(VkPhysicalDeviceShaderFloat16Int8FeaturesKHR)); |
| 76 | } |
| 77 | bool reported; |
| 78 | VkPhysicalDeviceShaderFloat16Int8FeaturesKHR shader_float16_int8_features_khr; |
| 79 | }; |
| 80 | |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 81 | struct VkJsonCore12 { |
| 82 | VkPhysicalDeviceVulkan12Properties properties; |
| 83 | VkPhysicalDeviceVulkan12Features features; |
| 84 | }; |
| 85 | |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 86 | struct VkJsonCore13 { |
| 87 | VkPhysicalDeviceVulkan13Properties properties; |
| 88 | VkPhysicalDeviceVulkan13Features features; |
| 89 | }; |
| 90 | |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 91 | struct VkJsonCore14 { |
| 92 | VkPhysicalDeviceVulkan14Properties properties; |
| 93 | VkPhysicalDeviceVulkan14Features features; |
| 94 | }; |
| 95 | |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 96 | struct VkJsonDevice { |
| 97 | VkJsonDevice() { |
| 98 | memset(&properties, 0, sizeof(VkPhysicalDeviceProperties)); |
| 99 | memset(&features, 0, sizeof(VkPhysicalDeviceFeatures)); |
| 100 | memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties)); |
| 101 | memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties)); |
| 102 | memset(&point_clipping_properties, 0, |
| 103 | sizeof(VkPhysicalDevicePointClippingProperties)); |
| 104 | memset(&multiview_properties, 0, |
| 105 | sizeof(VkPhysicalDeviceMultiviewProperties)); |
| 106 | memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties)); |
| 107 | memset(&maintenance3_properties, 0, |
| 108 | sizeof(VkPhysicalDeviceMaintenance3Properties)); |
| 109 | memset(&bit16_storage_features, 0, |
| 110 | sizeof(VkPhysicalDevice16BitStorageFeatures)); |
| 111 | memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures)); |
| 112 | memset(&variable_pointer_features, 0, |
| 113 | sizeof(VkPhysicalDeviceVariablePointerFeatures)); |
| 114 | memset(&protected_memory_features, 0, |
| 115 | sizeof(VkPhysicalDeviceProtectedMemoryFeatures)); |
| 116 | memset(&sampler_ycbcr_conversion_features, 0, |
| 117 | sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures)); |
| 118 | memset(&shader_draw_parameter_features, 0, |
| 119 | sizeof(VkPhysicalDeviceShaderDrawParameterFeatures)); |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 120 | memset(&core12, 0, sizeof(VkJsonCore12)); |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 121 | memset(&core13, 0, sizeof(VkJsonCore13)); |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 122 | memset(&core14, 0, sizeof(VkJsonCore14)); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 123 | } |
| 124 | VkPhysicalDeviceProperties properties; |
| 125 | VkPhysicalDeviceFeatures features; |
Yiwei Zhang | 7b4169d | 2018-10-02 18:58:31 -0700 | [diff] [blame] | 126 | VkJsonExtDriverProperties ext_driver_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 127 | VkJsonExtVariablePointerFeatures ext_variable_pointer_features; |
Nikita Gupta | 5acad43 | 2025-02-08 11:53:54 +0000 | [diff] [blame] | 128 | VkJsonExtImage2DViewOf3DFeatures ext_image_2d_view_of_3d_features; |
Peiyong Lin | c1b5ffb | 2020-02-27 19:31:51 -0800 | [diff] [blame] | 129 | VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 130 | VkPhysicalDeviceMemoryProperties memory; |
| 131 | std::vector<VkQueueFamilyProperties> queues; |
| 132 | std::vector<VkExtensionProperties> extensions; |
| 133 | std::vector<VkLayerProperties> layers; |
| 134 | std::map<VkFormat, VkFormatProperties> formats; |
| 135 | VkPhysicalDeviceSubgroupProperties subgroup_properties; |
| 136 | VkPhysicalDevicePointClippingProperties point_clipping_properties; |
| 137 | VkPhysicalDeviceMultiviewProperties multiview_properties; |
| 138 | VkPhysicalDeviceIDProperties id_properties; |
| 139 | VkPhysicalDeviceMaintenance3Properties maintenance3_properties; |
| 140 | VkPhysicalDevice16BitStorageFeatures bit16_storage_features; |
| 141 | VkPhysicalDeviceMultiviewFeatures multiview_features; |
| 142 | VkPhysicalDeviceVariablePointerFeatures variable_pointer_features; |
| 143 | VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features; |
| 144 | VkPhysicalDeviceSamplerYcbcrConversionFeatures |
| 145 | sampler_ycbcr_conversion_features; |
| 146 | VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features; |
| 147 | std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties> |
| 148 | external_fence_properties; |
| 149 | std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties> |
| 150 | external_semaphore_properties; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 151 | VkJsonCore12 core12; |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 152 | VkJsonCore13 core13; |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 153 | VkJsonCore14 core14; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | struct VkJsonDeviceGroup { |
| 157 | VkJsonDeviceGroup() { |
| 158 | memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties)); |
| 159 | } |
| 160 | VkPhysicalDeviceGroupProperties properties; |
| 161 | std::vector<uint32_t> device_inds; |
| 162 | }; |
| 163 | |
| 164 | struct VkJsonInstance { |
| 165 | VkJsonInstance() : api_version(0) {} |
| 166 | uint32_t api_version; |
| 167 | std::vector<VkJsonLayer> layers; |
| 168 | std::vector<VkExtensionProperties> extensions; |
| 169 | std::vector<VkJsonDevice> devices; |
| 170 | std::vector<VkJsonDeviceGroup> device_groups; |
| 171 | }; |
| 172 | |
| 173 | VkJsonInstance VkJsonGetInstance(); |
| 174 | std::string VkJsonInstanceToJson(const VkJsonInstance& instance); |
| 175 | bool VkJsonInstanceFromJson(const std::string& json, |
| 176 | VkJsonInstance* instance, |
| 177 | std::string* errors); |
| 178 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 179 | VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 180 | std::string VkJsonDeviceToJson(const VkJsonDevice& device); |
| 181 | bool VkJsonDeviceFromJson(const std::string& json, |
| 182 | VkJsonDevice* device, |
| 183 | std::string* errors); |
| 184 | |
| 185 | std::string VkJsonImageFormatPropertiesToJson( |
| 186 | const VkImageFormatProperties& properties); |
| 187 | bool VkJsonImageFormatPropertiesFromJson(const std::string& json, |
| 188 | VkImageFormatProperties* properties, |
| 189 | std::string* errors); |
| 190 | |
| 191 | // Backward-compatibility aliases |
| 192 | typedef VkJsonDevice VkJsonAllProperties; |
| 193 | inline VkJsonAllProperties VkJsonGetAllProperties( |
| 194 | VkPhysicalDevice physicalDevice) { |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 195 | return VkJsonGetDevice(physicalDevice); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 196 | } |
| 197 | inline std::string VkJsonAllPropertiesToJson( |
| 198 | const VkJsonAllProperties& properties) { |
| 199 | return VkJsonDeviceToJson(properties); |
| 200 | } |
| 201 | inline bool VkJsonAllPropertiesFromJson(const std::string& json, |
| 202 | VkJsonAllProperties* properties, |
| 203 | std::string* errors) { |
| 204 | return VkJsonDeviceFromJson(json, properties, errors); |
| 205 | } |
| 206 | |
| 207 | #endif // VKJSON_H_ |