nir: Fix interaction of GL_CLAMP lowering with texture offsets.
[mesa.git] / src / compiler / nir / nir_lower_clip.c
index 80db653a4286cb4176ea7f15e04e201939d04734..ea12f51a7bb0308e124c4a9142240cee789c0b34 100644 (file)
@@ -31,7 +31,7 @@
 
 /* Generates the lowering code for user-clip-planes, generating CLIPDIST
  * from UCP[n] + CLIPVERTEX or POSITION.  Additionally, an optional pass
- * for fragment shaders to insert conditional kill's based on the inter-
+ * for fragment shaders to insert conditional kills based on the inter-
  * polated CLIPDIST
  *
  * NOTE: should be run after nir_lower_outputs_to_temporaries() (or at
@@ -163,7 +163,7 @@ lower_clip_vs(nir_function_impl *impl, unsigned ucp_enables,
     * should be only a single predecessor block to end_block, which
     * makes the perfect place to insert the clipdist calculations.
     *
-    * NOTE: in case of early return's, these would have to be lowered
+    * NOTE: in case of early returns, these would have to be lowered
     * to jumps to end_block predecessor in a previous pass.  Not sure
     * if there is a good way to sanity check this, but for now the
     * users of this pass don't support sub-routines.
@@ -193,10 +193,10 @@ lower_clip_vs(nir_function_impl *impl, unsigned ucp_enables,
    nir_metadata_preserve(impl, nir_metadata_dominance);
 }
 
-/* ucp_enables is bitmask of enabled ucp's.  Actual ucp values are
+/* ucp_enables is bitmask of enabled ucps.  Actual ucp values are
  * passed in to shader via user_clip_plane system-values
  */
-void
+bool
 nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
 {
    int clipvertex = -1;
@@ -206,7 +206,7 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
    nir_variable *out[2] = { NULL };
 
    if (!ucp_enables)
-      return;
+      return false;
 
    /* find clipvertex/position outputs: */
    nir_foreach_variable(var, &shader->outputs) {
@@ -231,7 +231,7 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
           * there should be no user-clip-planes to deal
           * with.
           */
-         return;
+         return false;
       }
    }
 
@@ -240,7 +240,7 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
    else if (position != -1)
       cv = find_output(shader, position);
    else
-      return;
+      return false;
 
    /* insert CLIPDIST outputs: */
    if (ucp_enables & 0x0f)
@@ -254,6 +254,8 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
       if (!strcmp(function->name, "main"))
          lower_clip_vs(function->impl, ucp_enables, cv, out);
    }
+
+   return true;
 }
 
 /*
@@ -286,20 +288,24 @@ lower_clip_fs(nir_function_impl *impl, unsigned ucp_enables,
                                               nir_intrinsic_discard_if);
          discard->src[0] = nir_src_for_ssa(cond);
          nir_builder_instr_insert(&b, &discard->instr);
+
+         b.shader->info.fs.uses_discard = true;
       }
    }
+
+   nir_metadata_preserve(impl, nir_metadata_dominance);
 }
 
 /* insert conditional kill based on interpolated CLIPDIST
  */
-void
+bool
 nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables)
 {
    nir_variable *in[2];
    int maxloc = -1;
 
    if (!ucp_enables)
-      return;
+      return false;
 
    nir_foreach_variable(var, &shader->inputs) {
       int loc = var->data.driver_location;
@@ -328,4 +334,6 @@ nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables)
       if (!strcmp(function->name, "main"))
          lower_clip_fs(function->impl, ucp_enables, in);
    }
+
+   return true;
 }