xref: /aosp_15_r20/frameworks/native/vulkan/vkjson/vkjson.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 VkJsonCore14 {
88   VkPhysicalDeviceVulkan14Properties properties;
89   VkPhysicalDeviceVulkan14Features features;
90 };
91 
92 struct VkJsonDevice {
VkJsonDeviceVkJsonDevice93   VkJsonDevice() {
94     memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
95     memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
96     memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
97     memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties));
98     memset(&point_clipping_properties, 0,
99            sizeof(VkPhysicalDevicePointClippingProperties));
100     memset(&multiview_properties, 0,
101            sizeof(VkPhysicalDeviceMultiviewProperties));
102     memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties));
103     memset(&maintenance3_properties, 0,
104            sizeof(VkPhysicalDeviceMaintenance3Properties));
105     memset(&bit16_storage_features, 0,
106            sizeof(VkPhysicalDevice16BitStorageFeatures));
107     memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures));
108     memset(&variable_pointer_features, 0,
109            sizeof(VkPhysicalDeviceVariablePointerFeatures));
110     memset(&protected_memory_features, 0,
111            sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
112     memset(&sampler_ycbcr_conversion_features, 0,
113            sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
114     memset(&shader_draw_parameter_features, 0,
115            sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
116     memset(&core12, 0, sizeof(VkJsonCore12));
117     memset(&core13, 0, sizeof(VkJsonCore13));
118     memset(&core14, 0, sizeof(VkJsonCore14));
119   }
120   VkPhysicalDeviceProperties properties;
121   VkPhysicalDeviceFeatures features;
122   VkJsonExtDriverProperties ext_driver_properties;
123   VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
124   VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features;
125   VkPhysicalDeviceMemoryProperties memory;
126   std::vector<VkQueueFamilyProperties> queues;
127   std::vector<VkExtensionProperties> extensions;
128   std::vector<VkLayerProperties> layers;
129   std::map<VkFormat, VkFormatProperties> formats;
130   VkPhysicalDeviceSubgroupProperties subgroup_properties;
131   VkPhysicalDevicePointClippingProperties point_clipping_properties;
132   VkPhysicalDeviceMultiviewProperties multiview_properties;
133   VkPhysicalDeviceIDProperties id_properties;
134   VkPhysicalDeviceMaintenance3Properties maintenance3_properties;
135   VkPhysicalDevice16BitStorageFeatures bit16_storage_features;
136   VkPhysicalDeviceMultiviewFeatures multiview_features;
137   VkPhysicalDeviceVariablePointerFeatures variable_pointer_features;
138   VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features;
139   VkPhysicalDeviceSamplerYcbcrConversionFeatures
140       sampler_ycbcr_conversion_features;
141   VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features;
142   std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties>
143       external_fence_properties;
144   std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties>
145       external_semaphore_properties;
146   VkJsonCore12 core12;
147   VkJsonCore13 core13;
148   VkJsonCore14 core14;
149 };
150 
151 struct VkJsonDeviceGroup {
VkJsonDeviceGroupVkJsonDeviceGroup152   VkJsonDeviceGroup() {
153     memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
154   }
155   VkPhysicalDeviceGroupProperties properties;
156   std::vector<uint32_t> device_inds;
157 };
158 
159 struct VkJsonInstance {
VkJsonInstanceVkJsonInstance160   VkJsonInstance() : api_version(0) {}
161   uint32_t api_version;
162   std::vector<VkJsonLayer> layers;
163   std::vector<VkExtensionProperties> extensions;
164   std::vector<VkJsonDevice> devices;
165   std::vector<VkJsonDeviceGroup> device_groups;
166 };
167 
168 VkJsonInstance VkJsonGetInstance();
169 std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
170 bool VkJsonInstanceFromJson(const std::string& json,
171                             VkJsonInstance* instance,
172                             std::string* errors);
173 
174 VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device);
175 std::string VkJsonDeviceToJson(const VkJsonDevice& device);
176 bool VkJsonDeviceFromJson(const std::string& json,
177                           VkJsonDevice* device,
178                           std::string* errors);
179 
180 std::string VkJsonImageFormatPropertiesToJson(
181     const VkImageFormatProperties& properties);
182 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
183                                          VkImageFormatProperties* properties,
184                                          std::string* errors);
185 
186 // Backward-compatibility aliases
187 typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)188 inline VkJsonAllProperties VkJsonGetAllProperties(
189     VkPhysicalDevice physicalDevice) {
190   return VkJsonGetDevice(physicalDevice);
191 }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)192 inline std::string VkJsonAllPropertiesToJson(
193     const VkJsonAllProperties& properties) {
194   return VkJsonDeviceToJson(properties);
195 }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)196 inline bool VkJsonAllPropertiesFromJson(const std::string& json,
197                                         VkJsonAllProperties* properties,
198                                         std::string* errors) {
199   return VkJsonDeviceFromJson(json, properties, errors);
200 }
201 
202 #endif  // VKJSON_H_
203