1" ""VK API description"""
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# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and/or associated documentation files (the "Materials"), to
10# deal in the Materials without restriction, including without limitation the
11# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12# sell copies of the Materials, and to permit persons to whom the Materials
13# are furnished to do so, subject to the following conditions:
14#
15# The above copyright notice(s) and this permission notice shall be included
16# in all copies or substantial portions of the Materials.
17#
18# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21#
22# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
25# USE OR OTHER DEALINGS IN THE MATERIALS
26#
27# Author: Chia-I Wu <olv@lunarg.com>
28# Author: Jon Ashburn <jon@lunarg.com>
29# Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
30# Author: Tobin Ehlis <tobin@lunarg.com>
31# Author: Tony Barbour <tony@LunarG.com>
32# Author: Gwan-gyeong Mun <kk.moon@samsung.com>
33
34class Param(object):
35    """A function parameter."""
36
37    def __init__(self, ty, name):
38        self.ty = ty
39        self.name = name
40
41    def c(self):
42        """Return the parameter in C."""
43        idx = self.ty.find("[")
44
45        # arrays have a different syntax
46        if idx >= 0:
47            return "%s %s%s" % (self.ty[:idx], self.name, self.ty[idx:])
48        else:
49            return "%s %s" % (self.ty, self.name)
50
51    def indirection_level(self):
52        """Return the level of indirection."""
53        return self.ty.count("*") + self.ty.count("[")
54
55    def dereferenced_type(self, level=0):
56        """Return the type after dereferencing."""
57        if not level:
58            level = self.indirection_level()
59
60        deref = self.ty if level else ""
61        while level > 0:
62            idx = deref.rfind("[")
63            if idx < 0:
64                idx = deref.rfind("*")
65            if idx < 0:
66                deref = ""
67                break
68            deref = deref[:idx]
69            level -= 1;
70
71        return deref.rstrip()
72
73    def __repr__(self):
74        return "Param(\"%s\", \"%s\")" % (self.ty, self.name)
75
76class Proto(object):
77    """A function prototype."""
78
79    def __init__(self, ret, name, params=[]):
80        # the proto has only a param
81        if not isinstance(params, list):
82            params = [params]
83
84        self.ret = ret
85        self.name = name
86        self.params = params
87
88    def c_params(self, need_type=True, need_name=True):
89        """Return the parameter list in C."""
90        if self.params and (need_type or need_name):
91            if need_type and need_name:
92                return ", ".join([param.c() for param in self.params])
93            elif need_type:
94                return ", ".join([param.ty for param in self.params])
95            else:
96                return ", ".join([param.name for param in self.params])
97        else:
98            return "void" if need_type else ""
99
100    def c_decl(self, name, attr="", typed=False, need_param_names=True):
101        """Return a named declaration in C."""
102        if typed:
103            return "%s (%s*%s)(%s)" % (
104                self.ret,
105                attr + "_PTR " if attr else "",
106                name,
107                self.c_params(need_name=need_param_names))
108        else:
109            return "%s%s %s%s(%s)" % (
110                attr + "_ATTR " if attr else "",
111                self.ret,
112                attr + "_CALL " if attr else "",
113                name,
114                self.c_params(need_name=need_param_names))
115
116    def c_pretty_decl(self, name, attr=""):
117        """Return a named declaration in C, with vulkan.h formatting."""
118        plist = []
119        for param in self.params:
120            idx = param.ty.find("[")
121            if idx < 0:
122                idx = len(param.ty)
123
124            pad = 44 - idx
125            if pad <= 0:
126                pad = 1
127
128            plist.append("    %s%s%s%s" % (param.ty[:idx],
129                " " * pad, param.name, param.ty[idx:]))
130
131        return "%s%s %s%s(\n%s)" % (
132                attr + "_ATTR " if attr else "",
133                self.ret,
134                attr + "_CALL " if attr else "",
135                name,
136                ",\n".join(plist))
137
138    def c_typedef(self, suffix="", attr=""):
139        """Return the typedef for the prototype in C."""
140        return self.c_decl(self.name + suffix, attr=attr, typed=True)
141
142    def c_func(self, prefix="", attr=""):
143        """Return the prototype in C."""
144        return self.c_decl(prefix + self.name, attr=attr, typed=False)
145
146    def c_call(self):
147        """Return a call to the prototype in C."""
148        return "%s(%s)" % (self.name, self.c_params(need_type=False))
149
150    def object_in_params(self):
151        """Return the params that are simple VK objects and are inputs."""
152        return [param for param in self.params if param.ty in objects]
153
154    def object_out_params(self):
155        """Return the params that are simple VK objects and are outputs."""
156        return [param for param in self.params
157                if param.dereferenced_type() in objects]
158
159    def __repr__(self):
160        param_strs = []
161        for param in self.params:
162            param_strs.append(str(param))
163        param_str = "    [%s]" % (",\n     ".join(param_strs))
164
165        return "Proto(\"%s\", \"%s\",\n%s)" % \
166                (self.ret, self.name, param_str)
167
168class Extension(object):
169    def __init__(self, name, headers, objects, protos):
170        self.name = name
171        self.headers = headers
172        self.objects = objects
173        self.protos = protos
174
175    def __repr__(self):
176        lines = []
177        lines.append("Extension(")
178        lines.append("    name=\"%s\"," % self.name)
179        lines.append("    headers=[\"%s\"]," %
180                "\", \"".join(self.headers))
181
182        lines.append("    objects=[")
183        for obj in self.objects:
184            lines.append("        \"%s\"," % obj)
185        lines.append("    ],")
186
187        lines.append("    protos=[")
188        for proto in self.protos:
189            param_lines = str(proto).splitlines()
190            param_lines[-1] += ",\n" if proto != self.protos[-1] else ","
191            for p in param_lines:
192                lines.append("        " + p)
193        lines.append("    ],")
194        lines.append(")")
195
196        return "\n".join(lines)
197
198# VK core API
199core = Extension(
200    name="VK_CORE",
201    headers=["vulkan/vulkan.h"],
202    objects=[
203        "VkInstance",
204        "VkPhysicalDevice",
205        "VkDevice",
206        "VkQueue",
207        "VkSemaphore",
208        "VkCommandBuffer",
209        "VkFence",
210        "VkDeviceMemory",
211        "VkBuffer",
212        "VkImage",
213        "VkEvent",
214        "VkQueryPool",
215        "VkBufferView",
216        "VkImageView",
217        "VkShaderModule",
218        "VkPipelineCache",
219        "VkPipelineLayout",
220        "VkRenderPass",
221        "VkPipeline",
222        "VkDescriptorSetLayout",
223        "VkSampler",
224        "VkDescriptorPool",
225        "VkDescriptorSet",
226        "VkFramebuffer",
227        "VkCommandPool",
228    ],
229    protos=[
230        Proto("VkResult", "CreateInstance",
231            [Param("const VkInstanceCreateInfo*", "pCreateInfo"),
232             Param("const VkAllocationCallbacks*", "pAllocator"),
233             Param("VkInstance*", "pInstance")]),
234
235        Proto("void", "DestroyInstance",
236            [Param("VkInstance", "instance"),
237             Param("const VkAllocationCallbacks*", "pAllocator")]),
238
239        Proto("VkResult", "EnumeratePhysicalDevices",
240            [Param("VkInstance", "instance"),
241             Param("uint32_t*", "pPhysicalDeviceCount"),
242             Param("VkPhysicalDevice*", "pPhysicalDevices")]),
243
244        Proto("void", "GetPhysicalDeviceFeatures",
245            [Param("VkPhysicalDevice", "physicalDevice"),
246             Param("VkPhysicalDeviceFeatures*", "pFeatures")]),
247
248        Proto("void", "GetPhysicalDeviceFormatProperties",
249            [Param("VkPhysicalDevice", "physicalDevice"),
250             Param("VkFormat", "format"),
251             Param("VkFormatProperties*", "pFormatProperties")]),
252
253        Proto("VkResult", "GetPhysicalDeviceImageFormatProperties",
254            [Param("VkPhysicalDevice", "physicalDevice"),
255             Param("VkFormat", "format"),
256             Param("VkImageType", "type"),
257             Param("VkImageTiling", "tiling"),
258             Param("VkImageUsageFlags", "usage"),
259             Param("VkImageCreateFlags", "flags"),
260             Param("VkImageFormatProperties*", "pImageFormatProperties")]),
261
262        Proto("void", "GetPhysicalDeviceProperties",
263            [Param("VkPhysicalDevice", "physicalDevice"),
264             Param("VkPhysicalDeviceProperties*", "pProperties")]),
265
266        Proto("void", "GetPhysicalDeviceQueueFamilyProperties",
267            [Param("VkPhysicalDevice", "physicalDevice"),
268             Param("uint32_t*", "pQueueFamilyPropertyCount"),
269             Param("VkQueueFamilyProperties*", "pQueueFamilyProperties")]),
270
271        Proto("void", "GetPhysicalDeviceMemoryProperties",
272            [Param("VkPhysicalDevice", "physicalDevice"),
273             Param("VkPhysicalDeviceMemoryProperties*", "pMemoryProperties")]),
274
275        Proto("PFN_vkVoidFunction", "GetInstanceProcAddr",
276            [Param("VkInstance", "instance"),
277             Param("const char*", "pName")]),
278
279        Proto("PFN_vkVoidFunction", "GetDeviceProcAddr",
280            [Param("VkDevice", "device"),
281             Param("const char*", "pName")]),
282
283        Proto("VkResult", "CreateDevice",
284            [Param("VkPhysicalDevice", "physicalDevice"),
285             Param("const VkDeviceCreateInfo*", "pCreateInfo"),
286             Param("const VkAllocationCallbacks*", "pAllocator"),
287             Param("VkDevice*", "pDevice")]),
288
289        Proto("void", "DestroyDevice",
290            [Param("VkDevice", "device"),
291             Param("const VkAllocationCallbacks*", "pAllocator")]),
292
293        Proto("VkResult", "EnumerateInstanceExtensionProperties",
294            [Param("const char*", "pLayerName"),
295             Param("uint32_t*", "pPropertyCount"),
296             Param("VkExtensionProperties*", "pProperties")]),
297
298        Proto("VkResult", "EnumerateDeviceExtensionProperties",
299            [Param("VkPhysicalDevice", "physicalDevice"),
300             Param("const char*", "pLayerName"),
301             Param("uint32_t*", "pPropertyCount"),
302             Param("VkExtensionProperties*", "pProperties")]),
303
304        Proto("VkResult", "EnumerateInstanceLayerProperties",
305            [Param("uint32_t*", "pPropertyCount"),
306             Param("VkLayerProperties*", "pProperties")]),
307
308        Proto("VkResult", "EnumerateDeviceLayerProperties",
309            [Param("VkPhysicalDevice", "physicalDevice"),
310             Param("uint32_t*", "pPropertyCount"),
311             Param("VkLayerProperties*", "pProperties")]),
312
313        Proto("void", "GetDeviceQueue",
314            [Param("VkDevice", "device"),
315             Param("uint32_t", "queueFamilyIndex"),
316             Param("uint32_t", "queueIndex"),
317             Param("VkQueue*", "pQueue")]),
318
319        Proto("VkResult", "QueueSubmit",
320            [Param("VkQueue", "queue"),
321             Param("uint32_t", "submitCount"),
322             Param("const VkSubmitInfo*", "pSubmits"),
323             Param("VkFence", "fence")]),
324
325        Proto("VkResult", "QueueWaitIdle",
326            [Param("VkQueue", "queue")]),
327
328        Proto("VkResult", "DeviceWaitIdle",
329            [Param("VkDevice", "device")]),
330
331        Proto("VkResult", "AllocateMemory",
332            [Param("VkDevice", "device"),
333             Param("const VkMemoryAllocateInfo*", "pAllocateInfo"),
334             Param("const VkAllocationCallbacks*", "pAllocator"),
335             Param("VkDeviceMemory*", "pMemory")]),
336
337        Proto("void", "FreeMemory",
338            [Param("VkDevice", "device"),
339             Param("VkDeviceMemory", "memory"),
340             Param("const VkAllocationCallbacks*", "pAllocator")]),
341
342        Proto("VkResult", "MapMemory",
343            [Param("VkDevice", "device"),
344             Param("VkDeviceMemory", "memory"),
345             Param("VkDeviceSize", "offset"),
346             Param("VkDeviceSize", "size"),
347             Param("VkMemoryMapFlags", "flags"),
348             Param("void**", "ppData")]),
349
350        Proto("void", "UnmapMemory",
351            [Param("VkDevice", "device"),
352             Param("VkDeviceMemory", "memory")]),
353
354        Proto("VkResult", "FlushMappedMemoryRanges",
355            [Param("VkDevice", "device"),
356             Param("uint32_t", "memoryRangeCount"),
357             Param("const VkMappedMemoryRange*", "pMemoryRanges")]),
358
359        Proto("VkResult", "InvalidateMappedMemoryRanges",
360            [Param("VkDevice", "device"),
361             Param("uint32_t", "memoryRangeCount"),
362             Param("const VkMappedMemoryRange*", "pMemoryRanges")]),
363
364        Proto("void", "GetDeviceMemoryCommitment",
365            [Param("VkDevice", "device"),
366             Param("VkDeviceMemory", "memory"),
367             Param("VkDeviceSize*", "pCommittedMemoryInBytes")]),
368
369        Proto("VkResult", "BindBufferMemory",
370            [Param("VkDevice", "device"),
371             Param("VkBuffer", "buffer"),
372             Param("VkDeviceMemory", "memory"),
373             Param("VkDeviceSize", "memoryOffset")]),
374
375        Proto("VkResult", "BindImageMemory",
376            [Param("VkDevice", "device"),
377             Param("VkImage", "image"),
378             Param("VkDeviceMemory", "memory"),
379             Param("VkDeviceSize", "memoryOffset")]),
380
381        Proto("void", "GetBufferMemoryRequirements",
382            [Param("VkDevice", "device"),
383             Param("VkBuffer", "buffer"),
384             Param("VkMemoryRequirements*", "pMemoryRequirements")]),
385
386        Proto("void", "GetImageMemoryRequirements",
387            [Param("VkDevice", "device"),
388             Param("VkImage", "image"),
389             Param("VkMemoryRequirements*", "pMemoryRequirements")]),
390
391        Proto("void", "GetImageSparseMemoryRequirements",
392            [Param("VkDevice", "device"),
393             Param("VkImage", "image"),
394             Param("uint32_t*", "pSparseMemoryRequirementCount"),
395             Param("VkSparseImageMemoryRequirements*", "pSparseMemoryRequirements")]),
396
397        Proto("void", "GetPhysicalDeviceSparseImageFormatProperties",
398            [Param("VkPhysicalDevice", "physicalDevice"),
399             Param("VkFormat", "format"),
400             Param("VkImageType", "type"),
401             Param("VkSampleCountFlagBits", "samples"),
402             Param("VkImageUsageFlags", "usage"),
403             Param("VkImageTiling", "tiling"),
404             Param("uint32_t*", "pPropertyCount"),
405             Param("VkSparseImageFormatProperties*", "pProperties")]),
406
407        Proto("VkResult", "QueueBindSparse",
408            [Param("VkQueue", "queue"),
409             Param("uint32_t", "bindInfoCount"),
410             Param("const VkBindSparseInfo*", "pBindInfo"),
411             Param("VkFence", "fence")]),
412
413        Proto("VkResult", "CreateFence",
414            [Param("VkDevice", "device"),
415             Param("const VkFenceCreateInfo*", "pCreateInfo"),
416             Param("const VkAllocationCallbacks*", "pAllocator"),
417             Param("VkFence*", "pFence")]),
418
419        Proto("void", "DestroyFence",
420            [Param("VkDevice", "device"),
421             Param("VkFence", "fence"),
422             Param("const VkAllocationCallbacks*", "pAllocator")]),
423
424        Proto("VkResult", "ResetFences",
425            [Param("VkDevice", "device"),
426             Param("uint32_t", "fenceCount"),
427             Param("const VkFence*", "pFences")]),
428
429        Proto("VkResult", "GetFenceStatus",
430            [Param("VkDevice", "device"),
431             Param("VkFence", "fence")]),
432
433        Proto("VkResult", "WaitForFences",
434            [Param("VkDevice", "device"),
435             Param("uint32_t", "fenceCount"),
436             Param("const VkFence*", "pFences"),
437             Param("VkBool32", "waitAll"),
438             Param("uint64_t", "timeout")]),
439
440        Proto("VkResult", "CreateSemaphore",
441            [Param("VkDevice", "device"),
442             Param("const VkSemaphoreCreateInfo*", "pCreateInfo"),
443             Param("const VkAllocationCallbacks*", "pAllocator"),
444             Param("VkSemaphore*", "pSemaphore")]),
445
446        Proto("void", "DestroySemaphore",
447            [Param("VkDevice", "device"),
448             Param("VkSemaphore", "semaphore"),
449             Param("const VkAllocationCallbacks*", "pAllocator")]),
450
451        Proto("VkResult", "CreateEvent",
452            [Param("VkDevice", "device"),
453             Param("const VkEventCreateInfo*", "pCreateInfo"),
454             Param("const VkAllocationCallbacks*", "pAllocator"),
455             Param("VkEvent*", "pEvent")]),
456
457        Proto("void", "DestroyEvent",
458            [Param("VkDevice", "device"),
459             Param("VkEvent", "event"),
460             Param("const VkAllocationCallbacks*", "pAllocator")]),
461
462        Proto("VkResult", "GetEventStatus",
463            [Param("VkDevice", "device"),
464             Param("VkEvent", "event")]),
465
466        Proto("VkResult", "SetEvent",
467            [Param("VkDevice", "device"),
468             Param("VkEvent", "event")]),
469
470        Proto("VkResult", "ResetEvent",
471            [Param("VkDevice", "device"),
472             Param("VkEvent", "event")]),
473
474        Proto("VkResult", "CreateQueryPool",
475            [Param("VkDevice", "device"),
476             Param("const VkQueryPoolCreateInfo*", "pCreateInfo"),
477             Param("const VkAllocationCallbacks*", "pAllocator"),
478             Param("VkQueryPool*", "pQueryPool")]),
479
480        Proto("void", "DestroyQueryPool",
481            [Param("VkDevice", "device"),
482             Param("VkQueryPool", "queryPool"),
483             Param("const VkAllocationCallbacks*", "pAllocator")]),
484
485        Proto("VkResult", "GetQueryPoolResults",
486            [Param("VkDevice", "device"),
487             Param("VkQueryPool", "queryPool"),
488             Param("uint32_t", "firstQuery"),
489             Param("uint32_t", "queryCount"),
490             Param("size_t", "dataSize"),
491             Param("void*", "pData"),
492             Param("VkDeviceSize", "stride"),
493             Param("VkQueryResultFlags", "flags")]),
494
495        Proto("VkResult", "CreateBuffer",
496            [Param("VkDevice", "device"),
497             Param("const VkBufferCreateInfo*", "pCreateInfo"),
498             Param("const VkAllocationCallbacks*", "pAllocator"),
499             Param("VkBuffer*", "pBuffer")]),
500
501        Proto("void", "DestroyBuffer",
502            [Param("VkDevice", "device"),
503             Param("VkBuffer", "buffer"),
504             Param("const VkAllocationCallbacks*", "pAllocator")]),
505
506        Proto("VkResult", "CreateBufferView",
507            [Param("VkDevice", "device"),
508             Param("const VkBufferViewCreateInfo*", "pCreateInfo"),
509             Param("const VkAllocationCallbacks*", "pAllocator"),
510             Param("VkBufferView*", "pView")]),
511
512        Proto("void", "DestroyBufferView",
513            [Param("VkDevice", "device"),
514             Param("VkBufferView", "bufferView"),
515             Param("const VkAllocationCallbacks*", "pAllocator")]),
516
517        Proto("VkResult", "CreateImage",
518            [Param("VkDevice", "device"),
519             Param("const VkImageCreateInfo*", "pCreateInfo"),
520             Param("const VkAllocationCallbacks*", "pAllocator"),
521             Param("VkImage*", "pImage")]),
522
523        Proto("void", "DestroyImage",
524            [Param("VkDevice", "device"),
525             Param("VkImage", "image"),
526             Param("const VkAllocationCallbacks*", "pAllocator")]),
527
528        Proto("void", "GetImageSubresourceLayout",
529            [Param("VkDevice", "device"),
530             Param("VkImage", "image"),
531             Param("const VkImageSubresource*", "pSubresource"),
532             Param("VkSubresourceLayout*", "pLayout")]),
533
534        Proto("VkResult", "CreateImageView",
535            [Param("VkDevice", "device"),
536             Param("const VkImageViewCreateInfo*", "pCreateInfo"),
537             Param("const VkAllocationCallbacks*", "pAllocator"),
538             Param("VkImageView*", "pView")]),
539
540        Proto("void", "DestroyImageView",
541            [Param("VkDevice", "device"),
542             Param("VkImageView", "imageView"),
543             Param("const VkAllocationCallbacks*", "pAllocator")]),
544
545        Proto("VkResult", "CreateShaderModule",
546            [Param("VkDevice", "device"),
547             Param("const VkShaderModuleCreateInfo*", "pCreateInfo"),
548             Param("const VkAllocationCallbacks*", "pAllocator"),
549             Param("VkShaderModule*", "pShaderModule")]),
550
551        Proto("void", "DestroyShaderModule",
552            [Param("VkDevice", "device"),
553             Param("VkShaderModule", "shaderModule"),
554             Param("const VkAllocationCallbacks*", "pAllocator")]),
555
556        Proto("VkResult", "CreatePipelineCache",
557            [Param("VkDevice", "device"),
558             Param("const VkPipelineCacheCreateInfo*", "pCreateInfo"),
559             Param("const VkAllocationCallbacks*", "pAllocator"),
560             Param("VkPipelineCache*", "pPipelineCache")]),
561
562        Proto("void", "DestroyPipelineCache",
563            [Param("VkDevice", "device"),
564             Param("VkPipelineCache", "pipelineCache"),
565             Param("const VkAllocationCallbacks*", "pAllocator")]),
566
567        Proto("VkResult", "GetPipelineCacheData",
568            [Param("VkDevice", "device"),
569             Param("VkPipelineCache", "pipelineCache"),
570             Param("size_t*", "pDataSize"),
571             Param("void*", "pData")]),
572
573        Proto("VkResult", "MergePipelineCaches",
574            [Param("VkDevice", "device"),
575             Param("VkPipelineCache", "dstCache"),
576             Param("uint32_t", "srcCacheCount"),
577             Param("const VkPipelineCache*", "pSrcCaches")]),
578
579        Proto("VkResult", "CreateGraphicsPipelines",
580            [Param("VkDevice", "device"),
581             Param("VkPipelineCache", "pipelineCache"),
582             Param("uint32_t", "createInfoCount"),
583             Param("const VkGraphicsPipelineCreateInfo*", "pCreateInfos"),
584             Param("const VkAllocationCallbacks*", "pAllocator"),
585             Param("VkPipeline*", "pPipelines")]),
586
587        Proto("VkResult", "CreateComputePipelines",
588            [Param("VkDevice", "device"),
589             Param("VkPipelineCache", "pipelineCache"),
590             Param("uint32_t", "createInfoCount"),
591             Param("const VkComputePipelineCreateInfo*", "pCreateInfos"),
592             Param("const VkAllocationCallbacks*", "pAllocator"),
593             Param("VkPipeline*", "pPipelines")]),
594
595        Proto("void", "DestroyPipeline",
596            [Param("VkDevice", "device"),
597             Param("VkPipeline", "pipeline"),
598             Param("const VkAllocationCallbacks*", "pAllocator")]),
599
600        Proto("VkResult", "CreatePipelineLayout",
601            [Param("VkDevice", "device"),
602             Param("const VkPipelineLayoutCreateInfo*", "pCreateInfo"),
603             Param("const VkAllocationCallbacks*", "pAllocator"),
604             Param("VkPipelineLayout*", "pPipelineLayout")]),
605
606        Proto("void", "DestroyPipelineLayout",
607            [Param("VkDevice", "device"),
608             Param("VkPipelineLayout", "pipelineLayout"),
609             Param("const VkAllocationCallbacks*", "pAllocator")]),
610
611        Proto("VkResult", "CreateSampler",
612            [Param("VkDevice", "device"),
613             Param("const VkSamplerCreateInfo*", "pCreateInfo"),
614             Param("const VkAllocationCallbacks*", "pAllocator"),
615             Param("VkSampler*", "pSampler")]),
616
617        Proto("void", "DestroySampler",
618            [Param("VkDevice", "device"),
619             Param("VkSampler", "sampler"),
620             Param("const VkAllocationCallbacks*", "pAllocator")]),
621
622        Proto("VkResult", "CreateDescriptorSetLayout",
623            [Param("VkDevice", "device"),
624             Param("const VkDescriptorSetLayoutCreateInfo*", "pCreateInfo"),
625             Param("const VkAllocationCallbacks*", "pAllocator"),
626             Param("VkDescriptorSetLayout*", "pSetLayout")]),
627
628        Proto("void", "DestroyDescriptorSetLayout",
629            [Param("VkDevice", "device"),
630             Param("VkDescriptorSetLayout", "descriptorSetLayout"),
631             Param("const VkAllocationCallbacks*", "pAllocator")]),
632
633        Proto("VkResult", "CreateDescriptorPool",
634            [Param("VkDevice", "device"),
635             Param("const VkDescriptorPoolCreateInfo*", "pCreateInfo"),
636             Param("const VkAllocationCallbacks*", "pAllocator"),
637             Param("VkDescriptorPool*", "pDescriptorPool")]),
638
639        Proto("void", "DestroyDescriptorPool",
640            [Param("VkDevice", "device"),
641             Param("VkDescriptorPool", "descriptorPool"),
642             Param("const VkAllocationCallbacks*", "pAllocator")]),
643
644        Proto("VkResult", "ResetDescriptorPool",
645            [Param("VkDevice", "device"),
646             Param("VkDescriptorPool", "descriptorPool"),
647             Param("VkDescriptorPoolResetFlags", "flags")]),
648
649        Proto("VkResult", "AllocateDescriptorSets",
650            [Param("VkDevice", "device"),
651             Param("const VkDescriptorSetAllocateInfo*", "pAllocateInfo"),
652             Param("VkDescriptorSet*", "pDescriptorSets")]),
653
654        Proto("VkResult", "FreeDescriptorSets",
655            [Param("VkDevice", "device"),
656             Param("VkDescriptorPool", "descriptorPool"),
657             Param("uint32_t", "descriptorSetCount"),
658             Param("const VkDescriptorSet*", "pDescriptorSets")]),
659
660        Proto("void", "UpdateDescriptorSets",
661            [Param("VkDevice", "device"),
662             Param("uint32_t", "descriptorWriteCount"),
663             Param("const VkWriteDescriptorSet*", "pDescriptorWrites"),
664             Param("uint32_t", "descriptorCopyCount"),
665             Param("const VkCopyDescriptorSet*", "pDescriptorCopies")]),
666
667        Proto("VkResult", "CreateFramebuffer",
668            [Param("VkDevice", "device"),
669             Param("const VkFramebufferCreateInfo*", "pCreateInfo"),
670             Param("const VkAllocationCallbacks*", "pAllocator"),
671             Param("VkFramebuffer*", "pFramebuffer")]),
672
673        Proto("void", "DestroyFramebuffer",
674            [Param("VkDevice", "device"),
675             Param("VkFramebuffer", "framebuffer"),
676             Param("const VkAllocationCallbacks*", "pAllocator")]),
677
678        Proto("VkResult", "CreateRenderPass",
679            [Param("VkDevice", "device"),
680             Param("const VkRenderPassCreateInfo*", "pCreateInfo"),
681             Param("const VkAllocationCallbacks*", "pAllocator"),
682             Param("VkRenderPass*", "pRenderPass")]),
683
684        Proto("void", "DestroyRenderPass",
685            [Param("VkDevice", "device"),
686             Param("VkRenderPass", "renderPass"),
687             Param("const VkAllocationCallbacks*", "pAllocator")]),
688
689        Proto("void", "GetRenderAreaGranularity",
690            [Param("VkDevice", "device"),
691             Param("VkRenderPass", "renderPass"),
692             Param("VkExtent2D*", "pGranularity")]),
693
694        Proto("VkResult", "CreateCommandPool",
695            [Param("VkDevice", "device"),
696             Param("const VkCommandPoolCreateInfo*", "pCreateInfo"),
697             Param("const VkAllocationCallbacks*", "pAllocator"),
698             Param("VkCommandPool*", "pCommandPool")]),
699
700        Proto("void", "DestroyCommandPool",
701            [Param("VkDevice", "device"),
702             Param("VkCommandPool", "commandPool"),
703             Param("const VkAllocationCallbacks*", "pAllocator")]),
704
705        Proto("VkResult", "ResetCommandPool",
706            [Param("VkDevice", "device"),
707             Param("VkCommandPool", "commandPool"),
708             Param("VkCommandPoolResetFlags", "flags")]),
709
710        Proto("VkResult", "AllocateCommandBuffers",
711            [Param("VkDevice", "device"),
712             Param("const VkCommandBufferAllocateInfo*", "pAllocateInfo"),
713             Param("VkCommandBuffer*", "pCommandBuffers")]),
714
715        Proto("void", "FreeCommandBuffers",
716            [Param("VkDevice", "device"),
717             Param("VkCommandPool", "commandPool"),
718             Param("uint32_t", "commandBufferCount"),
719             Param("const VkCommandBuffer*", "pCommandBuffers")]),
720
721        Proto("VkResult", "BeginCommandBuffer",
722            [Param("VkCommandBuffer", "commandBuffer"),
723             Param("const VkCommandBufferBeginInfo*", "pBeginInfo")]),
724
725        Proto("VkResult", "EndCommandBuffer",
726            [Param("VkCommandBuffer", "commandBuffer")]),
727
728        Proto("VkResult", "ResetCommandBuffer",
729            [Param("VkCommandBuffer", "commandBuffer"),
730             Param("VkCommandBufferResetFlags", "flags")]),
731
732        Proto("void", "CmdBindPipeline",
733            [Param("VkCommandBuffer", "commandBuffer"),
734             Param("VkPipelineBindPoint", "pipelineBindPoint"),
735             Param("VkPipeline", "pipeline")]),
736
737        Proto("void", "CmdSetViewport",
738            [Param("VkCommandBuffer", "commandBuffer"),
739             Param("uint32_t", "firstViewport"),
740             Param("uint32_t", "viewportCount"),
741             Param("const VkViewport*", "pViewports")]),
742
743        Proto("void", "CmdSetScissor",
744            [Param("VkCommandBuffer", "commandBuffer"),
745             Param("uint32_t", "firstScissor"),
746             Param("uint32_t", "scissorCount"),
747             Param("const VkRect2D*", "pScissors")]),
748
749        Proto("void", "CmdSetLineWidth",
750            [Param("VkCommandBuffer", "commandBuffer"),
751             Param("float", "lineWidth")]),
752
753        Proto("void", "CmdSetDepthBias",
754            [Param("VkCommandBuffer", "commandBuffer"),
755             Param("float", "depthBiasConstantFactor"),
756             Param("float", "depthBiasClamp"),
757             Param("float", "depthBiasSlopeFactor")]),
758
759        Proto("void", "CmdSetBlendConstants",
760            [Param("VkCommandBuffer", "commandBuffer"),
761             Param("const float[4]", "blendConstants")]),
762
763        Proto("void", "CmdSetDepthBounds",
764            [Param("VkCommandBuffer", "commandBuffer"),
765             Param("float", "minDepthBounds"),
766             Param("float", "maxDepthBounds")]),
767
768        Proto("void", "CmdSetStencilCompareMask",
769            [Param("VkCommandBuffer", "commandBuffer"),
770             Param("VkStencilFaceFlags", "faceMask"),
771             Param("uint32_t", "compareMask")]),
772
773        Proto("void", "CmdSetStencilWriteMask",
774            [Param("VkCommandBuffer", "commandBuffer"),
775             Param("VkStencilFaceFlags", "faceMask"),
776             Param("uint32_t", "writeMask")]),
777
778        Proto("void", "CmdSetStencilReference",
779            [Param("VkCommandBuffer", "commandBuffer"),
780             Param("VkStencilFaceFlags", "faceMask"),
781             Param("uint32_t", "reference")]),
782
783        Proto("void", "CmdBindDescriptorSets",
784            [Param("VkCommandBuffer", "commandBuffer"),
785             Param("VkPipelineBindPoint", "pipelineBindPoint"),
786             Param("VkPipelineLayout", "layout"),
787             Param("uint32_t", "firstSet"),
788             Param("uint32_t", "descriptorSetCount"),
789             Param("const VkDescriptorSet*", "pDescriptorSets"),
790             Param("uint32_t", "dynamicOffsetCount"),
791             Param("const uint32_t*", "pDynamicOffsets")]),
792
793        Proto("void", "CmdBindIndexBuffer",
794            [Param("VkCommandBuffer", "commandBuffer"),
795             Param("VkBuffer", "buffer"),
796             Param("VkDeviceSize", "offset"),
797             Param("VkIndexType", "indexType")]),
798
799        Proto("void", "CmdBindVertexBuffers",
800            [Param("VkCommandBuffer", "commandBuffer"),
801             Param("uint32_t", "firstBinding"),
802             Param("uint32_t", "bindingCount"),
803             Param("const VkBuffer*", "pBuffers"),
804             Param("const VkDeviceSize*", "pOffsets")]),
805
806        Proto("void", "CmdDraw",
807            [Param("VkCommandBuffer", "commandBuffer"),
808             Param("uint32_t", "vertexCount"),
809             Param("uint32_t", "instanceCount"),
810             Param("uint32_t", "firstVertex"),
811             Param("uint32_t", "firstInstance")]),
812
813        Proto("void", "CmdDrawIndexed",
814            [Param("VkCommandBuffer", "commandBuffer"),
815             Param("uint32_t", "indexCount"),
816             Param("uint32_t", "instanceCount"),
817             Param("uint32_t", "firstIndex"),
818             Param("int32_t", "vertexOffset"),
819             Param("uint32_t", "firstInstance")]),
820
821        Proto("void", "CmdDrawIndirect",
822            [Param("VkCommandBuffer", "commandBuffer"),
823             Param("VkBuffer", "buffer"),
824             Param("VkDeviceSize", "offset"),
825             Param("uint32_t", "drawCount"),
826             Param("uint32_t", "stride")]),
827
828        Proto("void", "CmdDrawIndexedIndirect",
829            [Param("VkCommandBuffer", "commandBuffer"),
830             Param("VkBuffer", "buffer"),
831             Param("VkDeviceSize", "offset"),
832             Param("uint32_t", "drawCount"),
833             Param("uint32_t", "stride")]),
834
835        Proto("void", "CmdDispatch",
836            [Param("VkCommandBuffer", "commandBuffer"),
837             Param("uint32_t", "x"),
838             Param("uint32_t", "y"),
839             Param("uint32_t", "z")]),
840
841        Proto("void", "CmdDispatchIndirect",
842            [Param("VkCommandBuffer", "commandBuffer"),
843             Param("VkBuffer", "buffer"),
844             Param("VkDeviceSize", "offset")]),
845
846        Proto("void", "CmdCopyBuffer",
847            [Param("VkCommandBuffer", "commandBuffer"),
848             Param("VkBuffer", "srcBuffer"),
849             Param("VkBuffer", "dstBuffer"),
850             Param("uint32_t", "regionCount"),
851             Param("const VkBufferCopy*", "pRegions")]),
852
853        Proto("void", "CmdCopyImage",
854            [Param("VkCommandBuffer", "commandBuffer"),
855             Param("VkImage", "srcImage"),
856             Param("VkImageLayout", "srcImageLayout"),
857             Param("VkImage", "dstImage"),
858             Param("VkImageLayout", "dstImageLayout"),
859             Param("uint32_t", "regionCount"),
860             Param("const VkImageCopy*", "pRegions")]),
861
862        Proto("void", "CmdBlitImage",
863            [Param("VkCommandBuffer", "commandBuffer"),
864             Param("VkImage", "srcImage"),
865             Param("VkImageLayout", "srcImageLayout"),
866             Param("VkImage", "dstImage"),
867             Param("VkImageLayout", "dstImageLayout"),
868             Param("uint32_t", "regionCount"),
869             Param("const VkImageBlit*", "pRegions"),
870             Param("VkFilter", "filter")]),
871
872        Proto("void", "CmdCopyBufferToImage",
873            [Param("VkCommandBuffer", "commandBuffer"),
874             Param("VkBuffer", "srcBuffer"),
875             Param("VkImage", "dstImage"),
876             Param("VkImageLayout", "dstImageLayout"),
877             Param("uint32_t", "regionCount"),
878             Param("const VkBufferImageCopy*", "pRegions")]),
879
880        Proto("void", "CmdCopyImageToBuffer",
881            [Param("VkCommandBuffer", "commandBuffer"),
882             Param("VkImage", "srcImage"),
883             Param("VkImageLayout", "srcImageLayout"),
884             Param("VkBuffer", "dstBuffer"),
885             Param("uint32_t", "regionCount"),
886             Param("const VkBufferImageCopy*", "pRegions")]),
887
888        Proto("void", "CmdUpdateBuffer",
889            [Param("VkCommandBuffer", "commandBuffer"),
890             Param("VkBuffer", "dstBuffer"),
891             Param("VkDeviceSize", "dstOffset"),
892             Param("VkDeviceSize", "dataSize"),
893             Param("const uint32_t*", "pData")]),
894
895        Proto("void", "CmdFillBuffer",
896            [Param("VkCommandBuffer", "commandBuffer"),
897             Param("VkBuffer", "dstBuffer"),
898             Param("VkDeviceSize", "dstOffset"),
899             Param("VkDeviceSize", "size"),
900             Param("uint32_t", "data")]),
901
902        Proto("void", "CmdClearColorImage",
903            [Param("VkCommandBuffer", "commandBuffer"),
904             Param("VkImage", "image"),
905             Param("VkImageLayout", "imageLayout"),
906             Param("const VkClearColorValue*", "pColor"),
907             Param("uint32_t", "rangeCount"),
908             Param("const VkImageSubresourceRange*", "pRanges")]),
909
910        Proto("void", "CmdClearDepthStencilImage",
911            [Param("VkCommandBuffer", "commandBuffer"),
912             Param("VkImage", "image"),
913             Param("VkImageLayout", "imageLayout"),
914             Param("const VkClearDepthStencilValue*", "pDepthStencil"),
915             Param("uint32_t", "rangeCount"),
916             Param("const VkImageSubresourceRange*", "pRanges")]),
917
918        Proto("void", "CmdClearAttachments",
919            [Param("VkCommandBuffer", "commandBuffer"),
920             Param("uint32_t", "attachmentCount"),
921             Param("const VkClearAttachment*", "pAttachments"),
922             Param("uint32_t", "rectCount"),
923             Param("const VkClearRect*", "pRects")]),
924
925        Proto("void", "CmdResolveImage",
926            [Param("VkCommandBuffer", "commandBuffer"),
927             Param("VkImage", "srcImage"),
928             Param("VkImageLayout", "srcImageLayout"),
929             Param("VkImage", "dstImage"),
930             Param("VkImageLayout", "dstImageLayout"),
931             Param("uint32_t", "regionCount"),
932             Param("const VkImageResolve*", "pRegions")]),
933
934        Proto("void", "CmdSetEvent",
935            [Param("VkCommandBuffer", "commandBuffer"),
936             Param("VkEvent", "event"),
937             Param("VkPipelineStageFlags", "stageMask")]),
938
939        Proto("void", "CmdResetEvent",
940            [Param("VkCommandBuffer", "commandBuffer"),
941             Param("VkEvent", "event"),
942             Param("VkPipelineStageFlags", "stageMask")]),
943
944        Proto("void", "CmdWaitEvents",
945            [Param("VkCommandBuffer", "commandBuffer"),
946             Param("uint32_t", "eventCount"),
947             Param("const VkEvent*", "pEvents"),
948             Param("VkPipelineStageFlags", "srcStageMask"),
949             Param("VkPipelineStageFlags", "dstStageMask"),
950             Param("uint32_t", "memoryBarrierCount"),
951             Param("const VkMemoryBarrier*", "pMemoryBarriers"),
952             Param("uint32_t", "bufferMemoryBarrierCount"),
953             Param("const VkBufferMemoryBarrier*", "pBufferMemoryBarriers"),
954             Param("uint32_t", "imageMemoryBarrierCount"),
955             Param("const VkImageMemoryBarrier*", "pImageMemoryBarriers")]),
956
957        Proto("void", "CmdPipelineBarrier",
958            [Param("VkCommandBuffer", "commandBuffer"),
959             Param("VkPipelineStageFlags", "srcStageMask"),
960             Param("VkPipelineStageFlags", "dstStageMask"),
961             Param("VkDependencyFlags", "dependencyFlags"),
962             Param("uint32_t", "memoryBarrierCount"),
963             Param("const VkMemoryBarrier*", "pMemoryBarriers"),
964             Param("uint32_t", "bufferMemoryBarrierCount"),
965             Param("const VkBufferMemoryBarrier*", "pBufferMemoryBarriers"),
966             Param("uint32_t", "imageMemoryBarrierCount"),
967             Param("const VkImageMemoryBarrier*", "pImageMemoryBarriers")]),
968
969        Proto("void", "CmdBeginQuery",
970            [Param("VkCommandBuffer", "commandBuffer"),
971             Param("VkQueryPool", "queryPool"),
972             Param("uint32_t", "query"),
973             Param("VkQueryControlFlags", "flags")]),
974
975        Proto("void", "CmdEndQuery",
976            [Param("VkCommandBuffer", "commandBuffer"),
977             Param("VkQueryPool", "queryPool"),
978             Param("uint32_t", "query")]),
979
980        Proto("void", "CmdResetQueryPool",
981            [Param("VkCommandBuffer", "commandBuffer"),
982             Param("VkQueryPool", "queryPool"),
983             Param("uint32_t", "firstQuery"),
984             Param("uint32_t", "queryCount")]),
985
986        Proto("void", "CmdWriteTimestamp",
987            [Param("VkCommandBuffer", "commandBuffer"),
988             Param("VkPipelineStageFlagBits", "pipelineStage"),
989             Param("VkQueryPool", "queryPool"),
990             Param("uint32_t", "query")]),
991
992        Proto("void", "CmdCopyQueryPoolResults",
993            [Param("VkCommandBuffer", "commandBuffer"),
994             Param("VkQueryPool", "queryPool"),
995             Param("uint32_t", "firstQuery"),
996             Param("uint32_t", "queryCount"),
997             Param("VkBuffer", "dstBuffer"),
998             Param("VkDeviceSize", "dstOffset"),
999             Param("VkDeviceSize", "stride"),
1000             Param("VkQueryResultFlags", "flags")]),
1001
1002        Proto("void", "CmdPushConstants",
1003            [Param("VkCommandBuffer", "commandBuffer"),
1004             Param("VkPipelineLayout", "layout"),
1005             Param("VkShaderStageFlags", "stageFlags"),
1006             Param("uint32_t", "offset"),
1007             Param("uint32_t", "size"),
1008             Param("const void*", "pValues")]),
1009
1010        Proto("void", "CmdBeginRenderPass",
1011            [Param("VkCommandBuffer", "commandBuffer"),
1012             Param("const VkRenderPassBeginInfo*", "pRenderPassBegin"),
1013             Param("VkSubpassContents", "contents")]),
1014
1015        Proto("void", "CmdNextSubpass",
1016            [Param("VkCommandBuffer", "commandBuffer"),
1017             Param("VkSubpassContents", "contents")]),
1018
1019        Proto("void", "CmdEndRenderPass",
1020            [Param("VkCommandBuffer", "commandBuffer")]),
1021
1022        Proto("void", "CmdExecuteCommands",
1023            [Param("VkCommandBuffer", "commandBuffer"),
1024             Param("uint32_t", "commandBufferCount"),
1025             Param("const VkCommandBuffer*", "pCommandBuffers")]),
1026    ],
1027)
1028
1029ext_khr_surface = Extension(
1030    name="VK_KHR_surface",
1031    headers=["vulkan/vulkan.h"],
1032    objects=["vkSurfaceKHR"],
1033    protos=[
1034        Proto("void", "DestroySurfaceKHR",
1035            [Param("VkInstance", "instance"),
1036             Param("VkSurfaceKHR", "surface"),
1037             Param("const VkAllocationCallbacks*", "pAllocator")]),
1038
1039        Proto("VkResult", "GetPhysicalDeviceSurfaceSupportKHR",
1040            [Param("VkPhysicalDevice", "physicalDevice"),
1041             Param("uint32_t", "queueFamilyIndex"),
1042             Param("VkSurfaceKHR", "surface"),
1043             Param("VkBool32*", "pSupported")]),
1044
1045        Proto("VkResult", "GetPhysicalDeviceSurfaceCapabilitiesKHR",
1046            [Param("VkPhysicalDevice", "physicalDevice"),
1047	     Param("VkSurfaceKHR", "surface"),
1048             Param("VkSurfaceCapabilitiesKHR*", "pSurfaceCapabilities")]),
1049
1050        Proto("VkResult", "GetPhysicalDeviceSurfaceFormatsKHR",
1051            [Param("VkPhysicalDevice", "physicalDevice"),
1052	     Param("VkSurfaceKHR", "surface"),
1053	     Param("uint32_t*", "pSurfaceFormatCount"),
1054             Param("VkSurfaceFormatKHR*", "pSurfaceFormats")]),
1055
1056        Proto("VkResult", "GetPhysicalDeviceSurfacePresentModesKHR",
1057            [Param("VkPhysicalDevice", "physicalDevice"),
1058	     Param("VkSurfaceKHR", "surface"),
1059	     Param("uint32_t*", "pPresentModeCount"),
1060             Param("VkPresentModeKHR*", "pPresentModes")]),
1061    ],
1062)
1063
1064ext_khr_device_swapchain = Extension(
1065    name="VK_KHR_swapchain",
1066    headers=["vulkan/vulkan.h"],
1067    objects=["VkSwapchainKHR"],
1068    protos=[
1069        Proto("VkResult", "CreateSwapchainKHR",
1070            [Param("VkDevice", "device"),
1071             Param("const VkSwapchainCreateInfoKHR*", "pCreateInfo"),
1072             Param("const VkAllocationCallbacks*", "pAllocator"),
1073             Param("VkSwapchainKHR*", "pSwapchain")]),
1074
1075        Proto("void", "DestroySwapchainKHR",
1076            [Param("VkDevice", "device"),
1077             Param("VkSwapchainKHR", "swapchain"),
1078             Param("const VkAllocationCallbacks*", "pAllocator")]),
1079
1080        Proto("VkResult", "GetSwapchainImagesKHR",
1081            [Param("VkDevice", "device"),
1082	     Param("VkSwapchainKHR", "swapchain"),
1083	     Param("uint32_t*", "pSwapchainImageCount"),
1084             Param("VkImage*", "pSwapchainImages")]),
1085
1086        Proto("VkResult", "AcquireNextImageKHR",
1087            [Param("VkDevice", "device"),
1088             Param("VkSwapchainKHR", "swapchain"),
1089             Param("uint64_t", "timeout"),
1090             Param("VkSemaphore", "semaphore"),
1091             Param("VkFence", "fence"),
1092             Param("uint32_t*", "pImageIndex")]),
1093
1094        Proto("VkResult", "QueuePresentKHR",
1095            [Param("VkQueue", "queue"),
1096             Param("const VkPresentInfoKHR*", "pPresentInfo")]),
1097    ],
1098)
1099
1100ext_khr_xcb_surface = Extension(
1101    name="VK_KHR_xcb_surface",
1102    headers=["vulkan/vulkan.h"],
1103    objects=[],
1104    protos=[
1105        Proto("VkResult", "CreateXcbSurfaceKHR",
1106            [Param("VkInstance", "instance"),
1107             Param("const VkXcbSurfaceCreateInfoKHR*", "pCreateInfo"),
1108             Param("const VkAllocationCallbacks*", "pAllocator"),
1109             Param("VkSurfaceKHR*", "pSurface")]),
1110
1111        Proto("VkBool32", "GetPhysicalDeviceXcbPresentationSupportKHR",
1112            [Param("VkPhysicalDevice", "physicalDevice"),
1113             Param("uint32_t", "queueFamilyIndex"),
1114             Param("xcb_connection_t*", "connection"),
1115             Param("xcb_visualid_t", "visual_id")]),
1116    ],
1117)
1118ext_khr_xlib_surface = Extension(
1119    name="VK_KHR_xlib_surface",
1120    headers=["vulkan/vulkan.h"],
1121    objects=[],
1122    protos=[
1123        Proto("VkResult", "CreateXlibSurfaceKHR",
1124            [Param("VkInstance", "instance"),
1125             Param("const VkXlibSurfaceCreateInfoKHR*", "pCreateInfo"),
1126             Param("const VkAllocationCallbacks*", "pAllocator"),
1127             Param("VkSurfaceKHR*", "pSurface")]),
1128
1129        Proto("VkBool32", "GetPhysicalDeviceXlibPresentationSupportKHR",
1130            [Param("VkPhysicalDevice", "physicalDevice"),
1131             Param("uint32_t", "queueFamilyIndex"),
1132             Param("Display*", "dpy"),
1133             Param("VisualID", "visualID")]),
1134    ],
1135)
1136ext_khr_wayland_surface = Extension(
1137    name="VK_KHR_wayland_surface",
1138    headers=["vulkan/vulkan.h"],
1139    objects=[],
1140    protos=[
1141        Proto("VkResult", "CreateWaylandSurfaceKHR",
1142            [Param("VkInstance", "instance"),
1143             Param("const VkWaylandSurfaceCreateInfoKHR*", "pCreateInfo"),
1144             Param("const VkAllocationCallbacks*", "pAllocator"),
1145             Param("VkSurfaceKHR*", "pSurface")]),
1146
1147        Proto("VkBool32", "GetPhysicalDeviceWaylandPresentationSupportKHR",
1148            [Param("VkPhysicalDevice", "physicalDevice"),
1149             Param("uint32_t", "queueFamilyIndex"),
1150             Param("struct wl_display*", "display")]),
1151    ],
1152)
1153ext_khr_mir_surface = Extension(
1154    name="VK_KHR_mir_surface",
1155    headers=["vulkan/vulkan.h"],
1156    objects=[],
1157    protos=[
1158        Proto("VkResult", "CreateMirSurfaceKHR",
1159            [Param("VkInstance", "instance"),
1160             Param("const VkMirSurfaceCreateInfoKHR*", "pCreateInfo"),
1161             Param("const VkAllocationCallbacks*", "pAllocator"),
1162             Param("VkSurfaceKHR*", "pSurface")]),
1163
1164        Proto("VkBool32", "GetPhysicalDeviceMirPresentationSupportKHR",
1165            [Param("VkPhysicalDevice", "physicalDevice"),
1166             Param("uint32_t", "queueFamilyIndex"),
1167             Param("MirConnection*", "connection")]),
1168    ],
1169)
1170ext_khr_android_surface = Extension(
1171    name="VK_KHR_android_surface",
1172    headers=["vulkan/vulkan.h"],
1173    objects=[],
1174    protos=[
1175        Proto("VkResult", "CreateAndroidSurfaceKHR",
1176            [Param("VkInstance", "instance"),
1177             Param("const VkAndroidSurfaceCreateInfoKHR*", "pCreateInfo"),
1178             Param("const VkAllocationCallbacks*", "pAllocator"),
1179             Param("VkSurfaceKHR*", "pSurface")]),
1180    ],
1181)
1182ext_khr_win32_surface = Extension(
1183    name="VK_KHR_win32_surface",
1184    headers=["vulkan/vulkan.h"],
1185    objects=[],
1186    protos=[
1187        Proto("VkResult", "CreateWin32SurfaceKHR",
1188            [Param("VkInstance", "instance"),
1189             Param("const VkWin32SurfaceCreateInfoKHR*", "pCreateInfo"),
1190             Param("const VkAllocationCallbacks*", "pAllocator"),
1191             Param("VkSurfaceKHR*", "pSurface")]),
1192
1193        Proto("VkBool32", "GetPhysicalDeviceWin32PresentationSupportKHR",
1194            [Param("VkPhysicalDevice", "physicalDevice"),
1195             Param("uint32_t", "queueFamilyIndex")]),
1196    ],
1197)
1198lunarg_debug_report = Extension(
1199    name="VK_EXT_debug_report",
1200    headers=["vulkan/vulkan.h"],
1201    objects=[
1202        "VkDebugReportCallbackEXT",
1203    ],
1204    protos=[
1205        Proto("VkResult", "CreateDebugReportCallbackEXT",
1206            [Param("VkInstance", "instance"),
1207             Param("const VkDebugReportCallbackCreateInfoEXT*", "pCreateInfo"),
1208             Param("const VkAllocationCallbacks*", "pAllocator"),
1209             Param("VkDebugReportCallbackEXT*", "pCallback")]),
1210
1211        Proto("void", "DestroyDebugReportCallbackEXT",
1212            [Param("VkInstance", "instance"),
1213             Param("VkDebugReportCallbackEXT", "callback"),
1214             Param("const VkAllocationCallbacks*", "pAllocator")]),
1215
1216        Proto("void", "DebugReportMessageEXT",
1217            [Param("VkInstance", "instance"),
1218             Param("VkDebugReportFlagsEXT", "flags"),
1219             Param("VkDebugReportObjectTypeEXT", "objType"),
1220             Param("uint64_t", "object"),
1221             Param("size_t", "location"),
1222             Param("int32_t", "msgCode"),
1223             Param("const char *", "pLayerPrefix"),
1224             Param("const char *", "pMsg")]),
1225    ],
1226)
1227
1228import sys
1229
1230if len(sys.argv) > 3:
1231# TODO : Need to clean this up to more seemlessly handle building different targets than the platform you're on
1232    if sys.platform.startswith('win32') and sys.argv[1] != 'Android':
1233        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_win32_surface]
1234        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_win32_surface, lunarg_debug_report]
1235    elif sys.platform.startswith('linux') and sys.argv[1] != 'Android':
1236        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_xcb_surface]
1237        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_xcb_surface, lunarg_debug_report]
1238    else: # android
1239        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_android_surface]
1240        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_android_surface, lunarg_debug_report]
1241else :
1242    if sys.argv[1] == 'Win32':
1243        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_win32_surface]
1244        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_win32_surface, lunarg_debug_report]
1245    elif sys.argv[1] == 'Android':
1246        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_android_surface]
1247        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_android_surface, lunarg_debug_report]
1248    elif sys.argv[1] == 'Xcb':
1249        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_xcb_surface]
1250        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_xcb_surface, lunarg_debug_report]
1251    elif sys.argv[1] == 'Xlib':
1252        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_xlib_surface]
1253        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_xlib_surface, lunarg_debug_report]
1254    elif sys.argv[1] == 'Wayland':
1255        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_wayland_surface]
1256        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_wayland_surface, lunarg_debug_report]
1257    elif sys.argv[1] == 'Mir':
1258        extensions = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_mir_surface]
1259        extensions_all = [core, ext_khr_surface, ext_khr_device_swapchain, ext_khr_mir_surface, lunarg_debug_report]
1260    else:
1261        print('Error: Undefined DisplayServer')
1262        extensions = []
1263        extensions_all = []
1264
1265object_dispatch_list = [
1266    "VkInstance",
1267    "VkPhysicalDevice",
1268    "VkDevice",
1269    "VkQueue",
1270    "VkCommandBuffer",
1271]
1272
1273object_non_dispatch_list = [
1274    "VkCommandPool",
1275    "VkFence",
1276    "VkDeviceMemory",
1277    "VkBuffer",
1278    "VkImage",
1279    "VkSemaphore",
1280    "VkEvent",
1281    "VkQueryPool",
1282    "VkBufferView",
1283    "VkImageView",
1284    "VkShaderModule",
1285    "VkPipelineCache",
1286    "VkPipelineLayout",
1287    "VkPipeline",
1288    "VkDescriptorSetLayout",
1289    "VkSampler",
1290    "VkDescriptorPool",
1291    "VkDescriptorSet",
1292    "VkRenderPass",
1293    "VkFramebuffer",
1294    "VkSwapchainKHR",
1295    "VkSurfaceKHR",
1296    "VkDebugReportCallbackEXT",
1297]
1298
1299object_type_list = object_dispatch_list + object_non_dispatch_list
1300
1301headers = []
1302objects = []
1303protos = []
1304for ext in extensions:
1305    headers.extend(ext.headers)
1306    objects.extend(ext.objects)
1307    protos.extend(ext.protos)
1308
1309proto_names = [proto.name for proto in protos]
1310
1311def parse_vk_h(filename):
1312    # read object and protoype typedefs
1313    object_lines = []
1314    proto_lines = []
1315    with open(filename, "r") as fp:
1316        for line in fp:
1317            line = line.strip()
1318            if line.startswith("VK_DEFINE"):
1319                begin = line.find("(") + 1
1320                end = line.find(",")
1321                # extract the object type
1322                object_lines.append(line[begin:end])
1323            if line.startswith("typedef") and line.endswith(");"):
1324                if "*PFN_vkVoidFunction" in line:
1325                    continue
1326
1327                # drop leading "typedef " and trailing ");"
1328                proto_lines.append(line[8:-2])
1329
1330    # parse proto_lines to protos
1331    protos = []
1332    for line in proto_lines:
1333        first, rest = line.split(" (VKAPI_PTR *PFN_vk")
1334        second, third = rest.split(")(")
1335
1336        # get the return type, no space before "*"
1337        proto_ret = "*".join([t.rstrip() for t in first.split("*")])
1338
1339        # get the name
1340        proto_name = second.strip()
1341
1342        # get the list of params
1343        param_strs = third.split(", ")
1344        params = []
1345        for s in param_strs:
1346            ty, name = s.rsplit(" ", 1)
1347
1348            # no space before "*"
1349            ty = "*".join([t.rstrip() for t in ty.split("*")])
1350            # attach [] to ty
1351            idx = name.rfind("[")
1352            if idx >= 0:
1353                ty += name[idx:]
1354                name = name[:idx]
1355
1356            params.append(Param(ty, name))
1357
1358        protos.append(Proto(proto_ret, proto_name, params))
1359
1360    # make them an extension and print
1361    ext = Extension("VK_CORE",
1362            headers=["vulkan/vulkan.h"],
1363            objects=object_lines,
1364            protos=protos)
1365    print("core =", str(ext))
1366
1367    print("")
1368    print("typedef struct VkLayerDispatchTable_")
1369    print("{")
1370    for proto in ext.protos:
1371        print("    PFN_vk%s %s;" % (proto.name, proto.name))
1372    print("} VkLayerDispatchTable;")
1373
1374if __name__ == "__main__":
1375    parse_vk_h("include/vulkan/vulkan.h")
1376