{{Include "vulkan_common.tmpl"}}
{{Macro "DefineGlobals" $}}
{{$ | Macro "vk.xml" | Reflow 4 | Write "vk.xml"}}
{{/*
-------------------------------------------------------------------------------
Entry point
-------------------------------------------------------------------------------
*/}}
{{define "vk.xml"}}
»«
Copyright (c) 2015 The Khronos Group Inc.
¶
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
¶
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
¶
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
¶
------------------------------------------------------------------------
¶
This file, vk.xml, is the Vulkan API Registry.»
¶
»
#include "vk_platform.h"
¶
#define VK_MAKE_VERSION(major, minor, patch) \
«((major << 22) | (minor << 12) | patch)»
¶
// Vulkan API version supported by this file««
#define VK_API_VERSION VK_MAKE_VERSION({{Global "VERSION_MAJOR"}}, {{Global "VERSION_MINOR"}}, {{Global "VERSION_PATCH"}})
¶
»»««
#if (_MSC_VER >= 1800 || __cplusplus >= 201103L)
#define VK_NONDISP_HANDLE_OPERATOR_BOOL() explicit operator bool() const { return handle != 0; }
#else
#define VK_NONDISP_HANDLE_OPERATOR_BOOL()
«#endif
»»»
¶
«««
#define VK_DEFINE_HANDLE(obj) typedef struct obj##_T* obj;
»»»«««
#if defined(__cplusplus)
»»#if (_MSC_VER >= 1800 || __cplusplus >= 201103L)
»// The bool operator only works if there are no implicit conversions from an obj to
// a bool-compatible type, which can then be used to unintentionally violate type safety.
// C++11 and above supports the "explicit" keyword on conversion operators to stop this
// from happening. Otherwise users of C++ below C++11 won't get direct access to evaluating
// the object handle as a bool in expressions like:
// if (obj) vkDestroy(obj);
#define VK_NONDISP_HANDLE_OPERATOR_BOOL() explicit operator bool() const { return handle != 0; }
#define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
explicit obj(uint64_t x) : handle(x) { } \
obj(decltype(nullptr)) : handle(0) { }
«#else»
#define VK_NONDISP_HANDLE_OPERATOR_BOOL()
#define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
obj(uint64_t x) : handle(x) { }
«#endif
#define VK_DEFINE_NONDISP_HANDLE(obj) \»
struct obj { \
obj() { } \
VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \
obj& operator =(uint64_t x) { handle = x; return *this; } \
bool operator==(const obj& other) const { return handle == other.handle; } \
bool operator!=(const obj& other) const { return handle != other.handle; } \
bool operator!() const { return !handle; } \
VK_NONDISP_HANDLE_OPERATOR_BOOL() \
uint64_t handle; \
};
««#else
»#define VK_DEFINE_NONDISP_HANDLE(obj) typedef struct obj##_T { uint64_t handle; } obj;«
#endif
»»
¶
#if defined(__cplusplus) && ((defined(_MSC_VER) && _MSC_VER >= 1800) || __cplusplus >= 201103L)
»#define VK_NULL_HANDLE nullptr
«#else
»#define VK_NULL_HANDLE 0
«#endif
»»
¶
{{range $e := $.Enums}}
{{if $e.IsBitfield}}
{{$bits := print (Macro "EnumName" $e | TrimRight "s") "Bits"}}
typedef VkFlags {{$e.Name}};§
{{if $e.Entries}}{{Macro "XML.Docs" $e.Docs}}
{{else}}{{Macro "XML.Docs" (Strings $e.Docs "(no bits yet)")}}
{{end}}
{{end}}
{{end}}
¶
{{range $i, $p := $.Pseudonyms}}
{{ if (GetAnnotation $p "dispatchHandle")}}
{{if Global "VK_DEFINE_HANDLE_TYPE_DEFINED"}}
VK_DEFINE_HANDLE({{$p.Name}})
{{else}}
{{Global "VK_DEFINE_HANDLE_TYPE_DEFINED" "YES"}}
VK_DEFINE_HANDLE({{$p.Name}})
{{end}}
{{else if (GetAnnotation $p "nonDispatchHandle")}}
{{if Global "VK_DEFINE_NONDISP_HANDLE_TYPE_DEFINED"}}
VK_DEFINE_NONDISP_HANDLE({{$p.Name}})
{{else}}
{{Global "VK_DEFINE_NONDISP_HANDLE_TYPE_DEFINED" "YES"}}
VK_DEFINE_NONDISP_HANDLE({{$p.Name}})
{{end}}
{{end}}
{{end}}
¶
{{range $e := SortBy $.Enums "EnumName"}}
{{if and $e.Entries (not (GetAnnotation $e "internal"))}}
{{if $e.IsBitfield}}
{{else}}
{{end}}
{{end}}
{{end}}
¶
typedef void* (VKAPI *PFN_vkAllocFunction)(«
void* pUserData,
size_t size,
size_t alignment,
VkSystemAllocType allocType);»
typedef void (VKAPI *PFN_vkFreeFunction)(«
void* pUserData,
void* pMem);»
¶
typedef void (VKAPI *PFN_vkVoidFunction)(void);
¶
{{range $c := $.Classes}}
{{if not (GetAnnotation $c "internal")}}
{{Macro "Struct" $c}}
{{end}}
{{end}}
«
¶
¶
»
{{range $d := $.Definitions}}
{{if HasPrefix $d.Name "VK_"}}
{{Macro "XML.Docs" $d.Docs}}
{{end}}
{{end}}
«
¶
«
¶
{{range $e := $.Enums}}
{{if not (or $e.IsBitfield (GetAnnotation $e "internal"))}}
{{Macro "XML.Enum" $e}}
{{end}}
{{end}}
¶
{{range $e := $.Enums}}
{{if $e.IsBitfield}}
{{Macro "XML.Bitfield" $e}}
{{end}}
{{end}}
¶
»
{{range $f := AllCommands $}}
{{if not (GetAnnotation $f "pfn")}}
{{Macro "XML.Function" $f}}
{{end}}
{{end}}
«
¶
»
»
«
»
«
»
«
»
{{range $f := AllCommands $}}
{{if not (GetAnnotation $f "pfn")}}
{{end}}
{{end}}
«»
«
«
¶
«
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the C declaration for the specified bitfield.
-------------------------------------------------------------------------------
*/}}
{{define "XML.Bitfield"}}
{{AssertType $ "Enum"}}
{{if $.Entries}}
»
{{range $e := $.Entries}}
{{$pos := Bitpos $e.Value}}
{{end}}
«
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the C declaration for the specified enum.
-------------------------------------------------------------------------------
*/}}
{{define "XML.Enum"}}
{{AssertType $ "Enum"}}
»
{{range $i, $e := $.Entries}}
{{end}}
{{if $lu := GetAnnotation $ "lastUnused"}}
{{end}}
«
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the C declaration for the specified class.
-------------------------------------------------------------------------------
*/}}
{{define "Struct"}}
{{AssertType $ "Class"}}
»
{{range $f := $.Fields}}
{{Node "XML.Type" $f}} {{$f.Name}}{{Macro "XML.ArrayPostfix" $f}}{{Macro "XML.Docs" $f.Docs}}
{{end}}
«
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits either 'struct' or 'union' for the specified class.
-------------------------------------------------------------------------------
*/}}
{{define "StructType"}}
{{AssertType $ "Class"}}
{{if GetAnnotation $ "union"}}union{{else}}struct{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the C function pointer typedef declaration for the specified command.
-------------------------------------------------------------------------------
*/}}
{{define "XML.Function"}}
{{AssertType $ "Function"}}
{{$ts := GetAnnotation $ "threadSafety"}}
»
{{Node "XML.Type" $.Return}} {{$.Name}}
{{range $p := $.CallParameters}}
{{Node "XML.Type" $p}} {{$p.Name}}{{Macro "ArrayPostfix" $p}}
{{end}}
«
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the XML translation for the specified documentation block (string array).
-------------------------------------------------------------------------------
*/}}
{{define "XML.Docs"}}
{{if $}} {{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the C translation for the specified type.
-------------------------------------------------------------------------------
*/}}
{{define "XML.Type.Class" }}{{Macro "StructName" $.Type}}{{end}}
{{define "XML.Type.Pseudonym" }}{{$.Type.Name}}{{end}}
{{define "XML.Type.Enum" }}{{$.Type.Name}}{{end}}
{{define "XML.Type.StaticArray"}}{{Node "XML.Type" $.Type.ValueType}}{{end}}
{{define "XML.Type.Pointer" }}{{if $.Type.Const}}{{Node "XML.ConstType" $.Type.To}}{{else}}{{Node "XML.Type" $.Type.To}}{{end}}*{{end}}
{{define "XML.Type.Slice" }}{{Node "XML.Type" $.Type.To}}*{{end}}
{{define "XML.Type#s8" }}int8_t{{end}}
{{define "XML.Type#u8" }}uint8_t{{end}}
{{define "XML.Type#s16" }}int16_t{{end}}
{{define "XML.Type#u16" }}uint16_t{{end}}
{{define "XML.Type#s32" }}int32_t{{end}}
{{define "XML.Type#u32" }}uint32_t{{end}}
{{define "XML.Type#f32" }}float{{end}}
{{define "XML.Type#s64" }}int64_t{{end}}
{{define "XML.Type#u64" }}uint64_t{{end}}
{{define "XML.Type#f64" }}double{{end}}
{{define "XML.Type#char" }}char{{end}}
{{define "XML.Type#void" }}void{{end}}
{{define "XML.ConstType_Default"}}const {{Node "XML.Type" $.Type}}{{end}}
{{define "XML.ConstType.Pointer"}}{{Node "XML.Type" $.Type}} const{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a C type and name for the given parameter
-------------------------------------------------------------------------------
*/}}
{{define "XML.Parameter"}}
{{AssertType $ "Parameter"}}
{{Macro "ParameterType" $}} {{$.Name}}{{Macro "ArrayPostfix" $}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a comma-separated list of C type-name paired parameters for the given
command.
-------------------------------------------------------------------------------
*/}}
{{define "XML.Parameters"}}
{{AssertType $ "Function"}}
{{ForEach $.CallParameters "XML.Parameter" | JoinWith ", "}}
{{if not $.CallParameters}}void{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the fixed-size-array postfix for pseudonym types annotated with @array
-------------------------------------------------------------------------------
*/}}
{{define "XML.ArrayPostfix"}}{{Node "XML.ArrayPostfix" $}}{{end}}
{{define "XML.ArrayPostfix.StaticArray"}}[{{Node "XML.NamedValue" $.Type.SizeExpr}}]{{end}}
{{define "XML.ArrayPostfix_Default"}}{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the value of the given constant, or the tagged name if existant.
-------------------------------------------------------------------------------
*/}}
{{define "XML.NamedValue.Definition"}}{{$.Node.Name}}{{end}}
{{define "XML.NamedValue.EnumEntry"}}{{$.Node.Name}}{{end}}
{{define "XML.NamedValue_Default"}}{{$.Node}}{{end}}