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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user