nir: Only validate in passes that might have changed things.

If a pass returning boolean progress reports no change, we shouldn't need
to re-validate.  If a pass breaks the NIR but also fails to report
progress correctly, it would be up to the next pass to catch that.

This should hopefully help with test timeouts on
KHR-GL33.texture_swizzle.functional since switching softpipe to
nir-to-tgsi and enabling NIR validation in CI (27s to 20s on my system).

Suggested-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7239>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 106b608..1bae765 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4063,7 +4063,6 @@
       break;                                                         \
    }                                                                 \
    do_pass                                                           \
-   nir_validate_shader(nir, "after " #pass);                         \
    if (should_clone_nir()) {                                         \
       nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
       nir_shader_replace(nir, clone);                                \
@@ -4078,6 +4077,7 @@
    if (should_print_nir(nir))                                           \
       printf("%s\n", #pass);                                         \
    if (pass(nir, ##__VA_ARGS__)) {                                   \
+      nir_validate_shader(nir, "after " #pass);                      \
       progress = true;                                               \
       if (should_print_nir(nir))                                        \
          nir_print_shader(nir, stdout);                              \
@@ -4089,6 +4089,7 @@
    if (should_print_nir(nir))                                           \
       printf("%s\n", #pass);                                         \
    pass(nir, ##__VA_ARGS__);                                         \
+   nir_validate_shader(nir, "after " #pass);                         \
    if (should_print_nir(nir))                                           \
       nir_print_shader(nir, stdout);                                 \
 )