Skip to content

Commit

Permalink
Make all Vulkan types fundamental
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Feb 1, 2022
1 parent e0d8d8d commit 7412855
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/analysis/conversion_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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

Expand Down Expand Up @@ -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)),
}
Expand Down
3 changes: 2 additions & 1 deletion src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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())
Expand Down
66 changes: 63 additions & 3 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Default for Concurrency {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Fundamental {
None,
Boolean,
Expand Down Expand Up @@ -242,6 +242,7 @@ pub enum Fundamental {
OsString,
Bool,
Unsupported,
Vulkan(String),
}

impl Fundamental {
Expand Down Expand Up @@ -269,6 +270,7 @@ impl Fundamental {
| Fundamental::Float
| Fundamental::Double
| Fundamental::Bool
| Fundamental::Vulkan(_)
)
}
}
Expand Down Expand Up @@ -1031,6 +1033,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 {
Expand All @@ -1048,11 +1052,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);
Expand Down

0 comments on commit 7412855

Please sign in to comment.