28
Gallium3D - Mesa’s New Driver Model Chia-I Wu [email protected] Mar 27, 2011 Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 1 / 24

Gallium3D - Mesa's New Driver Model

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Gallium3D - Mesa's New Driver Model

Gallium3D - Mesa’s New Driver Model

Chia-I Wu

[email protected]

Mar 27, 2011

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 1 / 24

Page 2: Gallium3D - Mesa's New Driver Model

Agenda

Who Am I?

main developer of Mesa EGL stack

Android(-x86) port of Mesa

experiences in OpenGL stacks

a member of 0xlab

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 2 / 24

Page 3: Gallium3D - Mesa's New Driver Model

Agenda

Who Am I?

main developer of Mesa EGL stack

Android(-x86) port of Mesa

experiences in OpenGL stacks

a member of 0xlab

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 2 / 24

Page 4: Gallium3D - Mesa's New Driver Model

Agenda

Agenda

OpenGL and Linux: DRI

classic and Gallium3D driver models

how does it make a developer happy

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 3 / 24

Page 5: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

Mesa v.s. Proprietary Drivers

Isn’t this the case?

Mesa Proprietarystability . v

performance . vfeature set . v

it’s free v .

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 4 / 24

Page 6: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

Not Always

Figure: nouveau v.s. nVidia binary driver (phronix)

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 5 / 24

Page 7: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

People

BIG TEAMS / BIG BUDGET

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 6 / 24

Page 8: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

DRI

Direct Rendering Infrastructure, DRI

direct rendering

core X rendering

indirect rendering

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 7 / 24

Page 9: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

DRI

Direct Rendering Infrastructure, DRI

direct rendering

core X rendering

indirect rendering

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 7 / 24

Page 10: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

DRI Components

<hw> dri.so is the DRI or 3D driver

<hw> drv.so is the DDX or 2D driver

<hw>.ko is the DRM kernel module

libdrm <hw>.so is the user space library for the DRM module

GLX and DRI2 are X11 protocols

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 8 / 24

Page 11: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

DRI Components

<hw> dri.so is the DRI or 3D driver

<hw> drv.so is the DDX or 2D driver

<hw>.ko is the DRM kernel module

libdrm <hw>.so is the user space library for the DRM module

GLX and DRI2 are X11 protocols

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 8 / 24

Page 12: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

They are all complex

DRM driver for buffer management, mode setting, ... (radeon has ∼70k LoC)

DDX driver for 2D operations, video, mode setting, ... (radeon has ∼100k LoC)

DRI driver for OpenGL (radeon has ∼90k LoC)

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 9 / 24

Page 13: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

OpenGL under Mesa Classic Driver Model

<hw>_dri.so

DRI driver interface Mesa common code HW code

libGL.so libdrm_<hw>.so

In the classic model,

there is common code that checks the arguments of an OpenGL call and updatesinternal states

it then calls into the HW code using the function table implemented there

There is an almost one-to-one mapping between OpenGL API and the function table thatthe HW code implements.

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 10 / 24

Page 14: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

Dissection of the DRI driver

<hw>_dri.so

DRI driver interface Mesa common code HW code

libGL.so libdrm_<hw>.so

OS dependent: the HW code

display server dependent: none

OpenGL dependent: the common and HW code

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 11 / 24

Page 15: Gallium3D - Mesa's New Driver Model

OpenGL and Linux

Problems with the Classic Model

The problems with the classic model are

it is OpenGL(ES) only; even the hardware can support OpenVG, OpenCL, ...

the driver uses OpenGL data types and objects

the driver must handle the differences between OpenGL and the hardware

an implementation issue instead of a design issue in view of the DRI architecture

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 12 / 24

Page 16: Gallium3D - Mesa's New Driver Model

Gallium3D

Ideal Model

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 13 / 24

Page 17: Gallium3D - Mesa's New Driver Model

Gallium3D

Gallium3D

<hw>_dri.so

DRI state tracker

pipe driver pipe winsys

libGL.so libdrm_<hw>.so

OpenGL state tracker

OS dependent: the pipe winsys

display server dependent: none

OpenGL dependent: OpenGL state tracker

The pipe driver is highly protable and has a well-defined interface!

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 14 / 24

Page 18: Gallium3D - Mesa's New Driver Model

Gallium3D

Gallium3D

<hw>_dri.so

DRI state tracker

pipe driver pipe winsys

libGL.so libdrm_<hw>.so

OpenGL state tracker

OS dependent: the pipe winsys

display server dependent: none

OpenGL dependent: OpenGL state tracker

