17ec681f3SmrgSubmitting Patches
27ec681f3Smrg==================
37ec681f3Smrg
47ec681f3Smrg.. _guidelines:
57ec681f3Smrg
67ec681f3SmrgBasic guidelines
77ec681f3Smrg----------------
87ec681f3Smrg
97ec681f3Smrg-  Patches should not mix code changes with code formatting changes
107ec681f3Smrg   (except, perhaps, in very trivial cases.)
117ec681f3Smrg-  Code patches should follow Mesa :doc:`coding
127ec681f3Smrg   conventions <codingstyle>`.
137ec681f3Smrg-  Whenever possible, patches should only affect individual Mesa/Gallium
147ec681f3Smrg   components.
157ec681f3Smrg-  Patches should never introduce build breaks and should be bisectable
167ec681f3Smrg   (see ``Git bisect``.)
177ec681f3Smrg-  Patches should be properly :ref:`formatted <formatting>`.
187ec681f3Smrg-  Patches should be sufficiently :ref:`tested <testing>` before
197ec681f3Smrg   submitting.
207ec681f3Smrg-  Patches should be :ref:`submitted <submit>` via a merge request for
217ec681f3Smrg   :ref:`review <reviewing>`.
227ec681f3Smrg
237ec681f3Smrg.. _formatting:
247ec681f3Smrg
257ec681f3SmrgPatch formatting
267ec681f3Smrg----------------
277ec681f3Smrg
287ec681f3Smrg-  Lines should be limited to 75 characters or less so that Git logs
297ec681f3Smrg   displayed in 80-column terminals avoid line wrapping. Note that
307ec681f3Smrg   ``git log`` uses 4 spaces of indentation (4 + 75 < 80).
317ec681f3Smrg-  The first line should be a short, concise summary of the change
327ec681f3Smrg   prefixed with a module name. Examples:
337ec681f3Smrg
347ec681f3Smrg   ::
357ec681f3Smrg
367ec681f3Smrg      mesa: Add support for querying GL_VERTEX_ATTRIB_ARRAY_LONG
377ec681f3Smrg
387ec681f3Smrg      gallium: add PIPE_CAP_DEVICE_RESET_STATUS_QUERY
397ec681f3Smrg
407ec681f3Smrg      i965: Fix missing type in local variable declaration.
417ec681f3Smrg
427ec681f3Smrg-  Subsequent patch comments should describe the change in more detail,
437ec681f3Smrg   if needed. For example:
447ec681f3Smrg
457ec681f3Smrg   ::
467ec681f3Smrg
477ec681f3Smrg      i965: Remove end-of-thread SEND alignment code.
487ec681f3Smrg
497ec681f3Smrg      This was present in Eric's initial implementation of the compaction code
507ec681f3Smrg      for Sandybridge (commit 077d01b6). There is no documentation saying this
517ec681f3Smrg      is necessary, and removing it causes no regressions in piglit on any
527ec681f3Smrg      platform.
537ec681f3Smrg
547ec681f3Smrg-  A "Signed-off-by:" line is not required, but not discouraged either.
557ec681f3Smrg-  If a patch addresses an issue in GitLab, use the Closes: tag For
567ec681f3Smrg   example:
577ec681f3Smrg
587ec681f3Smrg   ::
597ec681f3Smrg
607ec681f3Smrg      Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1
617ec681f3Smrg
627ec681f3Smrg   Prefer the full URL to just ``Closes: #1``, since the URL makes it
637ec681f3Smrg   easier to get to the bug page from ``git log``
647ec681f3Smrg
657ec681f3Smrg   **Do not use the ``Fixes:`` tag for this!** Mesa already uses
667ec681f3Smrg   ``Fixes:`` for something else.
677ec681f3Smrg   See :ref:`below <fixes>`.
687ec681f3Smrg
697ec681f3Smrg-  If there have been several revisions to a patch during the review
707ec681f3Smrg   process, they should be noted such as in this example:
717ec681f3Smrg
727ec681f3Smrg   ::
737ec681f3Smrg
747ec681f3Smrg      st/mesa: add ARB_texture_stencil8 support (v4)
757ec681f3Smrg
767ec681f3Smrg      if we support stencil texturing, enable texture_stencil8
777ec681f3Smrg      there is no requirement to support native S8 for this,
787ec681f3Smrg      the texture can be converted to x24s8 fine.
797ec681f3Smrg
807ec681f3Smrg      v2: fold fixes from Marek in:
817ec681f3Smrg         a) put S8 last in the list
827ec681f3Smrg         b) fix renderable to always test for d/s renderable
837ec681f3Smrg           fixup the texture case to use a stencil only format
847ec681f3Smrg           for picking the format for the texture view.
857ec681f3Smrg      v3: hit fallback for getteximage
867ec681f3Smrg      v4: put s8 back in front, it shouldn't get picked now (Ilia)
877ec681f3Smrg
887ec681f3Smrg-  If someone tested your patch, document it with a line like this:
897ec681f3Smrg
907ec681f3Smrg   ::
917ec681f3Smrg
927ec681f3Smrg      Tested-by: Joe Hacker <jhacker@foo.com>
937ec681f3Smrg
947ec681f3Smrg-  If the patch was reviewed (usually the case) or acked by someone,
957ec681f3Smrg   that should be documented with:
967ec681f3Smrg
977ec681f3Smrg   ::
987ec681f3Smrg
997ec681f3Smrg      Reviewed-by: Joe Hacker <jhacker@foo.com>
1007ec681f3Smrg      Acked-by: Joe Hacker <jhacker@foo.com>
1017ec681f3Smrg
1027ec681f3Smrg-  When updating a merge request add all the tags (``Acked-by:``, ``Reviewed-by:``,
1037ec681f3Smrg   ``Fixes:``, ``Cc: mesa-stable`` and/or other) to the commit messages.
1047ec681f3Smrg   This provides reviewers with quick feedback if the patch has already
1057ec681f3Smrg   been reviewed.
1067ec681f3Smrg
1077ec681f3Smrg.. _fixes:
1087ec681f3Smrg
1097ec681f3SmrgThe ``Fixes:`` tag
1107ec681f3Smrg------------------
1117ec681f3Smrg
1127ec681f3SmrgIf a patch addresses a issue introduced with earlier commit, that
1137ec681f3Smrgshould be noted in the commit message. For example::
1147ec681f3Smrg
1157ec681f3Smrg    Fixes: d7b3707c612 ("util/disk_cache: use stat() to check if entry is a directory")
1167ec681f3Smrg
1177ec681f3SmrgYou can produce those fixes lines by running this command once::
1187ec681f3Smrg
1197ec681f3Smrg    git config --global alias.fixes "show -s --pretty='format:Fixes: %h (\"%s\")'"
1207ec681f3Smrg
1217ec681f3SmrgAfter that, using ``git fixes <sha1>`` will print the full line for you.
1227ec681f3Smrg
1237ec681f3SmrgThe stable tag
1247ec681f3Smrg~~~~~~~~~~~~~~
1257ec681f3Smrg
1267ec681f3SmrgIf you want a commit to be applied to a stable branch, you should add an
1277ec681f3Smrgappropriate note to the commit message.
1287ec681f3Smrg
1297ec681f3SmrgUsing a ``Fixes:`` tag as described in :ref:`Patch formatting <formatting>`
1307ec681f3Smrgis the preferred way to nominate a commit that should be backported.
1317ec681f3SmrgThere are scripts that will figure out which releases to apply the patch
1327ec681f3Smrgto automatically, so you don't need to figure it out.
1337ec681f3Smrg
1347ec681f3SmrgAlternatively, you may use a "CC:" tag. Here are some examples of such a
1357ec681f3Smrgnote::
1367ec681f3Smrg
1377ec681f3Smrg    Cc: mesa-stable
1387ec681f3Smrg    Cc: 20.0 <mesa-stable>
1397ec681f3Smrg    CC: 20.0 19.3 <mesa-stable>
1407ec681f3Smrg
1417ec681f3SmrgUsing the CC tag **should** include the stable branches you want to
1427ec681f3Smrgnominate the patch to. If you do not provide any version it is nominated
1437ec681f3Smrgto all active stable branches.
1447ec681f3Smrg
1457ec681f3Smrg.. _testing:
1467ec681f3Smrg
1477ec681f3SmrgTesting Patches
1487ec681f3Smrg---------------
1497ec681f3Smrg
1507ec681f3SmrgIt should go without saying that patches must be tested. In general, do
1517ec681f3Smrgwhatever testing is prudent.
1527ec681f3Smrg
1537ec681f3SmrgYou should always run the Mesa test suite before submitting patches. The
1547ec681f3Smrgtest suite can be run using the 'meson test' command. All tests must
1557ec681f3Smrgpass before patches will be accepted, this may mean you have to update
1567ec681f3Smrgthe tests themselves.
1577ec681f3Smrg
1587ec681f3SmrgWhenever possible and applicable, test the patch with
1597ec681f3Smrg`Piglit <https://piglit.freedesktop.org>`__ and/or
1607ec681f3Smrg`dEQP <https://android.googlesource.com/platform/external/deqp/>`__ to
1617ec681f3Smrgcheck for regressions.
1627ec681f3Smrg
1637ec681f3SmrgAs mentioned at the beginning, patches should be bisectable. A good way
1647ec681f3Smrgto test this is to make use of the \`git rebase\` command, to run your
1657ec681f3Smrgtests on each commit. Assuming your branch is based off
1667ec681f3Smrg``origin/main``, you can run:
1677ec681f3Smrg
1687ec681f3Smrg.. code-block:: console
1697ec681f3Smrg
1707ec681f3Smrg   $ git rebase --interactive --exec "meson test -C build/" origin/main
1717ec681f3Smrg
1727ec681f3Smrgreplacing ``"meson test"`` with whatever other test you want to run.
1737ec681f3Smrg
1747ec681f3Smrg.. _submit:
1757ec681f3Smrg
1767ec681f3SmrgSubmitting Patches
1777ec681f3Smrg------------------
1787ec681f3Smrg
1797ec681f3SmrgPatches are submitted to the Mesa project via a
1807ec681f3Smrg`GitLab <https://gitlab.freedesktop.org/mesa/mesa>`__ Merge Request.
1817ec681f3Smrg
1827ec681f3SmrgAdd labels to your MR to help reviewers find it. For example:
1837ec681f3Smrg
1847ec681f3Smrg-  Mesa changes affecting all drivers: mesa
1857ec681f3Smrg-  Hardware vendor specific code: amd, intel, nvidia, ...
1867ec681f3Smrg-  Driver specific code: anvil, freedreno, i965, iris, radeonsi, radv,
1877ec681f3Smrg   vc4, ...
1887ec681f3Smrg-  Other tag examples: gallium, util
1897ec681f3Smrg
1907ec681f3SmrgTick the following when creating the MR. It allows developers to rebase
1917ec681f3Smrgyour work on top of main.
1927ec681f3Smrg
1937ec681f3Smrg::
1947ec681f3Smrg
1957ec681f3Smrg   Allow commits from members who can merge to the target branch
1967ec681f3Smrg
1977ec681f3SmrgIf you revise your patches based on code review and push an update to
1987ec681f3Smrgyour branch, you should maintain a **clean** history in your patches.
1997ec681f3SmrgThere should not be "fixup" patches in the history. The series should be
2007ec681f3Smrgbuildable and functional after every commit whenever you push the
2017ec681f3Smrgbranch.
2027ec681f3Smrg
2037ec681f3SmrgIt is your responsibility to keep the MR alive and making progress, as
2047ec681f3Smrgthere are no guarantees that a Mesa dev will independently take interest
2057ec681f3Smrgin it.
2067ec681f3Smrg
2077ec681f3SmrgSome other notes:
2087ec681f3Smrg
2097ec681f3Smrg-  Make changes and update your branch based on feedback
2107ec681f3Smrg-  After an update, for the feedback you handled, close the feedback
2117ec681f3Smrg   discussion with the "Resolve Discussion" button. This way the
2127ec681f3Smrg   reviewers know which feedback got handled and which didn't.
2137ec681f3Smrg-  Old, stale MR may be closed, but you can reopen it if you still want
2147ec681f3Smrg   to pursue the changes
2157ec681f3Smrg-  You should periodically check to see if your MR needs to be rebased
2167ec681f3Smrg-  Make sure your MR is closed if your patches get pushed outside of
2177ec681f3Smrg   GitLab
2187ec681f3Smrg-  Please send MRs from a personal fork rather than from the main Mesa
2197ec681f3Smrg   repository, as it clutters it unnecessarily.
2207ec681f3Smrg
2217ec681f3Smrg.. _reviewing:
2227ec681f3Smrg
2237ec681f3SmrgReviewing Patches
2247ec681f3Smrg-----------------
2257ec681f3Smrg
2267ec681f3SmrgTo participate in code review, you can monitor the GitLab Mesa `Merge
2277ec681f3SmrgRequests <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests>`__
2287ec681f3Smrgpage, and/or register for notifications in your GitLab settings.
2297ec681f3Smrg
2307ec681f3SmrgWhen you've reviewed a patch, please be unambiguous about your review.
2317ec681f3SmrgThat is, state either
2327ec681f3Smrg
2337ec681f3Smrg::
2347ec681f3Smrg
2357ec681f3Smrg   Reviewed-by: Joe Hacker <jhacker@foo.com>
2367ec681f3Smrg
2377ec681f3Smrgor
2387ec681f3Smrg
2397ec681f3Smrg::
2407ec681f3Smrg
2417ec681f3Smrg   Acked-by: Joe Hacker <jhacker@foo.com>
2427ec681f3Smrg
2437ec681f3SmrgRather than saying just "LGTM" or "Seems OK".
2447ec681f3Smrg
2457ec681f3SmrgIf small changes are suggested, it's OK to say something like:
2467ec681f3Smrg
2477ec681f3Smrg::
2487ec681f3Smrg
2497ec681f3Smrg   With the above fixes, Reviewed-by: Joe Hacker <jhacker@foo.com>
2507ec681f3Smrg
2517ec681f3Smrgwhich tells the patch author that the patch can be committed, as long as
2527ec681f3Smrgthe issues are resolved first.
2537ec681f3Smrg
2547ec681f3SmrgThese Reviewed-by, Acked-by, and Tested-by tags should also be amended
2557ec681f3Smrginto commits in a MR before it is merged.
2567ec681f3Smrg
2577ec681f3SmrgWhen providing a Reviewed-by, Acked-by, or Tested-by tag in a GitLab MR,
2587ec681f3Smrgenclose the tag in backticks:
2597ec681f3Smrg
2607ec681f3Smrg::
2617ec681f3Smrg
2627ec681f3Smrg   `Reviewed-by: Joe Hacker <jhacker@example.com>`
2637ec681f3Smrg
2647ec681f3SmrgThis is the markdown format for literal, and will prevent GitLab from
2657ec681f3Smrghiding the < and > symbols.
2667ec681f3Smrg
2677ec681f3SmrgReview by non-experts is encouraged. Understanding how someone else goes
2687ec681f3Smrgabout solving a problem is a great way to learn your way around the
2697ec681f3Smrgproject. The submitter is expected to evaluate whether they have an
2707ec681f3Smrgappropriate amount of review feedback from people who also understand
2717ec681f3Smrgthe code before merging their patches.
2727ec681f3Smrg
2737ec681f3SmrgNominating a commit for a stable branch
2747ec681f3Smrg---------------------------------------
2757ec681f3Smrg
2767ec681f3SmrgThere are several ways to nominate a patch for inclusion in the stable
2777ec681f3Smrgbranch and release. In order or preference:
2787ec681f3Smrg
2797ec681f3Smrg- By adding the ``Fixes:`` tag in the commit message as described above, if you are fixing
2807ec681f3Smrg  a specific commit.
2817ec681f3Smrg- By adding the ``Cc: mesa-stable`` tag in the commit message as described above.
2827ec681f3Smrg- By submitting a merge request against the ``staging/year.quarter``
2837ec681f3Smrg  branch on GitLab.
2847ec681f3Smrg
2857ec681f3SmrgPlease **DO NOT** send patches to mesa-stable@lists.freedesktop.org, it
2867ec681f3Smrgis not monitored actively and is a historical artifact.
2877ec681f3Smrg
2887ec681f3SmrgIf you are not the author of the original patch, please Cc: them in your
2897ec681f3Smrgnomination request.
2907ec681f3Smrg
2917ec681f3SmrgThe current patch status can be observed in the :ref:`staging
2927ec681f3Smrgbranch <stagingbranch>`.
2937ec681f3Smrg
2947ec681f3Smrg.. _criteria:
2957ec681f3Smrg
2967ec681f3SmrgCriteria for accepting patches to the stable branch
2977ec681f3Smrg---------------------------------------------------
2987ec681f3Smrg
2997ec681f3SmrgMesa has a designated release manager for each stable branch, and the
3007ec681f3Smrgrelease manager is the only developer that should be pushing changes to
3017ec681f3Smrgthese branches. Everyone else should nominate patches using the
3027ec681f3Smrgmechanism described above. The following rules define which patches are
3037ec681f3Smrgaccepted and which are not. The stable-release manager is also given
3047ec681f3Smrgbroad discretion in rejecting patches that have been nominated.
3057ec681f3Smrg
3067ec681f3Smrg-  Patch must conform with the :ref:`Basic guidelines <guidelines>`
3077ec681f3Smrg-  Patch must have landed in main first. In case where the original
3087ec681f3Smrg   patch is too large and/or otherwise contradicts with the rules set
3097ec681f3Smrg   within, a backport is appropriate.
3107ec681f3Smrg-  It must not introduce a regression - be that build or runtime wise.
3117ec681f3Smrg
3127ec681f3Smrg   .. note::
3137ec681f3Smrg      If the regression is due to faulty piglit/dEQP/CTS/other test
3147ec681f3Smrg      the latter must be fixed first. A reference to the offending test(s)
3157ec681f3Smrg      and respective fix(es) should be provided in the nominated patch.
3167ec681f3Smrg
3177ec681f3Smrg-  Patch cannot be larger than 100 lines.
3187ec681f3Smrg-  Patches that move code around with no functional change should be
3197ec681f3Smrg   rejected.
3207ec681f3Smrg-  Patch must be a bug fix and not a new feature.
3217ec681f3Smrg
3227ec681f3Smrg   .. note::
3237ec681f3Smrg      An exception to this rule, are hardware-enabling "features". For
3247ec681f3Smrg      example, :ref:`backports <backports>` of new code to support a
3257ec681f3Smrg      newly-developed hardware product can be accepted if they can be
3267ec681f3Smrg      reasonably determined not to have effects on other hardware.
3277ec681f3Smrg
3287ec681f3Smrg-  Patch must be reviewed, For example, the commit message has
3297ec681f3Smrg   Reviewed-by, Signed-off-by, or Tested-by tags from someone but the
3307ec681f3Smrg   author.
3317ec681f3Smrg-  Performance patches are considered only if they provide information
3327ec681f3Smrg   about the hardware, program in question and observed improvement. Use
3337ec681f3Smrg   numbers to represent your measurements.
3347ec681f3Smrg
3357ec681f3SmrgIf the patch complies with the rules it will be
3367ec681f3Smrg:ref:`cherry-picked <pickntest>`. Alternatively the release
3377ec681f3Smrgmanager will reply to the patch in question stating why the patch has
3387ec681f3Smrgbeen rejected or would request a backport. The stable-release manager
3397ec681f3Smrgmay at times need to force-push changes to the stable branches, for
3407ec681f3Smrgexample, to drop a previously-picked patch that was later identified as
3417ec681f3Smrgcausing a regression). These force-pushes may cause changes to be lost
3427ec681f3Smrgfrom the stable branch if developers push things directly. Consider
3437ec681f3Smrgyourself warned.
3447ec681f3Smrg
3457ec681f3Smrg.. _backports:
3467ec681f3Smrg
3477ec681f3SmrgSending backports for the stable branch
3487ec681f3Smrg---------------------------------------
3497ec681f3Smrg
3507ec681f3SmrgBy default merge conflicts are resolved by the stable-release manager.
3517ec681f3SmrgThe release maintainer should resolve trivial conflicts, but for complex
3527ec681f3Smrgconflicts they should ask the original author to provide a backport or
3537ec681f3Smrgde-nominate the patch.
3547ec681f3Smrg
3557ec681f3SmrgFor patches that either need to be nominated after they've landed in
3567ec681f3Smrgmain, or that are known ahead of time to not not apply cleanly to a
3577ec681f3Smrgstable branch (such as due to a rename), using a GitLab MR is most
3587ec681f3Smrgappropriate. The MR should be based on and target the
3597ec681f3Smrgstaging/year.quarter branch, not on the year.quarter branch, per the
3607ec681f3Smrgstable branch policy. Assigning the MR to release maintainer for said
3617ec681f3Smrgbranch or mentioning them is helpful, but not required.
3627ec681f3Smrg
3637ec681f3SmrgDocumentation patches
3647ec681f3Smrg---------------------
3657ec681f3Smrg
3667ec681f3SmrgOur documentation is written as `reStructuredText`_ files in the
3677ec681f3Smrg:file:`docs` folder, and built using `Sphinx`_.
3687ec681f3Smrg
3697ec681f3SmrgThe preferred language of the documentation is US English. This
3707ec681f3Smrgdoesn't mean that everyone is expected to pay close attention to
3717ec681f3Smrgthe different English variants, but it does mean someone might
3727ec681f3Smrgsuggest a spelling-change, either during review or as a follow-up
3737ec681f3Smrgmerge-request.
3747ec681f3Smrg
3757ec681f3Smrg.. _reStructuredText: https://docutils.sourceforge.io/rst.html
3767ec681f3Smrg.. _Sphinx: https://www.sphinx-doc.org/
3777ec681f3Smrg
3787ec681f3SmrgGit tips
3797ec681f3Smrg--------
3807ec681f3Smrg
3817ec681f3Smrg-  ``git rebase -i ...`` is your friend. Don't be afraid to use it.
3827ec681f3Smrg-  Apply a fixup to commit FOO.
3837ec681f3Smrg
3847ec681f3Smrg   .. code-block:: console
3857ec681f3Smrg
3867ec681f3Smrg      git add ...
3877ec681f3Smrg      git commit --fixup=FOO
3887ec681f3Smrg      git rebase -i --autosquash ...
3897ec681f3Smrg
3907ec681f3Smrg-  Test for build breakage between patches e.g last 8 commits.
3917ec681f3Smrg
3927ec681f3Smrg   .. code-block:: console
3937ec681f3Smrg
3947ec681f3Smrg      git rebase -i --exec="ninja -C build/" HEAD~8
395