panfrost: Demote mediump varyings to fp16
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 9 Jun 2020 22:15:20 +0000 (18:15 -0400)
committerMarge Bot <eric+marge@anholt.net>
Fri, 12 Jun 2020 14:45:50 +0000 (14:45 +0000)
Likewise lowp.

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

src/gallium/drivers/panfrost/pan_assemble.c

index 7d0f07a0dd100644a098ed0ca5e620f42d470d5a..8a6caead34c5a9262055c4af18def9e9201db4b9 100644 (file)
@@ -77,7 +77,7 @@ pan_format_from_nir_size(nir_alu_type base, unsigned size)
 }
 
 static enum mali_format
-pan_format_from_glsl(const struct glsl_type *type, unsigned frac)
+pan_format_from_glsl(const struct glsl_type *type, unsigned precision, unsigned frac)
 {
         const struct glsl_type *column = glsl_without_array_or_matrix(type);
         enum glsl_base_type glsl_base = glsl_get_base_type(column);
@@ -95,6 +95,19 @@ pan_format_from_glsl(const struct glsl_type *type, unsigned frac)
         unsigned base = nir_alu_type_get_base_type(t);
         unsigned size = nir_alu_type_get_type_size(t);
 
+        /* Demote to fp16 where possible. int16 varyings are TODO as the hw
+         * will saturate instead of wrap which is not conformant, so we need to
+         * insert i2i16/u2u16 instructions before the st_vary_32i/32u to get
+         * the intended behaviour */
+
+        bool is_16 = (precision == GLSL_PRECISION_MEDIUM)
+                || (precision == GLSL_PRECISION_LOW);
+
+        if (is_16 && base == nir_type_float)
+                size = 16;
+        else
+                size = 32;
+
         return pan_format_from_nir_base(base) |
                 pan_format_from_nir_size(base, size) |
                 MALI_NR_CHANNELS(chan);
@@ -263,7 +276,8 @@ panfrost_shader_compile(struct panfrost_context *ctx,
 
                 for (int c = 0; c < sz; ++c) {
                         state->varyings_loc[loc + c] = var->data.location + c;
-                        state->varyings[loc + c] = pan_format_from_glsl(var->type, var->data.location_frac);
+                        state->varyings[loc + c] = pan_format_from_glsl(var->type,
+                                        var->data.precision, var->data.location_frac);
                 }
         }
 }