From ca50417f4ec3d544dadeb12fcae46ffa1528e3b4 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 30 May 2022 11:01:34 +0200 Subject: [PATCH] Make all Vulkan types fundamental --- src/analysis/conversion_type.rs | 1 + src/analysis/ffi_type.rs | 2 +- src/analysis/rust_type.rs | 5 ++- src/codegen/sys/ffi_type.rs | 3 +- src/library.rs | 66 +++++++++++++++++++++++++++++++-- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/analysis/conversion_type.rs b/src/analysis/conversion_type.rs index f66e1fe0f..79b9f3cee 100644 --- a/src/analysis/conversion_type.rs +++ b/src/analysis/conversion_type.rs @@ -79,6 +79,7 @@ impl ConversionType { IntPtr => ConversionType::Direct, UIntPtr => ConversionType::Direct, Bool => 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 cd3a3eb83..c2e6a5731 100644 --- a/src/analysis/ffi_type.rs +++ b/src/analysis/ffi_type.rs @@ -68,7 +68,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::Basic(fund) => { + Type::Basic(ref fund) => { use crate::library::Basic::*; let inner = match fund { None => "libc::c_void", diff --git a/src/analysis/rust_type.rs b/src/analysis/rust_type.rs index cac8cbbee..018d51ed9 100644 --- a/src/analysis/rust_type.rs +++ b/src/analysis/rust_type.rs @@ -253,7 +253,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_ { - Basic(fund) => { + Basic(ref fund) => { match fund { None => err("()"), Boolean | Bool => ok("bool"), @@ -270,7 +270,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 @@ -305,6 +305,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!("Basic: {:?}", fund)), } diff --git a/src/codegen/sys/ffi_type.rs b/src/codegen/sys/ffi_type.rs index 7c229ce9a..2c71002fa 100644 --- a/src/codegen/sys/ffi_type.rs +++ b/src/codegen/sys/ffi_type.rs @@ -66,7 +66,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result { let typ = env.library.type_(tid); let res = match *typ { - Type::Basic(fund) => { + Type::Basic(ref fund) => { use crate::library::Basic::*; let inner = match fund { None => "c_void", @@ -107,6 +107,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result { UIntPtr => "uintptr_t", Bool => "bool", 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 7d5b98b54..162a93f8b 100644 --- a/src/library.rs +++ b/src/library.rs @@ -203,7 +203,7 @@ impl Default for Concurrency { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Basic { None, Boolean, @@ -240,6 +240,7 @@ pub enum Basic { OsString, Bool, Unsupported, + Vulkan(String), } impl Basic { @@ -267,6 +268,7 @@ impl Basic { | Self::Float | Self::Double | Self::Bool + | Self::Vulkan(_) ) } } @@ -1036,6 +1038,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 { @@ -1053,11 +1057,67 @@ impl Library { INTERNAL_NAMESPACE, library.add_namespace(INTERNAL_NAMESPACE_NAME) ); - for &(name, t) in BASIC { - library.add_type(INTERNAL_NAMESPACE, name, Type::Basic(t)); + for (name, t) in BASIC { + library.add_type(INTERNAL_NAMESPACE, name, Type::Basic(t.clone())); } assert_eq!(MAIN_NAMESPACE, library.add_namespace(main_namespace_name)); + assert_eq!( + VULKAN_NAMESPACE, + library.add_namespace(VULKAN_NAMESPACE_NAME) + ); + // TODO: This should be parseable from gir-files/Vulkan-1.0.gir! + 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", + "PresentModeKHR", + "Queue", + "QueueFamilyProperties", + "QueueFlags", + "Result", + "SampleCountFlags", + "Semaphore", + "SurfaceKHR", + ]; + for v in VULKAN { + library.add_type( + VULKAN_NAMESPACE, + v, + Type::Basic(Basic::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);