From f83f10b2826ef1b66d0d795252b8da832801c53b Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 6 May 2021 22:51:59 +0200 Subject: [PATCH] Make all Vulkan types fundamental --- Cargo.lock | 18 ++++----- 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 +++++++++++++++++++++++++++++++-- 6 files changed, 79 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 719b2fdec..463bddfe3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,7 +41,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ - "log 0.4.14", + "log 0.4.15", ] [[package]] @@ -71,7 +71,7 @@ dependencies = [ "fix-getters-rules", "getopts", "hprof", - "log 0.4.14", + "log 0.4.15", "once_cell", "regex", "rustdoc-stripper", @@ -111,14 +111,14 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.14", + "log 0.4.15", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "1c4dcd960cc540667f619483fc99102f88d6118b87730e24e8fbe8054b7445e4" dependencies = [ "cfg-if", ] @@ -131,15 +131,15 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "once_cell" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] name = "regex" -version = "1.5.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ "aho-corasick", "memchr", diff --git a/src/analysis/conversion_type.rs b/src/analysis/conversion_type.rs index 7f9d3f0d4..731e6be56 100644 --- a/src/analysis/conversion_type.rs +++ b/src/analysis/conversion_type.rs @@ -78,6 +78,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 6d2c0326a..448c6ba94 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 c1f02064f..c392c42ef 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 | Bool => 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 6d3dee6b3..c66a8705e 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", @@ -115,6 +115,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 2dea4700b..0550f6cbb 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, @@ -242,6 +242,7 @@ pub enum Fundamental { OsString, Bool, Unsupported, + Vulkan(String), } impl Fundamental { @@ -269,6 +270,7 @@ impl Fundamental { | Fundamental::Float | Fundamental::Double | Fundamental::Bool + | Fundamental::Vulkan(_) ) } } @@ -1032,6 +1034,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 { @@ -1049,11 +1053,67 @@ 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) + ); + // 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::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);