vbo: merge use_buffer_objects into vbo_CreateContext to skip the big malloc
Reviewed-by: Mathias Fröhlich <mathias.froehlich@web.de> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3766>
This commit is contained in:
@@ -499,7 +499,7 @@ intelInitContext(struct intel_context *intel,
|
||||
ctx->Const.MaxRenderbufferSize = 2048;
|
||||
|
||||
_swrast_CreateContext(ctx);
|
||||
_vbo_CreateContext(ctx);
|
||||
_vbo_CreateContext(ctx, false);
|
||||
if (ctx->swrast_context) {
|
||||
_tnl_CreateContext(ctx);
|
||||
_swsetup_CreateContext(ctx);
|
||||
|
@@ -1000,7 +1000,7 @@ brwCreateContext(gl_api api,
|
||||
_swrast_CreateContext(ctx);
|
||||
}
|
||||
|
||||
_vbo_CreateContext(ctx);
|
||||
_vbo_CreateContext(ctx, true);
|
||||
if (ctx->swrast_context) {
|
||||
_tnl_CreateContext(ctx);
|
||||
TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
|
||||
@@ -1134,8 +1134,6 @@ brwCreateContext(gl_api api,
|
||||
if (ctx->Extensions.INTEL_performance_query)
|
||||
brw_init_performance_queries(brw);
|
||||
|
||||
vbo_use_buffer_objects(ctx);
|
||||
|
||||
brw->ctx.Cache = brw->screen->disk_cache;
|
||||
|
||||
if (driContextPriv->driScreenPriv->dri2.backgroundCallable &&
|
||||
|
@@ -133,7 +133,7 @@ nouveau_context_init(struct gl_context *ctx, gl_api api,
|
||||
nouveau_scratch_init(ctx);
|
||||
_mesa_meta_init(ctx);
|
||||
_swrast_CreateContext(ctx);
|
||||
_vbo_CreateContext(ctx);
|
||||
_vbo_CreateContext(ctx, true);
|
||||
_tnl_CreateContext(ctx);
|
||||
nouveau_span_functions_init(ctx);
|
||||
_mesa_allow_light_in_model(ctx, GL_FALSE);
|
||||
|
@@ -569,7 +569,6 @@ TAG(vbo_init)(struct gl_context *ctx)
|
||||
|
||||
/* Overwrite our draw function */
|
||||
ctx->Driver.Draw = TAG(vbo_draw);
|
||||
vbo_use_buffer_objects(ctx);
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -253,7 +253,7 @@ GLboolean r200CreateContext( gl_api api,
|
||||
/* Initialize the software rasterizer and helper modules.
|
||||
*/
|
||||
_swrast_CreateContext( ctx );
|
||||
_vbo_CreateContext( ctx );
|
||||
_vbo_CreateContext( ctx, false );
|
||||
_tnl_CreateContext( ctx );
|
||||
_swsetup_CreateContext( ctx );
|
||||
|
||||
|
@@ -216,7 +216,7 @@ r100CreateContext( gl_api api,
|
||||
/* Initialize the software rasterizer and helper modules.
|
||||
*/
|
||||
_swrast_CreateContext( ctx );
|
||||
_vbo_CreateContext( ctx );
|
||||
_vbo_CreateContext( ctx, false );
|
||||
_tnl_CreateContext( ctx );
|
||||
_swsetup_CreateContext( ctx );
|
||||
|
||||
|
@@ -809,7 +809,7 @@ dri_create_context(gl_api api,
|
||||
|
||||
/* create module contexts */
|
||||
_swrast_CreateContext( mesaCtx );
|
||||
_vbo_CreateContext( mesaCtx );
|
||||
_vbo_CreateContext( mesaCtx, false );
|
||||
_tnl_CreateContext( mesaCtx );
|
||||
_swsetup_CreateContext( mesaCtx );
|
||||
_swsetup_Wakeup( mesaCtx );
|
||||
|
@@ -890,7 +890,7 @@ OSMesaCreateContextAttribs(const int *attribList, OSMesaContext sharelist)
|
||||
TNLcontext *tnl;
|
||||
|
||||
if (!_swrast_CreateContext( ctx ) ||
|
||||
!_vbo_CreateContext( ctx ) ||
|
||||
!_vbo_CreateContext( ctx, false ) ||
|
||||
!_tnl_CreateContext( ctx ) ||
|
||||
!_swsetup_CreateContext( ctx )) {
|
||||
_mesa_destroy_visual(osmesa->gl_visual);
|
||||
|
@@ -941,7 +941,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
|
||||
/* Initialize the software rasterizer and helper modules.
|
||||
*/
|
||||
if (!_swrast_CreateContext( mesaCtx ) ||
|
||||
!_vbo_CreateContext( mesaCtx ) ||
|
||||
!_vbo_CreateContext( mesaCtx, false ) ||
|
||||
!_tnl_CreateContext( mesaCtx ) ||
|
||||
!_swsetup_CreateContext( mesaCtx )) {
|
||||
_mesa_free_context_data(&c->mesa);
|
||||
|
@@ -110,7 +110,7 @@ DispatchSanity_test::SetUpCtx(gl_api api, unsigned int version)
|
||||
&visual,
|
||||
NULL, // share_list
|
||||
&driver_functions);
|
||||
_vbo_CreateContext(&ctx);
|
||||
_vbo_CreateContext(&ctx, false);
|
||||
|
||||
_mesa_override_extensions(&ctx);
|
||||
ctx.Version = version;
|
||||
|
@@ -571,10 +571,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
|
||||
st->ctx = ctx;
|
||||
st->pipe = pipe;
|
||||
|
||||
/* state tracker needs the VBO module */
|
||||
_vbo_CreateContext(ctx);
|
||||
|
||||
st->dirty = ST_ALL_STATES_MASK;
|
||||
|
||||
st->can_bind_const_buffer_as_vertex =
|
||||
@@ -617,9 +613,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
st->util_velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT;
|
||||
}
|
||||
|
||||
/* we want all vertex data to be placed in buffer objects */
|
||||
vbo_use_buffer_objects(ctx);
|
||||
|
||||
/* Need these flags:
|
||||
*/
|
||||
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
|
||||
@@ -809,6 +802,11 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This must be done after extensions are initialized to enable persistent
|
||||
* mappings immediately.
|
||||
*/
|
||||
_vbo_CreateContext(ctx, true);
|
||||
|
||||
_mesa_initialize_dispatch_tables(ctx);
|
||||
_mesa_initialize_vbo_vtxfmt(ctx);
|
||||
st_init_driver_flags(st);
|
||||
|
@@ -42,7 +42,7 @@ extern "C" {
|
||||
struct gl_context;
|
||||
|
||||
GLboolean
|
||||
_vbo_CreateContext(struct gl_context *ctx);
|
||||
_vbo_CreateContext(struct gl_context *ctx, bool use_buffer_objects);
|
||||
|
||||
void
|
||||
_vbo_DestroyContext(struct gl_context *ctx);
|
||||
@@ -92,9 +92,6 @@ vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
|
||||
const struct _mesa_index_buffer *ib,
|
||||
GLuint *min_index, GLuint *max_index, GLuint nr_prims);
|
||||
|
||||
void
|
||||
vbo_use_buffer_objects(struct gl_context *ctx);
|
||||
|
||||
void
|
||||
vbo_sw_primitive_restart(struct gl_context *ctx,
|
||||
const struct _mesa_prim *prim,
|
||||
|
@@ -159,7 +159,7 @@ vbo_exec_invalidate_state(struct gl_context *ctx)
|
||||
|
||||
|
||||
GLboolean
|
||||
_vbo_CreateContext(struct gl_context *ctx)
|
||||
_vbo_CreateContext(struct gl_context *ctx, bool use_buffer_objects)
|
||||
{
|
||||
struct vbo_context *vbo = CALLOC_STRUCT(vbo_context);
|
||||
|
||||
@@ -181,7 +181,7 @@ _vbo_CreateContext(struct gl_context *ctx)
|
||||
* will pretty much be permanently installed, which means that the
|
||||
* vtxfmt mechanism can be removed now.
|
||||
*/
|
||||
vbo_exec_init(ctx);
|
||||
vbo_exec_init(ctx, use_buffer_objects);
|
||||
if (ctx->API == API_OPENGL_COMPAT)
|
||||
vbo_save_init(ctx);
|
||||
|
||||
|
@@ -109,13 +109,13 @@ _vbo_attribute_alias_map[VP_MODE_MAX][VERT_ATTRIB_MAX] = {
|
||||
|
||||
|
||||
void
|
||||
vbo_exec_init(struct gl_context *ctx)
|
||||
vbo_exec_init(struct gl_context *ctx, bool use_buffer_objects)
|
||||
{
|
||||
struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
|
||||
|
||||
exec->ctx = ctx;
|
||||
|
||||
vbo_exec_vtx_init(exec);
|
||||
vbo_exec_vtx_init(exec, use_buffer_objects);
|
||||
|
||||
ctx->Driver.NeedFlush = 0;
|
||||
ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
|
||||
|
@@ -122,13 +122,13 @@ struct vbo_exec_context
|
||||
|
||||
|
||||
void
|
||||
vbo_exec_init(struct gl_context *ctx);
|
||||
vbo_exec_init(struct gl_context *ctx, bool use_buffer_objects);
|
||||
|
||||
void
|
||||
vbo_exec_destroy(struct gl_context *ctx);
|
||||
|
||||
void
|
||||
vbo_exec_vtx_init(struct vbo_exec_context *exec);
|
||||
vbo_exec_vtx_init(struct vbo_exec_context *exec, bool use_buffer_objects);
|
||||
|
||||
void
|
||||
vbo_exec_vtx_destroy(struct vbo_exec_context *exec);
|
||||
|
@@ -979,38 +979,6 @@ vbo_exec_vtxfmt_init(struct vbo_exec_context *exec)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell the VBO module to use a real OpenGL vertex buffer object to
|
||||
* store accumulated immediate-mode vertex data.
|
||||
* This replaces the malloced buffer which was created in
|
||||
* vb_exec_vtx_init() below.
|
||||
*/
|
||||
void
|
||||
vbo_use_buffer_objects(struct gl_context *ctx)
|
||||
{
|
||||
struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
|
||||
/* Any buffer name but 0 can be used here since this bufferobj won't
|
||||
* go into the bufferobj hashtable.
|
||||
*/
|
||||
GLuint bufName = IMM_BUFFER_NAME;
|
||||
|
||||
/* Make sure this func is only used once */
|
||||
assert(exec->vtx.bufferobj == ctx->Shared->NullBufferObj);
|
||||
|
||||
_mesa_align_free(exec->vtx.buffer_map);
|
||||
exec->vtx.buffer_map = NULL;
|
||||
exec->vtx.buffer_ptr = NULL;
|
||||
|
||||
/* Allocate a real buffer object now */
|
||||
_mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
|
||||
exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName);
|
||||
|
||||
/* Map the buffer. */
|
||||
vbo_exec_vtx_map(exec);
|
||||
assert(exec->vtx.buffer_ptr);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
vbo_reset_all_attr(struct vbo_exec_context *exec)
|
||||
{
|
||||
@@ -1029,21 +997,28 @@ vbo_reset_all_attr(struct vbo_exec_context *exec)
|
||||
|
||||
|
||||
void
|
||||
vbo_exec_vtx_init(struct vbo_exec_context *exec)
|
||||
vbo_exec_vtx_init(struct vbo_exec_context *exec, bool use_buffer_objects)
|
||||
{
|
||||
struct gl_context *ctx = exec->ctx;
|
||||
|
||||
/* Allocate a buffer object. Will just reuse this object
|
||||
* continuously, unless vbo_use_buffer_objects() is called to enable
|
||||
* use of real VBOs.
|
||||
*/
|
||||
_mesa_reference_buffer_object(ctx,
|
||||
&exec->vtx.bufferobj,
|
||||
ctx->Shared->NullBufferObj);
|
||||
if (use_buffer_objects) {
|
||||
/* Use buffer objects for immediate mode. */
|
||||
struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
|
||||
|
||||
assert(!exec->vtx.buffer_map);
|
||||
exec->vtx.buffer_map = _mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
|
||||
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
|
||||
exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, IMM_BUFFER_NAME);
|
||||
|
||||
/* Map the buffer. */
|
||||
vbo_exec_vtx_map(exec);
|
||||
assert(exec->vtx.buffer_ptr);
|
||||
} else {
|
||||
/* Use allocated memory for immediate mode. */
|
||||
_mesa_reference_buffer_object(ctx,
|
||||
&exec->vtx.bufferobj,
|
||||
ctx->Shared->NullBufferObj);
|
||||
|
||||
exec->vtx.buffer_map = _mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
|
||||
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
|
||||
}
|
||||
|
||||
vbo_exec_vtxfmt_init(exec);
|
||||
_mesa_noop_vtxfmt_init(ctx, &exec->vtxfmt_noop);
|
||||
|
Reference in New Issue
Block a user