Android环境下Mesa初始化流程重学习之eglInitialize

Mesa初始化流程重学习之eglInitialize



引言

说来也惭愧,Mesa搞了这么久了,每次都想深入下,可是每次都是浅尝辄止了。这次趁着有了一定的闲暇时间并且有了调试景嘉微显卡的机会,还是想重新学习下,深入研究下!不说达到某个程度吗,至少能充实点!

这里我使用的mesa版本是22.3.7!其它版本可能存在一定差异,应该不大!

tree src/  -L 1
src/
├── amd
├── android_stub
├── asahi
├── broadcom
├── c11
├── compiler
├── drm-shim
├── egl
├── etnaviv
├── freedreno
├── gallium
├── gbm
├── getopt
├── glx
├── gtest
├── hgl
├── imagination
├── imgui
├── intel
├── loader
├── mapi
├── mesa
├── meson.build
├── microsoft
├── nouveau
├── panfrost
├── tool
├── util
├── virtio
└── vulkan29 directories, 1 filetree src/gallium/  -L 2
src/gallium/
├── auxiliary
│   ├── cso_cache
│   ├── draw
│   ├── driver_ddebug
│   ├── driver_noop
│   ├── driver_trace
│   ├── gallivm
│   ├── hud
│   ├── indices
│   ├── meson.build
│   ├── nir
│   ├── os
│   ├── pipebuffer
│   ├── pipe-loader
│   ├── postprocess
│   ├── renderonly
│   ├── rtasm
│   ├── target-helpers
│   ├── tessellator
│   ├── tgsi
│   ├── translate
│   ├── util
│   └── vl
├── drivers
│   ├── asahi
│   ├── crocus
│   ├── d3d12
│   ├── etnaviv
│   ├── freedreno
│   ├── i915
│   ├── iris
│   ├── lima
│   ├── llvmpipe
│   ├── xxx_gpu
│   ├── nouveau
│   ├── panfrost
│   ├── r300
│   ├── r600
│   ├── radeonsi
│   ├── softpipe
│   ├── svga
│   ├── tegra
│   ├── v3d
│   ├── vc4
│   ├── virgl
│   └── zink
├── frontends
│   ├── clover
│   ├── d3d10umd
│   ├── dri
│   ├── glx
│   ├── hgl
│   ├── lavapipe
│   ├── nine
│   ├── omx
│   ├── osmesa
│   ├── rusticl
│   ├── va
│   ├── vdpau
│   ├── wgl
│   └── xa
├── include
│   ├── frontend
│   ├── pipe
│   └── winsys
├── meson.build
├── README.portability
├── targets
│   ├── d3d10sw
│   ├── d3dadapter9
│   ├── dri
│   ├── dri-vdpau.dyn
│   ├── haiku-softpipe
│   ├── lavapipe
│   ├── libgl-gdi
│   ├── libgl-xlib
│   ├── omx
│   ├── opencl
│   ├── osmesa
│   ├── pipe-loader
│   ├── rusticl
│   ├── va
│   ├── vdpau
│   ├── wgl
│   └── xa
├── tests
│   ├── meson.build
│   ├── python
│   ├── trivial
│   └── unit
├── tools
│   ├── addr2line.sh
│   └── trace
└── winsys├── amdgpu├── asahi├── crocus├── d3d12├── etnaviv├── freedreno├── i915├── iris├── kmsro├── lima├── xxx_gpu├── nouveau├── panfrost├── radeon├── svga├── sw├── tegra├── v3d├── vc4└── virgl108 directories, 6 files


一. 核心结构体和关系

