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 #include "vkjson.h"
22
23 #include <assert.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include <cmath>
28 #include <cinttypes>
29 #include <cstdio>
30 #include <limits>
31 #include <memory>
32 #include <sstream>
33 #include <type_traits>
34 #include <utility>
35
36 #include <json/json.h>
37
38 namespace {
39
IsIntegral(double value)40 inline bool IsIntegral(double value) {
41 #if defined(ANDROID)
42 // Android NDK doesn't provide std::trunc yet
43 return trunc(value) == value;
44 #else
45 return std::trunc(value) == value;
46 #endif
47 }
48
49 template <typename T> struct EnumTraits;
50 template <> struct EnumTraits<VkPhysicalDeviceType> {
min__anoncd0603e70111::EnumTraits51 static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; }
max__anoncd0603e70111::EnumTraits52 static uint32_t max() { return VK_PHYSICAL_DEVICE_TYPE_END_RANGE; }
exist__anoncd0603e70111::EnumTraits53 static bool exist(uint32_t e) { return e >= min() && e <= max(); }
54 };
55
56 template <> struct EnumTraits<VkFormat> {
exist__anoncd0603e70111::EnumTraits57 static bool exist(uint32_t e) {
58 switch (e) {
59 case VK_FORMAT_UNDEFINED:
60 case VK_FORMAT_R4G4_UNORM_PACK8:
61 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
62 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
63 case VK_FORMAT_R5G6B5_UNORM_PACK16:
64 case VK_FORMAT_B5G6R5_UNORM_PACK16:
65 case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
66 case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
67 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
68 case VK_FORMAT_R8_UNORM:
69 case VK_FORMAT_R8_SNORM:
70 case VK_FORMAT_R8_USCALED:
71 case VK_FORMAT_R8_SSCALED:
72 case VK_FORMAT_R8_UINT:
73 case VK_FORMAT_R8_SINT:
74 case VK_FORMAT_R8_SRGB:
75 case VK_FORMAT_R8G8_UNORM:
76 case VK_FORMAT_R8G8_SNORM:
77 case VK_FORMAT_R8G8_USCALED:
78 case VK_FORMAT_R8G8_SSCALED:
79 case VK_FORMAT_R8G8_UINT:
80 case VK_FORMAT_R8G8_SINT:
81 case VK_FORMAT_R8G8_SRGB:
82 case VK_FORMAT_R8G8B8_UNORM:
83 case VK_FORMAT_R8G8B8_SNORM:
84 case VK_FORMAT_R8G8B8_USCALED:
85 case VK_FORMAT_R8G8B8_SSCALED:
86 case VK_FORMAT_R8G8B8_UINT:
87 case VK_FORMAT_R8G8B8_SINT:
88 case VK_FORMAT_R8G8B8_SRGB:
89 case VK_FORMAT_B8G8R8_UNORM:
90 case VK_FORMAT_B8G8R8_SNORM:
91 case VK_FORMAT_B8G8R8_USCALED:
92 case VK_FORMAT_B8G8R8_SSCALED:
93 case VK_FORMAT_B8G8R8_UINT:
94 case VK_FORMAT_B8G8R8_SINT:
95 case VK_FORMAT_B8G8R8_SRGB:
96 case VK_FORMAT_R8G8B8A8_UNORM:
97 case VK_FORMAT_R8G8B8A8_SNORM:
98 case VK_FORMAT_R8G8B8A8_USCALED:
99 case VK_FORMAT_R8G8B8A8_SSCALED:
100 case VK_FORMAT_R8G8B8A8_UINT:
101 case VK_FORMAT_R8G8B8A8_SINT:
102 case VK_FORMAT_R8G8B8A8_SRGB:
103 case VK_FORMAT_B8G8R8A8_UNORM:
104 case VK_FORMAT_B8G8R8A8_SNORM:
105 case VK_FORMAT_B8G8R8A8_USCALED:
106 case VK_FORMAT_B8G8R8A8_SSCALED:
107 case VK_FORMAT_B8G8R8A8_UINT:
108 case VK_FORMAT_B8G8R8A8_SINT:
109 case VK_FORMAT_B8G8R8A8_SRGB:
110 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
111 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
112 case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
113 case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
114 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
115 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
116 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
117 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
118 case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
119 case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
120 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
121 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
122 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
123 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
124 case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
125 case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
126 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
127 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
128 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
129 case VK_FORMAT_R16_UNORM:
130 case VK_FORMAT_R16_SNORM:
131 case VK_FORMAT_R16_USCALED:
132 case VK_FORMAT_R16_SSCALED:
133 case VK_FORMAT_R16_UINT:
134 case VK_FORMAT_R16_SINT:
135 case VK_FORMAT_R16_SFLOAT:
136 case VK_FORMAT_R16G16_UNORM:
137 case VK_FORMAT_R16G16_SNORM:
138 case VK_FORMAT_R16G16_USCALED:
139 case VK_FORMAT_R16G16_SSCALED:
140 case VK_FORMAT_R16G16_UINT:
141 case VK_FORMAT_R16G16_SINT:
142 case VK_FORMAT_R16G16_SFLOAT:
143 case VK_FORMAT_R16G16B16_UNORM:
144 case VK_FORMAT_R16G16B16_SNORM:
145 case VK_FORMAT_R16G16B16_USCALED:
146 case VK_FORMAT_R16G16B16_SSCALED:
147 case VK_FORMAT_R16G16B16_UINT:
148 case VK_FORMAT_R16G16B16_SINT:
149 case VK_FORMAT_R16G16B16_SFLOAT:
150 case VK_FORMAT_R16G16B16A16_UNORM:
151 case VK_FORMAT_R16G16B16A16_SNORM:
152 case VK_FORMAT_R16G16B16A16_USCALED:
153 case VK_FORMAT_R16G16B16A16_SSCALED:
154 case VK_FORMAT_R16G16B16A16_UINT:
155 case VK_FORMAT_R16G16B16A16_SINT:
156 case VK_FORMAT_R16G16B16A16_SFLOAT:
157 case VK_FORMAT_R32_UINT:
158 case VK_FORMAT_R32_SINT:
159 case VK_FORMAT_R32_SFLOAT:
160 case VK_FORMAT_R32G32_UINT:
161 case VK_FORMAT_R32G32_SINT:
162 case VK_FORMAT_R32G32_SFLOAT:
163 case VK_FORMAT_R32G32B32_UINT:
164 case VK_FORMAT_R32G32B32_SINT:
165 case VK_FORMAT_R32G32B32_SFLOAT:
166 case VK_FORMAT_R32G32B32A32_UINT:
167 case VK_FORMAT_R32G32B32A32_SINT:
168 case VK_FORMAT_R32G32B32A32_SFLOAT:
169 case VK_FORMAT_R64_UINT:
170 case VK_FORMAT_R64_SINT:
171 case VK_FORMAT_R64_SFLOAT:
172 case VK_FORMAT_R64G64_UINT:
173 case VK_FORMAT_R64G64_SINT:
174 case VK_FORMAT_R64G64_SFLOAT:
175 case VK_FORMAT_R64G64B64_UINT:
176 case VK_FORMAT_R64G64B64_SINT:
177 case VK_FORMAT_R64G64B64_SFLOAT:
178 case VK_FORMAT_R64G64B64A64_UINT:
179 case VK_FORMAT_R64G64B64A64_SINT:
180 case VK_FORMAT_R64G64B64A64_SFLOAT:
181 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
182 case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
183 case VK_FORMAT_D16_UNORM:
184 case VK_FORMAT_X8_D24_UNORM_PACK32:
185 case VK_FORMAT_D32_SFLOAT:
186 case VK_FORMAT_S8_UINT:
187 case VK_FORMAT_D16_UNORM_S8_UINT:
188 case VK_FORMAT_D24_UNORM_S8_UINT:
189 case VK_FORMAT_D32_SFLOAT_S8_UINT:
190 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
191 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
192 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
193 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
194 case VK_FORMAT_BC2_UNORM_BLOCK:
195 case VK_FORMAT_BC2_SRGB_BLOCK:
196 case VK_FORMAT_BC3_UNORM_BLOCK:
197 case VK_FORMAT_BC3_SRGB_BLOCK:
198 case VK_FORMAT_BC4_UNORM_BLOCK:
199 case VK_FORMAT_BC4_SNORM_BLOCK:
200 case VK_FORMAT_BC5_UNORM_BLOCK:
201 case VK_FORMAT_BC5_SNORM_BLOCK:
202 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
203 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
204 case VK_FORMAT_BC7_UNORM_BLOCK:
205 case VK_FORMAT_BC7_SRGB_BLOCK:
206 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
207 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
208 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
209 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
210 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
211 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
212 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
213 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
214 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
215 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
216 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
217 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
218 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
219 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
220 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
221 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
222 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
223 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
224 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
225 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
226 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
227 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
228 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
229 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
230 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
231 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
232 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
233 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
234 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
235 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
236 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
237 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
238 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
239 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
240 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
241 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
242 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
243 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
244 case VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG:
245 case VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG:
246 case VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG:
247 case VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG:
248 case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG:
249 case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG:
250 case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG:
251 case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG:
252 case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
253 case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
254 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
255 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
256 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
257 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
258 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
259 case VK_FORMAT_R10X6_UNORM_PACK16_KHR:
260 case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:
261 case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:
262 case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
263 case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
264 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
265 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
266 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
267 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
268 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
269 case VK_FORMAT_R12X4_UNORM_PACK16_KHR:
270 case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:
271 case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:
272 case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
273 case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
274 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
275 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
276 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
277 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
278 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
279 case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
280 case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
281 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
282 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
283 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
284 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
285 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
286 return true;
287 }
288 return false;
289 }
290 };
291
292 template <>
293 struct EnumTraits<VkPointClippingBehavior> {
min__anoncd0603e70111::EnumTraits294 static uint32_t min() { return VK_POINT_CLIPPING_BEHAVIOR_BEGIN_RANGE; }
max__anoncd0603e70111::EnumTraits295 static uint32_t max() { return VK_POINT_CLIPPING_BEHAVIOR_END_RANGE; }
exist__anoncd0603e70111::EnumTraits296 static bool exist(uint32_t e) { return e >= min() && e <= max(); }
297 };
298
299 template <>
300 struct EnumTraits<VkExternalFenceHandleTypeFlagBits> {
exist__anoncd0603e70111::EnumTraits301 static bool exist(uint32_t e) {
302 switch (e) {
303 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT:
304 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT:
305 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT:
306 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT:
307 return true;
308 }
309 return false;
310 }
311 };
312
313 template <>
314 struct EnumTraits<VkExternalSemaphoreHandleTypeFlagBits> {
exist__anoncd0603e70111::EnumTraits315 static bool exist(uint32_t e) {
316 switch (e) {
317 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT:
318 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT:
319 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT:
320 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT:
321 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT:
322 return true;
323 }
324 return false;
325 }
326 };
327
328 template <>
329 struct EnumTraits<VkDriverIdKHR> {
min__anoncd0603e70111::EnumTraits330 static uint32_t min() { return VK_DRIVER_ID_BEGIN_RANGE_KHR; }
max__anoncd0603e70111::EnumTraits331 static uint32_t max() { return VK_DRIVER_ID_END_RANGE_KHR; }
exist__anoncd0603e70111::EnumTraits332 static bool exist(uint32_t e) { return e >= min() && e <= max(); }
333 };
334
335 // VkSparseImageFormatProperties
336
337 template <typename Visitor>
Iterate(Visitor * visitor,VkExtent3D * extents)338 inline bool Iterate(Visitor* visitor, VkExtent3D* extents) {
339 return
340 visitor->Visit("width", &extents->width) &&
341 visitor->Visit("height", &extents->height) &&
342 visitor->Visit("depth", &extents->depth);
343 }
344
345 template <typename Visitor>
Iterate(Visitor * visitor,VkImageFormatProperties * properties)346 inline bool Iterate(Visitor* visitor, VkImageFormatProperties* properties) {
347 return
348 visitor->Visit("maxExtent", &properties->maxExtent) &&
349 visitor->Visit("maxMipLevels", &properties->maxMipLevels) &&
350 visitor->Visit("maxArrayLayers", &properties->maxArrayLayers) &&
351 visitor->Visit("sampleCounts", &properties->sampleCounts) &&
352 visitor->Visit("maxResourceSize", &properties->maxResourceSize);
353 }
354
355 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceLimits * limits)356 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceLimits* limits) {
357 return
358 visitor->Visit("maxImageDimension1D", &limits->maxImageDimension1D) &&
359 visitor->Visit("maxImageDimension2D", &limits->maxImageDimension2D) &&
360 visitor->Visit("maxImageDimension3D", &limits->maxImageDimension3D) &&
361 visitor->Visit("maxImageDimensionCube", &limits->maxImageDimensionCube) &&
362 visitor->Visit("maxImageArrayLayers", &limits->maxImageArrayLayers) &&
363 visitor->Visit("maxTexelBufferElements", &limits->maxTexelBufferElements) &&
364 visitor->Visit("maxUniformBufferRange", &limits->maxUniformBufferRange) &&
365 visitor->Visit("maxStorageBufferRange", &limits->maxStorageBufferRange) &&
366 visitor->Visit("maxPushConstantsSize", &limits->maxPushConstantsSize) &&
367 visitor->Visit("maxMemoryAllocationCount", &limits->maxMemoryAllocationCount) &&
368 visitor->Visit("maxSamplerAllocationCount", &limits->maxSamplerAllocationCount) &&
369 visitor->Visit("bufferImageGranularity", &limits->bufferImageGranularity) &&
370 visitor->Visit("sparseAddressSpaceSize", &limits->sparseAddressSpaceSize) &&
371 visitor->Visit("maxBoundDescriptorSets", &limits->maxBoundDescriptorSets) &&
372 visitor->Visit("maxPerStageDescriptorSamplers", &limits->maxPerStageDescriptorSamplers) &&
373 visitor->Visit("maxPerStageDescriptorUniformBuffers", &limits->maxPerStageDescriptorUniformBuffers) &&
374 visitor->Visit("maxPerStageDescriptorStorageBuffers", &limits->maxPerStageDescriptorStorageBuffers) &&
375 visitor->Visit("maxPerStageDescriptorSampledImages", &limits->maxPerStageDescriptorSampledImages) &&
376 visitor->Visit("maxPerStageDescriptorStorageImages", &limits->maxPerStageDescriptorStorageImages) &&
377 visitor->Visit("maxPerStageDescriptorInputAttachments", &limits->maxPerStageDescriptorInputAttachments) &&
378 visitor->Visit("maxPerStageResources", &limits->maxPerStageResources) &&
379 visitor->Visit("maxDescriptorSetSamplers", &limits->maxDescriptorSetSamplers) &&
380 visitor->Visit("maxDescriptorSetUniformBuffers", &limits->maxDescriptorSetUniformBuffers) &&
381 visitor->Visit("maxDescriptorSetUniformBuffersDynamic", &limits->maxDescriptorSetUniformBuffersDynamic) &&
382 visitor->Visit("maxDescriptorSetStorageBuffers", &limits->maxDescriptorSetStorageBuffers) &&
383 visitor->Visit("maxDescriptorSetStorageBuffersDynamic", &limits->maxDescriptorSetStorageBuffersDynamic) &&
384 visitor->Visit("maxDescriptorSetSampledImages", &limits->maxDescriptorSetSampledImages) &&
385 visitor->Visit("maxDescriptorSetStorageImages", &limits->maxDescriptorSetStorageImages) &&
386 visitor->Visit("maxDescriptorSetInputAttachments", &limits->maxDescriptorSetInputAttachments) &&
387 visitor->Visit("maxVertexInputAttributes", &limits->maxVertexInputAttributes) &&
388 visitor->Visit("maxVertexInputBindings", &limits->maxVertexInputBindings) &&
389 visitor->Visit("maxVertexInputAttributeOffset", &limits->maxVertexInputAttributeOffset) &&
390 visitor->Visit("maxVertexInputBindingStride", &limits->maxVertexInputBindingStride) &&
391 visitor->Visit("maxVertexOutputComponents", &limits->maxVertexOutputComponents) &&
392 visitor->Visit("maxTessellationGenerationLevel", &limits->maxTessellationGenerationLevel) &&
393 visitor->Visit("maxTessellationPatchSize", &limits->maxTessellationPatchSize) &&
394 visitor->Visit("maxTessellationControlPerVertexInputComponents", &limits->maxTessellationControlPerVertexInputComponents) &&
395 visitor->Visit("maxTessellationControlPerVertexOutputComponents", &limits->maxTessellationControlPerVertexOutputComponents) &&
396 visitor->Visit("maxTessellationControlPerPatchOutputComponents", &limits->maxTessellationControlPerPatchOutputComponents) &&
397 visitor->Visit("maxTessellationControlTotalOutputComponents", &limits->maxTessellationControlTotalOutputComponents) &&
398 visitor->Visit("maxTessellationEvaluationInputComponents", &limits->maxTessellationEvaluationInputComponents) &&
399 visitor->Visit("maxTessellationEvaluationOutputComponents", &limits->maxTessellationEvaluationOutputComponents) &&
400 visitor->Visit("maxGeometryShaderInvocations", &limits->maxGeometryShaderInvocations) &&
401 visitor->Visit("maxGeometryInputComponents", &limits->maxGeometryInputComponents) &&
402 visitor->Visit("maxGeometryOutputComponents", &limits->maxGeometryOutputComponents) &&
403 visitor->Visit("maxGeometryOutputVertices", &limits->maxGeometryOutputVertices) &&
404 visitor->Visit("maxGeometryTotalOutputComponents", &limits->maxGeometryTotalOutputComponents) &&
405 visitor->Visit("maxFragmentInputComponents", &limits->maxFragmentInputComponents) &&
406 visitor->Visit("maxFragmentOutputAttachments", &limits->maxFragmentOutputAttachments) &&
407 visitor->Visit("maxFragmentDualSrcAttachments", &limits->maxFragmentDualSrcAttachments) &&
408 visitor->Visit("maxFragmentCombinedOutputResources", &limits->maxFragmentCombinedOutputResources) &&
409 visitor->Visit("maxComputeSharedMemorySize", &limits->maxComputeSharedMemorySize) &&
410 visitor->Visit("maxComputeWorkGroupCount", &limits->maxComputeWorkGroupCount) &&
411 visitor->Visit("maxComputeWorkGroupInvocations", &limits->maxComputeWorkGroupInvocations) &&
412 visitor->Visit("maxComputeWorkGroupSize", &limits->maxComputeWorkGroupSize) &&
413 visitor->Visit("subPixelPrecisionBits", &limits->subPixelPrecisionBits) &&
414 visitor->Visit("subTexelPrecisionBits", &limits->subTexelPrecisionBits) &&
415 visitor->Visit("mipmapPrecisionBits", &limits->mipmapPrecisionBits) &&
416 visitor->Visit("maxDrawIndexedIndexValue", &limits->maxDrawIndexedIndexValue) &&
417 visitor->Visit("maxDrawIndirectCount", &limits->maxDrawIndirectCount) &&
418 visitor->Visit("maxSamplerLodBias", &limits->maxSamplerLodBias) &&
419 visitor->Visit("maxSamplerAnisotropy", &limits->maxSamplerAnisotropy) &&
420 visitor->Visit("maxViewports", &limits->maxViewports) &&
421 visitor->Visit("maxViewportDimensions", &limits->maxViewportDimensions) &&
422 visitor->Visit("viewportBoundsRange", &limits->viewportBoundsRange) &&
423 visitor->Visit("viewportSubPixelBits", &limits->viewportSubPixelBits) &&
424 visitor->Visit("minMemoryMapAlignment", &limits->minMemoryMapAlignment) &&
425 visitor->Visit("minTexelBufferOffsetAlignment", &limits->minTexelBufferOffsetAlignment) &&
426 visitor->Visit("minUniformBufferOffsetAlignment", &limits->minUniformBufferOffsetAlignment) &&
427 visitor->Visit("minStorageBufferOffsetAlignment", &limits->minStorageBufferOffsetAlignment) &&
428 visitor->Visit("minTexelOffset", &limits->minTexelOffset) &&
429 visitor->Visit("maxTexelOffset", &limits->maxTexelOffset) &&
430 visitor->Visit("minTexelGatherOffset", &limits->minTexelGatherOffset) &&
431 visitor->Visit("maxTexelGatherOffset", &limits->maxTexelGatherOffset) &&
432 visitor->Visit("minInterpolationOffset", &limits->minInterpolationOffset) &&
433 visitor->Visit("maxInterpolationOffset", &limits->maxInterpolationOffset) &&
434 visitor->Visit("subPixelInterpolationOffsetBits", &limits->subPixelInterpolationOffsetBits) &&
435 visitor->Visit("maxFramebufferWidth", &limits->maxFramebufferWidth) &&
436 visitor->Visit("maxFramebufferHeight", &limits->maxFramebufferHeight) &&
437 visitor->Visit("maxFramebufferLayers", &limits->maxFramebufferLayers) &&
438 visitor->Visit("framebufferColorSampleCounts", &limits->framebufferColorSampleCounts) &&
439 visitor->Visit("framebufferDepthSampleCounts", &limits->framebufferDepthSampleCounts) &&
440 visitor->Visit("framebufferStencilSampleCounts", &limits->framebufferStencilSampleCounts) &&
441 visitor->Visit("framebufferNoAttachmentsSampleCounts", &limits->framebufferNoAttachmentsSampleCounts) &&
442 visitor->Visit("maxColorAttachments", &limits->maxColorAttachments) &&
443 visitor->Visit("sampledImageColorSampleCounts", &limits->sampledImageColorSampleCounts) &&
444 visitor->Visit("sampledImageIntegerSampleCounts", &limits->sampledImageIntegerSampleCounts) &&
445 visitor->Visit("sampledImageDepthSampleCounts", &limits->sampledImageDepthSampleCounts) &&
446 visitor->Visit("sampledImageStencilSampleCounts", &limits->sampledImageStencilSampleCounts) &&
447 visitor->Visit("storageImageSampleCounts", &limits->storageImageSampleCounts) &&
448 visitor->Visit("maxSampleMaskWords", &limits->maxSampleMaskWords) &&
449 visitor->Visit("timestampComputeAndGraphics", &limits->timestampComputeAndGraphics) &&
450 visitor->Visit("timestampPeriod", &limits->timestampPeriod) &&
451 visitor->Visit("maxClipDistances", &limits->maxClipDistances) &&
452 visitor->Visit("maxCullDistances", &limits->maxCullDistances) &&
453 visitor->Visit("maxCombinedClipAndCullDistances", &limits->maxCombinedClipAndCullDistances) &&
454 visitor->Visit("discreteQueuePriorities", &limits->discreteQueuePriorities) &&
455 visitor->Visit("pointSizeRange", &limits->pointSizeRange) &&
456 visitor->Visit("lineWidthRange", &limits->lineWidthRange) &&
457 visitor->Visit("pointSizeGranularity", &limits->pointSizeGranularity) &&
458 visitor->Visit("lineWidthGranularity", &limits->lineWidthGranularity) &&
459 visitor->Visit("strictLines", &limits->strictLines) &&
460 visitor->Visit("standardSampleLocations", &limits->standardSampleLocations) &&
461 visitor->Visit("optimalBufferCopyOffsetAlignment", &limits->optimalBufferCopyOffsetAlignment) &&
462 visitor->Visit("optimalBufferCopyRowPitchAlignment", &limits->optimalBufferCopyRowPitchAlignment) &&
463 visitor->Visit("nonCoherentAtomSize", &limits->nonCoherentAtomSize);
464 }
465
466 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceSparseProperties * properties)467 inline bool Iterate(Visitor* visitor,
468 VkPhysicalDeviceSparseProperties* properties) {
469 return
470 visitor->Visit("residencyStandard2DBlockShape", &properties->residencyStandard2DBlockShape) &&
471 visitor->Visit("residencyStandard2DMultisampleBlockShape", &properties->residencyStandard2DMultisampleBlockShape) &&
472 visitor->Visit("residencyStandard3DBlockShape", &properties->residencyStandard3DBlockShape) &&
473 visitor->Visit("residencyAlignedMipSize", &properties->residencyAlignedMipSize) &&
474 visitor->Visit("residencyNonResidentStrict", &properties->residencyNonResidentStrict);
475 }
476
477 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceProperties * properties)478 inline bool Iterate(Visitor* visitor,
479 VkPhysicalDeviceProperties* properties) {
480 return
481 visitor->Visit("apiVersion", &properties->apiVersion) &&
482 visitor->Visit("driverVersion", &properties->driverVersion) &&
483 visitor->Visit("vendorID", &properties->vendorID) &&
484 visitor->Visit("deviceID", &properties->deviceID) &&
485 visitor->Visit("deviceType", &properties->deviceType) &&
486 visitor->Visit("deviceName", &properties->deviceName) &&
487 visitor->Visit("pipelineCacheUUID", &properties->pipelineCacheUUID) &&
488 visitor->Visit("limits", &properties->limits) &&
489 visitor->Visit("sparseProperties", &properties->sparseProperties);
490 }
491
492 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceFeatures * features)493 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceFeatures* features) {
494 return
495 visitor->Visit("robustBufferAccess", &features->robustBufferAccess) &&
496 visitor->Visit("fullDrawIndexUint32", &features->fullDrawIndexUint32) &&
497 visitor->Visit("imageCubeArray", &features->imageCubeArray) &&
498 visitor->Visit("independentBlend", &features->independentBlend) &&
499 visitor->Visit("geometryShader", &features->geometryShader) &&
500 visitor->Visit("tessellationShader", &features->tessellationShader) &&
501 visitor->Visit("sampleRateShading", &features->sampleRateShading) &&
502 visitor->Visit("dualSrcBlend", &features->dualSrcBlend) &&
503 visitor->Visit("logicOp", &features->logicOp) &&
504 visitor->Visit("multiDrawIndirect", &features->multiDrawIndirect) &&
505 visitor->Visit("drawIndirectFirstInstance", &features->drawIndirectFirstInstance) &&
506 visitor->Visit("depthClamp", &features->depthClamp) &&
507 visitor->Visit("depthBiasClamp", &features->depthBiasClamp) &&
508 visitor->Visit("fillModeNonSolid", &features->fillModeNonSolid) &&
509 visitor->Visit("depthBounds", &features->depthBounds) &&
510 visitor->Visit("wideLines", &features->wideLines) &&
511 visitor->Visit("largePoints", &features->largePoints) &&
512 visitor->Visit("alphaToOne", &features->alphaToOne) &&
513 visitor->Visit("multiViewport", &features->multiViewport) &&
514 visitor->Visit("samplerAnisotropy", &features->samplerAnisotropy) &&
515 visitor->Visit("textureCompressionETC2", &features->textureCompressionETC2) &&
516 visitor->Visit("textureCompressionASTC_LDR", &features->textureCompressionASTC_LDR) &&
517 visitor->Visit("textureCompressionBC", &features->textureCompressionBC) &&
518 visitor->Visit("occlusionQueryPrecise", &features->occlusionQueryPrecise) &&
519 visitor->Visit("pipelineStatisticsQuery", &features->pipelineStatisticsQuery) &&
520 visitor->Visit("vertexPipelineStoresAndAtomics", &features->vertexPipelineStoresAndAtomics) &&
521 visitor->Visit("fragmentStoresAndAtomics", &features->fragmentStoresAndAtomics) &&
522 visitor->Visit("shaderTessellationAndGeometryPointSize", &features->shaderTessellationAndGeometryPointSize) &&
523 visitor->Visit("shaderImageGatherExtended", &features->shaderImageGatherExtended) &&
524 visitor->Visit("shaderStorageImageExtendedFormats", &features->shaderStorageImageExtendedFormats) &&
525 visitor->Visit("shaderStorageImageMultisample", &features->shaderStorageImageMultisample) &&
526 visitor->Visit("shaderStorageImageReadWithoutFormat", &features->shaderStorageImageReadWithoutFormat) &&
527 visitor->Visit("shaderStorageImageWriteWithoutFormat", &features->shaderStorageImageWriteWithoutFormat) &&
528 visitor->Visit("shaderUniformBufferArrayDynamicIndexing", &features->shaderUniformBufferArrayDynamicIndexing) &&
529 visitor->Visit("shaderSampledImageArrayDynamicIndexing", &features->shaderSampledImageArrayDynamicIndexing) &&
530 visitor->Visit("shaderStorageBufferArrayDynamicIndexing", &features->shaderStorageBufferArrayDynamicIndexing) &&
531 visitor->Visit("shaderStorageImageArrayDynamicIndexing", &features->shaderStorageImageArrayDynamicIndexing) &&
532 visitor->Visit("shaderClipDistance", &features->shaderClipDistance) &&
533 visitor->Visit("shaderCullDistance", &features->shaderCullDistance) &&
534 visitor->Visit("shaderFloat64", &features->shaderFloat64) &&
535 visitor->Visit("shaderInt64", &features->shaderInt64) &&
536 visitor->Visit("shaderInt16", &features->shaderInt16) &&
537 visitor->Visit("shaderResourceResidency", &features->shaderResourceResidency) &&
538 visitor->Visit("shaderResourceMinLod", &features->shaderResourceMinLod) &&
539 visitor->Visit("sparseBinding", &features->sparseBinding) &&
540 visitor->Visit("sparseResidencyBuffer", &features->sparseResidencyBuffer) &&
541 visitor->Visit("sparseResidencyImage2D", &features->sparseResidencyImage2D) &&
542 visitor->Visit("sparseResidencyImage3D", &features->sparseResidencyImage3D) &&
543 visitor->Visit("sparseResidency2Samples", &features->sparseResidency2Samples) &&
544 visitor->Visit("sparseResidency4Samples", &features->sparseResidency4Samples) &&
545 visitor->Visit("sparseResidency8Samples", &features->sparseResidency8Samples) &&
546 visitor->Visit("sparseResidency16Samples", &features->sparseResidency16Samples) &&
547 visitor->Visit("sparseResidencyAliased", &features->sparseResidencyAliased) &&
548 visitor->Visit("variableMultisampleRate", &features->variableMultisampleRate) &&
549 visitor->Visit("inheritedQueries", &features->inheritedQueries);
550 }
551
552 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonExtDriverProperties * properties)553 inline bool Iterate(Visitor* visitor,
554 VkJsonExtDriverProperties* properties) {
555 return visitor->Visit("driverPropertiesKHR",
556 &properties->driver_properties_khr);
557 }
558
559 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceDriverPropertiesKHR * properties)560 inline bool Iterate(Visitor* visitor,
561 VkPhysicalDeviceDriverPropertiesKHR* properties) {
562 return visitor->Visit("driverID", &properties->driverID) &&
563 visitor->Visit("driverName", &properties->driverName) &&
564 visitor->Visit("driverInfo", &properties->driverInfo) &&
565 visitor->Visit("conformanceVersion", &properties->conformanceVersion);
566 }
567
568 template <typename Visitor>
Iterate(Visitor * visitor,VkConformanceVersionKHR * version)569 inline bool Iterate(Visitor* visitor,
570 VkConformanceVersionKHR* version) {
571 return visitor->Visit("major", &version->major) &&
572 visitor->Visit("minor", &version->minor) &&
573 visitor->Visit("subminor", &version->subminor) &&
574 visitor->Visit("patch", &version->patch);
575 }
576
577 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonExtVariablePointerFeatures * features)578 inline bool Iterate(Visitor* visitor,
579 VkJsonExtVariablePointerFeatures* features) {
580 return visitor->Visit("variablePointerFeaturesKHR",
581 &features->variable_pointer_features_khr);
582 }
583
584 template <typename Visitor>
Iterate(Visitor * visitor,VkMemoryType * type)585 inline bool Iterate(Visitor* visitor, VkMemoryType* type) {
586 return
587 visitor->Visit("propertyFlags", &type->propertyFlags) &&
588 visitor->Visit("heapIndex", &type->heapIndex);
589 }
590
591 template <typename Visitor>
Iterate(Visitor * visitor,VkMemoryHeap * heap)592 inline bool Iterate(Visitor* visitor, VkMemoryHeap* heap) {
593 return
594 visitor->Visit("size", &heap->size) &&
595 visitor->Visit("flags", &heap->flags);
596 }
597
598 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMemoryProperties * properties)599 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceMemoryProperties* properties) {
600 return
601 visitor->Visit("memoryTypeCount", &properties->memoryTypeCount) &&
602 visitor->VisitArray("memoryTypes", properties->memoryTypeCount, &properties->memoryTypes) &&
603 visitor->Visit("memoryHeapCount", &properties->memoryHeapCount) &&
604 visitor->VisitArray("memoryHeaps", properties->memoryHeapCount, &properties->memoryHeaps);
605 }
606
607 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceSubgroupProperties * properties)608 inline bool Iterate(Visitor* visitor,
609 VkPhysicalDeviceSubgroupProperties* properties) {
610 return visitor->Visit("subgroupSize", &properties->subgroupSize) &&
611 visitor->Visit("supportedStages", &properties->supportedStages) &&
612 visitor->Visit("supportedOperations",
613 &properties->supportedOperations) &&
614 visitor->Visit("quadOperationsInAllStages",
615 &properties->quadOperationsInAllStages);
616 }
617
618 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDevicePointClippingProperties * properties)619 inline bool Iterate(Visitor* visitor,
620 VkPhysicalDevicePointClippingProperties* properties) {
621 return visitor->Visit("pointClippingBehavior",
622 &properties->pointClippingBehavior);
623 }
624
625 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMultiviewProperties * properties)626 inline bool Iterate(Visitor* visitor,
627 VkPhysicalDeviceMultiviewProperties* properties) {
628 return visitor->Visit("maxMultiviewViewCount",
629 &properties->maxMultiviewViewCount) &&
630 visitor->Visit("maxMultiviewInstanceIndex",
631 &properties->maxMultiviewInstanceIndex);
632 }
633
634 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceIDProperties * properties)635 inline bool Iterate(Visitor* visitor,
636 VkPhysicalDeviceIDProperties* properties) {
637 return visitor->Visit("deviceUUID", &properties->deviceUUID) &&
638 visitor->Visit("driverUUID", &properties->driverUUID) &&
639 visitor->Visit("deviceLUID", &properties->deviceLUID) &&
640 visitor->Visit("deviceNodeMask", &properties->deviceNodeMask) &&
641 visitor->Visit("deviceLUIDValid", &properties->deviceLUIDValid);
642 }
643
644 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMaintenance3Properties * properties)645 inline bool Iterate(Visitor* visitor,
646 VkPhysicalDeviceMaintenance3Properties* properties) {
647 return visitor->Visit("maxPerSetDescriptors",
648 &properties->maxPerSetDescriptors) &&
649 visitor->Visit("maxMemoryAllocationSize",
650 &properties->maxMemoryAllocationSize);
651 }
652
653 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDevice16BitStorageFeatures * features)654 inline bool Iterate(Visitor* visitor,
655 VkPhysicalDevice16BitStorageFeatures* features) {
656 return visitor->Visit("storageBuffer16BitAccess",
657 &features->storageBuffer16BitAccess) &&
658 visitor->Visit("uniformAndStorageBuffer16BitAccess",
659 &features->uniformAndStorageBuffer16BitAccess) &&
660 visitor->Visit("storagePushConstant16",
661 &features->storagePushConstant16) &&
662 visitor->Visit("storageInputOutput16",
663 &features->storageInputOutput16);
664 }
665
666 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMultiviewFeatures * features)667 inline bool Iterate(Visitor* visitor,
668 VkPhysicalDeviceMultiviewFeatures* features) {
669 return visitor->Visit("multiview", &features->multiview) &&
670 visitor->Visit("multiviewGeometryShader",
671 &features->multiviewGeometryShader) &&
672 visitor->Visit("multiviewTessellationShader",
673 &features->multiviewTessellationShader);
674 }
675
676 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceVariablePointerFeatures * features)677 inline bool Iterate(Visitor* visitor,
678 VkPhysicalDeviceVariablePointerFeatures* features) {
679 return visitor->Visit("variablePointersStorageBuffer",
680 &features->variablePointersStorageBuffer) &&
681 visitor->Visit("variablePointers", &features->variablePointers);
682 }
683
684 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceProtectedMemoryFeatures * features)685 inline bool Iterate(Visitor* visitor,
686 VkPhysicalDeviceProtectedMemoryFeatures* features) {
687 return visitor->Visit("protectedMemory", &features->protectedMemory);
688 }
689
690 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceSamplerYcbcrConversionFeatures * features)691 inline bool Iterate(Visitor* visitor,
692 VkPhysicalDeviceSamplerYcbcrConversionFeatures* features) {
693 return visitor->Visit("samplerYcbcrConversion",
694 &features->samplerYcbcrConversion);
695 }
696
697 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceShaderDrawParameterFeatures * features)698 inline bool Iterate(Visitor* visitor,
699 VkPhysicalDeviceShaderDrawParameterFeatures* features) {
700 return visitor->Visit("shaderDrawParameters",
701 &features->shaderDrawParameters);
702 }
703
704 template <typename Visitor>
Iterate(Visitor * visitor,VkExternalFenceProperties * properties)705 inline bool Iterate(Visitor* visitor, VkExternalFenceProperties* properties) {
706 return visitor->Visit("exportFromImportedHandleTypes",
707 &properties->exportFromImportedHandleTypes) &&
708 visitor->Visit("compatibleHandleTypes",
709 &properties->compatibleHandleTypes) &&
710 visitor->Visit("externalFenceFeatures",
711 &properties->externalFenceFeatures);
712 }
713
714 template <typename Visitor>
Iterate(Visitor * visitor,VkExternalSemaphoreProperties * properties)715 inline bool Iterate(Visitor* visitor,
716 VkExternalSemaphoreProperties* properties) {
717 return visitor->Visit("exportFromImportedHandleTypes",
718 &properties->exportFromImportedHandleTypes) &&
719 visitor->Visit("compatibleHandleTypes",
720 &properties->compatibleHandleTypes) &&
721 visitor->Visit("externalSemaphoreFeatures",
722 &properties->externalSemaphoreFeatures);
723 }
724
725 template <typename Visitor>
Iterate(Visitor * visitor,VkQueueFamilyProperties * properties)726 inline bool Iterate(Visitor* visitor, VkQueueFamilyProperties* properties) {
727 return
728 visitor->Visit("queueFlags", &properties->queueFlags) &&
729 visitor->Visit("queueCount", &properties->queueCount) &&
730 visitor->Visit("timestampValidBits", &properties->timestampValidBits) &&
731 visitor->Visit("minImageTransferGranularity", &properties->minImageTransferGranularity);
732 }
733
734 template <typename Visitor>
Iterate(Visitor * visitor,VkExtensionProperties * properties)735 inline bool Iterate(Visitor* visitor, VkExtensionProperties* properties) {
736 return
737 visitor->Visit("extensionName", &properties->extensionName) &&
738 visitor->Visit("specVersion", &properties->specVersion);
739 }
740
741 template <typename Visitor>
Iterate(Visitor * visitor,VkLayerProperties * properties)742 inline bool Iterate(Visitor* visitor, VkLayerProperties* properties) {
743 return
744 visitor->Visit("layerName", &properties->layerName) &&
745 visitor->Visit("specVersion", &properties->specVersion) &&
746 visitor->Visit("implementationVersion", &properties->implementationVersion) &&
747 visitor->Visit("description", &properties->description);
748 }
749
750 template <typename Visitor>
Iterate(Visitor * visitor,VkFormatProperties * properties)751 inline bool Iterate(Visitor* visitor, VkFormatProperties* properties) {
752 return
753 visitor->Visit("linearTilingFeatures", &properties->linearTilingFeatures) &&
754 visitor->Visit("optimalTilingFeatures", &properties->optimalTilingFeatures) &&
755 visitor->Visit("bufferFeatures", &properties->bufferFeatures);
756 }
757
758 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonLayer * layer)759 inline bool Iterate(Visitor* visitor, VkJsonLayer* layer) {
760 return visitor->Visit("properties", &layer->properties) &&
761 visitor->Visit("extensions", &layer->extensions);
762 }
763
764 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonDeviceGroup * device_group)765 inline bool Iterate(Visitor* visitor, VkJsonDeviceGroup* device_group) {
766 return visitor->Visit("devices", &device_group->device_inds) &&
767 visitor->Visit("subsetAllocation",
768 &device_group->properties.subsetAllocation);
769 }
770
771 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonDevice * device)772 inline bool Iterate(Visitor* visitor, VkJsonDevice* device) {
773 bool ret = true;
774 switch (device->properties.apiVersion ^
775 VK_VERSION_PATCH(device->properties.apiVersion)) {
776 case VK_API_VERSION_1_1:
777 ret &=
778 visitor->Visit("subgroupProperties", &device->subgroup_properties) &&
779 visitor->Visit("pointClippingProperties",
780 &device->point_clipping_properties) &&
781 visitor->Visit("multiviewProperties",
782 &device->multiview_properties) &&
783 visitor->Visit("idProperties", &device->id_properties) &&
784 visitor->Visit("maintenance3Properties",
785 &device->maintenance3_properties) &&
786 visitor->Visit("16bitStorageFeatures",
787 &device->bit16_storage_features) &&
788 visitor->Visit("multiviewFeatures", &device->multiview_features) &&
789 visitor->Visit("variablePointerFeatures",
790 &device->variable_pointer_features) &&
791 visitor->Visit("protectedMemoryFeatures",
792 &device->protected_memory_features) &&
793 visitor->Visit("samplerYcbcrConversionFeatures",
794 &device->sampler_ycbcr_conversion_features) &&
795 visitor->Visit("shaderDrawParameterFeatures",
796 &device->shader_draw_parameter_features) &&
797 visitor->Visit("externalFenceProperties",
798 &device->external_fence_properties) &&
799 visitor->Visit("externalSemaphoreProperties",
800 &device->external_semaphore_properties);
801 FALLTHROUGH_INTENDED;
802 case VK_API_VERSION_1_0:
803 ret &= visitor->Visit("properties", &device->properties) &&
804 visitor->Visit("features", &device->features) &&
805 visitor->Visit("memory", &device->memory) &&
806 visitor->Visit("queues", &device->queues) &&
807 visitor->Visit("extensions", &device->extensions) &&
808 visitor->Visit("layers", &device->layers) &&
809 visitor->Visit("formats", &device->formats);
810 if (device->ext_driver_properties.reported) {
811 ret &= visitor->Visit("VK_KHR_driver_properties",
812 &device->ext_driver_properties);
813 }
814 if (device->ext_variable_pointer_features.reported) {
815 ret &= visitor->Visit("VK_KHR_variable_pointers",
816 &device->ext_variable_pointer_features);
817 }
818 }
819 return ret;
820 }
821
822 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonInstance * instance)823 inline bool Iterate(Visitor* visitor, VkJsonInstance* instance) {
824 bool ret = true;
825 switch (instance->api_version ^ VK_VERSION_PATCH(instance->api_version)) {
826 case VK_API_VERSION_1_1:
827 ret &= visitor->Visit("deviceGroups", &instance->device_groups);
828 FALLTHROUGH_INTENDED;
829 case VK_API_VERSION_1_0:
830 ret &= visitor->Visit("layers", &instance->layers) &&
831 visitor->Visit("extensions", &instance->extensions) &&
832 visitor->Visit("devices", &instance->devices);
833 }
834 return ret;
835 }
836
837 template <typename T>
838 using EnableForArithmetic =
839 typename std::enable_if<std::is_arithmetic<T>::value, void>::type;
840
841 template <typename T>
842 using EnableForStruct =
843 typename std::enable_if<std::is_class<T>::value, void>::type;
844
845 template <typename T>
846 using EnableForEnum =
847 typename std::enable_if<std::is_enum<T>::value, void>::type;
848
849 template <typename T, typename = EnableForStruct<T>, typename = void>
850 Json::Value ToJsonValue(const T& value);
851
852 template <typename T, typename = EnableForArithmetic<T>>
ToJsonValue(const T & value)853 inline Json::Value ToJsonValue(const T& value) {
854 return Json::Value(static_cast<double>(value));
855 }
856
ToJsonValue(const uint64_t & value)857 inline Json::Value ToJsonValue(const uint64_t& value) {
858 char string[19] = {0}; // "0x" + 16 digits + terminal \0
859 snprintf(string, sizeof(string), "0x%016" PRIx64, value);
860 return Json::Value(string);
861 }
862
863 template <typename T, typename = EnableForEnum<T>, typename = void,
864 typename = void>
ToJsonValue(const T & value)865 inline Json::Value ToJsonValue(const T& value) {
866 return Json::Value(static_cast<double>(value));
867 }
868
869 template <typename T>
ArrayToJsonValue(uint32_t count,const T * values)870 inline Json::Value ArrayToJsonValue(uint32_t count, const T* values) {
871 Json::Value array(Json::arrayValue);
872 for (unsigned int i = 0; i < count; ++i) array.append(ToJsonValue(values[i]));
873 return array;
874 }
875
876 template <typename T, unsigned int N>
ToJsonValue(const T (& value)[N])877 inline Json::Value ToJsonValue(const T (&value)[N]) {
878 return ArrayToJsonValue(N, value);
879 }
880
881 template <size_t N>
ToJsonValue(const char (& value)[N])882 inline Json::Value ToJsonValue(const char (&value)[N]) {
883 assert(strlen(value) < N);
884 return Json::Value(value);
885 }
886
887 template <typename T>
ToJsonValue(const std::vector<T> & value)888 inline Json::Value ToJsonValue(const std::vector<T>& value) {
889 assert(value.size() <= std::numeric_limits<uint32_t>::max());
890 return ArrayToJsonValue(static_cast<uint32_t>(value.size()), value.data());
891 }
892
893 template <typename F, typename S>
ToJsonValue(const std::pair<F,S> & value)894 inline Json::Value ToJsonValue(const std::pair<F, S>& value) {
895 Json::Value array(Json::arrayValue);
896 array.append(ToJsonValue(value.first));
897 array.append(ToJsonValue(value.second));
898 return array;
899 }
900
901 template <typename F, typename S>
ToJsonValue(const std::map<F,S> & value)902 inline Json::Value ToJsonValue(const std::map<F, S>& value) {
903 Json::Value array(Json::arrayValue);
904 for (auto& kv : value) array.append(ToJsonValue(kv));
905 return array;
906 }
907
908 class JsonWriterVisitor {
909 public:
JsonWriterVisitor()910 JsonWriterVisitor() : object_(Json::objectValue) {}
911
~JsonWriterVisitor()912 ~JsonWriterVisitor() {}
913
Visit(const char * key,const T * value)914 template <typename T> bool Visit(const char* key, const T* value) {
915 object_[key] = ToJsonValue(*value);
916 return true;
917 }
918
919 template <typename T, uint32_t N>
VisitArray(const char * key,uint32_t count,const T (* value)[N])920 bool VisitArray(const char* key, uint32_t count, const T (*value)[N]) {
921 assert(count <= N);
922 object_[key] = ArrayToJsonValue(count, *value);
923 return true;
924 }
925
get_object() const926 Json::Value get_object() const { return object_; }
927
928 private:
929 Json::Value object_;
930 };
931
932 template <typename Visitor, typename T>
VisitForWrite(Visitor * visitor,const T & t)933 inline void VisitForWrite(Visitor* visitor, const T& t) {
934 Iterate(visitor, const_cast<T*>(&t));
935 }
936
937 template <typename T, typename /*= EnableForStruct<T>*/, typename /*= void*/>
ToJsonValue(const T & value)938 Json::Value ToJsonValue(const T& value) {
939 JsonWriterVisitor visitor;
940 VisitForWrite(&visitor, value);
941 return visitor.get_object();
942 }
943
944 template <typename T, typename = EnableForStruct<T>>
945 bool AsValue(Json::Value* json_value, T* t);
946
AsValue(Json::Value * json_value,int32_t * value)947 inline bool AsValue(Json::Value* json_value, int32_t* value) {
948 if (json_value->type() != Json::realValue) return false;
949 double d = json_value->asDouble();
950 if (!IsIntegral(d) ||
951 d < static_cast<double>(std::numeric_limits<int32_t>::min()) ||
952 d > static_cast<double>(std::numeric_limits<int32_t>::max()))
953 return false;
954 *value = static_cast<int32_t>(d);
955 return true;
956 }
957
AsValue(Json::Value * json_value,uint64_t * value)958 inline bool AsValue(Json::Value* json_value, uint64_t* value) {
959 if (json_value->type() != Json::stringValue) return false;
960 int result =
961 std::sscanf(json_value->asString().c_str(), "0x%016" PRIx64, value);
962 return result == 1;
963 }
964
AsValue(Json::Value * json_value,uint32_t * value)965 inline bool AsValue(Json::Value* json_value, uint32_t* value) {
966 if (json_value->type() != Json::realValue) return false;
967 double d = json_value->asDouble();
968 if (!IsIntegral(d) || d < 0.0 ||
969 d > static_cast<double>(std::numeric_limits<uint32_t>::max()))
970 return false;
971 *value = static_cast<uint32_t>(d);
972 return true;
973 }
974
AsValue(Json::Value * json_value,uint8_t * value)975 inline bool AsValue(Json::Value* json_value, uint8_t* value) {
976 uint32_t value32 = 0;
977 AsValue(json_value, &value32);
978 if (value32 > std::numeric_limits<uint8_t>::max())
979 return false;
980 *value = static_cast<uint8_t>(value32);
981 return true;
982 }
983
AsValue(Json::Value * json_value,float * value)984 inline bool AsValue(Json::Value* json_value, float* value) {
985 if (json_value->type() != Json::realValue) return false;
986 *value = static_cast<float>(json_value->asDouble());
987 return true;
988 }
989
990 template <typename T>
AsArray(Json::Value * json_value,uint32_t count,T * values)991 inline bool AsArray(Json::Value* json_value, uint32_t count, T* values) {
992 if (json_value->type() != Json::arrayValue || json_value->size() != count)
993 return false;
994 for (uint32_t i = 0; i < count; ++i) {
995 if (!AsValue(&(*json_value)[i], values + i)) return false;
996 }
997 return true;
998 }
999
1000 template <typename T, unsigned int N>
AsValue(Json::Value * json_value,T (* value)[N])1001 inline bool AsValue(Json::Value* json_value, T (*value)[N]) {
1002 return AsArray(json_value, N, *value);
1003 }
1004
1005 template <size_t N>
AsValue(Json::Value * json_value,char (* value)[N])1006 inline bool AsValue(Json::Value* json_value, char (*value)[N]) {
1007 if (json_value->type() != Json::stringValue) return false;
1008 size_t len = json_value->asString().length();
1009 if (len >= N)
1010 return false;
1011 memcpy(*value, json_value->asString().c_str(), len);
1012 memset(*value + len, 0, N-len);
1013 return true;
1014 }
1015
1016 template <typename T, typename = EnableForEnum<T>, typename = void>
AsValue(Json::Value * json_value,T * t)1017 inline bool AsValue(Json::Value* json_value, T* t) {
1018 uint32_t value = 0;
1019 if (!AsValue(json_value, &value))
1020 return false;
1021 if (!EnumTraits<T>::exist(value)) return false;
1022 *t = static_cast<T>(value);
1023 return true;
1024 }
1025
1026 template <typename T>
AsValue(Json::Value * json_value,std::vector<T> * value)1027 inline bool AsValue(Json::Value* json_value, std::vector<T>* value) {
1028 if (json_value->type() != Json::arrayValue) return false;
1029 int size = json_value->size();
1030 value->resize(size);
1031 return AsArray(json_value, size, value->data());
1032 }
1033
1034 template <typename F, typename S>
AsValue(Json::Value * json_value,std::pair<F,S> * value)1035 inline bool AsValue(Json::Value* json_value, std::pair<F, S>* value) {
1036 if (json_value->type() != Json::arrayValue || json_value->size() != 2)
1037 return false;
1038 return AsValue(&(*json_value)[0], &value->first) &&
1039 AsValue(&(*json_value)[1], &value->second);
1040 }
1041
1042 template <typename F, typename S>
AsValue(Json::Value * json_value,std::map<F,S> * value)1043 inline bool AsValue(Json::Value* json_value, std::map<F, S>* value) {
1044 if (json_value->type() != Json::arrayValue) return false;
1045 int size = json_value->size();
1046 for (int i = 0; i < size; ++i) {
1047 std::pair<F, S> elem;
1048 if (!AsValue(&(*json_value)[i], &elem)) return false;
1049 if (!value->insert(elem).second)
1050 return false;
1051 }
1052 return true;
1053 }
1054
1055 template <typename T>
ReadValue(Json::Value * object,const char * key,T * value,std::string * errors)1056 bool ReadValue(Json::Value* object, const char* key, T* value,
1057 std::string* errors) {
1058 Json::Value json_value = (*object)[key];
1059 if (!json_value) {
1060 if (errors)
1061 *errors = std::string(key) + " missing.";
1062 return false;
1063 }
1064 if (AsValue(&json_value, value)) return true;
1065 if (errors)
1066 *errors = std::string("Wrong type for ") + std::string(key) + ".";
1067 return false;
1068 }
1069
1070 template <typename Visitor, typename T>
VisitForRead(Visitor * visitor,T * t)1071 inline bool VisitForRead(Visitor* visitor, T* t) {
1072 return Iterate(visitor, t);
1073 }
1074
1075 class JsonReaderVisitor {
1076 public:
JsonReaderVisitor(Json::Value * object,std::string * errors)1077 JsonReaderVisitor(Json::Value* object, std::string* errors)
1078 : object_(object), errors_(errors) {}
1079
Visit(const char * key,T * value) const1080 template <typename T> bool Visit(const char* key, T* value) const {
1081 return ReadValue(object_, key, value, errors_);
1082 }
1083
1084 template <typename T, uint32_t N>
VisitArray(const char * key,uint32_t count,T (* value)[N])1085 bool VisitArray(const char* key, uint32_t count, T (*value)[N]) {
1086 if (count > N)
1087 return false;
1088 Json::Value json_value = (*object_)[key];
1089 if (!json_value) {
1090 if (errors_)
1091 *errors_ = std::string(key) + " missing.";
1092 return false;
1093 }
1094 if (AsArray(&json_value, count, *value)) return true;
1095 if (errors_)
1096 *errors_ = std::string("Wrong type for ") + std::string(key) + ".";
1097 return false;
1098 }
1099
1100
1101 private:
1102 Json::Value* object_;
1103 std::string* errors_;
1104 };
1105
1106 template <typename T, typename /*= EnableForStruct<T>*/>
AsValue(Json::Value * json_value,T * t)1107 bool AsValue(Json::Value* json_value, T* t) {
1108 if (json_value->type() != Json::objectValue) return false;
1109 JsonReaderVisitor visitor(json_value, nullptr);
1110 return VisitForRead(&visitor, t);
1111 }
1112
1113
VkTypeToJson(const T & t)1114 template <typename T> std::string VkTypeToJson(const T& t) {
1115 JsonWriterVisitor visitor;
1116 VisitForWrite(&visitor, t);
1117 return visitor.get_object().toStyledString();
1118 }
1119
VkTypeFromJson(const std::string & json,T * t,std::string * errors)1120 template <typename T> bool VkTypeFromJson(const std::string& json,
1121 T* t,
1122 std::string* errors) {
1123 *t = T();
1124 Json::Value object(Json::objectValue);
1125 Json::Reader reader;
1126 reader.parse(json, object, false);
1127 if (!object) {
1128 if (errors) errors->assign(reader.getFormatedErrorMessages());
1129 return false;
1130 }
1131 return AsValue(&object, t);
1132 }
1133
1134 } // anonymous namespace
1135
VkJsonInstanceToJson(const VkJsonInstance & instance)1136 std::string VkJsonInstanceToJson(const VkJsonInstance& instance) {
1137 return VkTypeToJson(instance);
1138 }
1139
VkJsonInstanceFromJson(const std::string & json,VkJsonInstance * instance,std::string * errors)1140 bool VkJsonInstanceFromJson(const std::string& json,
1141 VkJsonInstance* instance,
1142 std::string* errors) {
1143 return VkTypeFromJson(json, instance, errors);
1144 }
1145
VkJsonDeviceToJson(const VkJsonDevice & device)1146 std::string VkJsonDeviceToJson(const VkJsonDevice& device) {
1147 return VkTypeToJson(device);
1148 }
1149
VkJsonDeviceFromJson(const std::string & json,VkJsonDevice * device,std::string * errors)1150 bool VkJsonDeviceFromJson(const std::string& json,
1151 VkJsonDevice* device,
1152 std::string* errors) {
1153 return VkTypeFromJson(json, device, errors);
1154 };
1155
VkJsonImageFormatPropertiesToJson(const VkImageFormatProperties & properties)1156 std::string VkJsonImageFormatPropertiesToJson(
1157 const VkImageFormatProperties& properties) {
1158 return VkTypeToJson(properties);
1159 }
1160
VkJsonImageFormatPropertiesFromJson(const std::string & json,VkImageFormatProperties * properties,std::string * errors)1161 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
1162 VkImageFormatProperties* properties,
1163 std::string* errors) {
1164 return VkTypeFromJson(json, properties, errors);
1165 };
1166