Module: Mesa
Branch: staging/22.2
Commit: f1328901300c196b5a90b6ce05f85b7ef28f5f09
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f1328901300c196b5a90b6ce05f85b7ef28f5f09

Author: Alyssa Rosenzweig <[email protected]>
Date:   Thu Oct 13 17:18:09 2022 -0400

nir: Fix nir_fmax_abs_vec_comp

This failed to take fabs of the first component, implementing an unintended
formula that would return the right results in some common cases but is wrong in
general:

   max { x, |y|, |z| }

instead of the intended

   max { |x|, |y|, |z| }

Reexpress the implementation to make correctness obvious.

Fixes: 272e927d0e9 ("nir/spirv: initial handling of OpenCL.std extension 
opcodes")
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Karol Herbst <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18754>
(cherry picked from commit fc5c671e8785c89cf986181e0e3e7fa8742c4dce)

---

 .pick_status.json                      | 2 +-
 src/compiler/nir/nir_builtin_builder.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index f842d6bf449..b28238c8f03 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -94,7 +94,7 @@
         "description": "nir: Fix nir_fmax_abs_vec_comp",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "272e927d0e9fed6e791d706ff5d895b6c2036fc0"
     },
diff --git a/src/compiler/nir/nir_builtin_builder.h 
b/src/compiler/nir/nir_builtin_builder.h
index 40983a26456..97a4e4d3010 100644
--- a/src/compiler/nir/nir_builtin_builder.h
+++ b/src/compiler/nir/nir_builtin_builder.h
@@ -62,9 +62,10 @@ nir_nan_check2(nir_builder *b, nir_ssa_def *x, nir_ssa_def 
*y, nir_ssa_def *res)
 static inline nir_ssa_def *
 nir_fmax_abs_vec_comp(nir_builder *b, nir_ssa_def *vec)
 {
-   nir_ssa_def *res = nir_channel(b, vec, 0);
+   nir_ssa_def *abs = nir_fabs(b, vec);
+   nir_ssa_def *res = nir_channel(b, abs, 0);
    for (unsigned i = 1; i < vec->num_components; ++i)
-      res = nir_fmax(b, res, nir_fabs(b, nir_channel(b, vec, i)));
+      res = nir_fmax(b, res, nir_channel(b, abs, i));
    return res;
 }
 

Reply via email to