From f11f4a2a4da965834cb0867e7ed931bf4aacbc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Fri, 2 Oct 2020 16:10:38 +0200 Subject: [PATCH] nir: Add ability to count primitives per stream. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Timur Kristóf Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir.h | 7 ++++--- src/compiler/nir/nir_gs_count_vertices.c | 18 +++++++++++++++--- src/intel/compiler/brw_vec4_gs_visitor.cpp | 3 ++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 465f507d27a..332903b76ad 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4107,9 +4107,10 @@ void nir_dump_dom_frontier(nir_shader *shader, FILE *fp); void nir_dump_cfg_impl(nir_function_impl *impl, FILE *fp); void nir_dump_cfg(nir_shader *shader, FILE *fp); -void nir_gs_count_vertices(const nir_shader *shader, - int *out_vtxcnt, - unsigned num_streams); +void nir_gs_count_vertices_and_primitives(const nir_shader *shader, + int *out_vtxcnt, + int *out_prmcnt, + unsigned num_streams); bool nir_shrink_vec_array_vars(nir_shader *shader, nir_variable_mode modes); bool nir_split_array_vars(nir_shader *shader, nir_variable_mode modes); diff --git a/src/compiler/nir/nir_gs_count_vertices.c b/src/compiler/nir/nir_gs_count_vertices.c index 32d3fceb6f9..0e97eddd73b 100644 --- a/src/compiler/nir/nir_gs_count_vertices.c +++ b/src/compiler/nir/nir_gs_count_vertices.c @@ -44,7 +44,7 @@ as_set_vertex_and_primitive_count(nir_instr *instr) } /** - * Count the number of vertices emitted by a geometry shader per stream. + * Count the number of vertices/primitives emitted by a geometry shader per stream. * If a constant number of vertices is emitted, the output is set to * that number, otherwise it is unknown at compile time and the * result will be -1. @@ -53,11 +53,15 @@ as_set_vertex_and_primitive_count(nir_instr *instr) * counting at the NIR level. */ void -nir_gs_count_vertices(const nir_shader *shader, int *out_vtxcnt, unsigned num_streams) +nir_gs_count_vertices_and_primitives(const nir_shader *shader, + int *out_vtxcnt, + int *out_prmcnt, + unsigned num_streams) { assert(num_streams); int vtxcnt_arr[4] = {-1, -1, -1, -1}; + int prmcnt_arr[4] = {-1, -1, -1, -1}; bool cnt_found[4] = {false, false, false, false}; nir_foreach_function(function, shader) { @@ -80,12 +84,15 @@ nir_gs_count_vertices(const nir_shader *shader, int *out_vtxcnt, unsigned num_st continue; int vtxcnt = -1; + int prmcnt = -1; - /* If the number of vertices is compile-time known, we use that, + /* If the number of vertices/primitives is compile-time known, we use that, * otherwise we leave it at -1 which means that it's unknown. */ if (nir_src_is_const(intrin->src[0])) vtxcnt = nir_src_as_int(intrin->src[0]); + if (nir_src_is_const(intrin->src[1])) + prmcnt = nir_src_as_int(intrin->src[1]); /* We've found contradictory set_vertex_and_primitive_count intrinsics. * This can happen if there are early-returns in main() and @@ -93,8 +100,11 @@ nir_gs_count_vertices(const nir_shader *shader, int *out_vtxcnt, unsigned num_st */ if (cnt_found[stream] && vtxcnt != vtxcnt_arr[stream]) vtxcnt = -1; + if (cnt_found[stream] && prmcnt != prmcnt_arr[stream]) + prmcnt = -1; vtxcnt_arr[stream] = vtxcnt; + prmcnt_arr[stream] = prmcnt; cnt_found[stream] = true; } } @@ -102,4 +112,6 @@ nir_gs_count_vertices(const nir_shader *shader, int *out_vtxcnt, unsigned num_st if (out_vtxcnt) memcpy(out_vtxcnt, vtxcnt_arr, num_streams * sizeof(int)); + if (out_prmcnt) + memcpy(out_prmcnt, prmcnt_arr, num_streams * sizeof(int)); } diff --git a/src/intel/compiler/brw_vec4_gs_visitor.cpp b/src/intel/compiler/brw_vec4_gs_visitor.cpp index ff60ec89afd..4800d9b3a99 100644 --- a/src/intel/compiler/brw_vec4_gs_visitor.cpp +++ b/src/intel/compiler/brw_vec4_gs_visitor.cpp @@ -628,7 +628,8 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data, prog_data->invocations = nir->info.gs.invocations; if (compiler->devinfo->gen >= 8) - nir_gs_count_vertices(nir, &prog_data->static_vertex_count, 1u); + nir_gs_count_vertices_and_primitives( + nir, &prog_data->static_vertex_count, nullptr, 1u); if (compiler->devinfo->gen >= 7) { if (nir->info.gs.output_primitive == GL_POINTS) {