Track activated effects and build minimal shader

Seems to work in most cases but needs more testing; there are probably
cases where the effect refcount can become inaccurate.
Still to do: allow reuse of previous (cached) assembler output and
consider binding fewer texture samplers when possible.