Home

Awesome

NVIDIA Variable-Rate Shading (VRS) and NVIDIA Adaptive Shading (NAS) Samples

Sample Contents

This repository contains two samples. The Variable-Rate Shading (VRS) sample shows how to use the D3D12 API to enable the feature as well as a simple example shader for initializing the shading rate surface. The NVIDIA Adaptive Shading (NAS) sample implements the fully-featured NAS algorithm described in the paper "Visually Lossless Content and Motion Adaptive Shading in Games" by Yang et al.

VRS Sample

located in `donut_examples/examples/variable_shading

This sample intends to show the necessary steps to enable VRS in a D3D12 application. All D3D12-specific code is in variable_shading.cpp. Within the file, the VRS-specific runtime calls are marked are located in the code section under the comment // VRS-specific code starts here. The compute shader used to fill the shading rate surface is written in shaders.hlsl. This shader averages the color in the VRS tile and outputs a 4x4 shading rate if the green channel is bigger than the red channel, or 1x1 rate otherwise. This calcuation is not an intelligent algorithm of any kind and is only used to put some kind of variable data into the shading rate surface. The sample also supports VRS via a more abstract rendering framework (NVRHI), which is more similar to the design used by most game engines. This abstraction layer supports both D3D12 and Vulkan. There is no "raw API" sample path for Vulkan, due to the API requiring that VRS state be attached to framebuffers, renderpasses, and graphics pipeline state, all of which are not currently accessible through the NVRHI abstraction layer. To learn more about how to use the Vulkan VRS API, we recommend looking at the Vulkan backend of NVRHI.

NAS Sample

located in adaptive_shading

This sample implements the algorithm described in the "Visually Lossless Content and Motion Adaptive Shading in Games" paper by Yang et al. Inside the AdaptiveShading.cpp file, NAS-specific initialization and runtime calls are located under the comment // NAS-related functions begin here. Those functions are then called from the main loop to compute and apply the NAS algorithm. Most of the algorithm itself is located in shader files. ComputeNASData.hlsl computes a partial derivative-based luminance error for a pixel tile. Then, ComputeShadingRate.hlsl uses that error along with the additional motion-adaptive terms to compute the minimum acceptable shading rate for the tile. Finally, SmoothShadingRate.hlsl fills in sharp transitions between high and low shading rates with intermediate rate values for a smoother boundary. This output is the VRS surface which will set the shading rates for subsequent draw calls.

Requirements

Build

  1. Clone a source tree with all sub-module dependencies:

    git clone --recursive <insert URL>
    
  2. Create a build folder

    • any name works, but git is configured to ignore folders named 'build'
    • this folder should be placed under directory created by 'git clone' in step #1
  3. Use CMake to configure the build and generate the project files.

    • Linux: cmake ..
    • Windows: use of CMake GUI is recommended. Make sure to select the x64 platform for the generator.
  4. Build the solution generated by CMake in the build folder.

    • Linux: make -j8 (example for an 8-core CPU)
    • Windows: Open the generated solution with Visual Studio and build it.
  5. Run the examples. They should be built in the bin folder.

Command Line

Both the VRS and NAS samples support D3D12 and Vulkan on Windows. They are built with all APIs supported in the same executable, and the API can be switched from the command line. Use these command line arguments:

License

Donut Examples are licensed under the MIT License.