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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29577>
This commit is contained in:
Friedrich Vock
2024-06-05 10:44:51 +02:00
committed by Marge Bot
parent 9b1f31a615
commit ebbb18aeb6
2 changed files with 13 additions and 9 deletions
+13
View File
@@ -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;
}
-9
View File
@@ -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);