nir: Remove handling of dead writes from copy_prop_vars
[mesa.git] / src / compiler / nir / nir_lower_tex.c
index 1ccd253320c2f1f7319801f344c44d2c252417e9..dc40d82b27f704be727c9ded211e97de5312db6d 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "nir.h"
 #include "nir_builder.h"
+#include "nir_format_convert.h"
 
 static void
 project_src(nir_builder *b, nir_tex_instr *tex)
@@ -479,8 +480,8 @@ lower_gradient_cube_map(nir_builder *b, nir_tex_instr *tex)
    nir_ssa_def *cond_z = nir_fge(b, abs_p_z, nir_fmax(b, abs_p_x, abs_p_y));
    nir_ssa_def *cond_y = nir_fge(b, abs_p_y, nir_fmax(b, abs_p_x, abs_p_z));
 
-   unsigned yzx[4] = { 1, 2, 0, 0 };
-   unsigned xzy[4] = { 0, 2, 1, 0 };
+   unsigned yzx[3] = { 1, 2, 0 };
+   unsigned xzy[3] = { 0, 2, 1 };
 
    Q = nir_bcsel(b, cond_z,
                  p,
@@ -508,16 +509,15 @@ lower_gradient_cube_map(nir_builder *b, nir_tex_instr *tex)
     */
    nir_ssa_def *rcp_Q_z = nir_frcp(b, nir_channel(b, Q, 2));
 
-   unsigned xy[4] = { 0, 1, 0, 0 };
-   nir_ssa_def *Q_xy = nir_swizzle(b, Q, xy, 2, false);
+   nir_ssa_def *Q_xy = nir_channels(b, Q, 0x3);
    nir_ssa_def *tmp = nir_fmul(b, Q_xy, rcp_Q_z);
 
-   nir_ssa_def *dQdx_xy = nir_swizzle(b, dQdx, xy, 2, false);
+   nir_ssa_def *dQdx_xy = nir_channels(b, dQdx, 0x3);
    nir_ssa_def *dQdx_z = nir_channel(b, dQdx, 2);
    nir_ssa_def *dx =
       nir_fmul(b, rcp_Q_z, nir_fsub(b, dQdx_xy, nir_fmul(b, tmp, dQdx_z)));
 
-   nir_ssa_def *dQdy_xy = nir_swizzle(b, dQdy, xy, 2, false);
+   nir_ssa_def *dQdy_xy = nir_channels(b, dQdy, 0x3);
    nir_ssa_def *dQdy_z = nir_channel(b, dQdy, 2);
    nir_ssa_def *dy =
       nir_fmul(b, rcp_Q_z, nir_fsub(b, dQdy_xy, nir_fmul(b, tmp, dQdy_z)));
@@ -711,24 +711,8 @@ linearize_srgb_result(nir_builder *b, nir_tex_instr *tex)
 
    b->cursor = nir_after_instr(&tex->instr);
 
-   static const unsigned swiz[4] = {0, 1, 2, 0};
-   nir_ssa_def *comp = nir_swizzle(b, &tex->dest.ssa, swiz, 3, true);
-
-   /* Formula is:
-    *    (comp <= 0.04045) ?
-    *          (comp / 12.92) :
-    *          pow((comp + 0.055) / 1.055, 2.4)
-    */
-   nir_ssa_def *low  = nir_fmul(b, comp, nir_imm_float(b, 1.0 / 12.92));
-   nir_ssa_def *high = nir_fpow(b,
-                                nir_fmul(b,
-                                         nir_fadd(b,
-                                                  comp,
-                                                  nir_imm_float(b, 0.055)),
-                                         nir_imm_float(b, 1.0 / 1.055)),
-                                nir_imm_float(b, 2.4));
-   nir_ssa_def *cond = nir_fge(b, nir_imm_float(b, 0.04045), comp);
-   nir_ssa_def *rgb  = nir_bcsel(b, cond, low, high);
+   nir_ssa_def *rgb =
+      nir_format_srgb_to_linear(b, nir_channels(b, &tex->dest.ssa, 0x7));
 
    /* alpha is untouched: */
    nir_ssa_def *result = nir_vec4(b,