remove duplicate extensions

This commit is contained in:
khyperia 2020-10-01 12:46:02 +02:00
parent b0c9965cfb
commit 16338fb079
2 changed files with 13 additions and 0 deletions

View File

@ -4,6 +4,18 @@ use rspirv::dr::{Instruction, Module, Operand};
use rspirv::spirv::{Op, Word}; use rspirv::spirv::{Op, Word};
use std::collections::{hash_map, HashMap, HashSet}; 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) { pub fn remove_duplicate_capablities(module: &mut Module) {
let mut set = HashSet::new(); let mut set = HashSet::new();
let mut caps = vec![]; let mut caps = vec![];

View File

@ -107,6 +107,7 @@ pub fn link<T>(inputs: &mut [&mut Module], timer: impl Fn(&'static str) -> T) ->
let remove_duplicates_timer = timer("link_remove_duplicates"); let remove_duplicates_timer = timer("link_remove_duplicates");
// remove duplicates (https://github.com/KhronosGroup/SPIRV-Tools/blob/e7866de4b1dc2a7e8672867caeb0bdca49f458d3/source/opt/remove_duplicates_pass.cpp) // 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_capablities(&mut output);
duplicates::remove_duplicate_ext_inst_imports(&mut output); duplicates::remove_duplicate_ext_inst_imports(&mut output);
duplicates::remove_duplicate_types(&mut output); duplicates::remove_duplicate_types(&mut output);