nir: Add lowering of nir_op_unpack_half_2x16.
authorMatt Turner <mattst88@gmail.com>
Thu, 21 Jan 2016 23:46:47 +0000 (15:46 -0800)
committerMatt Turner <mattst88@gmail.com>
Mon, 25 Jan 2016 19:11:56 +0000 (11:11 -0800)
src/glsl/nir/nir.h
src/glsl/nir/nir_lower_alu_to_scalar.c

index e2bd2bfa02555dadb9601216be7cd811d0261375..111303041709acf203600f00bb45f267e0db25cb 100644 (file)
@@ -1468,6 +1468,9 @@ typedef struct nir_shader_compiler_options {
    /** lowers ffract to fsub+ffloor: */
    bool lower_ffract;
 
+   bool lower_pack_half_2x16;
+   bool lower_unpack_half_2x16;
+
    /**
     * Does the driver support real 32-bit integers?  (Otherwise, integers
     * are simulated by floats.)
index 0a27e66cf0f596b24714172b60799eaf6e59895e..5372fbeed88403c6033477e208e24e2da8fa8bf3 100644 (file)
@@ -97,6 +97,20 @@ lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b)
        */
       return;
 
+   case nir_op_pack_half_2x16:
+      if (!b->shader->options->lower_pack_half_2x16)
+         return;
+
+      nir_ssa_def *val =
+         nir_pack_half_2x16_split(b, nir_channel(b, instr->src[0].src.ssa,
+                                                 instr->src[0].swizzle[0]),
+                                     nir_channel(b, instr->src[0].src.ssa,
+                                                 instr->src[0].swizzle[1]));
+
+      nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(val));
+      nir_instr_remove(&instr->instr);
+      return;
+
    case nir_op_unpack_unorm_4x8:
    case nir_op_unpack_snorm_4x8:
    case nir_op_unpack_unorm_2x16:
@@ -106,11 +120,19 @@ lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b)
        */
       return;
 
-   case nir_op_unpack_half_2x16:
-      /* We could split this into unpack_half_2x16_split_[xy], but should
-       * we?
-       */
+   case nir_op_unpack_half_2x16: {
+      if (!b->shader->options->lower_unpack_half_2x16)
+         return;
+
+      nir_ssa_def *comps[2];
+      comps[0] = nir_unpack_half_2x16_split_x(b, instr->src[0].src.ssa);
+      comps[1] = nir_unpack_half_2x16_split_y(b, instr->src[0].src.ssa);
+      nir_ssa_def *vec = nir_vec(b, comps, 2);
+
+      nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(vec));
+      nir_instr_remove(&instr->instr);
       return;
+   }
 
    case nir_op_fdph: {
       nir_ssa_def *sum[4];