_EGLDisplay和dri2_egl_display之间的关系
typedef struct _egl_display _EGLDisplay;struct _egl_display
{..._EGLPlatformType Platform; /**< The type of the platform display */void *PlatformDisplay;     /**< A pointer to the platform display */_EGLDevice *Device;        //这里的Driver指向_eglDriver,实现在Egl_dri2.cconst _EGLDriver *Driver;  /**< Matched driver of the display */    .../* these fields are set by the driver during init */void *DriverData;          /**< Driver private data */指向dri2_egl_display//disp->DriverData = (void *) dri2_dpy;_EGLExtensions Extensions; /**< Extensions supported */   ...
}struct dri2_egl_display
{const struct dri2_egl_display_vtbl *vtbl;mtx_t lock;int dri2_major;int dri2_minor;__DRIscreen *dri_screen; //这个screen很重要bool own_dri_screen;const __DRIconfig **driver_configs;void *driver;const __DRIcoreExtension *core;  //这些会在初始化的时候被赋值,指向target的dri前端const __DRIimageDriverExtension *image_driver;const __DRIdri2Extension *dri2;const __DRIswrastExtension *swrast;const __DRIkopperExtension *kopper;const __DRI2flushExtension *flush;const __DRI2flushControlExtension *flush_control;const __DRItexBufferExtension *tex_buffer;const __DRIimageExtension *image;const __DRIrobustnessExtension *robustness;const __DRI2configQueryExtension *config;const __DRI2fenceExtension *fence;const __DRI2bufferDamageExtension *buffer_damage;const __DRI2blobExtension *blob;const __DRI2rendererQueryExtension *rendererQuery;const __DRI2interopExtension *interop;const __DRIconfigOptionsExtension *configOptions;const __DRImutableRenderBufferDriverExtension *mutable_render_buffer;int fd;/* dri2_initialize/dri2_terminate increment/decrement this count, so does* dri2_make_current (tracks if there are active contexts/surfaces). */int ref_count;bool own_device;bool invalidate_available;int min_swap_interval;int max_swap_interval;int default_swap_interval;
#ifdef HAVE_DRM_PLATFORMstruct gbm_dri_device *gbm_dri;
#endifchar *driver_name;const __DRIextension **loader_extensions;const __DRIextension **driver_extensions;#ifdef HAVE_X11_PLATFORMxcb_connection_t *conn;xcb_screen_t *screen;bool swap_available;
#ifdef HAVE_DRI3bool multibuffers_available;int dri3_major_version;int dri3_minor_version;int present_major_version;int present_minor_version;struct loader_dri3_extensions loader_dri3_ext;struct loader_dri3_screen_resources screen_resources;
#endif
#endif#ifdef HAVE_WAYLAND_PLATFORMstruct wl_display *wl_dpy;struct wl_display *wl_dpy_wrapper;struct wl_registry *wl_registry;struct wl_drm *wl_server_drm;struct wl_drm *wl_drm;uint32_t wl_drm_version, wl_drm_name;struct wl_shm *wl_shm;struct wl_event_queue *wl_queue;struct zwp_linux_dmabuf_v1 *wl_dmabuf;struct dri2_wl_formats formats;struct zwp_linux_dmabuf_feedback_v1 *wl_dmabuf_feedback;struct dmabuf_feedback_format_table format_table;bool authenticated;uint32_t capabilities;char *device_name;
#endif#ifdef HAVE_ANDROID_PLATFORMconst gralloc_module_t *gralloc;/* gralloc vendor usage bit for front rendering */uint32_t front_rendering_usage;
#endifbool is_render_node;bool is_different_gpu;
};

可以通过_EGLDisplay的成员DriverData找到dri2_egl_display,并且dri2_dpy是一个非常重要的结构体!

_EGLDisplay *disp
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);

__DRIscreen dri_screen pipe_screen之间关联

各种srceend的起点,是从dri2_egl_display开始的,它们之间的关联如下:

struct dri2_egl_display
{...__DRIscreen *dri_screen;...
}//这块image_driver和dri2的extensions怎么赋值来的,后面会具体分析
dri2_dpy->dri_screen = dri2_dpy->image_driver->createNewScreen2(...)或者
dri2_dpy->dri_screen = dri2_dpy->dri2->createNewScreen2(...)

我们接下来看看__DRIscreen的定义


typedef struct __DRIscreenRec		__DRIscreen;struct __DRIscreenRec {/**static const struct __DRIDriverVtableExtensionRec galliumdrm_vtable = {.base = { __DRI_DRIVER_VTABLE, 1 },.vtable = &galliumdrm_driver_api,};    这里的driver指向galliumdrm_driver_apipsp->driver =((__DRIDriverVtableExtension *)driver_extensions[i])->vtable;    **/const struct __DriverAPIRec *driver;int myNum;int fd;void *driverPrivate;void *loaderPrivate;const __DRIextension **extensions;const __DRIswrastLoaderExtension *swrast_loader;const __DRIkopperLoaderExtension *kopper_loader;struct {const __DRIdri2LoaderExtension *loader;const __DRIimageLookupExtension *image;const __DRIuseInvalidateExtension *useInvalidate;const __DRIbackgroundCallableExtension *backgroundCallable;} dri2;struct {const __DRIimageLoaderExtension *loader;} image;struct {const __DRImutableRenderBufferLoaderExtension *loader;} mutableRenderBuffer;driOptionCache optionInfo;driOptionCache optionCache;unsigned int api_mask;
};

结构体dri_screen定义:

