mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-30 23:28:06 +02:00
nir: Add ability to count primitives per stream.
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6964>
This commit is contained in:
parent
aac5adc3c2
commit
f11f4a2a4d
3 changed files with 21 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue