1*b7893ccfSSadaf Ebrahimi# How to Contribute to Vulkan Source Repositories 2*b7893ccfSSadaf Ebrahimi 3*b7893ccfSSadaf Ebrahimi## **The Repository** 4*b7893ccfSSadaf Ebrahimi 5*b7893ccfSSadaf EbrahimiThe source code for The Vulkan-ValidationLayer components is sponsored by Khronos and LunarG. 6*b7893ccfSSadaf Ebrahimi* [Khronos Vulkan-ValidationLayers](https://github.com/KhronosGroup/Vulkan-ValidationLayers) 7*b7893ccfSSadaf Ebrahimi 8*b7893ccfSSadaf Ebrahimi 9*b7893ccfSSadaf Ebrahimi### **The Vulkan Ecosystem Needs Your Help** 10*b7893ccfSSadaf Ebrahimi 11*b7893ccfSSadaf EbrahimiThe Vulkan validation layers are one of the larger and more important components in this repository. 12*b7893ccfSSadaf EbrahimiWhile there are often active and organized development efforts underway to improve their coverage, 13*b7893ccfSSadaf Ebrahimithere are always opportunities for anyone to help by contributing additional validation layer checks 14*b7893ccfSSadaf Ebrahimiand tests for these validation checks. 15*b7893ccfSSadaf Ebrahimi 16*b7893ccfSSadaf EbrahimiThere are a couple of methods to identify areas of need: 17*b7893ccfSSadaf Ebrahimi* Examine the [issues list](https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues) 18*b7893ccfSSadaf Ebrahimiin this repository and look for issues that are of interest 19*b7893ccfSSadaf Ebrahimi* Alternatively, run the `vk_validation_stats.py` script (in the scripts directory) with the `-todo` 20*b7893ccfSSadaf Ebrahimicommand line argument to see a list of as-yet unimplemented validation checks. 21*b7893ccfSSadaf Ebrahimi* Having selected a validation check to work on, it is often efficient to implement a block of related checks 22*b7893ccfSSadaf Ebrahimiat once. Refer to the validation database output from `vk_validation_stats.py` (available in text, html, 23*b7893ccfSSadaf Ebrahimior csv format) to identify related checks that may be implemented simultaneously. 24*b7893ccfSSadaf Ebrahimi 25*b7893ccfSSadaf EbrahimiOf course, if you have your own work in mind, please open an issue to describe it and assign it to yourself. 26*b7893ccfSSadaf EbrahimiFinally, please feel free to contact any of the developers that are actively contributing should you 27*b7893ccfSSadaf Ebrahimiwish to coordinate further. 28*b7893ccfSSadaf EbrahimiPlease see the [section about Validation Layers](#special-considerations-for-validation-layers) 29*b7893ccfSSadaf Ebrahimilater on this page. 30*b7893ccfSSadaf Ebrahimi 31*b7893ccfSSadaf EbrahimiRepository Issue labels: 32*b7893ccfSSadaf Ebrahimi 33*b7893ccfSSadaf Ebrahimi* _Bug_: These issues refer to invalid or broken functionality and are the highest priority. 34*b7893ccfSSadaf Ebrahimi* _Incomplete_: These issues refer to missing validation checks that users have encountered during application 35*b7893ccfSSadaf Ebrahimidevelopment that would have been directly useful, and are high priority. 36*b7893ccfSSadaf Ebrahimi* _Enhancement_: These issues refer to ideas for extending or improving the validation layers. 37*b7893ccfSSadaf Ebrahimi* _Triaged_: These issues have been assessed and/or reviewed 38*b7893ccfSSadaf Ebrahimi 39*b7893ccfSSadaf EbrahimiIt is the maintainers goal for all issues to be assigned or triaged within one business day of their submission. If you choose 40*b7893ccfSSadaf Ebrahimito work on an issue that is assigned, simply coordinate with the current assignee. 41*b7893ccfSSadaf Ebrahimi 42*b7893ccfSSadaf Ebrahimi### **How to Submit Fixes** 43*b7893ccfSSadaf Ebrahimi 44*b7893ccfSSadaf Ebrahimi* **Ensure that the bug was not already reported or fixed** by searching on GitHub under Issues 45*b7893ccfSSadaf Ebrahimi and Pull Requests. 46*b7893ccfSSadaf Ebrahimi* Use the existing GitHub forking and pull request process. 47*b7893ccfSSadaf Ebrahimi This will involve [forking the repository](https://help.github.com/articles/fork-a-repo/), 48*b7893ccfSSadaf Ebrahimi creating a branch with your commits, and then [submitting a pull request](https://help.github.com/articles/using-pull-requests/). 49*b7893ccfSSadaf Ebrahimi* Please read and adhere to the style and process [guidelines ](#coding-conventions-and-formatting) enumerated below. 50*b7893ccfSSadaf Ebrahimi* Please base your fixes on the master branch. SDK branches are generally not updated except for critical fixes needed to repair an SDK release. 51*b7893ccfSSadaf Ebrahimi* The resulting Pull Request will be assigned to a repository maintainer. It is the maintainer's responsibility to ensure the Pull Request 52*b7893ccfSSadaf Ebrahimi passes the Google/LunarG internal CI processes. Once the Pull Request has been approved and is passing internal CI, a repository maintainer 53*b7893ccfSSadaf Ebrahimi will merge the PR. 54*b7893ccfSSadaf Ebrahimi 55*b7893ccfSSadaf Ebrahimi 56*b7893ccfSSadaf Ebrahimi#### **Coding Conventions and Formatting** 57*b7893ccfSSadaf Ebrahimi* Use the **[Google style guide](https://google.github.io/styleguide/cppguide.html)** for source code with the following exceptions: 58*b7893ccfSSadaf Ebrahimi * The column limit is 132 (as opposed to the default value 80). The clang-format tool will handle this. See below. 59*b7893ccfSSadaf Ebrahimi * The indent is 4 spaces instead of the default 2 spaces. Again, the clang-format tool will handle this. 60*b7893ccfSSadaf Ebrahimi * If you can justify a reason for violating a rule in the guidelines, then you are free to do so. Be prepared to defend your 61*b7893ccfSSadaf Ebrahimidecision during code review. This should be used responsibly. An example of a bad reason is "I don't like that rule." An example of 62*b7893ccfSSadaf Ebrahimia good reason is "This violates the style guide, but it improves type safety." 63*b7893ccfSSadaf Ebrahimi 64*b7893ccfSSadaf Ebrahimi* Run **clang-format** on your changes to maintain consistent formatting 65*b7893ccfSSadaf Ebrahimi * There are `.clang-format` files present in the repository to define clang-format settings 66*b7893ccfSSadaf Ebrahimi which are found and used automatically by clang-format. 67*b7893ccfSSadaf Ebrahimi * **clang-format** binaries are available from the LLVM orginization, here: [LLVM](https://clang.llvm.org/). Our CI system (Travis-CI) 68*b7893ccfSSadaf Ebrahimi currently uses clang-format version 5.0.0 to check that the lines of code you have changed are formatted properly. It is 69*b7893ccfSSadaf Ebrahimi recommended that you use the same version to format your code prior to submission. 70*b7893ccfSSadaf Ebrahimi * A sample git workflow may look like: 71*b7893ccfSSadaf Ebrahimi 72*b7893ccfSSadaf Ebrahimi> # Make changes to the source. 73*b7893ccfSSadaf Ebrahimi> $ git add -u . 74*b7893ccfSSadaf Ebrahimi> $ git clang-format --style=file 75*b7893ccfSSadaf Ebrahimi> # Check to see if clang-format made any changes and if they are OK. 76*b7893ccfSSadaf Ebrahimi> $ git add -u . 77*b7893ccfSSadaf Ebrahimi> $ git commit 78*b7893ccfSSadaf Ebrahimi 79*b7893ccfSSadaf Ebrahimi* **Commit Messages** 80*b7893ccfSSadaf Ebrahimi * Limit the subject line to 64 characters -- this allows the information to display correctly in git/GitHub logs 81*b7893ccfSSadaf Ebrahimi * Begin subject line with a one-word component description followed by a colon (e.g. build, docs, layers, tests, etc.) 82*b7893ccfSSadaf Ebrahimi * Separate subject from body with a blank line 83*b7893ccfSSadaf Ebrahimi * Wrap the body at 72 characters 84*b7893ccfSSadaf Ebrahimi * Capitalize the subject line 85*b7893ccfSSadaf Ebrahimi * Do not end the subject line with a period 86*b7893ccfSSadaf Ebrahimi * Use the body to explain what and why vs. how 87*b7893ccfSSadaf Ebrahimi * Use the imperative mode in the subject line. This just means to write it as a command (e.g. Fix the sprocket) 88*b7893ccfSSadaf Ebrahimi 89*b7893ccfSSadaf EbrahimiStrive for commits that implement a single or related set of functionality, using as many commits as is necessary (more is better). 90*b7893ccfSSadaf EbrahimiThat said, please ensure that the repository compiles and passes tests without error for each commit in your pull request. Note 91*b7893ccfSSadaf Ebrahimithat to be accepted into the repository, the pull request must [pass all tests](#testing your changes) on all supported platforms 92*b7893ccfSSadaf Ebrahimi-- the automatic Github Travis and AppVeyor continuous integration features will assist in enforcing this requirement. 93*b7893ccfSSadaf Ebrahimi 94*b7893ccfSSadaf Ebrahimi#### **Testing Your Changes** 95*b7893ccfSSadaf Ebrahimi* Run the existing tests in the repository before and after each of your commits to check for any regressions. 96*b7893ccfSSadaf Ebrahimi There are some tests that appear in all repositories. 97*b7893ccfSSadaf Ebrahimi These tests can be found in the following folders inside of your target build directory: 98*b7893ccfSSadaf Ebrahimi 99*b7893ccfSSadaf Ebrahimi (These instructions are for Linux) 100*b7893ccfSSadaf Ebrahimi 101*b7893ccfSSadaf Ebrahimi* In the `tests` directory, run: 102*b7893ccfSSadaf Ebrahimi 103*b7893ccfSSadaf Ebrahimi> run_all_tests.sh 104*b7893ccfSSadaf Ebrahimi 105*b7893ccfSSadaf Ebrahimi* On Windows, a quick sanity check can be run from inside Visual Studio -- just run the `vk_layer_validation_tests` project, 106*b7893ccfSSadaf Ebrahimior you can run `run_all_tests.ps1` from a PowerShell window 107*b7893ccfSSadaf Ebrahimi 108*b7893ccfSSadaf Ebrahimi* Note that some tests may fail with known issues or driver-specific problems. 109*b7893ccfSSadaf Ebrahimi The idea here is that your changes should not change the test results, unless that was the intent of your changes. 110*b7893ccfSSadaf Ebrahimi* Run tests that explicitly exercise your changes. 111*b7893ccfSSadaf Ebrahimi* Feel free to subject your code changes to other tests as well! 112*b7893ccfSSadaf Ebrahimi 113*b7893ccfSSadaf Ebrahimi#### **GitHub Cloud CI Testing** 114*b7893ccfSSadaf EbrahimiPull Requests to GitHub are tested in the cloud on Linux and Windows VMs. The Linux VMs use [Travis CI](https://travis-ci.org/KhronosGroup/Vulkan-ValidationLayers) with the sequence of commands driven by the [.travis.yml](https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/.travis.yml) file. The Windows VMs use [AppVeyor](https://ci.appveyor.com/project/Khronoswebmaster/vulkan-validationlayers/branch/master) with the sequence of commands driven by the [.appveyor.yml](https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/.appveyor.yml) file. 115*b7893ccfSSadaf Ebrahimi 116*b7893ccfSSadaf EbrahimiThe Linux testing includes iterating on all of the validation layer tests over multiple [different device](https://github.com/KhronosGroup/Vulkan-ValidationLayers/tree/master/tests/device_profiles) profiles using the [devsim layer](https://github.com/LunarG/VulkanTools/tree/master/layersvt) in combination with the [mock icd](https://github.com/KhronosGroup/Vulkan-Tools/tree/master/icd). This is a fast way to simulate testing across different devices. Any new tests must pass across all device profiles. 117*b7893ccfSSadaf Ebrahimi 118*b7893ccfSSadaf Ebrahimi#### **Special Considerations for Validation Layers** 119*b7893ccfSSadaf Ebrahimi* **Validation Tests:** If you are submitting a change that adds a new validation check, you should also construct a "negative" test function. 120*b7893ccfSSadaf EbrahimiThe negative test function purposely violates the validation rule that the new validation check is looking for. 121*b7893ccfSSadaf EbrahimiThe test should cause your new validation check to identify the violation and issue a validation error report. 122*b7893ccfSSadaf EbrahimiAnd finally, the test should check that the validation error report is generated and consider the test as "passing" 123*b7893ccfSSadaf Ebrahimiif the report is received. Otherwise, the test should indicate "failure". 124*b7893ccfSSadaf EbrahimiThis new test should be added to the validation layer test program in the `tests` directory and contributed 125*b7893ccfSSadaf Ebrahimiat the same time as the new validation check itself. There are many existing validation tests in this directory that can be 126*b7893ccfSSadaf Ebrahimiused as a starting point. 127*b7893ccfSSadaf Ebrahimi* **Validation Checks:** Validation checks are carried out by the Khronos Validation layer. The CoreChecks validation object 128*b7893ccfSSadaf Ebrahimicontains checks that require significant amounts of application state to carry out. In contrast, the stateless validation object contains 129*b7893ccfSSadaf Ebrahimichecks that require (mostly) no state at all. Please inquire if you are unsure of the location for your contribution. The other 130*b7893ccfSSadaf Ebrahimivalidation objects (thread_safety, object lifetimes) are more special-purpose and are mostly code-generated from the specification. 131*b7893ccfSSadaf Ebrahimi* **Validation Error/Warning Messages:** Strive to give specific information describing the particulars of the failure, including 132*b7893ccfSSadaf Ebrahimioutput all of the applicable Vulkan Objects and related values. Also, ensure that when messages can give suggestions about _how_ to 133*b7893ccfSSadaf Ebrahimifix the problem, they should do so to better assist the user. 134*b7893ccfSSadaf Ebrahimi* **Validation Statistics:** The `vk_validation_stats.py` script (in the scripts directory) inspects the layer and test source files 135*b7893ccfSSadaf Ebrahimiand reports a variety of statistics on validation completeness and correctness. Before submitting a change you should run this 136*b7893ccfSSadaf Ebrahimiscript with the consistency check (`-c`) argument to ensure that your changes have not introduced any inconsistencies in the code. 137*b7893ccfSSadaf Ebrahimi* **Generated Source Code:** The `layers/generated` directory contains source code that is created by several 138*b7893ccfSSadaf Ebrahimigenerator scripts in the `scripts` directory. All changes to these scripts _must_ be submitted with the 139*b7893ccfSSadaf Ebrahimicorresponding generated output to keep the repository self-consistent. This requirement is enforced by both 140*b7893ccfSSadaf EbrahimiTravis CI and AppVeyor test configurations. Regenerate source files after modifying any of the generator 141*b7893ccfSSadaf Ebrahimiscripts and before building and testing your changes. More details can be found in 142*b7893ccfSSadaf Ebrahimi[BUILD.md](https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/BUILD.md#generated-source-code). 143*b7893ccfSSadaf Ebrahimi 144*b7893ccfSSadaf Ebrahimi#### Coding Conventions for [CMake](http://cmake.org) files 145*b7893ccfSSadaf Ebrahimi 146*b7893ccfSSadaf Ebrahimi* When editing configuration files for CMake, follow the style conventions of the surrounding code. 147*b7893ccfSSadaf Ebrahimi * The column limit is 132. 148*b7893ccfSSadaf Ebrahimi * The indent is 4 spaces. 149*b7893ccfSSadaf Ebrahimi * CMake functions are lower-case. 150*b7893ccfSSadaf Ebrahimi * Variable and keyword names are upper-case. 151*b7893ccfSSadaf Ebrahimi* The format is defined by 152*b7893ccfSSadaf Ebrahimi [cmake-format](https://github.com/cheshirekow/cmake_format) 153*b7893ccfSSadaf Ebrahimi using the `.cmake-format.py` file in the repository to define the settings. 154*b7893ccfSSadaf Ebrahimi See the cmake-format page for information about its simple markup for comments. 155*b7893ccfSSadaf Ebrahimi* Disable reformatting of a block of comment lines by inserting 156*b7893ccfSSadaf Ebrahimi a `# ~~~` comment line before and after that block. 157*b7893ccfSSadaf Ebrahimi* Disable any formatting of a block of lines by surrounding that block with 158*b7893ccfSSadaf Ebrahimi `# cmake-format: off` and `# cmake-format: on` comment lines. 159*b7893ccfSSadaf Ebrahimi* To install: `sudo pip install cmake_format` 160*b7893ccfSSadaf Ebrahimi* To run: `cmake-format --in-place $FILENAME` 161*b7893ccfSSadaf Ebrahimi* **IMPORTANT (June 2018)** cmake-format v0.3.6 has a 162*b7893ccfSSadaf Ebrahimi [bug]( https://github.com/cheshirekow/cmake_format/issues/50) 163*b7893ccfSSadaf Ebrahimi that can corrupt the formatting of comment lines in CMake files. 164*b7893ccfSSadaf Ebrahimi A workaround is to use the following command _before_ running cmake-format: 165*b7893ccfSSadaf Ebrahimi `sed --in-place='' 's/^ *#/#/' $FILENAME` 166*b7893ccfSSadaf Ebrahimi 167*b7893ccfSSadaf Ebrahimi### **Contributor License Agreement (CLA)** 168*b7893ccfSSadaf Ebrahimi 169*b7893ccfSSadaf EbrahimiYou will be prompted with a one-time "click-through" CLA dialog as part of submitting your pull request 170*b7893ccfSSadaf Ebrahimior other contribution to GitHub. 171*b7893ccfSSadaf Ebrahimi 172*b7893ccfSSadaf Ebrahimi### **License and Copyrights** 173*b7893ccfSSadaf Ebrahimi 174*b7893ccfSSadaf EbrahimiAll contributions made to the Vulkan-ValidationLayers repository are Khronos branded and as such, 175*b7893ccfSSadaf Ebrahimiany new files need to have the Khronos license (Apache 2.0 style) and copyright included. 176*b7893ccfSSadaf EbrahimiPlease see an existing file in this repository for an example. 177*b7893ccfSSadaf Ebrahimi 178*b7893ccfSSadaf EbrahimiAll contributions made to the LunarG repositories are to be made under the Apache 2.0 license 179*b7893ccfSSadaf Ebrahimiand any new files need to include this license and any applicable copyrights. 180*b7893ccfSSadaf Ebrahimi 181*b7893ccfSSadaf EbrahimiYou can include your individual copyright after any existing copyrights. 182