From 8b818a2076902e4a25069c14b42e99ec4a6f676d Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 11 Feb 2024 16:51:25 -0500 Subject: [PATCH] Defer entry-point processing so that all potential uses of builtin's are found before culling the unused ones --- naga/src/front/spv/function.rs | 4 ++-- naga/src/front/spv/mod.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/naga/src/front/spv/function.rs b/naga/src/front/spv/function.rs index f5673379b..e81ecf5c9 100644 --- a/naga/src/front/spv/function.rs +++ b/naga/src/front/spv/function.rs @@ -292,13 +292,13 @@ impl> super::Frontend { ); 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, diff --git a/naga/src/front/spv/mod.rs b/naga/src/front/spv/mod.rs index 0861859e0..fb54e0d18 100644 --- a/naga/src/front/spv/mod.rs +++ b/naga/src/front/spv/mod.rs @@ -577,6 +577,9 @@ pub struct Frontend { lookup_function_type: FastHashMap, lookup_function: FastHashMap, lookup_entry_point: FastHashMap, + // 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` of the call site. deferred_function_calls: Vec, @@ -628,6 +631,7 @@ impl> Frontend { 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(), @@ -3954,7 +3958,11 @@ impl> Frontend { }?; } - // 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..."); {