| 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 |  | 
|  | 36 | #ifndef VK_API_VERSION_1_0 | 
|  | 37 | #define VK_API_VERSION_1_0 VK_MAKE_VERSION(1, 0, 0) | 
|  | 38 | #endif | 
|  | 39 |  | 
|  | 40 | #ifndef VK_API_VERSION_1_1 | 
|  | 41 | #define VK_API_VERSION_1_1 VK_MAKE_VERSION(1, 1, 0) | 
|  | 42 | #endif | 
|  | 43 |  | 
|  | 44 | struct VkJsonLayer { | 
|  | 45 | VkLayerProperties properties; | 
|  | 46 | std::vector<VkExtensionProperties> extensions; | 
|  | 47 | }; | 
|  | 48 |  | 
|  | 49 | struct VkJsonExtVariablePointerFeatures { | 
|  | 50 | VkJsonExtVariablePointerFeatures() { | 
|  | 51 | memset(&variable_pointer_features_khr, 0, | 
|  | 52 | sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR)); | 
|  | 53 | } | 
|  | 54 | VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr; | 
|  | 55 | }; | 
|  | 56 |  | 
|  | 57 | struct VkJsonDevice { | 
|  | 58 | VkJsonDevice() { | 
|  | 59 | memset(&properties, 0, sizeof(VkPhysicalDeviceProperties)); | 
|  | 60 | memset(&features, 0, sizeof(VkPhysicalDeviceFeatures)); | 
|  | 61 | memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties)); | 
|  | 62 | memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties)); | 
|  | 63 | memset(&point_clipping_properties, 0, | 
|  | 64 | sizeof(VkPhysicalDevicePointClippingProperties)); | 
|  | 65 | memset(&multiview_properties, 0, | 
|  | 66 | sizeof(VkPhysicalDeviceMultiviewProperties)); | 
|  | 67 | memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties)); | 
|  | 68 | memset(&maintenance3_properties, 0, | 
|  | 69 | sizeof(VkPhysicalDeviceMaintenance3Properties)); | 
|  | 70 | memset(&bit16_storage_features, 0, | 
|  | 71 | sizeof(VkPhysicalDevice16BitStorageFeatures)); | 
|  | 72 | memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures)); | 
|  | 73 | memset(&variable_pointer_features, 0, | 
|  | 74 | sizeof(VkPhysicalDeviceVariablePointerFeatures)); | 
|  | 75 | memset(&protected_memory_features, 0, | 
|  | 76 | sizeof(VkPhysicalDeviceProtectedMemoryFeatures)); | 
|  | 77 | memset(&sampler_ycbcr_conversion_features, 0, | 
|  | 78 | sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures)); | 
|  | 79 | memset(&shader_draw_parameter_features, 0, | 
|  | 80 | sizeof(VkPhysicalDeviceShaderDrawParameterFeatures)); | 
|  | 81 | } | 
|  | 82 | VkPhysicalDeviceProperties properties; | 
|  | 83 | VkPhysicalDeviceFeatures features; | 
|  | 84 | VkJsonExtVariablePointerFeatures ext_variable_pointer_features; | 
|  | 85 | VkPhysicalDeviceMemoryProperties memory; | 
|  | 86 | std::vector<VkQueueFamilyProperties> queues; | 
|  | 87 | std::vector<VkExtensionProperties> extensions; | 
|  | 88 | std::vector<VkLayerProperties> layers; | 
|  | 89 | std::map<VkFormat, VkFormatProperties> formats; | 
|  | 90 | VkPhysicalDeviceSubgroupProperties subgroup_properties; | 
|  | 91 | VkPhysicalDevicePointClippingProperties point_clipping_properties; | 
|  | 92 | VkPhysicalDeviceMultiviewProperties multiview_properties; | 
|  | 93 | VkPhysicalDeviceIDProperties id_properties; | 
|  | 94 | VkPhysicalDeviceMaintenance3Properties maintenance3_properties; | 
|  | 95 | VkPhysicalDevice16BitStorageFeatures bit16_storage_features; | 
|  | 96 | VkPhysicalDeviceMultiviewFeatures multiview_features; | 
|  | 97 | VkPhysicalDeviceVariablePointerFeatures variable_pointer_features; | 
|  | 98 | VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features; | 
|  | 99 | VkPhysicalDeviceSamplerYcbcrConversionFeatures | 
|  | 100 | sampler_ycbcr_conversion_features; | 
|  | 101 | VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features; | 
|  | 102 | std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties> | 
|  | 103 | external_fence_properties; | 
|  | 104 | std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties> | 
|  | 105 | external_semaphore_properties; | 
|  | 106 | }; | 
|  | 107 |  | 
|  | 108 | struct VkJsonDeviceGroup { | 
|  | 109 | VkJsonDeviceGroup() { | 
|  | 110 | memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties)); | 
|  | 111 | } | 
|  | 112 | VkPhysicalDeviceGroupProperties properties; | 
|  | 113 | std::vector<uint32_t> device_inds; | 
|  | 114 | }; | 
|  | 115 |  | 
|  | 116 | struct VkJsonInstance { | 
|  | 117 | VkJsonInstance() : api_version(0) {} | 
|  | 118 | uint32_t api_version; | 
|  | 119 | std::vector<VkJsonLayer> layers; | 
|  | 120 | std::vector<VkExtensionProperties> extensions; | 
|  | 121 | std::vector<VkJsonDevice> devices; | 
|  | 122 | std::vector<VkJsonDeviceGroup> device_groups; | 
|  | 123 | }; | 
|  | 124 |  | 
|  | 125 | VkJsonInstance VkJsonGetInstance(); | 
|  | 126 | std::string VkJsonInstanceToJson(const VkJsonInstance& instance); | 
|  | 127 | bool VkJsonInstanceFromJson(const std::string& json, | 
|  | 128 | VkJsonInstance* instance, | 
|  | 129 | std::string* errors); | 
|  | 130 |  | 
|  | 131 | VkJsonDevice VkJsonGetDevice(VkInstance instance, | 
|  | 132 | VkPhysicalDevice device, | 
|  | 133 | uint32_t instanceExtensionCount, | 
|  | 134 | const char* const* instanceExtensions); | 
|  | 135 | std::string VkJsonDeviceToJson(const VkJsonDevice& device); | 
|  | 136 | bool VkJsonDeviceFromJson(const std::string& json, | 
|  | 137 | VkJsonDevice* device, | 
|  | 138 | std::string* errors); | 
|  | 139 |  | 
|  | 140 | std::string VkJsonImageFormatPropertiesToJson( | 
|  | 141 | const VkImageFormatProperties& properties); | 
|  | 142 | bool VkJsonImageFormatPropertiesFromJson(const std::string& json, | 
|  | 143 | VkImageFormatProperties* properties, | 
|  | 144 | std::string* errors); | 
|  | 145 |  | 
|  | 146 | // Backward-compatibility aliases | 
|  | 147 | typedef VkJsonDevice VkJsonAllProperties; | 
|  | 148 | inline VkJsonAllProperties VkJsonGetAllProperties( | 
|  | 149 | VkPhysicalDevice physicalDevice) { | 
|  | 150 | return VkJsonGetDevice(VK_NULL_HANDLE, physicalDevice, 0, nullptr); | 
|  | 151 | } | 
|  | 152 | inline std::string VkJsonAllPropertiesToJson( | 
|  | 153 | const VkJsonAllProperties& properties) { | 
|  | 154 | return VkJsonDeviceToJson(properties); | 
|  | 155 | } | 
|  | 156 | inline bool VkJsonAllPropertiesFromJson(const std::string& json, | 
|  | 157 | VkJsonAllProperties* properties, | 
|  | 158 | std::string* errors) { | 
|  | 159 | return VkJsonDeviceFromJson(json, properties, errors); | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | #endif  // VKJSON_H_ |