struct dri_screen
{struct st_manager base;__DRIscreen *sPriv;//指向__DRIscreenboolean throttle;struct st_config_options options;/* Which postprocessing filters are enabled. */unsigned pp_enabled[PP_FILTERS];/* drm */int fd;boolean can_share_buffer;struct pipe_loader_device *dev;/* hooks filled in by dri2 & drisw */__DRIimage * (*lookup_egl_image)(struct dri_screen *ctx, void *handle);boolean (*validate_egl_image)(struct dri_screen *ctx, void *handle);__DRIimage * (*lookup_egl_image_validated)(struct dri_screen *ctx, void *handle);/* DRI exts that vary based on gallium pipe_screen caps. */__DRIimageExtension image_extension;__DRI2bufferDamageExtension buffer_damage_extension;/* DRI exts on this screen. Populated at init time based on device caps. */const __DRIextension *screen_extensions[14];...};struct st_manager
{struct pipe_screen *screen;//这里又和pipe_screen勾搭上了...
}

dri_screen和__DRIscreen是如何建立联系的,或者说他们之间的关系是什么:

__DRIscreen * sPriv
struct dri_screen *screen;
struct pipe_screen *pscreen = NULL;screen->sPriv = sPriv;
sPriv->driverPrivate = (void *)screen;

真可以说的上是你中有我,我中有你的典范啊。相互关联对方!


dri_screen和pipe_screen是如何建立联系的,或者说他们之间的关系是什么:

这里就不兜圈子了,直接上关系:

//src/gallium/frontends/dri/dri_screen.c
const __DRIconfig **
dri_init_screen_helper(struct dri_screen *screen,struct pipe_screen *pscreen)
{screen->base.screen = pscreen;...
}

最后可以得到如下的一张关系表,其中厂家会对dri_screen进行扩展,通过结构体的继承

在这里插入图片描述



二.Mesa下eglInitialize初始化流程

搞通了这个流程,基本把Mesa的基本框架打通了。这里我们一步一步来分析,不具体代码详细分析,只有关键地方会详细分析:

//src/egl/drivers/dri2/egl_dri2.c
const _EGLDriver _eglDriver = {.Initialize = dri2_initialize,.Terminate = dri2_terminate,.CreateContext = dri2_create_context,.DestroyContext = dri2_destroy_context,.MakeCurrent = dri2_make_current,.CreateWindowSurface = dri2_create_window_surface,.CreatePixmapSurface = dri2_create_pixmap_surface,.CreatePbufferSurface = dri2_create_pbuffer_surface,.DestroySurface = dri2_destroy_surface,.GetProcAddress = dri2_get_proc_address,.WaitClient = dri2_wait_client,.WaitNative = dri2_wait_native,.BindTexImage = dri2_bind_tex_image,.ReleaseTexImage = dri2_release_tex_image,.SwapInterval = dri2_swap_interval,.SwapBuffers = dri2_swap_buffers,.SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage,.SwapBuffersRegionNOK = dri2_swap_buffers_region,.SetDamageRegion = dri2_set_damage_region,.PostSubBufferNV = dri2_post_sub_buffer,.CopyBuffers = dri2_copy_buffers,.QueryBufferAge = dri2_query_buffer_age,.CreateImageKHR = dri2_create_image,.DestroyImageKHR = dri2_destroy_image_khr,.CreateWaylandBufferFromImageWL = dri2_create_wayland_buffer_from_image,.QuerySurface = dri2_query_surface,.QueryDriverName = dri2_query_driver_name,.QueryDriverConfig = dri2_query_driver_config,
#ifdef HAVE_LIBDRM.CreateDRMImageMESA = dri2_create_drm_image_mesa,.ExportDRMImageMESA = dri2_export_drm_image_mesa,.ExportDMABUFImageQueryMESA = dri2_export_dma_buf_image_query_mesa,.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa,.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats,.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers,
#endif
#ifdef HAVE_WAYLAND_PLATFORM.BindWaylandDisplayWL = dri2_bind_wayland_display_wl,.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl,.QueryWaylandBufferWL = dri2_query_wayland_buffer_wl,
#endif.GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium,.GetMscRateANGLE = dri2_get_msc_rate_angle,.CreateSyncKHR = dri2_create_sync,.ClientWaitSyncKHR = dri2_client_wait_sync,.SignalSyncKHR = dri2_signal_sync,.WaitSyncKHR = dri2_server_wait_sync,.DestroySyncKHR = dri2_destroy_sync,.GLInteropQueryDeviceInfo = dri2_interop_query_device_info,.GLInteropExportObject = dri2_interop_export_object,.GLInteropFlushObjects = dri2_interop_flush_objects,.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd,.SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs,
};
eglInitialize(...)//src/egl/main/eglapi.c_eglDriver.Initialize(disp)dri2_initialize(...)//src/egl/drivers/dri2/egl_dri2.cdri2_initialize_android(disp)//src/egl/drivers/dri2/platform_android.c

这里我们对dri2_initialize_android拿出来,另开分析,只是让后面自己回过头看更加清楚!

dri2_initialize_android(_EGLDisplay *disp)struct dri2_egl_display *dri2_dpy;dri2_dpy = calloc(1, sizeof(*dri2_dpy));disp->DriverData = (void *) dri2_dpy;ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,(const hw_module_t **)&dri2_dpy->gralloc);device_opened = droid_open_device(disp, disp->Options.ForceSoftware);dri2_dpy->vtbl = &droid_display_vtbl;droid_open_device(...)// src/egl/drivers/dri2/platform_android.cstruct dri2_egl_display *dri2_dpy = dri2_egl_display(disp)dri2_dpy->fd = loader_open_device(device->nodes[node_type])droid_probe_device(...)droid_load_driver(..)//这个非常重要,加载驱动dri2_dpy->loader_extensions = droid_image_loader_extensions;dri2_load_driver_dri3(...)dri2_create_screen(...)//构建screen,关于scrren的关系图前面已经放出来了,详见章节3

