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(VkPhysicalDevice device);
162 std::string VkJsonDeviceToJson(const VkJsonDevice& device);
163 bool VkJsonDeviceFromJson(const std::string& json,
164 VkJsonDevice* device,
165 std::string* errors);
166
167 std::string VkJsonImageFormatPropertiesToJson(
168 const VkImageFormatProperties& properties);
169 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
170 VkImageFormatProperties* properties,
171 std::string* errors);
172
173 // Backward-compatibility aliases
174 typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)175 inline VkJsonAllProperties VkJsonGetAllProperties(
176 VkPhysicalDevice physicalDevice) {
177 return VkJsonGetDevice(physicalDevice);
178 }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)179 inline std::string VkJsonAllPropertiesToJson(
180 const VkJsonAllProperties& properties) {
181 return VkJsonDeviceToJson(properties);
182 }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)183 inline bool VkJsonAllPropertiesFromJson(const std::string& json,
184 VkJsonAllProperties* properties,
185 std::string* errors) {
186 return VkJsonDeviceFromJson(json, properties, errors);
187 }
188
189 #endif // VKJSON_H_
190