vulkan_h.tmpl revision f09c6b1fe893f0d378cfd3228b10df6a448e3a1c
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 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¶ 56#define VK_DEFINE_HANDLE(obj) typedef struct obj##_T* obj; 57¶ 58#if defined(__cplusplus) 59#if (_MSC_VER >= 1800 || __cplusplus >= 201103L) 60// The bool operator only works if there are no implicit conversions from an obj to 61// a bool-compatible type, which can then be used to unintentionally violate type safety. 62// C++11 and above supports the "explicit" keyword on conversion operators to stop this 63// from happening. Otherwise users of C++ below C++11 won't get direct access to evaluating 64// the object handle as a bool in expressions like: 65// if (obj) vkDestroy(obj); 66#define VK_NONDISP_HANDLE_OPERATOR_BOOL() \ 67 explicit operator bool() const { return handle != 0; } 68#else 69#define VK_NONDISP_HANDLE_OPERATOR_BOOL() 70#endif 71#define VK_DEFINE_NONDISP_HANDLE(obj) \ 72 struct obj { \ 73 obj() : handle(0) { } \ 74 obj(uint64_t x) : handle(x) { } \ 75 obj& operator=(uint64_t x) { \ 76 handle = x; \ 77 return *this; \ 78 } \ 79 bool operator==(const obj& other) const { return handle == other.handle; } \ 80 bool operator!=(const obj& 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) \ 87 typedef struct obj##_T { uint64_t handle; } obj; 88#endif 89¶ 90#define VK_LOD_CLAMP_NONE MAX_FLOAT 91#define VK_LAST_MIP_LEVEL UINT32_MAX 92#define VK_LAST_ARRAY_SLICE UINT32_MAX 93#define VK_WHOLE_SIZE UINT64_MAX 94#define VK_ATTACHMENT_UNUSED UINT32_MAX 95{{range $d := $.Definitions}} 96 {{if HasPrefix $d.Name "VK_"}}#define {{$d.Name}} {{$d.Expression}}{{end}} 97{{end}} 98¶ 99{{range $i, $p := $.Pseudonyms}} 100 {{if GetAnnotation $p "dispatchHandle"}}VK_DEFINE_HANDLE({{$p.Name}}) 101 {{else if GetAnnotation $p "nonDispatchHandle"}}VK_DEFINE_NONDISP_HANDLE({{$p.Name}}) 102 {{end}} 103{{end}} 104¶ 105// ------------------------------------------------------------------------------------------------ 106// Enumerations 107¶ 108 {{range $e := $.Enums}} 109 {{if not $e.IsBitfield}} 110 {{Macro "Enum" $e}} 111 {{end}} 112 {{end}} 113¶ 114// ------------------------------------------------------------------------------------------------ 115// Flags 116¶ 117 {{range $e := $.Enums}} 118 {{if $e.IsBitfield}} 119 {{Macro "Bitfield" $e}} 120 {{end}} 121 {{end}} 122¶ 123// ------------------------------------------------------------------------------------------------ 124// Vulkan structures 125¶ 126 {{/* Function pointers */}} 127 {{range $f := AllCommands $}} 128 {{if GetAnnotation $f "pfn"}} 129 {{Macro "FunctionTypedef" $f}} 130 {{end}} 131 {{end}} 132¶ 133 {{range $c := $.Classes}} 134 {{if not (GetAnnotation $c "internal")}} 135 {{Macro "Struct" $c}} 136 {{end}} 137 {{end}} 138¶ 139// ------------------------------------------------------------------------------------------------ 140// API functions 141¶ 142 {{range $f := AllCommands $}} 143 {{if not (GetAnnotation $f "pfn")}} 144 {{Macro "FunctionTypedef" $f}} 145 {{end}} 146 {{end}} 147¶ 148#ifdef VK_PROTOTYPES 149¶ 150 {{range $f := AllCommands $}} 151 {{if not (GetAnnotation $f "pfn")}} 152 {{Macro "FunctionDecl" $f}} 153 {{end}} 154 {{end}} 155¶ 156#endif 157¶ 158#ifdef __cplusplus 159} 160#endif 161¶ 162#endif 163{{end}} 164 165{{/* 166------------------------------------------------------------------------------- 167 Emits the C declaration for the specified bitfield. 168------------------------------------------------------------------------------- 169*/}} 170{{define "Bitfield"}} 171 {{AssertType $ "Enum"}} 172 173 {{Macro "Docs" $.Docs}} 174 typedef VkFlags {{Macro "EnumName" $}}; 175 {{if $.Entries}} 176 typedef enum { 177 {{range $b := $.Entries}} 178 {{Macro "BitfieldEntryName" $b}} = {{printf "0x%.8X" $b.Value}}, {{Macro "Docs" $b.Docs}} 179 {{end}} 180 } {{Macro "EnumName" $ | TrimRight "s"}}Bits; 181 {{end}} 182 ¶ 183{{end}} 184 185 186{{/* 187------------------------------------------------------------------------------- 188 Emits the C declaration for the specified enum. 189------------------------------------------------------------------------------- 190*/}} 191{{define "Enum"}} 192 {{AssertType $ "Enum"}} 193 194 {{Macro "Docs" $.Docs}} 195 typedef enum { 196 {{range $i, $e := $.Entries}} 197 {{Macro "EnumEntry" $e}} = {{printf "0x%.8X" $e.Value}}, {{Macro "Docs" $e.Docs}} 198 {{end}} 199 ¶ 200 {{$name := Macro "EnumName" $ | TrimRight "ABCDEFGHIJKLMNOQRSTUVWXYZ" | SplitPascalCase | Upper | JoinWith "_"}} 201 {{if GetAnnotation $ "enumMaxOnly"}} 202 VK_MAX_ENUM({{$name | SplitOn "VK_"}}) 203 {{else}} 204 {{$first := Macro "EnumFirstEntry" $ | SplitOn $name | TrimLeft "_"}} 205 {{$last := Macro "EnumLastEntry" $ | SplitOn $name | TrimLeft "_"}} 206 VK_ENUM_RANGE({{$name | SplitOn "VK_"}}, {{$first}}, {{$last}}) 207 {{end}} 208 } {{Macro "EnumName" $}}; 209 ¶ 210{{end}} 211 212 213{{/* 214------------------------------------------------------------------------------- 215 Emits the C declaration for the specified class. 216------------------------------------------------------------------------------- 217*/}} 218{{define "Struct"}} 219 {{AssertType $ "Class"}} 220 221 {{Macro "Docs" $.Docs}} 222 typedef {{Macro "StructType" $}} { 223 {{ForEach $.Fields "Field" | JoinWith "\n"}} 224 } {{Macro "StructName" $}}; 225 ¶ 226{{end}} 227 228 229{{/* 230------------------------------------------------------------------------------- 231 Emits the C declaration for the specified class field. 232------------------------------------------------------------------------------- 233*/}} 234{{define "Field"}} 235 {{AssertType $ "Field"}} 236 237 {{Node "Type" $}} {{$.Name}}§ 238 {{Macro "ArrayPostfix" (TypeOf $)}}; {{Macro "Docs" $.Docs}} 239{{end}} 240 241 242{{/* 243------------------------------------------------------------------------------- 244 Emits either 'struct' or 'union' for the specified class. 245------------------------------------------------------------------------------- 246*/}} 247{{define "StructType"}} 248 {{AssertType $ "Class"}} 249 250 {{if GetAnnotation $ "union"}}union{{else}}struct{{end}} 251{{end}} 252 253 254{{/* 255------------------------------------------------------------------------------- 256 Emits the C function pointer typedef declaration for the specified command. 257------------------------------------------------------------------------------- 258*/}} 259{{define "FunctionTypedef"}} 260 {{AssertType $ "Function"}} 261 262 typedef {{Node "Type" $.Return}} (VKAPI* {{Macro "FunctionPtrName" $}})({{Macro "Parameters" $}}); 263{{end}} 264 265 266{{/* 267------------------------------------------------------------------------------- 268 Emits the C function declaration for the specified command. 269------------------------------------------------------------------------------- 270*/}} 271{{define "FunctionDecl"}} 272 {{AssertType $ "Function"}} 273 274 {{if not (GetAnnotation $ "fptr")}} 275 {{Macro "Docs" $.Docs}} 276 {{Node "Type" $.Return}} VKAPI {{Macro "FunctionName" $}}({{Macro "Parameters" $}}); 277 {{end}} 278{{end}} 279