• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{{Include "vulkan_common.tmpl"}}
2{{Macro "DefineGlobals" $}}
3{{$ | Macro "vulkan.h" | Format (Global "clang-format") | Write "../include/vulkan.h"}}
4
5
6{{/*
7-------------------------------------------------------------------------------
8  Entry point
9-------------------------------------------------------------------------------
10*/}}
11{{define "vulkan.h"}}
12#ifndef __vulkan_h_
13#define __vulkan_h_ 1
1415#ifdef __cplusplus
16extern "C" {
17#endif
1819/*
20** Copyright (c) 2015-2016 The Khronos Group Inc.
21**
22** Permission is hereby granted, free of charge, to any person obtaining a
23** copy of this software and/or associated documentation files (the
24** "Materials"), to deal in the Materials without restriction, including
25** without limitation the rights to use, copy, modify, merge, publish,
26** distribute, sublicense, and/or sell copies of the Materials, and to
27** permit persons to whom the Materials are furnished to do so, subject to
28** the following conditions:
29**
30** The above copyright notice and this permission notice shall be included
31** in all copies or substantial portions of the Materials.
32**
33** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
36** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
37** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
38** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
40*/
4142/*
43** This header is generated from the Khronos Vulkan API Registry.
44**
45*/
4647#define VK_VERSION_1_0 1
48#include "vk_platform.h"
4950#define VK_MAKE_VERSION(major, minor, patch) (((major) << 22) | ((minor) << 12) | (patch))
5152// Vulkan API version supported by this file
53#define VK_API_VERSION \
54    VK_MAKE_VERSION({{Global "VERSION_MAJOR"}}, {{Global "VERSION_MINOR"}}, {{Global "VERSION_PATCH"}})
5556#define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22)
57#define VK_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff)
58#define VK_VERSION_PATCH(version) ((uint32_t)(version) & 0xfff)
5960#if defined(__cplusplus) && ((defined(_MSC_VER) && _MSC_VER >= 1800 || __cplusplus >= 201103L)
61    #define VK_NULL_HANDLE nullptr
62#else
63    #define VK_NULL_HANDLE 0
64#endif
6566#define VK_DEFINE_HANDLE(obj) typedef struct obj##_T* obj;
6768#if defined(__cplusplus)
69#if ((defined(_MSC_VER) && _MSC_VER >= 1800 || __cplusplus >= 201103L)
70// The bool operator only works if there are no implicit conversions from an obj to
71// a bool-compatible type, which can then be used to unintentionally violate type safety.
72// C++11 and above supports the "explicit" keyword on conversion operators to stop this
73// from happening. Otherwise users of C++ below C++11 won't get direct access to evaluating
74// the object handle as a bool in expressions like:
75//     if (obj) vkDestroy(obj);
76#define VK_NONDISP_HANDLE_OPERATOR_BOOL() \
77    explicit operator bool() const { return handle != 0; }
78#define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
79    explicit obj(uint64_t x) : handle(x) { } \
80    obj(decltype(nullptr)) : handle(0) { }
81#else
82#define VK_NONDISP_HANDLE_OPERATOR_BOOL()
83#define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
84    obj(uint64_t x) : handle(x) { }
85#endif
86#define VK_DEFINE_NONDISP_HANDLE(obj)                                              \
87    struct obj {                                                                   \
88        obj() : handle(0) { }                                                      \
89        VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj)                             \
90        obj& operator=(uint64_t x) {                                               \
91            handle = x;                                                            \
92            return *this;                                                          \
93        }                                                                          \
94        bool operator==(const obj& other) const { return handle == other.handle; } \
95        bool operator!=(const obj& other) const { return handle != other.handle; } \
96        bool operator!() const { return !handle; }                                 \
97        VK_NONDISP_HANDLE_OPERATOR_BOOL()                                          \
98        uint64_t handle;                                                           \
99    };
100#else
101#define VK_DEFINE_NONDISP_HANDLE(obj) \
102    typedef struct obj##_T { uint64_t handle; } obj;
103#endif
104105#define VK_LOD_CLAMP_NONE         1000.0f
106#define VK_REMAINING_MIP_LEVELS   (~0U)
107#define VK_REMAINING_ARRAY_LAYERS (~0U)
108#define VK_WHOLE_SIZE             (~0ULL)
109#define VK_ATTACHMENT_UNUSED      (~0U)
110define VK_QUEUE_FAMILY_IGNORED    (~0U)
111define VK_SUBPASS_EXTERNAL        (~0U)
112{{range $d := $.Definitions}}
113  {{if HasPrefix $d.Name "VK_"}}#define {{$d.Name}}  {{$d.Expression}}{{end}}
114{{end}}
115116{{range $i, $p := $.Pseudonyms}}
117  {{if GetAnnotation $p "dispatchHandle"}}VK_DEFINE_HANDLE({{$p.Name}})
118  {{else if GetAnnotation $p "nonDispatchHandle"}}VK_DEFINE_NONDISP_HANDLE({{$p.Name}})
119  {{end}}
120{{end}}
121122// ------------------------------------------------------------------------------------------------
123// Enumerations
124125  {{range $e := $.Enums}}
126    {{if not $e.IsBitfield}}
127      {{Macro "Enum" $e}}
128    {{end}}
129  {{end}}
130131// ------------------------------------------------------------------------------------------------
132// Flags
133134  {{range $e := $.Enums}}
135    {{if $e.IsBitfield}}
136      {{Macro "Bitfield" $e}}
137    {{end}}
138  {{end}}
139140// ------------------------------------------------------------------------------------------------
141// Vulkan structures
142143  {{/* Function pointers */}}
144  {{range $f := AllCommands $}}
145    {{if GetAnnotation $f "pfn"}}
146      {{Macro "FunctionTypedef" $f}}
147    {{end}}
148  {{end}}
149150  {{range $c := $.Classes}}
151    {{if not (GetAnnotation $c "internal")}}
152      {{Macro "Struct" $c}}
153    {{end}}
154  {{end}}
155156// ------------------------------------------------------------------------------------------------
157// API functions
158159  {{range $f := AllCommands $}}
160    {{if not (GetAnnotation $f "pfn")}}
161      {{Macro "FunctionTypedef" $f}}
162    {{end}}
163  {{end}}
164165#ifdef VK_NO_PROTOTYPES
166167  {{range $f := AllCommands $}}
168    {{if not (GetAnnotation $f "pfn")}}
169      {{Macro "FunctionDecl" $f}}
170    {{end}}
171  {{end}}
172173#endif
174175#ifdef __cplusplus
176}
177#endif
178179#endif
180{{end}}
181
182{{/*
183-------------------------------------------------------------------------------
184  Emits the C declaration for the specified bitfield.
185-------------------------------------------------------------------------------
186*/}}
187{{define "Bitfield"}}
188  {{AssertType $ "Enum"}}
189
190  {{Macro "Docs" $.Docs}}
191  typedef VkFlags {{Macro "EnumName" $}};
192  {{if $.Entries}}
193  typedef enum {
194  {{range $b := $.Entries}}
195    {{Macro "BitfieldEntryName" $b}} = {{printf "0x%.8X" $b.Value}}, {{Macro "Docs" $b.Docs}}
196  {{end}}
197  } {{Macro "EnumName" $ | TrimRight "s"}}Bits;
198  {{end}}
199200{{end}}
201
202
203{{/*
204-------------------------------------------------------------------------------
205  Emits the C declaration for the specified enum.
206-------------------------------------------------------------------------------
207*/}}
208{{define "Enum"}}
209  {{AssertType $ "Enum"}}
210
211  {{Macro "Docs" $.Docs}}
212  typedef enum {
213    {{range $i, $e := $.Entries}}
214      {{Macro "EnumEntry" $e}} = {{printf "0x%.8X" $e.Value}}, {{Macro "Docs" $e.Docs}}
215    {{end}}
216217    {{$name  := Macro "EnumName" $ | TrimRight "ABCDEFGHIJKLMNOQRSTUVWXYZ" | SplitPascalCase | Upper | JoinWith "_"}}
218    {{if GetAnnotation $ "enumMaxOnly"}}
219      VK_MAX_ENUM({{$name | SplitOn "VK_"}})
220    {{else}}
221      {{$first := Macro "EnumFirstEntry" $ | SplitOn $name | TrimLeft "_"}}
222      {{$last  := Macro "EnumLastEntry" $  | SplitOn $name | TrimLeft "_"}}
223      VK_ENUM_RANGE({{$name | SplitOn "VK_"}}, {{$first}}, {{$last}})
224    {{end}}
225  } {{Macro "EnumName" $}};
226227{{end}}
228
229
230{{/*
231-------------------------------------------------------------------------------
232  Emits the C declaration for the specified class.
233-------------------------------------------------------------------------------
234*/}}
235{{define "Struct"}}
236  {{AssertType $ "Class"}}
237
238  {{Macro "Docs" $.Docs}}
239  typedef {{Macro "StructType" $}} {
240    {{ForEach $.Fields "Field" | JoinWith "\n"}}
241  } {{Macro "StructName" $}};
242243{{end}}
244
245
246{{/*
247-------------------------------------------------------------------------------
248  Emits the C declaration for the specified class field.
249-------------------------------------------------------------------------------
250*/}}
251{{define "Field"}}
252  {{AssertType $ "Field"}}
253
254  {{Node "Type" $}} {{$.Name}}§
255  {{Macro "ArrayPostfix" (TypeOf $)}}; {{Macro "Docs" $.Docs}}
256{{end}}
257
258
259{{/*
260-------------------------------------------------------------------------------
261  Emits either 'struct' or 'union' for the specified class.
262-------------------------------------------------------------------------------
263*/}}
264{{define "StructType"}}
265  {{AssertType $ "Class"}}
266
267  {{if GetAnnotation $ "union"}}union{{else}}struct{{end}}
268{{end}}
269
270
271{{/*
272-------------------------------------------------------------------------------
273  Emits the C function pointer typedef declaration for the specified command.
274-------------------------------------------------------------------------------
275*/}}
276{{define "FunctionTypedef"}}
277  {{AssertType $ "Function"}}
278
279  typedef {{Node "Type" $.Return}} (VKAPI* {{Macro "FunctionPtrName" $}})({{Macro "Parameters" $}});
280{{end}}
281
282
283{{/*
284-------------------------------------------------------------------------------
285  Emits the C function declaration for the specified command.
286-------------------------------------------------------------------------------
287*/}}
288{{define "FunctionDecl"}}
289  {{AssertType $ "Function"}}
290
291  {{if not (GetAnnotation $ "fptr")}}
292    {{Macro "Docs" $.Docs}}
293    {{Node "Type" $.Return}} VKAPI {{Macro "FunctionName" $}}({{Macro "Parameters" $}});
294  {{end}}
295{{end}}
296