static bool
combine_clip_cull(nir_shader *nir,
- struct exec_list *vars,
+ nir_variable_mode mode,
bool store_info)
{
nir_variable *cull = NULL;
nir_variable *clip = NULL;
- nir_foreach_variable(var, vars) {
+ nir_foreach_variable_with_modes(var, nir, mode) {
if (var->data.location == VARYING_SLOT_CLIP_DIST0)
clip = var;
cull = var;
}
- if (!cull && !clip)
+ if (!cull && !clip) {
+ /* If this is run after optimizations and the variables have been
+ * eliminated, we should update the shader info, because no other
+ * place does that.
+ */
+ if (store_info) {
+ nir->info.clip_distance_array_size = 0;
+ nir->info.cull_distance_array_size = 0;
+ }
return false;
+ }
if (!cull && clip) {
/* The GLSL IR lowering pass must have converted these to vectors */
}
if (cull) {
- assert(clip->data.compact);
+ assert(cull->data.compact);
cull->data.how_declared = nir_var_hidden;
cull->data.location = VARYING_SLOT_CLIP_DIST0 + clip_array_size / 4;
cull->data.location_frac = clip_array_size % 4;
}
- nir_foreach_function(function, nir) {
- if (function->impl) {
- nir_metadata_preserve(function->impl,
- nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_loop_analysis);
- }
- }
-
return true;
}
bool progress = false;
if (nir->info.stage <= MESA_SHADER_GEOMETRY)
- progress |= combine_clip_cull(nir, &nir->outputs, true);
+ progress |= combine_clip_cull(nir, nir_var_shader_out, true);
if (nir->info.stage > MESA_SHADER_VERTEX)
- progress |= combine_clip_cull(nir, &nir->inputs, false);
+ progress |= combine_clip_cull(nir, nir_var_shader_in, false);
+
+ nir_foreach_function(function, nir) {
+ if (!function->impl)
+ continue;
+
+ if (progress) {
+ nir_metadata_preserve(function->impl,
+ nir_metadata_block_index |
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_loop_analysis);
+ } else {
+ nir_metadata_preserve(function->impl, nir_metadata_all);
+ }
+ }
return progress;
}