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 /*
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 
42 struct VkJsonLayer {
43   VkLayerProperties properties;
44   std::vector<VkExtensionProperties> extensions;
45 };
46 
47 struct VkJsonExtDriverProperties {
VkJsonExtDriverPropertiesVkJsonExtDriverProperties48   VkJsonExtDriverProperties() {
49     reported = false;
50     memset(&driver_properties_khr, 0,
51            sizeof(VkPhysicalDeviceDriverPropertiesKHR));
52   }
53   bool reported;
54   VkPhysicalDeviceDriverPropertiesKHR driver_properties_khr;
55 };
56 
57 struct VkJsonExtVariablePointerFeatures {
VkJsonExtVariablePointerFeaturesVkJsonExtVariablePointerFeatures58   VkJsonExtVariablePointerFeatures() {
59     reported = false;
60     memset(&variable_pointer_features_khr, 0,
61            sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR));
62   }
63   bool reported;
64   VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr;
65 };
66 
67 struct VkJsonExtShaderFloat16Int8Features {
VkJsonExtShaderFloat16Int8FeaturesVkJsonExtShaderFloat16Int8Features68   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 
77 struct VkJsonCore12 {
78   VkPhysicalDeviceVulkan12Properties properties;
79   VkPhysicalDeviceVulkan12Features features;
80 };
81 
82 struct VkJsonCore13 {
83   VkPhysicalDeviceVulkan13Properties properties;
84   VkPhysicalDeviceVulkan13Features features;
85 };
86 
87 struct VkJsonDevice {
VkJsonDeviceVkJsonDevice88   VkJsonDevice() {
89     memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
90     memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
91     memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
92     memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties));
93     memset(&point_clipping_properties, 0,
94            sizeof(VkPhysicalDevicePointClippingProperties));
95     memset(&multiview_properties, 0,
96            sizeof(VkPhysicalDeviceMultiviewProperties));
97     memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties));
98     memset(&maintenance3_properties, 0,
99            sizeof(VkPhysicalDeviceMaintenance3Properties));
100     memset(&bit16_storage_features, 0,
101            sizeof(VkPhysicalDevice16BitStorageFeatures));
102     memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures));
103     memset(&variable_pointer_features, 0,
104            sizeof(VkPhysicalDeviceVariablePointerFeatures));
105     memset(&protected_memory_features, 0,
106            sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
107     memset(&sampler_ycbcr_conversion_features, 0,
108            sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
109     memset(&shader_draw_parameter_features, 0,
110            sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
111     memset(&core12, 0, sizeof(VkJsonCore12));
112     memset(&core13, 0, sizeof(VkJsonCore13));
113   }
114   VkPhysicalDeviceProperties properties;
115   VkPhysicalDeviceFeatures features;
116   VkJsonExtDriverProperties ext_driver_properties;
117   VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
118   VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features;
119   VkPhysicalDeviceMemoryProperties memory;
120   std::vector<VkQueueFamilyProperties> queues;
121   std::vector<VkExtensionProperties> extensions;
122   std::vector<VkLayerProperties> layers;
123   std::map<VkFormat, VkFormatProperties> formats;
124   VkPhysicalDeviceSubgroupProperties subgroup_properties;
125   VkPhysicalDevicePointClippingProperties point_clipping_properties;
126   VkPhysicalDeviceMultiviewProperties multiview_properties;
127   VkPhysicalDeviceIDProperties id_properties;
128   VkPhysicalDeviceMaintenance3Properties maintenance3_properties;
129   VkPhysicalDevice16BitStorageFeatures bit16_storage_features;
130   VkPhysicalDeviceMultiviewFeatures multiview_features;
131   VkPhysicalDeviceVariablePointerFeatures variable_pointer_features;
132   VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features;
133   VkPhysicalDeviceSamplerYcbcrConversionFeatures
134       sampler_ycbcr_conversion_features;
135   VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features;
136   std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties>
137       external_fence_properties;
138   std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties>
139       external_semaphore_properties;
140   VkJsonCore12 core12;
141   VkJsonCore13 core13;
142 };
143 
144 struct VkJsonDeviceGroup {
VkJsonDeviceGroupVkJsonDeviceGroup145   VkJsonDeviceGroup() {
146     memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
147   }
148   VkPhysicalDeviceGroupProperties properties;
149   std::vector<uint32_t> device_inds;
150 };
151 
152 struct VkJsonInstance {
VkJsonInstanceVkJsonInstance153   VkJsonInstance() : api_version(0) {}
154   uint32_t api_version;
155   std::vector<VkJsonLayer> layers;
156   std::vector<VkExtensionProperties> extensions;
157   std::vector<VkJsonDevice> devices;
158   std::vector<VkJsonDeviceGroup> device_groups;
159 };
160 
161 VkJsonInstance VkJsonGetInstance();
162 std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
163 bool VkJsonInstanceFromJson(const std::string& json,
164                             VkJsonInstance* instance,
165                             std::string* errors);
166 
167 VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device);
168 std::string VkJsonDeviceToJson(const VkJsonDevice& device);
169 bool VkJsonDeviceFromJson(const std::string& json,
170                           VkJsonDevice* device,
171                           std::string* errors);
172 
173 std::string VkJsonImageFormatPropertiesToJson(
174     const VkImageFormatProperties& properties);
175 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
176                                          VkImageFormatProperties* properties,
177                                          std::string* errors);
178 
179 // Backward-compatibility aliases
180 typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)181 inline VkJsonAllProperties VkJsonGetAllProperties(
182     VkPhysicalDevice physicalDevice) {
183   return VkJsonGetDevice(physicalDevice);
184 }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)185 inline std::string VkJsonAllPropertiesToJson(
186     const VkJsonAllProperties& properties) {
187   return VkJsonDeviceToJson(properties);
188 }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)189 inline bool VkJsonAllPropertiesFromJson(const std::string& json,
190                                         VkJsonAllProperties* properties,
191                                         std::string* errors) {
192   return VkJsonDeviceFromJson(json, properties, errors);
193 }
194 
195 #endif  // VKJSON_H_
196