summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_lower_clip.c
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2017-05-21 19:26:15 -0700
committerKenneth Graunke <[email protected]>2018-11-19 14:33:16 -0800
commit5b682143da1a24f4c66279fb5c6f9deefcb8a986 (patch)
tree7484fbbfac996271afd74710049607ef20466f25 /src/compiler/nir/nir_lower_clip.c
parentd0f746b6458e375a7f58f4f46a36f16dbb7089e1 (diff)
nir: Make nir_lower_clip_vs optionally work with variables.
The way nir_lower_clip_vs() works with store_output intrinsics makes a ton of assumptions about the driver_location field. In i965 and iris, I'd rather do this lowering early and work with variables. v3d may want to switch to that as well, and ir3 could too, but I'm not sure exactly what would need updating. For now, handle both methods. Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_lower_clip.c')
-rw-r--r--src/compiler/nir/nir_lower_clip.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/compiler/nir/nir_lower_clip.c b/src/compiler/nir/nir_lower_clip.c
index 496c39e1b6d..880d65c617b 100644
--- a/src/compiler/nir/nir_lower_clip.c
+++ b/src/compiler/nir/nir_lower_clip.c
@@ -152,9 +152,12 @@ find_output(nir_shader *shader, unsigned drvloc)
/* ucp_enables is bitmask of enabled ucps. Actual ucp values are
* passed in to shader via user_clip_plane system-values
+ *
+ * If use_vars is true, the pass will use variable loads and stores instead
+ * of working with store_output intrinsics.
*/
bool
-nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
+nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars)
{
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_ssa_def *clipdist[MAX_CLIP_PLANES];
@@ -196,17 +199,30 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
/* if shader is already writing CLIPDIST, then
* there should be no user-clip-planes to deal
* with.
+ *
+ * We assume nir_remove_dead_variables has removed the clipdist
+ * variables if they're not written.
*/
return false;
}
}
- if (clipvertex)
- cv = find_output(shader, clipvertex->data.driver_location);
- else if (position)
- cv = find_output(shader, position->data.driver_location);
- else
- return false;
+ if (use_vars) {
+ cv = nir_load_var(&b, clipvertex ? clipvertex : position);
+
+ if (clipvertex) {
+ exec_node_remove(&clipvertex->node);
+ clipvertex->data.mode = nir_var_global;
+ exec_list_push_tail(&shader->globals, &clipvertex->node);
+ }
+ } else {
+ if (clipvertex)
+ cv = find_output(shader, clipvertex->data.driver_location);
+ else if (position)
+ cv = find_output(shader, position->data.driver_location);
+ else
+ return false;
+ }
/* insert CLIPDIST outputs: */
if (ucp_enables & 0x0f)
@@ -228,10 +244,17 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
}
}
- if (ucp_enables & 0x0f)
- store_clipdist_output(&b, out[0], &clipdist[0]);
- if (ucp_enables & 0xf0)
- store_clipdist_output(&b, out[1], &clipdist[4]);
+ if (use_vars) {
+ if (ucp_enables & 0x0f)
+ nir_store_var(&b, out[0], nir_vec(&b, clipdist, 4), 0xf);
+ if (ucp_enables & 0xf0)
+ nir_store_var(&b, out[1], nir_vec(&b, &clipdist[4], 4), 0xf);
+ } else {
+ if (ucp_enables & 0x0f)
+ store_clipdist_output(&b, out[0], &clipdist[0]);
+ if (ucp_enables & 0xf0)
+ store_clipdist_output(&b, out[1], &clipdist[4]);
+ }
nir_metadata_preserve(impl, nir_metadata_dominance);