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 struct VkJsonLayer {
37   VkLayerProperties properties;
38   std::vector<VkExtensionProperties> extensions;
39 };
40 
41 struct VkJsonDevice {
VkJsonDeviceVkJsonDevice42   VkJsonDevice() {
43           memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
44           memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
45           memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
46   }
47   VkPhysicalDeviceProperties properties;
48   VkPhysicalDeviceFeatures features;
49   VkPhysicalDeviceMemoryProperties memory;
50   std::vector<VkQueueFamilyProperties> queues;
51   std::vector<VkExtensionProperties> extensions;
52   std::vector<VkLayerProperties> layers;
53   std::map<VkFormat, VkFormatProperties> formats;
54 };
55 
56 struct VkJsonInstance {
57   std::vector<VkJsonLayer> layers;
58   std::vector<VkExtensionProperties> extensions;
59   std::vector<VkJsonDevice> devices;
60 };
61 
62 VkJsonInstance VkJsonGetInstance();
63 std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
64 bool VkJsonInstanceFromJson(const std::string& json,
65                             VkJsonInstance* instance,
66                             std::string* errors);
67 
68 VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device);
69 std::string VkJsonDeviceToJson(const VkJsonDevice& device);
70 bool VkJsonDeviceFromJson(const std::string& json,
71                           VkJsonDevice* device,
72                           std::string* errors);
73 
74 std::string VkJsonImageFormatPropertiesToJson(
75     const VkImageFormatProperties& properties);
76 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
77                                          VkImageFormatProperties* properties,
78                                          std::string* errors);
79 
80 // Backward-compatibility aliases
81 typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)82 inline VkJsonAllProperties VkJsonGetAllProperties(
83     VkPhysicalDevice physicalDevice) {
84   return VkJsonGetDevice(physicalDevice);
85 }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)86 inline std::string VkJsonAllPropertiesToJson(
87     const VkJsonAllProperties& properties) {
88   return VkJsonDeviceToJson(properties);
89 }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)90 inline bool VkJsonAllPropertiesFromJson(const std::string& json,
91                                         VkJsonAllProperties* properties,
92                                         std::string* errors) {
93   return VkJsonDeviceFromJson(json, properties, errors);
94 }
95 
96 #endif  // VKJSON_H_
97