Skip to content

Commit

Permalink
Keep track of what feature set commands belong to
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusgo authored and Ralith committed Jul 26, 2024
1 parent 3d7928c commit 47936d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
28 changes: 18 additions & 10 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Parser {
self.parse_commands();
}
"feature" => {
self.parse_feature();
self.parse_feature(&attributes);
}
"extensions" => {
self.parse_extensions();
Expand Down Expand Up @@ -165,13 +165,14 @@ impl Parser {
}
}

fn parse_feature(&mut self) {
fn parse_feature(&mut self, attrs: &[OwnedAttribute]) {
let feature_name = Rc::<str>::from(attr(attrs, "name").unwrap());
loop {
use XmlEvent::*;
match self.reader.next().expect("failed to parse XML") {
StartElement { name, .. } => match &name.local_name[..] {
"require" => {
self.parse_required(None, None);
self.parse_required(None, None, Some(&feature_name));
}
_ => {
eprintln!("unimplemented feature element: {}", name.local_name);
Expand Down Expand Up @@ -235,7 +236,7 @@ impl Parser {
fn parse_extension_required(&mut self, attrs: &[OwnedAttribute]) {
let ext_name = Rc::<str>::from(attr(attrs, "name").unwrap());
let ext_number = attr(attrs, "number").unwrap().parse::<i32>().unwrap();
let (ext_version, commands) = self.parse_required(Some(&ext_name), Some(ext_number));
let (ext_version, commands) = self.parse_required(Some(&ext_name), Some(ext_number), None);
if attr(attrs, "supported").map_or(false, |x| x == "disabled") {
self.disabled_exts.insert(ext_name);
} else {
Expand Down Expand Up @@ -267,8 +268,10 @@ impl Parser {
&mut self,
ext_name: Option<&Rc<str>>,
ext_number: Option<i32>,
feature_name: Option<&Rc<str>>,
) -> (Option<u32>, Vec<String>) {
assert_eq!(ext_name.is_some(), ext_number.is_some());
assert_ne!(ext_name.is_some(), feature_name.is_some());
let mut ext_version = None;
let mut commands = Vec::new();
loop {
Expand All @@ -284,6 +287,11 @@ impl Parser {
command.extension = Some(ext_name.clone());
}
}
if let Some(feature_name) = feature_name {
if let Some(command) = self.commands.get_mut(cmd) {
command.feature = Some(feature_name.clone());
}
}
commands.push(cmd.into());
self.finish_element();
}
Expand Down Expand Up @@ -477,6 +485,7 @@ impl Parser {
Command {
params,
extension: None,
feature: None,
},
);
} else {
Expand Down Expand Up @@ -1308,13 +1317,11 @@ impl Parser {
/// Generate high-level code
#[allow(clippy::cognitive_complexity)] // TODO
fn generate_hl(&self) -> TokenStream {
const BLACKLISTED_COMMANDS: [&str; 3] = [
"xrNegotiateLoaderRuntimeInterface",
"xrNegotiateLoaderApiLayerInterface",
"xrCreateApiLayerInstance",
];
let (instance_pfn_fields, instance_pfn_inits) = self.commands.iter().map(|(name, command)| {
if command.extension.is_some() || BLACKLISTED_COMMANDS.contains(&name.as_str()) {
// We only want commands from xr version 1.0 here because these commands are always loaded.
if command.feature.as_ref().map_or(true, |feature|
feature.as_ref() != "XR_VERSION_1_0"
) {
return (quote! {}, quote! {});
}
let pfn_ident = xr_command_name(name);
Expand Down Expand Up @@ -2146,6 +2153,7 @@ struct Tag {
struct Command {
params: Vec<Member>,
extension: Option<Rc<str>>,
feature: Option<Rc<str>>,
}

#[derive(Debug)]
Expand Down
5 changes: 0 additions & 5 deletions openxr/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3365,7 +3365,6 @@ pub mod raw {
pub sync_actions: pfn::SyncActions,
pub enumerate_bound_sources_for_action: pfn::EnumerateBoundSourcesForAction,
pub get_input_source_localized_name: pfn::GetInputSourceLocalizedName,
pub locate_spaces: pfn::LocateSpaces,
}
impl Instance {
#[doc = r" Load the core function pointer table"]
Expand Down Expand Up @@ -3603,10 +3602,6 @@ pub mod raw {
instance,
CStr::from_bytes_with_nul_unchecked(b"xrGetInputSourceLocalizedName\0"),
)?),
locate_spaces: mem::transmute(entry.get_instance_proc_addr(
instance,
CStr::from_bytes_with_nul_unchecked(b"xrLocateSpaces\0"),
)?),
})
}
}
Expand Down

0 comments on commit 47936d2

Please sign in to comment.