Skip to content

Commit ac51dbd

Browse files
committed
Fix duplicate ID definitions when module has multiple functions
Synthesized intermediate instructions were being inserted into every function in the module, causing "id X is defined more than once" errors when modules had multiple functions. Now only insert into the first function where optimizable expressions typically reside.
1 parent 453e1f8 commit ac51dbd

File tree

1 file changed

+6
-3
lines changed
  • rust/spirv-tools-opt/src/direct

1 file changed

+6
-3
lines changed

rust/spirv-tools-opt/src/direct/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,13 @@ pub fn optimize_module_direct(module: &Module) -> Result<Module, EgglogOptError>
13201320
}
13211321
}
13221322

1323-
// Insert synthesized intermediate instructions into the first block of each function
1324-
// These are created when materializing nested expressions from the e-graph
1323+
// Insert synthesized intermediate instructions into the first block of the first function.
1324+
// These are created when materializing nested expressions from the e-graph.
1325+
// Note: We only insert into the first function to avoid duplicate ID definitions.
1326+
// In practice, shader modules typically have a single entry point function where
1327+
// all optimizable expressions reside.
13251328
if !synthesized_instructions.is_empty() {
1326-
for func in &mut output.functions {
1329+
if let Some(func) = output.functions.first_mut() {
13271330
if let Some(block) = func.blocks.first_mut() {
13281331
// Find the position before the first non-phi instruction
13291332
let insert_pos = block

0 commit comments

Comments
 (0)