Mesa (staging/18.1): i965/fs: Properly handle sign(-abs(x))
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jul 9 16:26:04 UTC 2018
Module: Mesa
Branch: staging/18.1
Commit: e7d4549ac039f93e90b707b6f50cb9a80bbd8789
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e7d4549ac039f93e90b707b6f50cb9a80bbd8789
Author: Ian Romanick <ian.d.romanick at intel.com>
Date: Tue Jun 26 15:11:21 2018 -0700
i965/fs: Properly handle sign(-abs(x))
Fixes new piglit tests:
- glsl-1.10/execution/fs-sign-neg-abs.shader_test
- glsl-1.10/execution/fs-sign-sat-neg-abs.shader_test
- glsl-1.10/execution/vs-sign-neg-abs.shader_test
- glsl-1.10/execution/vs-sign-sat-neg-abs.shader_test
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: mesa-stable at lists.freedesktop.org
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
(cherry picked from commit 88bd37c01060169b451ca2c3900830342d34a9a2)
---
src/intel/compiler/brw_fs_nir.cpp | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp
index 47e26f8ec4..8eb69b9a38 100644
--- a/src/intel/compiler/brw_fs_nir.cpp
+++ b/src/intel/compiler/brw_fs_nir.cpp
@@ -821,11 +821,20 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
case nir_op_fsign: {
if (op[0].abs) {
- /* Straightforward since the source can be assumed to be
- * non-negative.
+ /* Straightforward since the source can be assumed to be either
+ * strictly >= 0 or strictly <= 0 depending on the setting of the
+ * negate flag.
*/
set_condmod(BRW_CONDITIONAL_NZ, bld.MOV(result, op[0]));
- set_predicate(BRW_PREDICATE_NORMAL, bld.MOV(result, brw_imm_f(1.0f)));
+
+ inst = (op[0].negate)
+ ? bld.MOV(result, brw_imm_f(-1.0f))
+ : bld.MOV(result, brw_imm_f(1.0f));
+
+ set_predicate(BRW_PREDICATE_NORMAL, inst);
+
+ if (instr->dest.saturate)
+ inst->saturate = true;
} else if (type_sz(op[0].type) < 8) {
/* AND(val, 0x80000000) gives the sign bit.
More information about the mesa-commit
mailing list