From 4c2edecd7dc83caaaa37c797d66d9077e105eaee Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sat, 10 Feb 2018 22:42:11 +0100 Subject: vo_gpu: refactor HDR peak detection algorithm The major changes are as follows: 1. Use `uint32_t` instead of `unsigned int` for the SSBO size calculation. This doesn't really matter, since a too-big buffer will still work just fine, but since `uint` is a 32-bit integer by definition this is the correct way to do it. 2. Pre-divide the frame_sum by the num_wg immediately at the end of a frame. This change was made to prevent overflow. At 4K screen size, this code is currently already very at risk of overflow, especially once I started playing with longer averaging sizes. Pre-dividing this out makes it just about fit into 32-bit even for worst-case PQ content. (It's technically also faster and easier this way, so I should have done it to begin with). Rename `frame_sum` to `frame_avg` to clearly signal the change in semantics. 3. Implement a scene transition detection algorithm. This basically compares the current frame's average brightness against the (averaged) value of the past frames. If it exceeds a threshold, which I experimentally configured, we reset the peak detection SSBO's state immediately - so that it just contains the current frame. This prevents annoying "eye adaptation"-like effects on scene transitions. 4. As a result of the previous change, we can now use a much larger buffer size by default, which results in a more stable and less flickery result. I experimented with values between 20 and 256 and settled on the new value of 64. (I also switched to a power-of-2 array size, because I like powers of two) --- video/out/gpu/video.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'video/out/gpu/video.h') diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h index 71666059f9..dad6d447f6 100644 --- a/video/out/gpu/video.h +++ b/video/out/gpu/video.h @@ -96,7 +96,7 @@ enum tone_mapping { }; // How many frames to average over for HDR peak detection -#define PEAK_DETECT_FRAMES 20 +#define PEAK_DETECT_FRAMES 63 struct gl_video_opts { int dumb_mode; -- cgit v1.2.3