我们接下来分析dri2_load_driver_dri3的调用流程,代码流程比较多,只能一步步的来:

static const struct dri2_extension_match dri3_driver_extensions[] = {{ __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) },{ __DRI_IMAGE_DRIVER, 1, offsetof(struct dri2_egl_display, image_driver) },{ NULL, 0, 0 }
};
dri2_load_driver_dri3(...)//src/egl/drivers/dri2/egl_dri2.cdri2_load_driver_common(disp, dri3_driver_extensions)extensions = dri2_open_driver(disp)//详见章节2.1dri2_bind_extensions(dri2_dpy, driver_extensions, extensions, false)//详见章节2.2dri2_dpy->driver_extensions = extensions

2.1 dri2_open_driver

我们接下来重点分析该函数:

 dri2_open_driver()//src/egl/drivers/dri2/egl_dri2.cconst struct __DRIextensionRec **(*get_extensions)(void);void *driver = loader_open_driver_lib(driver_name, "_dri", search_path_vars,DEFAULT_DRIVER_DIR, true);//加载dri库get_extensions_name = loader_get_extensions_name(driver_name)//拼接驱动extensions名称,这里的拼接后是__driDriverGetExtensions_xxx_gpuget_extensions = dlsym(driver, get_extensions_name)//加载函数符号表等

这里的__driDriverGetExtensions_xxx_gpu函数符号表是怎么拼凑成的了,如果我们通过grep在mesa搜索,怎么搜索也搜不到了。它是通过宏定义实现的。它的定义如下:

//src/gallium/targets/dri/target.c
#define DEFINE_LOADER_DRM_ENTRYPOINT(drivername)                          \
const __DRIextension **__driDriverGetExtensions_##drivername(void);       \
PUBLIC const __DRIextension **__driDriverGetExtensions_##drivername(void) \
{                                                                         \return galliumdrm_driver_extensions;                                   \
}#if defined(GALLIUM_MWV207)
DEFINE_LOADER_DRM_ENTRYPOINT(xxx_gpu);  //这里我们也可以扩展,自己的驱动,譬如XXX参照这个
#endif

这里我们重点关注galliumdrm_driver_extensions的实现,我们接着继续往下看:

注意它的实现在代码是在frontends前端目录代码下


//src/gallium/frontends/dri/dri2.c
const __DRIextension *galliumdrm_driver_extensions[] = {&driCoreExtension.base,&driImageDriverExtension.base,&driDRI2Extension.base,&gallium_config_options.base,&galliumdrm_vtable.base,NULL
};//src/gallium/frontends/dri/dri_util.c
/** Core interface */
const __DRIcoreExtension driCoreExtension = {.base = { __DRI_CORE, 2 },.createNewScreen            = NULL,.destroyScreen              = driDestroyScreen,.getExtensions              = driGetExtensions,.getConfigAttrib            = driGetConfigAttrib,.indexConfigAttrib          = driIndexConfigAttrib,.createNewDrawable          = NULL,.destroyDrawable            = driDestroyDrawable,.swapBuffers                = driSwapBuffers, /* swrast */.createNewContext           = driCreateNewContext, /* swrast */.copyContext                = driCopyContext,.destroyContext             = driDestroyContext,.bindContext                = driBindContext,.unbindContext              = driUnbindContext
};/** Image driver interface */
const __DRIimageDriverExtension driImageDriverExtension = {.base = { __DRI_IMAGE_DRIVER, 1 },.createNewScreen2           = driCreateNewScreen2,.createNewDrawable          = driCreateNewDrawable,.getAPIMask                 = driGetAPIMask,.createContextAttribs       = driCreateContextAttribs,
};/** DRI2 interface */
const __DRIdri2Extension driDRI2Extension = {.base = { __DRI_DRI2, 4 },.createNewScreen            = dri2CreateNewScreen,.createNewDrawable          = driCreateNewDrawable,.createNewContext           = driCreateNewContext,.getAPIMask                 = driGetAPIMask,.createNewContextForAPI     = driCreateNewContextForAPI,.allocateBuffer             = dri2AllocateBuffer,.releaseBuffer              = dri2ReleaseBuffer,.createContextAttribs       = driCreateContextAttribs,.createNewScreen2           = driCreateNewScreen2,
};//src/gallium/frontends/dri/dri2.c
static const struct __DRIDriverVtableExtensionRec galliumdrm_vtable = {.base = { __DRI_DRIVER_VTABLE, 1 },.vtable = &galliumdrm_driver_api,
};

