nir: Move intel's half-float image store lowering to to nir_format.h.
authorEric Anholt <eric@anholt.net>
Tue, 11 Dec 2018 21:49:28 +0000 (13:49 -0800)
committerEric Anholt <eric@anholt.net>
Thu, 13 Dec 2018 20:24:26 +0000 (12:24 -0800)
I needed the same function for v3d.  This was originally in d3e046e76c06
("nir: Pull some of intel's image load/store format conversion to
nir_format.h") before we made am istake about simplifying the function.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_format_convert.h
src/intel/compiler/brw_nir_lower_image_load_store.c

index 7ebb7d50ca4797e4b95a09df8d7cd6c0b819eea3..9c8d0d21e0a89b694b7d7ee04a9740950a2e7196 100644 (file)
@@ -256,6 +256,19 @@ nir_format_float_to_snorm(nir_builder *b, nir_ssa_def *f, const unsigned *bits)
    return nir_f2i32(b, nir_fround_even(b, nir_fmul(b, f, factor)));
 }
 
+/* Converts a vector of floats to a vector of half-floats packed in the low 16
+ * bits.
+ */
+static inline nir_ssa_def *
+nir_format_float_to_half(nir_builder *b, nir_ssa_def *f)
+{
+   nir_ssa_def *zero = nir_imm_float(b, 0);
+   nir_ssa_def *f16comps[4];
+   for (unsigned i = 0; i < f->num_components; i++)
+      f16comps[i] = nir_pack_half_2x16_split(b, nir_channel(b, f, i), zero);
+   return nir_vec(b, f16comps, f->num_components);
+}
+
 static inline nir_ssa_def *
 nir_format_linear_to_srgb(nir_builder *b, nir_ssa_def *c)
 {
index 269dbf8e2835badd4ac6ab760965afca13b582f1..2abebceb2d1a37bf2a487a7a081c274f1b4be617 100644 (file)
@@ -544,14 +544,8 @@ convert_color_for_store(nir_builder *b, const struct gen_device_info *devinfo,
       break;
 
    case ISL_SFLOAT:
-      if (image.bits[0] == 16) {
-         nir_ssa_def *f16comps[4];
-         for (unsigned i = 0; i < image.chans; i++) {
-            f16comps[i] = nir_pack_half_2x16_split(b, nir_channel(b, color, i),
-                                                      nir_imm_float(b, 0));
-         }
-         color = nir_vec(b, f16comps, image.chans);
-      }
+      if (image.bits[0] == 16)
+         color = nir_format_float_to_half(b, color);
       break;
 
    case ISL_UINT: