vbo/dlist: rework buffer sizes

Use 20Mb as the default bo size and use the same limit when
allocating the CPU buffers in realloc_storage.

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:39:30 +02:00
parent 031cb085cd
commit 3253594268
2 changed files with 14 additions and 23 deletions

View File

@ -95,21 +95,12 @@ _vbo_save_get_stride(const struct vbo_save_vertex_list *node)
return node->VAO[0]->BufferBinding[0].Stride;
}
/* These buffers should be a reasonable size to support upload to
* hardware. Current vbo implementation will re-upload on any
* changes, so don't make too big or apps which dynamically create
* dlists and use only a few times will suffer.
*
* Consider stategy of uploading regions from the VBO on demand in the
* case of dynamic vbos. Then make the dlist code signal that
* likelyhood as it occurs. No reason we couldn't change usage
* internally even though this probably isn't allowed for client VBOs?
/* Default size for the buffer holding the vertices and the indices.
* A bigger buffer helps reducing the number of draw calls but may
* waste memory.
*/
#define VBO_SAVE_BUFFER_SIZE (256*1024) /* dwords */
#define VBO_SAVE_PRIM_SIZE 128
#define VBO_SAVE_PRIM_MODE_MASK 0x3f
#define VBO_SAVE_INDEX_SIZE (32 * 1024)
#define VBO_SAVE_BUFFER_SIZE (20*1024*1024)
#define VBO_SAVE_PRIM_MODE_MASK 0x3f
struct vbo_save_vertex_store {
fi_type *buffer_in_ram;

View File

@ -179,7 +179,7 @@ realloc_vertex_store(struct vbo_save_vertex_store *store, uint32_t vertex_size,
if (!store)
store = CALLOC_STRUCT(vbo_save_vertex_store);
int new_size = MAX2(vertex_count * vertex_size, VBO_SAVE_BUFFER_SIZE) * sizeof(GLfloat);
int new_size = MAX2(vertex_count * vertex_size * sizeof(GLfloat), 1024 * 1024);
if (new_size > store->buffer_in_ram_size) {
store->buffer_in_ram_size = new_size;
store->buffer_in_ram = realloc(store->buffer_in_ram, store->buffer_in_ram_size);
@ -194,8 +194,9 @@ realloc_prim_store(struct vbo_save_primitive_store *store, int prim_count)
{
if (store == NULL)
store = CALLOC_STRUCT(vbo_save_primitive_store);
uint32_t old_size = store->size;
store->size = MAX3(store->size, prim_count, VBO_SAVE_PRIM_SIZE);
store->size = MAX3(store->size, prim_count, 128);
store->prims = realloc(store->prims, store->size * sizeof(struct _mesa_prim));
memset(&store->prims[old_size], 0, (store->size - old_size) * sizeof(struct _mesa_prim));
store->used = 0;
@ -416,21 +417,20 @@ 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) {
vertex_count * save->vertex_size > VBO_SAVE_BUFFER_SIZE) {
wrap_filled_vertex(ctx);
vertex_count = ten_MB / save->vertex_size;
vertex_count = VBO_SAVE_BUFFER_SIZE / save->vertex_size;
}
if (prim_count > 0 &&
prim_count * sizeof(struct _mesa_prim) > ten_MB) {
prim_count * sizeof(struct _mesa_prim) > VBO_SAVE_BUFFER_SIZE) {
if (save->prim_store->used > 0)
compile_vertex_list(ctx);
prim_count = ten_MB / sizeof(struct _mesa_prim);
prim_count = VBO_SAVE_BUFFER_SIZE / sizeof(struct _mesa_prim);
}
if (vertex_count >= 0)
@ -764,7 +764,7 @@ compile_vertex_list(struct gl_context *ctx)
save->current_bo = ctx->Driver.NewBufferObject(ctx, VBO_BUF_ID + 1);
bool success = ctx->Driver.BufferData(ctx,
GL_ELEMENT_ARRAY_BUFFER_ARB,
MAX2(total_bytes_needed, VBO_SAVE_BUFFER_SIZE * sizeof(uint32_t)),
MAX2(total_bytes_needed, VBO_SAVE_BUFFER_SIZE),
NULL,
GL_STATIC_DRAW_ARB, GL_MAP_WRITE_BIT,
save->current_bo);
@ -894,7 +894,7 @@ end:
save->current_bo = ctx->Driver.NewBufferObject(ctx, VBO_BUF_ID + 1);
bool success = ctx->Driver.BufferData(ctx,
GL_ELEMENT_ARRAY_BUFFER_ARB,
VBO_SAVE_BUFFER_SIZE * sizeof(uint32_t),
VBO_SAVE_BUFFER_SIZE,
NULL,
GL_STATIC_DRAW_ARB, GL_MAP_WRITE_BIT,
save->current_bo);