2.2 dri2_bind_extensions

我们接下来重点分析该函数:

static EGLBoolean
dri2_bind_extensions(struct dri2_egl_display *dri2_dpy,const struct dri2_extension_match *matches,const __DRIextension **extensions,bool optional)
{int ret = EGL_TRUE;void *field;for (int i = 0; extensions[i]; i++) {_eglLog(_EGL_DEBUG, "found extension `%s'", extensions[i]->name);for (int j = 0; matches[j].name; j++) {if (strcmp(extensions[i]->name, matches[j].name) == 0 &&extensions[i]->version >= matches[j].version) {field = ((char *) dri2_dpy + matches[j].offset);*(const __DRIextension **) field = extensions[i];_eglLog(_EGL_INFO, "found extension %s version %d",extensions[i]->name, extensions[i]->version);break;}}}for (int j = 0; matches[j].name; j++) {field = ((char *) dri2_dpy + matches[j].offset);if (*(const __DRIextension **) field == NULL) {if (optional) {_eglLog(_EGL_DEBUG, "did not find optional extension %s version %d",matches[j].name, matches[j].version);} else {_eglLog(_EGL_WARNING, "did not find extension %s version %d",matches[j].name, matches[j].version);ret = EGL_FALSE;}}}return ret;
}

我们可以理解这个函数,这个函数主要是填充dri2_egl_display中的各个extensions扩展,譬如:

//src/egl/drivers/dri2/egl_dri2.h
struct dri2_egl_display
{...const __DRIcoreExtension *core;const __DRIimageDriverExtension *image_driver;const __DRIdri2Extension *dri2;const __DRIswrastExtension *swrast;const __DRIkopperExtension *kopper;const __DRI2flushExtension *flush;const __DRI2flushControlExtension *flush_control;const __DRItexBufferExtension *tex_buffer;const __DRIimageExtension *image;const __DRIrobustnessExtension *robustness;const __DRI2configQueryExtension *config;const __DRI2fenceExtension *fence;const __DRI2bufferDamageExtension *buffer_damage;const __DRI2blobExtension *blob;const __DRI2rendererQueryExtension *rendererQuery;const __DRI2interopExtension *interop;const __DRIconfigOptionsExtension *configOptions;const __DRImutableRenderBufferDriverExtension *mutable_render_buffer;    ...
}


三. dri2_create_screen的实现

万里长征刚开始,到这里还只是第一步啊,得接续往下走,我们接着接续分析!

//src/egl/drivers/dri2/egl_dri2.c
dri2_create_screen(...)dri2_dpy->dri_screen = dri2_dpy->image_driver->createNewScreen2(....)

这里的dri2_dpy->image_driver指向那里呢,这里可以在章节2.1和章节2.2找到答案,它指向了dri_util.c里面的结构体driImageDriverExtension,如下:

//src/gallium/frontends/dri/dri_util.c
/** Image driver interface */
const __DRIimageDriverExtension driImageDriverExtension = {.base = { __DRI_IMAGE_DRIVER, 1 },.createNewScreen2           = driCreateNewScreen2,.createNewDrawable          = driCreateNewDrawable,.getAPIMask                 = driGetAPIMask,.createContextAttribs       = driCreateContextAttribs,
};

所以我们继续看driCreateNewScreen2的实现:

//src/gallium/frontends/dri/dri_util.c
driCreateNewScreen2(...)__DRIscreen *psppsp = calloc(1, sizeof(*psp))psp->driver =((__DRIDriverVtableExtension *)driver_extensions[i])->vtable;//指向galliumdrm_driver_apipsp->driver->InitScreen(psp)//这里会指向galliumdrm_driver_api中dri2_init_screen,在dri2.c中实现

我们接着来看dri2_init_screen的实现:

