本文主要是介绍Android环境下Mesa初始化流程重学习之eglCreateContext,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Mesa初始化流程重学习之eglCreateContext
引言
没有啥好说的了,直接上手撸代码!总得找点事情干不是!我打工我快乐!我奋斗,我快乐!
一. 核心结构体之间的关联
二. eglCreateContext流程分析
eglCreateContext(...)//src/egl/main/eglapi.c_EGLContext *context;context = disp->Driver->CreateContext(disp, conf, share, attrib_list)//这里的Driver指向_eglDriver,定义在egl_dri2.c中dri2_create_context(...)//Called via eglCreateContext(), drv->CreateContext()struct dri2_egl_context *dri2_ctx;dri2_ctx = malloc(sizeof *dri2_ctx)dri2_ctx->dri_context = dri2_dpy->image_driver->createContextAttribs(...)//image_driver指向driImageDriverExtension,实现在dri_util.c中,指向driCreateContextAttribsreturn &dri2_ctx->base;driCreateContextAttribs(...) //src/gallium/frontends/dri/dri_util.c__DRIcontext *context;context = calloc(1, sizeof *context);context->driScreenPriv = screen;//__DRIscreen *screendri_create_context(...)//src/gallium/frontends/dri/dri_context.c__DRIscreen *sPriv = cPriv->driScreenPriv;struct dri_screen *screen = dri_screen(sPriv);struct dri_context *ctx = NULL; ctx = CALLOC_STRUCT(dri_context); cPriv->driverPrivate = ctx;//这个关系,后面必须通过关系图画出来ctx->cPriv = cPriv;ctx->sPriv = sPriv;ctx->st = st_api_create_context(&screen->base, &attribs, &ctx_err,st_share);ctx->st->st_manager_private = (void *) ctx;st_api_create_context(...) //src/mesa/state_tracker/st_manager.cstruct st_context *st;struct pipe_context *pipe;pipe = smapi->screen->context_create(smapi->screen, NULL, ctx_flags);//详见章节2.1st = st_create_context(api, pipe, mode_ptr, shared_ctx,&attribs->options, no_error,!!smapi->validate_egl_image);//详见章节2.2return &st->iface;
2.1 smapi->screen->context_create的实现
这块我们在前面分析时,已经提到过了。在vendor里面会进行赋值,如下:
struct pipe_screen *
xxx_gpu_create_screen(struct xxx_gpu_winsys *winsys)
{struct xxx_gpu_screen *screen = CALLOC_STRUCT(xxx_gpu_screen);if (!screen)return NULL;screen->ws = winsys;screen->base.get_name = xxx_gpu_get_name;screen->base.get_vendor = xxx_gpu_get_vendor;screen->base.get_device_vendor = xxx_gpu_get_device_vendor;screen->base.get_param = xxx_gpu_get_param;screen->base.get_paramf = xxx_gpu_get_paramf;screen->base.get_shader_param = xxx_gpu_get_shader_param;screen->base.get_compute_param = xxx_gpu_get_compute_param;screen->base.get_compiler_options = xxx_gpu_get_compiler_options;screen->base.is_format_supported = xxx_gpu_is_format_supported;screen->base.get_timestamp = xxx_gpu_get_timestamp;screen->base.context_create = xxx_gpu_context_create;screen->base.destroy = xxx_gpu_destroy_screen;screen->base.fence_reference = xxx_gpu_fence_reference;screen->base.fence_finish = xxx_gpu_fence_finish;screen->base.fence_get_fd = xxx_gpu_fence_get_fd;xxx_gpu_screen_resource_init(&screen->base);slab_create_parent(&screen->transfer_pool, sizeof(struct xxx_gpu_transfer), 16);glsl_type_singleton_init_or_ref();return &screen->base;
}
2.2 st_create_context的实现
接着继续往下看:
xxx_gpu_create_screen(...)//src/gallium/drivers/xxx_gpu/xxx_gpu_screen.cscreen->base.context_create = xxx_gpu_context_create;xxx_gpu_context_create(...)//src/gallium/drivers/xxx_gpu/xxx_gpu_context.cstruct xxx_gpu_screen *screen = xxx_gpu_screen(pscreen);struct xxx_gpu_context *ctx = CALLOC_STRUCT(xxx_gpu_context);ctx->base.screen = pscreen;ctx->base.priv = priv;ctx->ws = screen->ws;...ctx->base.flush = xxx_gpu_flush;...
我们接着继续分析_mesa_initialize_context
_mesa_initialize_context
_mesa_initialize_context(...)//src/mesa/main/context.cctx->Driver = *driverFunctions;/* setup the API dispatch tables with all nop functions */ctx->OutsideBeginEnd = _mesa_alloc_dispatch_table(false);_mesa_alloc_dispatch_table(...)//src/mesa/main/context.cstruct _glapi_table *table = _mesa_new_nop_table(numEntries, glthread)//和gl_dispatch分发有关struct _glapi_table *_mesa_new_nop_table(unsigned numEntries, bool glthread){struct _glapi_table *table;table = _glapi_new_nop_table(numEntries);return table;} return table;_glapi_table *_glapi_new_nop_table(...)//src/mapi/mapi_glapi.cstruct _glapi_table *table;table = malloc(num_entries * sizeof(mapi_func));memcpy(table, table_noop_array, num_entries * sizeof(mapi_func));return table//build-android-aarch64/src/mapi/shared-glapi/glapi_mapi_tmp.h
static void APIENTRY noopFlush(void)
{noop_warn("glFlush");
}
const mapi_func table_noop_array[] = {...(mapi_func) noopFlush,...
}
我们接着继续分析st_create_context_priv
st_create_context_priv
st_create_context_priv(...)//src/mesa/state_tracker/st_context.cstruct pipe_screen *screen = pipe->screen;struct st_context *st = CALLOC_STRUCT( st_context); ctx->st = st;st->ctx = ctx;st->screen = screen;st->pipe = pipe; _mesa_initialize_dispatch_tables(ctx);_mesa_initialize_dispatch_tables(...) //src/mesa/main/context.c_mesa_init_dispatch(ctx)//build-android-aarch64/src/mapi/glapi/gen/api_exec_init.cZ这个是构建完成以后生成的struct _glapi_table *table = ctx->OutsideBeginEnd;//还记得这个地方是怎么被赋值的吗SET_Flush(table, _mesa_Flush);//我们以这个实现来进行举例说明// build-android-arm/src/mesa/main/dispatch.h
#define SET_Flush(disp, func) do { \void (GLAPIENTRYP fn)(void) = func; \SET_by_offset(disp, _gloffset_Flush, fn); \
} while (0) #define SET_by_offset(disp, offset, fn) \do { \if ( (offset) < 0 ) { \/* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\n", */ \/* __func__, __LINE__, disp, offset, # fn); */ \/* abort(); */ \} \else { \( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \} \} while(0)
这里的核心是_glapi_table,它在前面已经被初始化了!
mesa 调试 —— 运行时函数栈的打印
Mesa GL Dispatch
mesa调用主线分析与理解
这篇关于Android环境下Mesa初始化流程重学习之eglCreateContext的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!