From: Steinar H. Gunderson Date: Thu, 24 Dec 2015 15:43:23 +0000 (+0100) Subject: Make shader generation more deterministic by removing a sort of pointers. X-Git-Tag: 1.3.0~5 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=0d964b485070dcc0a9b6874152204dd13112027d Make shader generation more deterministic by removing a sort of pointers. --- diff --git a/effect_chain.cpp b/effect_chain.cpp index c2402da..30dc3e4 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -589,9 +589,17 @@ Phase *EffectChain::construct_phase(Node *output, map *complete // and create a GLSL program for it. assert(!phase->effects.empty()); - // Deduplicate the inputs. - sort(phase->inputs.begin(), phase->inputs.end()); - phase->inputs.erase(unique(phase->inputs.begin(), phase->inputs.end()), phase->inputs.end()); + // Deduplicate the inputs, but don't change the ordering e.g. by sorting; + // that would be nondeterministic and thus reduce cacheability. + // TODO: Make this even more deterministic. + vector dedup_inputs; + set seen_inputs; + for (size_t i = 0; i < phase->inputs.size(); ++i) { + if (seen_inputs.insert(phase->inputs[i]).second) { + dedup_inputs.push_back(phase->inputs[i]); + } + } + swap(phase->inputs, dedup_inputs); // Allocate samplers for each input. phase->input_samplers.resize(phase->inputs.size());