From 0d964b485070dcc0a9b6874152204dd13112027d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 24 Dec 2015 16:43:23 +0100 Subject: [PATCH 1/1] Make shader generation more deterministic by removing a sort of pointers. --- effect_chain.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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()); -- 2.39.2