util: Add a way to set the min_buffer_size in linear_alloc

The default value remains 2048, which is also used for rounding up
any user provided size.

The option is useful in cases where there's a better idea of the
amount of data that's going to be used.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25279>
This commit is contained in:
Caio Oliveira
2023-10-02 22:35:04 -07:00
committed by Marge Bot
parent 39c8cca34f
commit 89afcc94ea
3 changed files with 47 additions and 7 deletions
+19
View File
@@ -70,3 +70,22 @@ TEST(LinearAlloc, AvoidWasteAfterLargeAlloc)
ralloc_free(ctx);
}
TEST(LinearAlloc, Options)
{
void *ctx = ralloc_context(NULL);
linear_opts opts = {};
opts.min_buffer_size = 8192;
linear_ctx *lin_ctx = linear_context_with_opts(ctx, &opts);
/* Assert allocations spanning the first 8192 bytes are contiguous. */
char *first = (char *)linear_alloc_child(lin_ctx, 1024);
for (int i = 1; i < 8; i++) {
char *ptr = (char *)linear_alloc_child(lin_ctx, 1024);
EXPECT_EQ(ptr - first, 1024 * i);
}
ralloc_free(ctx);
}