blob: c040938ae6b1d2a98b605e86d71d7df27e0cb048 [file] [log] [blame]
Jesse Halld27f6aa2015-08-15 17:58:48 -07001{{Include "vulkan_common.tmpl"}}
2{{Macro "DefineGlobals" $}}
3{{$ | Macro "vk.xml" | Reflow 4 | Write "vk.xml"}}
4
5
6{{/*
7-------------------------------------------------------------------------------
8 Entry point
9-------------------------------------------------------------------------------
10*/}}
11{{define "vk.xml"}}
12<?xml version="1.0" encoding="UTF-8"?>
13<registry>
14 »<comment
15Copyright (c) 2015 The Khronos Group Inc.
16
17Permission is hereby granted, free of charge, to any person obtaining a
18copy of this software and/or associated documentation files (the
19"Materials"), to deal in the Materials without restriction, including
20without limitation the rights to use, copy, modify, merge, publish,
21distribute, sublicense, and/or sell copies of the Materials, and to
22permit persons to whom the Materials are furnished to do so, subject to
23the following conditions:
24
25The above copyright notice and this permission notice shall be included
26in all copies or substantial portions of the Materials.
27
28THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
32CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
35
36------------------------------------------------------------------------
37
38This file, vk.xml, is the Vulkan API Registry
39 </comment>
40
41 <!-- SECTION: Vulkan type definitions -->
42 <types>»
43 <type name="vk_platform" category="include">#include "vk_platform.h"</type>
44
45 <type category="define">#define <name>VK_MAKE_VERSION</name>(major, minor, patch) \
46 «((major &lt;&lt; 22) | (minor &lt;&lt; 12) | patch)</type
47
48 <type category="define">// Vulkan API version supported by this file««
49#define <name>VK_API_VERSION</name> <type>VK_MAKE_VERSION</type>({{Global "VERSION_MAJOR"}}, {{Global "VERSION_MINOR"}}, {{Global "VERSION_PATCH"}})</type>
50
51 »»<type category="define">««
52#if (_MSC_VER &gt;= 1800 || __cplusplus &gt;= 201103L)
53#define <name>VK_NONDISP_HANDLE_OPERATOR_BOOL</name>() explicit operator bool() const { return handle != 0; }
54#else
55#define VK_NONDISP_HANDLE_OPERATOR_BOOL()
56«#endif
57 »»»</type>
58
59 <type category="define">«««
60#define <name>VK_DEFINE_HANDLE</name>(obj) typedef struct obj##_T* obj;</type>
61 »»»<type category="define">«««
62#if defined(__cplusplus)
63 »»#if (_MSC_VER &gt;= 1800 || __cplusplus &gt;= 201103L)
64 »// The bool operator only works if there are no implicit conversions from an obj to
65 // a bool-compatible type, which can then be used to unintentionally violate type safety.
66 // C++11 and above supports the "explicit" keyword on conversion operators to stop this
67 // from happening. Otherwise users of C++ below C++11 won't get direct access to evaluating
68 // the object handle as a bool in expressions like:
69 // if (obj) vkDestroy(obj);
70 #define VK_NONDISP_HANDLE_OPERATOR_BOOL() explicit operator bool() const { return handle != 0; }
71 «#else»
72 #define VK_NONDISP_HANDLE_OPERATOR_BOOL()
73 «#endif
74 #define <name>VK_DEFINE_NONDISP_HANDLE</name>(obj)
75 struct obj { \
76 obj() { } \
77 obj(uint64_t x) { handle = x; } \
78 obj&amp; operator =(uint64_t x) { handle = x; return *this; } \
79 bool operator==(const obj&amp; other) const { return handle == other.handle; } \
80 bool operator!=(const obj&amp; other) const { return handle != other.handle; } \
81 bool operator!() const { return !handle; } \
82 VK_NONDISP_HANDLE_OPERATOR_BOOL() \
83 uint64_t handle; \
84 };
85««#else
86 »#define VK_DEFINE_NONDISP_HANDLE(obj) typedef struct obj##_T { uint64_t handle; } obj;«
87#endif
88 »»</type>
89
90 <type requires="vk_platform" name="VkDeviceSize"/>
91 <type requires="vk_platform" name="VkSampleMask"/>
92 <type requires="vk_platform" name="VkFlags"/>
93 <!-- Basic C types, pulled in via vk_platform.h -->
94 <type requires="vk_platform" name="char"/>
95 <type requires="vk_platform" name="float"/>
96 <type requires="vk_platform" name="VkBool32"/>
97 <type requires="vk_platform" name="uint8_t"/>
98 <type requires="vk_platform" name="uint32_t"/>
99 <type requires="vk_platform" name="uint64_t"/>
100 <type requires="vk_platform" name="int32_t"/>
101 <type requires="vk_platform" name="size_t"/>
102 <!-- Bitfield types -->
103 {{range $e := $.Enums}}
104 {{if $e.IsBitfield}}
105 {{$bits := print (Macro "EnumName" $e | TrimRight "s") "Bits"}}
106 <type{{if $e.Entries}} requires="{{$bits}}"{{end}} category="bitmask">typedef <type>VkFlags</type> <name>{{$e.Name}}</name>;</type
107 {{if $e.Entries}}{{Macro "XML.Docs" $e.Docs}}
108 {{else}}{{Macro "XML.Docs" (Strings $e.Docs "(no bits yet)")}}
109 {{end}}
110 {{end}}
111 {{end}}
112
113 <!-- Types which can be void pointers or class pointers, selected at compile time -->
114 {{range $i, $p := $.Pseudonyms}}
115 {{ if (GetAnnotation $p "dispatchHandle")}}
116 {{if Global "VK_DEFINE_HANDLE_TYPE_DEFINED"}}
117 <type category="handle">VK_DEFINE_HANDLE(<name>{{$p.Name}}</name>)</type>
118 {{else}}
119 {{Global "VK_DEFINE_HANDLE_TYPE_DEFINED" "YES"}}
120 <type category="handle"><type>VK_DEFINE_HANDLE</type>(<name>{{$p.Name}}</name>)</type>
121 {{end}}
122 {{else if (GetAnnotation $p "nonDispatchHandle")}}
123 {{if Global "VK_DEFINE_NONDISP_HANDLE_TYPE_DEFINED"}}
124 <type category="handle">VK_DEFINE_NONDISP_HANDLE(<name>{{$p.Name}}</name>)</type>
125 {{else}}
126 {{Global "VK_DEFINE_NONDISP_HANDLE_TYPE_DEFINED" "YES"}}
127 <type category="handle"><type>VK_DEFINE_NONDISP_HANDLE</type>(<name>{{$p.Name}}</name>)</type>
128 {{end}}
129 {{end}}
130 {{end}}
131
132 <!-- Types generated from corresponding <enums> tags below -->
133 {{range $e := SortBy $.Enums "EnumName"}}
134 {{if and $e.Entries (not (GetAnnotation $e "internal"))}}
135 {{if $e.IsBitfield}}
136 <type name="{{Macro "EnumName" $e | TrimRight "s"}}Bits" category="enum"/>
137 {{else}}
138 <type name="{{$e.Name}}" category="enum"/>
139 {{end}}
140 {{end}}
141 {{end}}
142
143 <!-- The PFN_vk*Function types are used by VkAllocCallbacks below -->
144 <type>typedef void* (VKAPI *<name>PFN_vkAllocFunction</name>)(«
145 void* pUserData,
146 size_t size,
147 size_t alignment,
148 <type>VkSystemAllocType</type> allocType);</type
149 <type>typedef void (VKAPI *<name>PFN_vkFreeFunction</name>)(«
150 void* pUserData,
151 void* pMem);</type
152
153 <!-- The PFN_vkVoidFunction type are used by VkGet*ProcAddr below -->
154 <type>typedef void (VKAPI *<name>PFN_vkVoidFunction</name>)(void);</type>
155
156 <!-- Struct types -->
157 {{range $c := $.Classes}}
158 {{if not (GetAnnotation $c "internal")}}
159 {{Macro "Struct" $c}}
160 {{end}}
161 {{end}}
162 «</types>
163
164 <!-- SECTION: Vulkan enumerant (token) definitions. -->
165
166 <enums namespace="VK" comment="Misc. hardcoded constants - not an enumerated type"
167 <!-- This is part of the header boilerplate -->
168 {{range $d := $.Definitions}}
169 {{if HasPrefix $d.Name "VK_"}}
170 <enum value="{{$d.Expression}}" name="{{$d.Name}}"/>{{Macro "XML.Docs" $d.Docs}}
171 {{end}}
172 {{end}}
173 <enum value="MAX_FLOAT" name="VK_LOD_CLAMP_NONE"/>
174 <enum value="UINT32_MAX" name="VK_LAST_MIP_LEVEL"/>
175 <enum value="UINT32_MAX" name="VK_LAST_ARRAY_SLICE"/>
176 <enum value="UINT64_MAX" name="VK_WHOLE_SIZE"/>
177 <enum value="UINT32_MAX" name="VK_ATTACHMENT_UNUSED"/>
178 <enum value="UINT32_MAX" name="VK_QUEUE_FAMILY_IGNORED"/>
179 «</enums>
180
181 <!-- Unlike OpenGL, most tokens in Vulkan are actual typed enumerants in»
182 their own numeric namespaces. The "name" attribute is the C enum
183 type name, and is pulled in from a <type> definition above
184 (slightly clunky, but retains the type / enum distinction). "type"
185 attributes of "enum" or "bitmask" indicate that these values should
186 be generated inside an appropriate definition. -->«
187
188 {{range $e := $.Enums}}
189 {{if not (or $e.IsBitfield (GetAnnotation $e "internal"))}}
190 {{Macro "XML.Enum" $e}}
191 {{end}}
192 {{end}}
193
194 <!-- Flags -->
195 {{range $e := $.Enums}}
196 {{if $e.IsBitfield}}
197 {{Macro "XML.Bitfield" $e}}
198 {{end}}
199 {{end}}
200
201 <!-- SECTION: Vulkan command definitions -->
202 <commands namespace="vk"
203 {{range $f := AllCommands $}}
204 {{if not (GetAnnotation $f "pfn")}}
205 {{Macro "XML.Function" $f}}
206 {{end}}
207 {{end}}
208 «</commands>
209
210 <!-- SECTION: Vulkan API interface definitions -->
211 <feature api="vulkan" name="VK_VERSION_1_0" number="1.0"
212 <require comment="Header boilerplate"
213 <type name="vk_platform"/>
214 «</require>
215 <require comment="API version"
216 <type name="VK_API_VERSION"/>
217 «</require>
218 <require comment="API constants"
219 <enum name="VK_LOD_CLAMP_NONE"/>
220 <enum name="VK_LAST_MIP_LEVEL"/>
221 <enum name="VK_LAST_ARRAY_SLICE"/>
222 <enum name="VK_WHOLE_SIZE"/>
223 <enum name="VK_ATTACHMENT_UNUSED"/>
224 <enum name="VK_TRUE"/>
225 <enum name="VK_FALSE"/>
226 <enum name="VK_NULL_HANDLE"/>
227 «</require>
228 <require comment="All functions (TODO: split by type)"
229 {{range $f := AllCommands $}}
230 {{if not (GetAnnotation $f "pfn")}}
231 <command name="{{$f.Name}}"/>
232 {{end}}
233 {{end}}
234 </require>
235 «<require comment="Types not directly used by the API"
236 <!-- Include <type name="typename"/> here for e.g. structs that»
237 are not parameter types of commands, but still need to be
238 defined in the API.
239 «-->
240 <type name="VkBufferMemoryBarrier"/>
241 <type name="VkDispatchIndirectCmd"/>
242 <type name="VkDrawIndexedIndirectCmd"/>
243 <type name="VkDrawIndirectCmd"/>
244 <type name="VkImageMemoryBarrier"/>
245 <type name="VkMemoryBarrier"/>
246 «</require>
247 «</feature>
248
249 <!-- SECTION: Vulkan extension interface definitions (none yet) -->
250«</registry>
251{{end}}
252
253{{/*
254-------------------------------------------------------------------------------
255 Emits the C declaration for the specified bitfield.
256-------------------------------------------------------------------------------
257*/}}
258{{define "XML.Bitfield"}}
259 {{AssertType $ "Enum"}}
260
261 {{if $.Entries}}
262 <enums namespace="VK" name="{{Macro "EnumName" $ | TrimRight "s"}}Bits" type="bitmask"
263 {{range $e := $.Entries}}
264 {{$pos := Bitpos $e.Value}}
265 <enum §
266 {{if gt $pos -1}} bitpos="{{$pos}}" §
267 {{else}}value="{{if $e.Value}}{{printf "0x%.8X" $e.Value}}{{else}}0{{end}}" §
268 {{end}}name="{{Macro "BitfieldEntryName" $e}}" §
269 {{if $d := $e.Docs}} comment="{{$d | JoinWith " "}}"{{end}}/>
270 {{end}}
271 «</enums>
272 {{end}}
273
274{{end}}
275
276
277{{/*
278-------------------------------------------------------------------------------
279 Emits the C declaration for the specified enum.
280-------------------------------------------------------------------------------
281*/}}
282{{define "XML.Enum"}}
283 {{AssertType $ "Enum"}}
284
285 <enums namespace="VK" name="{{Macro "EnumName" $}}" type="enum" §
286 expand="{{Macro "EnumName" $ | SplitPascalCase | Upper | JoinWith "_"}}"{{if $.Docs}} comment="{{$.Docs | JoinWith " "}}"{{end}}>»
287 {{range $i, $e := $.Entries}}
288 <enum value="{{AsSigned $e.Value}}" name="{{Macro "BitfieldEntryName" $e}}"{{if $e.Docs}} comment="{{$e.Docs | JoinWith " "}}"{{end}}/>
289 {{end}}
290 {{if $lu := GetAnnotation $ "lastUnused"}}
291 <unused start="{{index $lu.Arguments 0}}"/>
292 {{end}}
293 «</enums>
294{{end}}
295
296
297{{/*
298-------------------------------------------------------------------------------
299 Emits the C declaration for the specified class.
300-------------------------------------------------------------------------------
301*/}}
302{{define "Struct"}}
303 {{AssertType $ "Class"}}
304
305 <type category="{{Macro "StructType" $}}" name="{{Macro "StructName" $}}"{{if $.Docs}} comment="{{$.Docs | JoinWith " "}}"{{end}}>»
306 {{range $f := $.Fields}}
307 <member>{{Node "XML.Type" $f}} <name>{{$f.Name}}</name>{{Macro "XML.ArrayPostfix" $f}}</member>{{Macro "XML.Docs" $f.Docs}}
308 {{end}}
309 «</type>
310{{end}}
311
312
313{{/*
314-------------------------------------------------------------------------------
315 Emits either 'struct' or 'union' for the specified class.
316-------------------------------------------------------------------------------
317*/}}
318{{define "StructType"}}
319 {{AssertType $ "Class"}}
320
321 {{if GetAnnotation $ "union"}}union{{else}}struct{{end}}
322{{end}}
323
324
325{{/*
326-------------------------------------------------------------------------------
327 Emits the C function pointer typedef declaration for the specified command.
328-------------------------------------------------------------------------------
329*/}}
330{{define "XML.Function"}}
331 {{AssertType $ "Function"}}
332
333 {{$ts := GetAnnotation $ "threadSafety"}}
334 <command{{if $ts}} threadsafe="{{index $ts.Arguments 0}}"{{end}}>»
335 <proto>{{Node "XML.Type" $.Return}} <name>{{$.Name}}</name></proto>
336 {{range $p := $.CallParameters}}
337 <param>{{Node "XML.Type" $p}} <name>{{$p.Name}}{{Macro "ArrayPostfix" $p}}</name></param>
338 {{end}}
339 «</command>
340{{end}}
341
342
343{{/*
344-------------------------------------------------------------------------------
345 Emits the XML translation for the specified documentation block (string array).
346-------------------------------------------------------------------------------
347*/}}
348{{define "XML.Docs"}}
349 {{if $}} <!-- {{JoinWith " " $ | Replace "<" "" | Replace ">" ""}} -->{{end}}
350{{end}}
351
352{{/*
353-------------------------------------------------------------------------------
354 Emits the C translation for the specified type.
355-------------------------------------------------------------------------------
356*/}}
357{{define "XML.Type.Class" }}<type>{{Macro "StructName" $.Type}}</type>{{end}}
358{{define "XML.Type.Pseudonym" }}<type>{{$.Type.Name}}</type>{{end}}
359{{define "XML.Type.Enum" }}<type>{{$.Type.Name}}</type>{{end}}
360{{define "XML.Type.StaticArray"}}{{Node "XML.Type" $.Type.ValueType}}{{end}}
361{{define "XML.Type.Pointer" }}{{if $.Type.Const}}{{Node "XML.ConstType" $.Type.To}}{{else}}{{Node "XML.Type" $.Type.To}}{{end}}*{{end}}
362{{define "XML.Type.Slice" }}<type>{{Node "XML.Type" $.Type.To}}</type>*{{end}}
363{{define "XML.Type#s8" }}<type>int8_t</type>{{end}}
364{{define "XML.Type#u8" }}<type>uint8_t</type>{{end}}
365{{define "XML.Type#s16" }}<type>int16_t</type>{{end}}
366{{define "XML.Type#u16" }}<type>uint16_t</type>{{end}}
367{{define "XML.Type#s32" }}<type>int32_t</type>{{end}}
368{{define "XML.Type#u32" }}<type>uint32_t</type>{{end}}
369{{define "XML.Type#f32" }}<type>float</type>{{end}}
370{{define "XML.Type#s64" }}<type>int64_t</type>{{end}}
371{{define "XML.Type#u64" }}<type>uint64_t</type>{{end}}
372{{define "XML.Type#f64" }}<type>double</type>{{end}}
373{{define "XML.Type#char" }}<type>char</type>{{end}}
374{{define "XML.Type#void" }}void{{end}}
375
376{{define "XML.ConstType_Default"}}const {{Node "XML.Type" $.Type}}{{end}}
377{{define "XML.ConstType.Pointer"}}{{Node "XML.Type" $.Type}} const{{end}}
378
379
380{{/*
381-------------------------------------------------------------------------------
382 Emits a C type and name for the given parameter
383-------------------------------------------------------------------------------
384*/}}
385{{define "XML.Parameter"}}
386 {{AssertType $ "Parameter"}}
387
388 <type>{{Macro "ParameterType" $}}</type> <name>{{$.Name}}{{Macro "ArrayPostfix" $}}</name>
389{{end}}
390
391{{/*
392-------------------------------------------------------------------------------
393 Emits a comma-separated list of C type-name paired parameters for the given
394 command.
395-------------------------------------------------------------------------------
396*/}}
397{{define "XML.Parameters"}}
398 {{AssertType $ "Function"}}
399
400 {{ForEach $.CallParameters "XML.Parameter" | JoinWith ", "}}
401 {{if not $.CallParameters}}<type>void</type>{{end}}
402{{end}}
403
404
405{{/*
406-------------------------------------------------------------------------------
407 Emits the fixed-size-array postfix for pseudonym types annotated with @array
408-------------------------------------------------------------------------------
409*/}}
410{{define "XML.ArrayPostfix"}}{{Node "XML.ArrayPostfix" $}}{{end}}
411{{define "XML.ArrayPostfix.StaticArray"}}[{{Node "XML.NamedValue" $.Type.SizeExpr}}]{{end}}
412{{define "XML.ArrayPostfix_Default"}}{{end}}
413
414
415{{/*
416-------------------------------------------------------------------------------
417 Emits the value of the given constant, or the <enum> tagged name if existant.
418-------------------------------------------------------------------------------
419*/}}
420{{define "XML.NamedValue.Definition"}}<enum>{{$.Node.Name}}</enum>{{end}}
421{{define "XML.NamedValue.EnumEntry"}}<enum>{{$.Node.Name}}</enum>{{end}}
422{{define "XML.NamedValue_Default"}}{{$.Node}}{{end}}