--- src/compiler/nir/nir.h | 2 +- .../nir/nir_lower_clip_cull_distance_arrays.c | 39 ++++++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 1c792f1..a0c57f4 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2498,7 +2498,7 @@ bool nir_lower_idiv(nir_shader *shader); void nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables); void nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables); -void nir_lower_clip_cull_distance_arrays(nir_shader *nir); +bool nir_lower_clip_cull_distance_arrays(nir_shader *nir); void nir_lower_two_sided_color(nir_shader *shader); diff --git a/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c b/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c index 5a89edd..b255bc5 100644 --- a/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c +++ b/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c @@ -73,13 +73,13 @@ update_type(nir_variable *var, gl_shader_stage stage, unsigned length) /** * Rewrite any clip/cull distances to refer to the new combined array. */ -static void +static bool rewrite_references(nir_instr *instr, nir_variable *combined, unsigned cull_offset) { if (instr->type != nir_instr_type_intrinsic) - return; + return false; nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); @@ -88,15 +88,15 @@ rewrite_references(nir_instr *instr, if (intrin->intrinsic != nir_intrinsic_load_var && intrin->intrinsic != nir_intrinsic_store_var) - return; + return false; nir_deref_var *var_ref = intrin->variables[0]; if (var_ref->var->data.mode != combined->data.mode) - return; + return false; if (var_ref->var->data.location != VARYING_SLOT_CLIP_DIST0 && var_ref->var->data.location != VARYING_SLOT_CULL_DIST0) - return; + return false; /* Update types along the deref chain */ const struct glsl_type *type = combined->type; @@ -119,15 +119,18 @@ rewrite_references(nir_instr *instr, var_ref->var = combined; /* There's no need to update writemasks; it's a scalar array. */ + + return true; } -static void +static bool combine_clip_cull(nir_shader *nir, struct exec_list *vars, bool store_info) { nir_variable *cull = NULL; nir_variable *clip = NULL; + bool progress = false; nir_foreach_variable(var, vars) { if (var->data.location == VARYING_SLOT_CLIP_DIST0) @@ -162,11 +165,21 @@ combine_clip_cull(nir_shader *nir, /* Rewrite CullDistance to reference the combined array */ nir_foreach_function(function, nir) { if (function->impl) { + bool this_progress = false; + nir_foreach_block(block, function->impl) { nir_foreach_instr(instr, block) { - rewrite_references(instr, clip, clip_array_size); + this_progress |= rewrite_references(instr, clip, + clip_array_size); } } + + if (this_progress) { + nir_metadata_preserve(function->impl, + nir_metadata_block_index | + nir_metadata_dominance); + } + progress |= this_progress; } } @@ -175,14 +188,20 @@ combine_clip_cull(nir_shader *nir, ralloc_free(cull); } } + + return progress; } -void +bool nir_lower_clip_cull_distance_arrays(nir_shader *nir) { + bool progress = false; + if (nir->stage <= MESA_SHADER_GEOMETRY) - combine_clip_cull(nir, &nir->outputs, true); + progress |= combine_clip_cull(nir, &nir->outputs, true); if (nir->stage > MESA_SHADER_VERTEX) - combine_clip_cull(nir, &nir->inputs, false); + progress |= combine_clip_cull(nir, &nir->inputs, false); + + return progress; } -- 2.10.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev