From 43dca3640d91021a1a3d20c20be572ac8dbae494 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 19 Jun 2024 13:03:15 +0200 Subject: [PATCH] pan/cs: Allow lazy root chunk allocation We don't necessarily want to allocate the root CS chunk upfront if we don't know if there will be instructions emitted on the CS. Signed-off-by: Boris Brezillon Reviewed-by: Mary Guillemard Part-of: --- src/panfrost/lib/genxml/cs_builder.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/panfrost/lib/genxml/cs_builder.h b/src/panfrost/lib/genxml/cs_builder.h index 17c1958120a..58e45cd5a26 100644 --- a/src/panfrost/lib/genxml/cs_builder.h +++ b/src/panfrost/lib/genxml/cs_builder.h @@ -87,6 +87,9 @@ struct cs_builder { /* CS builder configuration */ struct cs_builder_conf conf; + /* True if an allocation failed, making the whole CS invalid. */ + bool invalid; + /* Initial (root) CS chunk. */ struct cs_chunk root_chunk; @@ -124,7 +127,7 @@ cs_builder_init(struct cs_builder *b, const struct cs_builder_conf *conf, static bool cs_is_valid(struct cs_builder *b) { - return b->cur_chunk.buffer.cpu != NULL; + return !b->invalid; } /* @@ -275,9 +278,19 @@ cs_alloc_ins(struct cs_builder *b) /* If an allocation failure happened before, we just discard all following * instructions. */ - if (unlikely(!b->cur_chunk.buffer.cpu)) + if (unlikely(!cs_is_valid(b))) return &b->discard_instr_slot; + /* Lazy root chunk allocation. */ + if (unlikely(!b->root_chunk.buffer.cpu)) { + b->root_chunk.buffer = b->conf.alloc_buffer(b->conf.cookie); + b->cur_chunk.buffer = b->root_chunk.buffer; + if (!b->cur_chunk.buffer.cpu) { + b->invalid = true; + return &b->discard_instr_slot; + } + } + /* If the current chunk runs out of space, allocate a new one and jump to it. * We actually do this a few instructions before running out, because the * sequence to jump to a new queue takes multiple instructions.