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 Dec 11, 2022
1 parent 952ff41 commit ca50417
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/analysis/conversion_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 @@ -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",
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 @@ -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"),
Expand All @@ -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

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

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

impl Basic {
Expand Down Expand Up @@ -267,6 +268,7 @@ impl Basic {
| Self::Float
| Self::Double
| Self::Bool
| Self::Vulkan(_)
)
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit ca50417

Please sign in to comment.