Developer Documentation
Generating the wrapper
A large portion of this package relies on static code generation. To re-generate the main wrapper (generated/vulkan_wrapper.jl
), execute generator/scripts/generate_wrapper.jl
in the generator
environment:
julia --color=yes --project=generator -e 'using Pkg; Pkg.instantiate(); include("generator/scripts/generate_wrapper.jl")'
Note that VulkanGen, the generator module, contains tests which should be run first to ensure the correctness of the wrapping process. Therefore, it is recommended to use this command instead to also test both VulkanGen and Vulkan.jl:
julia --color=yes --project=generator -e 'include(\"generator/test/runtests.jl\"); include(\"generator/scripts/generate_wrapper.jl\"); using Pkg; Pkg.activate(\".\"); Pkg.test()'
VulkanGen API
VulkanGen.consumed_handles
VulkanGen.disabled_specs
VulkanGen.spec_aliases
VulkanGen.spec_all_noalias
VulkanGen.spec_all_semantic_enums
VulkanGen.spec_bitmasks
VulkanGen.spec_constants
VulkanGen.spec_enums
VulkanGen.spec_flags
VulkanGen.spec_funcs
VulkanGen.spec_handles
VulkanGen.spec_structs
VulkanGen.spec_unions
VulkanGen.CreateFunc
VulkanGen.DestroyFunc
VulkanGen.FUNC_TYPE
VulkanGen.FieldIterator
VulkanGen.PARAM_REQUIREMENT
VulkanGen.QueueType
VulkanGen.RenderPassInside
VulkanGen.RenderPassOutside
VulkanGen.RenderPassRequirement
VulkanGen.STRUCT_TYPE
VulkanGen.Spec
VulkanGen.SpecAlias
VulkanGen.SpecBit
VulkanGen.SpecBitmask
VulkanGen.SpecConstant
VulkanGen.SpecEnum
VulkanGen.SpecFlag
VulkanGen.SpecFunc
VulkanGen.SpecFuncParam
VulkanGen.SpecHandle
VulkanGen.SpecStruct
VulkanGen.SpecStructMember
VulkanGen.SpecUnion
VulkanGen._wrap_implicit_return
VulkanGen.extend_handle_constructor
VulkanGen.func_ptr_args
VulkanGen.func_ptr_args
VulkanGen.func_ptrs
VulkanGen.hasalias
VulkanGen.is_pointer_start
VulkanGen.isalias
VulkanGen.nice_julian_type
VulkanGen.translate_c_type
VulkanGen.wrap_identifier
VulkanGen.consumed_handles
— ConstantThese handle types are consumed by whatever command uses them. From the specification: "The following object types are consumed when they are passed into a Vulkan command and not further accessed by the objects they are used to create.".
VulkanGen.disabled_specs
— ConstantSome specifications are disabled in the Vulkan headers (see https://github.com/KhronosGroup/Vulkan-Docs/issues/1225).
VulkanGen.spec_aliases
— ConstantAll specification aliases.
VulkanGen.spec_all_noalias
— ConstantAll specifications except aliases.
VulkanGen.spec_all_semantic_enums
— ConstantAll enumerations, regardless of them being bitmasks or regular enum values.
VulkanGen.spec_bitmasks
— ConstantSpecification bitmask enumerations.
VulkanGen.spec_constants
— ConstantSpecification constants, usually defined in C with #define.
VulkanGen.spec_enums
— ConstantSpecification enumerations, excluding bitmasks.
VulkanGen.spec_flags
— ConstantFlag types.
VulkanGen.spec_funcs
— ConstantSpecification functions.
VulkanGen.spec_handles
— ConstantSpecification handle types.
VulkanGen.spec_structs
— ConstantSpecification structures.
VulkanGen.spec_unions
— ConstantSpecification for union types.
VulkanGen.CreateFunc
— TypeFunction func
that creates a handle
from a create info structure create_info_struct
passed as the value of the parameter create_info_param
.
If batch
is true, then func
expects a list of multiple create info structures and will create multiple handles at once.
struct CreateFunc <: Spec
func::SpecFunc
handle::SpecHandle
create_info_struct::Union{Nothing, SpecStruct}
create_info_param::Union{Nothing, SpecFuncParam}
batch::Bool
VulkanGen.DestroyFunc
— TypeFunction func
that destroys a handle
passed as the value of the parameter destroyed_param
.
If batch
is true, then func
expects a list of multiple handles and will destroy all of them at once.
struct DestroyFunc <: Spec
func::SpecFunc
handle::SpecHandle
destroyed_param::SpecFuncParam
batch::Bool
VulkanGen.FUNC_TYPE
— TypeFunction type classification.
Types:
CREATE
: constructor (functions that begin withvkCreate
).DESTROY
: destructor (functions that begin withvkDestroy
).ALLOCATE
: allocator (functions that begin withvkAllocate
).FREE
: deallocator (functions that begin withvkFree
).COMMAND
: Vulkan command (functions that begin withvkCmd
).QUERY
: used to query parameters, returned directly or indirectly through pointer mutation (typically, functions that begin withvkEnumerate
andvkGet
, but not all of them and possibly others).OTHER
: no identified type.
primitive type FUNC_TYPE <: Enum{Int32} 32
VulkanGen.FieldIterator
— TypeIterate through function or struct specification fields from a list of fields. list
is a sequence of fields to get through from root
.
struct FieldIterator
root::Any
list::Any
VulkanGen.PARAM_REQUIREMENT
— TypeParameter requirement. Applies both to struct members and function parameters.
Requirement types:
OPTIONAL
: may have its default zero (or nullptr) value, acting as a sentinel value (similar toNothing
in Julia).REQUIRED
: must be provided, no sentinel value is allowed.POINTER_OPTIONAL
: is a pointer which may be null, but must have valid elements if provided.POINTER_REQUIRED
: must be a valid pointer, but its elements are optional (e.g. are allowed to be sentinel values).
primitive type PARAM_REQUIREMENT <: Enum{Int32} 32
VulkanGen.QueueType
— TypeQueue type on which a computation can be carried.
abstract type QueueType
VulkanGen.RenderPassInside
— TypeThe command can be executed inside a render pass.
struct RenderPassInside <: RenderPassRequirement
VulkanGen.RenderPassOutside
— TypeThe command can be executed outside a render pass.
struct RenderPassOutside <: RenderPassRequirement
VulkanGen.RenderPassRequirement
— TypeRender pass execution specification for commands.
abstract type RenderPassRequirement
VulkanGen.STRUCT_TYPE
— TypeStructure type classification.
Types:
CREATE_INFO
: holds constructor parameters (structures that end withCreateInfo
).ALLOCATE_INFO
: holds allocator parameters (structures that end withAllocateInfo
).GENERIC_INFO
: holds parameters for another function or structure (structures that end withInfo
, excluding those falling into the previous types).DATA
: usually represents user or Vulkan data.PROPERTY
: is a property returned by Vulkan in areturnedonly
structure, usually done throughQUERY
type functions.
primitive type STRUCT_TYPE <: Enum{Int32} 32
VulkanGen.Spec
— TypeEverything that a Vulkan specification can apply to: data structures, functions, parameters...
abstract type Spec
VulkanGen.SpecAlias
— TypeSpecification for an alias of the form const <name> = <alias>
.
VulkanGen.SpecBit
— TypeSpecification for a bit used in a bitmask.
struct SpecBit <: Spec
name::Symbol
Name of the bit.
position::Int64
Position of the bit.
VulkanGen.SpecBitmask
— TypeSpecification for a bitmask type that must be formed through a combination of bits
.
Is usually an alias for a UInt32
type which carries meaning through its bits.
struct SpecBitmask <: Spec
name::Symbol
Name of the bitmask type.
bits::StructArrays.StructVector{SpecBit, C, I} where {C<:Union{Tuple, NamedTuple}, I}
Valid bits that can be combined to form the final bitmask value.
width::Integer
VulkanGen.SpecConstant
— TypeSpecification for a constant.
struct SpecConstant <: Spec
name::Symbol
Name of the constant.
value::Any
Value of the constant.
VulkanGen.SpecEnum
— TypeSpecification for an enumeration type.
struct SpecEnum <: Spec
name::Symbol
Name of the enumeration type.
enums::StructArrays.StructVector{SpecConstant, C, I} where {C<:Union{Tuple, NamedTuple}, I}
Vector of possible enumeration values.
VulkanGen.SpecFlag
— TypeSpecification for a flag type name
that is a type alias of typealias
. Can be associated with a bitmask structure, in which case the bitmask
number is set to the corresponding SpecBitmask
.
struct SpecFlag <: Spec
name::Symbol
Name of the flag type.
typealias::Symbol
The type it aliases.
bitmask::Union{Nothing, SpecBitmask}
Bitmask, if applicable.
VulkanGen.SpecFunc
— TypeSpecification for a function.
struct SpecFunc <: Spec
name::Symbol
Name of the function.
type::FUNC_TYPE
FUNC_TYPE
classification.return_type::Union{Nothing, Expr, Symbol}
Return type (void if
Nothing
).render_pass_compatibility::Vector{RenderPassRequirement}
Whether the function can be executed inside a render pass, outside, or both. Empty if not specified, in which case it is equivalent to both inside and outside.
queue_compatibility::Vector{QueueType}
Type of queues on which the function can be executed. Empty if not specified, in which case it is equivalent to being executable on all queues.
params::StructArrays.StructVector{SpecFuncParam, C, I} where {C<:Union{Tuple, NamedTuple}, I}
Function parameters.
success_codes::Vector{Symbol}
error_codes::Vector{Symbol}
VulkanGen.SpecFuncParam
— TypeSpecification for a function parameter.
struct SpecFuncParam <: Spec
func::Symbol
Name of the parent function.
name::Symbol
Identifier.
type::Union{Expr, Symbol}
Expression of its Julian type.
is_constant::Bool
If constant, cannot be mutated by Vulkan functions.
is_externsync::Bool
Whether it must be externally synchronized before calling the function.
requirement::PARAM_REQUIREMENT
PARAM_REQUIREMENT
classification.len::Union{Nothing, Symbol}
Name of the parameter (of the same function) which represents its length.
Nothing
for non-vector types.arglen::Vector{Symbol}
Name of the parameters (of the same function) it is a length of.
autovalidity::Bool
Whether automatic validity documentation is enabled. If false, this means that the parameter may be an exception to at least one Vulkan convention.
VulkanGen.SpecHandle
— TypeSpecification for handle types.
A handle may possess a parent. In this case, the handle can only be valid if its parent is valid.
Some handles are dispatchable, which means that they are represented as opaque pointers. Non-dispatchable handles are 64-bit integer types, and may encode information directly into their value.
struct SpecHandle <: Spec
name::Symbol
Name of the handle type.
parent::Union{Nothing, Symbol}
Name of the parent handle, if any.
is_dispatchable::Bool
Whether the handle is dispatchable or not.
VulkanGen.SpecStruct
— TypeSpecification for a structure.
struct SpecStruct <: Spec
name::Symbol
Name of the structure.
type::STRUCT_TYPE
STRUCT_TYPE
classification.is_returnedonly::Bool
Whether the structure is only returned by Vulkan functions (and never requested as input).
extends::Vector{Symbol}
Name of the structures it extends, usually done through the original structures'
pNext
argument.members::StructArrays.StructVector{SpecStructMember, C, I} where {C<:Union{Tuple, NamedTuple}, I}
Structure members.
VulkanGen.SpecStructMember
— TypeSpecification for a structure parameter.
struct SpecStructMember <: Spec
parent::Symbol
Name of the parent structure.
name::Symbol
Identifier.
type::Union{Expr, Symbol}
Expression of its Julian type.
is_constant::Bool
If constant, cannot be mutated by Vulkan functions.
is_externsync::Bool
Whether it must be externally synchronized before calling any function which uses the parent structure.
requirement::PARAM_REQUIREMENT
PARAM_REQUIREMENT
classification.len::Union{Nothing, Expr, Symbol}
Name of the member (of the same structure) which represents its length.
Nothing
for non-vector types.arglen::Vector{Union{Expr, Symbol}}
Name of the members (of the same structure) it is a length of.
autovalidity::Bool
Whether automatic validity documentation is enabled. If false, this means that the member may be an exception to at least one Vulkan convention.
VulkanGen.SpecUnion
— TypeSpecification for a union type.
struct SpecUnion <: Spec
name::Symbol
Name of the union type.
types::Vector{Union{Expr, Symbol}}
Possible types for the union.
selectors::Vector{Symbol}
Selector values, if any, to determine the type of the union in a given context (function call for example).
is_returnedonly::Bool
Whether the type is only returned by Vulkan functions (and never requested as input).
Base.write
— MethodWrite the wrapper to destfile
.
write(vw::VulkanWrapper, destfile::Any, docfile::Any)
VulkanGen._wrap_implicit_return
— MethodBuild a return expression from an implicit return parameter. Implicit return parameters are pointers that are mutated by the API, rather than returned directly. API functions with implicit return parameters return either nothing or a return code, which is automatically checked and not returned by the wrapper. Such implicit return parameters are Ref
s or Vector
s holding either a base type or an API struct Vk*. They need to be converted by the wrapper to their wrapping type.
_wrap_implicit_return(return_param::SpecFuncParam; with_func_ptr) -> Union{Expr, Symbol}
VulkanGen.extend_handle_constructor
— MethodExtend functions that create (or allocate) one or several handles, by exposing the parameters of the associated CreateInfo structures. spec
must have one or several CreateInfo arguments.
extend_handle_constructor(spec::VulkanGen.CreateFunc; with_func_ptr) -> Dict{_A, _B} where {_A, _B}
VulkanGen.func_ptr_args
— MethodFunction pointer arguments for a function. Takes the function pointers arguments of the underlying handle if it is a Vulkan constructor, or a unique fun_ptr
if that's just a normal Vulkan function.
func_ptr_args(spec::SpecFunc) -> Vector{Expr}
VulkanGen.func_ptr_args
— MethodFunction pointer arguments for a handle. Includes one fun_ptr_create
for the constructor (if applicable), and one fun_ptr_destroy
for the destructor (if applicable).
func_ptr_args(spec::SpecHandle) -> Vector{Expr}
VulkanGen.func_ptrs
— MethodCorresponding pointer argument for a Vulkan function.
func_ptrs(spec::Spec) -> AbstractVector{var"#s828"} where var"#s828"
VulkanGen.hasalias
— MethodWhether an alias was built from this name.
hasalias(name::Any) -> Union{Missing, Bool}
VulkanGen.is_pointer_start
— MethodRepresent an integer that gives the start of a C pointer.
is_pointer_start(spec::Spec) -> Union{Missing, Bool}
VulkanGen.isalias
— MethodWhether this type is an alias for another name.
isalias(name::Any) -> Bool
VulkanGen.nice_julian_type
— MethodReturn a new type easier to deal with.
nice_julian_type(spec::Spec) -> Any
VulkanGen.translate_c_type
— MethodSemantically translate C types to their Julia counterpart. Note that since it is a semantic translation, translated types do not necessarily have the same layout, e.g. VkBool32 => Bool (8 bits).
translate_c_type(ctype::Any) -> Any
VulkanGen.wrap_identifier
— MethodGenerate an identifier from a Vulkan identifier, in lower snake case and without pointer prefixes (such as in pNext
).
wrap_identifier(identifier::Any) -> Any