1fd4e5da5Sopenharmony_ci# Contributing to SPIR-V Tools
2fd4e5da5Sopenharmony_ci
3fd4e5da5Sopenharmony_ci## For users: Reporting bugs and requesting features
4fd4e5da5Sopenharmony_ci
5fd4e5da5Sopenharmony_ciWe organize known future work in GitHub projects. See
6fd4e5da5Sopenharmony_ci[Tracking SPIRV-Tools work with GitHub projects](https://github.com/KhronosGroup/SPIRV-Tools/blob/main/docs/projects.md)
7fd4e5da5Sopenharmony_cifor more.
8fd4e5da5Sopenharmony_ci
9fd4e5da5Sopenharmony_ciTo report a new bug or request a new feature, please file a GitHub issue. Please
10fd4e5da5Sopenharmony_ciensure the bug has not already been reported by searching
11fd4e5da5Sopenharmony_ci[issues](https://github.com/KhronosGroup/SPIRV-Tools/issues) and
12fd4e5da5Sopenharmony_ci[projects](https://github.com/KhronosGroup/SPIRV-Tools/projects). If the bug has
13fd4e5da5Sopenharmony_cinot already been reported open a new one
14fd4e5da5Sopenharmony_ci[here](https://github.com/KhronosGroup/SPIRV-Tools/issues/new).
15fd4e5da5Sopenharmony_ci
16fd4e5da5Sopenharmony_ciWhen opening a new issue for a bug, make sure you provide the following:
17fd4e5da5Sopenharmony_ci
18fd4e5da5Sopenharmony_ci*   A clear and descriptive title.
19fd4e5da5Sopenharmony_ci    *   We want a title that will make it easy for people to remember what the
20fd4e5da5Sopenharmony_ci        issue is about. Simply using "Segfault in spirv-opt" is not helpful
21fd4e5da5Sopenharmony_ci        because there could be (but hopefully aren't) multiple bugs with
22fd4e5da5Sopenharmony_ci        segmentation faults with different causes.
23fd4e5da5Sopenharmony_ci*   A test case that exposes the bug, with the steps and commands to reproduce
24fd4e5da5Sopenharmony_ci    it.
25fd4e5da5Sopenharmony_ci    *   The easier it is for a developer to reproduce the problem, the quicker a
26fd4e5da5Sopenharmony_ci        fix can be found and verified. It will also make it easier for someone
27fd4e5da5Sopenharmony_ci        to possibly realize the bug is related to another issue.
28fd4e5da5Sopenharmony_ci
29fd4e5da5Sopenharmony_ciFor feature requests, we use
30fd4e5da5Sopenharmony_ci[issues](https://github.com/KhronosGroup/SPIRV-Tools/issues) as well. Please
31fd4e5da5Sopenharmony_cicreate a new issue, as with bugs. In the issue provide
32fd4e5da5Sopenharmony_ci
33fd4e5da5Sopenharmony_ci*   A description of the problem that needs to be solved.
34fd4e5da5Sopenharmony_ci*   Examples that demonstrate the problem.
35fd4e5da5Sopenharmony_ci
36fd4e5da5Sopenharmony_ci## For developers: Contributing a patch
37fd4e5da5Sopenharmony_ci
38fd4e5da5Sopenharmony_ciBefore we can use your code, you must sign the
39fd4e5da5Sopenharmony_ci[Khronos Open Source Contributor License Agreement](https://cla-assistant.io/KhronosGroup/SPIRV-Tools)
40fd4e5da5Sopenharmony_ci(CLA), which you can do online. The CLA is necessary mainly because you own the
41fd4e5da5Sopenharmony_cicopyright to your changes, even after your contribution becomes part of our
42fd4e5da5Sopenharmony_cicodebase, so we need your permission to use and distribute your code. We also
43fd4e5da5Sopenharmony_cineed to be sure of various other things -- for instance that you'll tell us if
44fd4e5da5Sopenharmony_ciyou know that your code infringes on other people's patents. You don't have to
45fd4e5da5Sopenharmony_cisign the CLA until after you've submitted your code for review and a member has
46fd4e5da5Sopenharmony_ciapproved it, but you must do it before we can put your code into our codebase.
47fd4e5da5Sopenharmony_ci
48fd4e5da5Sopenharmony_ciSee
49fd4e5da5Sopenharmony_ci[README.md](https://github.com/KhronosGroup/SPIRV-Tools/blob/main/README.md)
50fd4e5da5Sopenharmony_cifor instruction on how to get, build, and test the source. Once you have made
51fd4e5da5Sopenharmony_ciyour changes:
52fd4e5da5Sopenharmony_ci
53fd4e5da5Sopenharmony_ci*   Ensure the code follows the
54fd4e5da5Sopenharmony_ci    [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
55fd4e5da5Sopenharmony_ci    Running `clang-format -style=file -i [modified-files]` can help.
56fd4e5da5Sopenharmony_ci*   Create a pull request (PR) with your patch.
57fd4e5da5Sopenharmony_ci*   Make sure the PR description clearly identified the problem, explains the
58fd4e5da5Sopenharmony_ci    solution, and references the issue if applicable.
59fd4e5da5Sopenharmony_ci*   If your patch completely fixes bug 1234, the commit message should say
60fd4e5da5Sopenharmony_ci    `Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1234` When you do
61fd4e5da5Sopenharmony_ci    this, the issue will be closed automatically when the commit goes into
62fd4e5da5Sopenharmony_ci    main. Also, this helps us update the [CHANGES](CHANGES) file.
63fd4e5da5Sopenharmony_ci*   Watch the continuous builds to make sure they pass.
64fd4e5da5Sopenharmony_ci*   Request a code review.
65fd4e5da5Sopenharmony_ci
66fd4e5da5Sopenharmony_ciThe reviewer can either approve your PR or request changes. If changes are
67fd4e5da5Sopenharmony_cirequested:
68fd4e5da5Sopenharmony_ci
69fd4e5da5Sopenharmony_ci*   Please add new commits to your branch, instead of amending your commit.
70fd4e5da5Sopenharmony_ci    Adding new commits makes it easier for the reviewer to see what has changed
71fd4e5da5Sopenharmony_ci    since the last review.
72fd4e5da5Sopenharmony_ci*   Once you are ready for another round of reviews, add a comment at the
73fd4e5da5Sopenharmony_ci    bottom, such as "Ready for review" or "Please take a look" (or "PTAL"). This
74fd4e5da5Sopenharmony_ci    explicit handoff is useful when responding with multiple small commits.
75fd4e5da5Sopenharmony_ci
76fd4e5da5Sopenharmony_ciAfter the PR has been reviewed it is the job of the reviewer to merge the PR.
77fd4e5da5Sopenharmony_ciInstructions for this are given below.
78fd4e5da5Sopenharmony_ci
79fd4e5da5Sopenharmony_ci## For maintainers: Reviewing a PR
80fd4e5da5Sopenharmony_ci
81fd4e5da5Sopenharmony_ciThe formal code reviews are done on GitHub. Reviewers are to look for all of the
82fd4e5da5Sopenharmony_ciusual things:
83fd4e5da5Sopenharmony_ci
84fd4e5da5Sopenharmony_ci*   Coding style follows the
85fd4e5da5Sopenharmony_ci    [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
86fd4e5da5Sopenharmony_ci*   Identify potential functional problems.
87fd4e5da5Sopenharmony_ci*   Identify code duplication.
88fd4e5da5Sopenharmony_ci*   Ensure the unit tests have enough coverage.
89fd4e5da5Sopenharmony_ci*   Ensure continuous integration (CI) bots run on the PR. If not run (in the
90fd4e5da5Sopenharmony_ci    case of PRs by external contributors), add the "kokoro:run" label to the
91fd4e5da5Sopenharmony_ci    pull request which will trigger running all CI jobs.
92fd4e5da5Sopenharmony_ci
93fd4e5da5Sopenharmony_ciWhen looking for functional problems, there are some common problems reviewers
94fd4e5da5Sopenharmony_cishould pay particular attention to:
95fd4e5da5Sopenharmony_ci
96fd4e5da5Sopenharmony_ci*   Does the code work for both Shader (Vulkan and OpenGL) and Kernel (OpenCL)
97fd4e5da5Sopenharmony_ci    scenarios? The respective SPIR-V dialects are slightly different.
98fd4e5da5Sopenharmony_ci*   Changes are made to a container while iterating through it. You have to be
99fd4e5da5Sopenharmony_ci    careful that iterators are not invalidated or that elements are not skipped.
100fd4e5da5Sopenharmony_ci*   For SPIR-V transforms: The module is changed, but the analyses are not
101fd4e5da5Sopenharmony_ci    updated. For example, a new instruction is added, but the def-use manager is
102fd4e5da5Sopenharmony_ci    not updated. Later on, it is possible that the def-use manager will be used,
103fd4e5da5Sopenharmony_ci    and give wrong results.
104fd4e5da5Sopenharmony_ci*   If a pass gets the id of a type from the type manager, make sure the type is
105fd4e5da5Sopenharmony_ci    not a struct or array. It there are two structs that look the same, the type
106fd4e5da5Sopenharmony_ci    manager can return the wrong one.
107fd4e5da5Sopenharmony_ci
108fd4e5da5Sopenharmony_ci## For maintainers: Merging a PR
109fd4e5da5Sopenharmony_ci
110fd4e5da5Sopenharmony_ciWe intend to maintain a linear history on the GitHub main branch, and the
111fd4e5da5Sopenharmony_cibuild and its tests should pass at each commit in that history. A linear
112fd4e5da5Sopenharmony_cialways-working history is easier to understand and to bisect in case we want to
113fd4e5da5Sopenharmony_cifind which commit introduced a bug. The
114fd4e5da5Sopenharmony_ci[Squash and Merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-commits)
115fd4e5da5Sopenharmony_cibutton on the GitHub web interface. All other ways of merging on the web
116fd4e5da5Sopenharmony_ciinterface have been disabled.
117fd4e5da5Sopenharmony_ci
118fd4e5da5Sopenharmony_ciBefore merging, we generally require:
119fd4e5da5Sopenharmony_ci
120fd4e5da5Sopenharmony_ci1.  All tests except for the smoke test pass. See
121fd4e5da5Sopenharmony_ci    [failing smoke test](#failing-smoke-test).
122fd4e5da5Sopenharmony_ci1.  The PR is approved by at least one of the maintainers. If the PR modifies
123fd4e5da5Sopenharmony_ci    different parts of the code, then multiple reviewers might be necessary.
124fd4e5da5Sopenharmony_ci
125fd4e5da5Sopenharmony_ciThe squash-and-merge button will turn green when these requirements are met.
126fd4e5da5Sopenharmony_ciMaintainers have the to power to merge even if the button is not green, but that
127fd4e5da5Sopenharmony_ciis discouraged.
128fd4e5da5Sopenharmony_ci
129fd4e5da5Sopenharmony_ci### Failing smoke test
130fd4e5da5Sopenharmony_ci
131fd4e5da5Sopenharmony_ciThe purpose of the smoke test is to let us know if
132fd4e5da5Sopenharmony_ci[shaderc](https://github.com/google/shaderc) fails to build with the change. If
133fd4e5da5Sopenharmony_ciit fails, the maintainer needs to determine if the reason for the failure is a
134fd4e5da5Sopenharmony_ciproblem in the current PR or if another repository needs to be changed. Most of
135fd4e5da5Sopenharmony_cithe time [Glslang](https://github.com/KhronosGroup/glslang) needs to be updated
136fd4e5da5Sopenharmony_cito account for the change in SPIR-V Tools.
137fd4e5da5Sopenharmony_ci
138fd4e5da5Sopenharmony_ciThe PR can still be merged if the problem is not with that PR.
139fd4e5da5Sopenharmony_ci
140fd4e5da5Sopenharmony_ci## For maintainers: Running tests
141fd4e5da5Sopenharmony_ci
142fd4e5da5Sopenharmony_ciFor security reasons, not all tests will run automatically. When they do not, a
143fd4e5da5Sopenharmony_cimaintainer will have to start the tests.
144fd4e5da5Sopenharmony_ci
145fd4e5da5Sopenharmony_ciIf the Github actions tests do not run on a PR, they can be initiated by closing
146fd4e5da5Sopenharmony_ciand reopening the PR.
147fd4e5da5Sopenharmony_ci
148fd4e5da5Sopenharmony_ciIf the kokoro tests are not run, they can be run by adding the label
149fd4e5da5Sopenharmony_ci`kokoro:run` to the PR.
150