blob: b2a77ec4a71b0cac748bdb09af6ac9f02774c310 [file] [log] [blame]
Jesse Halld27f6aa2015-08-15 17:58:48 -07001{{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
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/*
20** Copyright (c) 2015 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*/
41
42/*
43** This header is generated from the Khronos Vulkan API Registry.
44**
45*/
46
47#define VK_VERSION_1_0 1
48#include "vk_platform.h"
49
50#define VK_MAKE_VERSION(major, minor, patch) ((major << 22) | (minor << 12) | patch)
51
52// 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"}})
55
Jesse Hallacfa5342015-11-19 21:51:33 -080056#if defined(__cplusplus) && ((defined(_MSC_VER) && _MSC_VER >= 1800 || __cplusplus >= 201103L)
Jesse Hall5ae3abb2015-10-08 14:00:22 -070057 #define VK_NULL_HANDLE nullptr
58#else
59 #define VK_NULL_HANDLE 0
60#endif
61
Jesse Halld27f6aa2015-08-15 17:58:48 -070062#define VK_DEFINE_HANDLE(obj) typedef struct obj##_T* obj;
63
64#if defined(__cplusplus)
Jesse Hall5ae3abb2015-10-08 14:00:22 -070065#if ((defined(_MSC_VER) && _MSC_VER >= 1800 || __cplusplus >= 201103L)
Jesse Halld27f6aa2015-08-15 17:58:48 -070066// The bool operator only works if there are no implicit conversions from an obj to
67// a bool-compatible type, which can then be used to unintentionally violate type safety.
68// C++11 and above supports the "explicit" keyword on conversion operators to stop this
69// from happening. Otherwise users of C++ below C++11 won't get direct access to evaluating
70// the object handle as a bool in expressions like:
71// if (obj) vkDestroy(obj);
72#define VK_NONDISP_HANDLE_OPERATOR_BOOL() \
73 explicit operator bool() const { return handle != 0; }
Jesse Hall5ae3abb2015-10-08 14:00:22 -070074#define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
75 explicit obj(uint64_t x) : handle(x) { } \
76 obj(decltype(nullptr)) : handle(0) { }
Jesse Halld27f6aa2015-08-15 17:58:48 -070077#else
78#define VK_NONDISP_HANDLE_OPERATOR_BOOL()
Jesse Hall5ae3abb2015-10-08 14:00:22 -070079#define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
80 obj(uint64_t x) : handle(x) { }
Jesse Halld27f6aa2015-08-15 17:58:48 -070081#endif
82#define VK_DEFINE_NONDISP_HANDLE(obj) \
83 struct obj { \
Jesse Hallf09c6b12015-08-15 19:54:28 -070084 obj() : handle(0) { } \
Jesse Hall5ae3abb2015-10-08 14:00:22 -070085 VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
Jesse Halld27f6aa2015-08-15 17:58:48 -070086 obj& operator=(uint64_t x) { \
87 handle = x; \
88 return *this; \
89 } \
90 bool operator==(const obj& other) const { return handle == other.handle; } \
91 bool operator!=(const obj& other) const { return handle != other.handle; } \
92 bool operator!() const { return !handle; } \
93 VK_NONDISP_HANDLE_OPERATOR_BOOL() \
94 uint64_t handle; \
95 };
96#else
97#define VK_DEFINE_NONDISP_HANDLE(obj) \
98 typedef struct obj##_T { uint64_t handle; } obj;
99#endif
100
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700101#define VK_LOD_CLAMP_NONE 1000.0f
102#define VK_REMAINING_MIP_LEVELS (~0U)
103#define VK_REMAINING_ARRAY_LAYERS (~0U)
104#define VK_WHOLE_SIZE (~0ULL)
105#define VK_ATTACHMENT_UNUSED (~0U)
106define VK_QUEUE_FAMILY_IGNORED (~0U)
107define VK_SUBPASS_EXTERNAL (~0U)
Jesse Halld27f6aa2015-08-15 17:58:48 -0700108{{range $d := $.Definitions}}
109 {{if HasPrefix $d.Name "VK_"}}#define {{$d.Name}} {{$d.Expression}}{{end}}
110{{end}}
111
112{{range $i, $p := $.Pseudonyms}}
113 {{if GetAnnotation $p "dispatchHandle"}}VK_DEFINE_HANDLE({{$p.Name}})
114 {{else if GetAnnotation $p "nonDispatchHandle"}}VK_DEFINE_NONDISP_HANDLE({{$p.Name}})
115 {{end}}
116{{end}}
117
118// ------------------------------------------------------------------------------------------------
119// Enumerations
120
121 {{range $e := $.Enums}}
122 {{if not $e.IsBitfield}}
123 {{Macro "Enum" $e}}
124 {{end}}
125 {{end}}
126
127// ------------------------------------------------------------------------------------------------
128// Flags
129
130 {{range $e := $.Enums}}
131 {{if $e.IsBitfield}}
132 {{Macro "Bitfield" $e}}
133 {{end}}
134 {{end}}
135
136// ------------------------------------------------------------------------------------------------
137// Vulkan structures
138
139 {{/* Function pointers */}}
140 {{range $f := AllCommands $}}
141 {{if GetAnnotation $f "pfn"}}
142 {{Macro "FunctionTypedef" $f}}
143 {{end}}
144 {{end}}
145
146 {{range $c := $.Classes}}
147 {{if not (GetAnnotation $c "internal")}}
148 {{Macro "Struct" $c}}
149 {{end}}
150 {{end}}
151
152// ------------------------------------------------------------------------------------------------
153// API functions
154
155 {{range $f := AllCommands $}}
156 {{if not (GetAnnotation $f "pfn")}}
157 {{Macro "FunctionTypedef" $f}}
158 {{end}}
159 {{end}}
160
Jesse Hall563380d2016-01-15 23:14:05 -0800161#ifdef VK_NO_PROTOTYPES
Jesse Halld27f6aa2015-08-15 17:58:48 -0700162
163 {{range $f := AllCommands $}}
164 {{if not (GetAnnotation $f "pfn")}}
165 {{Macro "FunctionDecl" $f}}
166 {{end}}
167 {{end}}
168
169#endif
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif
176{{end}}
177
178{{/*
179-------------------------------------------------------------------------------
180 Emits the C declaration for the specified bitfield.
181-------------------------------------------------------------------------------
182*/}}
183{{define "Bitfield"}}
184 {{AssertType $ "Enum"}}
185
186 {{Macro "Docs" $.Docs}}
187 typedef VkFlags {{Macro "EnumName" $}};
188 {{if $.Entries}}
189 typedef enum {
190 {{range $b := $.Entries}}
191 {{Macro "BitfieldEntryName" $b}} = {{printf "0x%.8X" $b.Value}}, {{Macro "Docs" $b.Docs}}
192 {{end}}
193 } {{Macro "EnumName" $ | TrimRight "s"}}Bits;
194 {{end}}
195
196{{end}}
197
198
199{{/*
200-------------------------------------------------------------------------------
201 Emits the C declaration for the specified enum.
202-------------------------------------------------------------------------------
203*/}}
204{{define "Enum"}}
205 {{AssertType $ "Enum"}}
206
207 {{Macro "Docs" $.Docs}}
208 typedef enum {
209 {{range $i, $e := $.Entries}}
210 {{Macro "EnumEntry" $e}} = {{printf "0x%.8X" $e.Value}}, {{Macro "Docs" $e.Docs}}
211 {{end}}
212
213 {{$name := Macro "EnumName" $ | TrimRight "ABCDEFGHIJKLMNOQRSTUVWXYZ" | SplitPascalCase | Upper | JoinWith "_"}}
214 {{if GetAnnotation $ "enumMaxOnly"}}
215 VK_MAX_ENUM({{$name | SplitOn "VK_"}})
216 {{else}}
217 {{$first := Macro "EnumFirstEntry" $ | SplitOn $name | TrimLeft "_"}}
218 {{$last := Macro "EnumLastEntry" $ | SplitOn $name | TrimLeft "_"}}
219 VK_ENUM_RANGE({{$name | SplitOn "VK_"}}, {{$first}}, {{$last}})
220 {{end}}
221 } {{Macro "EnumName" $}};
222
223{{end}}
224
225
226{{/*
227-------------------------------------------------------------------------------
228 Emits the C declaration for the specified class.
229-------------------------------------------------------------------------------
230*/}}
231{{define "Struct"}}
232 {{AssertType $ "Class"}}
233
234 {{Macro "Docs" $.Docs}}
235 typedef {{Macro "StructType" $}} {
236 {{ForEach $.Fields "Field" | JoinWith "\n"}}
237 } {{Macro "StructName" $}};
238
239{{end}}
240
241
242{{/*
243-------------------------------------------------------------------------------
244 Emits the C declaration for the specified class field.
245-------------------------------------------------------------------------------
246*/}}
247{{define "Field"}}
248 {{AssertType $ "Field"}}
249
250 {{Node "Type" $}} {{$.Name}}§
251 {{Macro "ArrayPostfix" (TypeOf $)}}; {{Macro "Docs" $.Docs}}
252{{end}}
253
254
255{{/*
256-------------------------------------------------------------------------------
257 Emits either 'struct' or 'union' for the specified class.
258-------------------------------------------------------------------------------
259*/}}
260{{define "StructType"}}
261 {{AssertType $ "Class"}}
262
263 {{if GetAnnotation $ "union"}}union{{else}}struct{{end}}
264{{end}}
265
266
267{{/*
268-------------------------------------------------------------------------------
269 Emits the C function pointer typedef declaration for the specified command.
270-------------------------------------------------------------------------------
271*/}}
272{{define "FunctionTypedef"}}
273 {{AssertType $ "Function"}}
274
275 typedef {{Node "Type" $.Return}} (VKAPI* {{Macro "FunctionPtrName" $}})({{Macro "Parameters" $}});
276{{end}}
277
278
279{{/*
280-------------------------------------------------------------------------------
281 Emits the C function declaration for the specified command.
282-------------------------------------------------------------------------------
283*/}}
284{{define "FunctionDecl"}}
285 {{AssertType $ "Function"}}
286
287 {{if not (GetAnnotation $ "fptr")}}
288 {{Macro "Docs" $.Docs}}
289 {{Node "Type" $.Return}} VKAPI {{Macro "FunctionName" $}}({{Macro "Parameters" $}});
290 {{end}}
291{{end}}