]> git.sesse.net Git - movit/commitdiff
Unbreak FBO caching in unit tests.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 22 Nov 2017 23:18:28 +0000 (00:18 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 22 Nov 2017 23:19:49 +0000 (00:19 +0100)
EffectChain::render_to_textures() ended up reusing FBOs in a way that
was not compatible with how the tester managed textures; this broke nearly all
unit tests on NVIDIA.

effect_chain.h
test_util.cpp

index 8d75e8a7bd1b6dbad1363608529271c4fd7ae471..992fb58da2e172969b178c3ac012746ab4673fe9 100644 (file)
@@ -397,8 +397,10 @@ public:
        // Only one destination texture is supported. This restriction will be lifted
        // in the future.
        //
-       // All destination textures must be exactly of size <width> x <height>.
-       // width and height can not be zero.
+       // All destination textures must be exactly of size <width> x <height>,
+       // and must either come from the same ResourcePool the effect uses, or outlive
+       // the EffectChain (otherwise, we could be allocating FBOs that end up being
+       // stale). width and height can not be zero.
        struct DestinationTexture {
                GLuint texnum;
                GLenum format;
index 78122ced00d5f30190a5a9d7edabc97f2acd5260..ec8b146bae96c41e8f1fac705348a33a90fdf230 100644 (file)
@@ -248,20 +248,10 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T
                num_outputs = 1;
        }
 
-       GLuint texnum[4];
-
-       glGenTextures(num_outputs, texnum);
-       check_error();
-       for (unsigned i = 0; i < num_outputs; ++i) {
-               glBindTexture(GL_TEXTURE_2D, texnum[i]);
-               check_error();
-               glTexImage2D(GL_TEXTURE_2D, 0, framebuffer_format, width, height, 0, GL_RGBA, type, nullptr);
-               check_error();
-       }
-
        vector<EffectChain::DestinationTexture> textures;
        for (unsigned i = 0; i < num_outputs; ++i) {
-               textures.push_back(EffectChain::DestinationTexture{texnum[i], framebuffer_format});
+               GLuint texnum = chain.get_resource_pool()->create_2d_texture(framebuffer_format, width, height);
+               textures.push_back(EffectChain::DestinationTexture{texnum, framebuffer_format});
        }
 
        chain.render_to_texture(textures, width, height);
@@ -286,7 +276,7 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T
 
        for (unsigned i = 0; i < num_outputs; ++i) {
                T *ptr = data[i];
-               glBindTexture(GL_TEXTURE_2D, texnum[i]);
+               glBindTexture(GL_TEXTURE_2D, textures[i].texnum);
                check_error();
                if (!epoxy_is_desktop_gl() && (format == GL_RED || format == GL_BLUE || format == GL_ALPHA)) {
                        // GLES will only read GL_RGBA.
@@ -319,8 +309,9 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T
                }
        }
 
-       glDeleteTextures(num_outputs, texnum);
-       check_error();
+       for (unsigned i = 0; i < num_outputs; ++i) {
+               chain.get_resource_pool()->release_2d_texture(textures[i].texnum);
+       }
 }
 
 void EffectChainTester::add_output(const ImageFormat &format, OutputAlphaFormat alpha_format)