From: Steinar H. Gunderson Date: Thu, 28 Dec 2017 21:13:50 +0000 (+0100) Subject: Change the resampling tests to fp16 (arguably more useful). X-Git-Tag: 1.6.0~17 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=910df1ba510ad8dfda93e175d1d66d33e9519b19 Change the resampling tests to fp16 (arguably more useful). --- diff --git a/resample_effect_test.cpp b/resample_effect_test.cpp index b47bd57..84f61e7 100644 --- a/resample_effect_test.cpp +++ b/resample_effect_test.cpp @@ -8,6 +8,7 @@ #include "effect_chain.h" #include "flat_input.h" +#include "fp16.h" #include "image_format.h" #include "init.h" #include "resample_effect.h" @@ -431,6 +432,8 @@ TEST(ResampleEffectTest, Precision) { } #ifdef HAVE_BENCHMARK +template<> inline uint8_t from_fp32(float x) { return x; } + template void BM_ResampleEffect(benchmark::State &state, GammaCurve gamma_curve, GLenum output_format, const std::string &shader_type) { @@ -444,7 +447,7 @@ void BM_ResampleEffect(benchmark::State &state, GammaCurve gamma_curve, GLenum o unique_ptr out_data(new T[out_width * out_height * 4]); for (unsigned i = 0; i < in_width * in_height * 4; ++i) { - data[i] = rand(); + data[i] = from_fp32(float(rand())); } EffectChainTester tester(nullptr, out_width, out_height, FORMAT_BGRA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, gamma_curve, output_format); @@ -457,9 +460,9 @@ void BM_ResampleEffect(benchmark::State &state, GammaCurve gamma_curve, GLenum o tester.benchmark(state, out_data.get(), GL_BGRA, COLORSPACE_sRGB, gamma_curve, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED); } -void BM_ResampleEffectFloat(benchmark::State &state, GammaCurve gamma_curve, const std::string &shader_type) +void BM_ResampleEffectHalf(benchmark::State &state, GammaCurve gamma_curve, const std::string &shader_type) { - BM_ResampleEffect(state, gamma_curve, GL_RGBA16F, shader_type); + BM_ResampleEffect(state, gamma_curve, GL_RGBA16F, shader_type); } void BM_ResampleEffectInt8(benchmark::State &state, GammaCurve gamma_curve, const std::string &shader_type) @@ -468,9 +471,9 @@ void BM_ResampleEffectInt8(benchmark::State &state, GammaCurve gamma_curve, cons } BENCHMARK_CAPTURE(BM_ResampleEffectInt8, Int8Upscale, GAMMA_REC_709, "fragment")->Args({640, 360, 1280, 720})->Args({320, 180, 1280, 720})->Args({321, 181, 1280, 720})->UseRealTime()->Unit(benchmark::kMicrosecond); -BENCHMARK_CAPTURE(BM_ResampleEffectFloat, Float32Upscale, GAMMA_LINEAR, "fragment")->Args({640, 360, 1280, 720})->Args({320, 180, 1280, 720})->Args({321, 181, 1280, 720})->UseRealTime()->Unit(benchmark::kMicrosecond); +BENCHMARK_CAPTURE(BM_ResampleEffectHalf, Float16Upscale, GAMMA_LINEAR, "fragment")->Args({640, 360, 1280, 720})->Args({320, 180, 1280, 720})->Args({321, 181, 1280, 720})->UseRealTime()->Unit(benchmark::kMicrosecond); BENCHMARK_CAPTURE(BM_ResampleEffectInt8, Int8Downscale, GAMMA_REC_709, "fragment")->Args({1280, 720, 640, 360})->Args({1280, 720, 320, 180})->Args({1280, 720, 321, 181})->UseRealTime()->Unit(benchmark::kMicrosecond); -BENCHMARK_CAPTURE(BM_ResampleEffectFloat, Float32Downscale, GAMMA_LINEAR, "fragment")->Args({1280, 720, 640, 360})->Args({1280, 720, 320, 180})->Args({1280, 720, 321, 181})->UseRealTime()->Unit(benchmark::kMicrosecond); +BENCHMARK_CAPTURE(BM_ResampleEffectHalf, Float16Downscale, GAMMA_LINEAR, "fragment")->Args({1280, 720, 640, 360})->Args({1280, 720, 320, 180})->Args({1280, 720, 321, 181})->UseRealTime()->Unit(benchmark::kMicrosecond); void BM_ComputeScalingWeights(benchmark::State &state) { diff --git a/test_util.cpp b/test_util.cpp index 14f8966..30ba94a 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -89,6 +89,25 @@ Input *EffectChainTester::add_input(const float *data, MovitPixelFormat pixel_fo return input; } +Input *EffectChainTester::add_input(const fp16_int_t *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_HALF_FLOAT, input_width, input_height); + input->set_pixel_data_fp16(data); + chain.add_input(input); + return input; +} + 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; @@ -180,6 +199,26 @@ void EffectChainTester::benchmark(benchmark::State &state, float *out_data, floa internal_run(out_data, out_data2, out_data3, out_data4, 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(out_data, nullptr, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); +} + +void EffectChainTester::benchmark(benchmark::State &state, fp16_int_t *out_data, fp16_int_t *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) +{ + internal_run(out_data, out_data2, nullptr, nullptr, format, color_space, gamma_curve, alpha_format, &state); +} + +void EffectChainTester::benchmark(benchmark::State &state, fp16_int_t *out_data, fp16_int_t *out_data2, fp16_int_t *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) +{ + internal_run(out_data, out_data2, out_data3, nullptr, format, color_space, gamma_curve, alpha_format, &state); +} + +void EffectChainTester::benchmark(benchmark::State &state, fp16_int_t *out_data, fp16_int_t *out_data2, fp16_int_t *out_data3, fp16_int_t *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format) +{ + 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, format, color_space, gamma_curve, alpha_format, &state); @@ -228,6 +267,8 @@ void EffectChainTester::internal_run(T *out_data, T *out_data2, T *out_data3, T 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) { diff --git a/test_util.h b/test_util.h index 985fec4..f50f579 100644 --- a/test_util.h +++ b/test_util.h @@ -6,6 +6,7 @@ #include #endif #include "effect_chain.h" +#include "fp16.h" #include "image_format.h" namespace movit { @@ -23,6 +24,7 @@ public: EffectChain *get_chain() { return &chain; } Input *add_input(const float *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, int input_width = -1, int input_height = -1); + Input *add_input(const fp16_int_t *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, int input_width = -1, int input_height = -1); Input *add_input(const unsigned char *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, int input_width = -1, int input_height = -1); void run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); @@ -41,6 +43,10 @@ public: void benchmark(benchmark::State &state, float *out_data, float *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); void benchmark(benchmark::State &state, float *out_data, float *out_data2, float *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); void 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 = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); + void benchmark(benchmark::State &state, fp16_int_t *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); + void benchmark(benchmark::State &state, fp16_int_t *out_data, fp16_int_t *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); + void benchmark(benchmark::State &state, fp16_int_t *out_data, fp16_int_t *out_data2, fp16_int_t *out_data3, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); + void benchmark(benchmark::State &state, fp16_int_t *out_data, fp16_int_t *out_data2, fp16_int_t *out_data3, fp16_int_t *out_data4, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); void benchmark(benchmark::State &state, unsigned char *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); void benchmark(benchmark::State &state, unsigned char *out_data, unsigned char *out_data2, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED); void 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 = OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);