From 3685528c1ea1fb8b68a421a96a888f2b7ba914f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Sun, 26 Jun 2022 01:18:09 +0200 Subject: [PATCH] nir: track if var copies lowering was called In general we should only call it once, and then we should avoid to call any lowering that introduce back copies. So far we were tracking that manually out of the nir shader on several places. Ideally we would like to add a nir_validate rule, but right now there are some exceptions to this rule. For example right now the Intel compiler calls nir_lower_io_to_temporaries as part of linking tess_ctrl/mesh/task sahders. One option would be to allow drivers to reset the value, but for now let's not add that validation rule. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_lower_var_copies.c | 2 ++ src/compiler/nir/nir_validate.c | 6 ++++++ src/compiler/shader_info.h | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/compiler/nir/nir_lower_var_copies.c b/src/compiler/nir/nir_lower_var_copies.c index 8a748982431..c7a3a67a41a 100644 --- a/src/compiler/nir/nir_lower_var_copies.c +++ b/src/compiler/nir/nir_lower_var_copies.c @@ -164,6 +164,8 @@ nir_lower_var_copies(nir_shader *shader) { bool progress = false; + shader->info.var_copies_lowered = true; + nir_foreach_function(function, shader) { if (function->impl) progress |= lower_var_copies_impl(function->impl); diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index 4ff72977053..5e778109a73 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -643,6 +643,12 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state) validate_assert(state, glsl_get_bare_type(dst->type) == glsl_get_bare_type(src->type)); validate_assert(state, !nir_deref_mode_may_be(dst, nir_var_read_only_modes)); + /* FIXME: now that we track if the var copies were lowered, it would be + * good to validate here that no new copy derefs were added. Right now + * we can't as there are some specific cases where copies are added even + * after the lowering. One example is the Intel compiler, that calls + * nir_lower_io_to_temporaries when linking some shader stages. + */ break; } diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index 806f4bdc2d1..fd673d135d5 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -297,6 +297,11 @@ typedef struct shader_info { */ bool io_lowered:1; + /** Has nir_lower_var_copies called. To avoid calling any + * lowering/optimization that would introduce any copy_deref later. + */ + bool var_copies_lowered:1; + /* Whether the shader writes memory, including transform feedback. */ bool writes_memory:1;