Mesa (staging/21.0): tgsi_exec: Fix NaN behavior of min and max
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Apr 27 16:37:53 UTC 2021
Module: Mesa
Branch: staging/21.0
Commit: 4ad22a053f72a4902e67b976d1874ba66dfa8752
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4ad22a053f72a4902e67b976d1874ba66dfa8752
Author: Ian Romanick <ian.d.romanick at intel.com>
Date: Thu Apr 22 17:46:39 2021 -0700
tgsi_exec: Fix NaN behavior of min and max
Modern shader APIs, like DX10 and GLSL 1.30, want min() and max() to
"cleanse" NaN. If one source is NaN, the other value should be chosen.
If both sources are NaN, the result may be either.
There are many cases where TGSI is generate from NIR, and many
optimizations in NIR expect this behavior. Not meeting these
expectations can lead to unexpected results.
Reviewed-by: Eric Anholt <eric at anholt.net>
Fixes: ffe58739da9 ("Softpipe: import TGSI tree. Not hooked-up yet.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10419>
(cherry picked from commit 939bf7a4198cecff57510b7fe5d38ef9b5dd22be)
Conflicts:
.gitlab-ci/piglit/softpipe-quick.txt
---
.gitlab-ci/piglit/softpipe-quick.txt | 1 -
.pick_status.json | 2 +-
src/gallium/auxiliary/tgsi/tgsi_exec.c | 32 ++++++++++++++++----------------
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/.gitlab-ci/piglit/softpipe-quick.txt b/.gitlab-ci/piglit/softpipe-quick.txt
index d500fb01306..2159d3acc8e 100644
--- a/.gitlab-ci/piglit/softpipe-quick.txt
+++ b/.gitlab-ci/piglit/softpipe-quick.txt
@@ -2718,7 +2718,6 @@ spec/glsl-1.10/execution/loops/glsl-fs-unroll-explosion: crash
spec/glsl-1.10/execution/loops/glsl-vs-unroll-explosion: crash
spec/glsl-1.10/preprocessor/extension-defined-test: skip
spec/glsl-1.10/preprocessor/extension-if-1: skip
-spec/glsl-1.10/preprocessor/if-eq: skip
spec/glsl-1.30/execution/tex-miplevel-selection texturegrad 1d: fail
spec/glsl-1.30/execution/tex-miplevel-selection texturegrad 1darray: fail
spec/glsl-1.30/execution/tex-miplevel-selection texturegrad 1darrayshadow: fail
diff --git a/.pick_status.json b/.pick_status.json
index 6c12b57ace7..0ec63cc09ec 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -949,7 +949,7 @@
"description": "tgsi_exec: Fix NaN behavior of min and max",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "ffe58739da9eee2e99682747cc8f26e412c87430"
},
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 08be2e95688..c35437343fe 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -263,20 +263,20 @@ static void
micro_dmax(union tgsi_double_channel *dst,
const union tgsi_double_channel *src)
{
- dst->d[0] = src[0].d[0] > src[1].d[0] ? src[0].d[0] : src[1].d[0];
- dst->d[1] = src[0].d[1] > src[1].d[1] ? src[0].d[1] : src[1].d[1];
- dst->d[2] = src[0].d[2] > src[1].d[2] ? src[0].d[2] : src[1].d[2];
- dst->d[3] = src[0].d[3] > src[1].d[3] ? src[0].d[3] : src[1].d[3];
+ dst->d[0] = src[0].d[0] > src[1].d[0] || isnan(src[1].d[0]) ? src[0].d[0] : src[1].d[0];
+ dst->d[1] = src[0].d[1] > src[1].d[1] || isnan(src[1].d[1]) ? src[0].d[1] : src[1].d[1];
+ dst->d[2] = src[0].d[2] > src[1].d[2] || isnan(src[1].d[2]) ? src[0].d[2] : src[1].d[2];
+ dst->d[3] = src[0].d[3] > src[1].d[3] || isnan(src[1].d[3]) ? src[0].d[3] : src[1].d[3];
}
static void
micro_dmin(union tgsi_double_channel *dst,
const union tgsi_double_channel *src)
{
- dst->d[0] = src[0].d[0] < src[1].d[0] ? src[0].d[0] : src[1].d[0];
- dst->d[1] = src[0].d[1] < src[1].d[1] ? src[0].d[1] : src[1].d[1];
- dst->d[2] = src[0].d[2] < src[1].d[2] ? src[0].d[2] : src[1].d[2];
- dst->d[3] = src[0].d[3] < src[1].d[3] ? src[0].d[3] : src[1].d[3];
+ dst->d[0] = src[0].d[0] < src[1].d[0] || isnan(src[1].d[0]) ? src[0].d[0] : src[1].d[0];
+ dst->d[1] = src[0].d[1] < src[1].d[1] || isnan(src[1].d[1]) ? src[0].d[1] : src[1].d[1];
+ dst->d[2] = src[0].d[2] < src[1].d[2] || isnan(src[1].d[2]) ? src[0].d[2] : src[1].d[2];
+ dst->d[3] = src[0].d[3] < src[1].d[3] || isnan(src[1].d[3]) ? src[0].d[3] : src[1].d[3];
}
static void
@@ -1357,10 +1357,10 @@ micro_max(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src0,
const union tgsi_exec_channel *src1)
{
- dst->f[0] = src0->f[0] > src1->f[0] ? src0->f[0] : src1->f[0];
- dst->f[1] = src0->f[1] > src1->f[1] ? src0->f[1] : src1->f[1];
- dst->f[2] = src0->f[2] > src1->f[2] ? src0->f[2] : src1->f[2];
- dst->f[3] = src0->f[3] > src1->f[3] ? src0->f[3] : src1->f[3];
+ dst->f[0] = src0->f[0] > src1->f[0] || isnan(src1->f[0]) ? src0->f[0] : src1->f[0];
+ dst->f[1] = src0->f[1] > src1->f[1] || isnan(src1->f[1]) ? src0->f[1] : src1->f[1];
+ dst->f[2] = src0->f[2] > src1->f[2] || isnan(src1->f[2]) ? src0->f[2] : src1->f[2];
+ dst->f[3] = src0->f[3] > src1->f[3] || isnan(src1->f[3]) ? src0->f[3] : src1->f[3];
}
static void
@@ -1368,10 +1368,10 @@ micro_min(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src0,
const union tgsi_exec_channel *src1)
{
- dst->f[0] = src0->f[0] < src1->f[0] ? src0->f[0] : src1->f[0];
- dst->f[1] = src0->f[1] < src1->f[1] ? src0->f[1] : src1->f[1];
- dst->f[2] = src0->f[2] < src1->f[2] ? src0->f[2] : src1->f[2];
- dst->f[3] = src0->f[3] < src1->f[3] ? src0->f[3] : src1->f[3];
+ dst->f[0] = src0->f[0] < src1->f[0] || isnan(src1->f[0]) ? src0->f[0] : src1->f[0];
+ dst->f[1] = src0->f[1] < src1->f[1] || isnan(src1->f[1]) ? src0->f[1] : src1->f[1];
+ dst->f[2] = src0->f[2] < src1->f[2] || isnan(src1->f[2]) ? src0->f[2] : src1->f[2];
+ dst->f[3] = src0->f[3] < src1->f[3] || isnan(src1->f[3]) ? src0->f[3] : src1->f[3];
}
static void
More information about the mesa-commit
mailing list