summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_lower_clip.c
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2019-06-28 10:10:28 +1000
committerTimothy Arceri <[email protected]>2019-07-19 09:25:47 +1000
commite38b93087638781ef83c9b3cc3bb424e448a5380 (patch)
tree1a6c3730c412e1f92558f04f7d8ad42c058ff15f /src/compiler/nir/nir_lower_clip.c
parent0395b58c92bf70c76accc6387141937bf748553d (diff)
nir/lower_clip: add a find_clipvertex_and_position_outputs() helper
This will allow code sharing in a following patch that adds support for lowering in geometry shaders. It also allows us to exit early if there is no lowering to do which allows a small code tidy up. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_lower_clip.c')
-rw-r--r--src/compiler/nir/nir_lower_clip.c59
1 files changed, 35 insertions, 24 deletions
diff --git a/src/compiler/nir/nir_lower_clip.c b/src/compiler/nir/nir_lower_clip.c
index 474854d047b..1536f0a3451 100644
--- a/src/compiler/nir/nir_lower_clip.c
+++ b/src/compiler/nir/nir_lower_clip.c
@@ -146,6 +146,35 @@ find_output(nir_shader *shader, unsigned drvloc)
return def;
}
+static bool
+find_clipvertex_and_position_outputs(nir_shader *shader,
+ nir_variable **clipvertex,
+ nir_variable **position)
+{
+ nir_foreach_variable(var, &shader->outputs) {
+ switch (var->data.location) {
+ case VARYING_SLOT_POS:
+ *position = var;
+ break;
+ case VARYING_SLOT_CLIP_VERTEX:
+ *clipvertex = var;
+ break;
+ case VARYING_SLOT_CLIP_DIST0:
+ case VARYING_SLOT_CLIP_DIST1:
+ /* 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;
+ }
+ }
+
+ return *clipvertex || *position;
+}
+
/*
* VS lowering
*/
@@ -185,27 +214,9 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars)
assert(impl->end_block->predecessors->entries == 1);
b.cursor = nir_after_cf_list(&impl->body);
- /* find clipvertex/position outputs: */
- nir_foreach_variable(var, &shader->outputs) {
- switch (var->data.location) {
- case VARYING_SLOT_POS:
- position = var;
- break;
- case VARYING_SLOT_CLIP_VERTEX:
- clipvertex = var;
- break;
- case VARYING_SLOT_CLIP_DIST0:
- case VARYING_SLOT_CLIP_DIST1:
- /* 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;
- }
- }
+ /* find clipvertex/position outputs */
+ if (!find_clipvertex_and_position_outputs(shader, &clipvertex, &position))
+ return false;
if (use_vars) {
cv = nir_load_var(&b, clipvertex ? clipvertex : position);
@@ -218,10 +229,10 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars)
} else {
if (clipvertex)
cv = find_output(shader, clipvertex->data.driver_location);
- else if (position)
+ else {
+ assert(position);
cv = find_output(shader, position->data.driver_location);
- else
- return false;
+ }
}
/* insert CLIPDIST outputs: */