Mesa (master): nir/lower_double_ops: add note for lowering mod

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 26 11:10:46 UTC 2020


Module: Mesa
Branch: master
Commit: 784c454607be3e8dc395de429d9b99521d5ef8a8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=784c454607be3e8dc395de429d9b99521d5ef8a8

Author: Juan A. Suarez Romero <jasuarez at igalia.com>
Date:   Wed Jan  8 10:48:29 2020 +0000

nir/lower_double_ops: add note for lowering mod

Add a note to clarify that while Vulkan allows mod(x,y) to be in [0, y]
range, OpenGL does not allow it, so the lowering ensures the result is
always in [0, y) range, as this lowering is shared by the Vulkan and
OpenGL implementation.

Reviewed-by: Elie Tournier <elie.tournier at collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3315>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3315>

---

 src/compiler/nir/nir_lower_double_ops.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c
index 322ae49bacd..e0617211d45 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -427,6 +427,10 @@ lower_mod(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1)
     * If the division is lowered, it could add some rounding errors that make
     * floor() to return the quotient minus one when x = N * y. If this is the
     * case, we return zero because mod(x, y) output value is [0, y).
+    *
+    * Worth to note that Vulkan allows the output value to be in range [0, y],
+    * so mod(x, y) could return y; but as OpenGL does not allow this, we add
+    * the extra instruction to ensure the value is always in [0, y).
     */
    nir_ssa_def *floor = nir_ffloor(b, nir_fdiv(b, src0, src1));
    nir_ssa_def *mod = nir_fsub(b, src0, nir_fmul(b, src1, floor));



More information about the mesa-commit mailing list