vbo/dlist: limit allocation sizes

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12646>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2021-08-13 17:16:19 +02:00
parent ea99d1c748
commit 94a2063987
1 changed files with 20 additions and 0 deletions

View File

@ -368,10 +368,30 @@ update_vao(struct gl_context *ctx,
}
static void wrap_filled_vertex(struct gl_context *ctx);
static void compile_vertex_list(struct gl_context *ctx);
static void
realloc_storage(struct gl_context *ctx, int prim_count, int vertex_count)
{
struct vbo_save_context *save = &vbo_context(ctx)->save;
const int ten_MB = 10 * 1024 * 1024;
/* Limit how much memory we allocate. */
if (save->prim_store->used > 0 &&
vertex_count > 0 &&
vertex_count * save->vertex_size > ten_MB) {
wrap_filled_vertex(ctx);
vertex_count = ten_MB / save->vertex_size;
}
if (prim_count > 0 &&
prim_count * sizeof(struct _mesa_prim) > ten_MB) {
if (save->prim_store->used > 0)
compile_vertex_list(ctx);
prim_count = ten_MB / sizeof(struct _mesa_prim);
}
if (vertex_count >= 0)
save->vertex_store = realloc_vertex_store(save->vertex_store, save->vertex_size, vertex_count);