add link to nlnet project page for mesa driver
[libreriscv.git] / nlnet_2019_amdvlk_port.mdwn
1 # NL.net proposal 2019-10-042
2
3 * [[questions]]
4 * NLNet Project page <https://nlnet.nl/project/LibreSoC-3Ddriver/>
5
6 ## Project name
7
8 Port of AMDVLK/RADV 3D Driver to the Libre RISC-V SoC
9
10 ## Website / wiki
11
12 <https://libre-riscv.org/nlnet_2019_amdvlk_port>
13
14 Please be short and to the point in your answers; focus primarily on
15 the what and how, not so much on the why. Add longer descriptions as
16 attachments (see below). If English isn't your first language, don't
17 worry - our reviewers don't care about spelling errors, only about
18 great ideas. We apologise for the inconvenience of having to submit in
19 English. On the up side, you can be as technical as you need to be (but
20 you don't have to). Do stay concrete. Use plain text in your reply only,
21 if you need any HTML to make your point please include this as attachment.
22
23 ## Abstract: Can you explain the whole project and its expected outcome(s).
24
25 The Libre RISCV SoC is being developed to provide a privacy-respecting
26 modern processor, developed transparently and as libre to the bedrock
27 as possible. As a hybrid processor, it is intended to be both a CPU
28 *and* a GPU. GPUs are normally proprietary (and thus are perfect candidate
29 attack vectors), as is the 3D driver software.
30
31 In January 2019, AMD released a fully-functioning libre-licensed Vulkan
32 Driver for their Radeon GPUs. A close examination of its source code
33 shows that it would be relatively straightforward to replace the libraries
34 that generate Radeon GPU assembly code with ones that generate assembly
35 for the Libre RISC-V SoC, instead.
36
37 In addition, further investigation shows that RADV, the libre-licensed
38 MESA 3D Driver, also supports SPIR-V (by way of conversion to MESA NIR),
39 and, likewise, may be a good candidate for replacing Radeon with Libre
40 RISC-V assembly.
41
42 Thus we intend to do exactly that: leverage the excellent work already
43 done to create a libre-licensed commercial-grade Vulkan 3D driver that
44 takes full advantage
45 of the parallelism and Vectorisation in the hybrid Libre RISC-V SoC.
46
47 # Have you been involved with projects or organisations relevant to this project before? And if so, can you tell us a bit about your contributions?
48
49 Luke Leighton is an ethical technology specialist who has a consistent
50 24-year track record of developing code in a real-time transparent
51 (fully libre) fashion, and in managing Software Libre teams. He is the
52 lead developer on the Libre RISC-V SoC.
53
54 Jacob Lifshay is a software libre 3D expert who developed a Vulkan 3D
55 software render engine under the GSoc2017 Programme. He also developed
56 his own libre-licensed 32-bit RISC-V processor, and has written an
57 optimising javascript compiler. Jacob is a valuable member of the team and is
58 working on Kazan (https://salsa.debian.org/Kazan-team/kazan)
59
60 # Requested Amount
61
62 EUR 50,000.
63
64 # Explain what the requested budget will be used for?
65
66 After a thorough and comprehensive evaluation to see which will be the
67 best to choose (RADV or AMDVLK), we are aiming for a multi-stage process,
68 starting with the basics:
69
70 * The first stage is to remove AMD's "PAL" Library in AMDVLK, or the
71 AMDGPU engine used in RADV, and replace it with a straightforward
72 upstream port of the current LLVM JIT compiler, alongside a "support"
73 library that will call OpenCL / OpenGL functions directly on the main
74 processor. This "effectively" turns the engine into a peer of google
75 swiftshader (a "Software 3D Renderer") which will allow us to carry out
76 rapid testing on stable x86 systems before moving on to the next stage.
77 * The second stage is to confirm that the standard RISC-V LLVM JIT
78 (which was recently upstreamed as of LLVM 9.0.0) is properly functional
79 under an emulator or other RV64GC system.
80 * The third phase will be to begin the iterative process, tying in closely
81 with the work on Kazan, to experiment in both a software simulator
82 as well as in FPGAs, with the addition of both Vectorisation as well
83 as custom opcodes that will significantly improve performance as well
84 as meet commercially-acceptable power-performance demands.
85
86 At the point where commercial power-performance requirements are met we may
87 officially declare the project a "success".
88
89 # Does the project have other funding sources, both past and present?
90
91 The overall project has sponsorship from Purism as well as a prior grant
92 from NLNet. However that is for specifically covering the development
93 of the RTL (the hardware source code), and for a "parallel" 3D Vulkan
94 Driver effort, Kazan.
95
96 Kazan is to be written in Rust and its inclusion in the initial 2018
97 proposal was *before* AMDVLK was released (Jan 2019). AMDVLK is written
98 in c++, is a significant way along (further than Kazan), however there
99 is a different design focus in each that makes choosing one over the
100 other not only difficult but potentially a costly mistake.
101
102 # Compare your own project with existing or historical efforts.
103
104 Nyuzi is a Software-based 3D Engine that has an LLVM port. The problem
105 is that it has deliberately been designed to be a software-only
106 Vector Processor. As such, with no custom accelerated opcodes
107 dedicated to 3D, its power-performance metric is a whopping 25% that of
108 commercially-acceptable 3D GPUs. It also has no actual 3D Vulkan Driver:
109 the developers focussed only on the "core algorithms" as part of an
110 (extremely useful) academic exercise, only.
111
112 Google's swiftshader is a software-based 3D Driver/Engine that is compatible
113 with at least one version of Vulkan. On the face of it, this would be a
114 perfect match for the Libre RISC-V SoC due to it being a hybrid CPU / GPU.
115 The problem is that swiftshader was designed - from the ground up - never
116 to have Vectorisation or any form of accelerated hardware beyond SIMD
117 (NEON, Altivec, SSE/AVX). As Nyuzi clearly shows, this approach is
118 known to give a massive 400% power penalty. Not only that, but our
119 additions would not be welcome due to the primary focus of swiftshader
120 being on non-hardware-accelerated, non-custom processors.
121
122 RADV is the free software competitor to AMDVLK. It takes a different
123 route: converting SPIR-V to NIR (New Internal Representation) which will
124 need close evaluation to ensure that it's directly suited to Vector
125 Processing. Like AMDVLK, it does not directly support RISC-V: it was
126 purely intended to support Radeon GPUs.
127
128 Our initial proposal - Kazan - is much more interesting to discern and
129 compare against. Kazan is being specifically designed so that the
130 SPIR-V compiler is capable of fully supporting "full-function vectorisation".
131 LLVM IR does *NOT* normally support this (which is why SPIR-V was created
132 by the Khronos Group in the first place). However, AMDVLK, which is a
133 hard fork of LLVM, has had its LLVM-IR specifically modified to support
134 both full-function vectorisation, predication, and in addition, texturisation,
135 such that this information may be "carried" down to the Radeon assembly level,
136 through the PAL library.
137
138 Standard LLVM does *not* support this full-function vectorisation
139 capability: it is typically left up to any given assembly-level
140 converter (such as the RISC-V Vector Engine) to "opportunistically"
141 turn non-vectorised programs *into* vectorised ones, whereas AMDVLK
142 *explicitly* carries this very same information.
143
144 Kazan on the other hand intends to perform explicit Vectorisation
145 code-transformations in a different location: inside the SPIR-V compiler
146 itself. This key radical technical difference is why we seek to explore
147 the alternative approach taken by AMD side-by-side with that of Kazan,
148 because it is just not possible to predict in advance which would be "better".
149
150 ## What are significant technical challenges you expect to solve during the project, if any?
151
152 This is compiler technology, which is traditionally viewed as particularly
153 challenging. We are slightly fortunate in that much of the pieces of
154 the puzzle already exist: AMDVLK, RADV, the upstreamed acceptance of
155 RISC-V LLVM 9.0.0 being the key ones.
156
157 Whilst we know *technically* what they did and why they did it, the key
158 challenge will be to unravel what exact changes AMD made which caused
159 them to have to "fork" LLVM several years back, to keep track of their
160 efforts to introduce "mainline" LLVM patches on an ongoing piecemeal
161 basis, and at the same time *add our own assembler back-end* into the
162 same fast-moving target.
163
164 Whereas with RADV it is upstreamed in MESA, and has much wider community
165 support, it will need very careful detailed evaluation to ensure that it meets
166 the needs of the Libre RISC-V Vector Engine.
167
168 ## Describe the ecosystem of the project, and how you will engage with relevant actors and promote the outcomes?
169
170 As mentioned in the 2018 submission, the Libre RISC-V
171 SoC has a full set of resources for Libre Project Management and development:
172 mailing list, bugtracker, git repository and wiki - all listed here:
173 <https://libre-riscv.org/>
174
175 In addition, we have a Crowdsupply page
176 <https://www.crowdsupply.com/libre-risc-v/m-class> which provides a public
177 gateway, and heise.de, reddit, phoronix, slashdot and other locations have
178 all picked up the story. The list is updated and maintained here:
179 <https://libre-riscv.org/3d_gpu/>
180
181 # Extra info to be submitted
182
183 * <http://libre-riscv.org/3d_gpu/>
184 * <https://nlnet.nl/project/Libre-RISCV/>
185 * <https://github.com/GPUOpen-Drivers/AMDVLK>
186 * <https://github.com/google/swiftshader/>
187 * <https://salsa.debian.org/Kazan-team/kazan>
188 * <https://github.com/mesa3d/mesa/tree/master/src/amd/vulkan>
189
190 # Management Summary
191
192 The Libre SoC Project core is funded from an initial 2018 proposal. This includes a 3D Driver, called Kazan, and its purpose is to provide a Vulkan compliant hybrid hardware-software API. Given the complex nature of 3D driver development, and because Kazan is a novel approach (written in rust, for security reasons) a second oroposal was submitted to develop a Mesa3D driver (in c++). A second more traditional (c++) 3D Driver allows for increased transparency and collaboration on this ambitious project.