@@ -41,17 +41,16 @@ pub enum PipelineConstantError {
4141 NegativeWorkgroupSize ,
4242}
4343
44- /// Replace all overrides in `module` with constants.
44+ /// Compact `module` and replace all overrides with constants.
4545///
46- /// If no changes are needed, this just returns `Cow::Borrowed`
47- /// references to `module` and `module_info`. Otherwise, it clones
48- /// ` module` , edits its [`global_expressions`] arena to contain only
49- /// fully-evaluated expressions, and returns `Cow::Owned` values
50- /// holding the simplified module and its validation results.
46+ /// If no changes are needed, this just returns `Cow::Borrowed` references to
47+ /// `module` and `module_info`. Otherwise, it clones `module`, retains only the
48+ /// selected entry point, compacts the module, edits its [`global_expressions`]
49+ /// arena to contain only fully-evaluated expressions, and returns the
50+ /// simplified module and its validation results.
5151///
52- /// In either case, the module returned has an empty `overrides`
53- /// arena, and the `global_expressions` arena contains only
54- /// fully-evaluated expressions.
52+ /// The module returned has an empty `overrides` arena, and the
53+ /// `global_expressions` arena contains only fully-evaluated expressions.
5554///
5655/// [`global_expressions`]: Module::global_expressions
5756pub fn process_overrides < ' a > (
@@ -60,22 +59,27 @@ pub fn process_overrides<'a>(
6059 entry_point : Option < ( ir:: ShaderStage , & str ) > ,
6160 pipeline_constants : & PipelineConstants ,
6261) -> Result < ( Cow < ' a , Module > , Cow < ' a , ModuleInfo > ) , PipelineConstantError > {
63- if module. overrides . is_empty ( ) {
62+ if ( entry_point . is_none ( ) || module . entry_points . len ( ) <= 1 ) && module. overrides . is_empty ( ) {
6463 return Ok ( ( Cow :: Borrowed ( module) , Cow :: Borrowed ( module_info) ) ) ;
6564 }
6665
6766 let mut module = module. clone ( ) ;
68-
69- // If an entry point was specified, compact the module to remove anything
70- // not reachable from that entry point. This is necessary because we may not
71- // have values for overrides that are not reachable from the entry point.
7267 if let Some ( ( ep_stage, ep_name) ) = entry_point {
7368 module
7469 . entry_points
7570 . retain ( |ep| ep. stage == ep_stage && ep. name == ep_name) ;
7671 }
72+
73+ // Compact the module to remove anything not reachable from an entry point.
74+ // This is necessary because we may not have values for overrides that are
75+ // not reachable from the/an entry point.
7776 compact ( & mut module, KeepUnused :: No ) ;
7877
78+ // If there are no overrides in the module, then we can skip the rest.
79+ if module. overrides . is_empty ( ) {
80+ return revalidate ( module) ;
81+ }
82+
7983 // A map from override handles to the handles of the constants
8084 // we've replaced them with.
8185 let mut override_map = HandleVec :: with_capacity ( module. overrides . len ( ) ) ;
@@ -237,9 +241,14 @@ pub fn process_overrides<'a>(
237241 // Now that we've rewritten all the expressions, we need to
238242 // recompute their types and other metadata. For the time being,
239243 // do a full re-validation.
244+ revalidate ( module)
245+ }
246+
247+ fn revalidate (
248+ module : Module ,
249+ ) -> Result < ( Cow < ' static , Module > , Cow < ' static , ModuleInfo > ) , PipelineConstantError > {
240250 let mut validator = Validator :: new ( ValidationFlags :: all ( ) , Capabilities :: all ( ) ) ;
241251 let module_info = validator. validate_resolved_overrides ( & module) ?;
242-
243252 Ok ( ( Cow :: Owned ( module) , Cow :: Owned ( module_info) ) )
244253}
245254
0 commit comments