blob: 28de680a99382a2c51f17e890f8e8581ffdc7d9a [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
Trevor David Black79883792021-11-04 23:46:31 +000082struct VkJsonCore13 {
83 VkPhysicalDeviceVulkan13Properties properties;
84 VkPhysicalDeviceVulkan13Features features;
85};
86
Tom Murphy80d9ca72024-10-17 09:52:47 +000087struct VkJsonCore14 {
88 VkPhysicalDeviceVulkan14Properties properties;
89 VkPhysicalDeviceVulkan14Features features;
90};
91
Yiwei Zhangf9a57e62018-04-05 00:17:22 -070092struct VkJsonDevice {
93 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));
Trevor David Blackd35f0f62021-09-07 23:39:36 +0000116 memset(&core12, 0, sizeof(VkJsonCore12));
Trevor David Black79883792021-11-04 23:46:31 +0000117 memset(&core13, 0, sizeof(VkJsonCore13));
Tom Murphy80d9ca72024-10-17 09:52:47 +0000118 memset(&core14, 0, sizeof(VkJsonCore14));
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700119 }
120 VkPhysicalDeviceProperties properties;
121 VkPhysicalDeviceFeatures features;
Yiwei Zhang7b4169d2018-10-02 18:58:31 -0700122 VkJsonExtDriverProperties ext_driver_properties;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700123 VkJsonExtVariablePointerFeatures ext_variable_pointer_features;
Peiyong Linc1b5ffb2020-02-27 19:31:51 -0800124 VkJsonExtShaderFloat16Int8Features ext_shader_float16_int8_features;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700125 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;
Trevor David Blackd35f0f62021-09-07 23:39:36 +0000146 VkJsonCore12 core12;
Trevor David Black79883792021-11-04 23:46:31 +0000147 VkJsonCore13 core13;
Tom Murphy80d9ca72024-10-17 09:52:47 +0000148 VkJsonCore14 core14;
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700149};
150
151struct VkJsonDeviceGroup {
152 VkJsonDeviceGroup() {
153 memset(&properties, 0, sizeof(VkPhysicalDeviceGroupProperties));
154 }
155 VkPhysicalDeviceGroupProperties properties;
156 std::vector<uint32_t> device_inds;
157};
158
159struct VkJsonInstance {
160 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
168VkJsonInstance VkJsonGetInstance();
169std::string VkJsonInstanceToJson(const VkJsonInstance& instance);
170bool VkJsonInstanceFromJson(const std::string& json,
171 VkJsonInstance* instance,
172 std::string* errors);
173
Yiwei Zhang91fc3dc2020-07-05 23:33:22 -0700174VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device);
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700175std::string VkJsonDeviceToJson(const VkJsonDevice& device);
176bool VkJsonDeviceFromJson(const std::string& json,
177 VkJsonDevice* device,
178 std::string* errors);
179
180std::string VkJsonImageFormatPropertiesToJson(
181 const VkImageFormatProperties& properties);
182bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
183 VkImageFormatProperties* properties,
184 std::string* errors);
185
186// Backward-compatibility aliases
187typedef VkJsonDevice VkJsonAllProperties;
188inline VkJsonAllProperties VkJsonGetAllProperties(
189 VkPhysicalDevice physicalDevice) {
Yiwei Zhang91fc3dc2020-07-05 23:33:22 -0700190 return VkJsonGetDevice(physicalDevice);
Yiwei Zhangf9a57e62018-04-05 00:17:22 -0700191}
192inline std::string VkJsonAllPropertiesToJson(
193 const VkJsonAllProperties& properties) {
194 return VkJsonDeviceToJson(properties);
195}
196inline 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_