diff options
author | Timothy Arceri <[email protected]> | 2019-06-27 14:20:37 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2019-07-19 09:25:47 +1000 |
commit | 30038dd5ec9179d939b8b91864293a1008cae070 (patch) | |
tree | ea6787149e64034267c11dd72c3c08128a209f29 /src | |
parent | 4b08bb47704ee181c9406e26c086815bd4c241ec (diff) |
nir/lower_clip: add support for geometry shaders
This will be used to enabled compat profile support for geometry
shaders.
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/nir/nir.h | 1 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_clip.c | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c94da19668e..15c4cd42571 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3776,6 +3776,7 @@ bool nir_lower_idiv(nir_shader *shader); bool nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval); bool nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars); +bool nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables); bool nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables); bool nir_lower_clip_cull_distance_arrays(nir_shader *nir); diff --git a/src/compiler/nir/nir_lower_clip.c b/src/compiler/nir/nir_lower_clip.c index ec0285f47ba..26c3e64856b 100644 --- a/src/compiler/nir/nir_lower_clip.c +++ b/src/compiler/nir/nir_lower_clip.c @@ -290,6 +290,63 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars) return true; } +static void +lower_clip_in_gs_block(nir_builder *b, nir_block *block, nir_variable *position, + nir_variable *clipvertex, nir_variable **out, + unsigned ucp_enables) +{ + nir_foreach_instr_safe(instr, block) { + if (instr->type != nir_instr_type_intrinsic) + continue; + + nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); + switch (intrin->intrinsic) { + case nir_intrinsic_emit_vertex_with_counter: + case nir_intrinsic_emit_vertex: + b->cursor = nir_before_instr(instr); + lower_clip_outputs(b, position, clipvertex, out, ucp_enables, true); + break; + default: + /* not interesting; skip this */ + break; + } + } +} + +/* + * GS lowering + */ + +bool +nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables) +{ + nir_function_impl *impl = nir_shader_get_entrypoint(shader); + nir_builder b; + int maxloc = -1; + nir_variable *position = NULL; + nir_variable *clipvertex = NULL; + nir_variable *out[2] = { NULL }; + + if (!ucp_enables) + return false; + + /* find clipvertex/position outputs */ + if (!find_clipvertex_and_position_outputs(shader, &clipvertex, &position)) + return false; + + /* insert CLIPDIST outputs */ + create_clipdist_vars(shader, out, ucp_enables, &maxloc, true); + + nir_builder_init(&b, impl); + + nir_foreach_block(block, impl) + lower_clip_in_gs_block(&b, block, position, clipvertex, out, ucp_enables); + + nir_metadata_preserve(impl, nir_metadata_dominance); + + return true; +} + /* * FS lowering */ |