loading and initializing Gallium driver
1) program calls OpenGL API
main cube.c:90 glutCreateWindow glut_win.c:731
__glutCreateWindow glut_win.c:522
__glutDetermineVisual glut_win.c:401
__glutGetVisualInfo glut_win.c:383
getVisualInfoRGB glut_win.c:348
2) OpenGL API calls GLX extension which loads Gallium Driver and binds OpenGL, DRI state checker, and HW pipe driver.
__glXIintialize() glxext.c
– init DRI per display data & functions:
– Create display structs by calling:
– dri2CreateDisplay glx/dri2_glx.c
– driCreateDisplay glx/dri_glx.c
– drwswCreateDisplay glx/drisw_glx.c
& save in display struct ptr to screen create functions
– dri2Display->createScreen = dri2CreateScreen (dir2_glx.c)
– driswDisplay->createScreen = driCreateScreen (dirsw_glx.c)
– then calls AllocAndFetchScreenConfigs to create screen, calling:
– dri2Display->createScreen() (for hardware)
– driswDisplay->createScreen() (for softpipe)
the screen screate functions:
– dlloads dri/drisw driver module and open driver
– dlsym DRI ext. table DRI_DRIVER_EXTENSIONS (__driDriverExtenaions)
– calls createNewScreen() in DRI driver extension table (in DRI st tracker)
– dri2CreateNewScreen (hw pipes – dri_util.c)
– driCreateNewScreen (soft pipe – dirsw_util.c)
these saves ptr to DRI Driver Vitrual Function table (in DRI st tracker)
then calls the init function in the table,
– driDriverAPI.InitScreen2 (dri2_init_screen – dri2.c for hw pipes)
– driDriverAPI.InitScreen (drisw_init_screen – drisw.c for soft pipe)
which binds DRI st tracker and OpenGL, and
calls create_screen ptr in Driver Descriptor Table (in individual driver)
————————————————————–
DRI Driver Extension Tables
~/src/gallium/state_trackers/dri/drm/dri2.c (for hw pipe drivers)
/* This is the table of extensions that the loader will dlsym() for. */
PUBLIC const __DRIextension *__driDriverExtensions[] = {
&driCoreExtension.base,
&driLegacyExtension.base,
&driDRI2Extension.base,
NULL
};
~/src/gallium/state_trackers/dri/sw/drisw.c (for softpipe)
/* This is the table of extensions that the loader will dlsym() for. */
PUBLIC const __DRIextension *__driDriverExtensions[] = {
&driCoreExtension.base,
&driSWRastExtension.base,
NULL
};
————————————————————–
* note: The DRI interface table is defined in dri_util.c for gallium DRI drivers
The ones defined in ~/src/mesa/drivers/dri/xxx are for pre-gallium DRI drivers
~/src/mesa/drivers/dri/common/dri_util.c
/** DRI2 interface */
const __DRIdri2Extension driDRI2Extension = {
{ __DRI_DRI2, __DRI_DRI2_VERSION },
dri2CreateNewScreen, /* called by dri2CreateScreen */
dri2CreateNewDrawable,
dri2CreateNewContext,
dri2GetAPIMask,
dri2CreateNewContextForAPI
};
~/src/mesa/drivers/dri/common/drisw_util.c
const __DRIswrastExtension driSWRastExtension = {
{ __DRI_SWRAST, __DRI_SWRAST_VERSION },
driCreateNewScreen, /* called by driCreateScreen */
driCreateNewDrawable
};
————————————————————–
DRI Driver Virtual function tables
~/src/gallium/state_trackers/dri/drm/dri2.c (for hardware pipes)
/* DRI driver virtual function table. */
const struct __DriverAPIRec driDriverAPI = {
.InitScreen = NULL,
.InitScreen2 = dri2_init_screen,
.DestroyScreen = dri_destroy_screen,
.CreateContext = dri2_create_context,
.DestroyContext = dri_destroy_context,
.CreateBuffer = dri2_create_buffer,
.DestroyBuffer = dri_destroy_buffer,
.MakeCurrent = dri_make_current,
.UnbindContext = dri_unbind_context,
.GetSwapInfo = NULL,
.GetDrawableMSC = NULL,
.WaitForMSC = NULL,
.SwapBuffers = NULL,
.CopySubBuffer = NULL,
};
~/src/gallium/state_trackers/dri/sw/drisw.c (for softpipe)
const struct __DriverAPIRec driDriverAPI = {
.InitScreen = drisw_init_screen,
.DestroyScreen = dri_destroy_screen,
.CreateContext = dri_create_context,
.DestroyContext = dri_destroy_context,
.CreateBuffer = drisw_create_buffer,
.DestroyBuffer = dri_destroy_buffer,
.MakeCurrent = dri_make_current,
.UnbindContext = dri_unbind_context,
.SwapBuffers = drisw_swap_buffers,
};
————————————————————–
Gallium Driver Descriptor Table (used for HW pipes only)
e.g. gallium/targets/dri-i915/target.c
defines:
create_screen() init i915 winsys and screen
i915_drm_winsys_create() winsys/i915/drm/i915_drm_winsys.c
i915_screen_create() drivers/i915/i915_screen.c:
driver_descriptor global struc:
driver_descriptor.name = i915
.driver_name = i915;
.create-screen = create screen
————————————————————–
Context creation flows through in similar manner:
dri2_glx.c:
static const struct glx_screen_vtable dri2_screen_vtable = {
dri2_create_context
};
glxcmds.c: glXCreateContext
-> glxcmds: CreateContext
-> dri2.c: dri2_create_context (via dri2_screen_vtable)
-> …
The actual hw rendering interface hooks into the context jump table setup here.