xref: /aosp_15_r20/frameworks/native/vulkan/vkjson/vkjson.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker ///////////////////////////////////////////////////////////////////////////////
2*38e8c45fSAndroid Build Coastguard Worker //
3*38e8c45fSAndroid Build Coastguard Worker // Copyright (c) 2015-2016 The Khronos Group Inc.
4*38e8c45fSAndroid Build Coastguard Worker // Copyright (c) 2015-2016 Valve Corporation
5*38e8c45fSAndroid Build Coastguard Worker // Copyright (c) 2015-2016 LunarG, Inc.
6*38e8c45fSAndroid Build Coastguard Worker // Copyright (c) 2015-2016 Google, Inc.
7*38e8c45fSAndroid Build Coastguard Worker //
8*38e8c45fSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
9*38e8c45fSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
10*38e8c45fSAndroid Build Coastguard Worker // You may obtain a copy of the License at
11*38e8c45fSAndroid Build Coastguard Worker //
12*38e8c45fSAndroid Build Coastguard Worker //     http://www.apache.org/licenses/LICENSE-2.0
13*38e8c45fSAndroid Build Coastguard Worker //
14*38e8c45fSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
15*38e8c45fSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
16*38e8c45fSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17*38e8c45fSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
18*38e8c45fSAndroid Build Coastguard Worker // limitations under the License.
19*38e8c45fSAndroid Build Coastguard Worker ///////////////////////////////////////////////////////////////////////////////
20*38e8c45fSAndroid Build Coastguard Worker 
21*38e8c45fSAndroid Build Coastguard Worker #ifndef VKJSON_H_
22*38e8c45fSAndroid Build Coastguard Worker #define VKJSON_H_
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include <vulkan/vulkan.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <string.h>
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker #include <map>
28*38e8c45fSAndroid Build Coastguard Worker #include <string>
29*38e8c45fSAndroid Build Coastguard Worker #include <vector>
30*38e8c45fSAndroid Build Coastguard Worker 
31*38e8c45fSAndroid Build Coastguard Worker #ifdef WIN32
32*38e8c45fSAndroid Build Coastguard Worker #undef min
33*38e8c45fSAndroid Build Coastguard Worker #undef max
34*38e8c45fSAndroid Build Coastguard Worker #endif
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker /*
37*38e8c45fSAndroid Build Coastguard Worker  * Annotation to tell clang that we intend to fall through from one case to
38*38e8c45fSAndroid Build Coastguard Worker  * another in a switch. Sourced from android-base/macros.h.
39*38e8c45fSAndroid Build Coastguard Worker  */
40*38e8c45fSAndroid Build Coastguard Worker #define FALLTHROUGH_INTENDED [[clang::fallthrough]]
41*38e8c45fSAndroid Build Coastguard Worker 
42*38e8c45fSAndroid Build Coastguard Worker struct VkJsonLayer {
43*38e8c45fSAndroid Build Coastguard Worker   VkLayerProperties properties;
44*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkExtensionProperties> extensions;
45*38e8c45fSAndroid Build Coastguard Worker };
46*38e8c45fSAndroid Build Coastguard Worker 
47*38e8c45fSAndroid Build Coastguard Worker struct VkJsonExtDriverProperties {
VkJsonExtDriverPropertiesVkJsonExtDriverProperties48*38e8c45fSAndroid Build Coastguard Worker   VkJsonExtDriverProperties() {
49*38e8c45fSAndroid Build Coastguard Worker     reported = false;
50*38e8c45fSAndroid Build Coastguard Worker     memset(&driver_properties_khr, 0,
51*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceDriverPropertiesKHR));
52*38e8c45fSAndroid Build Coastguard Worker   }
53*38e8c45fSAndroid Build Coastguard Worker   bool reported;
54*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceDriverPropertiesKHR driver_properties_khr;
55*38e8c45fSAndroid Build Coastguard Worker };
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker struct VkJsonExtVariablePointerFeatures {
VkJsonExtVariablePointerFeaturesVkJsonExtVariablePointerFeatures58*38e8c45fSAndroid Build Coastguard Worker   VkJsonExtVariablePointerFeatures() {
59*38e8c45fSAndroid Build Coastguard Worker     reported = false;
60*38e8c45fSAndroid Build Coastguard Worker     memset(&variable_pointer_features_khr, 0,
61*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR));
62*38e8c45fSAndroid Build Coastguard Worker   }
63*38e8c45fSAndroid Build Coastguard Worker   bool reported;
64*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr;
65*38e8c45fSAndroid Build Coastguard Worker };
66*38e8c45fSAndroid Build Coastguard Worker 
67*38e8c45fSAndroid Build Coastguard Worker struct VkJsonExtShaderFloat16Int8Features {
VkJsonExtShaderFloat16Int8FeaturesVkJsonExtShaderFloat16Int8Features68*38e8c45fSAndroid Build Coastguard Worker   VkJsonExtShaderFloat16Int8Features() {
69*38e8c45fSAndroid Build Coastguard Worker     reported = false;
70*38e8c45fSAndroid Build Coastguard Worker     memset(&shader_float16_int8_features_khr, 0,
71*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceShaderFloat16Int8FeaturesKHR));
72*38e8c45fSAndroid Build Coastguard Worker   }
73*38e8c45fSAndroid Build Coastguard Worker   bool reported;
74*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceShaderFloat16Int8FeaturesKHR shader_float16_int8_features_khr;
75*38e8c45fSAndroid Build Coastguard Worker };
76*38e8c45fSAndroid Build Coastguard Worker 
77*38e8c45fSAndroid Build Coastguard Worker struct VkJsonCore12 {
78*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVulkan12Properties properties;
79*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVulkan12Features features;
80*38e8c45fSAndroid Build Coastguard Worker };
81*38e8c45fSAndroid Build Coastguard Worker 
82*38e8c45fSAndroid Build Coastguard Worker struct VkJsonCore13 {
83*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVulkan13Properties properties;
84*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVulkan13Features features;
85*38e8c45fSAndroid Build Coastguard Worker };
86*38e8c45fSAndroid Build Coastguard Worker 
87*38e8c45fSAndroid Build Coastguard Worker struct VkJsonCore14 {
88*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVulkan14Properties properties;
89*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVulkan14Features features;
90*38e8c45fSAndroid Build Coastguard Worker };
91*38e8c45fSAndroid Build Coastguard Worker 
92*38e8c45fSAndroid Build Coastguard Worker struct VkJsonDevice {
VkJsonDeviceVkJsonDevice93*38e8c45fSAndroid Build Coastguard Worker   VkJsonDevice() {
94*38e8c45fSAndroid Build Coastguard Worker     memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
95*38e8c45fSAndroid Build Coastguard Worker     memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
96*38e8c45fSAndroid Build Coastguard Worker     memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
97*38e8c45fSAndroid Build Coastguard Worker     memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties));
98*38e8c45fSAndroid Build Coastguard Worker     memset(&point_clipping_properties, 0,
99*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDevicePointClippingProperties));
100*38e8c45fSAndroid Build Coastguard Worker     memset(&multiview_properties, 0,
101*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceMultiviewProperties));
102*38e8c45fSAndroid Build Coastguard Worker     memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties));
103*38e8c45fSAndroid Build Coastguard Worker     memset(&maintenance3_properties, 0,
104*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceMaintenance3Properties));
105*38e8c45fSAndroid Build Coastguard Worker     memset(&bit16_storage_features, 0,
106*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDevice16BitStorageFeatures));
107*38e8c45fSAndroid Build Coastguard Worker     memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures));
108*38e8c45fSAndroid Build Coastguard Worker     memset(&variable_pointer_features, 0,
109*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceVariablePointerFeatures));
110*38e8c45fSAndroid Build Coastguard Worker     memset(&protected_memory_features, 0,
111*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
112*38e8c45fSAndroid Build Coastguard Worker     memset(&sampler_ycbcr_conversion_features, 0,
113*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
114*38e8c45fSAndroid Build Coastguard Worker     memset(&shader_draw_parameter_features, 0,
115*38e8c45fSAndroid Build Coastguard Worker            sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
116*38e8c45fSAndroid Build Coastguard Worker     memset(&core12, 0, sizeof(VkJsonCore12));
117*38e8c45fSAndroid Build Coastguard Worker     memset(&core13, 0, sizeof(VkJsonCore13));
118*38e8c45fSAndroid Build Coastguard Worker     memset(&core14, 0, sizeof(VkJsonCore14));
119*38e8c45fSAndroid Build Coastguard Worker   }
120*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceProperties properties;
121*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceFeatures features;
122*38e8c45fSAndroid Build Coastguard Worker   VkJsonExtDriverProperties ext_driver_properties;
123*38e8c45fSAndroid Build Coastguard Worker   VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
124*38e8c45fSAndroid Build Coastguard Worker   VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features;
125*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceMemoryProperties memory;
126*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkQueueFamilyProperties> queues;
127*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkExtensionProperties> extensions;
128*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkLayerProperties> layers;
129*38e8c45fSAndroid Build Coastguard Worker   std::map<VkFormat, VkFormatProperties> formats;
130*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceSubgroupProperties subgroup_properties;
131*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDevicePointClippingProperties point_clipping_properties;
132*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceMultiviewProperties multiview_properties;
133*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceIDProperties id_properties;
134*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceMaintenance3Properties maintenance3_properties;
135*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDevice16BitStorageFeatures bit16_storage_features;
136*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceMultiviewFeatures multiview_features;
137*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceVariablePointerFeatures variable_pointer_features;
138*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features;
139*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceSamplerYcbcrConversionFeatures
140*38e8c45fSAndroid Build Coastguard Worker       sampler_ycbcr_conversion_features;
141*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features;
142*38e8c45fSAndroid Build Coastguard Worker   std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties>
143*38e8c45fSAndroid Build Coastguard Worker       external_fence_properties;
144*38e8c45fSAndroid Build Coastguard Worker   std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties>
145*38e8c45fSAndroid Build Coastguard Worker       external_semaphore_properties;
146*38e8c45fSAndroid Build Coastguard Worker   VkJsonCore12 core12;
147*38e8c45fSAndroid Build Coastguard Worker   VkJsonCore13 core13;
148*38e8c45fSAndroid Build Coastguard Worker   VkJsonCore14 core14;
149*38e8c45fSAndroid Build Coastguard Worker };
150*38e8c45fSAndroid Build Coastguard Worker 
151*38e8c45fSAndroid Build Coastguard Worker struct VkJsonDeviceGroup {
VkJsonDeviceGroupVkJsonDeviceGroup152*38e8c45fSAndroid Build Coastguard Worker   VkJsonDeviceGroup() {
153*38e8c45fSAndroid Build Coastguard Worker     memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
154*38e8c45fSAndroid Build Coastguard Worker   }
155*38e8c45fSAndroid Build Coastguard Worker   VkPhysicalDeviceGroupProperties properties;
156*38e8c45fSAndroid Build Coastguard Worker   std::vector<uint32_t> device_inds;
157*38e8c45fSAndroid Build Coastguard Worker };
158*38e8c45fSAndroid Build Coastguard Worker 
159*38e8c45fSAndroid Build Coastguard Worker struct VkJsonInstance {
VkJsonInstanceVkJsonInstance160*38e8c45fSAndroid Build Coastguard Worker   VkJsonInstance() : api_version(0) {}
161*38e8c45fSAndroid Build Coastguard Worker   uint32_t api_version;
162*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkJsonLayer> layers;
163*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkExtensionProperties> extensions;
164*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkJsonDevice> devices;
165*38e8c45fSAndroid Build Coastguard Worker   std::vector<VkJsonDeviceGroup> device_groups;
166*38e8c45fSAndroid Build Coastguard Worker };
167*38e8c45fSAndroid Build Coastguard Worker 
168*38e8c45fSAndroid Build Coastguard Worker VkJsonInstance VkJsonGetInstance();
169*38e8c45fSAndroid Build Coastguard Worker std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
170*38e8c45fSAndroid Build Coastguard Worker bool VkJsonInstanceFromJson(const std::string& json,
171*38e8c45fSAndroid Build Coastguard Worker                             VkJsonInstance* instance,
172*38e8c45fSAndroid Build Coastguard Worker                             std::string* errors);
173*38e8c45fSAndroid Build Coastguard Worker 
174*38e8c45fSAndroid Build Coastguard Worker VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device);
175*38e8c45fSAndroid Build Coastguard Worker std::string VkJsonDeviceToJson(const VkJsonDevice& device);
176*38e8c45fSAndroid Build Coastguard Worker bool VkJsonDeviceFromJson(const std::string& json,
177*38e8c45fSAndroid Build Coastguard Worker                           VkJsonDevice* device,
178*38e8c45fSAndroid Build Coastguard Worker                           std::string* errors);
179*38e8c45fSAndroid Build Coastguard Worker 
180*38e8c45fSAndroid Build Coastguard Worker std::string VkJsonImageFormatPropertiesToJson(
181*38e8c45fSAndroid Build Coastguard Worker     const VkImageFormatProperties& properties);
182*38e8c45fSAndroid Build Coastguard Worker bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
183*38e8c45fSAndroid Build Coastguard Worker                                          VkImageFormatProperties* properties,
184*38e8c45fSAndroid Build Coastguard Worker                                          std::string* errors);
185*38e8c45fSAndroid Build Coastguard Worker 
186*38e8c45fSAndroid Build Coastguard Worker // Backward-compatibility aliases
187*38e8c45fSAndroid Build Coastguard Worker typedef VkJsonDevice VkJsonAllProperties;
VkJsonGetAllProperties(VkPhysicalDevice physicalDevice)188*38e8c45fSAndroid Build Coastguard Worker inline VkJsonAllProperties VkJsonGetAllProperties(
189*38e8c45fSAndroid Build Coastguard Worker     VkPhysicalDevice physicalDevice) {
190*38e8c45fSAndroid Build Coastguard Worker   return VkJsonGetDevice(physicalDevice);
191*38e8c45fSAndroid Build Coastguard Worker }
VkJsonAllPropertiesToJson(const VkJsonAllProperties & properties)192*38e8c45fSAndroid Build Coastguard Worker inline std::string VkJsonAllPropertiesToJson(
193*38e8c45fSAndroid Build Coastguard Worker     const VkJsonAllProperties& properties) {
194*38e8c45fSAndroid Build Coastguard Worker   return VkJsonDeviceToJson(properties);
195*38e8c45fSAndroid Build Coastguard Worker }
VkJsonAllPropertiesFromJson(const std::string & json,VkJsonAllProperties * properties,std::string * errors)196*38e8c45fSAndroid Build Coastguard Worker inline bool VkJsonAllPropertiesFromJson(const std::string& json,
197*38e8c45fSAndroid Build Coastguard Worker                                         VkJsonAllProperties* properties,
198*38e8c45fSAndroid Build Coastguard Worker                                         std::string* errors) {
199*38e8c45fSAndroid Build Coastguard Worker   return VkJsonDeviceFromJson(json, properties, errors);
200*38e8c45fSAndroid Build Coastguard Worker }
201*38e8c45fSAndroid Build Coastguard Worker 
202*38e8c45fSAndroid Build Coastguard Worker #endif  // VKJSON_H_
203