nir: improvements to native_integers removal
[mesa.git] / src / mesa / program / prog_to_nir.c
index 9d4f6d63dccf4cf976782afb1dcb4acef0dcb193..a5ac37af9089ced7108cd9b50830190a1cf5833a 100644 (file)
@@ -62,7 +62,7 @@ struct ptn_compile {
 
 #define SWIZ(X, Y, Z, W) \
    (unsigned[4]){ SWIZZLE_##X, SWIZZLE_##Y, SWIZZLE_##Z, SWIZZLE_##W }
-#define ptn_channel(b, src, ch) nir_swizzle(b, src, SWIZ(ch, ch, ch, ch), 1, true)
+#define ptn_channel(b, src, ch) nir_channel(b, src, SWIZZLE_##ch)
 
 static nir_ssa_def *
 ptn_src_for_dest(struct ptn_compile *c, nir_alu_dest *dest)
@@ -83,7 +83,7 @@ ptn_src_for_dest(struct ptn_compile *c, nir_alu_dest *dest)
    for (int i = 0; i < 4; i++)
       src.swizzle[i] = i;
 
-   return nir_fmov_alu(b, src, 4);
+   return nir_mov_alu(b, src, 4);
 }
 
 static nir_alu_dest
@@ -205,7 +205,7 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
       for (int i = 0; i < 4; i++)
          src.swizzle[i] = GET_SWZ(prog_src->Swizzle, i);
 
-      def = nir_fmov_alu(b, src, 4);
+      def = nir_mov_alu(b, src, 4);
 
       if (prog_src->Negate)
          def = nir_fneg(b, def);
@@ -222,7 +222,7 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
             chans[i] = nir_imm_float(b, 1.0);
          } else {
             assert(swizzle != SWIZZLE_NIL);
-            nir_alu_instr *mov = nir_alu_instr_create(b->shader, nir_op_fmov);
+            nir_alu_instr *mov = nir_alu_instr_create(b->shader, nir_op_mov);
             nir_ssa_dest_init(&mov->instr, &mov->dest.dest, 1, 32, NULL);
             mov->dest.write_mask = 0x1;
             mov->src[0] = src;
@@ -262,7 +262,7 @@ ptn_move_dest_masked(nir_builder *b, nir_alu_dest dest,
    if (!(dest.write_mask & write_mask))
       return;
 
-   nir_alu_instr *mov = nir_alu_instr_create(b->shader, nir_op_fmov);
+   nir_alu_instr *mov = nir_alu_instr_create(b->shader, nir_op_mov);
    if (!mov)
       return;
 
@@ -336,8 +336,8 @@ ptn_dst(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
 {
    ptn_move_dest_masked(b, dest, nir_imm_float(b, 1.0), WRITEMASK_X);
    ptn_move_dest_masked(b, dest, nir_fmul(b, src[0], src[1]), WRITEMASK_Y);
-   ptn_move_dest_masked(b, dest, nir_fmov(b, src[0]), WRITEMASK_Z);
-   ptn_move_dest_masked(b, dest, nir_fmov(b, src[1]), WRITEMASK_W);
+   ptn_move_dest_masked(b, dest, nir_mov(b, src[0]), WRITEMASK_Z);
+   ptn_move_dest_masked(b, dest, nir_mov(b, src[1]), WRITEMASK_W);
 }
 
 /* LIT - Light Coefficients
@@ -362,18 +362,10 @@ ptn_lit(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
       nir_ssa_def *pow = nir_fpow(b, nir_fmax(b, src0_y, nir_imm_float(b, 0.0)),
                                   wclamp);
 
-      nir_ssa_def *z;
-      if (b->shader->options->native_integers) {
-         z = nir_bcsel(b,
-                       nir_fge(b, nir_imm_float(b, 0.0), ptn_channel(b, src[0], X)),
-                       nir_imm_float(b, 0.0),
-                       pow);
-      } else {
-         z = nir_fcsel(b,
-                       nir_sge(b, nir_imm_float(b, 0.0), ptn_channel(b, src[0], X)),
-                       nir_imm_float(b, 0.0),
-                       pow);
-      }
+      nir_ssa_def *z = nir_bcsel(b,
+                                 nir_fge(b, nir_imm_float(b, 0.0), ptn_channel(b, src[0], X)),
+                                 nir_imm_float(b, 0.0),
+                                 pow);
 
       ptn_move_dest_masked(b, dest, z, WRITEMASK_Z);
    }
@@ -396,30 +388,16 @@ ptn_scs(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
    ptn_move_dest_masked(b, dest, nir_imm_float(b, 1.0), WRITEMASK_W);
 }
 
-/**
- * Emit SLT.  For platforms with integers, prefer b2f(flt(...)).
- */
 static void
 ptn_slt(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
 {
-   if (b->shader->options->native_integers) {
-      ptn_move_dest(b, dest, nir_b2f32(b, nir_flt(b, src[0], src[1])));
-   } else {
-      ptn_move_dest(b, dest, nir_slt(b, src[0], src[1]));
-   }
+   ptn_move_dest(b, dest, nir_slt(b, src[0], src[1]));
 }
 
-/**
- * Emit SGE.  For platforms with integers, prefer b2f(fge(...)).
- */
 static void
 ptn_sge(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
 {
-   if (b->shader->options->native_integers) {
-      ptn_move_dest(b, dest, nir_b2f32(b, nir_fge(b, src[0], src[1])));
-   } else {
-      ptn_move_dest(b, dest, nir_sge(b, src[0], src[1]));
-   }
+   ptn_move_dest(b, dest, nir_sge(b, src[0], src[1]));
 }
 
 static void
@@ -428,11 +406,11 @@ ptn_xpd(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
    ptn_move_dest_masked(b, dest,
                         nir_fsub(b,
                                  nir_fmul(b,
-                                          nir_swizzle(b, src[0], SWIZ(Y, Z, X, W), 3, true),
-                                          nir_swizzle(b, src[1], SWIZ(Z, X, Y, W), 3, true)),
+                                          nir_swizzle(b, src[0], SWIZ(Y, Z, X, W), 3),
+                                          nir_swizzle(b, src[1], SWIZ(Z, X, Y, W), 3)),
                                  nir_fmul(b,
-                                          nir_swizzle(b, src[1], SWIZ(Y, Z, X, W), 3, true),
-                                          nir_swizzle(b, src[0], SWIZ(Z, X, Y, W), 3, true))),
+                                          nir_swizzle(b, src[1], SWIZ(Y, Z, X, W), 3),
+                                          nir_swizzle(b, src[0], SWIZ(Z, X, Y, W), 3))),
                         WRITEMASK_XYZ);
    ptn_move_dest_masked(b, dest, nir_imm_float(b, 1.0), WRITEMASK_W);
 }
@@ -464,15 +442,9 @@ ptn_dph(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
 static void
 ptn_cmp(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
 {
-   if (b->shader->options->native_integers) {
-      ptn_move_dest(b, dest, nir_bcsel(b,
-                                       nir_flt(b, src[0], nir_imm_float(b, 0.0)),
-                                       src[1], src[2]));
-   } else {
-      ptn_move_dest(b, dest, nir_fcsel(b,
-                                       nir_slt(b, src[0], nir_imm_float(b, 0.0)),
-                                       src[1], src[2]));
-   }
+   ptn_move_dest(b, dest, nir_bcsel(b,
+                                    nir_flt(b, src[0], nir_imm_float(b, 0.0)),
+                                    src[1], src[2]));
 }
 
 static void
@@ -484,9 +456,7 @@ ptn_lrp(nir_builder *b, nir_alu_dest dest, nir_ssa_def **src)
 static void
 ptn_kil(nir_builder *b, nir_ssa_def **src)
 {
-   nir_ssa_def *cmp = b->shader->options->native_integers ?
-      nir_bany(b, nir_flt(b, src[0], nir_imm_float(b, 0.0))) :
-      nir_fany_nequal4(b, nir_slt(b, src[0], nir_imm_float(b, 0.0)), nir_imm_float(b, 0.0));
+   nir_ssa_def *cmp = nir_bany(b, nir_flt(b, src[0], nir_imm_float(b, 0.0)));
 
    nir_intrinsic_instr *discard =
       nir_intrinsic_instr_create(b->shader, nir_intrinsic_discard_if);
@@ -604,7 +574,7 @@ ptn_tex(struct ptn_compile *c, nir_alu_dest dest, nir_ssa_def **src,
 
    instr->src[src_number].src =
       nir_src_for_ssa(nir_swizzle(b, src[0], SWIZ(X, Y, Z, W),
-                                  instr->coord_components, true));
+                                  instr->coord_components));
    instr->src[src_number].src_type = nir_tex_src_coord;
    src_number++;
 
@@ -671,7 +641,7 @@ static const nir_op op_trans[MAX_OPCODE] = {
    [OPCODE_MAD] = 0,
    [OPCODE_MAX] = nir_op_fmax,
    [OPCODE_MIN] = nir_op_fmin,
-   [OPCODE_MOV] = nir_op_fmov,
+   [OPCODE_MOV] = nir_op_mov,
    [OPCODE_MUL] = nir_op_fmul,
    [OPCODE_POW] = 0,
    [OPCODE_RCP] = 0,
@@ -821,7 +791,7 @@ ptn_emit_instruction(struct ptn_compile *c, struct prog_instruction *prog_inst)
 
    case OPCODE_SWZ:
       /* Extended swizzles were already handled in ptn_get_src(). */
-      ptn_alu(b, nir_op_fmov, dest, src);
+      ptn_alu(b, nir_op_mov, dest, src);
       break;
 
    case OPCODE_NOP:
@@ -867,6 +837,11 @@ ptn_add_output_stores(struct ptn_compile *c)
           */
          src = nir_channel(b, src, 2);
       }
+      if (c->prog->Target == GL_VERTEX_PROGRAM_ARB &&
+          var->data.location == VARYING_SLOT_FOGC) {
+         /* result.fogcoord is a single component value */
+         src = nir_channel(b, src, 0);
+      }
       unsigned num_components = glsl_get_vector_elements(var->type);
       nir_store_var(b, var, src, (1 << num_components) - 1);
    }
@@ -890,10 +865,7 @@ setup_registers_and_variables(struct ptn_compile *c)
       var->data.index = 0;
 
       if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
-         if (i == VARYING_SLOT_POS) {
-            var->data.origin_upper_left = c->prog->OriginUpperLeft;
-            var->data.pixel_center_integer = c->prog->PixelCenterInteger;
-         } else if (i == VARYING_SLOT_FOGC) {
+         if (i == VARYING_SLOT_FOGC) {
             /* fogcoord is defined as <f, 0.0, 0.0, 1.0>.  Make the actual
              * input variable a float, and create a local containing the
              * full vec4 value.
@@ -934,12 +906,6 @@ setup_registers_and_variables(struct ptn_compile *c)
       var->data.location = i;
       var->data.index = 0;
 
-      if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
-          i == SYSTEM_VALUE_FRAG_COORD) {
-         var->data.origin_upper_left = c->prog->OriginUpperLeft;
-         var->data.pixel_center_integer = c->prog->PixelCenterInteger;
-      }
-
       c->sysval_vars[i] = var;
    }
 
@@ -959,7 +925,8 @@ setup_registers_and_variables(struct ptn_compile *c)
       reg->num_components = 4;
 
       nir_variable *var = rzalloc(shader, nir_variable);
-      if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB && i == FRAG_RESULT_DEPTH)
+      if ((c->prog->Target == GL_FRAGMENT_PROGRAM_ARB && i == FRAG_RESULT_DEPTH) ||
+          (c->prog->Target == GL_VERTEX_PROGRAM_ARB && i == VARYING_SLOT_FOGC))
          var->type = glsl_float_type();
       else
          var->type = glsl_vec4_type();
@@ -1021,13 +988,11 @@ prog_to_nir(const struct gl_program *prog,
    s = c->build.shader;
 
    if (prog->Parameters->NumParameters > 0) {
-      c->parameters = rzalloc(s, nir_variable);
-      c->parameters->type =
+      const struct glsl_type *type =
          glsl_array_type(glsl_vec4_type(), prog->Parameters->NumParameters, 0);
-      c->parameters->name = "parameters";
-      c->parameters->data.read_only = true;
-      c->parameters->data.mode = nir_var_uniform;
-      exec_list_push_tail(&s->uniforms, &c->parameters->node);
+      c->parameters =
+         nir_variable_create(s, nir_var_uniform, type,
+                             prog->Parameters->Parameters[0].Name);
    }
 
    setup_registers_and_variables(c);