X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=test_util.cpp;h=14f896600a15b60c8c91c19030be8f8de412ed77;hb=cd353a6a5869f1de43073f871fad7ba368c0272f;hp=096c07a426eb21018b7e9b73d97a4a8e7f8aca97;hpb=e8a32d0ba0f66979f3c95702b95cd3ab967987c4;p=movit diff --git a/test_util.cpp b/test_util.cpp index 096c07a..14f8966 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -59,7 +59,7 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned output_added(false), finalized(false) { - CHECK(init_movit(".", MOVIT_DEBUG_OFF)); + init_movit_for_test(); if (data != nullptr) { add_input(data, pixel_format, color_space, gamma_curve); @@ -110,110 +110,110 @@ Input *EffectChainTester::add_input(const unsigned char *data, MovitPixelFormat void EffectChainTester::run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_FLOAT, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(float *out_data, float *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, nullptr, nullptr, GL_FLOAT, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, out_data2, nullptr, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(float *out_data, float *out_data2, float *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, nullptr, GL_FLOAT, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, out_data2, out_data3, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(float *out_data, float *out_data2, float *out_data3, float *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, out_data4, GL_FLOAT, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, out_data2, out_data3, out_data4, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(unsigned char *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(unsigned char *out_data, unsigned char *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, nullptr, nullptr, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, out_data2, nullptr, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(unsigned char *out_data, unsigned char *out_data2, unsigned char *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, nullptr, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, out_data2, out_data3, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(unsigned char *out_data, unsigned char *out_data2, unsigned char *out_data3, unsigned char *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, out_data4, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, out_data2, out_data3, out_data4, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run(uint16_t *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_UNSIGNED_SHORT, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format); } void EffectChainTester::run_10_10_10_2(uint32_t *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_UNSIGNED_INT_2_10_10_10_REV, format, color_space, gamma_curve, alpha_format); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format); } #ifdef HAVE_BENCHMARK void EffectChainTester::benchmark(benchmark::State &state, float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_FLOAT, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, float *out_data, float *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, nullptr, nullptr, GL_FLOAT, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, out_data2, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, float *out_data, float *out_data2, float *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, nullptr, GL_FLOAT, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, out_data2, out_data3, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, float *out_data, float *out_data2, float *out_data3, float *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, out_data4, GL_FLOAT, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, out_data2, out_data3, out_data4, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, unsigned char *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, unsigned char *out_data, unsigned char *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, nullptr, nullptr, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, out_data2, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, unsigned char *out_data, unsigned char *out_data2, unsigned char *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, nullptr, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, out_data2, out_data3, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, unsigned char *out_data, unsigned char *out_data2, unsigned char *out_data3, unsigned char *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, out_data2, out_data3, out_data4, GL_UNSIGNED_BYTE, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, out_data2, out_data3, out_data4, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark(benchmark::State &state, uint16_t *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_UNSIGNED_SHORT, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); } void EffectChainTester::benchmark_10_10_10_2(benchmark::State &state, uint32_t *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) { - internal_run(out_data, nullptr, nullptr, nullptr, GL_UNSIGNED_INT_2_10_10_10_REV, format, color_space, gamma_curve, alpha_format, &state); + internal_run(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); } #endif template -void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T *out_data4, GLenum internal_format, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format +void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format #ifdef HAVE_BENCHMARK , benchmark::State *benchmark_state #endif @@ -248,35 +248,22 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T num_outputs = 1; } - GLuint fbo, texnum[4]; - - glGenTextures(num_outputs, texnum); + glActiveTexture(GL_TEXTURE0); 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(); - } - glGenFramebuffers(1, &fbo); - check_error(); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - check_error(); + vector textures; for (unsigned i = 0; i < num_outputs; ++i) { - glFramebufferTexture2D( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0 + i, - GL_TEXTURE_2D, - texnum[i], - 0); + GLuint texnum = chain.get_resource_pool()->create_2d_texture(framebuffer_format, width, height); + textures.push_back(EffectChain::DestinationTexture{texnum, framebuffer_format}); + + // The output texture needs to have valid state to be written to by a compute shader. + glBindTexture(GL_TEXTURE_2D, texnum); + check_error(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); check_error(); } - GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; - glDrawBuffers(num_outputs, bufs); - - chain.render_to_fbo(fbo, width, height); + chain.render_to_texture(textures, width, height); #ifdef HAVE_BENCHMARK // If running benchmarks: Now we've warmed up everything, so let's run the @@ -285,7 +272,7 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T glFinish(); size_t iters = benchmark_state->max_iterations; for (auto _ : *benchmark_state) { - chain.render_to_fbo(fbo, width, height); + chain.render_to_texture(textures, width, height); if (--iters == 0) { glFinish(); } @@ -298,7 +285,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. @@ -331,10 +318,9 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T } } - glDeleteFramebuffers(1, &fbo); - check_error(); - 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)