Gallium

Gallium3D是一个图形接口层,解耦合上层操作与驱动。主要接口包括pipe_context和pipe_screen,用于设置渲染状态、创建纹理等。State tracker负责将Mesa状态和绘制命令转化为pipe对象。Ancillary Modules如Draw、TGSI提供额外服务。资源、转移、资源目标、PIPE_BUFFER、表面和采样视图是关键概念,详细解释了它们在图形处理中的作用。

http://www.freedesktop.org/wiki/Software/gallium/

Gallium3D其实是一个接口层,解耦上层操作与驱动之间的联系:

主要接口

  • pipe_context 结构体(p_context.h), 其中定义了和context相关的函数集,这些函数主要包括如下功能:

    • Setting rendering state (texture sampler state, blending state, rasterization state, vertex array info, drawing surfaces, etc.)
    • Setting shader state, using the TGSI binary shader representation.
    • Vertex array and indexed vertex array drawing.
  • pipe_screen结构体,包含与context无关的信息和函数集

    • Creating textures (and drawing surfaces)
    • Getting “views” into textures
    • Hardware queries (number of texture units, max texture size, etc).
    • Creating generic memory buffers
    • Mapping/unmapping buffers
    • Fencing
  • 另外还有一些数据结构定义在p_state.h中

    • Graphics state (blending, texture sampling, rasterization)
    • Texture and surface resources
    • Vertex array layout

State tracker

It’s responsible for translating Mesa state (blend modes, texture state, etc) and drawing commands (like glDrawArrays and glDrawPixels) into pipe objects and operations.

Traditional fixed-function OpenGL components (such as lighting and texture combining) are implemented with shaders. OpenGL commands such as glDrawPixels are translated into textured quadrilateral rendering. Basically, any rendering operation that isn’t directly supported by modern graphics hardware is translated into a hardware-friendly form.

Ancillary Modules

A number of ancillary modules are available to Gallium3D drivers:

  1. The Draw module provides point/line/polygon rendering services such as vertex transformation, polygon culling and clipping. It will be used by drivers for hardware which lacks vertex transformation (such as the i915/i945). It may also be instantiated and used directly by the state tracker to implement some API functionality that doesn’t map well to hardware capabilities.

  2. The TGSI module provides a universal representation of shaders and CPU-based execution of shaders. All Mesa vertex/fragment programs and shaders are translated into the TGSI representation before being passed to the driver. In turn, the driver will convert the TGSI instructions into GPU-specific instructions. For hardware that lacks vertex or fragment shader support, the TGSI’s executor can be used. The TGSI executor includes support for SSE code generation. Support for other processors (such as Cell) will be added in the future.

  3. The RTASM module provides support for Run-Time Assembly/Machine code generation. There are sub-modules for X86/SSE, PPC and Cell machine code generation.

  4. The CSO module provides support for Constant State Objects. CSOs help to filter out redundant state changes from getting sent to the driver. State changes can be expensive and we want to avoid them whenever possible.

  5. The util module has code for debugging, image manipulation, hashing, math and miscellaneous helper routines.

TGSI, Tungsten Graphics Shader Infrastructure, is an intermediate language for describing shaders. Since Gallium is inherently shaderful, shaders are an important part of the API. TGSI is the only intermediate representation used by all drivers.

术语解释

Resources

Resources represent objects that hold data: textures and buffers.

They are mostly modelled after the resources in Direct3D 10/11, but with a different transfer/update mechanism, and more features for OpenGL support.

Resources can be used in several ways, and it is required to specify all planned uses through an appropriate set of bind flags.

Transfers

Transfers are the mechanism used to access resources with the CPU.

  • OpenGL: OpenGL supports mapping buffers and has inline transfer functions for both buffers and textures
  • D3D11: D3D11 lacks transfers, but has special resource types that are mappable to the CPU address space

Resource targets

Resource targets determine the type of a resource.

Note that drivers may not actually have the restrictions listed regarding coordinate normalization and wrap modes, and in fact efficient OpenCL support will probably require drivers that don’t have any of them, which will probably be advertised with an appropriate cap.

PIPE_BUFFER

Buffer resource: can be used as a vertex, index, constant buffer (appropriate bind flags must be requested).

Buffers do not really have a format, it’s just bytes, but they are required to have their type set to a R8 format (without a specific “just byte” format, R8_UINT would probably make the most sense, but for historic reasons R8_UNORM is ok too). (This is just to make some shared buffer/texture code easier so format size can be queried.) width0 serves as size, most other resource properties don’t apply but must be set appropriately (depth0/height0/array_size must be 1, last_level 0).

