diff --git a/rspirv-linker/src/duplicates.rs b/rspirv-linker/src/duplicates.rs index 7bb3aa5c96..989e837092 100644 --- a/rspirv-linker/src/duplicates.rs +++ b/rspirv-linker/src/duplicates.rs @@ -4,6 +4,18 @@ use rspirv::dr::{Instruction, Module, Operand}; use rspirv::spirv::{Op, Word}; use std::collections::{hash_map, HashMap, HashSet}; +pub fn remove_duplicate_extensions(module: &mut Module) { + let mut set = HashSet::new(); + + module.extensions.retain(|inst| { + inst.class.opcode != Op::Extension + || set.insert(match &inst.operands[0] { + Operand::LiteralString(s) => s.clone(), + _ => panic!(), + }) + }); +} + pub fn remove_duplicate_capablities(module: &mut Module) { let mut set = HashSet::new(); let mut caps = vec![]; diff --git a/rspirv-linker/src/lib.rs b/rspirv-linker/src/lib.rs index 951654b313..115fc3406a 100644 --- a/rspirv-linker/src/lib.rs +++ b/rspirv-linker/src/lib.rs @@ -107,6 +107,7 @@ pub fn link(inputs: &mut [&mut Module], timer: impl Fn(&'static str) -> T) -> let remove_duplicates_timer = timer("link_remove_duplicates"); // remove duplicates (https://github.com/KhronosGroup/SPIRV-Tools/blob/e7866de4b1dc2a7e8672867caeb0bdca49f458d3/source/opt/remove_duplicates_pass.cpp) + duplicates::remove_duplicate_extensions(&mut output); duplicates::remove_duplicate_capablities(&mut output); duplicates::remove_duplicate_ext_inst_imports(&mut output); duplicates::remove_duplicate_types(&mut output);