blob: 0575147efa8b2836e9e908c663c2df9588df2ea8 [file] [log] [blame]
Yiwei Zhangf9a57e62018-04-05 00:17:22 -07001///////////////////////////////////////////////////////////////////////////////
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
Yiwei Zhang59b492c2018-10-11 16:26:51 -070036/*
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
Yiwei Zhangf9a57e62018-04-05 00:17:22 -070042struct VkJsonLayer {
43 VkLayerProperties properties;
44 std::vector<VkExtensionProperties> extensions;
45};
46
Yiwei Zhang7b4169d2018-10-02 18:58:31 -070047struct VkJsonExtDriverProperties {
48 VkJsonExtDriverProperties() {
49 reported = false;
50 memset(&driver_properties_khr, 0,
51 sizeof(VkPhysicalDeviceDriverPropertiesKHR));
52 }
53 bool reported;
54 VkPhysicalDeviceDriverPropertiesKHR driver_properties_khr;
55};
56
Yiwei Zhangf9a57e62018-04-05 00:17:22 -070057struct VkJsonExtVariablePointerFeatures {
58 VkJsonExtVariablePointerFeatures() {
Yiwei Zhang7b4169d2018-10-02 18:58:31 -070059 reported = false;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -070060 memset(&variable_pointer_features_khr, 0,
61 sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR));
62 }
Yiwei Zhang7b4169d2018-10-02 18:58:31 -070063 bool reported;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -070064 VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointer_features_khr;
65};
66
Peiyong Linc1b5ffb2020-02-27 19:31:51 -080067struct VkJsonExtShaderFloat16Int8Features {
68 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
Trevor David Blackd35f0f62021-09-07 23:39:36 +000077struct VkJsonCore12 {
78 VkPhysicalDeviceVulkan12Properties properties;
79 VkPhysicalDeviceVulkan12Features features;
80};
81
Yiwei Zhangf9a57e62018-04-05 00:17:22 -070082struct VkJsonDevice {
83 VkJsonDevice() {
84 memset(&properties, 0, sizeof(VkPhysicalDeviceProperties));
85 memset(&features, 0, sizeof(VkPhysicalDeviceFeatures));
86 memset(&memory, 0, sizeof(VkPhysicalDeviceMemoryProperties));
87 memset(&subgroup_properties, 0, sizeof(VkPhysicalDeviceSubgroupProperties));
88 memset(&point_clipping_properties, 0,
89 sizeof(VkPhysicalDevicePointClippingProperties));
90 memset(&multiview_properties, 0,
91 sizeof(VkPhysicalDeviceMultiviewProperties));
92 memset(&id_properties, 0, sizeof(VkPhysicalDeviceIDProperties));
93 memset(&maintenance3_properties, 0,
94 sizeof(VkPhysicalDeviceMaintenance3Properties));
95 memset(&bit16_storage_features, 0,
96 sizeof(VkPhysicalDevice16BitStorageFeatures));
97 memset(&multiview_features, 0, sizeof(VkPhysicalDeviceMultiviewFeatures));
98 memset(&variable_pointer_features, 0,
99 sizeof(VkPhysicalDeviceVariablePointerFeatures));
100 memset(&protected_memory_features, 0,
101 sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
102 memset(&sampler_ycbcr_conversion_features, 0,
103 sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
104 memset(&shader_draw_parameter_features, 0,
105 sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
Trevor David Blackd35f0f62021-09-07 23:39:36 +0000106 memset(&core12, 0, sizeof(VkJsonCore12));
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700107 }
108 VkPhysicalDeviceProperties properties;
109 VkPhysicalDeviceFeatures features;
Yiwei Zhang7b4169d2018-10-02 18:58:31 -0700110 VkJsonExtDriverProperties ext_driver_properties;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700111 VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
Peiyong Linc1b5ffb2020-02-27 19:31:51 -0800112 VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700113 VkPhysicalDeviceMemoryProperties memory;
114 std::vector<VkQueueFamilyProperties> queues;
115 std::vector<VkExtensionProperties> extensions;
116 std::vector<VkLayerProperties> layers;
117 std::map<VkFormat, VkFormatProperties> formats;
118 VkPhysicalDeviceSubgroupProperties subgroup_properties;
119 VkPhysicalDevicePointClippingProperties point_clipping_properties;
120 VkPhysicalDeviceMultiviewProperties multiview_properties;
121 VkPhysicalDeviceIDProperties id_properties;
122 VkPhysicalDeviceMaintenance3Properties maintenance3_properties;
123 VkPhysicalDevice16BitStorageFeatures bit16_storage_features;
124 VkPhysicalDeviceMultiviewFeatures multiview_features;
125 VkPhysicalDeviceVariablePointerFeatures variable_pointer_features;
126 VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features;
127 VkPhysicalDeviceSamplerYcbcrConversionFeatures
128 sampler_ycbcr_conversion_features;
129 VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_parameter_features;
130 std::map<VkExternalFenceHandleTypeFlagBits, VkExternalFenceProperties>
131 external_fence_properties;
132 std::map<VkExternalSemaphoreHandleTypeFlagBits, VkExternalSemaphoreProperties>
133 external_semaphore_properties;
Trevor David Blackd35f0f62021-09-07 23:39:36 +0000134 VkJsonCore12 core12;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700135};
136
137struct VkJsonDeviceGroup {
138 VkJsonDeviceGroup() {
139 memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
140 }
141 VkPhysicalDeviceGroupProperties properties;
142 std::vector<uint32_t> device_inds;
143};
144
145struct VkJsonInstance {
146 VkJsonInstance() : api_version(0) {}
147 uint32_t api_version;
148 std::vector<VkJsonLayer> layers;
149 std::vector<VkExtensionProperties> extensions;
150 std::vector<VkJsonDevice> devices;
151 std::vector<VkJsonDeviceGroup> device_groups;
152};
153
154VkJsonInstance VkJsonGetInstance();
155std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
156bool VkJsonInstanceFromJson(const std::string& json,
157 VkJsonInstance* instance,
158 std::string* errors);
159
Yiwei Zhang91fc3dc2020-07-05 23:33:22 -0700160VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device);
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700161std::string VkJsonDeviceToJson(const VkJsonDevice& device);
162bool VkJsonDeviceFromJson(const std::string& json,
163 VkJsonDevice* device,
164 std::string* errors);
165
166std::string VkJsonImageFormatPropertiesToJson(
167 const VkImageFormatProperties& properties);
168bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
169 VkImageFormatProperties* properties,
170 std::string* errors);
171
172// Backward-compatibility aliases
173typedef VkJsonDevice VkJsonAllProperties;
174inline VkJsonAllProperties VkJsonGetAllProperties(
175 VkPhysicalDevice physicalDevice) {
Yiwei Zhang91fc3dc2020-07-05 23:33:22 -0700176 return VkJsonGetDevice(physicalDevice);
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700177}
178inline std::string VkJsonAllPropertiesToJson(
179 const VkJsonAllProperties& properties) {
180 return VkJsonDeviceToJson(properties);
181}
182inline bool VkJsonAllPropertiesFromJson(const std::string& json,
183 VkJsonAllProperties* properties,
184 std::string* errors) {
185 return VkJsonDeviceFromJson(json, properties, errors);
186}
187
188#endif // VKJSON_H_