nir/lower_double_ops: relax lower mod()
authorJuan A. Suarez Romero <jasuarez@igalia.com>
Tue, 10 Mar 2020 10:49:42 +0000 (10:49 +0000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 12 Mar 2020 16:42:52 +0000 (16:42 +0000)
commitacd0dd3b4b223a423fbe9ffd118c3fbbf119d993
treef6e660f525721bca846ead002a196d08dcf93357
parentb83c9aca4a5fd02d920c90c1799137fed52dc1d9
nir/lower_double_ops: relax lower mod()

Currently when lowering mod() we add an extra instruction so if
mod(a,b) == b then 0 is returned instead of b, as mathematically
mod(a,b) is in the interval [0, b).

But Vulkan spec has relaxed this restriction, and allows the result to
be in the interval [0, b].

For the OpenGL case, while the spec does not allow this behaviour, due
the allowed precision errors we can end up having the same result, so
from a practical point of view, this behaviour is allowed (see
https://github.com/KhronosGroup/VK-GL-CTS/issues/51).

This commit takes this in account to remove the extra instruction
required to return 0 instead.

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4118>
src/compiler/nir/nir_lower_double_ops.c