Skip to content

Commit

Permalink
Defer entry-point processing so that all potential uses of builtin's …
Browse files Browse the repository at this point in the history
…are found before culling the unused ones
  • Loading branch information
Imberflur committed Feb 15, 2024
1 parent e13e1e4 commit 2703bec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions naga/src/front/spv/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
);

if let Some(ep) = self.lookup_entry_point.remove(&fun_id) {
self.process_entry_point(module, ep, fun_id)?;
self.deferred_entry_points.push((ep, fun_id));
}

Ok(())
}

fn process_entry_point(
pub(super) fn process_entry_point(
&mut self,
module: &mut crate::Module,
ep: super::EntryPoint,
Expand Down
10 changes: 9 additions & 1 deletion naga/src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ pub struct Frontend<I> {
lookup_function_type: FastHashMap<spirv::Word, LookupFunctionType>,
lookup_function: FastHashMap<spirv::Word, LookupFunction>,
lookup_entry_point: FastHashMap<spirv::Word, EntryPoint>,
// When parsing functions, each entry point function gets an entry here so that additional
// processing for them can be performed after all function parsing.
deferred_entry_points: Vec<(EntryPoint, spirv::Word)>,
//Note: each `OpFunctionCall` gets a single entry here, indexed by the
// dummy `Handle<crate::Function>` of the call site.
deferred_function_calls: Vec<spirv::Word>,
Expand Down Expand Up @@ -628,6 +631,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
lookup_function_type: FastHashMap::default(),
lookup_function: FastHashMap::default(),
lookup_entry_point: FastHashMap::default(),
deferred_entry_points: Vec::default(),
deferred_function_calls: Vec::default(),
dummy_functions: Arena::new(),
function_call_graph: GraphMap::new(),
Expand Down Expand Up @@ -3954,7 +3958,11 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
}?;
}

// TODO: clear unused builtin's here?
// Do entry point specific processing after all functions are parsed so that we can
// cull unused problematic builtins of gl_PerVertex.
for (ep, fun_id) in core::mem::take(&mut self.deferred_entry_points) {
self.process_entry_point(&mut module, ep, fun_id)?;
}

log::info!("Patching...");
{
Expand Down

0 comments on commit 2703bec

Please sign in to comment.