//src/gallium/frontends/dri/dri2.c
static const __DRIconfig **
dri2_init_screen(__DRIscreen * sPriv)
{const __DRIconfig **configs;struct dri_screen *screen;//各种screen开始出现struct pipe_screen *pscreen = NULL;screen = CALLOC_STRUCT(dri_screen);//构建一个,还没有开始初始化screen->sPriv = sPriv;//开始指向,并赋值了screen->fd = sPriv->fd;sPriv->driverPrivate = (void *)screen;//相互引用if (pipe_loader_drm_probe_fd(&screen->dev, screen->fd)) {//详见章节3.1pscreen = pipe_loader_create_screen(screen->dev);//详见章节3.2dri_init_options(screen);}dri2_init_screen_extensions(screen, pscreen, false);configs = dri_init_screen_helper(screen, pscreen);...
}

为了排版简介明了一些,这里我们不全部放在一个大章节里面,而是进行小章节,这样排版会更加合理看起来也更加的舒服!


3.1 pipe_loader_drm_probe_fd

我们接着继续往下分析该源码的实现:

//src/gallium/auxiliary/pipe-loader/pipe_loader_drm.cstatic struct pipe_screen *
pipe_loader_drm_create_screen(struct pipe_loader_device *dev,const struct pipe_screen_config *config, bool sw_vk)
{struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(dev);return ddev->dd->create_screen(ddev->fd, config);
}static const struct pipe_loader_ops pipe_loader_drm_ops = {.create_screen = pipe_loader_drm_create_screen,.get_driconf = pipe_loader_drm_get_driconf,.release = pipe_loader_drm_release
};pipe_loader_drm_probe_fd(...)pipe_loader_drm_probe_fd_nodup(struct pipe_loader_device **dev, int fd)struct pipe_loader_drm_device *ddev = CALLOC_STRUCT(pipe_loader_drm_device);ddev->base.ops = &pipe_loader_drm_ops;ddev->fd = fd;ddev->base.driver_name = loader_get_driver_for_fd(fd)ddev->dd = get_driver_descriptor(ddev->base.driver_name, plib)*dev = &ddev->base;

我们接着看get_driver_descriptor的实现,看看它究竟在干啥!

//src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
#ifdef GALLIUM_STATIC_TARGETS
static const struct drm_driver_descriptor *driver_descriptors[] = {&i915_driver_descriptor,&iris_driver_descriptor,&crocus_driver_descriptor,&nouveau_driver_descriptor,&r300_driver_descriptor,&r600_driver_descriptor,&radeonsi_driver_descriptor,&vmwgfx_driver_descriptor,&kgsl_driver_descriptor,&msm_driver_descriptor,&virtio_gpu_driver_descriptor,&v3d_driver_descriptor,&vc4_driver_descriptor,&panfrost_driver_descriptor,&asahi_driver_descriptor,&etnaviv_driver_descriptor,&tegra_driver_descriptor,&lima_driver_descriptor,&zink_driver_descriptor,&xxx_gpu_driver_descriptor,
};
#endifstatic const struct drm_driver_descriptor *
get_driver_descriptor(const char *driver_name, struct util_dl_library **plib)
{
#ifdef GALLIUM_STATIC_TARGETSfor (int i = 0; i < ARRAY_SIZE(driver_descriptors); i++) {if (strcmp(driver_descriptors[i]->driver_name, driver_name) == 0)return driver_descriptors[i];}return &kmsro_driver_descriptor;
#else...
#endif...
}

那么这里的xxx_driver_descriptor是怎么实现的,刚开始我通过grep搜索发现只有定义,没有怎么实现。尼玛见鬼了不成,这又是套路啊,又是通过各种宏来实现的。我们看看它是怎么实现的(这里我以景嘉微的xxx_gpu为例来说明)。

//src/gallium/auxiliary/target-helpers/drm_helper.h/*** Instantiate a drm_driver_descriptor struct.*/
#define DEFINE_DRM_DRIVER_DESCRIPTOR(descriptor_name, driver, _driconf, _driconf_count, func) \
const struct drm_driver_descriptor descriptor_name = {         \.driver_name = #driver,                                     \.driconf = _driconf,                                        \.driconf_count = _driconf_count,                            \.create_screen = func,                                      \
};#define DRM_DRIVER_DESCRIPTOR(driver, driconf, driconf_count)                          \DEFINE_DRM_DRIVER_DESCRIPTOR(driver##_driver_descriptor, driver, driconf, driconf_count, pipe_##driver##_create_screen)#include "xxx_gpu/drm/xxx_gpu_drm_public.h"static struct pipe_screen *
pipe_xxx_gpu_create_screen(int fd, const struct pipe_screen_config *config)
{struct pipe_screen *screen;screen = xxx_gpu_drm_create_screen(fd);return screen ? debug_screen_wrap(screen) : NULL;
}DRM_DRIVER_DESCRIPTOR(xxx_gpu, NULL, 0)

