Debian Codegraph @

docs/submittingpatches.rst

raw
1 Submitting Patches
2 ==================
3
4 .. _introduction:
5
6 Introduction
7 ------------
8
9 Mesa contribution is a collaborative process that works like this:
10 A contributor proposes a change (usually in the form of a GitLab
11 merge request), which must undergo a review (usually in the form of
12 comments from the maintainers on the merge request).
13
14 The maintainers either accept it as-is, reject it outright,
15 or request changes from the contributor before a contribution
16 can be accepted.
17
18 Mesa is a project that is made up of many different subprojects,
19 for example drivers, API frontends, shader compiler infrastructure,
20 etc. Each of these parts may have different maintainers and/or
21 different rules and conventions. It is up to the maintainers of
22 each specific part to decide what is acceptable for them and
23 to direct the development of that part.
24
25 .. _expectations_on_contributors:
26
27 Expectations on contributors
28 ----------------------------
29
30 Due to the collaborative nature of development, the expectation is that
31 the contributor engages with the maintainers and works with
32 us to shape the changeset into a form that can be accepted in the project.
33
34 If you want to contribute code to Mesa, we highly recommend the following:
35
36 - Familiarize yourself with `Git <https://git-scm.com>`__.
37 - Understand the code you write at least well enough to be able
38 to explain why your changes are beneficial to the project.
39 - It's up you what tools you use to write code (development environment,
40 coding assistant, etc.), but keep in mind that no tool can substitute
41 actual understanding.
42
43 In case you are not familiar with the code base, it's okay to ask for help
44 and guidance from more experienced developers.
45
46 The submitter is responsible for the code change, regardless of where
47 that code change came from, whether they wrote it themselves, used an
48 "AI" or other tool, or got it from someone else. That responsibility
49 includes making sure that the code change can be submitted under the
50 MIT license that Mesa uses.
51
52 The submitter needs to understand what code they are changing,
53 what the change does, and justify that change in the commit messages.
54 Using coding assistants or "AI" or other tools does not grant additional
55 privileges or reduce our expectations.
56
57 If you don't know programming (and don't want to learn), but you are
58 interested in the Mesa project, there are plenty of other ways to
59 contribute besides writing code, for example reporting bugs, benchmarking,
60 testing changes, etc.
61
62 .. _guidelines:
63
64 Basic guidelines
65 ----------------
66
67 - Patches should not mix code changes with code formatting changes
68 (except, perhaps, in very trivial cases.)
69 - Code patches should follow Mesa :doc:`coding
70 conventions <codingstyle>`.
71 - Whenever possible, patches should only affect individual Mesa/Gallium
72 components.
73 - Patches should never introduce build breaks and should be bisectable
74 (see ``Git bisect``.)
75 - Patches should be properly :ref:`formatted <formatting>`.
76 - Patches should be sufficiently :ref:`tested <testing>` before
77 submitting.
78 - Patches should be :ref:`submitted <submit>` via a merge request for
79 :ref:`review <reviewing>`.
80
81 .. _formatting:
82
83 Patch formatting
84 ----------------
85
86 - Lines should be limited to 75 characters or less so that Git logs
87 displayed in 80-column terminals avoid line wrapping. Note that
88 ``git log`` uses 4 spaces of indentation (4 + 75 < 80).
89 - The first line should be a short, concise summary of the change
90 prefixed with a module name. Examples:
91
92 ::
93
94 mesa: Add support for querying GL_VERTEX_ATTRIB_ARRAY_LONG
95
96 gallium: add pipe_caps.device_reset_status_query
97
98 i965: Fix missing type in local variable declaration.
99
100 - Subsequent patch comments should describe the change in more detail,
101 if needed. For example:
102
103 ::
104
105 i965: Remove end-of-thread SEND alignment code.
106
107 This was present in Eric's initial implementation of the compaction code
108 for Sandybridge (commit 077d01b6). There is no documentation saying this
109 is necessary, and removing it causes no regressions in piglit on any
110 platform.
111
112 - A "Signed-off-by:" line is not required, but not discouraged either.
113 - If a patch addresses an issue in GitLab, use the Closes: tag For
114 example:
115
116 ::
117
118 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1
119
120 Prefer the full URL to just ``Closes: #1``, since the URL makes it
121 easier to get to the bug page from ``git log``
122
123 **Do not use the ``Fixes:`` tag for this!** Mesa already uses
124 ``Fixes:`` for something else.
125 See :ref:`below <fixes>`.
126
127 - If there have been several revisions to a patch during the review
128 process, they should be noted such as in this example:
129
130 ::
131
132 st/mesa: add ARB_texture_stencil8 support (v4)
133
134 if we support stencil texturing, enable texture_stencil8
135 there is no requirement to support native S8 for this,
136 the texture can be converted to x24s8 fine.
137
138 v2: fold fixes from Marek in:
139 a) put S8 last in the list
140 b) fix renderable to always test for d/s renderable
141 fixup the texture case to use a stencil only format
142 for picking the format for the texture view.
143 v3: hit fallback for getteximage
144 v4: put s8 back in front, it shouldn't get picked now (Ilia)
145
146 - If someone tested your patch, document it with a line like this:
147
148 ::
149
150 Tested-by: Joe Hacker <[email protected]>
151
152 - If the patch was reviewed (usually the case) or acked by someone,
153 that should be documented with:
154
155 ::
156
157 Reviewed-by: Joe Hacker <[email protected]>
158 Acked-by: Joe Hacker <[email protected]>
159
160 - When updating a merge request add all the tags (``Acked-by:``, ``Reviewed-by:``,
161 ``Fixes:``, ``Backport-to:`` and/or other) to the commit messages.
162 This provides reviewers with quick feedback if the patch has already
163 been reviewed.
164
165 .. _fixes:
166
167 The ``Fixes:`` tag
168 ------------------
169
170 If a patch addresses a issue introduced with earlier commit, that
171 should be noted in the commit message. For example::
172
173 Fixes: d7b3707c612 ("util/disk_cache: use stat() to check if entry is a directory")
174
175 You can produce those fixes lines by running this command once::
176
177 git config --global alias.fixes "show -s --pretty='format:Fixes: %h (\"%s\")'"
178
179 After that, using ``git fixes <sha1>`` will print the full line for you.
180
181 The stable tag
182 ~~~~~~~~~~~~~~
183
184 If you want a commit to be applied to a stable branch, you should add an
185 appropriate note to the commit message.
186
187 Using a ``Fixes:`` tag as described in :ref:`Patch formatting <formatting>`
188 is the preferred way to nominate a commit that should be backported.
189 There are scripts that will figure out which releases to apply the patch
190 to automatically, so you don't need to figure it out.
191
192 Alternatively, you may use the ``Backport-to:`` tag, as presented in the
193 following example::
194
195 Backport-to: 21.0
196
197 This will backport the commit to the 21.0 branch, as well as any more recent
198 stable branch. Multiple ``Backport-to:`` lines are allowed, but only the
199 lowest number mentioned actually matters, so for clarity, please only use one.
200 You can also use the special ``Backport-to: *`` which will nominate the commit
201 to be backported to every active stable branch, making it a synonym to the ``Cc:
202 mesa-stable`` below.
203
204 The last option is deprecated and mostly here for historical reasons
205 dating back to when patch submission was done via emails: using a ``Cc:``
206 tag. Support for this tag will be removed at some point.
207 Here are some examples of such a note::
208
209 Cc: mesa-stable
210 Cc: 20.0 <mesa-stable>
211 CC: 20.0 19.3 <mesa-stable>
212
213 Using the CC tag **should** include the stable branches you want to
214 nominate the patch to. If you do not provide any version it is nominated
215 to all active stable branches.
216
217 .. _testing:
218
219 Testing Patches
220 ---------------
221
222 It should go without saying that patches must be tested. In general, do
223 whatever testing is prudent.
224
225 You should always run the Mesa test suite before submitting patches. The
226 test suite can be run using the 'meson test' command. All tests must
227 pass before patches will be accepted, this may mean you have to update
228 the tests themselves.
229
230 Whenever possible and applicable, test the patch with
231 `Piglit <https://piglit.freedesktop.org>`__ and/or
232 `dEQP <https://android.googlesource.com/platform/external/deqp/>`__ to
233 check for regressions.
234
235 As mentioned at the beginning, patches should be bisectable. A good way
236 to test this is to make use of the \`git rebase\` command, to run your
237 tests on each commit. Assuming your branch is based off
238 ``origin/main``, you can run:
239
240 .. code-block:: sh
241
242 $ git rebase --interactive --exec "meson test -C build/" origin/main
243
244 replacing ``"meson test"`` with whatever other test you want to run.
245
246 .. _submit:
247
248 Submitting Patches
249 ------------------
250
251 Patches are submitted to the Mesa project via a
252 `GitLab <https://gitlab.freedesktop.org/mesa/mesa>`__ Merge Request (MR).
253
254 - Please do NOT submit your patches in email to a mailing list,
255 we only review patches on GitLab.
256 - Please do NOT paste your patches as comments in a conversation,
257 unless it is small or unless that is what the maintainers requested.
258 - If you are not familiar with how to use git, please learn that
259 before making a contribution to Mesa.
260
261 When opening a merge request, we recommend the following best practices:
262
263 Add a prefix to the title of the MR to indicate which part of the
264 codebase is affected. This is helpful to people who receive many MRs
265 and filter them by title. All commits must also have a prefix.
266 If you are unsure what is the correct prefix, please check the git
267 history for the files you are changing and choose based on that.
268
269 If you are already in the 'developer' role,
270 add labels to your MR to help reviewers find your MR.
271 For example:
272
273 - Mesa changes affecting all drivers: mesa
274 - Hardware vendor specific code: AMD common, intel, ...
275 - Driver specific code: ANV, freedreno, i965, iris, radeonsi, RADV,
276 vc4, ...
277 - Other tag examples: gallium, util
278
279 If you don't add any labels, a bot will attempt to add the correct ones.
280
281 Tick the following when creating the MR. It allows developers to rebase
282 your work on top of main.
283
284 ::
285
286 Allow commits from members who can merge to the target branch
287
288 If you revise your patches based on code review and push an update to
289 your branch, you should maintain a **clean** history in your patches.
290 There should not be "fixup" patches in the history. The series should be
291 buildable and functional after every commit whenever you push the
292 branch.
293
294 It is your responsibility to keep the MR alive and making progress, as
295 there are no guarantees that a Mesa dev will independently take interest
296 in it.
297
298 Some other notes:
299
300 - Make changes and update your branch based on feedback
301 - After an update, for the feedback you handled, close the feedback
302 discussion with the "Resolve Discussion" button. This way the
303 reviewers know which feedback got handled and which didn't.
304 - Old, stale MR may be closed, but you can reopen it if you still want
305 to pursue the changes
306 - You should periodically check to see if your MR needs to be rebased
307 - Make sure your MR is closed if your patches get pushed outside of
308 GitLab
309 - Please send MRs from a personal fork rather than from the main Mesa
310 repository, as it clutters it unnecessarily.
311
312 .. _reviewing:
313
314 Reviewing Patches
315 -----------------
316
317 To participate in code review, you can monitor the GitLab Mesa `Merge
318 Requests <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests>`__
319 page, and/or register for notifications in your GitLab settings.
320
321 When you've reviewed a patch, please be unambiguous about your review.
322 That is, state either
323
324 ::
325
326 Reviewed-by: Joe Hacker <[email protected]>
327
328 or
329
330 ::
331
332 Acked-by: Joe Hacker <[email protected]>
333
334 Rather than saying just "LGTM" or "Seems OK".
335
336 If small changes are suggested, it's OK to say something like:
337
338 ::
339
340 With the above fixes, Reviewed-by: Joe Hacker <[email protected]>
341
342 which tells the patch author that the patch can be committed, as long as
343 the issues are resolved first.
344
345 These Reviewed-by, Acked-by, and Tested-by tags should also be amended
346 into commits in a MR before it is merged.
347
348 When providing a Reviewed-by, Acked-by, or Tested-by tag in a GitLab MR,
349 enclose the tag in backticks:
350
351 ::
352
353 `Reviewed-by: Joe Hacker <[email protected]>`
354
355 This is the markdown format for literal, and will prevent GitLab from
356 hiding the < and > symbols.
357
358 Review by non-experts is encouraged. Understanding how someone else goes
359 about solving a problem is a great way to learn your way around the
360 project. The submitter is expected to evaluate whether they have an
361 appropriate amount of review feedback from people who also understand
362 the code before merging their patches.
363
364 .. _merging:
365
366 Merging merge requests
367 ----------------------
368
369 Once a merge request has been appropriately reviewed, its author can decide to
370 merge it.
371
372 .. warning::
373 Pushing (``git push``) directly to ``main`` is forbidden. This bypasses all
374 the CI checks and is likely to cause issues for everyone else.
375
376 .. warning::
377 Do not use the "Merge"/"Merge when pipeline succeeds"/"Set to auto-merge"
378 buttons.
379
380 We use a `custom script <https://gitlab.com/marge-org/marge-bot>`__ to manage
381 this, triggered by **assigning the MR** to the pseudo-user `@marge-bot
382 <https://gitlab.freedesktop.org/marge-bot>`__.
383
384 Authors who do not have ``Developer`` access (or above) should ask on the
385 merge request for someone else to do it for them, or reach on
386 :doc:`other channels <lists>` if the MR reviewers don't have access themselves.
387
388 Do not merge someone else's MR unless you are sure they don't have a new
389 version that they are testing locally for instance.
390 **When in doubt, ask**, for instance by leaving a comment on that MR.
391
392 Nominating a commit for a stable branch
393 ---------------------------------------
394
395 There are several ways to nominate a patch for inclusion in the stable
396 branch and release. In order or preference:
397
398 - By adding the ``Fixes:`` tag in the commit message as described above, if you are fixing
399 a specific commit.
400 - By adding the ``Cc: mesa-stable`` tag in the commit message as described above.
401 - By submitting a merge request against the ``staging/year.quarter``
402 branch on GitLab. Refer to the :ref:`instructions below <backports>`.
403
404 Please **DO NOT** send patches to [email protected], it
405 is not monitored actively and is a historical artifact.
406
407 If you are not the author of the original patch, please Cc: them in your
408 nomination request.
409
410 The current patch status can be observed in the :ref:`staging
411 branch <stagingbranch>`.
412
413 .. _criteria:
414
415 Criteria for accepting patches to the stable branch
416 ---------------------------------------------------
417
418 Mesa has a designated release manager for each stable branch, and the
419 release manager is the only developer that should be pushing changes to
420 these branches. Everyone else should nominate patches using the
421 mechanism described above. The following rules define which patches are
422 accepted and which are not. The stable-release manager is also given
423 broad discretion in rejecting patches that have been nominated.
424
425 - Patch must conform with the :ref:`Basic guidelines <guidelines>`
426 - Patch must have landed in main first. In case where the original
427 patch is too large and/or otherwise contradicts with the rules set
428 within, a backport is appropriate.
429 - It must not introduce a regression - be that build or runtime wise.
430
431 .. note::
432 If the regression is due to faulty Piglit/dEQP/CTS/other test
433 the latter must be fixed first. A reference to the offending test(s)
434 and respective fix(es) should be provided in the nominated patch.
435
436 - Patch cannot be larger than 100 lines.
437 - Patches that move code around with no functional change should be
438 rejected.
439 - Patch must be a bug fix and not a new feature.
440
441 .. note::
442 An exception to this rule, are hardware-enabling "features". For
443 example, :ref:`backports <backports>` of new code to support a
444 newly-developed hardware product can be accepted if they can be
445 reasonably determined not to have effects on other hardware.
446
447 - Patch must be reviewed, For example, the commit message has
448 Reviewed-by, Signed-off-by, or Tested-by tags from someone but the
449 author.
450 - Performance patches are considered only if they provide information
451 about the hardware, program in question and observed improvement. Use
452 numbers to represent your measurements.
453
454 If the patch complies with the rules it will be
455 :ref:`cherry-picked <pickntest>`. Alternatively the release
456 manager will reply to the patch in question stating why the patch has
457 been rejected or would request a backport. The stable-release manager
458 may at times need to force-push changes to the stable branches, for
459 example, to drop a previously-picked patch that was later identified as
460 causing a regression). These force-pushes may cause changes to be lost
461 from the stable branch if developers push things directly. Consider
462 yourself warned.
463
464 .. _backports:
465
466 Sending backports for the stable branch
467 ---------------------------------------
468
469 By default merge conflicts are resolved by the stable-release manager.
470 The release maintainer should resolve trivial conflicts, but for complex
471 conflicts they should ask the original author to provide a backport or
472 denominate the patch.
473
474 For patches that either need to be nominated after they've landed in
475 main, or that are known ahead of time to not not apply cleanly to a
476 stable branch (such as due to a rename), using a GitLab MR is most
477 appropriate. The MR must be based on and target the ``YY.N`` branch, and the
478 release manager will change the target to the ``staging/YY.N`` branch when
479 merging it; this avoid issues with the rebasing nature of the ``staging``
480 branches. Assigning the MR to release maintainer for said branch or mentioning
481 them is not required but helpful, to allow them to see the MR as soon as
482 possible.
483
484 .. warning::
485 Do not merge your backport MR yourself, even if you think it's ready.
486 The release manager will do it once everything is ok.
487
488 Make sure to use ``git cherry-pick -x`` when cherry-picking the commits
489 from the main branch. This adds the "cherry picked from commit ..." line
490 to the commit message, to allow the release maintainters to mark those
491 as backported, which in turn allows the tools to correctly report any
492 future ``Fixes:`` affecting the commits you backported.
493
494 Documentation patches
495 ---------------------
496
497 Our documentation is written as `reStructuredText`_ files in the
498 :file:`docs` folder, and built using `Sphinx`_.
499
500 .. code-block:: sh
501
502 # Install dependencies (adapt for your distribution)
503 apk add coreutils graphviz clang-dev musl-dev linux-headers
504 python3 -m venv docs-build
505 ./docs-build/bin/pip3 install sphinx===8.2.3 mako===1.2.3 hawkmoth===0.19.0 clang===$(llvm-config --version)
506
507 # Build docs (on Debian, set LD_LIBRARY_PATH to /usr/lib/llvm-VERSION/lib so it can find libclang.so)
508 ./docs-build/bin/sphinx-build -W -b html docs docs-html/
509
510 The preferred language of the documentation is US English. This
511 doesn't mean that everyone is expected to pay close attention to
512 the different English variants, but it does mean someone might
513 suggest a spelling-change, either during review or as a follow-up
514 merge-request.
515
516 .. _reStructuredText: https://docutils.sourceforge.io/rst.html
517 .. _Sphinx: https://www.sphinx-doc.org/
518
519 Git tips
520 --------
521
522 - ``git rebase -i ...`` is your friend. Don't be afraid to use it.
523 - Apply a fixup to commit FOO.
524
525 .. code-block:: sh
526
527 git add ...
528 git commit --fixup=FOO
529 git rebase -i --autosquash ...
530
531 - Test for build breakage between patches e.g last 8 commits.
532
533 .. code-block:: sh
534
535 git rebase -i --exec="ninja -C build/" HEAD~8