From a4c5a4486e5897cd6fb5d8136ec1ea031a3e045a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 23 Sep 2018 00:29:44 +0200 Subject: vo_gpu: adjust PRNG variant used by GL shaders Certain low-end Mali GPUs have a rather low precision and overflow during the PRNG calculations, thereby breaking e.g. deband-grain. Modify the permute() to avoid this, this does not impact the quality of PRNG output (noticeably). This problem was observed on: GL_VENDOR='ARM', GL_RENDERER='Mali-T720' GL_VERSION='OpenGL ES 3.1 v1.r15p0-00rel0.bdd9e62cdc8c88e0610a16b5901161e9' --- video/out/gpu/video_shaders.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/video/out/gpu/video_shaders.c b/video/out/gpu/video_shaders.c index 2b18d172db..342fb39ded 100644 --- a/video/out/gpu/video_shaders.c +++ b/video/out/gpu/video_shaders.c @@ -833,10 +833,14 @@ void pass_color_map(struct gl_shader_cache *sc, // Wide usage friendly PRNG, shamelessly stolen from a GLSL tricks forum post. // Obtain random numbers by calling rand(h), followed by h = permute(h) to // update the state. Assumes the texture was hooked. +// permute() was modified from the original to avoid "large" numbers in +// calculations, since low-end mobile GPUs choke on them (overflow). static void prng_init(struct gl_shader_cache *sc, AVLFG *lfg) { GLSLH(float mod289(float x) { return x - floor(x * 1.0/289.0) * 289.0; }) - GLSLH(float permute(float x) { return mod289((34.0*x + 1.0) * x); }) + GLSLHF("float permute(float x) {\n"); + GLSLH(return mod289( mod289(34.0*x + 1.0) * (fract(x) + 1.0) );) + GLSLHF("}\n"); GLSLH(float rand(float x) { return fract(x * 1.0/41.0); }) // Initialize the PRNG by hashing the position + a random uniform -- cgit v1.2.3