Mesa (main): nir/lower_blend: Use correct clamp for SNORM

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 26 19:41:52 UTC 2021


Module: Mesa
Branch: main
Commit: d8b1afdc85078faee96cd1f8dd6f188843c0d705
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d8b1afdc85078faee96cd1f8dd6f188843c0d705

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Fri Oct 22 21:12:59 2021 -0400

nir/lower_blend: Use correct clamp for SNORM

nir_lower_blend was written against the OpenGL ES 3.2 specification,
which does not support blending SNORM render targets. The ES spec
says that non-floating point buffers get clamped to [0, 1] before
blending. The story is not so simple: SNORM buffers are blendable in
OpenGL and must clamped to [-1, 1] rather than [0, 1]. Handle this case.

NIR does have the fsat_signed_mali instruction to clamp to [-1, 1], but
it is only implemented in Panfrost, and this pass is in common code.
Open code it instead. Panfrost optimizes the open coded version, so this
is good enough.

Fixes SNORM subtests of Piglit arb_texture_view-rendering-formats.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Reviewed-by: Boris Brezillon <boris.brezillon at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13499>

---

 src/compiler/nir/nir_lower_blend.c            | 19 ++++++++++++++++++-
 src/panfrost/ci/piglit-panfrost-g52-fails.txt |  6 ------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/compiler/nir/nir_lower_blend.c b/src/compiler/nir/nir_lower_blend.c
index 5e6a04f0ec7..dc19b02c43a 100644
--- a/src/compiler/nir/nir_lower_blend.c
+++ b/src/compiler/nir/nir_lower_blend.c
@@ -247,6 +247,13 @@ nir_blend_logicop(
    return out;
 }
 
+static nir_ssa_def *
+nir_fsat_signed(nir_builder *b, nir_ssa_def *x)
+{
+   return nir_fclamp(b, x, nir_imm_floatN_t(b, -1.0, x->bit_size),
+                           nir_imm_floatN_t(b, +1.0, x->bit_size));
+}
+
 /* Given a blend state, the source color, and the destination color,
  * return the blended color
  */
@@ -276,8 +283,18 @@ nir_blend(
    /* Fixed-point framebuffers require their inputs clamped. */
    enum pipe_format format = options.format[rt];
 
-   if (!util_format_is_float(format))
+   /* From section 17.3.6 "Blending" of the OpenGL 4.5 spec:
+    *
+    *     If the color buffer is fixed-point, the components of the source and
+    *     destination values and blend factors are each clamped to [0, 1] or
+    *     [-1, 1] respectively for an unsigned normalized or signed normalized
+    *     color buffer prior to evaluating the blend equation. If the color
+    *     buffer is floating-point, no clamping occurs.
+    */
+   if (util_format_is_unorm(format))
       src = nir_fsat(b, src);
+   else if (util_format_is_snorm(format))
+      src = nir_fsat_signed(b, src);
 
    /* DST_ALPHA reads back 1.0 if there is no alpha channel */
    const struct util_format_description *desc =
diff --git a/src/panfrost/ci/piglit-panfrost-g52-fails.txt b/src/panfrost/ci/piglit-panfrost-g52-fails.txt
index b5203451f39..67b89ce7e49 100644
--- a/src/panfrost/ci/piglit-panfrost-g52-fails.txt
+++ b/src/panfrost/ci/piglit-panfrost-g52-fails.txt
@@ -400,12 +400,6 @@ spec at arb_texture_rg@texwrap formats-float bordercolor-swizzled at GL_R16F- swizzled
 spec at arb_texture_rg@texwrap formats-float bordercolor-swizzled at GL_R32F- swizzled- border color only,Fail
 spec at arb_texture_rg@texwrap formats-float bordercolor-swizzled at GL_RG16F- swizzled- border color only,Fail
 spec at arb_texture_rg@texwrap formats-float bordercolor-swizzled at GL_RG32F- swizzled- border color only,Fail
-spec at arb_texture_view@rendering-formats at render to GL_RG32F as GL_RGBA16_SNORM,Fail
-spec at arb_texture_view@rendering-formats at render to GL_RG32I as GL_RGBA16_SNORM,Fail
-spec at arb_texture_view@rendering-formats at render to GL_RG32UI as GL_RGBA16_SNORM,Fail
-spec at arb_texture_view@rendering-formats at render to GL_RGBA16F as GL_RGBA16_SNORM,Fail
-spec at arb_texture_view@rendering-formats at render to GL_RGBA16I as GL_RGBA16_SNORM,Fail
-spec at arb_texture_view@rendering-formats at render to GL_RGBA16UI as GL_RGBA16_SNORM,Fail
 spec at arb_texture_view@sampling-2d-array-as-cubemap-array,Crash
 spec at arb_texture_view@sampling-2d-array-as-cubemap,Crash
 spec at arb_transform_feedback_instanced@draw-auto instanced,Fail



More information about the mesa-commit mailing list