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