Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Treat all types in the Vulkan namespace as fundamental #1134

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/analysis/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ impl RustType {
type_name.as_str()
);

if env.type_status(&type_id.full_name(&env.library)).ignored() {
// if env.namespaces[type_id.ns_id].higher_crate_name == "vulkan" {
// dbg!(&type_name);
// dbg!(&type_id.full_name(&env.library));
// // dbg!(&env.config.objects);
// // panic!();
// }
if env.type_status(&type_id.full_name(&env.library)).ignored()
// TODO
&& env.namespaces[type_id.ns_id].higher_crate_name != "vulkan"
{
// dbg!(&type_name);
return Err(TypeError::Ignored(type_name));
}
}
Expand Down Expand Up @@ -271,7 +281,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
4 changes: 4 additions & 0 deletions src/analysis/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ impl IsIncomplete for Record {
// Search for GHookList in sys codegen for rationale.
false
} else {
// BADHACK: Prevent a horrible cyclic dependency on the "refs" array
if self.name == "VulkanDecoderPicture" {
return false;
}
self.fields.as_slice().is_incomplete(lib)
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
| Type::List(..)
| Type::SList(..)
| Type::HashTable(..) => fix_name(env, tid, &inner),
// TODO: Add namespace!
Type::Custom(ref c) => {
// return Ok(c.name.clone().into());
Ok(format!(
"{}::{}",
env.namespaces[tid.ns_id].higher_crate_name, c.name
)
.into())
}
_ => {
if let Some(glib_name) = env.library.type_(tid).get_glib_name() {
if inner != glib_name {
Expand Down
18 changes: 17 additions & 1 deletion src/library_postprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use log::{error, info};

use crate::{
analysis::types::IsIncomplete,
analysis::{conversion_type::ConversionType, types::IsIncomplete},
config::{
gobjects::{GObject, GStatus},
matchable::Matchable,
Expand Down Expand Up @@ -34,6 +34,7 @@ type DetectedCTypes = HashMap<TypeId, String>;

impl Library {
pub fn postprocessing(&mut self, config: &Config) {
self.define_vulkan_types();
self.fix_gtype();
self.check_resolved();
self.fill_empty_signals_c_types();
Expand All @@ -46,6 +47,21 @@ impl Library {
self.mark_ignored_enum_members(config);
}

fn define_vulkan_types(&mut self) {
if let Some(ns_id) = self.find_namespace("Vulkan") {
let ns = self.namespace_mut(ns_id);
for ns_type in ns.types.iter_mut().flatten() {
if let Type::Record(incomplete_record) = ns_type {
*ns_type = Type::Custom(Custom {
// name: format!("ash::vk::{}", incomplete_record.name),
name: incomplete_record.name.clone(),
conversion_type: ConversionType::Direct,
});
}
}
}
}

fn fix_gtype(&mut self) {
if let Some(ns_id) = self.find_namespace("GObject") {
// hide the `GType` type alias in `GObject`
Expand Down
Loading