The pipe driver is highly protable and has a well-defined interface!

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 14 / 24

Page 19: Gallium3D - Mesa's New Driver Model

Gallium3D

Classic Model to Gallium3D Model

<hw>_dri.so

DRIOdriverOinterface MesaOcommonOcode HWOcode

libGL.so libdrm_<hw>.so

DRIOstateOtracker

OpenGLOstateOtracker

pipeOdriver pipeOwinsys

This is a non-trivial process

DRI and OpenGL state trackers are written once and shared

the pipe driver and winsys must be written for each HW

new drivers should adopt the Gallium3D model from beginning

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 15 / 24

Page 20: Gallium3D - Mesa's New Driver Model

Gallium3D

Gallium3D: examples

<hw>_dri.so

DRIVstateVtracker

pipeVdriver pipeVwinsys

libEGL.so libdrm_<hw>.so

OpenVGVstateVtracker

<hw>_dri.so

DRIVstateVtracker

pipeVdriver pipeVwinsys

libOpenCL.so libdrm_<hw>.so

OpenCLVstateVtracker

egl_dri2.so

(You can also have all OpenGL, OpenVG, and OpenCL state trackers inside a single DRIdriver)

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 16 / 24

Page 21: Gallium3D - Mesa's New Driver Model

Gallium3D

Gallium3D: even for DDX

<hw>_drv.so (DDX)

DDX state tracker pipe driver pipe winsys

Xorg libdrm_<hw>.so

A modern DDX driver is more than a 2D driver

EXA/UXA

Xrender

video decoding

mode setting KMS

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 17 / 24

Page 22: Gallium3D - Mesa's New Driver Model

Gallium3D

Gallium3D: SVGA

VMWare has a virtual GPU named SVGA. The aquisition of Tungsten Graphics gives

vmwgfx.ko DRM module

Gallium3D based DRI driver

Gallium3D based DDX driver

Gallium3D based D3D9 driver (D3D9 state tracker + Windows winsys)

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 18 / 24

Page 23: Gallium3D - Mesa's New Driver Model

Developers

Gallium3D core

Gallium3D core consists of

two interfaces: struct pipe screen and struct pipe context

helper functions for format conversions, buffer management, vertex processing, andetc.

wrappers of OS or compiler dependent functions, such as threads, timing, I/O

Pipe drivers implement struct pipe screen and struct pipe context interfaces.State trackers are users of the interfaces.

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 19 / 24

Page 24: Gallium3D - Mesa's New Driver Model

Developers

struct pipe screen

The pipe screen is an abstraction of the adapter. It is used for

querying adapter capabilities/limitations

creating resources

fencing

and other misc operations

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 20 / 24

Page 25: Gallium3D - Mesa's New Driver Model

Developers

struct pipe context

The pipe context is an abstraction of the graphics pipeline (and some misc operations)

vertex fetcher

vertex shader

geometry shader stream output buffers

rasterizer

fragment shader

textures andconstant buffers

per-fragment ops color and depth buffers

vertex buffers

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 21 / 24

Page 26: Gallium3D - Mesa's New Driver Model

Developers

Pseudo Code

/∗ c r e a t e t h e p i p e s c r e e n ∗/s t r u c t p i p e s c r e e n ∗ s c r e e n = o p e n h w d e v i c e ( dev name ) ;

/∗ c r e a t e a p i p e c o n t e x t ∗/s t r u c t p i p e s c r e e n ∗ p i p e = s c r e e n−>c o n t e x t c r e a t e ( / ∗ . . . ∗ / ) ;s t r u c t p i p e r e s o u r c e ∗ r e s ;

/∗ c r e a t e a r e s o u r c e from t h e s c r e e n ∗/r e s = s c r e e n−>r e s o u r c e c r e a t e ( / ∗ . . . ∗ / ) ;

/∗ s e t th e r e s o u r c e as t h e f r a m e b u f f e r ∗/p ipe−>s e t f r a m e b u f f e r s t a t e ( / ∗ . . . ∗ / ) ;

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 22 / 24

Page 27: Gallium3D - Mesa's New Driver Model

Developers

It is easier

Gallium3D driver model

has well-defined interfaces and types

is close to the hardware

has reusable state trackers

has lots of helper functions

supports pipe screen/context wrapping: trace, rbug, galahad

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 23 / 24

Page 28: Gallium3D - Mesa's New Driver Model

Q & A

Q & A

Questions?

Chia-I Wu ([email protected]) Gallium3D - Mesa’s New Driver Model Mar 27, 2011 24 / 24