+Input *EffectChainTester::add_input(const unsigned char *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, int input_width, int input_height)
+{
+ ImageFormat format;
+ format.color_space = color_space;
+ format.gamma_curve = gamma_curve;
+
+ if (input_width == -1) {
+ input_width = width;
+ }
+ if (input_height == -1) {
+ input_height = height;
+ }
+
+ FlatInput *input = new FlatInput(format, pixel_format, GL_UNSIGNED_BYTE, input_width, input_height);
+ input->set_pixel_data(data);
+ chain.add_input(input);
+ return input;
+}
+
+void EffectChainTester::run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<float>({out_data}, format, color_space, gamma_curve, alpha_format);
+}
+
+void EffectChainTester::run(const std::vector<float *> &out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<float>(out_data, 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<unsigned char>({out_data}, format, color_space, gamma_curve, alpha_format);
+}
+
+void EffectChainTester::run(const std::vector<unsigned char *> &out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<unsigned char>(out_data, 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<uint16_t>({out_data}, 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<uint32_t>({out_data}, 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<float>({out_data}, format, color_space, gamma_curve, alpha_format, &state);
+}
+
+void EffectChainTester::benchmark(benchmark::State &state, const std::vector<float *> &out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<float>(out_data, format, color_space, gamma_curve, alpha_format, &state);
+}
+
+void EffectChainTester::benchmark(benchmark::State &state, fp16_int_t *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<fp16_int_t>({out_data}, format, color_space, gamma_curve, alpha_format, &state);
+}
+
+void EffectChainTester::benchmark(benchmark::State &state, const std::vector<fp16_int_t *> &out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<fp16_int_t>(out_data, 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<unsigned char>({out_data}, format, color_space, gamma_curve, alpha_format, &state);
+}
+
+void EffectChainTester::benchmark(benchmark::State &state, const std::vector<unsigned char *> &out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format)
+{
+ internal_run<unsigned char>(out_data, 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<uint16_t>({out_data}, 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<uint32_t>({out_data}, format, color_space, gamma_curve, alpha_format, &state);
+}
+
+#endif
+
+template<class T>
+void EffectChainTester::internal_run(const std::vector<T *> &out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format
+#ifdef HAVE_BENCHMARK
+, benchmark::State *benchmark_state
+#endif
+)
+{
+ if (!finalized) {
+ finalize_chain(color_space, gamma_curve, alpha_format);
+ }
+
+ GLuint type;
+ if (framebuffer_format == GL_RGBA8) {
+ type = GL_UNSIGNED_BYTE;
+ } else if (framebuffer_format == GL_RGBA16) {
+ type = GL_UNSIGNED_SHORT;
+ } else if (framebuffer_format == GL_RGBA16F && sizeof(T) == 2) {
+ type = GL_HALF_FLOAT;
+ } else if (framebuffer_format == GL_RGBA16F || framebuffer_format == GL_RGBA32F) {
+ type = GL_FLOAT;
+ } else if (framebuffer_format == GL_RGB10_A2) {
+ type = GL_UNSIGNED_INT_2_10_10_10_REV;
+ } else {
+ // Add more here as needed.
+ assert(false);
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ check_error();
+
+ vector<EffectChain::DestinationTexture> textures;
+ for (unsigned i = 0; i < out_data.size(); ++i) {
+ 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();
+ }
+
+ chain.render_to_texture(textures, width, height);
+
+#ifdef HAVE_BENCHMARK
+ // If running benchmarks: Now we've warmed up everything, so let's run the
+ // actual benchmark loop.
+ if (benchmark_state != nullptr) {
+ glFinish();
+ size_t iters = benchmark_state->max_iterations;
+ for (auto _ : *benchmark_state) {
+ chain.render_to_texture(textures, width, height);
+ if (--iters == 0) {
+ glFinish();
+ }