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:
parent
031cb085cd
commit
3253594268
|
@ -95,21 +95,12 @@ _vbo_save_get_stride(const struct vbo_save_vertex_list *node)
|
||||||
return node->VAO[0]->BufferBinding[0].Stride;
|
return node->VAO[0]->BufferBinding[0].Stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Default size for the buffer holding the vertices and the indices.
|
||||||
/* These buffers should be a reasonable size to support upload to
|
* A bigger buffer helps reducing the number of draw calls but may
|
||||||
* hardware. Current vbo implementation will re-upload on any
|
* waste memory.
|
||||||
* 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?
|
|
||||||
*/
|
*/
|
||||||
#define VBO_SAVE_BUFFER_SIZE (256*1024) /* dwords */
|
#define VBO_SAVE_BUFFER_SIZE (20*1024*1024)
|
||||||
#define VBO_SAVE_PRIM_SIZE 128
|
#define VBO_SAVE_PRIM_MODE_MASK 0x3f
|
||||||
#define VBO_SAVE_PRIM_MODE_MASK 0x3f
|
|
||||||
#define VBO_SAVE_INDEX_SIZE (32 * 1024)
|
|
||||||
|
|
||||||
struct vbo_save_vertex_store {
|
struct vbo_save_vertex_store {
|
||||||
fi_type *buffer_in_ram;
|
fi_type *buffer_in_ram;
|
||||||
|
|
|
@ -179,7 +179,7 @@ realloc_vertex_store(struct vbo_save_vertex_store *store, uint32_t vertex_size,
|
||||||
if (!store)
|
if (!store)
|
||||||
store = CALLOC_STRUCT(vbo_save_vertex_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) {
|
if (new_size > store->buffer_in_ram_size) {
|
||||||
store->buffer_in_ram_size = new_size;
|
store->buffer_in_ram_size = new_size;
|
||||||
store->buffer_in_ram = realloc(store->buffer_in_ram, store->buffer_in_ram_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)
|
if (store == NULL)
|
||||||
store = CALLOC_STRUCT(vbo_save_primitive_store);
|
store = CALLOC_STRUCT(vbo_save_primitive_store);
|
||||||
|
|
||||||
uint32_t old_size = store->size;
|
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));
|
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));
|
memset(&store->prims[old_size], 0, (store->size - old_size) * sizeof(struct _mesa_prim));
|
||||||
store->used = 0;
|
store->used = 0;
|
||||||
|
@ -416,21 +417,20 @@ static void
|
||||||
realloc_storage(struct gl_context *ctx, int prim_count, int vertex_count)
|
realloc_storage(struct gl_context *ctx, int prim_count, int vertex_count)
|
||||||
{
|
{
|
||||||
struct vbo_save_context *save = &vbo_context(ctx)->save;
|
struct vbo_save_context *save = &vbo_context(ctx)->save;
|
||||||
const int ten_MB = 10 * 1024 * 1024;
|
|
||||||
|
|
||||||
/* Limit how much memory we allocate. */
|
/* Limit how much memory we allocate. */
|
||||||
if (save->prim_store->used > 0 &&
|
if (save->prim_store->used > 0 &&
|
||||||
vertex_count > 0 &&
|
vertex_count > 0 &&
|
||||||
vertex_count * save->vertex_size > ten_MB) {
|
vertex_count * save->vertex_size > VBO_SAVE_BUFFER_SIZE) {
|
||||||
wrap_filled_vertex(ctx);
|
wrap_filled_vertex(ctx);
|
||||||
vertex_count = ten_MB / save->vertex_size;
|
vertex_count = VBO_SAVE_BUFFER_SIZE / save->vertex_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prim_count > 0 &&
|
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)
|
if (save->prim_store->used > 0)
|
||||||
compile_vertex_list(ctx);
|
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)
|
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);
|
save->current_bo = ctx->Driver.NewBufferObject(ctx, VBO_BUF_ID + 1);
|
||||||
bool success = ctx->Driver.BufferData(ctx,
|
bool success = ctx->Driver.BufferData(ctx,
|
||||||
GL_ELEMENT_ARRAY_BUFFER_ARB,
|
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,
|
NULL,
|
||||||
GL_STATIC_DRAW_ARB, GL_MAP_WRITE_BIT,
|
GL_STATIC_DRAW_ARB, GL_MAP_WRITE_BIT,
|
||||||
save->current_bo);
|
save->current_bo);
|
||||||
|
@ -894,7 +894,7 @@ end:
|
||||||
save->current_bo = ctx->Driver.NewBufferObject(ctx, VBO_BUF_ID + 1);
|
save->current_bo = ctx->Driver.NewBufferObject(ctx, VBO_BUF_ID + 1);
|
||||||
bool success = ctx->Driver.BufferData(ctx,
|
bool success = ctx->Driver.BufferData(ctx,
|
||||||
GL_ELEMENT_ARRAY_BUFFER_ARB,
|
GL_ELEMENT_ARRAY_BUFFER_ARB,
|
||||||
VBO_SAVE_BUFFER_SIZE * sizeof(uint32_t),
|
VBO_SAVE_BUFFER_SIZE,
|
||||||
NULL,
|
NULL,
|
||||||
GL_STATIC_DRAW_ARB, GL_MAP_WRITE_BIT,
|
GL_STATIC_DRAW_ARB, GL_MAP_WRITE_BIT,
|
||||||
save->current_bo);
|
save->current_bo);
|
||||||
|
|
Loading…
Reference in New Issue