diff --git a/generator/scripts/externsync.jl b/generator/scripts/externsync.jl index 4dc50f43..1d4a9e7a 100644 --- a/generator/scripts/externsync.jl +++ b/generator/scripts/externsync.jl @@ -1,11 +1,8 @@ using Pkg Pkg.activate(dirname(@__DIR__)) -include("../src/spec/VulkanSpec.jl") - -using .VulkanSpec # List all function parameters which require external synchronization. -for f in spec_funcs +for f in api.functions if any(f.params.is_externsync) print("Function: ") printstyled(f.name, '\n'; color = :cyan) diff --git a/generator/src/VulkanGen.jl b/generator/src/VulkanGen.jl index 28a2e7f6..276a5f40 100644 --- a/generator/src/VulkanGen.jl +++ b/generator/src/VulkanGen.jl @@ -24,9 +24,7 @@ using Pkg: project $(SIGNATURES) """ -const VULKAN_API = Ref{VulkanAPI}() - -__init__() = VULKAN_API[] = VulkanAPI(project().version) +const api = VulkanAPI(project().version) include("types.jl") include("exprs.jl") @@ -106,6 +104,6 @@ export Parent, exports, - VULKAN_API + api end # module VulkanGen diff --git a/generator/src/config.jl b/generator/src/config.jl index 92faf4a7..4c893c1c 100644 --- a/generator/src/config.jl +++ b/generator/src/config.jl @@ -15,12 +15,12 @@ end include_provisional_exts(config::WrapperConfig) = config.include_provisional_exts || PLATFORM_PROVISIONAL in config.include_platforms function extensions(config::WrapperConfig) - exts = filter(x -> x.is_provisional && include_provisional_exts(config) || x.platform in config.include_platforms || x.platform == PLATFORM_NONE && config.wrap_core, spec_extensions_supported) + exts = filter(x -> x.is_provisional && include_provisional_exts(config) || x.platform in config.include_platforms || x.platform == PLATFORM_NONE && config.wrap_core, filter(x -> !x.is_disabled, api.extensions)) end function _filter_specs(specs, extensions, wrap_core) filter(specs) do spec - ext = extension(spec) + ext = get(api.extensions, spec, nothing) isnothing(ext) && wrap_core || ext in extensions end end diff --git a/generator/src/dependency_resolution.jl b/generator/src/dependency_resolution.jl index f3591751..1ef45270 100644 --- a/generator/src/dependency_resolution.jl +++ b/generator/src/dependency_resolution.jl @@ -42,7 +42,7 @@ function dependencies(ex) deps = raw_dependencies(ex) filter!.( [ - !isalias, + x -> !isalias(x, api.aliases), x -> !startswith(string(x), r"(?:Vk|VK_|StdVideo)"), !is_vulkan_type, !in(known_dependencies), diff --git a/generator/src/type_conversions.jl b/generator/src/type_conversions.jl index 2a861a79..af1dd6ef 100644 --- a/generator/src/type_conversions.jl +++ b/generator/src/type_conversions.jl @@ -1,7 +1,7 @@ function hl_type(spec::Spec) @match s = spec begin if s.name == :pNext end => :Any - GuardBy(is_version) => :VersionNumber + if is_version(s, api.constants) end => :VersionNumber GuardBy(is_arr) => begin T = hl_type(ptr_type(s.type)) :(Vector{$T}) @@ -23,15 +23,15 @@ function hl_type(type) end :(NTuple{$_N,$(hl_type(T))}) end - GuardBy(in([spec_structs.name; spec_unions.name])) => struct_name(t, true) - GuardBy(in(spec_handles.name)) => remove_vk_prefix(t) + GuardBy(in([api.structs.name; api.unions.name])) => struct_name(t, true) + GuardBy(in(api.handles.name)) => remove_vk_prefix(t) GuardBy(is_fn_ptr) => :FunctionPtr :(Ptr{$T}) => hl_type(T) GuardBy(is_flag_bitmask) => bitmask_flag_type(t) - GuardBy(in(spec_flags.name)) && if !isnothing(flag_by_name(t).bitmask) - end => bitmask_flag_type(flag_by_name(t).bitmask) - GuardBy(in(spec_constants.name)) => follow_constant(t) - GuardBy(in(spec_enums.name)) => enum_type(t) + GuardBy(in(api.flags.name)) && if !isnothing(api.flags[t].bitmask) + end => bitmask_flag_type(api.flags[t].bitmask) + GuardBy(in(api.constants.name)) => follow_constant(t, api.constants) + GuardBy(in(api.enums.name)) => enum_type(t) GuardBy(is_vulkan_type) => remove_vk_prefix(t) GuardBy(is_intermediate) => Symbol(string(t)[2:end]) _ => t @@ -53,13 +53,13 @@ function idiomatic_julia_type(type) :Cstring => :String :VkBool32 => :Bool :(Ptr{$pt}) => idiomatic_julia_type(pt) - GuardBy(in([spec_structs.name; spec_unions.name])) => struct_name(t) - GuardBy(in(spec_handles.name)) => remove_vk_prefix(t) - GuardBy(in(spec_enums.name)) => enum_type(t) + GuardBy(in([api.structs.name; api.unions.name])) => struct_name(t) + GuardBy(in(api.handles.name)) => remove_vk_prefix(t) + GuardBy(in(api.enums.name)) => enum_type(t) GuardBy(is_flag_bitmask) => bitmask_flag_type(t) - GuardBy(in(spec_flags.name)) && if !isnothing(flag_by_name(t).bitmask) - end => bitmask_flag_type(flag_by_name(t).bitmask) - GuardBy(in(spec_constants.name)) => follow_constant(t) + GuardBy(in(api.flags.name)) && if !isnothing(api.flags[t].bitmask) + end => bitmask_flag_type(api.flags[t].bitmask) + GuardBy(in(api.constants.name)) => follow_constant(t, api.constants) _ => t end end @@ -69,7 +69,7 @@ Return a new type easier to deal with. """ function idiomatic_julia_type(spec::Spec) @match s = spec begin - GuardBy(is_version) => :VersionNumber + if is_version(s, api.constants) end => :VersionNumber GuardBy(is_arr) => :(Vector{$(idiomatic_julia_type(ptr_type(s.type)))}) GuardBy(is_data) => :(Ptr{Cvoid}) _ => idiomatic_julia_type(s.type) diff --git a/generator/src/types.jl b/generator/src/types.jl index 82d25183..317d14b0 100644 --- a/generator/src/types.jl +++ b/generator/src/types.jl @@ -9,7 +9,7 @@ ntuple_type(ex) = @when :(NTuple{$N,$T}) = ex T is_ntuple(ex) = !isnothing(ntuple_type(ex)) -is_vulkan_type(name) = name ∈ [spec_handles.name; spec_structs.name; spec_unions.name] +is_vulkan_type(name) = name ∈ [api.handles.name; api.structs.name; api.unions.name] inner_type(ex) = @when :($T{$(args...)}) = ex map(args) do arg @match arg begin diff --git a/generator/src/wrap.jl b/generator/src/wrap.jl index 9f88997f..03560a15 100644 --- a/generator/src/wrap.jl +++ b/generator/src/wrap.jl @@ -62,8 +62,6 @@ struct Parent <: MethodDefinition p::Dict end -VulkanSpec.has_parent(def::HandleDefinition) = has_parent(def.spec) - struct StructureType <: MethodDefinition spec::SpecStruct ex::Expr @@ -153,19 +151,19 @@ include("wrap/docs.jl") function VulkanWrapper(config::WrapperConfig) f = filter_specs(config) - constants = ConstantDefinition.(filter(include_constant, f(spec_constants))) - enums = EnumDefinition.(f(spec_enums)) - bitmasks = BitmaskDefinition.(f(spec_bitmasks)) - handles = HandleDefinition.(f(spec_handles)) + constants = ConstantDefinition.(filter(include_constant, f(api.constants))) + enums = EnumDefinition.(f(api.enums)) + bitmasks = BitmaskDefinition.(f(api.bitmasks)) + handles = HandleDefinition.(f(api.handles)) # Structures. - structs = StructDefinition{false}.(f(spec_structs)) + structs = StructDefinition{false}.(f(api.structs)) structs_hl = StructDefinition{true}.(structs) struct_constructors = Constructor.(structs) struct_constructors_from_hl = [Constructor(T, x) for (T, x) in zip(structs, structs_hl)] struct_constructors_from_ll = [Constructor(T, x) for (T, x) in zip(structs_hl, structs)] - struct_constructors_from_core = [Constructor(T, x) for (T, x) in zip(structs_hl, f(spec_structs))] + struct_constructors_from_core = [Constructor(T, x) for (T, x) in zip(structs_hl, f(api.structs))] struct_constructors_hl = Constructor.(structs_hl) ## Do not overwrite the default constructor (leads to infinite recursion). @@ -174,7 +172,7 @@ function VulkanWrapper(config::WrapperConfig) end # Unions. - unions = StructDefinition{false}.(f(spec_unions)) + unions = StructDefinition{false}.(f(api.unions)) unions_hl = StructDefinition{true}.(unions) union_constructors = [constructors.(unions)...;] @@ -185,13 +183,13 @@ function VulkanWrapper(config::WrapperConfig) enum_converts_to_integer = [Convert(enum, enum_val_type(enum)) for enum in enums] enum_converts_to_enum = [Convert(enum_val_type(enum), enum) for enum in enums] - enum_converts_from_spec = [Convert(enum, spec_enum.name) for (enum, spec_enum) in zip(enums, f(spec_enums))] - enum_converts_to_spec = [Convert(spec_enum.name, enum) for (enum, spec_enum) in zip(enums, f(spec_enums))] + enum_converts_from_spec = [Convert(enum, spec_enum.name) for (enum, spec_enum) in zip(enums, f(api.enums))] + enum_converts_to_spec = [Convert(spec_enum.name, enum) for (enum, spec_enum) in zip(enums, f(api.enums))] struct_converts_to_ll = [Convert(T, x) for (T, x) in zip(structs, structs_hl)] union_converts_to_ll = [Convert(T, x) for (T, x) in zip(unions, unions_hl)] - funcs = APIFunction.(f(spec_funcs), false) - funcs_fptr = APIFunction.(f(spec_funcs), true) + funcs = APIFunction.(f(api.functions), false) + funcs_fptr = APIFunction.(f(api.functions), true) funcs_hl = promote_hl.(funcs) funcs_hl_fptr = promote_hl.(funcs_fptr) @@ -209,7 +207,7 @@ function VulkanWrapper(config::WrapperConfig) handle_constructors_api_hl_fptr = Constructor{HandleDefinition,APIFunction{APIFunction{SpecFunc}}}[] for handle in handles - cs = f(filter(x -> x.handle == handle.spec && !x.batch, spec_create_funcs)) + cs = f(filter(x -> x.handle == handle.spec && !x.batch, api.constructors)) for api_constructor in cs (; func) = api_constructor f1 = APIFunction(func, false) @@ -246,16 +244,16 @@ function VulkanWrapper(config::WrapperConfig) parent_overloads = Parent.(filter(has_parent, handles)) - stypes = StructureType.(filter(x -> haskey(structure_types, x.name), f(spec_structs))) - hl_type_mappings = [HLTypeMapping.(f(spec_structs)); HLTypeMapping.(f(spec_unions))] - core_type_mappings = [CoreTypeMapping.(f(spec_structs)); CoreTypeMapping.(f(spec_unions))] - intermediate_type_mappings = IntermediateTypeMapping.(filter(has_intermediate_type, f(spec_structs))) + stypes = StructureType.(filter(x -> haskey(api.structure_types, x.name), f(api.structs))) + hl_type_mappings = [HLTypeMapping.(f(api.structs)); HLTypeMapping.(f(api.unions))] + core_type_mappings = [CoreTypeMapping.(f(api.structs)); CoreTypeMapping.(f(api.unions))] + intermediate_type_mappings = IntermediateTypeMapping.(filter(has_intermediate_type, f(api.structs))) # For SPIR-V, there is no platform-dependent behavior, so no need to call `f`. - spirv_exts = spec_spirv_extensions - spirv_caps = map(spec_spirv_capabilities) do spec + spirv_exts = api.extensions_spirv + spirv_caps = map(api.capabilities_spirv) do spec feats = map(spec.enabling_features) do feat - FeatureCondition(struct_name(follow_alias(feat.type), true), nc_convert(SnakeCaseLower, feat.member), feat.core_version, feat.extension) + FeatureCondition(struct_name(follow_alias(feat.type, api.aliases), true), nc_convert(SnakeCaseLower, feat.member), feat.core_version, feat.extension) end props = map(spec.enabling_properties) do prop bit = isnothing(prop.bit) ? nothing : remove_vk_prefix(prop.bit) @@ -269,17 +267,17 @@ function VulkanWrapper(config::WrapperConfig) ] aliases = AliasDeclaration[] - for (source, target) in collect(alias_dict) + for (source, target) in collect(api.aliases.dict) startswith(string(target), "vk") && continue al = AliasDeclaration(source => target) al.target in exported_symbols && push!(aliases, al) end function_aliases = Expr[] - _spec_funcs = f(spec_funcs) - for (source, target) in collect(alias_dict) + functions = f(api.functions) + for (source, target) in collect(api.aliases.dict) al = AliasDeclaration(source => target) startswith(string(source), "vk") || continue - f = func_by_name(target) + f = api.functions[target] handle = dispatch_handle(f) param = @match handle begin :(device($x)) || :(instance($x)) || x::Symbol => x @@ -287,7 +285,7 @@ function VulkanWrapper(config::WrapperConfig) end args = Any[:(args...)] !isnothing(param) && pushfirst!(args, param) - if f in _spec_funcs + if f in functions push!(function_aliases, # :($source(args..., fptr::FunctionPtr; kwargs...) = $target(args..., fptr; kwargs...)), :($(al.source)($(args...); kwargs...) = @dispatch $source $handle $(al.target)($(args...); kwargs...)) @@ -348,9 +346,9 @@ function VulkanWrapper(config::WrapperConfig) :(const SPIRV_EXTENSIONS = [$(spirv_exts...)]); :(const SPIRV_CAPABILITIES = [$(spirv_caps...)]); - :(const CORE_FUNCTIONS = $core_functions); - :(const INSTANCE_FUNCTIONS = $instance_functions); - :(const DEVICE_FUNCTIONS = $device_functions); + :(const CORE_FUNCTIONS = $(api.core_functions)); + :(const INSTANCE_FUNCTIONS = $(api.instance_functions)); + :(const DEVICE_FUNCTIONS = $(api.device_functions)); ], exported_symbols, ) diff --git a/generator/src/wrap/call.jl b/generator/src/wrap/call.jl index 7770c5d3..51b1bf93 100644 --- a/generator/src/wrap/call.jl +++ b/generator/src/wrap/call.jl @@ -16,7 +16,7 @@ end function len_expr(x::Spec, identifier) @assert !isnothing(x.len) - params = children(parent_spec(x)) + params = children(x.parent) postwalk(x.len) do ex ex == :/ && return :÷ ex isa Symbol && ex in params.name && return :($identifier.$ex) @@ -27,11 +27,11 @@ end function from_vk_call(prop, t, jtype = hl_type(t)) @match t begin :Cstring => :(unsafe_string($prop)) - GuardBy(in(spec_flags.name)) || GuardBy(in(spec_enums.name)) => prop - GuardBy(in(getproperty.(filter(!isnothing, spec_flags.bitmask), :name))) => :($jtype(UInt32($prop))) - GuardBy(in(spec_handles.name)) => :($(remove_vk_prefix(t))($prop)) + GuardBy(in(api.flags.name)) || GuardBy(in(api.enums.name)) => prop + GuardBy(in(getproperty.(filter(!isnothing, api.flags.bitmask), :name))) => :($jtype(UInt32($prop))) + GuardBy(in(api.handles.name)) => :($(remove_vk_prefix(t))($prop)) :(NTuple{$_,$T}) && if jtype ≠ :String end => broadcast_ex(from_vk_call(prop, ntuple_type(t))) - if follow_constant(t) == jtype + if follow_constant(t, api.constants) == jtype end => prop if is_hl(jtype) end => :($jtype($prop)) _ => :(from_vk($jtype, $prop)) @@ -42,8 +42,8 @@ function vk_call(x::Spec) var = wrap_identifier(x.name) jtype = idiomatic_julia_type(x) @match x begin - ::SpecStructMember && if x.type == :VkStructureType && parent(x) ∈ keys(structure_types) - end => :(structure_type($(parent(x)))) + ::SpecStructMember && if x.type == :VkStructureType && x.parent.name ∈ keys(api.structure_types) + end => :(structure_type($(x.parent.name))) ::SpecStructMember && if is_semantic_ptr(x.type) end => :(unsafe_convert($(x.type), $var)) if is_fn_ptr(x.type) @@ -59,30 +59,30 @@ function vk_call(x::Spec) end end GuardBy(is_pointer_start) => 0 # always set first* variables to 0, and the user should provide a (sub)array of the desired length - if x.type ∈ spec_handles.name + if x.type ∈ api.handles.name end => var # handled by unsafe_convert in ccall # constant pointer to a unique object if is_ptr(x.type) && !is_arr(x) && - (x.is_constant || (func = func_by_name(x.func); func.type == FTYPE_QUERY && x ≠ last(children(func)))) + (x.is_constant || (func = api.functions[x.func]; func.type == FTYPE_QUERY && x ≠ last(children(func)))) end => @match x begin - if ptr_type(x.type) ∈ [spec_structs.name; spec_unions.name] + if ptr_type(x.type) ∈ [api.structs.name; api.unions.name] end => var # handled by cconvert and unsafe_convert in ccall if x.requirement == OPTIONAL end => :($var == $(default(x)) ? $(default(x)) : Ref($var)) # allow optional pointers to be passed as C_NULL instead of a pointer to a 0-valued integer _ => :(Ref($var)) end - if x.type ∈ [spec_flags.name; spec_enums.name] + if x.type ∈ [api.flags.name; api.enums.name] end => var - if x.type ∈ getproperty.(filter(!isnothing, spec_flags.bitmask), :name) + if x.type ∈ getproperty.(filter(!isnothing, api.flags.bitmask), :name) end => :($(x.type)($var.val)) if x.type ∈ extension_types end => var _ => @match jtype begin - :String || :Bool || :(Vector{$et}) || if jtype == follow_constant(x.type) + :String || :Bool || :(Vector{$et}) || if jtype == follow_constant(x.type, api.constants) end => var # conversions are already defined - if x.type in [spec_structs.name; spec_unions.name] && jtype == struct_name(x.type) + if x.type in [api.structs.name; api.unions.name] && jtype == struct_name(x.type) end => :($var.vks) :(NTuple{Int($_N),$_T}) => var _ => :(to_vk($(x.type), $var)) # fall back to the to_vk function for conversion diff --git a/generator/src/wrap/classification.jl b/generator/src/wrap/classification.jl index ec266327..4ae9ce36 100644 --- a/generator/src/wrap/classification.jl +++ b/generator/src/wrap/classification.jl @@ -4,9 +4,8 @@ is_optional(param::SpecFuncParam) = param.requirement ∈ [OPTIONAL, POINTER_OPT """ Represent an integer that gives the start of a C pointer. """ -function is_pointer_start(spec::Spec) - params = children(parent_spec(spec)) - any(params) do param +function is_pointer_start(spec::Union{SpecStructMember, SpecFuncParam}) + any(spec.parent) do param !isempty(param.arglen) && spec.type == :UInt32 && string(spec.name) == string("first", uppercasefirst(replace(string(param.name), r"Count$" => ""))) @@ -21,6 +20,14 @@ is_data_with_retrievable_size(spec::SpecFuncParam) = is_data(spec) && len(spec). is_opaque_data(spec) = is_data(spec) && len(spec).requirement ≠ POINTER_REQUIRED is_opaque_pointer(type) = is_ptr(type) && is_void(ptr_type(type)) is_opaque_pointer(spec::Spec) = is_opaque_pointer(spec.type) +is_void(t) = t == :Cvoid || t in [ + :xcb_connection_t, + :_XDisplay, + :Display, + :wl_surface, + :wl_display, + :CAMetalLayer, +] is_opaque(spec) = is_opaque_data(spec) || is_opaque_pointer(spec) is_implicit_return(spec::SpecFuncParam) = !is_opaque_data(spec) && @@ -30,15 +37,15 @@ is_implicit_return(spec::SpecFuncParam) = spec.type ∉ extension_types && ptr_type(spec.type) ∉ extension_types has_implicit_return_parameters(spec::SpecFunc) = any(is_implicit_return, children(spec)) -is_flag(type) = type in spec_flags.name -is_flag(spec::Union{SpecFuncParam,SpecStructMember}) = spec.type in spec_flags.name -is_flag_bitmask(type) = type ∈ getproperty.(filter(!isnothing, spec_flags.bitmask), :name) +is_flag(type) = type in api.flags.name +is_flag(spec::Union{SpecFuncParam,SpecStructMember}) = spec.type in api.flags.name +is_flag_bitmask(type) = type ∈ getproperty.(filter(!isnothing, api.flags.bitmask), :name) is_fn_ptr(type) = startswith(string(type), "PFN_") is_fn_ptr(spec::Spec) = is_fn_ptr(spec.type) function is_hl(type) vktype = Symbol(:Vk, type) - vktype in [spec_structs.name; spec_unions.name] + vktype in [api.structs.name; api.unions.name] end is_intermediate(type) = startswith(string(type), '_') diff --git a/generator/src/wrap/decl.jl b/generator/src/wrap/decl.jl index dd598cf7..03b1bcb7 100644 --- a/generator/src/wrap/decl.jl +++ b/generator/src/wrap/decl.jl @@ -1,6 +1,6 @@ function arg_decl(x::Spec) T = idiomatic_julia_type(x) - T in struct_name.(spec_handles, true) && return wrap_identifier(x) + T in struct_name.(api.handles, true) && return wrap_identifier(x) :($(wrap_identifier(x))::$(signature_type(T))) end @@ -18,7 +18,7 @@ and one `fptr_destroy` for the destructor (if applicable). """ function func_ptr_args(spec::SpecHandle) args = Expr[] - spec ∈ spec_create_funcs.handle && push!(args, :(fptr_create::FunctionPtr)) + spec ∈ api.constructors.handle && push!(args, :(fptr_create::FunctionPtr)) destructor(spec) ≠ :identity && push!(args, :(fptr_destroy::FunctionPtr)) args end @@ -30,7 +30,7 @@ or a unique `fptr` if that's just a normal Vulkan function. """ function func_ptr_args(spec::SpecFunc) if spec.type ∈ [FTYPE_CREATE, FTYPE_ALLOCATE] - func_ptr_args(create_func(spec).handle) + func_ptr_args(api.constructors[spec].handle) else [:(fptr::FunctionPtr)] end @@ -44,7 +44,7 @@ func_ptrs(spec::Spec) = name.(func_ptr_args(spec)) function add_func_args!(p::Dict, spec, params; with_func_ptr = false) params = filter(!drop_arg, params) arg_filter = if spec.type ∈ [FTYPE_DESTROY, FTYPE_FREE] - destroyed_type = destroy_func(spec).handle.name + destroyed_type = api.destructors[spec].handle.name x -> !is_optional(x) || x.type == destroyed_type else !is_optional diff --git a/generator/src/wrap/defaults.jl b/generator/src/wrap/defaults.jl index e2a87f34..7a8d8392 100644 --- a/generator/src/wrap/defaults.jl +++ b/generator/src/wrap/defaults.jl @@ -2,8 +2,8 @@ default(::SpecHandle) = :C_NULL function default(spec::Union{SpecStructMember,SpecFuncParam}) is_length_exception(spec) && return default_length_exception(spec) @match spec.requirement begin - if spec.type ∈ spec_handles.name - end => default(handle_by_name(spec.type)) + if spec.type ∈ api.handles.name + end => default(api.handles[spec.type]) &POINTER_OPTIONAL || &POINTER_REQUIRED || if is_ptr(spec.type) || spec.type == :Cstring end => :C_NULL &OPTIONAL || &REQUIRED => 0 @@ -11,7 +11,7 @@ function default(spec::Union{SpecStructMember,SpecFuncParam}) end function default_length_exception(spec::Spec) - @match parent(spec) begin + @match spec.parent.name begin :VkWriteDescriptorSet => :(max($((:(pointer_length($(wrap_identifier(arg)))) for arg in arglen(spec))...))) end end diff --git a/generator/src/wrap/docs.jl b/generator/src/wrap/docs.jl index 47efca3b..ef7f2507 100644 --- a/generator/src/wrap/docs.jl +++ b/generator/src/wrap/docs.jl @@ -65,7 +65,7 @@ api_doc(::Nothing) = "" extension_doc(::Nothing) = "" function extension_doc(spec) - ext = extension(spec) + ext = get(api.extensions, spec, nothing) isnothing(ext) && return "" string("\n\n", "Extension: ", replace(string(ext.name), '_' => "\\\\_")) end diff --git a/generator/src/wrap/functions.jl b/generator/src/wrap/functions.jl index 5c6123f9..7dc1faa9 100644 --- a/generator/src/wrap/functions.jl +++ b/generator/src/wrap/functions.jl @@ -14,10 +14,10 @@ end function dispatch_handle(spec::SpecFunc) maybe_handle = !isempty(children(spec)) ? first(children(spec)).type : :nothing - if maybe_handle in spec_handles.name - handle = handle_by_name(maybe_handle) + if maybe_handle in api.handles.name + handle = api.handles[maybe_handle] handle_id = wrap_identifier(handle) - hierarchy = parent_hierarchy(handle) + hierarchy = parent_hierarchy(handle, api.handles) if handle.name == :VkDevice || handle.name == :VkInstance # to avoid name conflicts handle_id @@ -116,7 +116,7 @@ function APIFunction(spec::SpecFunc, with_func_ptr) if spec.type == FTYPE_QUERY && length(queried_params) == 1 && begin t = ptr_type(only(queried_params).type) - is_vulkan_type(t) && !in(t, spec_handles.name) && any(Base.Fix1(in, t), spec_structs.extends) + is_vulkan_type(t) && !in(t, api.handles.name) && any(Base.Fix1(in, t), api.structs.extends) end param = only(queried_params) diff --git a/generator/src/wrap/handles.jl b/generator/src/wrap/handles.jl index badb39df..27d194c9 100644 --- a/generator/src/wrap/handles.jl +++ b/generator/src/wrap/handles.jl @@ -16,7 +16,7 @@ function HandleDefinition(spec::SpecHandle) ) if !isnothing(spec.parent) - id = wrap_identifier(handle_by_name(spec.parent)) + id = wrap_identifier(api.handles[spec.parent]) pdecl = :($id::$(handle_type(spec.parent))) insert!(d[:fields], 2, pdecl) d[:constructors] = [ @@ -34,7 +34,7 @@ function HandleDefinition(spec::SpecHandle) end function destructor(handle::SpecHandle, with_func_ptr = false) - dfs = destroy_funcs(handle) + dfs = api.destructors[handle] has_destructors = !isempty(dfs) if has_destructors @assert length(dfs) == 1 diff --git a/generator/src/wrap/identifiers.jl b/generator/src/wrap/identifiers.jl index ff1041d6..afc22e69 100644 --- a/generator/src/wrap/identifiers.jl +++ b/generator/src/wrap/identifiers.jl @@ -15,7 +15,7 @@ function wrap_identifier(spec::Union{SpecFuncParam,SpecStructMember}) # handle the case where two identifiers end up being the same # issue caused by VkAccelerationStructureBuildGeometryInfoKHR # which has both pGeometries and ppGeometries - siblings = children(parent_spec(spec)) + siblings = children(spec.parent) id = wrap_identifier(spec.name) ids = wrap_identifier.(siblings.name) if count(==(id), ids) == 2 @@ -33,25 +33,23 @@ end function wrap_identifier(spec::SpecHandle) # try to get an id from an existing function parameter spec.name == :VkDeferredOperationKHR && return :operation - cfs = create_funcs(spec) + cfs = api.constructors[spec] id = nothing if !isempty(cfs) for cf in cfs id = wrap_identifier(spec, first(cfs).func) - !isnothing(id) && break - end - end - if isnothing(id) - for f ∈ spec_funcs - id = wrap_identifier(spec, f) !isnothing(id) && return id end - wrap_identifier(remove_vk_prefix(spec.name)) end + for f in api.functions + id = wrap_identifier(spec, f) + !isnothing(id) && return id + end + wrap_identifier(remove_vk_prefix(spec.name)) end function wrap_identifier(spec::SpecHandle, func::SpecFunc) - for param ∈ children(func) + for param in func if spec.name == param.type return wrap_identifier(param) end @@ -60,7 +58,7 @@ function wrap_identifier(spec::SpecHandle, func::SpecFunc) end function struct_name(sym::Symbol, is_high_level = false) - spec = @something(struct_by_name(sym), union_by_name(sym), handle_by_name(sym)) + spec = @something(get(api.structs, sym, nothing), get(api.unions, sym, nothing), api.handles[sym]) struct_name(spec, is_high_level) end diff --git a/generator/src/wrap/initialization.jl b/generator/src/wrap/initialization.jl index e5cdb494..5c3edf63 100644 --- a/generator/src/wrap/initialization.jl +++ b/generator/src/wrap/initialization.jl @@ -1,5 +1,5 @@ function retrieve_length(spec) - chain = length_chain(spec, spec.len) + chain = length_chain(spec.parent, spec.len, api.structs) @match length(chain) begin 1 => vk_call(first(chain)) GuardBy(>(1)) => diff --git a/generator/src/wrap/parent.jl b/generator/src/wrap/parent.jl index bfddcbc1..ea016976 100644 --- a/generator/src/wrap/parent.jl +++ b/generator/src/wrap/parent.jl @@ -40,14 +40,14 @@ assign_parent(::Symbol) = nothing assign_parent(parent_ex::Expr) = :($(assigned_parent_symbol(parent_ex)) = $parent_ex) function parent_handles(spec::SpecStruct) - filter(x -> x.type ∈ spec_handles.name, children(spec)) + filter(x -> in(x.type, api.handles.name), spec) end """ These 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.". """ is_consumed(spec::SpecHandle) = name(spec) ∈ (:VkShaderModule, :VkPipelineCache, :VkValidationCacheEXT) -is_consumed(name::Symbol) = is_consumed(handle_by_name(name)) +is_consumed(name::Symbol) = is_consumed(api.handles[name]) is_consumed(spec::Union{SpecFuncParam,SpecStructMember}) = is_consumed(spec.type) function Parent(def::HandleDefinition) @@ -56,7 +56,7 @@ function Parent(def::HandleDefinition) :name => :parent, :short => true, :args => [:($(wrap_identifier(def.spec))::$(name(def)))], - :body => :($(wrap_identifier(def.spec)).$(wrap_identifier(parent_spec(def.spec)))), + :body => :($(wrap_identifier(def.spec)).$(wrap_identifier(api.handles[def.spec.parent]))), ) Parent(def, p) end diff --git a/generator/src/wrap/return.jl b/generator/src/wrap/return.jl index 2871ee03..82c9807d 100644 --- a/generator/src/wrap/return.jl +++ b/generator/src/wrap/return.jl @@ -4,11 +4,11 @@ wrap_return(ex, type, jtype, next_types = nothing) = @match t = type begin GuardBy(is_opaque_pointer) => ex # Call handle constructor. - GuardBy(in(spec_handles.name)) => :($(remove_vk_prefix(t))($ex)) + GuardBy(in(api.handles.name)) => :($(remove_vk_prefix(t))($ex)) # Don't change enumeration variables since they won't be wrapped under a new name - GuardBy(in(spec_enums.name)) => ex + GuardBy(in(api.enums.name)) => ex # Vulkan and idiomatic Julia types are the same (up to aliases). - if is_fn_ptr(type) || follow_constant(type) == jtype || innermost_type(type) ∈ spec_flags.name + if is_fn_ptr(type) || follow_constant(type, api.constants) == jtype || innermost_type(type) ∈ api.flags.name end => ex # Fall back to the from_vk function for conversion. _ => isnothing(next_types) ? :(from_vk($jtype, $ex)) : :(from_vk($jtype, $ex, $next_types)) @@ -30,7 +30,7 @@ They need to be converted by the wrapper to their wrapping type. function _wrap_implicit_return(return_param::SpecFuncParam, next_types = nothing; with_func_ptr = false) p = return_param @assert is_ptr(p.type) "Invalid core type for an implicit return. Expected $(p.type) <: Ptr" - pt = follow_alias(ptr_type(p.type)) + pt = follow_alias(ptr_type(p.type), api.aliases) ex = @match p begin # array pointer @@ -50,8 +50,8 @@ function _wrap_implicit_return(return_param::SpecFuncParam, next_types = nothing end @match p begin - if pt ∈ spec_handles.name - end => wrap_implicit_handle_return(parent_spec(return_param), handle_by_name(pt), ex, with_func_ptr) + if pt ∈ api.handles.name + end => wrap_implicit_handle_return(return_param.parent, api.handles[pt], ex, with_func_ptr) _ => ex end end @@ -81,11 +81,11 @@ end function wrap_implicit_handle_return(spec::SpecFunc, handle::SpecHandle, ex::Expr, with_func_ptr) destroy = spec.type ≠ FTYPE_QUERY - args = @match parent_spec(handle) begin + args = @match handle.parent begin ::Nothing => (handle, ex) - p::SpecHandle => @match spec.type begin - &FTYPE_CREATE || &FTYPE_ALLOCATE => (handle, ex, p, retrieve_parent_ex(p, create_func(spec))) - _ => (handle, ex, p, retrieve_parent_ex(p, spec)::Symbol) + name::Symbol && Do(parent = api.handles[name]) => @match spec.type begin + &FTYPE_CREATE || &FTYPE_ALLOCATE => (handle, ex, parent, retrieve_parent_ex(parent, api.constructors[spec])) + _ => (handle, ex, parent, retrieve_parent_ex(parent, spec)::Symbol) end end diff --git a/generator/src/wrap/structs.jl b/generator/src/wrap/structs.jl index 0fb07e71..864c36af 100644 --- a/generator/src/wrap/structs.jl +++ b/generator/src/wrap/structs.jl @@ -15,8 +15,8 @@ function StructDefinition{false}(spec::SpecStruct) end function Constructor(def::StructDefinition{false}) - spec = def.spec - cconverted_members = getindex(children(spec), findall(is_semantic_ptr, children(spec).type)) + (; spec) = def + cconverted_members = spec[findall(is_semantic_ptr, spec.members.type)] cconverted_ids = map(wrap_identifier, cconverted_members) p = Dict( :category => :function, @@ -32,13 +32,13 @@ function Constructor(def::StructDefinition{false}) )... ) deps = Any[$((cconverted_ids)...)] - vks = $(spec.name)($(map(vk_call, children(spec))...)) + vks = $(spec.name)($(map(vk_call, spec)...)) $(name(def))(vks, deps, $(wrap_identifier.(parent_handles(spec))...)) end else - p[:body] = :($(name(def))($(spec.name)($(map(vk_call, children(spec))...)), $(wrap_identifier.(parent_handles(spec))...))) + p[:body] = :($(name(def))($(spec.name)($(map(vk_call, spec)...)), $(wrap_identifier.(parent_handles(spec))...))) end - potential_args = filter(x -> x.type ≠ :VkStructureType, children(spec)) + potential_args = filter(x -> x.type ≠ :VkStructureType, spec) add_func_args!(p, spec, potential_args) Constructor(p, def, def.spec) end @@ -189,13 +189,13 @@ function embeds_sentinel(member::SpecStructMember) end @match member.type begin - GuardBy(in(spec_enums.name)) || GuardBy(in(spec_bitmasks.name)) || GuardBy(is_flag) => true + GuardBy(in(api.enums.name)) || GuardBy(in(api.bitmasks.name)) || GuardBy(is_flag) => true _ => false end end function StructureType(spec::SpecStruct) - stype = structure_types[spec.name] + stype = api.structure_types[spec.name] types = [spec.name, struct_name(spec.name), struct_name(spec.name, true)] ex = :(structure_type(@nospecialize(_::Union{$((:(Type{$T}) for T in types)...)})) = $stype) StructureType(spec, ex) diff --git a/generator/src/wrap/unions.jl b/generator/src/wrap/unions.jl index 5ad27754..b7433960 100644 --- a/generator/src/wrap/unions.jl +++ b/generator/src/wrap/unions.jl @@ -36,11 +36,11 @@ function constructors(def::StructDefinition{HL,SpecUnion}) where {HL} map(zip(spec.types, sig_types, spec.fields)) do (type, sig_type, field) var = wrap_identifier(field) - call = if type in spec_unions.name + call = if type in api.unions.name :($var.vks) - elseif HL && type in spec_structs.name + elseif HL && type in api.structs.name :(($(struct_name(type))($var)).vks) - elseif type in spec_structs.name + elseif type in api.structs.name :($var.vks) else var diff --git a/generator/test/codegen/aliases.jl b/generator/test/codegen/aliases.jl index 81f3ccce..c4ae8a4e 100644 --- a/generator/test/codegen/aliases.jl +++ b/generator/test/codegen/aliases.jl @@ -7,4 +7,4 @@ end test_alias(:vkCmdSetCullModeEXT, :vkCmdSetCullMode, :(const cmd_set_cull_mode_ext = cmd_set_cull_mode)) test_alias(:VK_RENDERING_RESUMING_BIT_KHR, :VK_RENDERING_RESUMING_BIT, :(const RENDERING_RESUMING_BIT_KHR = RENDERING_RESUMING_BIT)) test_alias(:VkPhysicalDeviceImageFormatInfo2KHR, :VkPhysicalDeviceImageFormatInfo2, :(const PhysicalDeviceImageFormatInfo2KHR = PhysicalDeviceImageFormatInfo2)) -end +end; diff --git a/generator/test/codegen/constants.jl b/generator/test/codegen/constants.jl index fa293c5a..d77c3b22 100644 --- a/generator/test/codegen/constants.jl +++ b/generator/test/codegen/constants.jl @@ -1,3 +1,3 @@ @testset "Constants" begin - test(ConstantDefinition, constant_by_name, :VK_SUBPASS_EXTERNAL, :(const SUBPASS_EXTERNAL = VK_SUBPASS_EXTERNAL)) -end + test_ex(ConstantDefinition(api.constants[:VK_SUBPASS_EXTERNAL]), :(const SUBPASS_EXTERNAL = VK_SUBPASS_EXTERNAL)) +end; diff --git a/generator/test/codegen/docs.jl b/generator/test/codegen/docs.jl index 9e1fef7d..06d738d4 100644 --- a/generator/test/codegen/docs.jl +++ b/generator/test/codegen/docs.jl @@ -2,7 +2,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc @testset "Generated documentation" begin @testset "Low-level structs" begin - test_doc(StructDefinition{false}(struct_by_name(:VkExtent2D)), + test_doc(StructDefinition{false}(api.structs[:VkExtent2D]), """ Intermediate wrapper for VkExtent2D. @@ -11,7 +11,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - Constructor(StructDefinition{false}(struct_by_name(:VkExtent2D))), + Constructor(StructDefinition{false}(api.structs[:VkExtent2D])), """ Arguments: - `width::UInt32` @@ -22,7 +22,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - Constructor(StructDefinition{false}(struct_by_name(:VkInstanceCreateInfo))), + Constructor(StructDefinition{false}(api.structs[:VkInstanceCreateInfo])), """ Arguments: - `enabled_layer_names::Vector{String}` @@ -36,7 +36,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - Constructor(StructDefinition{false}(struct_by_name(:VkSubmitInfo2))), + Constructor(StructDefinition{false}(api.structs[:VkSubmitInfo2])), """ Arguments: - `wait_semaphore_infos::Vector{_SemaphoreSubmitInfo}` @@ -51,7 +51,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc end @testset "High-level structs" begin - test_doc(StructDefinition{true}(struct_by_name(:VkInstanceCreateInfo)), + test_doc(StructDefinition{true}(api.structs[:VkInstanceCreateInfo]), """ High-level wrapper for VkInstanceCreateInfo. @@ -60,7 +60,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - Constructor(StructDefinition{true}(struct_by_name(:VkInstanceCreateInfo))), + Constructor(StructDefinition{true}(api.structs[:VkInstanceCreateInfo])), """ Arguments: - `enabled_layer_names::Vector{String}` @@ -74,7 +74,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - APIFunction(create_func(:vkCreateInstance), false), + APIFunction(api.constructors[:vkCreateInstance], false), """ Return codes: - `ERROR_OUT_OF_HOST_MEMORY` @@ -100,7 +100,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc @testset "API functions" begin @testset "Intermediate functions" begin test_doc( - APIFunction(func_by_name(:vkEnumerateInstanceExtensionProperties), false), + APIFunction(api.functions[:vkEnumerateInstanceExtensionProperties], false), """ Return codes: - `ERROR_OUT_OF_HOST_MEMORY` @@ -115,7 +115,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - APIFunction(func_by_name(:vkDestroyDevice), false), + APIFunction(api.functions[:vkDestroyDevice], false), """ Arguments: - `device::Device` (externsync) @@ -126,7 +126,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - APIFunction(func_by_name(:vkGetPipelineCacheData), false), + APIFunction(api.functions[:vkGetPipelineCacheData], false), """ Return codes: - `ERROR_OUT_OF_HOST_MEMORY` @@ -144,7 +144,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - APIFunction(func_by_name(:vkWriteAccelerationStructuresPropertiesKHR), false), + APIFunction(api.functions[:vkWriteAccelerationStructuresPropertiesKHR], false), """ Extension: VK\\\\_KHR\\\\_acceleration\\\\_structure @@ -165,7 +165,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - APIFunction(func_by_name(:vkEnumerateInstanceLayerProperties), false), + APIFunction(api.functions[:vkEnumerateInstanceLayerProperties], false), """ Return codes: - `ERROR_OUT_OF_HOST_MEMORY` @@ -178,7 +178,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc @testset "High-level functions" begin test_doc( - VulkanGen.promote_hl(APIFunction(func_by_name(:vkWriteAccelerationStructuresPropertiesKHR), false)), + VulkanGen.promote_hl(APIFunction(api.functions[:vkWriteAccelerationStructuresPropertiesKHR], false)), """ Extension: VK\\\\_KHR\\\\_acceleration\\\\_structure @@ -199,7 +199,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - VulkanGen.promote_hl(APIFunction(func_by_name(:vkEnumerateInstanceLayerProperties), false)), + VulkanGen.promote_hl(APIFunction(api.functions[:vkEnumerateInstanceLayerProperties], false)), """ Return codes: - `ERROR_OUT_OF_HOST_MEMORY` @@ -210,7 +210,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - VulkanGen.promote_hl(APIFunction(func_by_name(:vkAcquireNextImageKHR), false)), + VulkanGen.promote_hl(APIFunction(api.functions[:vkAcquireNextImageKHR], false)), """ Extension: VK\\\\_KHR\\\\_swapchain @@ -238,7 +238,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc ) test_doc( - VulkanGen.promote_hl(APIFunction(func_by_name(:vkGetDescriptorSetLayoutSupport), false)), + VulkanGen.promote_hl(APIFunction(api.functions[:vkGetDescriptorSetLayoutSupport], false)), """ Arguments: - `device::Device` @@ -252,7 +252,7 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc end @testset "Handles" begin test_doc( - Constructor(HandleDefinition(handle_by_name(:VkInstance)), VulkanGen.promote_hl(APIFunction(create_func(:vkCreateInstance), false))), + Constructor(HandleDefinition(api.handles[:VkInstance]), VulkanGen.promote_hl(APIFunction(api.constructors[:vkCreateInstance], false))), """ Arguments: - `enabled_layer_names::Vector{String}` @@ -266,4 +266,4 @@ test_doc(obj, doc) = @test Documented(obj).p[:docstring] == doc """ ) end -end +end; diff --git a/generator/test/codegen/enums/bitmasks.jl b/generator/test/codegen/enums/bitmasks.jl index 944ea3cd..0a6c37f4 100644 --- a/generator/test/codegen/enums/bitmasks.jl +++ b/generator/test/codegen/enums/bitmasks.jl @@ -1,5 +1,5 @@ @testset "Bitmask flags" begin - test(BitmaskDefinition, bitmask_by_name, :VkQueryPipelineStatisticFlagBits, :( + test_ex(BitmaskDefinition(api.bitmasks[:VkQueryPipelineStatisticFlagBits]), :( @bitmask QueryPipelineStatisticFlag::UInt32 begin QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT = 1 QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT = 2 @@ -15,13 +15,13 @@ end )) - test(BitmaskDefinition, bitmask_by_name, :VkSparseMemoryBindFlagBits, :( + test_ex(BitmaskDefinition(api.bitmasks[:VkSparseMemoryBindFlagBits]), :( @bitmask SparseMemoryBindFlag::UInt32 begin SPARSE_MEMORY_BIND_METADATA_BIT = 1 end )) - test(BitmaskDefinition, bitmask_by_name, :VkShaderStageFlagBits, :( + test_ex(BitmaskDefinition(api.bitmasks[:VkShaderStageFlagBits]), :( @bitmask ShaderStageFlag::UInt32 begin SHADER_STAGE_VERTEX_BIT = 1 SHADER_STAGE_TESSELLATION_CONTROL_BIT = 2 @@ -43,7 +43,7 @@ end )) - test(BitmaskDefinition, bitmask_by_name, :VkCullModeFlagBits, :( + test_ex(BitmaskDefinition(api.bitmasks[:VkCullModeFlagBits]), :( @bitmask CullModeFlag::UInt32 begin CULL_MODE_FRONT_BIT = 1 CULL_MODE_BACK_BIT = 2 @@ -51,4 +51,4 @@ CULL_MODE_FRONT_AND_BACK = 3 end )) -end +end; diff --git a/generator/test/codegen/enums/enums.jl b/generator/test/codegen/enums/enums.jl index 35df5766..ca8c1639 100644 --- a/generator/test/codegen/enums/enums.jl +++ b/generator/test/codegen/enums/enums.jl @@ -1,5 +1,5 @@ @testset "Enums" begin - test(EnumDefinition, enum_by_name, :VkAttachmentLoadOp, :( + test_ex(EnumDefinition(api.enums[:VkAttachmentLoadOp]), :( @cenum AttachmentLoadOp::UInt32 begin ATTACHMENT_LOAD_OP_LOAD = 0 ATTACHMENT_LOAD_OP_CLEAR = 1 @@ -8,7 +8,7 @@ end )) - test(EnumDefinition, enum_by_name, :VkResult, :( + test_ex(EnumDefinition(api.enums[:VkResult]), :( @cenum Result::Int32 begin SUCCESS = 0 NOT_READY = 1 @@ -51,9 +51,9 @@ end )) - test(EnumDefinition, enum_by_name, :VkPipelineCacheHeaderVersion, :( + test_ex(EnumDefinition(api.enums[:VkPipelineCacheHeaderVersion]), :( @cenum PipelineCacheHeaderVersion::UInt32 begin PIPELINE_CACHE_HEADER_VERSION_ONE = 1 end )) -end +end; diff --git a/generator/test/codegen/functions/high_level.jl b/generator/test/codegen/functions/high_level.jl index 494672b2..a1644b2f 100644 --- a/generator/test/codegen/functions/high_level.jl +++ b/generator/test/codegen/functions/high_level.jl @@ -1,25 +1,25 @@ @testset "High-level functions" begin - test_ex(VulkanGen.promote_hl(APIFunction(func_by_name(:vkEnumeratePhysicalDevices), false)), :( + test_ex(VulkanGen.promote_hl(APIFunction(api.functions[:vkEnumeratePhysicalDevices], false)), :( function enumerate_physical_devices(instance)::ResultTypes.Result{Vector{PhysicalDevice}, VulkanError} val = @propagate_errors(_enumerate_physical_devices(instance)) val end )) - test_ex(VulkanGen.promote_hl(APIFunction(func_by_name(:vkGetPerformanceParameterINTEL), false)), :( + test_ex(VulkanGen.promote_hl(APIFunction(api.functions[:vkGetPerformanceParameterINTEL], false)), :( function get_performance_parameter_intel(device, parameter::PerformanceParameterTypeINTEL)::ResultTypes.Result{PerformanceValueINTEL, VulkanError} val = @propagate_errors _get_performance_parameter_intel(device, parameter) PerformanceValueINTEL(val) end )) - test_ex(VulkanGen.promote_hl(APIFunction(func_by_name(:vkDestroyInstance), false)), :( + test_ex(VulkanGen.promote_hl(APIFunction(api.functions[:vkDestroyInstance], false)), :( function destroy_instance(instance; allocator = C_NULL) _destroy_instance(instance; allocator) end )) - test_ex(VulkanGen.promote_hl(APIFunction(func_by_name(:vkGetPhysicalDeviceProperties2), false)), :( + test_ex(VulkanGen.promote_hl(APIFunction(api.functions[:vkGetPhysicalDeviceProperties2], false)), :( function get_physical_device_properties_2(physical_device, next_types::Type...) next_types_hl = next_types next_types = intermediate_type.(next_types) @@ -27,7 +27,7 @@ end )) - test_ex(VulkanGen.promote_hl(APIFunction(func_by_name(:vkGetPhysicalDeviceImageFormatProperties2), false)), :( + test_ex(VulkanGen.promote_hl(APIFunction(api.functions[:vkGetPhysicalDeviceImageFormatProperties2], false)), :( function get_physical_device_image_format_properties_2(physical_device, image_format_info::PhysicalDeviceImageFormatInfo2, next_types::Type...)::ResultTypes.Result{ImageFormatProperties2, VulkanError} next_types_hl = next_types next_types = intermediate_type.(next_types) @@ -36,10 +36,10 @@ end )) - test_ex(VulkanGen.promote_hl(APIFunction(create_func(:vkCreateInstance), false)), :( + test_ex(VulkanGen.promote_hl(APIFunction(api.constructors[:vkCreateInstance], false)), :( function create_instance(enabled_layer_names::AbstractArray, enabled_extension_names::AbstractArray; allocator = C_NULL, next = C_NULL, flags = 0, application_info = C_NULL)::ResultTypes.Result{Instance, VulkanError} val = @propagate_errors(_create_instance(enabled_layer_names, enabled_extension_names; allocator, next, flags, application_info)) val end )) -end +end; diff --git a/generator/test/codegen/functions/low_level.jl b/generator/test/codegen/functions/low_level.jl index a32487ee..9bfaa828 100644 --- a/generator/test/codegen/functions/low_level.jl +++ b/generator/test/codegen/functions/low_level.jl @@ -1,5 +1,5 @@ @testset "API functions" begin - test_ex(APIFunction(func_by_name(:vkEnumeratePhysicalDevices), false), :( + test_ex(APIFunction(api.functions[:vkEnumeratePhysicalDevices], false), :( function _enumerate_physical_devices(instance)::ResultTypes.Result{Vector{PhysicalDevice},VulkanError} pPhysicalDeviceCount = Ref{UInt32}() @repeat_while_incomplete begin @@ -11,7 +11,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkGetPhysicalDeviceProperties), false), :( + test_ex(APIFunction(api.functions[:vkGetPhysicalDeviceProperties], false), :( function _get_physical_device_properties(physical_device)::_PhysicalDeviceProperties pProperties = Ref{VkPhysicalDeviceProperties}() @dispatch instance(physical_device) vkGetPhysicalDeviceProperties(physical_device, pProperties) @@ -19,7 +19,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkEnumerateInstanceVersion), false), :( + test_ex(APIFunction(api.functions[:vkEnumerateInstanceVersion], false), :( function _enumerate_instance_version()::ResultTypes.Result{VersionNumber,VulkanError} pApiVersion = Ref{UInt32}() @check @dispatch nothing vkEnumerateInstanceVersion(pApiVersion) @@ -27,7 +27,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkEnumerateInstanceExtensionProperties), false), :( + test_ex(APIFunction(api.functions[:vkEnumerateInstanceExtensionProperties], false), :( function _enumerate_instance_extension_properties(; layer_name = C_NULL)::ResultTypes.Result{Vector{_ExtensionProperties},VulkanError} pPropertyCount = Ref{UInt32}() @repeat_while_incomplete begin @@ -39,7 +39,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkGetGeneratedCommandsMemoryRequirementsNV), false), :( + test_ex(APIFunction(api.functions[:vkGetGeneratedCommandsMemoryRequirementsNV], false), :( function _get_generated_commands_memory_requirements_nv(device, info::_GeneratedCommandsMemoryRequirementsInfoNV, next_types::Type...)::_MemoryRequirements2 memory_requirements = initialize(_MemoryRequirements2, next_types...) pMemoryRequirements = Ref(Base.unsafe_convert(VkMemoryRequirements2, memory_requirements)) @@ -50,10 +50,10 @@ end )) - test_ex(APIFunction(func_by_name(:vkGetInstanceProcAddr), false), :(_get_instance_proc_addr(name::AbstractString; instance = C_NULL)::FunctionPtr = vkGetInstanceProcAddr(instance, name))) - test_ex(APIFunction(func_by_name(:vkGetInstanceProcAddr), true), :(_get_instance_proc_addr(name::AbstractString, fptr::FunctionPtr; instance = C_NULL)::FunctionPtr = vkGetInstanceProcAddr(instance, name, fptr))) + test_ex(APIFunction(api.functions[:vkGetInstanceProcAddr], false), :(_get_instance_proc_addr(name::AbstractString; instance = C_NULL)::FunctionPtr = vkGetInstanceProcAddr(instance, name))) + test_ex(APIFunction(api.functions[:vkGetInstanceProcAddr], true), :(_get_instance_proc_addr(name::AbstractString, fptr::FunctionPtr; instance = C_NULL)::FunctionPtr = vkGetInstanceProcAddr(instance, name, fptr))) - test_ex(APIFunction(func_by_name(:vkGetPhysicalDeviceSurfacePresentModesKHR), false), :( + test_ex(APIFunction(api.functions[:vkGetPhysicalDeviceSurfacePresentModesKHR], false), :( function _get_physical_device_surface_present_modes_khr(physical_device; surface = C_NULL)::ResultTypes.Result{Vector{PresentModeKHR},VulkanError} pPresentModeCount = Ref{UInt32}() @repeat_while_incomplete begin @@ -65,7 +65,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkGetRandROutputDisplayEXT), false), :( + test_ex(APIFunction(api.functions[:vkGetRandROutputDisplayEXT], false), :( function _get_rand_r_output_display_ext(physical_device, dpy::Ptr{vk.Display}, rr_output::vk.RROutput)::ResultTypes.Result{DisplayKHR,VulkanError} pDisplay = Ref{VkDisplayKHR}() @check @dispatch instance(physical_device) vkGetRandROutputDisplayEXT(physical_device, dpy, rr_output, pDisplay) @@ -73,7 +73,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkRegisterDeviceEventEXT), false), :( + test_ex(APIFunction(api.functions[:vkRegisterDeviceEventEXT], false), :( function _register_device_event_ext(device, device_event_info::_DeviceEventInfoEXT; allocator = C_NULL)::ResultTypes.Result{Fence,VulkanError} pFence = Ref{VkFence}() @check @dispatch device vkRegisterDeviceEventEXT(device, device_event_info, allocator, pFence) @@ -81,7 +81,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkCreateInstance), false), :( + test_ex(APIFunction(api.functions[:vkCreateInstance], false), :( function _create_instance(create_info::_InstanceCreateInfo; allocator = C_NULL)::ResultTypes.Result{Instance,VulkanError} pInstance = Ref{VkInstance}() @check @dispatch nothing vkCreateInstance(create_info, allocator, pInstance) @@ -89,7 +89,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkCreateDebugReportCallbackEXT), true), :( + test_ex(APIFunction(api.functions[:vkCreateDebugReportCallbackEXT], true), :( function _create_debug_report_callback_ext(instance, create_info::_DebugReportCallbackCreateInfoEXT, fptr_create::FunctionPtr, fptr_destroy::FunctionPtr; allocator = C_NULL)::ResultTypes.Result{DebugReportCallbackEXT,VulkanError} pCallback = Ref{VkDebugReportCallbackEXT}() @check vkCreateDebugReportCallbackEXT(instance, create_info, allocator, pCallback, fptr_create) @@ -97,7 +97,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkCreateGraphicsPipelines), false), :( + test_ex(APIFunction(api.functions[:vkCreateGraphicsPipelines], false), :( function _create_graphics_pipelines(device, create_infos::AbstractArray; pipeline_cache = C_NULL, allocator = C_NULL)::ResultTypes.Result{Tuple{Vector{Pipeline},Result},VulkanError} pPipelines = Vector{VkPipeline}(undef, pointer_length(create_infos)) @check @dispatch device vkCreateGraphicsPipelines(device, pipeline_cache, pointer_length(create_infos), create_infos, allocator, pPipelines) @@ -105,7 +105,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkAllocateDescriptorSets), false), :( + test_ex(APIFunction(api.functions[:vkAllocateDescriptorSets], false), :( function _allocate_descriptor_sets(device, allocate_info::_DescriptorSetAllocateInfo)::ResultTypes.Result{Vector{DescriptorSet},VulkanError} pDescriptorSets = Vector{VkDescriptorSet}(undef, allocate_info.vks.descriptorSetCount) @check @dispatch device vkAllocateDescriptorSets(device, allocate_info, pDescriptorSets) @@ -113,11 +113,11 @@ end )) - test_ex(APIFunction(func_by_name(:vkMergePipelineCaches), false), :( + test_ex(APIFunction(api.functions[:vkMergePipelineCaches], false), :( _merge_pipeline_caches(device, dst_cache, src_caches::AbstractArray)::ResultTypes.Result{Result,VulkanError} = @check(@dispatch(device, vkMergePipelineCaches(device, dst_cache, pointer_length(src_caches), src_caches))) )) - test_ex(APIFunction(func_by_name(:vkGetFenceFdKHR), false), :( + test_ex(APIFunction(api.functions[:vkGetFenceFdKHR], false), :( function _get_fence_fd_khr(device, get_fd_info::_FenceGetFdInfoKHR)::ResultTypes.Result{Int,VulkanError} pFd = Ref{Int}() @check @dispatch device vkGetFenceFdKHR(device, get_fd_info, pFd) @@ -125,7 +125,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkGetDeviceGroupPeerMemoryFeatures), false), :( + test_ex(APIFunction(api.functions[:vkGetDeviceGroupPeerMemoryFeatures], false), :( function _get_device_group_peer_memory_features(device, heap_index::Integer, local_device_index::Integer, remote_device_index::Integer)::PeerMemoryFeatureFlag pPeerMemoryFeatures = Ref{VkPeerMemoryFeatureFlags}() @dispatch device vkGetDeviceGroupPeerMemoryFeatures(device, heap_index, local_device_index, remote_device_index, pPeerMemoryFeatures) @@ -133,23 +133,23 @@ end )) - test_ex(APIFunction(func_by_name(:vkUpdateDescriptorSets), false), :( + test_ex(APIFunction(api.functions[:vkUpdateDescriptorSets], false), :( _update_descriptor_sets(device, descriptor_writes::AbstractArray, descriptor_copies::AbstractArray)::Cvoid = @dispatch device vkUpdateDescriptorSets(device, pointer_length(descriptor_writes), descriptor_writes, pointer_length(descriptor_copies), descriptor_copies) )) - test_ex(APIFunction(func_by_name(:vkCmdSetViewport), false), :( + test_ex(APIFunction(api.functions[:vkCmdSetViewport], false), :( _cmd_set_viewport(command_buffer, viewports::AbstractArray)::Cvoid = @dispatch device(command_buffer) vkCmdSetViewport(command_buffer, 0, pointer_length(viewports), viewports) )) - test_ex(APIFunction(func_by_name(:vkCmdSetLineWidth), false), :( + test_ex(APIFunction(api.functions[:vkCmdSetLineWidth], false), :( _cmd_set_line_width(command_buffer, line_width::Real)::Cvoid = @dispatch device(command_buffer) vkCmdSetLineWidth(command_buffer, line_width) )) - test_ex(APIFunction(func_by_name(:vkDestroyInstance), false), :( + test_ex(APIFunction(api.functions[:vkDestroyInstance], false), :( _destroy_instance(instance; allocator = C_NULL)::Cvoid = @dispatch instance vkDestroyInstance(instance, allocator) )) - test_ex(APIFunction(func_by_name(:vkMapMemory), false), :( + test_ex(APIFunction(api.functions[:vkMapMemory], false), :( function _map_memory(device, memory, offset::Integer, size::Integer; flags = 0)::ResultTypes.Result{Ptr{Cvoid},VulkanError} ppData = Ref{Ptr{Cvoid}}() @check @dispatch device vkMapMemory(device, memory, offset, size, flags, ppData) @@ -157,7 +157,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR), false), :( + test_ex(APIFunction(api.functions[:vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR], false), :( function _enumerate_physical_device_queue_family_performance_query_counters_khr(physical_device, queue_family_index::Integer)::ResultTypes.Result{Tuple{Vector{_PerformanceCounterKHR},Vector{_PerformanceCounterDescriptionKHR}},VulkanError} pCounterCount = Ref{UInt32}() @repeat_while_incomplete begin @@ -170,7 +170,7 @@ end )) - test_ex(APIFunction(func_by_name(:vkGetPipelineCacheData), false), :( + test_ex(APIFunction(api.functions[:vkGetPipelineCacheData], false), :( function _get_pipeline_cache_data(device, pipeline_cache)::ResultTypes.Result{Tuple{UInt,Ptr{Cvoid}},VulkanError} pDataSize = Ref{UInt}() @repeat_while_incomplete begin @@ -185,19 +185,19 @@ end )) - test_ex(APIFunction(func_by_name(:vkWriteAccelerationStructuresPropertiesKHR), false), :( + test_ex(APIFunction(api.functions[:vkWriteAccelerationStructuresPropertiesKHR], false), :( _write_acceleration_structures_properties_khr(device, acceleration_structures::AbstractArray, query_type::QueryType, data_size::Integer, data::Ptr{Cvoid}, stride::Integer)::ResultTypes.Result{Result,VulkanError} = @check @dispatch device vkWriteAccelerationStructuresPropertiesKHR(device, pointer_length(acceleration_structures), acceleration_structures, query_type, data_size, data, stride) )) - test_ex(APIFunction(func_by_name(:vkGetQueryPoolResults), false), :( + test_ex(APIFunction(api.functions[:vkGetQueryPoolResults], false), :( _get_query_pool_results(device, query_pool, first_query::Integer, query_count::Integer, data_size::Integer, data::Ptr{Cvoid}, stride::Integer; flags = 0)::ResultTypes.Result{Result,VulkanError} = @check @dispatch device vkGetQueryPoolResults(device, query_pool, first_query, query_count, data_size, data, stride, flags) )) - test_ex(APIFunction(func_by_name(:vkGetFenceStatus), false), :( + test_ex(APIFunction(api.functions[:vkGetFenceStatus], false), :( _get_fence_status(device, fence)::ResultTypes.Result{Result,VulkanError} = @check(@dispatch(device, vkGetFenceStatus(device, fence))) )) - test_ex(APIFunction(func_by_name(:vkGetSwapchainImagesKHR), false), :( + test_ex(APIFunction(api.functions[:vkGetSwapchainImagesKHR], false), :( function _get_swapchain_images_khr(device, swapchain)::ResultTypes.Result{Vector{Image},VulkanError} pSwapchainImageCount = Ref{UInt32}() @repeat_while_incomplete begin @@ -210,13 +210,13 @@ )) @testset "Automatic reconstruction of create infos" begin - test_ex(APIFunction(create_func(:vkCreateInstance), false), :( + test_ex(APIFunction(api.constructors[:vkCreateInstance], false), :( _create_instance(enabled_layer_names::AbstractArray, enabled_extension_names::AbstractArray; allocator = C_NULL, next = C_NULL, flags = 0, application_info = C_NULL) = _create_instance(_InstanceCreateInfo(enabled_layer_names, enabled_extension_names; next, flags, application_info); allocator) )) - test_ex(APIFunction(create_func(:vkCreateDebugReportCallbackEXT), true), :( + test_ex(APIFunction(api.constructors[:vkCreateDebugReportCallbackEXT], true), :( _create_debug_report_callback_ext(instance, pfn_callback::FunctionPtr, fptr_create::FunctionPtr, fptr_destroy::FunctionPtr; allocator = C_NULL, next = C_NULL, flags = 0, user_data = C_NULL) = _create_debug_report_callback_ext(instance, _DebugReportCallbackCreateInfoEXT(pfn_callback; next, flags, user_data), fptr_create, fptr_destroy; allocator) ), ) end -end +end; diff --git a/generator/test/codegen/functions/overloads.jl b/generator/test/codegen/functions/overloads.jl index 8d26f2a7..33cab95a 100644 --- a/generator/test/codegen/functions/overloads.jl +++ b/generator/test/codegen/functions/overloads.jl @@ -1,11 +1,11 @@ @testset "Overloads" begin @testset "Parent navigation" begin - test_ex(Parent(HandleDefinition(handle_by_name(:VkDevice))), :( + test_ex(Parent(HandleDefinition(api.handles[:VkDevice])), :( parent(device::Device) = device.physical_device )) - test_ex(Parent(HandleDefinition(handle_by_name(:VkSurfaceKHR))), :( + test_ex(Parent(HandleDefinition(api.handles[:VkSurfaceKHR])), :( parent(surface::SurfaceKHR) = surface.instance )) end -end +end; diff --git a/generator/test/codegen/handles.jl b/generator/test/codegen/handles.jl index 8ce1d50e..54e9330a 100644 --- a/generator/test/codegen/handles.jl +++ b/generator/test/codegen/handles.jl @@ -1,6 +1,6 @@ @testset "Handles" begin @testset "Definitions" begin - test(HandleDefinition, handle_by_name, :VkInstance, :( + test_ex(HandleDefinition(api.handles[:VkInstance]), :( mutable struct Instance <: Handle vks::VkInstance refcount::RefCounter @@ -9,7 +9,7 @@ end )) - test(HandleDefinition, handle_by_name, :VkPhysicalDevice, :( + test_ex(HandleDefinition(api.handles[:VkPhysicalDevice]), :( mutable struct PhysicalDevice <: Handle vks::VkPhysicalDevice instance::Instance @@ -19,7 +19,7 @@ end )) - test(HandleDefinition, handle_by_name, :VkDevice, :( + test_ex(HandleDefinition(api.handles[:VkDevice]), :( mutable struct Device <: Handle vks::VkDevice physical_device::PhysicalDevice @@ -33,8 +33,8 @@ @testset "Constructors" begin test_ex( Constructor( - HandleDefinition(handle_by_name(:VkInstance)), - APIFunction(create_func(:vkCreateInstance), false), + HandleDefinition(api.handles[:VkInstance]), + APIFunction(api.constructors[:vkCreateInstance], false), ), :( Instance(enabled_layer_names::AbstractArray, enabled_extension_names::AbstractArray; allocator = C_NULL, next=C_NULL, flags=0, application_info=C_NULL) = unwrap(_create_instance(enabled_layer_names, enabled_extension_names; allocator, next, flags, application_info)) @@ -43,8 +43,8 @@ test_ex( Constructor( - HandleDefinition(handle_by_name(:VkInstance)), - APIFunction(func_by_name(:vkCreateInstance), false), + HandleDefinition(api.handles[:VkInstance]), + APIFunction(api.functions[:vkCreateInstance], false), ), :( Instance(create_info::_InstanceCreateInfo; allocator = C_NULL) = unwrap(_create_instance(create_info; allocator)) @@ -53,8 +53,8 @@ test_ex( Constructor( - HandleDefinition(handle_by_name(:VkInstance)), - VulkanGen.promote_hl(APIFunction(func_by_name(:vkCreateInstance), false)), + HandleDefinition(api.handles[:VkInstance]), + VulkanGen.promote_hl(APIFunction(api.functions[:vkCreateInstance], false)), ), :( Instance(create_info::InstanceCreateInfo; allocator = C_NULL) = unwrap(create_instance(create_info; allocator)) @@ -63,8 +63,8 @@ test_ex( Constructor( - HandleDefinition(handle_by_name(:VkDebugReportCallbackEXT)), - APIFunction(create_func(:vkCreateDebugReportCallbackEXT), true), + HandleDefinition(api.handles[:VkDebugReportCallbackEXT]), + APIFunction(api.constructors[:vkCreateDebugReportCallbackEXT], true), ), :( DebugReportCallbackEXT(instance, pfn_callback::FunctionPtr, fptr_create::FunctionPtr, fptr_destroy::FunctionPtr; allocator = C_NULL, next = C_NULL, flags = 0, user_data = C_NULL) = unwrap(_create_debug_report_callback_ext(instance, pfn_callback, fptr_create, fptr_destroy; allocator, next, flags, user_data)) @@ -73,8 +73,8 @@ test_ex( Constructor( - HandleDefinition(handle_by_name(:VkDeferredOperationKHR)), - APIFunction(func_by_name(:vkCreateDeferredOperationKHR), false), + HandleDefinition(api.handles[:VkDeferredOperationKHR]), + APIFunction(api.functions[:vkCreateDeferredOperationKHR], false), ), :( DeferredOperationKHR(device; allocator = C_NULL) = unwrap(_create_deferred_operation_khr(device; allocator)) @@ -83,8 +83,8 @@ test_ex( Constructor( - HandleDefinition(handle_by_name(:VkRenderPass)), - promote_hl(APIFunction(create_func(:vkCreateRenderPass), false)), + HandleDefinition(api.handles[:VkRenderPass]), + promote_hl(APIFunction(api.constructors[:vkCreateRenderPass], false)), ), :( RenderPass(device, attachments::AbstractArray, subpasses::AbstractArray, dependencies::AbstractArray; allocator = C_NULL, next = C_NULL, flags = 0) = unwrap(create_render_pass(device, attachments, subpasses, dependencies; allocator, next, flags)) @@ -93,12 +93,12 @@ test_ex( Constructor( - HandleDefinition(handle_by_name(:VkRenderPass)), - promote_hl(APIFunction(create_func(:vkCreateRenderPass2), false)), + HandleDefinition(api.handles[:VkRenderPass]), + promote_hl(APIFunction(api.constructors[:vkCreateRenderPass2], false)), ), :( RenderPass(device, attachments::AbstractArray, subpasses::AbstractArray, dependencies::AbstractArray, correlated_view_masks::AbstractArray; allocator = C_NULL, next = C_NULL, flags = 0) = unwrap(create_render_pass_2(device, attachments, subpasses, dependencies, correlated_view_masks; allocator, next, flags)) ), ) end -end +end; diff --git a/generator/test/codegen/structs/high_level.jl b/generator/test/codegen/structs/high_level.jl index acb30cbb..283793ce 100644 --- a/generator/test/codegen/structs/high_level.jl +++ b/generator/test/codegen/structs/high_level.jl @@ -1,6 +1,6 @@ @testset "High-level wrapper" begin @testset "Generated structs" begin - test(StructDefinition{true}, struct_by_name, :VkPhysicalDeviceProperties, :( + test_ex(StructDefinition{true}(api.structs[:VkPhysicalDeviceProperties]), :( @struct_hash_equal struct PhysicalDeviceProperties <: HighLevelStruct api_version::VersionNumber driver_version::VersionNumber @@ -14,14 +14,14 @@ end )) - test(StructDefinition{true}, struct_by_name, :VkExternalBufferProperties, :( + test_ex(StructDefinition{true}(api.structs[:VkExternalBufferProperties]), :( @struct_hash_equal struct ExternalBufferProperties <: HighLevelStruct next::Any external_memory_properties::ExternalMemoryProperties end )) - test(StructDefinition{true}, struct_by_name, :VkPipelineExecutableInternalRepresentationKHR, :( + test_ex(StructDefinition{true}(api.structs[:VkPipelineExecutableInternalRepresentationKHR]), :( @struct_hash_equal struct PipelineExecutableInternalRepresentationKHR <: HighLevelStruct next::Any name::String @@ -32,7 +32,7 @@ end )) - test(StructDefinition{true}, struct_by_name, :VkApplicationInfo, :( + test_ex(StructDefinition{true}(api.structs[:VkApplicationInfo]), :( @struct_hash_equal struct ApplicationInfo <: HighLevelStruct next::Any application_name::String @@ -43,7 +43,7 @@ end )) - test(StructDefinition{true}, struct_by_name, :VkInstanceCreateInfo, :( + test_ex(StructDefinition{true}(api.structs[:VkInstanceCreateInfo]), :( @struct_hash_equal struct InstanceCreateInfo <: HighLevelStruct next::Any flags::UInt32 @@ -53,7 +53,7 @@ end )) - test(StructDefinition{true}, struct_by_name, :VkXcbSurfaceCreateInfoKHR, :( + test_ex(StructDefinition{true}(api.structs[:VkXcbSurfaceCreateInfoKHR]), :( @struct_hash_equal struct XcbSurfaceCreateInfoKHR <: HighLevelStruct next::Any flags::UInt32 @@ -66,8 +66,8 @@ @testset "Conversion to low-level structs" begin test_ex( Constructor( - StructDefinition{false}(struct_by_name(:VkApplicationInfo)), - StructDefinition{true}(struct_by_name(:VkApplicationInfo)), + StructDefinition{false}(api.structs[:VkApplicationInfo]), + StructDefinition{true}(api.structs[:VkApplicationInfo]), ), :( _ApplicationInfo(x::ApplicationInfo) = _ApplicationInfo(x.application_version, x.engine_version, x.api_version; x.next, x.application_name, x.engine_name) @@ -75,8 +75,8 @@ ) test_ex( Constructor( - StructDefinition{false}(struct_by_name(:VkInstanceCreateInfo)), - StructDefinition{true}(struct_by_name(:VkInstanceCreateInfo)), + StructDefinition{false}(api.structs[:VkInstanceCreateInfo]), + StructDefinition{true}(api.structs[:VkInstanceCreateInfo]), ), :( _InstanceCreateInfo(x::InstanceCreateInfo) = _InstanceCreateInfo(x.enabled_layer_names, x.enabled_extension_names; x.next, x.flags, application_info = convert_nonnull(_ApplicationInfo, x.application_info)) @@ -84,8 +84,8 @@ ) test_ex( Constructor( - StructDefinition{false}(struct_by_name(:VkRenderingAttachmentInfo)), - StructDefinition{true}(struct_by_name(:VkRenderingAttachmentInfo)), + StructDefinition{false}(api.structs[:VkRenderingAttachmentInfo]), + StructDefinition{true}(api.structs[:VkRenderingAttachmentInfo]), ), :( _RenderingAttachmentInfo(x::RenderingAttachmentInfo) = _RenderingAttachmentInfo(x.image_layout, x.resolve_image_layout, x.load_op, x.store_op, convert_nonnull(_ClearValue, x.clear_value); x.next, x.image_view, x.resolve_mode, x.resolve_image_view) @@ -94,15 +94,15 @@ end @testset "Additional constructor" begin - test(Constructor, StructDefinition{true}(StructDefinition{false}(struct_by_name(:VkApplicationInfo))), :( + test_ex(Constructor(StructDefinition{true}(StructDefinition{false}(api.structs[:VkApplicationInfo]))), :( ApplicationInfo(application_version::VersionNumber, engine_version::VersionNumber, api_version::VersionNumber; next = C_NULL, application_name = "", engine_name = "") = ApplicationInfo(next, application_name, application_version, engine_name, engine_version, api_version) )) end @testset "`Core -> High-level constructors`" begin function test_constructor_core_to_hl(name, with_next_types, body) - spec = struct_by_name(name) - def = StructDefinition{true}(struct_by_name(name)) + spec = api.structs[name] + def = StructDefinition{true}(api.structs[name]) cons = Constructor(def, spec) expected = :($(VulkanGen.struct_name(name, true))(x::$name) = $body) with_next_types && push!(expected.args[1].args, :(next_types::Type...)) @@ -140,7 +140,7 @@ @testset "`Low-level -> High-level constructors`" begin function test_constructor_ll_to_hl(name, ex) - s = struct_by_name(name) + s = api.structs[name] def_hl = StructDefinition{true}(s) def_ll = StructDefinition{false}(s) c = Constructor(def_hl, def_ll) @@ -156,4 +156,4 @@ PhysicalDeviceFeatures(x::_PhysicalDeviceFeatures) = PhysicalDeviceFeatures(x.vks) )) end -end +end; diff --git a/generator/test/codegen/structs/low_level.jl b/generator/test/codegen/structs/low_level.jl index d8b29208..b7c243f9 100644 --- a/generator/test/codegen/structs/low_level.jl +++ b/generator/test/codegen/structs/low_level.jl @@ -1,36 +1,36 @@ @testset "Low-level" begin @testset "Definitions" begin - test(StructDefinition{false}, struct_by_name, :VkPhysicalDeviceProperties, :( + test_ex(StructDefinition{false}(api.structs[:VkPhysicalDeviceProperties]), :( struct _PhysicalDeviceProperties <: VulkanStruct{false} vks::VkPhysicalDeviceProperties end)) - test(StructDefinition{false}, struct_by_name, :VkApplicationInfo, :( + test_ex(StructDefinition{false}(api.structs[:VkApplicationInfo]), :( struct _ApplicationInfo <: VulkanStruct{true} vks::VkApplicationInfo deps::Vector{Any} end)) - test(StructDefinition{false}, struct_by_name, :VkExtent2D, :( + test_ex(StructDefinition{false}(api.structs[:VkExtent2D]), :( struct _Extent2D <: VulkanStruct{false} vks::VkExtent2D end)) - test(StructDefinition{false}, struct_by_name, :VkExternalBufferProperties, :( + test_ex(StructDefinition{false}(api.structs[:VkExternalBufferProperties]), :( struct _ExternalBufferProperties <: VulkanStruct{true} vks::VkExternalBufferProperties deps::Vector{Any} end )) - test(StructDefinition{false}, struct_by_name, :VkPipelineExecutableInternalRepresentationKHR, :( + test_ex(StructDefinition{false}(api.structs[:VkPipelineExecutableInternalRepresentationKHR]), :( struct _PipelineExecutableInternalRepresentationKHR <: VulkanStruct{true} vks::VkPipelineExecutableInternalRepresentationKHR deps::Vector{Any} end )) - test(StructDefinition{false}, struct_by_name, :VkDescriptorSetAllocateInfo, :( + test_ex(StructDefinition{false}(api.structs[:VkDescriptorSetAllocateInfo]), :( struct _DescriptorSetAllocateInfo <: VulkanStruct{true} vks::VkDescriptorSetAllocateInfo deps::Vector{Any} @@ -38,7 +38,7 @@ end )) - test(StructDefinition{false}, struct_by_name, :VkAccelerationStructureBuildGeometryInfoKHR, :( + test_ex(StructDefinition{false}(api.structs[:VkAccelerationStructureBuildGeometryInfoKHR]), :( struct _AccelerationStructureBuildGeometryInfoKHR <: VulkanStruct{true} vks::VkAccelerationStructureBuildGeometryInfoKHR deps::Vector{Any} @@ -49,13 +49,13 @@ end @testset "Friendly constructors" begin - test(Constructor, StructDefinition{false}(struct_by_name(:VkPhysicalDeviceProperties)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkPhysicalDeviceProperties])), :( function _PhysicalDeviceProperties(api_version::VersionNumber, driver_version::VersionNumber, vendor_id::Integer, device_id::Integer, device_type::PhysicalDeviceType, device_name::AbstractString, pipeline_cache_uuid::NTuple{Int(VK_UUID_SIZE), UInt8}, limits::_PhysicalDeviceLimits, sparse_properties::_PhysicalDeviceSparseProperties) _PhysicalDeviceProperties(VkPhysicalDeviceProperties(to_vk(UInt32, api_version), to_vk(UInt32, driver_version), vendor_id, device_id, device_type, device_name, pipeline_cache_uuid, limits.vks, sparse_properties.vks)) end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkInstanceCreateInfo)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkInstanceCreateInfo])), :( function _InstanceCreateInfo(enabled_layer_names::AbstractArray, enabled_extension_names::AbstractArray; next=C_NULL, flags=0, application_info=C_NULL) next = cconvert(Ptr{Cvoid}, next) application_info = cconvert(Ptr{VkApplicationInfo}, application_info) @@ -80,13 +80,13 @@ end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkSubpassSampleLocationsEXT)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkSubpassSampleLocationsEXT])), :( function _SubpassSampleLocationsEXT(subpass_index::Integer, sample_locations_info::_SampleLocationsInfoEXT) _SubpassSampleLocationsEXT(VkSubpassSampleLocationsEXT(subpass_index, sample_locations_info.vks)) end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkDebugUtilsMessengerCreateInfoEXT)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkDebugUtilsMessengerCreateInfoEXT])), :( function _DebugUtilsMessengerCreateInfoEXT(message_severity::DebugUtilsMessageSeverityFlagEXT, message_type::DebugUtilsMessageTypeFlagEXT, pfn_user_callback::FunctionPtr; next = C_NULL, flags = 0, user_data = C_NULL) next = cconvert(Ptr{Cvoid}, next) user_data = cconvert(Ptr{Cvoid}, user_data) @@ -96,7 +96,7 @@ end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkDescriptorSetAllocateInfo)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkDescriptorSetAllocateInfo])), :( function _DescriptorSetAllocateInfo(descriptor_pool, set_layouts::AbstractArray; next = C_NULL) next = cconvert(Ptr{Cvoid}, next) set_layouts = cconvert(Ptr{VkDescriptorSetLayout}, set_layouts) @@ -106,7 +106,7 @@ end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkPipelineShaderStageCreateInfo)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkPipelineShaderStageCreateInfo])), :( function _PipelineShaderStageCreateInfo(stage::ShaderStageFlag, _module, name::AbstractString; next = C_NULL, flags = 0, specialization_info = C_NULL) next = cconvert(Ptr{Cvoid}, next) name = cconvert(Cstring, name) @@ -117,13 +117,13 @@ end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkDescriptorImageInfo)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkDescriptorImageInfo])), :( function _DescriptorImageInfo(sampler, image_view, image_layout::ImageLayout) _DescriptorImageInfo(VkDescriptorImageInfo(sampler, image_view, image_layout), sampler, image_view) end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkDescriptorSetLayoutBinding)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkDescriptorSetLayoutBinding])), :( function _DescriptorSetLayoutBinding(binding::Integer, descriptor_type::DescriptorType, stage_flags::ShaderStageFlag; descriptor_count = 0, immutable_samplers = C_NULL) immutable_samplers = cconvert(Ptr{VkSampler}, immutable_samplers) deps = Any[immutable_samplers] @@ -132,7 +132,7 @@ end )) - test(Constructor, StructDefinition{false}(struct_by_name(:VkXcbSurfaceCreateInfoKHR)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkXcbSurfaceCreateInfoKHR])), :( function _XcbSurfaceCreateInfoKHR(connection::Ptr{vk.xcb_connection_t}, window::vk.xcb_window_t; next = C_NULL, flags = 0) next = cconvert(Ptr{Cvoid}, next) connection = cconvert(Ptr{vk.xcb_connection_t}, connection) @@ -144,7 +144,7 @@ end @testset "Manual tweaks" begin - test(Constructor, StructDefinition{false}(struct_by_name(:VkWriteDescriptorSet)), :( + test_ex(Constructor(StructDefinition{false}(api.structs[:VkWriteDescriptorSet])), :( function _WriteDescriptorSet(dst_set, dst_binding::Integer, dst_array_element::Integer, descriptor_type::DescriptorType, image_info::AbstractArray, buffer_info::AbstractArray, texel_buffer_view::AbstractArray; next = C_NULL, descriptor_count = max(pointer_length(image_info), pointer_length(buffer_info), pointer_length(texel_buffer_view))) next = cconvert(Ptr{Cvoid}, next) image_info = cconvert(Ptr{VkDescriptorImageInfo}, image_info) @@ -156,4 +156,4 @@ end )) end -end +end; diff --git a/generator/test/codegen/structs/unions.jl b/generator/test/codegen/structs/unions.jl index 517704b8..b22a8155 100644 --- a/generator/test/codegen/structs/unions.jl +++ b/generator/test/codegen/structs/unions.jl @@ -1,12 +1,12 @@ @testset "Unions" begin @testset "Low-level" begin - test(StructDefinition{false}, union_by_name, :VkClearColorValue, :( + test_ex(StructDefinition{false}(api.unions[:VkClearColorValue]), :( struct _ClearColorValue <: VulkanStruct{false} vks::VkClearColorValue end )) - test(StructDefinition{false}, union_by_name, :VkClearValue, :( + test_ex(StructDefinition{false}(api.unions[:VkClearValue]), :( struct _ClearValue <: VulkanStruct{false} vks::VkClearValue end @@ -14,13 +14,13 @@ end @testset "High-level" begin - test(StructDefinition{true}, union_by_name, :VkClearColorValue, :( + test_ex(StructDefinition{true}(api.unions[:VkClearColorValue]), :( struct ClearColorValue <: HighLevelStruct vks::VkClearColorValue end )) - test(StructDefinition{true}, union_by_name, :VkClearValue, :( + test_ex(StructDefinition{true}(api.unions[:VkClearValue]), :( struct ClearValue <: HighLevelStruct vks::VkClearValue end @@ -28,11 +28,11 @@ end @testset "Constructors" begin - consts = VulkanGen.constructors(StructDefinition{true}(union_by_name(:VkClearValue))) + consts = VulkanGen.constructors(StructDefinition{true}(api.unions[:VkClearValue])) expected = [ :(ClearValue(color::ClearColorValue) = ClearValue(VkClearValue(color.vks))), :(ClearValue(depth_stencil::ClearDepthStencilValue) = ClearValue(VkClearValue(_ClearDepthStencilValue(depth_stencil).vks))), ] foreach(Base.splat(test_ex), zip(consts, expected)) end -end +end; diff --git a/generator/test/config.jl b/generator/test/config.jl index a6b5b88f..b5d2999d 100644 --- a/generator/test/config.jl +++ b/generator/test/config.jl @@ -1,7 +1,9 @@ wrapper_config(; kwargs...) = WrapperConfig(; destfile="", kwargs...) -@test isempty(extensions(wrapper_config(wrap_core=false))) -@test length(extensions(wrapper_config())) > 200 -@test length(extensions(wrapper_config(wrap_core=false, include_platforms=[PLATFORM_VI]))) < 5 -@test length(extensions(wrapper_config(include_provisional_exts=true))) > length(extensions(wrapper_config())) -@test extensions(wrapper_config(include_provisional_exts=true)) == extensions(wrapper_config(include_platforms=[PLATFORM_PROVISIONAL])) +@testset "WrapperConfig" begin + @test isempty(extensions(wrapper_config(wrap_core=false))) + @test length(extensions(wrapper_config())) > 200 + @test length(extensions(wrapper_config(wrap_core=false, include_platforms=[PLATFORM_VI]))) < 5 + @test length(extensions(wrapper_config(include_provisional_exts=true))) > length(extensions(wrapper_config())) + @test extensions(wrapper_config(include_provisional_exts=true)) == extensions(wrapper_config(include_platforms=[PLATFORM_PROVISIONAL])) +end; diff --git a/generator/test/runtests.jl b/generator/test/runtests.jl index 2fb70b96..e95df6ed 100644 --- a/generator/test/runtests.jl +++ b/generator/test/runtests.jl @@ -6,9 +6,6 @@ test_ex(x, y) = @test prettify(x) == prettify(y) test_ex(x::AbstractArray, y::AbstractArray) = foreach(test_ex, x, y) test_ex(x::WrapperNode, y) = @test prettify(to_expr(x)) == prettify(y) -test(T, f, name, ex) = test_ex(T(f(name)), ex) -test(T, arg, ex) = test(T, identity, arg, ex) - @testset "VulkanGen.jl" begin @testset "Wrapper utilities" begin include("utilities/exprs.jl") @@ -40,6 +37,4 @@ test(T, arg, ex) = test(T, identity, arg, ex) include("codegen/aliases.jl") include("codegen/docs.jl") end -end - end;