X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=effect_chain.cpp;h=23156cb2db604422a7b3ecf66f24f345cac36a8c;hb=f909bfe0621e8c844695ef327b71457893633cae;hp=a83a952dfaae331bb5431000823cecefd6b82e7f;hpb=5e771df1523ea3f7926c0b5a115c29d134c53f11;p=movit diff --git a/effect_chain.cpp b/effect_chain.cpp index a83a952..23156cb 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -38,8 +38,8 @@ namespace { class IdentityEffect : public Effect { public: IdentityEffect() {} - virtual string effect_type_id() const { return "IdentityEffect"; } - string output_fragment_shader() { return read_file("identity.frag"); } + string effect_type_id() const override { return "IdentityEffect"; } + string output_fragment_shader() override { return read_file("identity.frag"); } }; } // namespace @@ -1882,9 +1882,18 @@ void EffectChain::render(GLuint dest_fbo, const vector &dest set generated_mipmaps; - // We choose the simplest option of having one texture per output, - // since otherwise this turns into an (albeit simple) register allocation problem. + // We keep one texture per output, but only for as long as we actually have any + // phases that need it as an input. (We don't make any effort to reorder phases + // to minimize the number of textures in play, as register allocation can be + // complicated and we rarely have much to gain, since our graphs are typically + // pretty linear.) map output_textures; + map ref_counts; + for (Phase *phase : phases) { + for (Phase *input : phase->inputs) { + ++ref_counts[input]; + } + } size_t num_phases = phases.size(); if (destinations.empty()) { @@ -1972,6 +1981,15 @@ void EffectChain::render(GLuint dest_fbo, const vector &dest if (do_phase_timing) { glEndQuery(GL_TIME_ELAPSED); } + + // Drop any input textures we don't need anymore. + for (Phase *input : phase->inputs) { + assert(ref_counts[input] > 0); + if (--ref_counts[input] == 0) { + resource_pool->release_2d_texture(output_textures[input]); + output_textures.erase(input); + } + } } for (const auto &phase_and_texnum : output_textures) {