小工具知识网

当前位置: 首页 > 行业知识 > Mesa Gallium框架入门初探

行业知识

Mesa Gallium框架入门初探

2026-10-27 16:12:34 来源:互联网转载

Mesa Gallium框架入门初探

MESA Gallium框架

MESA源码里面有2套架构,现在驱动主要基于Gallium架构。 这里我们重点来看看Gallium架构:

经典架构 Gallium架构


Gallium展开

Gallium中主要包含下面几块:

  • Auxiliary模块:一些公共函数或者辅助的服务,比如状态缓存和缓存管理等。

    tree   src/gallium/auxiliary/ -L 1src/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└── vl21 directories, 1 file
  • State Tracker: 它负责把上层库的state(blend modes、texture statte等)和draw command(glDrawArrays、glDrawPixels)等转换成MESA内部的pipe对象和操作。

    tree src/mesa/state_tracker/  -L 1src/mesa/state_tracker/├── st_atifs_to_nir.c├── st_atifs_to_nir.h├── st_atom_array.cpp├── st_atom_atomicbuf.c├── st_atom_blend.c├── st_atom.c├── st_atom_clip.c├── st_atom_constbuf.c├── st_atom_constbuf.h├── st_atom_depth.c├── st_atom_framebuffer.c├── st_atom.h├── st_atom_image.c├── st_atom_list.h├── st_atom_msaa.c├── st_atom_pixeltransfer.c├── st_atom_rasterizer.c├── st_atom_sampler.c├── st_atom_scissor.c├── st_atom_shader.c├── st_atom_stipple.c├── st_atom_storagebuf.c├── st_atom_tess.c├── st_atom_texture.c├── st_atom_viewport.c├── st_cb_bitmap.c├── st_cb_bitmap.h├── st_cb_clear.c├── st_cb_clear.h├── st_cb_copyimage.c├── st_cb_copyimage.h├── st_cb_drawpixels.c├── st_cb_drawpixels.h├── st_cb_drawtex.c├── st_cb_drawtex.h├── st_cb_eglimage.c├── st_cb_eglimage.h├── st_cb_feedback.c├── st_cb_feedback.h├── st_cb_flush.c├── st_cb_flush.h├── st_cb_rasterpos.c├── st_cb_rasterpos.h├── st_cb_readpixels.c├── st_cb_readpixels.h├── st_cb_texture.c├── st_cb_texture.h├── st_context.c├── st_context.h├── st_copytex.c├── st_copytex.h├── st_debug.c├── st_debug.h├── st_draw.c├── st_draw_feedback.c├── st_draw.h├── st_draw_hw_select.c├── st_extensions.c├── st_extensions.h├── st_format.c├── st_format.h├── st_gen_mipmap.c├── st_gen_mipmap.h├── st_glsl_to_ir.cpp├── st_glsl_to_ir.h├── st_glsl_to_nir.cpp├── st_interop.c├── st_interop.h├── st_manager.c├── st_manager.h├── st_nir_builtins.c├── st_nir.h├── st_nir_lower_builtin.c├── st_nir_lower_tex_src_plane.c├── st_pbo.c├── st_pbo_compute.c├── st_pbo.h├── st_program.c├── st_program.h├── st_sampler_view.c├── st_sampler_view.h├── st_scissor.c├── st_scissor.h├── st_shader_cache.c├── st_shader_cache.h├── st_texture.c├── st_texture.h├── st_util.h├── st_vdpau.c├── st_vdpau.h└── tests1 directory, 90 files
  • Pipe Driver: 把Gallium的state、shader和primitive概念转换成硬件能懂的语言

    tree  src/gallium/drivers/  -L 1src/gallium/drivers/├── asahi├── crocus├── d3d12├── etnaviv├── freedreno├── i915├── iris├── lima├── llvmpipe├── xxx_gpu├── nouveau├── panfrost├── r300├── r600├── radeonsi├── softpipe├── svga├── tegra├── v3d├── vc4├── virgl└── zink22 directories, 0 files
  • Winsys: 实例化state tracker和pipe driver,并和具体的操作系统及2D显示驱动绑定

    tree src/gallium/winsys/ -L 1src/gallium/winsys/├── amdgpu├── asahi├── crocus├── d3d12├── etnaviv├── freedreno├── i915├── iris├── kmsro├── lima├── xxx_gpu├── nouveau├── panfrost├── radeon├── svga├── sw├── tegra├── v3d├── vc4└── virgl20 directories, 0 files

    最后我们看下,构建完成生成gallium目录代码:

    tree build-android-aarch64/src/gallium/  -L 2build-android-aarch64/src/gallium/├── auxiliary│   ├── libgallium.a│   ├── libgallium.a.p│   ├── libgalliumvl.a│   ├── libgalliumvl.a.p│   ├── libgalliumvl_stub.a.p│   ├── libgalliumvlwinsys.a.p│   ├── pipe-loader│   ├── tr_util.c│   ├── tr_util.h│   ├── u_indices_gen.c│   ├── u_tracepoints.c│   ├── u_tracepoints.h│   └── u_unfilled_gen.c├── drivers│   └── xxx_gpu├── frontends│   └── dri├── targets│   └── dri└── winsys    ├── xxx_gpu    └── sw15 directories, 8 files

    其中只有Pipe Driver和具体的硬件有关系。

    对于GPU硬件厂家来说,主要实现Pipe driver和winsys层。

    从数据流看,如下:

    state tracker -> Pipe Driver -> Winsyst -> 具体的OS -> OS内核态GPU驱动 -> 具体的GPU硬件

    另外Gallium中还有两个比较重要的概念:

    • CSO context:GPU中有些状态是不变的常量,Gallium提供了CSO机制帮助创建、销毁、管理这些对象
    • Draw: 有些硬件不支持坐标变换,光照、裁剪,Gallium也提供了软件机制帮忙实现

      加上这两个概念之后,数据流如下:

      state tracker -> CSO context -> Draw -> Pipe Driver -> Winsys -> 具体的OS -> OS内核态GPU驱动 -> 具体的GPU硬件

      state tracker和pipe driver通信是通过pipe context 和pipe screen这两个软件概念

      state tracker也可以直接通过p_winsys和Winsys通信,一般GPU厂商也要实现一个自己的winsys,可以参考纯软的 kms_dri_sw_winsys.c

      1. Mesa Gallium 驱动框架

      2. GPU Mesa Gallium架构

      这个系列博客,确实写得蛮好的。属于可以深入研读系列的!

上一篇:方舟服务器怎么挤进去的?

下一篇:建筑/室内设计二级建造师可以挂在哪里?