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 VkJsonExtShaderFloat16Int8Features {
VkJsonExtShaderFloat16Int8FeaturesVkJsonExtShaderFloat16Int8Features76   VkJsonExtShaderFloat16Int8Features() {
77     reported = false;
78     memset(&shader_float16_int8_features_khr, 0,
79            sizeof(VkPhysicalDeviceShaderFloat16Int8FeaturesKHR));
80   }
81   bool reported;
82   VkPhysicalDeviceShaderFloat16Int8FeaturesKHR shader_float16_int8_features_khr;
83 };
84 
85 struct VkJsonDevice {
VkJsonDeviceVkJsonDevice86   VkJsonDevice() {
87     memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
88     memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
89     memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
90     memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties));
91     memset(&point_clipping_properties, 0,
92            sizeof(VkPhysicalDevicePointClippingProperties));
93     memset(&multiview_properties, 0,
94            sizeof(VkPhysicalDeviceMultiviewProperties));
95     memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties));
96     memset(&maintenance3_properties, 0,
97            sizeof(VkPhysicalDeviceMaintenance3Properties));
98     memset(&bit16_storage_features, 0,
99            sizeof(VkPhysicalDevice16BitStorageFeatures));
100     memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures));
101     memset(&variable_pointer_features, 0,
102            sizeof(VkPhysicalDeviceVariablePointerFeatures));
103     memset(&protected_memory_features, 0,
104            sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
105     memset(&sampler_ycbcr_conversion_features, 0,
106            sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
107     memset(&shader_draw_parameter_features, 0,
108            sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
109   }
110   VkPhysicalDeviceProperties properties;
111   VkPhysicalDeviceFeatures features;
112   VkJsonExtDriverProperties ext_driver_properties;
113   VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
114   VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features;
115   VkPhysicalDeviceMemoryProperties memory;
116   std::vector<VkQueueFamilyProperties> queues;
117   std::vector<VkExtensionProperties> extensions;
118   std::vector<VkLayerProperties> layers;
119   std::map<VkFormat, VkFormatProperties> formats;
120   VkPhysicalDeviceSubgroupProperties subgroup_properties;
121   VkPhysicalDevicePointClippingProperties point_clipping_properties;
122   VkPhysicalDeviceMultiviewProperties multiview_properties;
123   VkPhysicalDeviceIDProperties id_properties;
124   VkPhysicalDeviceMaintenance3Properties maintenance3_properties;
125   VkPhysicalDevice16BitStorageFeatures bit16_storage_features;
126   VkPhysicalDeviceMultiviewFeatures multiview_features;
127   VkPhysicalDeviceVariablePointerFeatures variable_pointer_features;
128   VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features;
129   VkPhysicalDeviceSamplerYcbcrConversionFeatures
130       sampler_ycbcr_conversion_features;
131   VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features;
132   std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties>
133       external_fence_properties;
134   std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties>
135       external_semaphore_properties;
136 };
137 
138 struct VkJsonDeviceGroup {
VkJsonDeviceGroupVkJsonDeviceGroup139   VkJsonDeviceGroup() {
140     memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
141   }
142   VkPhysicalDeviceGroupProperties properties;
143   std::vector<uint32_t> device_inds;
144 };
145 
146 struct VkJsonInstance {
VkJsonInstanceVkJsonInstance147   VkJsonInstance() : api_version(0) {}
148   uint32_t api_version;
149   std::vector<VkJsonLayer> layers;
150   std::vector<VkExtensionProperties> extensions;
151   std::vector<VkJsonDevice> devices;
152   std::vector<VkJsonDeviceGroup> device_groups;
153 };
154 
155 VkJsonInstance VkJsonGetInstance();
156 std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
157 bool VkJsonInstanceFromJson(const std::string& json,
158                             VkJsonInstance* instance,
159                             std::string* errors);
160 
161 VkJsonDevice VkJsonGetDevice(VkInstance instance,
162                              VkPhysicalDevice device,
163                              uint32_t instanceExtensionCount,
164                              const char* const* instanceExtensions);
165 std::string VkJsonDeviceToJson(const VkJsonDevice& device);
166 bool VkJsonDeviceFromJson(const std::string& json,
167                           VkJsonDevice* device,
168                           std::string* errors);
169 
170 std::string VkJsonImageFormatPropertiesToJson(
171     const VkImageFormatProperties& properties);
172 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
173                                          VkImageFormatProperties* properties,
174                                          std::string* errors);
175 
176 // Backward-compatibility aliases
177 typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)178 inline VkJsonAllProperties VkJsonGetAllProperties(
179     VkPhysicalDevice physicalDevice) {
180   return VkJsonGetDevice(VK_NULL_HANDLE, physicalDevice, 0, nullptr);
181 }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)182 inline std::string VkJsonAllPropertiesToJson(
183     const VkJsonAllProperties& properties) {
184   return VkJsonDeviceToJson(properties);
185 }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)186 inline bool VkJsonAllPropertiesFromJson(const std::string& json,
187                                         VkJsonAllProperties* properties,
188                                         std::string* errors) {
189   return VkJsonDeviceFromJson(json, properties, errors);
190 }
191 
192 #endif  // VKJSON_H_
193