Mesa (master): panfrost: Clamp pure int pixels

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 13 14:04:06 UTC 2020


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

Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date:   Fri Jul 10 13:57:58 2020 -0400

panfrost: Clamp pure int pixels

We need saturate, not wrap semantic. Could optimize to a .isat/.usat
modifier but that's for future.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5755>

---

 src/gallium/drivers/panfrost/pan_blend_shaders.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c
index 29763251848..1e9d7d474cb 100644
--- a/src/gallium/drivers/panfrost/pan_blend_shaders.c
+++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c
@@ -123,6 +123,12 @@ nir_make_options(const struct pipe_blend_state *blend, unsigned i)
         return options;
 }
 
+static nir_ssa_def *
+nir_iclamp(nir_builder *b, nir_ssa_def *v, int32_t lo, int32_t hi)
+{
+        return nir_imin(b, nir_imax(b, v, nir_imm_int(b, lo)), nir_imm_int(b, hi));
+}
+
 struct panfrost_blend_shader
 panfrost_compile_blend_shader(
         struct panfrost_context *ctx,
@@ -178,13 +184,13 @@ panfrost_compile_blend_shader(
         if (T == nir_type_float16)
                 s_src = nir_f2f16(b, s_src);
         else if (T == nir_type_int16)
-                s_src = nir_i2i16(b, s_src);
+                s_src = nir_i2i16(b, nir_iclamp(b, s_src, -32768, 32767));
         else if (T == nir_type_uint16)
-                s_src = nir_u2u16(b, s_src);
+                s_src = nir_u2u16(b, nir_umin(b, s_src, nir_imm_int(b, 65535)));
         else if (T == nir_type_int8)
-                s_src = nir_i2i8(b, s_src);
+                s_src = nir_i2i8(b, nir_iclamp(b, s_src, -128, 127));
         else if (T == nir_type_uint8)
-                s_src = nir_u2u8(b, s_src);
+                s_src = nir_u2u8(b, nir_umin(b, s_src, nir_imm_int(b, 255)));
 
         /* Build a trivial blend shader */
         nir_store_var(b, c_out, s_src, 0xFF);



More information about the mesa-commit mailing list