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 <stdlib.h>
25 #include <string.h>
26 
27 #include <json/json.h>
28 
29 #include <algorithm>
30 #include <cinttypes>
31 #include <cmath>
32 #include <cstdio>
33 #include <limits>
34 #include <memory>
35 #include <sstream>
36 #include <type_traits>
37 #include <utility>
38 
39 namespace {
40 
IsIntegral(double value)41 inline bool IsIntegral(double value) {
42 #if defined(ANDROID)
43   // Android NDK doesn't provide std::trunc yet
44   return trunc(value) == value;
45 #else
46   return std::trunc(value) == value;
47 #endif
48 }
49 
50 // Floating point fields of Vulkan structure use single precision. The string
51 // output of max double value in c++ will be larger than Java double's infinity
52 // value. Below fake double max/min values are only to serve the safe json text
53 // parsing in between C++ and Java, becasue Java json library simply cannot
54 // handle infinity.
55 static const double SAFE_DOUBLE_MAX = 0.99 * std::numeric_limits<double>::max();
56 static const double SAFE_DOUBLE_MIN = -SAFE_DOUBLE_MAX;
57 
58 template <typename T> struct EnumTraits;
59 template <> struct EnumTraits<VkPhysicalDeviceType> {
exist__anonaa66467e0111::EnumTraits60   static bool exist(uint32_t e) {
61     switch (e) {
62       case VK_PHYSICAL_DEVICE_TYPE_OTHER:
63       case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
64       case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
65       case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
66       case VK_PHYSICAL_DEVICE_TYPE_CPU:
67         return true;
68     }
69     return false;
70   }
71 };
72 
73 template <> struct EnumTraits<VkFormat> {
exist__anonaa66467e0111::EnumTraits74   static bool exist(uint32_t e) {
75     switch (e) {
76       case VK_FORMAT_UNDEFINED:
77       case VK_FORMAT_R4G4_UNORM_PACK8:
78       case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
79       case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
80       case VK_FORMAT_R5G6B5_UNORM_PACK16:
81       case VK_FORMAT_B5G6R5_UNORM_PACK16:
82       case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
83       case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
84       case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
85       case VK_FORMAT_R8_UNORM:
86       case VK_FORMAT_R8_SNORM:
87       case VK_FORMAT_R8_USCALED:
88       case VK_FORMAT_R8_SSCALED:
89       case VK_FORMAT_R8_UINT:
90       case VK_FORMAT_R8_SINT:
91       case VK_FORMAT_R8_SRGB:
92       case VK_FORMAT_R8G8_UNORM:
93       case VK_FORMAT_R8G8_SNORM:
94       case VK_FORMAT_R8G8_USCALED:
95       case VK_FORMAT_R8G8_SSCALED:
96       case VK_FORMAT_R8G8_UINT:
97       case VK_FORMAT_R8G8_SINT:
98       case VK_FORMAT_R8G8_SRGB:
99       case VK_FORMAT_R8G8B8_UNORM:
100       case VK_FORMAT_R8G8B8_SNORM:
101       case VK_FORMAT_R8G8B8_USCALED:
102       case VK_FORMAT_R8G8B8_SSCALED:
103       case VK_FORMAT_R8G8B8_UINT:
104       case VK_FORMAT_R8G8B8_SINT:
105       case VK_FORMAT_R8G8B8_SRGB:
106       case VK_FORMAT_B8G8R8_UNORM:
107       case VK_FORMAT_B8G8R8_SNORM:
108       case VK_FORMAT_B8G8R8_USCALED:
109       case VK_FORMAT_B8G8R8_SSCALED:
110       case VK_FORMAT_B8G8R8_UINT:
111       case VK_FORMAT_B8G8R8_SINT:
112       case VK_FORMAT_B8G8R8_SRGB:
113       case VK_FORMAT_R8G8B8A8_UNORM:
114       case VK_FORMAT_R8G8B8A8_SNORM:
115       case VK_FORMAT_R8G8B8A8_USCALED:
116       case VK_FORMAT_R8G8B8A8_SSCALED:
117       case VK_FORMAT_R8G8B8A8_UINT:
118       case VK_FORMAT_R8G8B8A8_SINT:
119       case VK_FORMAT_R8G8B8A8_SRGB:
120       case VK_FORMAT_B8G8R8A8_UNORM:
121       case VK_FORMAT_B8G8R8A8_SNORM:
122       case VK_FORMAT_B8G8R8A8_USCALED:
123       case VK_FORMAT_B8G8R8A8_SSCALED:
124       case VK_FORMAT_B8G8R8A8_UINT:
125       case VK_FORMAT_B8G8R8A8_SINT:
126       case VK_FORMAT_B8G8R8A8_SRGB:
127       case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
128       case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
129       case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
130       case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
131       case VK_FORMAT_A8B8G8R8_UINT_PACK32:
132       case VK_FORMAT_A8B8G8R8_SINT_PACK32:
133       case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
134       case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
135       case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
136       case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
137       case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
138       case VK_FORMAT_A2R10G10B10_UINT_PACK32:
139       case VK_FORMAT_A2R10G10B10_SINT_PACK32:
140       case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
141       case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
142       case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
143       case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
144       case VK_FORMAT_A2B10G10R10_UINT_PACK32:
145       case VK_FORMAT_A2B10G10R10_SINT_PACK32:
146       case VK_FORMAT_R16_UNORM:
147       case VK_FORMAT_R16_SNORM:
148       case VK_FORMAT_R16_USCALED:
149       case VK_FORMAT_R16_SSCALED:
150       case VK_FORMAT_R16_UINT:
151       case VK_FORMAT_R16_SINT:
152       case VK_FORMAT_R16_SFLOAT:
153       case VK_FORMAT_R16G16_UNORM:
154       case VK_FORMAT_R16G16_SNORM:
155       case VK_FORMAT_R16G16_USCALED:
156       case VK_FORMAT_R16G16_SSCALED:
157       case VK_FORMAT_R16G16_UINT:
158       case VK_FORMAT_R16G16_SINT:
159       case VK_FORMAT_R16G16_SFLOAT:
160       case VK_FORMAT_R16G16B16_UNORM:
161       case VK_FORMAT_R16G16B16_SNORM:
162       case VK_FORMAT_R16G16B16_USCALED:
163       case VK_FORMAT_R16G16B16_SSCALED:
164       case VK_FORMAT_R16G16B16_UINT:
165       case VK_FORMAT_R16G16B16_SINT:
166       case VK_FORMAT_R16G16B16_SFLOAT:
167       case VK_FORMAT_R16G16B16A16_UNORM:
168       case VK_FORMAT_R16G16B16A16_SNORM:
169       case VK_FORMAT_R16G16B16A16_USCALED:
170       case VK_FORMAT_R16G16B16A16_SSCALED:
171       case VK_FORMAT_R16G16B16A16_UINT:
172       case VK_FORMAT_R16G16B16A16_SINT:
173       case VK_FORMAT_R16G16B16A16_SFLOAT:
174       case VK_FORMAT_R32_UINT:
175       case VK_FORMAT_R32_SINT:
176       case VK_FORMAT_R32_SFLOAT:
177       case VK_FORMAT_R32G32_UINT:
178       case VK_FORMAT_R32G32_SINT:
179       case VK_FORMAT_R32G32_SFLOAT:
180       case VK_FORMAT_R32G32B32_UINT:
181       case VK_FORMAT_R32G32B32_SINT:
182       case VK_FORMAT_R32G32B32_SFLOAT:
183       case VK_FORMAT_R32G32B32A32_UINT:
184       case VK_FORMAT_R32G32B32A32_SINT:
185       case VK_FORMAT_R32G32B32A32_SFLOAT:
186       case VK_FORMAT_R64_UINT:
187       case VK_FORMAT_R64_SINT:
188       case VK_FORMAT_R64_SFLOAT:
189       case VK_FORMAT_R64G64_UINT:
190       case VK_FORMAT_R64G64_SINT:
191       case VK_FORMAT_R64G64_SFLOAT:
192       case VK_FORMAT_R64G64B64_UINT:
193       case VK_FORMAT_R64G64B64_SINT:
194       case VK_FORMAT_R64G64B64_SFLOAT:
195       case VK_FORMAT_R64G64B64A64_UINT:
196       case VK_FORMAT_R64G64B64A64_SINT:
197       case VK_FORMAT_R64G64B64A64_SFLOAT:
198       case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
199       case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
200       case VK_FORMAT_D16_UNORM:
201       case VK_FORMAT_X8_D24_UNORM_PACK32:
202       case VK_FORMAT_D32_SFLOAT:
203       case VK_FORMAT_S8_UINT:
204       case VK_FORMAT_D16_UNORM_S8_UINT:
205       case VK_FORMAT_D24_UNORM_S8_UINT:
206       case VK_FORMAT_D32_SFLOAT_S8_UINT:
207       case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
208       case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
209       case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
210       case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
211       case VK_FORMAT_BC2_UNORM_BLOCK:
212       case VK_FORMAT_BC2_SRGB_BLOCK:
213       case VK_FORMAT_BC3_UNORM_BLOCK:
214       case VK_FORMAT_BC3_SRGB_BLOCK:
215       case VK_FORMAT_BC4_UNORM_BLOCK:
216       case VK_FORMAT_BC4_SNORM_BLOCK:
217       case VK_FORMAT_BC5_UNORM_BLOCK:
218       case VK_FORMAT_BC5_SNORM_BLOCK:
219       case VK_FORMAT_BC6H_UFLOAT_BLOCK:
220       case VK_FORMAT_BC6H_SFLOAT_BLOCK:
221       case VK_FORMAT_BC7_UNORM_BLOCK:
222       case VK_FORMAT_BC7_SRGB_BLOCK:
223       case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
224       case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
225       case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
226       case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
227       case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
228       case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
229       case VK_FORMAT_EAC_R11_UNORM_BLOCK:
230       case VK_FORMAT_EAC_R11_SNORM_BLOCK:
231       case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
232       case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
233       case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
234       case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
235       case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
236       case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
237       case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
238       case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
239       case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
240       case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
241       case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
242       case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
243       case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
244       case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
245       case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
246       case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
247       case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
248       case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
249       case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
250       case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
251       case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
252       case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
253       case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
254       case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
255       case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
256       case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
257       case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
258       case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
259       case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
260       case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
261       case VK_FORMAT_G8B8G8R8_422_UNORM:
262       case VK_FORMAT_B8G8R8G8_422_UNORM:
263       case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
264       case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
265       case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
266       case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
267       case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
268       case VK_FORMAT_R10X6_UNORM_PACK16:
269       case VK_FORMAT_R10X6G10X6_UNORM_2PACK16:
270       case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16:
271       case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16:
272       case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16:
273       case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
274       case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
275       case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
276       case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
277       case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
278       case VK_FORMAT_R12X4_UNORM_PACK16:
279       case VK_FORMAT_R12X4G12X4_UNORM_2PACK16:
280       case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16:
281       case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16:
282       case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16:
283       case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
284       case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
285       case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
286       case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
287       case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
288       case VK_FORMAT_G16B16G16R16_422_UNORM:
289       case VK_FORMAT_B16G16R16G16_422_UNORM:
290       case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
291       case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
292       case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
293       case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
294       case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
295       case VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG:
296       case VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG:
297       case VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG:
298       case VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG:
299       case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG:
300       case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG:
301       case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG:
302       case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG:
303       case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT:
304       case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK_EXT:
305       case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK_EXT:
306       case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK_EXT:
307       case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK_EXT:
308       case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK_EXT:
309       case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK_EXT:
310       case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK_EXT:
311       case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK_EXT:
312       case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK_EXT:
313       case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK_EXT:
314       case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK_EXT:
315       case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK_EXT:
316       case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT:
317       case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
318       case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
319         return true;
320     }
321     return false;
322   }
323 };
324 
325 template <>
326 struct EnumTraits<VkPointClippingBehavior> {
exist__anonaa66467e0111::EnumTraits327   static bool exist(uint32_t e) {
328     switch (e) {
329       case VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES:
330       case VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY:
331         return true;
332     }
333     return false;
334   }
335 };
336 
337 template <>
338 struct EnumTraits<VkExternalFenceHandleTypeFlagBits> {
exist__anonaa66467e0111::EnumTraits339   static bool exist(uint32_t e) {
340     switch (e) {
341       case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT:
342       case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT:
343       case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT:
344       case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT:
345         return true;
346     }
347     return false;
348   }
349 };
350 
351 template <>
352 struct EnumTraits<VkExternalSemaphoreHandleTypeFlagBits> {
exist__anonaa66467e0111::EnumTraits353   static bool exist(uint32_t e) {
354     switch (e) {
355       case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT:
356       case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT:
357       case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT:
358       case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT:
359       case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT:
360         return true;
361     }
362     return false;
363   }
364 };
365 
366 template <>
367 struct EnumTraits<VkDriverIdKHR> {
exist__anonaa66467e0111::EnumTraits368   static bool exist(uint32_t e) {
369     switch (e) {
370       case VK_DRIVER_ID_AMD_PROPRIETARY:
371       case VK_DRIVER_ID_AMD_OPEN_SOURCE:
372       case VK_DRIVER_ID_MESA_RADV:
373       case VK_DRIVER_ID_NVIDIA_PROPRIETARY:
374       case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS:
375       case VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA:
376       case VK_DRIVER_ID_IMAGINATION_PROPRIETARY:
377       case VK_DRIVER_ID_QUALCOMM_PROPRIETARY:
378       case VK_DRIVER_ID_ARM_PROPRIETARY:
379       case VK_DRIVER_ID_GOOGLE_SWIFTSHADER:
380       case VK_DRIVER_ID_GGP_PROPRIETARY:
381       case VK_DRIVER_ID_BROADCOM_PROPRIETARY:
382       case VK_DRIVER_ID_MESA_LLVMPIPE:
383       case VK_DRIVER_ID_MOLTENVK:
384         return true;
385     }
386     return false;
387   }
388 };
389 
390 template <>
391 struct EnumTraits<VkShaderFloatControlsIndependence> {
exist__anonaa66467e0111::EnumTraits392   static bool exist(uint32_t e) {
393     switch (e) {
394       case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
395       case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
396       case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
397         return true;
398     }
399     return false;
400   }
401 };
402 
403 // VkSparseImageFormatProperties
404 
405 template <typename Visitor>
Iterate(Visitor * visitor,VkExtent3D * extents)406 inline bool Iterate(Visitor* visitor, VkExtent3D* extents) {
407   return
408     visitor->Visit("width", &extents->width) &&
409     visitor->Visit("height", &extents->height) &&
410     visitor->Visit("depth", &extents->depth);
411 }
412 
413 template <typename Visitor>
Iterate(Visitor * visitor,VkImageFormatProperties * properties)414 inline bool Iterate(Visitor* visitor, VkImageFormatProperties* properties) {
415   return
416     visitor->Visit("maxExtent", &properties->maxExtent) &&
417     visitor->Visit("maxMipLevels", &properties->maxMipLevels) &&
418     visitor->Visit("maxArrayLayers", &properties->maxArrayLayers) &&
419     visitor->Visit("sampleCounts", &properties->sampleCounts) &&
420     visitor->Visit("maxResourceSize", &properties->maxResourceSize);
421 }
422 
423 // clang-format off
424 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceLimits * limits)425 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceLimits* limits) {
426   return
427     visitor->Visit("maxImageDimension1D", &limits->maxImageDimension1D) &&
428     visitor->Visit("maxImageDimension2D", &limits->maxImageDimension2D) &&
429     visitor->Visit("maxImageDimension3D", &limits->maxImageDimension3D) &&
430     visitor->Visit("maxImageDimensionCube", &limits->maxImageDimensionCube) &&
431     visitor->Visit("maxImageArrayLayers", &limits->maxImageArrayLayers) &&
432     visitor->Visit("maxTexelBufferElements", &limits->maxTexelBufferElements) &&
433     visitor->Visit("maxUniformBufferRange", &limits->maxUniformBufferRange) &&
434     visitor->Visit("maxStorageBufferRange", &limits->maxStorageBufferRange) &&
435     visitor->Visit("maxPushConstantsSize", &limits->maxPushConstantsSize) &&
436     visitor->Visit("maxMemoryAllocationCount", &limits->maxMemoryAllocationCount) &&
437     visitor->Visit("maxSamplerAllocationCount", &limits->maxSamplerAllocationCount) &&
438     visitor->Visit("bufferImageGranularity", &limits->bufferImageGranularity) &&
439     visitor->Visit("sparseAddressSpaceSize", &limits->sparseAddressSpaceSize) &&
440     visitor->Visit("maxBoundDescriptorSets", &limits->maxBoundDescriptorSets) &&
441     visitor->Visit("maxPerStageDescriptorSamplers", &limits->maxPerStageDescriptorSamplers) &&
442     visitor->Visit("maxPerStageDescriptorUniformBuffers", &limits->maxPerStageDescriptorUniformBuffers) &&
443     visitor->Visit("maxPerStageDescriptorStorageBuffers", &limits->maxPerStageDescriptorStorageBuffers) &&
444     visitor->Visit("maxPerStageDescriptorSampledImages", &limits->maxPerStageDescriptorSampledImages) &&
445     visitor->Visit("maxPerStageDescriptorStorageImages", &limits->maxPerStageDescriptorStorageImages) &&
446     visitor->Visit("maxPerStageDescriptorInputAttachments", &limits->maxPerStageDescriptorInputAttachments) &&
447     visitor->Visit("maxPerStageResources", &limits->maxPerStageResources) &&
448     visitor->Visit("maxDescriptorSetSamplers", &limits->maxDescriptorSetSamplers) &&
449     visitor->Visit("maxDescriptorSetUniformBuffers", &limits->maxDescriptorSetUniformBuffers) &&
450     visitor->Visit("maxDescriptorSetUniformBuffersDynamic", &limits->maxDescriptorSetUniformBuffersDynamic) &&
451     visitor->Visit("maxDescriptorSetStorageBuffers", &limits->maxDescriptorSetStorageBuffers) &&
452     visitor->Visit("maxDescriptorSetStorageBuffersDynamic", &limits->maxDescriptorSetStorageBuffersDynamic) &&
453     visitor->Visit("maxDescriptorSetSampledImages", &limits->maxDescriptorSetSampledImages) &&
454     visitor->Visit("maxDescriptorSetStorageImages", &limits->maxDescriptorSetStorageImages) &&
455     visitor->Visit("maxDescriptorSetInputAttachments", &limits->maxDescriptorSetInputAttachments) &&
456     visitor->Visit("maxVertexInputAttributes", &limits->maxVertexInputAttributes) &&
457     visitor->Visit("maxVertexInputBindings", &limits->maxVertexInputBindings) &&
458     visitor->Visit("maxVertexInputAttributeOffset", &limits->maxVertexInputAttributeOffset) &&
459     visitor->Visit("maxVertexInputBindingStride", &limits->maxVertexInputBindingStride) &&
460     visitor->Visit("maxVertexOutputComponents", &limits->maxVertexOutputComponents) &&
461     visitor->Visit("maxTessellationGenerationLevel", &limits->maxTessellationGenerationLevel) &&
462     visitor->Visit("maxTessellationPatchSize", &limits->maxTessellationPatchSize) &&
463     visitor->Visit("maxTessellationControlPerVertexInputComponents", &limits->maxTessellationControlPerVertexInputComponents) &&
464     visitor->Visit("maxTessellationControlPerVertexOutputComponents", &limits->maxTessellationControlPerVertexOutputComponents) &&
465     visitor->Visit("maxTessellationControlPerPatchOutputComponents", &limits->maxTessellationControlPerPatchOutputComponents) &&
466     visitor->Visit("maxTessellationControlTotalOutputComponents", &limits->maxTessellationControlTotalOutputComponents) &&
467     visitor->Visit("maxTessellationEvaluationInputComponents", &limits->maxTessellationEvaluationInputComponents) &&
468     visitor->Visit("maxTessellationEvaluationOutputComponents", &limits->maxTessellationEvaluationOutputComponents) &&
469     visitor->Visit("maxGeometryShaderInvocations", &limits->maxGeometryShaderInvocations) &&
470     visitor->Visit("maxGeometryInputComponents", &limits->maxGeometryInputComponents) &&
471     visitor->Visit("maxGeometryOutputComponents", &limits->maxGeometryOutputComponents) &&
472     visitor->Visit("maxGeometryOutputVertices", &limits->maxGeometryOutputVertices) &&
473     visitor->Visit("maxGeometryTotalOutputComponents", &limits->maxGeometryTotalOutputComponents) &&
474     visitor->Visit("maxFragmentInputComponents", &limits->maxFragmentInputComponents) &&
475     visitor->Visit("maxFragmentOutputAttachments", &limits->maxFragmentOutputAttachments) &&
476     visitor->Visit("maxFragmentDualSrcAttachments", &limits->maxFragmentDualSrcAttachments) &&
477     visitor->Visit("maxFragmentCombinedOutputResources", &limits->maxFragmentCombinedOutputResources) &&
478     visitor->Visit("maxComputeSharedMemorySize", &limits->maxComputeSharedMemorySize) &&
479     visitor->Visit("maxComputeWorkGroupCount", &limits->maxComputeWorkGroupCount) &&
480     visitor->Visit("maxComputeWorkGroupInvocations", &limits->maxComputeWorkGroupInvocations) &&
481     visitor->Visit("maxComputeWorkGroupSize", &limits->maxComputeWorkGroupSize) &&
482     visitor->Visit("subPixelPrecisionBits", &limits->subPixelPrecisionBits) &&
483     visitor->Visit("subTexelPrecisionBits", &limits->subTexelPrecisionBits) &&
484     visitor->Visit("mipmapPrecisionBits", &limits->mipmapPrecisionBits) &&
485     visitor->Visit("maxDrawIndexedIndexValue", &limits->maxDrawIndexedIndexValue) &&
486     visitor->Visit("maxDrawIndirectCount", &limits->maxDrawIndirectCount) &&
487     visitor->Visit("maxSamplerLodBias", &limits->maxSamplerLodBias) &&
488     visitor->Visit("maxSamplerAnisotropy", &limits->maxSamplerAnisotropy) &&
489     visitor->Visit("maxViewports", &limits->maxViewports) &&
490     visitor->Visit("maxViewportDimensions", &limits->maxViewportDimensions) &&
491     visitor->Visit("viewportBoundsRange", &limits->viewportBoundsRange) &&
492     visitor->Visit("viewportSubPixelBits", &limits->viewportSubPixelBits) &&
493     visitor->Visit("minMemoryMapAlignment", &limits->minMemoryMapAlignment) &&
494     visitor->Visit("minTexelBufferOffsetAlignment", &limits->minTexelBufferOffsetAlignment) &&
495     visitor->Visit("minUniformBufferOffsetAlignment", &limits->minUniformBufferOffsetAlignment) &&
496     visitor->Visit("minStorageBufferOffsetAlignment", &limits->minStorageBufferOffsetAlignment) &&
497     visitor->Visit("minTexelOffset", &limits->minTexelOffset) &&
498     visitor->Visit("maxTexelOffset", &limits->maxTexelOffset) &&
499     visitor->Visit("minTexelGatherOffset", &limits->minTexelGatherOffset) &&
500     visitor->Visit("maxTexelGatherOffset", &limits->maxTexelGatherOffset) &&
501     visitor->Visit("minInterpolationOffset", &limits->minInterpolationOffset) &&
502     visitor->Visit("maxInterpolationOffset", &limits->maxInterpolationOffset) &&
503     visitor->Visit("subPixelInterpolationOffsetBits", &limits->subPixelInterpolationOffsetBits) &&
504     visitor->Visit("maxFramebufferWidth", &limits->maxFramebufferWidth) &&
505     visitor->Visit("maxFramebufferHeight", &limits->maxFramebufferHeight) &&
506     visitor->Visit("maxFramebufferLayers", &limits->maxFramebufferLayers) &&
507     visitor->Visit("framebufferColorSampleCounts", &limits->framebufferColorSampleCounts) &&
508     visitor->Visit("framebufferDepthSampleCounts", &limits->framebufferDepthSampleCounts) &&
509     visitor->Visit("framebufferStencilSampleCounts", &limits->framebufferStencilSampleCounts) &&
510     visitor->Visit("framebufferNoAttachmentsSampleCounts", &limits->framebufferNoAttachmentsSampleCounts) &&
511     visitor->Visit("maxColorAttachments", &limits->maxColorAttachments) &&
512     visitor->Visit("sampledImageColorSampleCounts", &limits->sampledImageColorSampleCounts) &&
513     visitor->Visit("sampledImageIntegerSampleCounts", &limits->sampledImageIntegerSampleCounts) &&
514     visitor->Visit("sampledImageDepthSampleCounts", &limits->sampledImageDepthSampleCounts) &&
515     visitor->Visit("sampledImageStencilSampleCounts", &limits->sampledImageStencilSampleCounts) &&
516     visitor->Visit("storageImageSampleCounts", &limits->storageImageSampleCounts) &&
517     visitor->Visit("maxSampleMaskWords", &limits->maxSampleMaskWords) &&
518     visitor->Visit("timestampComputeAndGraphics", &limits->timestampComputeAndGraphics) &&
519     visitor->Visit("timestampPeriod", &limits->timestampPeriod) &&
520     visitor->Visit("maxClipDistances", &limits->maxClipDistances) &&
521     visitor->Visit("maxCullDistances", &limits->maxCullDistances) &&
522     visitor->Visit("maxCombinedClipAndCullDistances", &limits->maxCombinedClipAndCullDistances) &&
523     visitor->Visit("discreteQueuePriorities", &limits->discreteQueuePriorities) &&
524     visitor->Visit("pointSizeRange", &limits->pointSizeRange) &&
525     visitor->Visit("lineWidthRange", &limits->lineWidthRange) &&
526     visitor->Visit("pointSizeGranularity", &limits->pointSizeGranularity) &&
527     visitor->Visit("lineWidthGranularity", &limits->lineWidthGranularity) &&
528     visitor->Visit("strictLines", &limits->strictLines) &&
529     visitor->Visit("standardSampleLocations", &limits->standardSampleLocations) &&
530     visitor->Visit("optimalBufferCopyOffsetAlignment", &limits->optimalBufferCopyOffsetAlignment) &&
531     visitor->Visit("optimalBufferCopyRowPitchAlignment", &limits->optimalBufferCopyRowPitchAlignment) &&
532     visitor->Visit("nonCoherentAtomSize", &limits->nonCoherentAtomSize);
533 }
534 
535 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceSparseProperties * properties)536 inline bool Iterate(Visitor* visitor,
537                     VkPhysicalDeviceSparseProperties* properties) {
538   return
539     visitor->Visit("residencyStandard2DBlockShape", &properties->residencyStandard2DBlockShape) &&
540     visitor->Visit("residencyStandard2DMultisampleBlockShape", &properties->residencyStandard2DMultisampleBlockShape) &&
541     visitor->Visit("residencyStandard3DBlockShape", &properties->residencyStandard3DBlockShape) &&
542     visitor->Visit("residencyAlignedMipSize", &properties->residencyAlignedMipSize) &&
543     visitor->Visit("residencyNonResidentStrict", &properties->residencyNonResidentStrict);
544 }
545 
546 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceProperties * properties)547 inline bool Iterate(Visitor* visitor,
548                     VkPhysicalDeviceProperties* properties) {
549   return
550     visitor->Visit("apiVersion", &properties->apiVersion) &&
551     visitor->Visit("driverVersion", &properties->driverVersion) &&
552     visitor->Visit("vendorID", &properties->vendorID) &&
553     visitor->Visit("deviceID", &properties->deviceID) &&
554     visitor->Visit("deviceType", &properties->deviceType) &&
555     visitor->Visit("deviceName", &properties->deviceName) &&
556     visitor->Visit("pipelineCacheUUID", &properties->pipelineCacheUUID) &&
557     visitor->Visit("limits", &properties->limits) &&
558     visitor->Visit("sparseProperties", &properties->sparseProperties);
559 }
560 
561 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceFeatures * features)562 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceFeatures* features) {
563   return
564     visitor->Visit("robustBufferAccess", &features->robustBufferAccess) &&
565     visitor->Visit("fullDrawIndexUint32", &features->fullDrawIndexUint32) &&
566     visitor->Visit("imageCubeArray", &features->imageCubeArray) &&
567     visitor->Visit("independentBlend", &features->independentBlend) &&
568     visitor->Visit("geometryShader", &features->geometryShader) &&
569     visitor->Visit("tessellationShader", &features->tessellationShader) &&
570     visitor->Visit("sampleRateShading", &features->sampleRateShading) &&
571     visitor->Visit("dualSrcBlend", &features->dualSrcBlend) &&
572     visitor->Visit("logicOp", &features->logicOp) &&
573     visitor->Visit("multiDrawIndirect", &features->multiDrawIndirect) &&
574     visitor->Visit("drawIndirectFirstInstance", &features->drawIndirectFirstInstance) &&
575     visitor->Visit("depthClamp", &features->depthClamp) &&
576     visitor->Visit("depthBiasClamp", &features->depthBiasClamp) &&
577     visitor->Visit("fillModeNonSolid", &features->fillModeNonSolid) &&
578     visitor->Visit("depthBounds", &features->depthBounds) &&
579     visitor->Visit("wideLines", &features->wideLines) &&
580     visitor->Visit("largePoints", &features->largePoints) &&
581     visitor->Visit("alphaToOne", &features->alphaToOne) &&
582     visitor->Visit("multiViewport", &features->multiViewport) &&
583     visitor->Visit("samplerAnisotropy", &features->samplerAnisotropy) &&
584     visitor->Visit("textureCompressionETC2", &features->textureCompressionETC2) &&
585     visitor->Visit("textureCompressionASTC_LDR", &features->textureCompressionASTC_LDR) &&
586     visitor->Visit("textureCompressionBC", &features->textureCompressionBC) &&
587     visitor->Visit("occlusionQueryPrecise", &features->occlusionQueryPrecise) &&
588     visitor->Visit("pipelineStatisticsQuery", &features->pipelineStatisticsQuery) &&
589     visitor->Visit("vertexPipelineStoresAndAtomics", &features->vertexPipelineStoresAndAtomics) &&
590     visitor->Visit("fragmentStoresAndAtomics", &features->fragmentStoresAndAtomics) &&
591     visitor->Visit("shaderTessellationAndGeometryPointSize", &features->shaderTessellationAndGeometryPointSize) &&
592     visitor->Visit("shaderImageGatherExtended", &features->shaderImageGatherExtended) &&
593     visitor->Visit("shaderStorageImageExtendedFormats", &features->shaderStorageImageExtendedFormats) &&
594     visitor->Visit("shaderStorageImageMultisample", &features->shaderStorageImageMultisample) &&
595     visitor->Visit("shaderStorageImageReadWithoutFormat", &features->shaderStorageImageReadWithoutFormat) &&
596     visitor->Visit("shaderStorageImageWriteWithoutFormat", &features->shaderStorageImageWriteWithoutFormat) &&
597     visitor->Visit("shaderUniformBufferArrayDynamicIndexing", &features->shaderUniformBufferArrayDynamicIndexing) &&
598     visitor->Visit("shaderSampledImageArrayDynamicIndexing", &features->shaderSampledImageArrayDynamicIndexing) &&
599     visitor->Visit("shaderStorageBufferArrayDynamicIndexing", &features->shaderStorageBufferArrayDynamicIndexing) &&
600     visitor->Visit("shaderStorageImageArrayDynamicIndexing", &features->shaderStorageImageArrayDynamicIndexing) &&
601     visitor->Visit("shaderClipDistance", &features->shaderClipDistance) &&
602     visitor->Visit("shaderCullDistance", &features->shaderCullDistance) &&
603     visitor->Visit("shaderFloat64", &features->shaderFloat64) &&
604     visitor->Visit("shaderInt64", &features->shaderInt64) &&
605     visitor->Visit("shaderInt16", &features->shaderInt16) &&
606     visitor->Visit("shaderResourceResidency", &features->shaderResourceResidency) &&
607     visitor->Visit("shaderResourceMinLod", &features->shaderResourceMinLod) &&
608     visitor->Visit("sparseBinding", &features->sparseBinding) &&
609     visitor->Visit("sparseResidencyBuffer", &features->sparseResidencyBuffer) &&
610     visitor->Visit("sparseResidencyImage2D", &features->sparseResidencyImage2D) &&
611     visitor->Visit("sparseResidencyImage3D", &features->sparseResidencyImage3D) &&
612     visitor->Visit("sparseResidency2Samples", &features->sparseResidency2Samples) &&
613     visitor->Visit("sparseResidency4Samples", &features->sparseResidency4Samples) &&
614     visitor->Visit("sparseResidency8Samples", &features->sparseResidency8Samples) &&
615     visitor->Visit("sparseResidency16Samples", &features->sparseResidency16Samples) &&
616     visitor->Visit("sparseResidencyAliased", &features->sparseResidencyAliased) &&
617     visitor->Visit("variableMultisampleRate", &features->variableMultisampleRate) &&
618     visitor->Visit("inheritedQueries", &features->inheritedQueries);
619 }
620 
621 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonCore12 * core)622 inline bool Iterate(Visitor* visitor, VkJsonCore12* core) {
623   return
624     visitor->Visit("features", &core->features) &&
625     visitor->Visit("properties", &core->properties);
626 }
627 
628 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceVulkan12Properties * properties)629 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceVulkan12Properties* properties) {
630   return
631     visitor->Visit("driverID", &properties->driverID) &&
632     visitor->Visit("driverName", &properties->driverName) &&
633     visitor->Visit("driverInfo", &properties->driverInfo) &&
634     visitor->Visit("conformanceVersion", &properties->conformanceVersion) &&
635     visitor->Visit("denormBehaviorIndependence", &properties->denormBehaviorIndependence) &&
636     visitor->Visit("roundingModeIndependence", &properties->roundingModeIndependence) &&
637     visitor->Visit("shaderSignedZeroInfNanPreserveFloat16", &properties->shaderSignedZeroInfNanPreserveFloat16) &&
638     visitor->Visit("shaderSignedZeroInfNanPreserveFloat32", &properties->shaderSignedZeroInfNanPreserveFloat32) &&
639     visitor->Visit("shaderSignedZeroInfNanPreserveFloat64", &properties->shaderSignedZeroInfNanPreserveFloat64) &&
640     visitor->Visit("shaderDenormPreserveFloat16", &properties->shaderDenormPreserveFloat16) &&
641     visitor->Visit("shaderDenormPreserveFloat32", &properties->shaderDenormPreserveFloat32) &&
642     visitor->Visit("shaderDenormPreserveFloat64", &properties->shaderDenormPreserveFloat64) &&
643     visitor->Visit("shaderDenormFlushToZeroFloat16", &properties->shaderDenormFlushToZeroFloat16) &&
644     visitor->Visit("shaderDenormFlushToZeroFloat32", &properties->shaderDenormFlushToZeroFloat32) &&
645     visitor->Visit("shaderDenormFlushToZeroFloat64", &properties->shaderDenormFlushToZeroFloat64) &&
646     visitor->Visit("shaderRoundingModeRTEFloat16", &properties->shaderRoundingModeRTEFloat16) &&
647     visitor->Visit("shaderRoundingModeRTEFloat32", &properties->shaderRoundingModeRTEFloat32) &&
648     visitor->Visit("shaderRoundingModeRTEFloat64", &properties->shaderRoundingModeRTEFloat64) &&
649     visitor->Visit("shaderRoundingModeRTZFloat16", &properties->shaderRoundingModeRTZFloat16) &&
650     visitor->Visit("shaderRoundingModeRTZFloat32", &properties->shaderRoundingModeRTZFloat32) &&
651     visitor->Visit("shaderRoundingModeRTZFloat64", &properties->shaderRoundingModeRTZFloat64) &&
652     visitor->Visit("maxUpdateAfterBindDescriptorsInAllPools", &properties->maxUpdateAfterBindDescriptorsInAllPools) &&
653     visitor->Visit("shaderUniformBufferArrayNonUniformIndexingNative", &properties->shaderUniformBufferArrayNonUniformIndexingNative) &&
654     visitor->Visit("shaderSampledImageArrayNonUniformIndexingNative", &properties->shaderSampledImageArrayNonUniformIndexingNative) &&
655     visitor->Visit("shaderStorageBufferArrayNonUniformIndexingNative", &properties->shaderStorageBufferArrayNonUniformIndexingNative) &&
656     visitor->Visit("shaderStorageImageArrayNonUniformIndexingNative", &properties->shaderStorageImageArrayNonUniformIndexingNative) &&
657     visitor->Visit("shaderInputAttachmentArrayNonUniformIndexingNative", &properties->shaderInputAttachmentArrayNonUniformIndexingNative) &&
658     visitor->Visit("robustBufferAccessUpdateAfterBind", &properties->robustBufferAccessUpdateAfterBind) &&
659     visitor->Visit("quadDivergentImplicitLod", &properties->quadDivergentImplicitLod) &&
660     visitor->Visit("maxPerStageDescriptorUpdateAfterBindSamplers", &properties->maxPerStageDescriptorUpdateAfterBindSamplers) &&
661     visitor->Visit("maxPerStageDescriptorUpdateAfterBindUniformBuffers", &properties->maxPerStageDescriptorUpdateAfterBindUniformBuffers) &&
662     visitor->Visit("maxPerStageDescriptorUpdateAfterBindStorageBuffers", &properties->maxPerStageDescriptorUpdateAfterBindStorageBuffers) &&
663     visitor->Visit("maxPerStageDescriptorUpdateAfterBindSampledImages", &properties->maxPerStageDescriptorUpdateAfterBindSampledImages) &&
664     visitor->Visit("maxPerStageDescriptorUpdateAfterBindStorageImages", &properties->maxPerStageDescriptorUpdateAfterBindStorageImages) &&
665     visitor->Visit("maxPerStageDescriptorUpdateAfterBindInputAttachments", &properties->maxPerStageDescriptorUpdateAfterBindInputAttachments) &&
666     visitor->Visit("maxPerStageUpdateAfterBindResources", &properties->maxPerStageUpdateAfterBindResources) &&
667     visitor->Visit("maxDescriptorSetUpdateAfterBindSamplers", &properties->maxDescriptorSetUpdateAfterBindSamplers) &&
668     visitor->Visit("maxDescriptorSetUpdateAfterBindUniformBuffers", &properties->maxDescriptorSetUpdateAfterBindUniformBuffers) &&
669     visitor->Visit("maxDescriptorSetUpdateAfterBindUniformBuffersDynamic", &properties->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic) &&
670     visitor->Visit("maxDescriptorSetUpdateAfterBindStorageBuffers", &properties->maxDescriptorSetUpdateAfterBindStorageBuffers) &&
671     visitor->Visit("maxDescriptorSetUpdateAfterBindStorageBuffersDynamic", &properties->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic) &&
672     visitor->Visit("maxDescriptorSetUpdateAfterBindSampledImages", &properties->maxDescriptorSetUpdateAfterBindSampledImages) &&
673     visitor->Visit("maxDescriptorSetUpdateAfterBindStorageImages", &properties->maxDescriptorSetUpdateAfterBindStorageImages) &&
674     visitor->Visit("maxDescriptorSetUpdateAfterBindInputAttachments", &properties->maxDescriptorSetUpdateAfterBindInputAttachments) &&
675     visitor->Visit("supportedDepthResolveModes", &properties->supportedDepthResolveModes) &&
676     visitor->Visit("supportedStencilResolveModes", &properties->supportedStencilResolveModes) &&
677     visitor->Visit("independentResolveNone", &properties->independentResolveNone) &&
678     visitor->Visit("independentResolve", &properties->independentResolve) &&
679     visitor->Visit("filterMinmaxSingleComponentFormats", &properties->filterMinmaxSingleComponentFormats) &&
680     visitor->Visit("filterMinmaxImageComponentMapping", &properties->filterMinmaxImageComponentMapping) &&
681     visitor->Visit("maxTimelineSemaphoreValueDifference", &properties->maxTimelineSemaphoreValueDifference) &&
682     visitor->Visit("framebufferIntegerColorSampleCounts", &properties->framebufferIntegerColorSampleCounts);
683 }
684 
685 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceVulkan12Features * features)686 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceVulkan12Features* features) {
687   return
688     visitor->Visit("samplerMirrorClampToEdge", &features->samplerMirrorClampToEdge) &&
689     visitor->Visit("drawIndirectCount", &features->drawIndirectCount) &&
690     visitor->Visit("storageBuffer8BitAccess", &features->storageBuffer8BitAccess) &&
691     visitor->Visit("uniformAndStorageBuffer8BitAccess", &features->uniformAndStorageBuffer8BitAccess) &&
692     visitor->Visit("storagePushConstant8", &features->storagePushConstant8) &&
693     visitor->Visit("shaderBufferInt64Atomics", &features->shaderBufferInt64Atomics) &&
694     visitor->Visit("shaderSharedInt64Atomics", &features->shaderSharedInt64Atomics) &&
695     visitor->Visit("shaderFloat16", &features->shaderFloat16) &&
696     visitor->Visit("shaderInt8", &features->shaderInt8) &&
697     visitor->Visit("descriptorIndexing", &features->descriptorIndexing) &&
698     visitor->Visit("shaderInputAttachmentArrayDynamicIndexing", &features->shaderInputAttachmentArrayDynamicIndexing) &&
699     visitor->Visit("shaderUniformTexelBufferArrayDynamicIndexing", &features->shaderUniformTexelBufferArrayDynamicIndexing) &&
700     visitor->Visit("shaderStorageTexelBufferArrayDynamicIndexing", &features->shaderStorageTexelBufferArrayDynamicIndexing) &&
701     visitor->Visit("shaderUniformBufferArrayNonUniformIndexing", &features->shaderUniformBufferArrayNonUniformIndexing) &&
702     visitor->Visit("shaderSampledImageArrayNonUniformIndexing", &features->shaderSampledImageArrayNonUniformIndexing) &&
703     visitor->Visit("shaderStorageBufferArrayNonUniformIndexing", &features->shaderStorageBufferArrayNonUniformIndexing) &&
704     visitor->Visit("shaderStorageImageArrayNonUniformIndexing", &features->shaderStorageImageArrayNonUniformIndexing) &&
705     visitor->Visit("shaderInputAttachmentArrayNonUniformIndexing", &features->shaderInputAttachmentArrayNonUniformIndexing) &&
706     visitor->Visit("shaderUniformTexelBufferArrayNonUniformIndexing", &features->shaderUniformTexelBufferArrayNonUniformIndexing) &&
707     visitor->Visit("shaderStorageTexelBufferArrayNonUniformIndexing", &features->shaderStorageTexelBufferArrayNonUniformIndexing) &&
708     visitor->Visit("descriptorBindingUniformBufferUpdateAfterBind", &features->descriptorBindingUniformBufferUpdateAfterBind) &&
709     visitor->Visit("descriptorBindingSampledImageUpdateAfterBind", &features->descriptorBindingSampledImageUpdateAfterBind) &&
710     visitor->Visit("descriptorBindingStorageImageUpdateAfterBind", &features->descriptorBindingStorageImageUpdateAfterBind) &&
711     visitor->Visit("descriptorBindingStorageBufferUpdateAfterBind", &features->descriptorBindingStorageBufferUpdateAfterBind) &&
712     visitor->Visit("descriptorBindingUniformTexelBufferUpdateAfterBind", &features->descriptorBindingUniformTexelBufferUpdateAfterBind) &&
713     visitor->Visit("descriptorBindingStorageTexelBufferUpdateAfterBind", &features->descriptorBindingStorageTexelBufferUpdateAfterBind) &&
714     visitor->Visit("descriptorBindingUpdateUnusedWhilePending", &features->descriptorBindingUpdateUnusedWhilePending) &&
715     visitor->Visit("descriptorBindingPartiallyBound", &features->descriptorBindingPartiallyBound) &&
716     visitor->Visit("descriptorBindingVariableDescriptorCount", &features->descriptorBindingVariableDescriptorCount) &&
717     visitor->Visit("runtimeDescriptorArray", &features->runtimeDescriptorArray) &&
718     visitor->Visit("samplerFilterMinmax", &features->samplerFilterMinmax) &&
719     visitor->Visit("scalarBlockLayout", &features->scalarBlockLayout) &&
720     visitor->Visit("imagelessFramebuffer", &features->imagelessFramebuffer) &&
721     visitor->Visit("uniformBufferStandardLayout", &features->uniformBufferStandardLayout) &&
722     visitor->Visit("shaderSubgroupExtendedTypes", &features->shaderSubgroupExtendedTypes) &&
723     visitor->Visit("separateDepthStencilLayouts", &features->separateDepthStencilLayouts) &&
724     visitor->Visit("hostQueryReset", &features->hostQueryReset) &&
725     visitor->Visit("timelineSemaphore", &features->timelineSemaphore) &&
726     visitor->Visit("bufferDeviceAddress", &features->bufferDeviceAddress) &&
727     visitor->Visit("bufferDeviceAddressCaptureReplay", &features->bufferDeviceAddressCaptureReplay) &&
728     visitor->Visit("bufferDeviceAddressMultiDevice", &features->bufferDeviceAddressMultiDevice) &&
729     visitor->Visit("vulkanMemoryModel", &features->vulkanMemoryModel) &&
730     visitor->Visit("vulkanMemoryModelDeviceScope", &features->vulkanMemoryModelDeviceScope) &&
731     visitor->Visit("vulkanMemoryModelAvailabilityVisibilityChains", &features->vulkanMemoryModelAvailabilityVisibilityChains) &&
732     visitor->Visit("shaderOutputViewportIndex", &features->shaderOutputViewportIndex) &&
733     visitor->Visit("shaderOutputLayer", &features->shaderOutputLayer) &&
734     visitor->Visit("subgroupBroadcastDynamicId", &features->subgroupBroadcastDynamicId);
735 }
736 
737 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonCore13 * core)738 inline bool Iterate(Visitor* visitor, VkJsonCore13* core) {
739   return
740     visitor->Visit("features", &core->features) &&
741     visitor->Visit("properties", &core->properties);
742 }
743 
744 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceVulkan13Properties * properties)745 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceVulkan13Properties* properties) {
746   return
747     visitor->Visit("minSubgroupSize", &properties->minSubgroupSize) &&
748     visitor->Visit("maxSubgroupSize", &properties->maxSubgroupSize) &&
749     visitor->Visit("maxComputeWorkgroupSubgroups", &properties->maxComputeWorkgroupSubgroups) &&
750     visitor->Visit("requiredSubgroupSizeStages", &properties->requiredSubgroupSizeStages) &&
751     visitor->Visit("maxInlineUniformBlockSize", &properties->maxInlineUniformBlockSize) &&
752     visitor->Visit("maxPerStageDescriptorInlineUniformBlocks", &properties->maxPerStageDescriptorInlineUniformBlocks) &&
753     visitor->Visit("maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks", &properties->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks) &&
754     visitor->Visit("maxDescriptorSetInlineUniformBlocks", &properties->maxDescriptorSetInlineUniformBlocks) &&
755     visitor->Visit("maxDescriptorSetUpdateAfterBindInlineUniformBlocks", &properties->maxDescriptorSetUpdateAfterBindInlineUniformBlocks) &&
756     visitor->Visit("maxInlineUniformTotalSize", &properties->maxInlineUniformTotalSize) &&
757     visitor->Visit("integerDotProduct8BitUnsignedAccelerated", &properties->integerDotProduct8BitUnsignedAccelerated) &&
758     visitor->Visit("integerDotProduct8BitSignedAccelerated", &properties->integerDotProduct8BitSignedAccelerated) &&
759     visitor->Visit("integerDotProduct8BitMixedSignednessAccelerated", &properties->integerDotProduct8BitMixedSignednessAccelerated) &&
760     visitor->Visit("integerDotProduct4x8BitPackedUnsignedAccelerated", &properties->integerDotProduct4x8BitPackedUnsignedAccelerated) &&
761     visitor->Visit("integerDotProduct4x8BitPackedSignedAccelerated", &properties->integerDotProduct4x8BitPackedSignedAccelerated) &&
762     visitor->Visit("integerDotProduct4x8BitPackedMixedSignednessAccelerated", &properties->integerDotProduct4x8BitPackedMixedSignednessAccelerated) &&
763     visitor->Visit("integerDotProduct16BitUnsignedAccelerated", &properties->integerDotProduct16BitUnsignedAccelerated) &&
764     visitor->Visit("integerDotProduct16BitSignedAccelerated", &properties->integerDotProduct16BitSignedAccelerated) &&
765     visitor->Visit("integerDotProduct16BitMixedSignednessAccelerated", &properties->integerDotProduct16BitMixedSignednessAccelerated) &&
766     visitor->Visit("integerDotProduct32BitUnsignedAccelerated", &properties->integerDotProduct32BitUnsignedAccelerated) &&
767     visitor->Visit("integerDotProduct32BitSignedAccelerated", &properties->integerDotProduct32BitSignedAccelerated) &&
768     visitor->Visit("integerDotProduct32BitMixedSignednessAccelerated", &properties->integerDotProduct32BitMixedSignednessAccelerated) &&
769     visitor->Visit("integerDotProduct64BitUnsignedAccelerated", &properties->integerDotProduct64BitUnsignedAccelerated) &&
770     visitor->Visit("integerDotProduct64BitSignedAccelerated", &properties->integerDotProduct64BitSignedAccelerated) &&
771     visitor->Visit("integerDotProduct64BitMixedSignednessAccelerated", &properties->integerDotProduct64BitMixedSignednessAccelerated) &&
772     visitor->Visit("integerDotProductAccumulatingSaturating8BitUnsignedAccelerated", &properties->integerDotProductAccumulatingSaturating8BitUnsignedAccelerated) &&
773     visitor->Visit("integerDotProductAccumulatingSaturating8BitSignedAccelerated", &properties->integerDotProductAccumulatingSaturating8BitSignedAccelerated) &&
774     visitor->Visit("integerDotProductAccumulatingSaturating8BitMixedSignednessAccelerated", &properties->integerDotProductAccumulatingSaturating8BitMixedSignednessAccelerated) &&
775     visitor->Visit("integerDotProductAccumulatingSaturating4x8BitPackedUnsignedAccelerated", &properties->integerDotProductAccumulatingSaturating4x8BitPackedUnsignedAccelerated) &&
776     visitor->Visit("integerDotProductAccumulatingSaturating4x8BitPackedSignedAccelerated", &properties->integerDotProductAccumulatingSaturating4x8BitPackedSignedAccelerated) &&
777     visitor->Visit("integerDotProductAccumulatingSaturating4x8BitPackedMixedSignednessAccelerated", &properties->integerDotProductAccumulatingSaturating4x8BitPackedMixedSignednessAccelerated) &&
778     visitor->Visit("integerDotProductAccumulatingSaturating16BitUnsignedAccelerated", &properties->integerDotProductAccumulatingSaturating16BitUnsignedAccelerated) &&
779     visitor->Visit("integerDotProductAccumulatingSaturating16BitSignedAccelerated", &properties->integerDotProductAccumulatingSaturating16BitSignedAccelerated) &&
780     visitor->Visit("integerDotProductAccumulatingSaturating16BitMixedSignednessAccelerated", &properties->integerDotProductAccumulatingSaturating16BitMixedSignednessAccelerated) &&
781     visitor->Visit("integerDotProductAccumulatingSaturating32BitUnsignedAccelerated", &properties->integerDotProductAccumulatingSaturating32BitUnsignedAccelerated) &&
782     visitor->Visit("integerDotProductAccumulatingSaturating32BitSignedAccelerated", &properties->integerDotProductAccumulatingSaturating32BitSignedAccelerated) &&
783     visitor->Visit("integerDotProductAccumulatingSaturating32BitMixedSignednessAccelerated", &properties->integerDotProductAccumulatingSaturating32BitMixedSignednessAccelerated) &&
784     visitor->Visit("integerDotProductAccumulatingSaturating64BitUnsignedAccelerated", &properties->integerDotProductAccumulatingSaturating64BitUnsignedAccelerated) &&
785     visitor->Visit("integerDotProductAccumulatingSaturating64BitSignedAccelerated", &properties->integerDotProductAccumulatingSaturating64BitSignedAccelerated) &&
786     visitor->Visit("integerDotProductAccumulatingSaturating64BitMixedSignednessAccelerated", &properties->integerDotProductAccumulatingSaturating64BitMixedSignednessAccelerated) &&
787     visitor->Visit("storageTexelBufferOffsetAlignmentBytes", &properties->storageTexelBufferOffsetAlignmentBytes) &&
788     visitor->Visit("storageTexelBufferOffsetSingleTexelAlignment", &properties->storageTexelBufferOffsetSingleTexelAlignment) &&
789     visitor->Visit("uniformTexelBufferOffsetAlignmentBytes", &properties->uniformTexelBufferOffsetAlignmentBytes) &&
790     visitor->Visit("uniformTexelBufferOffsetSingleTexelAlignment", &properties->uniformTexelBufferOffsetSingleTexelAlignment) &&
791     visitor->Visit("maxBufferSize", &properties->maxBufferSize);
792 }
793 
794 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceVulkan13Features * features)795 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceVulkan13Features* features) {
796   return
797     visitor->Visit("robustImageAccess", &features->robustImageAccess) &&
798     visitor->Visit("inlineUniformBlock", &features->inlineUniformBlock) &&
799     visitor->Visit("descriptorBindingInlineUniformBlockUpdateAfterBind", &features->descriptorBindingInlineUniformBlockUpdateAfterBind) &&
800     visitor->Visit("pipelineCreationCacheControl", &features->pipelineCreationCacheControl) &&
801     visitor->Visit("privateData", &features->privateData) &&
802     visitor->Visit("shaderDemoteToHelperInvocation", &features->shaderDemoteToHelperInvocation) &&
803     visitor->Visit("shaderTerminateInvocation", &features->shaderTerminateInvocation) &&
804     visitor->Visit("subgroupSizeControl", &features->subgroupSizeControl) &&
805     visitor->Visit("computeFullSubgroups", &features->computeFullSubgroups) &&
806     visitor->Visit("synchronization2", &features->synchronization2) &&
807     visitor->Visit("textureCompressionASTC_HDR", &features->textureCompressionASTC_HDR) &&
808     visitor->Visit("shaderZeroInitializeWorkgroupMemory", &features->shaderZeroInitializeWorkgroupMemory) &&
809     visitor->Visit("dynamicRendering", &features->dynamicRendering) &&
810     visitor->Visit("shaderIntegerDotProduct", &features->shaderIntegerDotProduct) &&
811     visitor->Visit("maintenance4", &features->maintenance4);
812 }
813 // clang-format on
814 
815 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonExtDriverProperties * properties)816 inline bool Iterate(Visitor* visitor,
817                     VkJsonExtDriverProperties* properties) {
818   return visitor->Visit("driverPropertiesKHR",
819                         &properties->driver_properties_khr);
820 }
821 
822 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceDriverPropertiesKHR * properties)823 inline bool Iterate(Visitor* visitor,
824                     VkPhysicalDeviceDriverPropertiesKHR* properties) {
825   return visitor->Visit("driverID", &properties->driverID) &&
826          visitor->Visit("driverName", &properties->driverName) &&
827          visitor->Visit("driverInfo", &properties->driverInfo) &&
828          visitor->Visit("conformanceVersion", &properties->conformanceVersion);
829 }
830 
831 template <typename Visitor>
Iterate(Visitor * visitor,VkConformanceVersionKHR * version)832 inline bool Iterate(Visitor* visitor,
833                     VkConformanceVersionKHR* version) {
834   return visitor->Visit("major", &version->major) &&
835          visitor->Visit("minor", &version->minor) &&
836          visitor->Visit("subminor", &version->subminor) &&
837          visitor->Visit("patch", &version->patch);
838 }
839 
840 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonExtVariablePointerFeatures * features)841 inline bool Iterate(Visitor* visitor,
842                     VkJsonExtVariablePointerFeatures* features) {
843   return visitor->Visit("variablePointerFeaturesKHR",
844                         &features->variable_pointer_features_khr);
845 }
846 
847 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonExtShaderFloat16Int8Features * features)848 inline bool Iterate(Visitor* visitor,
849                     VkJsonExtShaderFloat16Int8Features* features) {
850   return visitor->Visit("shaderFloat16Int8FeaturesKHR",
851                         &features->shader_float16_int8_features_khr);
852 }
853 
854 template <typename Visitor>
Iterate(Visitor * visitor,VkMemoryType * type)855 inline bool Iterate(Visitor* visitor, VkMemoryType* type) {
856   return
857     visitor->Visit("propertyFlags", &type->propertyFlags) &&
858     visitor->Visit("heapIndex", &type->heapIndex);
859 }
860 
861 template <typename Visitor>
Iterate(Visitor * visitor,VkMemoryHeap * heap)862 inline bool Iterate(Visitor* visitor, VkMemoryHeap* heap) {
863   return
864     visitor->Visit("size", &heap->size) &&
865     visitor->Visit("flags", &heap->flags);
866 }
867 
868 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMemoryProperties * properties)869 inline bool Iterate(Visitor* visitor, VkPhysicalDeviceMemoryProperties* properties) {
870   return
871     visitor->Visit("memoryTypeCount", &properties->memoryTypeCount) &&
872     visitor->VisitArray("memoryTypes", properties->memoryTypeCount, &properties->memoryTypes) &&
873     visitor->Visit("memoryHeapCount", &properties->memoryHeapCount) &&
874     visitor->VisitArray("memoryHeaps", properties->memoryHeapCount, &properties->memoryHeaps);
875 }
876 
877 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceSubgroupProperties * properties)878 inline bool Iterate(Visitor* visitor,
879                     VkPhysicalDeviceSubgroupProperties* properties) {
880   return visitor->Visit("subgroupSize", &properties->subgroupSize) &&
881          visitor->Visit("supportedStages", &properties->supportedStages) &&
882          visitor->Visit("supportedOperations",
883                         &properties->supportedOperations) &&
884          visitor->Visit("quadOperationsInAllStages",
885                         &properties->quadOperationsInAllStages);
886 }
887 
888 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDevicePointClippingProperties * properties)889 inline bool Iterate(Visitor* visitor,
890                     VkPhysicalDevicePointClippingProperties* properties) {
891   return visitor->Visit("pointClippingBehavior",
892                         &properties->pointClippingBehavior);
893 }
894 
895 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMultiviewProperties * properties)896 inline bool Iterate(Visitor* visitor,
897                     VkPhysicalDeviceMultiviewProperties* properties) {
898   return visitor->Visit("maxMultiviewViewCount",
899                         &properties->maxMultiviewViewCount) &&
900          visitor->Visit("maxMultiviewInstanceIndex",
901                         &properties->maxMultiviewInstanceIndex);
902 }
903 
904 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceIDProperties * properties)905 inline bool Iterate(Visitor* visitor,
906                     VkPhysicalDeviceIDProperties* properties) {
907   return visitor->Visit("deviceUUID", &properties->deviceUUID) &&
908          visitor->Visit("driverUUID", &properties->driverUUID) &&
909          visitor->Visit("deviceLUID", &properties->deviceLUID) &&
910          visitor->Visit("deviceNodeMask", &properties->deviceNodeMask) &&
911          visitor->Visit("deviceLUIDValid", &properties->deviceLUIDValid);
912 }
913 
914 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMaintenance3Properties * properties)915 inline bool Iterate(Visitor* visitor,
916                     VkPhysicalDeviceMaintenance3Properties* properties) {
917   return visitor->Visit("maxPerSetDescriptors",
918                         &properties->maxPerSetDescriptors) &&
919          visitor->Visit("maxMemoryAllocationSize",
920                         &properties->maxMemoryAllocationSize);
921 }
922 
923 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDevice16BitStorageFeatures * features)924 inline bool Iterate(Visitor* visitor,
925                     VkPhysicalDevice16BitStorageFeatures* features) {
926   return visitor->Visit("storageBuffer16BitAccess",
927                         &features->storageBuffer16BitAccess) &&
928          visitor->Visit("uniformAndStorageBuffer16BitAccess",
929                         &features->uniformAndStorageBuffer16BitAccess) &&
930          visitor->Visit("storagePushConstant16",
931                         &features->storagePushConstant16) &&
932          visitor->Visit("storageInputOutput16",
933                         &features->storageInputOutput16);
934 }
935 
936 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceMultiviewFeatures * features)937 inline bool Iterate(Visitor* visitor,
938                     VkPhysicalDeviceMultiviewFeatures* features) {
939   return visitor->Visit("multiview", &features->multiview) &&
940          visitor->Visit("multiviewGeometryShader",
941                         &features->multiviewGeometryShader) &&
942          visitor->Visit("multiviewTessellationShader",
943                         &features->multiviewTessellationShader);
944 }
945 
946 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceVariablePointerFeatures * features)947 inline bool Iterate(Visitor* visitor,
948                     VkPhysicalDeviceVariablePointerFeatures* features) {
949   return visitor->Visit("variablePointersStorageBuffer",
950                         &features->variablePointersStorageBuffer) &&
951          visitor->Visit("variablePointers", &features->variablePointers);
952 }
953 
954 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceShaderFloat16Int8FeaturesKHR * features)955 inline bool Iterate(Visitor* visitor,
956                     VkPhysicalDeviceShaderFloat16Int8FeaturesKHR* features) {
957   return visitor->Visit("shaderFloat16", &features->shaderFloat16) &&
958          visitor->Visit("shaderInt8", &features->shaderInt8);
959 }
960 
961 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceProtectedMemoryFeatures * features)962 inline bool Iterate(Visitor* visitor,
963                     VkPhysicalDeviceProtectedMemoryFeatures* features) {
964   return visitor->Visit("protectedMemory", &features->protectedMemory);
965 }
966 
967 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceSamplerYcbcrConversionFeatures * features)968 inline bool Iterate(Visitor* visitor,
969                     VkPhysicalDeviceSamplerYcbcrConversionFeatures* features) {
970   return visitor->Visit("samplerYcbcrConversion",
971                         &features->samplerYcbcrConversion);
972 }
973 
974 template <typename Visitor>
Iterate(Visitor * visitor,VkPhysicalDeviceShaderDrawParameterFeatures * features)975 inline bool Iterate(Visitor* visitor,
976                     VkPhysicalDeviceShaderDrawParameterFeatures* features) {
977   return visitor->Visit("shaderDrawParameters",
978                         &features->shaderDrawParameters);
979 }
980 
981 template <typename Visitor>
Iterate(Visitor * visitor,VkExternalFenceProperties * properties)982 inline bool Iterate(Visitor* visitor, VkExternalFenceProperties* properties) {
983   return visitor->Visit("exportFromImportedHandleTypes",
984                         &properties->exportFromImportedHandleTypes) &&
985          visitor->Visit("compatibleHandleTypes",
986                         &properties->compatibleHandleTypes) &&
987          visitor->Visit("externalFenceFeatures",
988                         &properties->externalFenceFeatures);
989 }
990 
991 template <typename Visitor>
Iterate(Visitor * visitor,VkExternalSemaphoreProperties * properties)992 inline bool Iterate(Visitor* visitor,
993                     VkExternalSemaphoreProperties* properties) {
994   return visitor->Visit("exportFromImportedHandleTypes",
995                         &properties->exportFromImportedHandleTypes) &&
996          visitor->Visit("compatibleHandleTypes",
997                         &properties->compatibleHandleTypes) &&
998          visitor->Visit("externalSemaphoreFeatures",
999                         &properties->externalSemaphoreFeatures);
1000 }
1001 
1002 template <typename Visitor>
Iterate(Visitor * visitor,VkQueueFamilyProperties * properties)1003 inline bool Iterate(Visitor* visitor, VkQueueFamilyProperties* properties) {
1004   return
1005     visitor->Visit("queueFlags", &properties->queueFlags) &&
1006     visitor->Visit("queueCount", &properties->queueCount) &&
1007     visitor->Visit("timestampValidBits", &properties->timestampValidBits) &&
1008     visitor->Visit("minImageTransferGranularity", &properties->minImageTransferGranularity);
1009 }
1010 
1011 template <typename Visitor>
Iterate(Visitor * visitor,VkExtensionProperties * properties)1012 inline bool Iterate(Visitor* visitor, VkExtensionProperties* properties) {
1013   return
1014     visitor->Visit("extensionName", &properties->extensionName) &&
1015     visitor->Visit("specVersion", &properties->specVersion);
1016 }
1017 
1018 template <typename Visitor>
Iterate(Visitor * visitor,VkLayerProperties * properties)1019 inline bool Iterate(Visitor* visitor, VkLayerProperties* properties) {
1020   return
1021     visitor->Visit("layerName", &properties->layerName) &&
1022     visitor->Visit("specVersion", &properties->specVersion) &&
1023     visitor->Visit("implementationVersion", &properties->implementationVersion) &&
1024     visitor->Visit("description", &properties->description);
1025 }
1026 
1027 template <typename Visitor>
Iterate(Visitor * visitor,VkFormatProperties * properties)1028 inline bool Iterate(Visitor* visitor, VkFormatProperties* properties) {
1029   return
1030     visitor->Visit("linearTilingFeatures", &properties->linearTilingFeatures) &&
1031     visitor->Visit("optimalTilingFeatures", &properties->optimalTilingFeatures) &&
1032     visitor->Visit("bufferFeatures", &properties->bufferFeatures);
1033 }
1034 
1035 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonLayer * layer)1036 inline bool Iterate(Visitor* visitor, VkJsonLayer* layer) {
1037   return visitor->Visit("properties", &layer->properties) &&
1038          visitor->Visit("extensions", &layer->extensions);
1039 }
1040 
1041 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonDeviceGroup * device_group)1042 inline bool Iterate(Visitor* visitor, VkJsonDeviceGroup* device_group) {
1043   return visitor->Visit("devices", &device_group->device_inds) &&
1044          visitor->Visit("subsetAllocation",
1045                         &device_group->properties.subsetAllocation);
1046 }
1047 
1048 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonDevice * device)1049 inline bool Iterate(Visitor* visitor, VkJsonDevice* device) {
1050   bool ret = true;
1051   switch (device->properties.apiVersion ^
1052           VK_API_VERSION_PATCH(device->properties.apiVersion)) {
1053     case VK_API_VERSION_1_3:
1054       ret &= visitor->Visit("core13", &device->core13);
1055       FALLTHROUGH_INTENDED;
1056     case VK_API_VERSION_1_2:
1057       ret &= visitor->Visit("core12", &device->core12);
1058       FALLTHROUGH_INTENDED;
1059     case VK_API_VERSION_1_1:
1060       ret &=
1061           visitor->Visit("subgroupProperties", &device->subgroup_properties) &&
1062           visitor->Visit("pointClippingProperties",
1063                          &device->point_clipping_properties) &&
1064           visitor->Visit("multiviewProperties",
1065                          &device->multiview_properties) &&
1066           visitor->Visit("idProperties", &device->id_properties) &&
1067           visitor->Visit("maintenance3Properties",
1068                          &device->maintenance3_properties) &&
1069           visitor->Visit("16bitStorageFeatures",
1070                          &device->bit16_storage_features) &&
1071           visitor->Visit("multiviewFeatures", &device->multiview_features) &&
1072           visitor->Visit("variablePointerFeatures",
1073                          &device->variable_pointer_features) &&
1074           visitor->Visit("protectedMemoryFeatures",
1075                          &device->protected_memory_features) &&
1076           visitor->Visit("samplerYcbcrConversionFeatures",
1077                          &device->sampler_ycbcr_conversion_features) &&
1078           visitor->Visit("shaderDrawParameterFeatures",
1079                          &device->shader_draw_parameter_features) &&
1080           visitor->Visit("externalFenceProperties",
1081                          &device->external_fence_properties) &&
1082           visitor->Visit("externalSemaphoreProperties",
1083                          &device->external_semaphore_properties);
1084       FALLTHROUGH_INTENDED;
1085     case VK_API_VERSION_1_0:
1086       ret &= visitor->Visit("properties", &device->properties) &&
1087              visitor->Visit("features", &device->features) &&
1088              visitor->Visit("memory", &device->memory) &&
1089              visitor->Visit("queues", &device->queues) &&
1090              visitor->Visit("extensions", &device->extensions) &&
1091              visitor->Visit("layers", &device->layers) &&
1092              visitor->Visit("formats", &device->formats);
1093       if (device->ext_driver_properties.reported) {
1094         ret &= visitor->Visit("VK_KHR_driver_properties",
1095                             &device->ext_driver_properties);
1096       }
1097       if (device->ext_variable_pointer_features.reported) {
1098         ret &= visitor->Visit("VK_KHR_variable_pointers",
1099                             &device->ext_variable_pointer_features);
1100       }
1101       if (device->ext_shader_float16_int8_features.reported) {
1102         ret &= visitor->Visit("VK_KHR_shader_float16_int8",
1103                               &device->ext_shader_float16_int8_features);
1104       }
1105   }
1106   return ret;
1107 }
1108 
1109 template <typename Visitor>
Iterate(Visitor * visitor,VkJsonInstance * instance)1110 inline bool Iterate(Visitor* visitor, VkJsonInstance* instance) {
1111   bool ret = true;
1112   switch (instance->api_version ^ VK_API_VERSION_PATCH(instance->api_version)) {
1113     case VK_API_VERSION_1_3:
1114       FALLTHROUGH_INTENDED;
1115     case VK_API_VERSION_1_2:
1116       ret &= visitor->Visit("apiVersion", &instance->api_version);
1117       FALLTHROUGH_INTENDED;
1118     case VK_API_VERSION_1_1:
1119       ret &= visitor->Visit("deviceGroups", &instance->device_groups);
1120       FALLTHROUGH_INTENDED;
1121     case VK_API_VERSION_1_0:
1122       char depString[] =
1123           "vkjson is deprecated, and will be replaced in a future release";
1124       ret &= visitor->Visit("layers", &instance->layers) &&
1125              visitor->Visit("extensions", &instance->extensions) &&
1126              visitor->Visit("devices", &instance->devices) &&
1127              visitor->Visit("_comment", &depString);
1128   }
1129   return ret;
1130 }
1131 
1132 template <typename T>
1133 using EnableForArithmetic =
1134     typename std::enable_if<std::is_arithmetic<T>::value, void>::type;
1135 
1136 template <typename T>
1137 using EnableForStruct =
1138     typename std::enable_if<std::is_class<T>::value, void>::type;
1139 
1140 template <typename T>
1141 using EnableForEnum =
1142     typename std::enable_if<std::is_enum<T>::value, void>::type;
1143 
1144 template <typename T, typename = EnableForStruct<T>, typename = void>
1145 Json::Value ToJsonValue(const T& value);
1146 
1147 template <typename T, typename = EnableForArithmetic<T>>
ToJsonValue(const T & value)1148 inline Json::Value ToJsonValue(const T& value) {
1149   return Json::Value(
1150       std::clamp(static_cast<double>(value), SAFE_DOUBLE_MIN, SAFE_DOUBLE_MAX));
1151 }
1152 
ToJsonValue(const uint64_t & value)1153 inline Json::Value ToJsonValue(const uint64_t& value) {
1154   char string[19] = {0};  // "0x" + 16 digits + terminal \0
1155   snprintf(string, sizeof(string), "0x%016" PRIx64, value);
1156   return Json::Value(string);
1157 }
1158 
1159 template <typename T, typename = EnableForEnum<T>, typename = void,
1160           typename = void>
ToJsonValue(const T & value)1161 inline Json::Value ToJsonValue(const T& value) {
1162   return Json::Value(static_cast<double>(value));
1163 }
1164 
1165 template <typename T>
ArrayToJsonValue(uint32_t count,const T * values)1166 inline Json::Value ArrayToJsonValue(uint32_t count, const T* values) {
1167   Json::Value array(Json::arrayValue);
1168   for (unsigned int i = 0; i < count; ++i) array.append(ToJsonValue(values[i]));
1169   return array;
1170 }
1171 
1172 template <typename T, unsigned int N>
ToJsonValue(const T (& value)[N])1173 inline Json::Value ToJsonValue(const T (&value)[N]) {
1174   return ArrayToJsonValue(N, value);
1175 }
1176 
1177 template <size_t N>
ToJsonValue(const char (& value)[N])1178 inline Json::Value ToJsonValue(const char (&value)[N]) {
1179   assert(strlen(value) < N);
1180   return Json::Value(value);
1181 }
1182 
1183 template <typename T>
ToJsonValue(const std::vector<T> & value)1184 inline Json::Value ToJsonValue(const std::vector<T>& value) {
1185   assert(value.size() <= std::numeric_limits<uint32_t>::max());
1186   return ArrayToJsonValue(static_cast<uint32_t>(value.size()), value.data());
1187 }
1188 
1189 template <typename F, typename S>
ToJsonValue(const std::pair<F,S> & value)1190 inline Json::Value ToJsonValue(const std::pair<F, S>& value) {
1191   Json::Value array(Json::arrayValue);
1192   array.append(ToJsonValue(value.first));
1193   array.append(ToJsonValue(value.second));
1194   return array;
1195 }
1196 
1197 template <typename F, typename S>
ToJsonValue(const std::map<F,S> & value)1198 inline Json::Value ToJsonValue(const std::map<F, S>& value) {
1199   Json::Value array(Json::arrayValue);
1200   for (auto& kv : value) array.append(ToJsonValue(kv));
1201   return array;
1202 }
1203 
1204 class JsonWriterVisitor {
1205  public:
JsonWriterVisitor()1206   JsonWriterVisitor() : object_(Json::objectValue) {}
1207 
~JsonWriterVisitor()1208   ~JsonWriterVisitor() {}
1209 
Visit(const char * key,const T * value)1210   template <typename T> bool Visit(const char* key, const T* value) {
1211     object_[key] = ToJsonValue(*value);
1212     return true;
1213   }
1214 
1215   template <typename T, uint32_t N>
VisitArray(const char * key,uint32_t count,const T (* value)[N])1216   bool VisitArray(const char* key, uint32_t count, const T (*value)[N]) {
1217     assert(count <= N);
1218     object_[key] = ArrayToJsonValue(count, *value);
1219     return true;
1220   }
1221 
get_object() const1222   Json::Value get_object() const { return object_; }
1223 
1224  private:
1225   Json::Value object_;
1226 };
1227 
1228 template <typename Visitor, typename T>
VisitForWrite(Visitor * visitor,const T & t)1229 inline void VisitForWrite(Visitor* visitor, const T& t) {
1230   Iterate(visitor, const_cast<T*>(&t));
1231 }
1232 
1233 template <typename T, typename /*= EnableForStruct<T>*/, typename /*= void*/>
ToJsonValue(const T & value)1234 Json::Value ToJsonValue(const T& value) {
1235   JsonWriterVisitor visitor;
1236   VisitForWrite(&visitor, value);
1237   return visitor.get_object();
1238 }
1239 
1240 template <typename T, typename = EnableForStruct<T>>
1241 bool AsValue(Json::Value* json_value, T* t);
1242 
AsValue(Json::Value * json_value,int32_t * value)1243 inline bool AsValue(Json::Value* json_value, int32_t* value) {
1244   if (json_value->type() != Json::realValue) return false;
1245   double d = json_value->asDouble();
1246   if (!IsIntegral(d) ||
1247       d < static_cast<double>(std::numeric_limits<int32_t>::min()) ||
1248       d > static_cast<double>(std::numeric_limits<int32_t>::max()))
1249     return false;
1250   *value = static_cast<int32_t>(d);
1251   return true;
1252 }
1253 
AsValue(Json::Value * json_value,uint64_t * value)1254 inline bool AsValue(Json::Value* json_value, uint64_t* value) {
1255   if (json_value->type() != Json::stringValue) return false;
1256   int result =
1257       std::sscanf(json_value->asString().c_str(), "0x%016" PRIx64, value);
1258   return result == 1;
1259 }
1260 
AsValue(Json::Value * json_value,uint32_t * value)1261 inline bool AsValue(Json::Value* json_value, uint32_t* value) {
1262   if (json_value->type() != Json::realValue) return false;
1263   double d = json_value->asDouble();
1264   if (!IsIntegral(d) || d < 0.0 ||
1265       d > static_cast<double>(std::numeric_limits<uint32_t>::max()))
1266     return false;
1267   *value = static_cast<uint32_t>(d);
1268   return true;
1269 }
1270 
AsValue(Json::Value * json_value,uint8_t * value)1271 inline bool AsValue(Json::Value* json_value, uint8_t* value) {
1272   uint32_t value32 = 0;
1273   AsValue(json_value, &value32);
1274   if (value32 > std::numeric_limits<uint8_t>::max())
1275     return false;
1276   *value = static_cast<uint8_t>(value32);
1277   return true;
1278 }
1279 
AsValue(Json::Value * json_value,float * value)1280 inline bool AsValue(Json::Value* json_value, float* value) {
1281   if (json_value->type() != Json::realValue) return false;
1282   *value = static_cast<float>(json_value->asDouble());
1283   return true;
1284 }
1285 
1286 template <typename T>
AsArray(Json::Value * json_value,uint32_t count,T * values)1287 inline bool AsArray(Json::Value* json_value, uint32_t count, T* values) {
1288   if (json_value->type() != Json::arrayValue || json_value->size() != count)
1289     return false;
1290   for (uint32_t i = 0; i < count; ++i) {
1291     if (!AsValue(&(*json_value)[i], values + i)) return false;
1292   }
1293   return true;
1294 }
1295 
1296 template <typename T, unsigned int N>
AsValue(Json::Value * json_value,T (* value)[N])1297 inline bool AsValue(Json::Value* json_value, T (*value)[N]) {
1298   return AsArray(json_value, N, *value);
1299 }
1300 
1301 template <size_t N>
AsValue(Json::Value * json_value,char (* value)[N])1302 inline bool AsValue(Json::Value* json_value, char (*value)[N]) {
1303   if (json_value->type() != Json::stringValue) return false;
1304   size_t len = json_value->asString().length();
1305   if (len >= N)
1306     return false;
1307   memcpy(*value, json_value->asString().c_str(), len);
1308   memset(*value + len, 0, N-len);
1309   return true;
1310 }
1311 
1312 template <typename T, typename = EnableForEnum<T>, typename = void>
AsValue(Json::Value * json_value,T * t)1313 inline bool AsValue(Json::Value* json_value, T* t) {
1314   uint32_t value = 0;
1315   if (!AsValue(json_value, &value))
1316       return false;
1317   if (!EnumTraits<T>::exist(value)) return false;
1318   *t = static_cast<T>(value);
1319   return true;
1320 }
1321 
1322 template <typename T>
AsValue(Json::Value * json_value,std::vector<T> * value)1323 inline bool AsValue(Json::Value* json_value, std::vector<T>* value) {
1324   if (json_value->type() != Json::arrayValue) return false;
1325   int size = json_value->size();
1326   value->resize(size);
1327   return AsArray(json_value, size, value->data());
1328 }
1329 
1330 template <typename F, typename S>
AsValue(Json::Value * json_value,std::pair<F,S> * value)1331 inline bool AsValue(Json::Value* json_value, std::pair<F, S>* value) {
1332   if (json_value->type() != Json::arrayValue || json_value->size() != 2)
1333     return false;
1334   return AsValue(&(*json_value)[0], &value->first) &&
1335          AsValue(&(*json_value)[1], &value->second);
1336 }
1337 
1338 template <typename F, typename S>
AsValue(Json::Value * json_value,std::map<F,S> * value)1339 inline bool AsValue(Json::Value* json_value, std::map<F, S>* value) {
1340   if (json_value->type() != Json::arrayValue) return false;
1341   int size = json_value->size();
1342   for (int i = 0; i < size; ++i) {
1343     std::pair<F, S> elem;
1344     if (!AsValue(&(*json_value)[i], &elem)) return false;
1345     if (!value->insert(elem).second)
1346       return false;
1347   }
1348   return true;
1349 }
1350 
1351 template <typename T>
ReadValue(Json::Value * object,const char * key,T * value,std::string * errors)1352 bool ReadValue(Json::Value* object, const char* key, T* value,
1353                std::string* errors) {
1354   Json::Value json_value = (*object)[key];
1355   if (!json_value) {
1356     if (errors)
1357       *errors = std::string(key) + " missing.";
1358     return false;
1359   }
1360   if (AsValue(&json_value, value)) return true;
1361   if (errors)
1362     *errors = std::string("Wrong type for ") + std::string(key) + ".";
1363   return false;
1364 }
1365 
1366 template <typename Visitor, typename T>
VisitForRead(Visitor * visitor,T * t)1367 inline bool VisitForRead(Visitor* visitor, T* t) {
1368   return Iterate(visitor, t);
1369 }
1370 
1371 class JsonReaderVisitor {
1372  public:
JsonReaderVisitor(Json::Value * object,std::string * errors)1373   JsonReaderVisitor(Json::Value* object, std::string* errors)
1374       : object_(object), errors_(errors) {}
1375 
Visit(const char * key,T * value) const1376   template <typename T> bool Visit(const char* key, T* value) const {
1377     return ReadValue(object_, key, value, errors_);
1378   }
1379 
1380   template <typename T, uint32_t N>
VisitArray(const char * key,uint32_t count,T (* value)[N])1381   bool VisitArray(const char* key, uint32_t count, T (*value)[N]) {
1382     if (count > N)
1383       return false;
1384     Json::Value json_value = (*object_)[key];
1385     if (!json_value) {
1386       if (errors_)
1387         *errors_ = std::string(key) + " missing.";
1388       return false;
1389     }
1390     if (AsArray(&json_value, count, *value)) return true;
1391     if (errors_)
1392       *errors_ = std::string("Wrong type for ") + std::string(key) + ".";
1393     return false;
1394   }
1395 
1396 
1397  private:
1398   Json::Value* object_;
1399   std::string* errors_;
1400 };
1401 
1402 template <typename T, typename /*= EnableForStruct<T>*/>
AsValue(Json::Value * json_value,T * t)1403 bool AsValue(Json::Value* json_value, T* t) {
1404   if (json_value->type() != Json::objectValue) return false;
1405   JsonReaderVisitor visitor(json_value, nullptr);
1406   return VisitForRead(&visitor, t);
1407 }
1408 
1409 
VkTypeToJson(const T & t)1410 template <typename T> std::string VkTypeToJson(const T& t) {
1411   JsonWriterVisitor visitor;
1412   VisitForWrite(&visitor, t);
1413   return visitor.get_object().toStyledString();
1414 }
1415 
VkTypeFromJson(const std::string & json,T * t,std::string * errors)1416 template <typename T> bool VkTypeFromJson(const std::string& json,
1417                                           T* t,
1418                                           std::string* errors) {
1419   *t = T();
1420   Json::Value object(Json::objectValue);
1421   Json::CharReaderBuilder builder;
1422   builder["collectComments"] = false;
1423   std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
1424   if (!reader->parse(json.data(), json.data() + json.size(), &object, errors)) {
1425     return false;
1426   }
1427   return AsValue(&object, t);
1428 }
1429 
1430 }  // anonymous namespace
1431 
VkJsonInstanceToJson(const VkJsonInstance & instance)1432 std::string VkJsonInstanceToJson(const VkJsonInstance& instance) {
1433   return VkTypeToJson(instance);
1434 }
1435 
VkJsonInstanceFromJson(const std::string & json,VkJsonInstance * instance,std::string * errors)1436 bool VkJsonInstanceFromJson(const std::string& json,
1437                             VkJsonInstance* instance,
1438                             std::string* errors) {
1439   return VkTypeFromJson(json, instance, errors);
1440 }
1441 
VkJsonDeviceToJson(const VkJsonDevice & device)1442 std::string VkJsonDeviceToJson(const VkJsonDevice& device) {
1443   return VkTypeToJson(device);
1444 }
1445 
VkJsonDeviceFromJson(const std::string & json,VkJsonDevice * device,std::string * errors)1446 bool VkJsonDeviceFromJson(const std::string& json,
1447                           VkJsonDevice* device,
1448                           std::string* errors) {
1449   return VkTypeFromJson(json, device, errors);
1450 };
1451 
VkJsonImageFormatPropertiesToJson(const VkImageFormatProperties & properties)1452 std::string VkJsonImageFormatPropertiesToJson(
1453     const VkImageFormatProperties& properties) {
1454   return VkTypeToJson(properties);
1455 }
1456 
VkJsonImageFormatPropertiesFromJson(const std::string & json,VkImageFormatProperties * properties,std::string * errors)1457 bool VkJsonImageFormatPropertiesFromJson(const std::string& json,
1458                                          VkImageFormatProperties* properties,
1459                                          std::string* errors) {
1460   return VkTypeFromJson(json, properties, errors);
1461 };
1462