1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-21 15:27:00 +00:00

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'
This commit is contained in:
sfan5 2018-09-23 00:29:44 +02:00 committed by Jan Ekström
parent 9dbab9661c
commit a4c5a4486e

View File

@ -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