版本:20.0.8
硬件:i965
入口:_mesa_DrawArrays
before: flush vertex if needed
- _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx));
设置vao相关的内容,load数据等,过程比较复杂 - _mesa_draw_arrays(ctx, mode, start, count, 1, 0, 0);
prim的定义:
struct _mesa_prim
{
GLuint mode:8; /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */
GLuint indexed:1;
GLuint begin:1;
GLuint end:1;
GLuint is_indirect:1;
GLuint pad:20;
GLuint start;
GLuint count;
GLint basevertex;
GLuint num_instances;
GLuint base_instance;
GLuint draw_id;
GLsizeiptr indirect_offset;
};
ctx->Driver.Draw(ctx, &prim, 1, NULL, GL_TRUE, start, start + count - 1, NULL, 0, NULL);
走到 brw_draw_prims 这个函数中,这个函数就到了intel的具体驱动中了,主要是prepare、draw_prim和flush
- brw_prepare_drawing(intel_prepare_render): 准备sample、texture、shader等资源。
- brw_draw_single_prim: 这里面是render的过程调用到 mesa/drivers/dri/i965/genX_pipe_control.c 中控制draw的流程,驱动的函数是brw_batch_emit (里面具体的详细过程没有看)
- brw_finish_drawing: 进行标志的判断
Driver create context 的加载过程
- eglInitialize下的调用_eglMatchDriver => _eglMatchAndInitialize => dri2_initialize => dri2_initialize_x11 => dri2_load_driver => dri2_open_driver => loader_open_driver
return loader_open_driver(dri2_dpy->driver_name,
&dri2_dpy->driver,
search_path_vars);
loader_open_driver -> loader_get_extensions_name函数中
#define DEFINE_LOADER_DRM_ENTRYPOINT(drivername) \
const __DRIextension **__driDriverGetExtensions_##drivername(void); \
PUBLIC const __DRIextension **__driDriverGetExtensions_##drivername(void) \
{ \
globalDriverAPI = &galliumdrm_driver_api; \
return galliumdrm_driver_extensions; \
}
……
……
asprintf(&name, "%s_%s", __DRI_DRIVER_GET_EXTENSIONS, driver_name)
拼出函数名 __driDriverGetExtensions_xxx,其他的驱动都是在mesa/src/gallium/targets/dri/target.c 中调用上面的宏DEFINE_LOADER_DRM_ENTRYPOINT加载,src/mesa/drivers/dri/common/megadriver_stub.c 给出了porting的demo框架。
PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void)
{
globalDriverAPI = &brw_driver_api;
return brw_driver_extensions;
}
这里将driver统一挂在globalDriverAPI上,这个globalDriverAPI在初始化的时候给到ctx上,后面的egl一些主要API调用中就调用到这几个函数。
2 . 上面的glDraw函数挂在是在eglCreateContext开始的,
eglCreateContext中:drv->API.CreateContext 调到 dri2_create_context
=> dri2_dpy->dri2->createContextAttribs 调到 driCreateContextAttribs
=> screen->driver->CreateContext 调到 brwCreateContext
调用到globalDriverAPI 中的 brwCreateContext。
mesa/drivers/dri/i965/brw_context.c: brwCreateContext
brw_init_driver_functions(brw, &functions);
brw_init_driver_function 中按照功能模块初始化所有的functions,其中包含draw函数:
void
brw_init_draw_functions(struct dd_function_table *functions)
{
functions->Draw = brw_draw_prims;
functions->DrawIndirect = brw_draw_indirect_prims;
}
初始化完成后所有driver function都填充上后,brwCreateContext 中再调用:
_mesa_initialize_context(ctx, api, mesaVis, shareCtx, &functions)
_mesa_initialize_context 中给到将gl driver funciotn挂在gl_context上
ctx->Driver = *driverFunctions;
后面的drawArray中的调用: ctx->Driver.Draw 就直接调用到brw_draw_prims这个函数上。
总结:
gl driver functions 的加载是在 eglCreateContext 下完成的,从上到下分了三层:egl Driver API -> dri2Extensiont(egl的几个context相关函数,具体的porting要填充这个,实现自己的_DriverAPIRec)-> gl driver API (这个挂在gl context上)
后面各 gl API 调用的时候从 gl ctx -> driver 中取。