所以分析到这里我们获得了ddev->dd的指向,它指向了vendor实现的结构体drm_driver_descriptor。搞清楚了这个我们接着继续看 ddev->dd->create_screen的实现,它指向了pipe_xxx_gpu_create_screen,我们接着分析:

//src/gallium/auxiliary/target-helpers/drm_helper.h
static struct pipe_screen *
pipe_xxx_gpu_create_screen(int fd, const struct pipe_screen_config *config)
{struct pipe_screen *screen;screen = xxx_gpu_drm_create_screen(fd);//返回封装好的pipe_screenstruct xxx_gpu_winsys *ws;ws = CALLOC_STRUCT(xxx_gpu_winsys)ws->screen = xxx_gpu_create_screen(ws)return ws->screenreturn screen ? debug_screen_wrap(screen) : NULL;
}

3.2 pipe_loader_create_screen

分析完了pipe_loader_drm_probe_fd流程,我们接着咔咔一顿接着继续分析,pipe_loader_create_screen它会构建pipe_screen的结构体类型!

pipe_loader_create_screen(...)//src/gallium/frontends/dri/dri2.cpipe_loader_create_screen(...)//src/gallium/auxiliary/pipe-loader/pipe_loader.cpipe_loader_create_screen_vk(...)dev->ops->create_screen(...)//这里的ops指向了pipe_loader_drm_ops,定义在pipe_loader_drm.c  pipe_loader_drm_create_screen(...)ddev->dd->create_screen(...)//这里的ddev->dd指向了前面获取的结构体pipe_xxx_gpu_create_screen(...)

到这里整个流程就基本结束了。后续如果需要查看的,可以继续dri2_init_screen研究,主要是要理清楚几个screen之间的关系!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/335001.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

springboot集成nacos

springboot集成nacos 1.版本2. POM依赖3. nacos服务3.1 下载nacos压缩包3.2 启动nacos 4. yaml配置5.Demo5.1 配置中心简单格式获取方式普通方式还可以再启动类上添加注解完成5.2 获取json格式的demo5.2 自动注册根据yaml配置 1.版本 nacos版本:2.3.2 springboot版本&#xff…

护网2024-攻防对抗解决方案思路

一、护网行动简介 近年来&#xff0c;网络安全已被国家上升为国家安全的战略层面&#xff0c;网络安全同样也被视为维护企业业务持续性的关键。国家在网络安全治理方面不断出台法规与制度&#xff0c;并实施了一些大型项目和计划&#xff0c;如网络安全法、等级保护、网络安全…

idea项目一直在build

IDEA项目一直在build的原因可能包括构建进程堆大小过小、缓存问题、依赖包下载缓慢或网络问题。12 构建进程堆大小过小&#xff1a;如果IDEA的构建进程堆大小设置得不够大&#xff0c;可能会导致构建过程缓慢或卡顿。解决方法是将构建进程堆大小参数扩大&#xff0c;例如将700…

介绍Django Ninja框架

文章目录 安装快速开始特性详解自动文档生成定义请求和响应模型异步支持中间件支持测试客户端 结论 Django Ninja是一个基于Python的快速API开发框架&#xff0c;它结合了Django和FastAPI的优点&#xff0c;提供了简单易用的方式来构建高性能的Web API。 安装 使用以下命令安…

消费增值的真面目!绿色积分的合理运用!

各位朋友&#xff0c;大家好&#xff01;我是吴军&#xff0c;来自一家备受瞩目的软件开发企业&#xff0c;担任产品经理一职。今天&#xff0c;我非常荣幸能有机会与大家分享一种在市场上备受瞩目的新型商业模式——消费增值模式。 随着环保和可持续发展理念日益深入人心&…

【学习笔记】计算机组成原理(八)

CPU 的结构和功能 文章目录 CPU 的结构和功能8.1 CPU的结构8.1.1 CPU的功能8.1.2 CPU结构框图8.1.3 CPU的寄存器8.1.4 控制单元CU和中断系统 8.2 指令周期8.2.1 指令周期的基本概念8.2.2 指令周期的数据流 8.3 指令流水8.3.1 指令流水原理8.3.2 影响流水线性能的因素8.3.3 流水…

【错误记录】HarmonyOS 运行报错 ( Failure INSTALL _PARSE _FAILED _USESDK _ERROR )

文章目录 一、报错信息二、问题分析三、解决方案 一、报错信息 在 DevEco Studio 中 , 使用 远程设备 , 向 P40 Failure[INSTALL_PARSE_FAILED_USESDK_ERROR] compileSdkVersion and releaseType of the app do not match the apiVersion and releaseType on the device. 二、…

Filebeat进阶指南:核心架构与功能组件的深度剖析

