Fix two issues related to non-treelike (diamond) effect graphs.
First of all, we could have an assert failure when an input was used twice.
Work around it by simply ignoring the input the second time.
This, however, would expose an issue where effects could be emitted in the
.glsl file out-of-order. Refactor the topological sort code so that it can
be reused for arbitrary subgraphs, and then use it to topologically sort
the list of effects in each pass.