From c7d25046254bbd1a96ce4ba7572c1afb8dc52afd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 7 Mar 2019 09:55:09 -0700 Subject: [PATCH] st/mesa: move around some code in st_context.c st_init_driver_functions() is only called in st_context.c so there's no need for the prototype in st_context.h To avoid a forward declaration of st_init_driver_functions() in st_context.c, we need to move around several other functions. No functional change. Reviewed-by: Neha Bhende --- src/mesa/state_tracker/st_context.c | 229 ++++++++++++++++++------------------ src/mesa/state_tracker/st_context.h | 9 -- 2 files changed, 116 insertions(+), 122 deletions(-) diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 68b6ddb..f30afee 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -572,118 +572,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, } -struct st_context * -st_create_context(gl_api api, struct pipe_context *pipe, - const struct gl_config *visual, - struct st_context *share, - const struct st_config_options *options, - bool no_error) -{ - struct gl_context *ctx; - struct gl_context *shareCtx = share ? share->ctx : NULL; - struct dd_function_table funcs; - struct st_context *st; - - util_cpu_detect(); - - memset(&funcs, 0, sizeof(funcs)); - st_init_driver_functions(pipe->screen, &funcs); - - ctx = calloc(1, sizeof(struct gl_context)); - if (!ctx) - return NULL; - - if (!_mesa_initialize_context(ctx, api, visual, shareCtx, &funcs)) { - free(ctx); - return NULL; - } - - st_debug_init(); - - if (pipe->screen->get_disk_shader_cache && - !(ST_DEBUG & DEBUG_TGSI)) - ctx->Cache = pipe->screen->get_disk_shader_cache(pipe->screen); - - /* XXX: need a capability bit in gallium to query if the pipe - * driver prefers DP4 or MUL/MAD for vertex transformation. - */ - if (debug_get_option_mesa_mvp_dp4()) - ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE; - - st = st_create_context_priv(ctx, pipe, options, no_error); - if (!st) { - _mesa_destroy_context(ctx); - } - - return st; -} - - -/** - * Callback to release the sampler view attached to a texture object. - * Called by _mesa_HashWalk(). - */ -static void -destroy_tex_sampler_cb(GLuint id, void *data, void *userData) -{ - struct gl_texture_object *texObj = (struct gl_texture_object *) data; - struct st_context *st = (struct st_context *) userData; - - st_texture_release_sampler_view(st, st_texture_object(texObj)); -} - - -void -st_destroy_context(struct st_context *st) -{ - struct gl_context *ctx = st->ctx; - struct st_framebuffer *stfb, *next; - - GET_CURRENT_CONTEXT(curctx); - - if (curctx == NULL) { - /* No current context, but we need one to release - * renderbuffer surface when we release framebuffer. - * So temporarily bind the context. - */ - _mesa_make_current(ctx, NULL, NULL); - } - - /* This must be called first so that glthread has a chance to finish */ - _mesa_glthread_destroy(ctx); - - _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st); - - st_reference_fragprog(st, &st->fp, NULL); - st_reference_prog(st, &st->gp, NULL); - st_reference_vertprog(st, &st->vp, NULL); - st_reference_prog(st, &st->tcp, NULL); - st_reference_prog(st, &st->tep, NULL); - st_reference_compprog(st, &st->cp, NULL); - - /* release framebuffer in the winsys buffers list */ - LIST_FOR_EACH_ENTRY_SAFE_REV(stfb, next, &st->winsys_buffers, head) { - st_framebuffer_reference(&stfb, NULL); - } - - pipe_sampler_view_reference(&st->pixel_xfer.pixelmap_sampler_view, NULL); - pipe_resource_reference(&st->pixel_xfer.pixelmap_texture, NULL); - - _vbo_DestroyContext(ctx); - - st_destroy_program_variants(st); - - _mesa_free_context_data(ctx); - - /* This will free the st_context too, so 'st' must not be accessed - * afterwards. */ - st_destroy_context_priv(st, true); - st = NULL; - - free(ctx); -} - - static void st_emit_string_marker(struct gl_context *ctx, const GLchar *string, GLsizei len) { @@ -727,7 +615,7 @@ st_get_driver_uuid(struct gl_context *ctx, char *uuid) } -void +static void st_init_driver_functions(struct pipe_screen *screen, struct dd_function_table *functions) { @@ -798,3 +686,118 @@ st_init_driver_functions(struct pipe_screen *screen, st_deserialise_tgsi_program; } } + + +struct st_context * +st_create_context(gl_api api, struct pipe_context *pipe, + const struct gl_config *visual, + struct st_context *share, + const struct st_config_options *options, + bool no_error) +{ + struct gl_context *ctx; + struct gl_context *shareCtx = share ? share->ctx : NULL; + struct dd_function_table funcs; + struct st_context *st; + + util_cpu_detect(); + + memset(&funcs, 0, sizeof(funcs)); + st_init_driver_functions(pipe->screen, &funcs); + + ctx = calloc(1, sizeof(struct gl_context)); + if (!ctx) + return NULL; + + if (!_mesa_initialize_context(ctx, api, visual, shareCtx, &funcs)) { + free(ctx); + return NULL; + } + + st_debug_init(); + + if (pipe->screen->get_disk_shader_cache && + !(ST_DEBUG & DEBUG_TGSI)) + ctx->Cache = pipe->screen->get_disk_shader_cache(pipe->screen); + + /* XXX: need a capability bit in gallium to query if the pipe + * driver prefers DP4 or MUL/MAD for vertex transformation. + */ + if (debug_get_option_mesa_mvp_dp4()) + ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE; + + st = st_create_context_priv(ctx, pipe, options, no_error); + if (!st) { + _mesa_destroy_context(ctx); + } + + return st; +} + + +/** + * When we destroy a context, we must examine all texture objects to + * find/release any sampler views created by that context. + * + * This callback is called per-texture object. It releases all the + * texture's sampler views which belong to the context. + */ +static void +destroy_tex_sampler_cb(GLuint id, void *data, void *userData) +{ + struct gl_texture_object *texObj = (struct gl_texture_object *) data; + struct st_context *st = (struct st_context *) userData; + + st_texture_release_sampler_view(st, st_texture_object(texObj)); +} + + +void +st_destroy_context(struct st_context *st) +{ + struct gl_context *ctx = st->ctx; + struct st_framebuffer *stfb, *next; + + GET_CURRENT_CONTEXT(curctx); + + if (curctx == NULL) { + /* No current context, but we need one to release + * renderbuffer surface when we release framebuffer. + * So temporarily bind the context. + */ + _mesa_make_current(ctx, NULL, NULL); + } + + /* This must be called first so that glthread has a chance to finish */ + _mesa_glthread_destroy(ctx); + + _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st); + + st_reference_fragprog(st, &st->fp, NULL); + st_reference_prog(st, &st->gp, NULL); + st_reference_vertprog(st, &st->vp, NULL); + st_reference_prog(st, &st->tcp, NULL); + st_reference_prog(st, &st->tep, NULL); + st_reference_compprog(st, &st->cp, NULL); + + /* release framebuffer in the winsys buffers list */ + LIST_FOR_EACH_ENTRY_SAFE_REV(stfb, next, &st->winsys_buffers, head) { + st_framebuffer_reference(&stfb, NULL); + } + + pipe_sampler_view_reference(&st->pixel_xfer.pixelmap_sampler_view, NULL); + pipe_resource_reference(&st->pixel_xfer.pixelmap_texture, NULL); + + _vbo_DestroyContext(ctx); + + st_destroy_program_variants(st); + + _mesa_free_context_data(ctx); + + /* This will free the st_context too, so 'st' must not be accessed + * afterwards. */ + st_destroy_context_priv(st, true); + st = NULL; + + free(ctx); +} diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 58a1ead..a3f70ec 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -331,18 +331,9 @@ st_destroy_context(struct st_context *st); extern void -st_init_driver_functions(struct pipe_screen *screen, - struct dd_function_table *functions); - - -extern void st_invalidate_buffers(struct st_context *st); -extern uint64_t -st_get_active_states(struct gl_context *ctx); - - /** * Wrapper for struct gl_framebuffer. * This is an opaque type to the outside world. -- 2.7.4