]> git.sesse.net Git - movit/blobdiff - effect_chain.cpp
Fix a typo in ResizeEffect. Found by virtual → override transition.
[movit] / effect_chain.cpp
index d56a24806771a0a1e8d444078a28935731305720..c9d746fbafaa390b5cc17437348df0f77e82e87f 100644 (file)
@@ -500,7 +500,7 @@ void EffectChain::compile_glsl_program(Phase *phase)
        }
 
        if (phase->is_compute_shader) {
-               frag_shader.append(read_file("footer.compute"));
+               frag_shader.append(read_file("footer.comp"));
                phase->output_node->effect->register_uniform_vec2("inv_output_size", (float *)&phase->inv_output_size);
                phase->output_node->effect->register_uniform_vec2("output_texcoord_adjust", (float *)&phase->output_texcoord_adjust);
        } else {
@@ -1882,9 +1882,18 @@ void EffectChain::render(GLuint dest_fbo, const vector<DestinationTexture> &dest
 
        set<Phase *> 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<Phase *, GLuint> output_textures;
+       map<Phase *, int> 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<DestinationTexture> &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) {