diff --git a/src/analysis/conversion_type.rs b/src/analysis/conversion_type.rs index da38f2680..0fa458df7 100644 --- a/src/analysis/conversion_type.rs +++ b/src/analysis/conversion_type.rs @@ -77,6 +77,7 @@ impl ConversionType { None => ConversionType::Unknown, IntPtr => ConversionType::Direct, UIntPtr => ConversionType::Direct, + Vulkan(_) => ConversionType::Direct, Unsupported => ConversionType::Unknown, }, Alias(alias) if alias.c_identifier == "GQuark" => ConversionType::Scalar, diff --git a/src/analysis/ffi_type.rs b/src/analysis/ffi_type.rs index a69a08b37..bf0806890 100644 --- a/src/analysis/ffi_type.rs +++ b/src/analysis/ffi_type.rs @@ -73,7 +73,7 @@ pub fn ffi_type(env: &Env, tid: TypeId, c_type: &str) -> Result { fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result { let typ = env.library.type_(tid); match *typ { - Type::Fundamental(fund) => { + Type::Fundamental(ref fund) => { use crate::library::Fundamental::*; let inner = match fund { None => "libc::c_void", diff --git a/src/analysis/rust_type.rs b/src/analysis/rust_type.rs index 0a9926fb1..c272c2a8c 100644 --- a/src/analysis/rust_type.rs +++ b/src/analysis/rust_type.rs @@ -251,7 +251,7 @@ impl<'env> RustTypeBuilder<'env> { let mut skip_option = false; let type_ = self.env.library.type_(self.type_id); let mut rust_type = match *type_ { - Fundamental(fund) => { + Fundamental(ref fund) => { match fund { None => err("()"), Boolean => ok("bool"), @@ -268,7 +268,7 @@ impl<'env> RustTypeBuilder<'env> { UInt => ok("u32"), //maybe dependent on target system Short => ok_and_use("libc::c_short"), //depends of target system - UShort => ok_and_use("libc::c_ushort"), //depends o f target system + UShort => ok_and_use("libc::c_ushort"), //depends of target system Long => ok_and_use("libc::c_long"), //depends of target system ULong => ok_and_use("libc::c_ulong"), //depends of target system @@ -303,6 +303,7 @@ impl<'env> RustTypeBuilder<'env> { Type => ok_and_use(&use_glib_type(self.env, "types::Type")), Char => ok_and_use(&use_glib_type(self.env, "Char")), UChar => ok_and_use(&use_glib_type(self.env, "UChar")), + Vulkan(name) => ok_and_use(&format!("ash::vk::{}", name)), Unsupported => err("Unsupported"), _ => err(&format!("Fundamental: {:?}", fund)), } diff --git a/src/codegen/sys/ffi_type.rs b/src/codegen/sys/ffi_type.rs index 6f53664f3..6c728b2f1 100644 --- a/src/codegen/sys/ffi_type.rs +++ b/src/codegen/sys/ffi_type.rs @@ -74,7 +74,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result { let typ = env.library.type_(tid); let res = match *typ { - Type::Fundamental(fund) => { + Type::Fundamental(ref fund) => { use crate::library::Fundamental::*; let inner = match fund { None => "c_void", @@ -114,6 +114,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result { IntPtr => "intptr_t", UIntPtr => "uintptr_t", Unsupported => return Err(TypeError::Unimplemented(inner)), + Vulkan(v) => return Ok(format!("ash::vk::{}", v).into()), VarArgs => panic!("Should not reach here"), }; Ok(inner.into()) diff --git a/src/library.rs b/src/library.rs index 0f618dd19..b84fbddd8 100644 --- a/src/library.rs +++ b/src/library.rs @@ -205,7 +205,7 @@ impl Default for Concurrency { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Fundamental { None, Boolean, @@ -241,6 +241,7 @@ pub enum Fundamental { //Not defined in GLib directly OsString, Unsupported, + Vulkan(String), } impl Fundamental { @@ -267,6 +268,7 @@ impl Fundamental { | Fundamental::SSize | Fundamental::Float | Fundamental::Double + | Fundamental::Vulkan(_) ) } } @@ -992,6 +994,8 @@ impl Namespace { pub const INTERNAL_NAMESPACE_NAME: &str = "*"; pub const INTERNAL_NAMESPACE: u16 = 0; pub const MAIN_NAMESPACE: u16 = 1; +pub const VULKAN_NAMESPACE_NAME: &str = "Vulkan"; +pub const VULKAN_NAMESPACE: u16 = 2; #[derive(Debug)] pub struct Library { @@ -1009,11 +1013,65 @@ impl Library { INTERNAL_NAMESPACE, library.add_namespace(INTERNAL_NAMESPACE_NAME) ); - for &(name, t) in FUNDAMENTAL { - library.add_type(INTERNAL_NAMESPACE, name, Type::Fundamental(t)); + for (name, t) in FUNDAMENTAL { + library.add_type(INTERNAL_NAMESPACE, name, Type::Fundamental(t.clone())); } assert_eq!(MAIN_NAMESPACE, library.add_namespace(main_namespace_name)); + assert_eq!( + VULKAN_NAMESPACE, + library.add_namespace(VULKAN_NAMESPACE_NAME) + ); + const VULKAN: &[&str] = &[ + "AccessFlags", + "Buffer", + "BufferUsageFlags", + "CommandBuffer", + "CommandBufferLevel", + "CommandPool", + "DescriptorPool", + "DescriptorSet", + "Device", + "DeviceMemory", + "DeviceSize", + "Fence", + "Format", + "Image", + "ImageCreateInfo", + "ImageFormatProperties", + "ImageLayout", + "ImageSubresourceRange", + "ImageTiling", + "ImageUsageFlags", + "ImageView", + "ImageViewCreateInfo", + "Instance", + "MemoryAllocateInfo", + "MemoryHeapFlags", + "MemoryPropertyFlags", + "MemoryRequirements", + "PhysicalDevice", + "PhysicalDeviceFeatures", + "PhysicalDeviceMemoryProperties", + "PhysicalDeviceProperties", + "PhysicalDeviceType", + "PipelineStageFlags", + "Queue", + "QueueFamilyProperties", + "QueueFlags", + "Result", + "SampleCountFlags", + "Semaphore", + "SurfaceKHR", + ]; + for v in VULKAN { + library.add_type( + VULKAN_NAMESPACE, + v, + Type::Fundamental(Fundamental::Vulkan(v.to_string())), + ); + } + //For string_type override Type::c_array(&mut library, TypeId::tid_utf8(), None, None); Type::c_array(&mut library, TypeId::tid_filename(), None, None);