They can be bound to stream output if supported.
TODO: what about the restrictions lifted by the several later GL transform feedback extensions? How does one advertise that in Gallium?

They can be also be bound to a shader stage (for sampling) as usual by creating an appropriate sampler view, if the driver supports PIPE_CAP_TEXTURE_BUFFER_OBJECTS. This supports larger width than a 1d texture would
(TODO limit currently unspecified, minimum must be at least 65536). Only the “direct fetch” sample opcodes are supported (TGSI_OPCODE_TXF, TGSI_OPCODE_SAMPLE_I) so the sampler state (coord wrapping etc.) is mostly ignored (with SAMPLE_I there’s no sampler state at all).

They can be also be bound to the framebuffer (only as color render target, not depth buffer, also there cannot be a depth buffer bound at the same time) as usual by creating an appropriate view (this is not usable in OpenGL). TODO there’s no CAP bit currently for this, there’s also unspecified size etc. limits TODO: is there any chance of supporting GL pixel buffer object acceleration with this?

  • OpenGL: vertex buffers in GL 1.5 or GL_ARB_vertex_buffer_object

    • Binding to stream out requires GL 3.0 or GL_NV_transform_feedback
    • Binding as constant buffers requires GL 3.1 or GL_ARB_uniform_buffer_object
    • Binding to a sampling stage requires GL 3.1 or GL_ARB_texture_buffer_object
  • D3D11: buffer resources - Binding to a render target requires D3D_FEATURE_LEVEL_10_0

Surfaces

Surfaces are views of a resource that can be bound as a framebuffer to serve as the render target or depth buffer.
TODO: write much more on surfaces

  • OpenGL: FBOs are collections of surfaces in GL 3.0 or GL_ARB_framebuffer_object
  • D3D11: render target views and depth/stencil views

Sampler views

Sampler views are views of a resource that can be bound to a pipeline stage to be sampled from shaders.
TODO: write much more on sampler views

  • OpenGL: texture objects are actually sampler view and resource in a single unit
  • D3D11: shader resource views
### GALLIUM_DRIVER 的定义及其与 Mesa 和 DRI 驱动的关系 #### 1. GALLIUM_DRIVER 的作用 `GALLIUM_DRIVER` 是一个环境变量,用于指定 Mesa 图形栈中要使用的 Gallium3D 子系统驱动。Mesa 支持多种图形渲染路径,其中包括传统的 DRI 驱动和现代的 Gallium3D 框架。通过设置 `GALLIUM_DRIVER`,可以强制 Mesa 使用特定的 Gallium3D 驱动而不是默认的选择[^1]。 例如,在某些情况下可能希望切换到纯软件渲染模式以进行调试或性能分析。此时可将 `GALLIUM_DRIVER` 设为 `softpipe` 或其他可用选项之一。 #### 2. Gallium3D 框架简介 Gallium3D 是一种抽象层设计,旨在简化新硬件支持的开发工作量,并提供更高的灵活性和支持更广泛的图形 API。它的基本架构由几个主要组成部分构成: - **State Trackers**: 这些模块实现了高层级图形 API(如 OpenGL、Vulkan),并将它们映射到底层通用接口。 - **Pipe Drivers**: 对应具体的硬件实现细节,负责生成针对某类 GPU 的优化指令序列。 - **Winsys Layers**: 处理窗口系统交互问题,比如 X11 或 Wayland 下表面管理等功能。 整个数据流动向大致遵循以下顺序:state tracker -> pipe driver -> winsys layer -> OS kernel mode component -> actual GPU hardware[^4]. #### 3. GALLIUM_DRIVER 与传统 DRI 驱动的区别 尽管两者都隶属于整体 Mesa 生态圈内,但它们之间存在显著差异: | 特性 | Traditional DRI Drives | Gallium3D Framework | |---------------------|-------------------------------|---------------------------| | 抽象程度 | 较低 | 更高 | | 新硬件适配难度 | 较大 | 减少 | | 支持API范围 | 主要是OpenGL | 包括更多新兴标准 | 因此,当提到 `GALLIUM_DRIVER` 时通常是指那些构建于 Gallium3D 基础之上的新型解决方案而非经典的单一目的型 DRI 组件[^3]. ```bash export GALLIUM_DRIVER=radeonsi ./your_graphics_application ``` 上面例子演示了怎样简单地改变所采用的核心渲染引擎仅需调整相应 shell session里的这个关键参数即可生效。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值