nir: add NIR_PASS_ASSERT_NO_PROGRESS
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

This aborts if a pass would make any progress. It can be used to assert that:
- our minimalist pass invocation loops in drivers are sufficient and don't
  leave any unoptimized code in the shader
- our lowering is sufficient and other passes don't add instructions that
  would cause lowering having to be repeated

Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Acked-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38406>
This commit is contained in:
Marek Olšák 2025-11-05 19:54:05 -05:00 committed by Marge Bot
parent 482fa6818e
commit 4e834b4321
2 changed files with 43 additions and 0 deletions

View file

@ -4916,6 +4916,30 @@ do { \
#define NIR_SKIP(name) should_skip_nir(#name)
#ifndef NDEBUG
void _nir_assert_no_progress(bool progress, const char *when);
/* Abort if the pass has made any progress. This can be used to assert that:
* - our minimalist pass invocation loops in drivers are sufficient and don't
* leave any unoptimized code in the shader
* - our lowering is sufficient and other passes don't add instructions that
* would cause lowering having to be repeated
*/
#define NIR_PASS_ASSERT_NO_PROGRESS(nir, pass, ...) \
do { \
if (!NIR_DEBUG(NOVALIDATE)) { \
static const char *when = #pass " in " __FILE__ ":" NIR_STRINGIZE(__LINE__); \
bool _progress = false; \
NIR_PASS(_progress, nir, pass, ##__VA_ARGS__); \
_nir_assert_no_progress(_progress, when); \
} \
} while (0)
#else
#define NIR_ASSERT_PASS_NO_PROGRESS(nir, pass, ...)
#endif
/** An instruction filtering callback with writemask
*
* Returns true if the instruction should be processed with the associated

View file

@ -2355,4 +2355,23 @@ nir_validate_ssa_dominance(nir_shader *shader, const char *when)
destroy_validate_state(&state);
}
void
_nir_assert_no_progress(bool progress, const char *when)
{
if (!progress)
return;
/* Lock around dumping so that we get clean dumps in a multi-threaded
* scenario.
*/
simple_mtx_lock(&fail_dump_mutex);
fprintf(stderr, "NIR assertion failed: Expected no progress from %s.\n",
when);
fflush(stderr);
simple_mtx_unlock(&fail_dump_mutex);
abort();
}
#endif /* NDEBUG */