Project

General

Profile

FundingGraphicsAcceleration » History » Version 1

Denis 'GNUtoo' Carikli, 11/30/2022 03:25 PM
Move from TasksFunding

1 1 Denis 'GNUtoo' Carikli
h2. Graphics acceleration
2
3
Currently, all supported devices on Replicant lack a free software driver for their GPU. This means that OpenGL ES (GLES) rendering must be done on the CPU (software rendering). The current approach to software rendering on Replicant 6 is based on "libAGL":https://android.googlesource.com/platform/frameworks/native/+/master/opengl, an optimized GLES 1.x implementation that uses "libpixelflinger":https://android.googlesource.com/platform/system/core/+log/master/libpixelflinger software renderer. Development on both these libraries ceased in 2013 and no work was done to support newer GLES versions.
4
The major consequences of this are that:
5
* Critical applications like web browsers crash due to lack of GLES 2.0 (#705). Replicant currently uses an out-dated browser that has many security flaws.
6
* Replicant relies on patches to the Android framework to make things like the camera application work.
7
* The rendering speed has degraded over the newer Android versions, like Android 6. Even applications that do not crash become difficult to use due to the huge rendering delays.
8
9
This task aims to fix all these severe issues by putting together a new graphics stack for the Android 9 port. This new graphics stack must be compatible with Android 9 Hardware Abstraction Layers (HAL) and provide at least GLES 2.0 rendering. It should be flexible enough to do software rendering with "Mesa":https://www.mesa3d.org/intro.html or "SwiftShader":https://swiftshader.googlesource.com/SwiftShader (Google's current software renderer), and also GPU rendering on devices where a free GPU driver is available.
10
11
"Joonas Kylmälä":https://redmine.replicant.us/users/8585 has done some introductory work on the Android 9 port for the i9305, and found a way to have it rendering to the screen. He put together a graphics stack composed of: gbm_gralloc ("Gralloc HAL":https://source.android.com/devices/graphics/implement#gralloc_hal) + drm_hwcomposer ("Hardware Composer HAL":https://source.android.com/devices/graphics/implement#hardware_composer_hal) + Mesa with kms_swrast driver with softpipe backend (CPU software renderer for GLES). This will be the starting point for this task.
12
13
Joonas' prototype shows that Replicant can use "gbm_gralloc":https://osdn.net/projects/android-x86/scm/git/external-gbm_gralloc/summary, an existing graphics memory allocator (gralloc) HAL maintained(ish) by Android-x86, in conjunction with "drm-hwcomposer":https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer, a libre implementation of Android's Hardware Composer HAL based on Linux's DRM, to achieve software rendering with Mesa. This solution avoids the need to write a custom gralloc for Replicant, and takes advantage of the hardware acceleration for composition provided by drm-hwcomposer on devices with a free software DRM driver (e.g. exynos-based smartphones and tablets).
14
15
Much more testing is needed to confirm that gbm_gralloc can be the definitive gralloc HAL on Replicant 9. It still wasn't tried with SwiftShader, or even Mesa's llvmpipe backend, which is a must since the softpipe backend is too slow to be usable.
16
Joonas' tests showed that some other components will need our attention, mostly the drm/exynos driver. In order to make drm/exynos work with gbm_gralloc and drm-hwcomposer Joonas had to disable "DRM-Auth":https://en.wikipedia.org/wiki/Direct_Rendering_Manager#DRM-Master_and_DRM-Auth and hack some missing pixel formats into it by using the default pixel format for everything. Besides drm/exynos, we will also have to make the graphics stack work with the "virtual GEM (vGEM) driver":https://www.phoronix.com/scan.php?page=news_item&px=DRM-vGEM-Mesa-Software, in order to support devices that lack a real drm driver.
17
18
The major and first goal of this task is thus to build upon Joonas's prototype and put together a stable and fully free graphics stack, compatible with GLES 2.0, that does software rendering through Mesa's llvmpipe with a decent performance.
19
20
*Hardware requirements*: A computer that is able to build Replicant. A Samsung Galaxy S3 or S3 4G to run the [[Porting_Replicant_to_Android_9|current Replicant 9 port]].
21
22
*Difficulty*: Medium / Hard
23
24
*Requirements/Prerequisites*: Knowledge of C++, kernel interfaces knowledge or the ability to learn them
25
26
*Expected outcomes*:
27
* Graphics stack with decent performance on software rendering
28
* Working GLES 2.0 implementation
29
* Fast enough graphics
30
* F-Droid applications not crashing anymore because of GLES.
31
32
*Time +estimation+*:
33
34
|_. Step |_. man-hours |
35
| Set up the development environment, including the current Replicant 9 port on the test device. |>. 24 |
36
| Read AOSP documentation and understand all details of the graphics stack. |>. 16 |
37
| Adapt the build files to use Mesa's llvmpipe backend instead of softpipe. Fix potential LLVM version incompatibilities between Mesa and Android. |>. 40 |
38
| Properly implement the missing pixel formats in drm/exynos and try to have it merged into upstream. |>. 72 |
39
| Find a proper way to use DRM-Master and DRM-Auth with gbm_gralloc and drm-hwcomposer. |>. 40 |
40
| Create test scenarios and check if the graphics stack works as expected. Consider "alternative grallocs":https://redmine.replicant.us/projects/replicant/wiki/GraphicsResearch#Gralloc if necessary. |>. 40 |
41
| Make the graphics stack work with vGEM driver besides drm/exynos. |>. 40 |
42
| Document the design decisions. |>. 16 |
43
|_. TOTAL |_>. 288 |
44
45
h3. Subtasks
46
47
The following sub-tasks could also be worked on after finishing writing the gralloc:
48
* [[Tasks_funding#SwiftShader|SwiftShader]]
49
* [[Tasks_funding#llvmpipe optimizations|llvmpipe optimizations]]
50
* [[Tasks_funding#Lima driver|Lima driver]]
51
52
h3. SwiftShader
53
54
"SwiftShader":https://swiftshader.googlesource.com/SwiftShader is Google's current software renderer that is capable of GLES 2.0 and is now "under work to support Vulkan":https://swiftshader.googlesource.com/SwiftShader/+log/master.
55
56
Mesa is the preferred renderer on Replicant for several reasons such as its support for both software and hardware (GPU) rendering, and its big community, with hundreds of active contributors. However, Mesa lacks a Vulkan software renderer. With Vulkan soon becoming a "requirement for new Android versions":https://android-developers.googleblog.com/2019/03/introducing-android-q-beta.html, we must make sure that Replicant's graphics stack can use SwiftShader in order to become futureproof. Furthermore, SwiftShader was built with performance in mind, specially for ARM CPUs, and may bring speed improvements on some devices.
57
58
The goal of this sub-task is thus to create a compile-time or run-time option that allows using Replicant 9 with SwiftShader as it's software renderer instead of Mesa.
59
60
*Hardware requirements*: A computer that is able to build Replicant. A smartphone or tablet that is supported by Replicant to be able to test the result.
61
62
*Difficulty*: Medium
63
64
*Requirements/Prerequisites*: Knowledge of C++, Makefiles and git. Android's graphics stack knowledge or the ability to learn them.
65
66
*Expected outcomes*:
67
* SwiftShader running on Replicant.
68
* Working Vulkan implementation.
69
70
*Time +estimation+*: 40 man-hours.
71
72
h3. llvmpipe optimizations
73
74
Mesa is a highly versatile library that can be extended with device drivers to allow it to be used in different environments ranging from software emulation to complete hardware acceleration. One such driver is the "Gallium llvmpipe driver":https://www.mesa3d.org/llvmpipe.html, which is a software rasterizer that uses LLVM to do runtime code generation. It only needs a CPU to run graphics computations and thus brings full GLES support to all Replicant devices.
75
76
"llvmpipe has been integrated in Replicant 6":https://git.replicant.us/replicant/external_mesa3d/log/ but it's not activated by default yet as it is very slow. It is also not fully complete.
77
78
To fix that, llvmpipe and/or the integration of it in Replicant should be optimized. We should first start by configuring llvmpipe and/or Mesa "to not implement very expensive OpenGL operations":https://www.mesa3d.org/perf.html. If that's not sufficient, or if that breaks application compatibility, various software or hardware features ("ARM NEON":https://www.arm.com/products/processors/technologies/neon.php, hardware 2D acceleration, etc) could be used to improve the speed.
79
80
Considerable speed improvements may be achieved with a fine-tuned emulation for division instructions. The ARM cores on many Replicant devices do not have hardware "support for the SDIV/UDIV instructions":https://community.arm.com/processors/b/blog/posts/divide-and-conquer. We should profile some apps and check whether GLES functions requiring divisions are to blame for the poor performance.
81
82
*Hardware requirements* : A computer that is able to build Replicant. A smartphone or tablet that is supported by Replicant to be able to test the result.
83
84
*Difficulty*: Medium / Hard (depending on the amount of optimizations required)
85
86
*Requirements/Prerequisites*: See with Mesa project
87
88
*Expected outcomes*: faster llvmpipe on ARM devices, able to run apps such as Fennec F-Droid (Firefox).
89
90
*Time +estimation+*:
91
92
|_. Step |_. man-hours |
93
| Setup a "testing and benchmarking environment":https://source.android.com/devices/graphics/testing |>. 40 |
94
| Disable expensive OpenGL operations. Check speedup and stability. |>. 24 |
95
| Recap matrix operations (Linear Algebra) and study ARM NEON. |>. 48 |
96
| Do a profiling of several apps to find the most used GLES operations. |>. 32 |
97
| Use "Ne10 library":https://github.com/projectNe10/Ne10 or "Neon Intrinsics":https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics for the most used GLES operations. |>. 80 |
98
| Fix bugs, re-write the code where needed, get it stable. |>. 80 |
99
|_. TOTAL |_>. 304 |
100
101
h3. Lima driver
102
103
"Lima":https://gitlab.freedesktop.org/lima is a free software Mesa driver for ARM Mali-4xx (Utgard) GPUs. These GPUs are present in several Replicant supported devices such as Galaxy S2, S3, S3 4G, Note and Note 2. 
104
105
Lima aims to full GLES support but it is still in development. However the "current implementation status":https://gitlab.freedesktop.org/lima/mesa/issues/39#note_79193 already allows the hardware acceleration of several tasks. GPU-based hardware acceleration is faster and less power hungry than software rendering, both by several orders of magnitude. It would allow Replicant devices to run applications with a performance close to that of non-free devices.
106
107
*Hardware requirements* : A computer that is able to build Replicant. A Replicant device with a Mali-4xx GPU that can run mainline Linux (e.g. Galaxy S3 or Note 2).
108
109
*Difficulty*: Medium
110
111
*Requirements/Prerequisites*: "See with Lima project":https://gitlab.freedesktop.org/lima/web/wikis/home#build-and-install
112
113
*Expected outcomes*: Lima driver being used for GLES rendering on a supported device.
114
115
|_. Step |_. man-hours |
116
| Rebase "Lima's Linux kernel DRM driver":https://gitlab.freedesktop.org/lima/linux on top of "forkbomb's Midas on Mainline kernel":https://blog.forkwhiletrue.me/pages/midas-mainline/. |>. 80 |
117
| Replace mainline Mesa for "Lima's Mesa":https://gitlab.freedesktop.org/lima/mesa (with their driver).  |>. 16 |
118
| Build and test thoroughly with "synthetic":https://source.android.com/devices/graphics/testing and real applications. |>. 40 |
119
| Create a fallback mechanism that uses the software renderer for GLES functions not yet implemented in Lima. |>. 100 |
120
|_. TOTAL |_>. 236 |
121
122
h3. Software Bill of Materials
123
124
* "Replicant 9":https://redmine.replicant.us/projects/replicant/wiki/Porting_Replicant_to_Android_9
125
* "Mesa":https://www.mesa3d.org/intro.html (in particular: "Gallium llvmpipe driver":https://www.mesa3d.org/llvmpipe.html)
126
* "gbm_gralloc":https://osdn.net/projects/android-x86/scm/git/external-gbm_gralloc/summary
127
* "drm-hwcomposer":https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer
128
* "Linux kernel":https://www.kernel.org/ (in particular: drm/exynos driver and "vGEM driver":https://www.phoronix.com/scan.php?page=news_item&px=DRM-vGEM-Mesa-Software)
129
* "SwiftShader":https://swiftshader.googlesource.com/SwiftShader
130
* "Ne10 library":https://github.com/projectNe10/Ne10
131
* "Neon Intrinsics":https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics
132
* "Lima":https://gitlab.freedesktop.org/lima
133
134
h3. "Graphics acceleration on Replicant" nlnet Grant application
135
136
|_. Project name | Graphics acceleration on Replicant |
137
|_. Website / wiki | https://redmine.replicant.us/projects/replicant/wiki/Tasks_funding#Graphics-acceleration |
138
139
Abstract: Can you explain the whole project and its expected outcome(s) in 1200 characters
140
<pre>
141
Replicant is a fully free software Android distribution which is approved by the
142
FSF. All supported devices on Replicant currently lack a free software driver
143
for their GPU. As such, OpenGL ES (GLES) rendering must be done on the CPU
144
through software rendering (SR).
145
146
Replicant's current renderer is both incomplete and slow. It causes essential
147
apps like web browsers to crash due to lack of GLES 2.0, and many other
148
apps run too slow to be usable.
149
150
This project aims to fix this by complementing Android's 9 graphics stack.
151
Adding a few missing components will created of a fully-free, fast and compliant
152
graphics stack.
153
154
First we will write a gralloc (graphics memory allocator) tailored for SR that
155
is compatible with drm-hwcomposer (a libre implementation of Android's Hardware
156
Composer HAL). This gralloc enables drm-hwcomposer to work with SurfaceFlinger
157
and SwiftShader, creating a stack capable of GLES 2.0 on the CPU of all Replicant
158
devices.
159
160
Afterwards we will integrate and optimize Mesa's llvmpipe SR, which offers better
161
community support than SwiftShader. As last step we will add support for the
162
Lima driver, which will bring an even faster GPU-backed GLES to at least 5
163
devices.
164
</pre> 
165
166
|_. Have you been involved with projects or organizations relevant to this project before?
167
And if so, can you tell us a bit about your contributions? | SEE TEMPLATE |
168
169
|_. Requested Amount (Between 5000 and 50000 Euros) | 50000 Euros |
170
|_. Does the project have other funding sources, both past and present? | SEE TEMPLATE |
171
172
Explain what the requested budget will be used for? 
173
<pre>
174
The budget will only be used to fund this project through contract work.
175
176
We estimate that this project should take 868 man-hours to reach full completion,
177
with 632 man-hours being enough to reach all software rendering goals, leaving only
178
the GPU rendering to be done. A detailed run-down of this estimate is available at
179
https://redmine.replicant.us/projects/replicant/wiki/Tasks_funding#Graphics-acceleration
180
181
So far we have a team of two people interested on working on this project (the
182
two authors and submitters of this application). Both can commit to the project
183
on a part-time regime (17.5 hours per week), which means that the project should
184
be fully completed in about 6 months.
185
186
We will make sure that everybody has a chance to apply for doing contract work.
187
If we take the cost of a freelance developer in the USA (75 to 150 USD
188
per hour) as a basis, to enable people living in Europe and the USA
189
to apply, we can fund between 380 and 760 man-hours with the 50000 EUR budget.
190
This should be enough to cover all work on software rendering plus the initial
191
work on GPU rendering.
192
193
As happens on all software projects, getting a precise time/effort evaluation is
194
a difficult endeavour, specially when dealing with a project that is heavy on
195
research such as this one.
196
197
If the software rendering goals are not reached when the 50000 EUR budget runs
198
out, or if the Replicant project deems it necessary to have GPU rendering, it
199
will use its existing funds to pay for contract work if no volunteers are found
200
to finish the project.
201
202
The Replicant project will also make sure that the people working on this project
203
have the necessary hardware to do it, for instance by shipping or reimbursing the
204
purchase of a compatible smartphone with the Replicant project funds.
205
</pre>
206
207
Compare your own project with existing or historical efforts.
208
<pre>
209
Past Replicant versions have relied on patches to the Android framework to make
210
software rendering work. These patches were quite specific for Replicant and
211
had no use elsewhere. This made them unfit for upstreaming or sharing with any
212
other project.
213
214
Android's Project Treble new graphics stack allows us to follow a different
215
approach this time. Instead of patching the Android framework, we will
216
implement one of the well defined Android HALs (Hardware Abstraction Layer):
217
the gralloc HAL. The end result will be a software library that can prove to be
218
useful on several projects besides Replicant (e.g. Android-x86 project) and
219
thus fit for upstreaming.
220
221
222
Furthermore, past Replicant versions relied on Google's software renderers
223
(ligAGL and libpixelflinger) for OpenGL ES support. As quite a few other
224
Google's open-source projects, these two had no community behind them and got
225
stalled as soon as Google deprecated them.
226
227
This time will we take a different approach. Although our first graphics stack
228
will rely on Google's SwiftShader renderer, we will then move our efforts into
229
Mesa. Mesa is a big community project, with hundreds of active contributors and
230
great community support. It includes the llvmpipe software renderer along with
231
new drivers in development for GPUs present on current and future Replicant
232
devices. Mesa should provide a stable and maintained platform for years to come.
233
</pre>
234
235
What are significant technical challenges you expect to solve during the project, if any?
236
<pre>
237
We expect to solve significant technical challenges during this project:
238
1. Implementation of the first Android gralloc library compatible with software
239
rendering.
240
2. Development of free-software benchmarks for OpenGL ES on Android, used to test
241
our optimizations to llvmpipe.
242
3. Optimization of llvmpipe by at least one order of magnitude.
243
4. Running an exynos based smartphone with fully free-software GPU graphics
244
acceleration.
245
</pre>
246
247
Describe the ecosystem of the project, and how you will engage with relevant actors and promote the outcomes?
248
<pre>
249
This project will re-use code from several projects such as Android,
250
drm-hwcomposer, Mesa and Lima driver. Whenever possible we will foster
251
collaboration with these projects and submit our changes upstream.
252
253
The Replicant project contributors and the FSF will supervise
254
contractors to do the work.
255
256
A blog post will announce that the Replicant project
257
has got some funding for this specific task, and that it is
258
looking for a contractor to work on it. This is to make sure
259
that everyone has equal chances in the application process.
260
261
Then the most suited contractor will be selected. Only contractors
262
that already have worked on similar tasks as part of free and open
263
source software projects will be chosen. This way we can look at
264
their existing contributions and make sure that they are able to
265
do the task before engaging with them.
266
267
The Replicant project will also make sure that the contractor has
268
or gets the hardware required to work on the task, before starting
269
to work on it.
270
</pre>
271
272
|_. Attachments | SEE TEMPLATE |