Mesa Gallium框架入门初探

Mesa Gallium框架入门初探



MESA Gallium框架

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

在这里插入图片描述

经典架构

在这里插入图片描述

Gallium架构

image




Gallium展开

Gallium中主要包含下面几块:

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

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

    tree src/mesa/state_tracker/  -L 1
    src/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
    └── tests
    
    1 directory, 90 files
    
  • Pipe Driver: 把Gallium的state、shader和primitive概念转换成硬件能懂的语言

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

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

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

tree build-android-aarch64/src/gallium/  -L 2
build-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
    └── sw

15 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架构

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

  • 26
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值