From ebbb18aeb6133f4f6d7d6eba24c3a1659ea61e6e Mon Sep 17 00:00:00 2001 From: Friedrich Vock Date: Wed, 5 Jun 2024 10:44:51 +0200 Subject: [PATCH] nir: Free liveness info when invalidating metadata Liveness info can be huge, since with larger shaders it essentially grows quadratically (linear increase in number of SSA defs * linear increase in blocks). Freeing liveness info early helps somewhat mitigate memory usage here. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_metadata.c | 13 +++++++++++++ src/compiler/nir/nir_sweep.c | 9 --------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/compiler/nir/nir_metadata.c b/src/compiler/nir/nir_metadata.c index 55283f946d2..6956a2d0333 100644 --- a/src/compiler/nir/nir_metadata.c +++ b/src/compiler/nir/nir_metadata.c @@ -66,6 +66,19 @@ nir_metadata_require(nir_function_impl *impl, nir_metadata required, ...) void nir_metadata_preserve(nir_function_impl *impl, nir_metadata preserved) { + /* If we discard valid liveness information, immediately free the + * liveness information for each block. For large shaders, it can + * consume a huge amount of memory, and it's usually not immediately + * needed after dirtying. + */ + if ((impl->valid_metadata & ~preserved) & nir_metadata_live_defs) { + nir_foreach_block(block, impl) { + ralloc_free(block->live_in); + ralloc_free(block->live_out); + block->live_in = block->live_out = NULL; + } + } + impl->valid_metadata &= preserved; } diff --git a/src/compiler/nir/nir_sweep.c b/src/compiler/nir/nir_sweep.c index 9acd60a60b8..009343c3cf9 100644 --- a/src/compiler/nir/nir_sweep.c +++ b/src/compiler/nir/nir_sweep.c @@ -47,15 +47,6 @@ sweep_block(nir_shader *nir, nir_block *block) { ralloc_steal(nir, block); - /* sweep_impl will mark all metadata invalid. We can safely release all of - * this here. - */ - ralloc_free(block->live_in); - block->live_in = NULL; - - ralloc_free(block->live_out); - block->live_out = NULL; - nir_foreach_instr(instr, block) { gc_mark_live(nir->gctx, instr);