&#x1f407;明明跟你说过&#xff1a;个人主页 &#x1f3c5;个人专栏&#xff1a;《洞察之眼&#xff1a;ELK监控与可视化》&#x1f3c5; &#x1f516;行路有良友&#xff0c;便是天堂&#x1f516; 目录 一、引言 1、什么是ELK 2、FileBeat在ELK中的角色 二、Fil…

前端渲染页面的原理

之前一直不愿意写一篇关于原理的&#xff0c;因为说起来实在是太繁杂&#xff0c;要写得细&#xff0c;码字梳理&#xff0c;计算下来起码都要差不多三周。以前一直躲避这个事情&#xff0c;现在反正有时间&#xff0c;为了不荒废自己&#xff0c;那就从头捋一遍。也方便自己后…

刷代码随想录有感(81):贪心算法——分发饼干

题干&#xff1a; class Solution { public:int findContentChildren(vector<int>& g, vector<int>& s) {sort(g.begin(), g.end());sort(s.begin(), s.end());int index s.size() - 1;int res 0;for(int i g.size() - 1; i > 0; i--){if(index >…

MyBatis学习笔记(周五前学完)

MyBatis-Plus是一个MyBatis的增强工具。在MyBatis的基础上只做增强不做改变&#xff0c;为简化开发、提高效率而生。 通过MyBatis-Plus来进行数据插入时&#xff0c;它默认会 使用雪花算法来生成id&#xff0c;长度比较长 增删改的返回值都是统一的&#xff0c;影响的只有行数。…

react ant 表格实现 拖拽排序和多选

项目背景 : react ant 要实现 : 有多选功能(实现批量删除 , 也可以全选) 可以拖拽(可以复制 , 方便顶部的搜索功能) 要实现效果如下 1 这是最初的拖拽功能实现 , 不能复制表格里的内容 , 不符合要求 2 更改了ROW的内容 , 实现了可以复制表格内容 代码 //控制是否可以选中表格…

Petalinux 制作ZYNQ镜像文件流程

1概述 在Zynq-7000 SoC中搭建运行Linux&#xff0c;嵌入式软件栈。 处理器系统引导是一个分两个阶段的过程。第一个阶段是一个内部 BootROM&#xff0c;它存储 stage-0 的引导代码。BootROM 在 CPU 0 上执行&#xff0c;CPU 1 执行等待事件&#xff08;WFE&#xff09;指令。…

english语法

从句&#xff1a;简单句连词 介词

PaddleSeg训练推理及模型转换全流程

文章目录 1、数据准备1.1 数据标注1.2 数据导出1.3 标签较验1.4 数据集整理1.5 标签可视化 2、 模型训练3、模型验证4、模型推理5、模型导出6、导出文件的推理7、将模型转换成onnx8、使用onnx进行推理 本文记录一下使用paddleseg进行语议分割模型对人体进行分割的使用流程。事实…

基础8 探索JAVA图形编程桌面:邮件操作组件详解

在一个静谧的午后&#xff0c;卧龙和凤雏相邀来到一家古朴典雅的茶馆。茶馆内环境清幽&#xff0c;袅袅的茶香与悠扬的古筝声交织在一起&#xff0c;营造出一种宁静而祥和的氛围。 卧龙和凤雏坐在茶馆的一角&#xff0c;面前的桌子上摆放着一套精致的茶具。茶香四溢&#xff0c…

科技查新是什么?一文了解!

本文主要解答 1、什么是科技查新&#xff1f; 2、科技查新有哪些作用&#xff1f; 3、科技查新一般应用于什么地方&#xff1f; 4、在哪能出具正规查新报告&#xff1f; 5、科技查新流程是怎样的&#xff1f; 带着这些问题阅读这篇文章相信一定会有收获&#xff01;干活内…

第十三届蓝桥杯国赛大学B组填空题(c++)

A.2022 动态规划 AC; #include<iostream> #define int long long using namespace std; int dp[2050][15]; //dp[i][j]:把数字i分解为j个不同的数的方法数 signed main(){dp[0][0]1;for(int i1;i<2022;i){for(int j1;j<10;j){//一种是已经分成j个数,这时只需每一个…

服务器上创建搭建gitlab

一、下载与安装 在主目录操作~ 1.使用wget下载 wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.0.1-ce.0.el7.x86_64.rpm 可以在开源软件镜像站选择合适的版本&#xff0c;版本不同页面菜单会稍有差异&#xff0c;此次选…

【云原生 | 59】Docker中通过docker-compose部署ELK

目录 1、组件介绍 2 、项目环境 2.1 各个环境版本 2.2 Docker-Compose变量配置 2.3 Docker-Compose服务配置 3、在Services中声明了四个服务 3.1 ElasticSearch服务 3.2 Logstash服务 3.3 Kibana服务 3.4 Filebeat服务 4、使用方法 4.1 方法一 4.2 方法二 5、启动…