Code Monkey home page Code Monkey logo

nas-sample's Introduction

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

  • Windows or Linux
  • CMake 3.12
  • C++ 17

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:

  • -dx12 for D3D12 (default)
  • -vk for Vulkan

License

Donut Examples are licensed under the MIT License.

nas-sample's People

Contributors

jukim-nv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.