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 /*
45  * Annotation to tell clang that we intend to fall through from one case to
46  * another in a switch. Sourced from android-base/macros.h.
47  */
48 #define FALLTHROUGH_INTENDED [[clang::fallthrough]]
49 
50 struct VkJsonLayer {
51   VkLayerProperties properties;
52   std::vector<VkExtensionProperties> extensions;
53 };
54 
55 struct VkJsonExtDriverProperties {
VkJsonExtDriverPropertiesVkJsonExtDriverProperties56   VkJsonExtDriverProperties() {
57     reported = false;
58     memset(&driver_properties_khr, 0,
59            sizeof(VkPhysicalDeviceDriverPropertiesKHR));
60   }
61   bool reported;
62   VkPhysicalDeviceDriverPropertiesKHR driver_properties_khr;
63 };
64 
65 struct VkJsonExtVariablePointerFeatures {
VkJsonExtVariablePointerFeaturesVkJsonExtVariablePointerFeatures66   VkJsonExtVariablePointerFeatures() {
67     reported = false;
68     memset(&variable_pointer_features_khr, 0,
69            sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR));
70   }
71   bool reported;
72   VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr;
73 };
74 
75 struct VkJsonDevice {
VkJsonDeviceVkJsonDevice76   VkJsonDevice() {
77     memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
78     memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
79     memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
80     memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties));
81     memset(&point_clipping_properties, 0,
82            sizeof(VkPhysicalDevicePointClippingProperties));
83     memset(&multiview_properties, 0,
84            sizeof(VkPhysicalDeviceMultiviewProperties));
85     memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties));
86     memset(&maintenance3_properties, 0,
87            sizeof(VkPhysicalDeviceMaintenance3Properties));
88     memset(&bit16_storage_features, 0,
89            sizeof(VkPhysicalDevice16BitStorageFeatures));
90     memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures));
91     memset(&variable_pointer_features, 0,
92            sizeof(VkPhysicalDeviceVariablePointerFeatures));
93     memset(&protected_memory_features, 0,
94            sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
95     memset(&sampler_ycbcr_conversion_features, 0,
96            sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
97     memset(&shader_draw_parameter_features, 0,
98            sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
99   }
100   VkPhysicalDeviceProperties properties;
101   VkPhysicalDeviceFeatures features;
102   VkJsonExtDriverProperties ext_driver_properties;
103   VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
104   VkPhysicalDeviceMemoryProperties memory;
105   std::vector<VkQueueFamilyProperties> queues;
106   std::vector<VkExtensionProperties> extensions;
107   std::vector<VkLayerProperties> layers;
108   std::map<VkFormat, VkFormatProperties> formats;
109   VkPhysicalDeviceSubgroupProperties subgroup_properties;
110   VkPhysicalDevicePointClippingProperties point_clipping_properties;
111   VkPhysicalDeviceMultiviewProperties multiview_properties;
112   VkPhysicalDeviceIDProperties id_properties;
113   VkPhysicalDeviceMaintenance3Properties maintenance3_properties;
114   VkPhysicalDevice16BitStorageFeatures bit16_storage_features;
115   VkPhysicalDeviceMultiviewFeatures multiview_features;
116   VkPhysicalDeviceVariablePointerFeatures variable_pointer_features;
117   VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features;
118   VkPhysicalDeviceSamplerYcbcrConversionFeatures
119       sampler_ycbcr_conversion_features;
120   VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features;
121   std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties>
122       external_fence_properties;
123   std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties>
124       external_semaphore_properties;
125 };
126 
127 struct VkJsonDeviceGroup {
VkJsonDeviceGroupVkJsonDeviceGroup128   VkJsonDeviceGroup() {
129     memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
130   }
131   VkPhysicalDeviceGroupProperties properties;
132   std::vector<uint32_t> device_inds;
133 };
134 
135 struct VkJsonInstance {
VkJsonInstanceVkJsonInstance136   VkJsonInstance() : api_version(0) {}
137   uint32_t api_version;
138   std::vector<VkJsonLayer> layers;
139   std::vector<VkExtensionProperties> extensions;
140   std::vector<VkJsonDevice> devices;
141   std::vector<VkJsonDeviceGroup> device_groups;
142 };
143 
144 VkJsonInstance VkJsonGetInstance();
145 std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
146 bool VkJsonInstanceFromJson(const std::string& json,
147                             VkJsonInstance* instance,
148                             std::string* errors);
149 
150 VkJsonDevice VkJsonGetDevice(VkInstance instance,
151                              VkPhysicalDevice device,
152                              uint32_t instanceExtensionCount,
153                              const char* const* instanceExtensions);
154 std::string VkJsonDeviceToJson(const VkJsonDevice& device);
155 bool VkJsonDeviceFromJson(const std::string& json,
156                           VkJsonDevice* device,
157                           std::string* errors);
158 
159 std::string VkJsonImageFormatPropertiesToJson(
160     const VkImageFormatProperties& properties);
161 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
162                                          VkImageFormatProperties* properties,
163                                          std::string* errors);
164 
165 // Backward-compatibility aliases
166 typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)167 inline VkJsonAllProperties VkJsonGetAllProperties(
168     VkPhysicalDevice physicalDevice) {
169   return VkJsonGetDevice(VK_NULL_HANDLE, physicalDevice, 0, nullptr);
170 }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)171 inline std::string VkJsonAllPropertiesToJson(
172     const VkJsonAllProperties& properties) {
173   return VkJsonDeviceToJson(properties);
174 }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)175 inline bool VkJsonAllPropertiesFromJson(const std::string& json,
176                                         VkJsonAllProperties* properties,
177                                         std::string* errors) {
178   return VkJsonDeviceFromJson(json, properties, errors);
179 }
180 
181 #endif  // VKJSON_H_
182