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 May 15, 2021
1 parent 4c6b244 commit c599d79
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/analysis/conversion_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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
3 changes: 2 additions & 1 deletion src/analysis/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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"),
Expand Down Expand Up @@ -295,6 +295,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 @@ -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())
Expand Down
64 changes: 61 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 @@ -241,6 +241,7 @@ pub enum Fundamental {
//Not defined in GLib directly
OsString,
Unsupported,
Vulkan(String),
}

impl Fundamental {
Expand All @@ -267,6 +268,7 @@ impl Fundamental {
| Fundamental::SSize
| Fundamental::Float
| Fundamental::Double
| Fundamental::Vulkan(_)
)
}
}
Expand Down Expand Up @@ -989,6 +991,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 @@ -1006,11 +1010,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);
Expand Down

0 comments on commit c599d79

Please sign in to comment.