docs: use code-block with caption instead of table
[mesa.git] / docs / submittingpatches.rst
1 Submitting Patches
2 ==================
3
4 - `Basic guidelines <#guidelines>`__
5 - `Patch formatting <#formatting>`__
6 - `Testing Patches <#testing>`__
7 - `Submitting Patches <#submit>`__
8 - `Reviewing Patches <#reviewing>`__
9 - `Nominating a commit for a stable branch <#nominations>`__
10 - `Criteria for accepting patches to the stable branch <#criteria>`__
11 - `Sending backports for the stable branch <#backports>`__
12 - `Git tips <#gittips>`__
13
14 .. _guidelines:
15
16 Basic guidelines
17 ----------------
18
19 - Patches should not mix code changes with code formatting changes
20 (except, perhaps, in very trivial cases.)
21 - Code patches should follow Mesa `coding
22 conventions <codingstyle.html>`__.
23 - Whenever possible, patches should only affect individual Mesa/Gallium
24 components.
25 - Patches should never introduce build breaks and should be bisectable
26 (see ``git bisect``.)
27 - Patches should be properly `formatted <#formatting>`__.
28 - Patches should be sufficiently `tested <#testing>`__ before
29 submitting.
30 - Patches should be `submitted <#submit>`__ via a merge request for
31 `review <#reviewing>`__.
32
33 .. _formatting:
34
35 Patch formatting
36 ----------------
37
38 - Lines should be limited to 75 characters or less so that git logs
39 displayed in 80-column terminals avoid line wrapping. Note that git
40 log uses 4 spaces of indentation (4 + 75 < 80).
41 - The first line should be a short, concise summary of the change
42 prefixed with a module name. Examples:
43
44 ::
45
46 mesa: Add support for querying GL_VERTEX_ATTRIB_ARRAY_LONG
47
48 gallium: add PIPE_CAP_DEVICE_RESET_STATUS_QUERY
49
50 i965: Fix missing type in local variable declaration.
51
52 - Subsequent patch comments should describe the change in more detail,
53 if needed. For example:
54
55 ::
56
57 i965: Remove end-of-thread SEND alignment code.
58
59 This was present in Eric's initial implementation of the compaction code
60 for Sandybridge (commit 077d01b6). There is no documentation saying this
61 is necessary, and removing it causes no regressions in piglit on any
62 platform.
63
64 - A "Signed-off-by:" line is not required, but not discouraged either.
65 - If a patch addresses an issue in gitlab, use the Closes: tag For
66 example:
67
68 ::
69
70 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1
71
72 Prefer the full url to just ``Closes: #1``, since the url makes it
73 easier to get to the bug page from ``git log``
74
75 **Do not use the Fixes: tag for this!** Mesa already uses Fixes for
76 something else.
77
78 - If a patch addresses a issue introduced with earlier commit, that
79 should be noted in the patch comment. For example:
80
81 ::
82
83 Fixes: d7b3707c612 "util/disk_cache: use stat() to check if entry is a directory"
84
85 - You can produce those fixes lines by running
86
87 ::
88
89 git config --global alias.fixes "show -s --pretty='format:Fixes: %h (\"%s\")'"
90
91 once and then using
92
93 ::
94
95 git fixes <sha1>
96
97 - If there have been several revisions to a patch during the review
98 process, they should be noted such as in this example:
99
100 ::
101
102 st/mesa: add ARB_texture_stencil8 support (v4)
103
104 if we support stencil texturing, enable texture_stencil8
105 there is no requirement to support native S8 for this,
106 the texture can be converted to x24s8 fine.
107
108 v2: fold fixes from Marek in:
109 a) put S8 last in the list
110 b) fix renderable to always test for d/s renderable
111 fixup the texture case to use a stencil only format
112 for picking the format for the texture view.
113 v3: hit fallback for getteximage
114 v4: put s8 back in front, it shouldn't get picked now (Ilia)
115
116 - If someone tested your patch, document it with a line like this:
117
118 ::
119
120 Tested-by: Joe Hacker <jhacker@foo.com>
121
122 - If the patch was reviewed (usually the case) or acked by someone,
123 that should be documented with:
124
125 ::
126
127 Reviewed-by: Joe Hacker <jhacker@foo.com>
128 Acked-by: Joe Hacker <jhacker@foo.com>
129
130 - If sending later revision of a patch, add all the tags - ack, r-b,
131 Cc: mesa-stable and/or other. This provides reviewers with quick
132 feedback if the patch has already been reviewed.
133
134 .. _testing:
135
136 Testing Patches
137 ---------------
138
139 It should go without saying that patches must be tested. In general, do
140 whatever testing is prudent.
141
142 You should always run the Mesa test suite before submitting patches. The
143 test suite can be run using the 'meson test' command. All tests must
144 pass before patches will be accepted, this may mean you have to update
145 the tests themselves.
146
147 Whenever possible and applicable, test the patch with
148 `Piglit <https://piglit.freedesktop.org>`__ and/or
149 `dEQP <https://android.googlesource.com/platform/external/deqp/>`__ to
150 check for regressions.
151
152 As mentioned at the beginning, patches should be bisectable. A good way
153 to test this is to make use of the \`git rebase\` command, to run your
154 tests on each commit. Assuming your branch is based off
155 ``origin/master``, you can run:
156
157 ::
158
159 $ git rebase --interactive --exec "meson test -C build/" origin/master
160
161 replacing ``"meson test"`` with whatever other test you want to run.
162
163 .. _submit:
164
165 Submitting Patches
166 ------------------
167
168 Patches are submitted to the Mesa project via a
169 `GitLab <https://gitlab.freedesktop.org/mesa/mesa>`__ Merge Request.
170
171 Add labels to your MR to help reviewers find it. For example:
172
173 - Mesa changes affecting all drivers: mesa
174 - Hardware vendor specific code: amd, intel, nvidia, ...
175 - Driver specific code: anvil, freedreno, i965, iris, radeonsi, radv,
176 vc4, ...
177 - Other tag examples: gallium, util
178
179 Tick the following when creating the MR. It allows developers to rebase
180 your work on top of master.
181
182 ::
183
184 Allow commits from members who can merge to the target branch
185
186 If you revise your patches based on code review and push an update to
187 your branch, you should maintain a **clean** history in your patches.
188 There should not be "fixup" patches in the history. The series should be
189 buildable and functional after every commit whenever you push the
190 branch.
191
192 It is your responsibility to keep the MR alive and making progress, as
193 there are no guarantees that a Mesa dev will independently take interest
194 in it.
195
196 Some other notes:
197
198 - Make changes and update your branch based on feedback
199 - After an update, for the feedback you handled, close the feedback
200 discussion with the "Resolve Discussion" button. This way the
201 reviewers know which feedback got handled and which didn't.
202 - Old, stale MR may be closed, but you can reopen it if you still want
203 to pursue the changes
204 - You should periodically check to see if your MR needs to be rebased
205 - Make sure your MR is closed if your patches get pushed outside of
206 GitLab
207 - Please send MRs from a personal fork rather than from the main Mesa
208 repository, as it clutters it unnecessarily.
209
210 .. _reviewing:
211
212 Reviewing Patches
213 -----------------
214
215 To participate in code review, you can monitor the GitLab Mesa `Merge
216 Requests <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests>`__
217 page, and/or register for notifications in your gitlab settings.
218
219 When you've reviewed a patch, please be unambiguous about your review.
220 That is, state either
221
222 ::
223
224 Reviewed-by: Joe Hacker <jhacker@foo.com>
225
226 or
227
228 ::
229
230 Acked-by: Joe Hacker <jhacker@foo.com>
231
232 Rather than saying just "LGTM" or "Seems OK".
233
234 If small changes are suggested, it's OK to say something like:
235
236 ::
237
238 With the above fixes, Reviewed-by: Joe Hacker <jhacker@foo.com>
239
240 which tells the patch author that the patch can be committed, as long as
241 the issues are resolved first.
242
243 These Reviewed-by, Acked-by, and Tested-by tags should also be amended
244 into commits in a MR before it is merged.
245
246 When providing a Reviewed-by, Acked-by, or Tested-by tag in a gitlab MR,
247 enclose the tag in backticks:
248
249 ::
250
251 `Reviewed-by: Joe Hacker <jhacker@example.com>`
252
253 This is the markdown format for literal, and will prevent gitlab from
254 hiding the < and > symbols.
255
256 Review by non-experts is encouraged. Understanding how someone else goes
257 about solving a problem is a great way to learn your way around the
258 project. The submitter is expected to evaluate whether they have an
259 appropriate amount of review feedback from people who also understand
260 the code before merging their patches.
261
262 .. _nominations:
263
264 Nominating a commit for a stable branch
265 ---------------------------------------
266
267 There are three ways to nominate a patch for inclusion in the stable
268 branch and release.
269
270 - By adding the Cc: mesa-stable@ tag as described below.
271 - By adding the fixes: tag as described below.
272 - By submitting a merge request against the "staging/year.quarter"
273 branch on gitlab.
274
275 Please **DO NOT** send patches to mesa-stable@lists.freedesktop.org, it
276 is not monitored actively and is a historical artifact.
277
278 If you are not the author of the original patch, please Cc: them in your
279 nomination request.
280
281 The current patch status can be observed in the `staging
282 branch <releasing.html#stagingbranch>`__.
283
284 .. _thetag:
285
286 The stable tag
287 ~~~~~~~~~~~~~~
288
289 If you want a commit to be applied to a stable branch, you should add an
290 appropriate note to the commit message.
291
292 Using a "fixes tag" as described in `Patch formatting <#formatting>`__
293 is the preferred way to nominate a commit that you know ahead of time
294 should be backported. There are scripts that will figure out which
295 releases to apply the patch to automatically, so you don't need to
296 figure it out.
297
298 Alternatively, you may use a "CC:" tag. Here are some examples of such a
299 note:
300
301 ::
302
303 CC: 20.0 19.3 <mesa-stable@lists.freedesktop.org>
304
305 Using the CC tag **should** include the stable branches you want to
306 nominate the patch to. If you do not provide any version it is nominated
307 to all active stable branches.
308
309 .. _criteria:
310
311 Criteria for accepting patches to the stable branch
312 ---------------------------------------------------
313
314 Mesa has a designated release manager for each stable branch, and the
315 release manager is the only developer that should be pushing changes to
316 these branches. Everyone else should nominate patches using the
317 mechanism described above. The following rules define which patches are
318 accepted and which are not. The stable-release manager is also given
319 broad discretion in rejecting patches that have been nominated.
320
321 - Patch must conform with the `Basic guidelines <#guidelines>`__
322 - Patch must have landed in master first. In case where the original
323 patch is too large and/or otherwise contradicts with the rules set
324 within, a backport is appropriate.
325 - It must not introduce a regression - be that build or runtime wise.
326 Note: If the regression is due to faulty piglit/dEQP/CTS/other test
327 the latter must be fixed first. A reference to the offending test(s)
328 and respective fix(es) should be provided in the nominated patch.
329 - Patch cannot be larger than 100 lines.
330 - Patches that move code around with no functional change should be
331 rejected.
332 - Patch must be a bug fix and not a new feature. Note: An exception to
333 this rule, are hardware-enabling "features". For example,
334 `backports <#backports>`__ of new code to support a newly-developed
335 hardware product can be accepted if they can be reasonably determined
336 not to have effects on other hardware.
337 - Patch must be reviewed, For example, the commit message has
338 Reviewed-by, Signed-off-by, or Tested-by tags from someone but the
339 author.
340 - Performance patches are considered only if they provide information
341 about the hardware, program in question and observed improvement. Use
342 numbers to represent your measurements.
343
344 If the patch complies with the rules it will be
345 `cherry-picked <releasing.html#pickntest>`__. Alternatively the release
346 manager will reply to the patch in question stating why the patch has
347 been rejected or would request a backport. The stable-release manager
348 may at times need to force-push changes to the stable branches, for
349 example, to drop a previously-picked patch that was later identified as
350 causing a regression). These force-pushes may cause changes to be lost
351 from the stable branch if developers push things directly. Consider
352 yourself warned.
353
354 .. _backports:
355
356 Sending backports for the stable branch
357 ---------------------------------------
358
359 By default merge conflicts are resolved by the stable-release manager.
360 The release maintainer should resolve trivial conflicts, but for complex
361 conflicts they should ask the original author to provide a backport or
362 de-nominate the patch.
363
364 For patches that either need to be nominated after they've landed in
365 master, or that are known ahead of time to not not apply cleanly to a
366 stable branch (such as due to a rename), using a gitlab MR is most
367 appropriate. The MR should be based on and target the
368 staging/year.quarter branch, not on the year.quarter branch, per the
369 stable branch policy. Assigning the MR to release maintainer for said
370 branch or mentioning them is helpful, but not required.
371
372 .. _gittips:
373
374 Git tips
375 --------
376
377 - ``git rebase -i ...`` is your friend. Don't be afraid to use it.
378 - Apply a fixup to commit FOO.
379
380 ::
381
382 git add ...
383 git commit --fixup=FOO
384 git rebase -i --autosquash ...
385
386 - Test for build breakage between patches e.g last 8 commits.
387
388 ::
389
390 git rebase -i --exec="ninja -C build/" HEAD~8
391
392 - Sets the default mailing address for your repo.
393
394 ::
395
396 git config --local sendemail.to mesa-dev@lists.freedesktop.org
397
398 - Add version to subject line of patch series in this case for the last
399 8 commits before sending.
400
401 ::
402
403 git send-email --subject-prefix="PATCH v4" HEAD~8
404 git send-email -v4 @~8 # shorter version, inherited from git format-patch