zachsaw/RenderScripts — pull request #3 by Shiandow (2014-11-09 16:39:29+00:00)
Title: Improved texture allocation

Changes:
-Mark a texture as 'stolen' when it has been stolen by another filter.
-Do not allow 'stolen' textures to be reused.
-Only reuse textures if "f.LastDependentIndex < FilterIndex" to prevent a shader from reading and writing to the same texture.
-Added a dummy filter to SourceFilter to allow OutputRenderTarget to be reused,

This method should probably be replaced by something nicer eventually, but it seems to work (more or less). For example, using 8 shaders will cause textures to be reused in the following way:
filter 2 steals texture of filter 0
filter 3 steals texture of filter 1
filter 4 steals texture of filter 2
filter 5 steals texture of filter 3
filter 6 steals texture of filter 4
filter 7 steals texture of filter 5
(Note this is what actually happened, not just theoretically)

This way I also discovered another bug: AllocateTextures is called before SourceFilter.OutputTexture has a value, making it impossible to reuse that texture (note that texture -1 is never 'stolen'). Maybe call AllocateTextures just before rendering? (allocating textures seems to be fast enough for this to work)
Same thing happens to the OuputDummy filter (texture -2).