Skip to content

Commit

Permalink
v1.1.0 (#10)
Browse files Browse the repository at this point in the history
* 1.1.0 code changes

* Update submodules
  • Loading branch information
fstrugar-nv authored Jun 20, 2023
1 parent 397dfce commit a0da071
Show file tree
Hide file tree
Showing 109 changed files with 5,513 additions and 2,931 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bin/
build*/
.vs
nvapi/
/external/NVAPI
nrd.cfg
omm.cfg
media/
Expand Down
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build-debug-job:

stage: build
script:
- ./update_dependencies.bat
- mkdir build_debug
- cd build_debug
- cmake .. -DCMAKE_BUILD_TYPE=Debug
Expand All @@ -24,6 +25,7 @@ build-release-job:

stage: build
script:
- ./update_dependencies.bat
- mkdir build_release
- cd build_release
- cmake .. -DCMAKE_BUILD_TYPE=Release
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
path = external/RTXDI
url = https://github.com/NVIDIAGameWorks/RTXDI.git
branch = sdk-only
[submodule "external/Streamline"]
path = external/Streamline
url = https://github.com/NVIDIAGameWorks/Streamline.git
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

option(STREAMLINE_INTEGRATION "Enable Streamline integration (Required for DLSS3.0 and etc.)" FALSE)
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/external/NVAPI" OR NOT EXISTS "${CMAKE_SOURCE_DIR}/media")
message(FATAL_ERROR "${CMAKE_SOURCE_DIR}/external/NVAPI and/or ${CMAKE_SOURCE_DIR}/media folders not present: \n!!!! please run update_dependencies.bat first !!!! ")
endif()

option(STREAMLINE_INTEGRATION "Enable Streamline integration (Required for DLSS3.0 and etc.)" ON)

option(NVRHI_WITH_NVAPI "Include NVAPI support (requires NVAPI SDK)" ON)
set(NVAPI_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/nvapi/" CACHE STRING "Path to NVAPI include headers/shaders" )
set(NVAPI_LIBRARY "${CMAKE_SOURCE_DIR}/external/nvapi/amd64/nvapi64.lib" CACHE STRING "Path to NVAPI .lib file")

set(DXC_CUSTOM_PATH "${CMAKE_SOURCE_DIR}/external/dxc/bin/x64/" CACHE STRING "Path to embedded dxc")
set(DXC_PATH "${DXC_CUSTOM_PATH}/dxc.exe" CACHE STRING "Path to embedded dxc file for DX12")
set(DXC_DXIL_EXECUTABLE "${DXC_CUSTOM_PATH}/dxc.exe" CACHE STRING "Path to embedded dxc file for DX12")
#set(DXC_SPIRV_EXECUTABLE "${DXC_CUSTOM_PATH}/dxc.exe" CACHE STRING "Path to embedded dxc file for SPIRV") # default to using dxc from the Vulkan SDK; remove this to use embedded .dxc

if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_ITERATOR_DEBUG_LEVEL=1")
endif()

set(DXC_DXIL_EXECUTABLE "${CMAKE_SOURCE_DIR}/external/dxc/bin/x64/dxc.exe" CACHE STRING "DXC shader compiler path")

# option(USE_RAY_TRACING_DENOISER "Include NRD as part of the sample." ON)
option(DONUT_WITH_ASSIMP "" OFF)

Expand Down
49 changes: 35 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Path Tracing SDK v1.0.0
# Path Tracing SDK v1.1.0

![Title](./images/r-title.png)


## Overview

Path Tracing SDK is a code sample that strives to embody years of ray tracing and neural graphics research and experience. It is intended as a starting point for a path tracer integration, as a reference for various integrated SDKs, and/or for learning and experimentation.

The base path tracing implementation derives from NVIDIA’s [Falcor Research Path Tracer](https://github.com/NVIDIAGameWorks/Falcor), ported to approachable C++/HLSL [Donut framework](https://github.com/NVIDIAGameWorks/donut).

GTC presentation [How to Build a Real-time Path Tracer](https://www.nvidia.com/gtc/session-catalog/?tab.catalogallsessionstab=16566177511100015Kus&search.industry=option_1559593201839#/session/1666651593475001NN25) provides a high level introduction to most of the features.


## Features

* DirectX 12 and Vulkan back-ends
Expand All @@ -23,12 +27,8 @@ The base path tracing implementation derives from NVIDIA’s [Falcor Research Pa
* [NRD](https://github.com/NVIDIAGameWorks/RayTracingDenoiser) ReLAX and ReBLUR denoiser integration with up to 3-layer path space decomposition (Stable Planes)
* Reference mode 'photo-mode screenshot' with basic [OptiX denoiser](https://developer.nvidia.com/optix-denoiser) integration
* Basic TAA, tone mapping, etc.
* Streamline + DLSS integration (coming very soon)
* Streamline + DLSS integration

## Known Issues

* DLSS is currently not enabled due to upgrade to Streamline 2.0; integration is work in progress
* SER support on Vulkan is currently work in progress

## Requirements

Expand All @@ -37,7 +37,15 @@ The base path tracing implementation derives from NVIDIA’s [Falcor Research Pa
- GeForce Game Ready Driver 531.18 or newer
- DirectX 12 or Vulkan API
- DirectX Raytracing 1.1 API, or higher
- Visual Studio 2019 or later
- Visual Studio 2019 or later with Windows 10 SDK version 10.0.20348.0 or later


## Known Issues

* Enabling Vulkan support requires a couple of manual steps, see [below](#building-vulkan)
* SER support on Vulkan is currently work in progress
* Using SER with DLSS3 Frame Generation is known to cause crashes in certain conditions. We are working on a driver update to address this.
* Running Vulkan on AMD GPUs may trigger a TDR during TLAS building in scenes with null TLAS instances.

## Folder Structure

Expand All @@ -62,7 +70,7 @@ At the moment, only Windows builds are supported. We are going to add Linux supp

`git clone --recursive https://github.com/NVIDIAGameWorks/Path-Tracing-SDK.git`

2. Pull the media files from Packman:
2. Pull the media and other non-git-hosted files:

```
cd Path-Tracing-SDK
Expand Down Expand Up @@ -90,31 +98,44 @@ At the moment, only Windows builds are supported. We are going to add Linux supp

If making a binary build, the `media` and `tools` folders can be placed into `bin` and packed up together (i.e. the sample app will search for both `media\` and `..\media\`).

## User Interface

## Building Vulkan

Due to interaction with various included libraries, Vulkan support is not enabled by default and needs a couple of additional tweaks on the user side; please find the recommended steps below:
* Install Vulkan SDK (we tested with 1.3.246.1 but others will work)
* Set DONUT_WITH_VULKAN and NVRHI_WITH_VULKAN CMake variables to ON
* Disable STREAMLINE_INTEGRATION (set CMake variable to OFF)
* Clear CMake cache (if applicable) to make sure the correct dxc.exe path (from Vulkan SDK) is set for SPIRV compilation


## User Interface

Once the application is running, most of the SDK features can be accessed via the UI window on the left hand side and drop-down controls in the top-center.

![UI](./images/r-ui.png)

Camera can be moved using W/S/A/D keys and rotated by dragging with the left mouse cursor.


## Command Line

- `-scene` loads a specific .scene.json file; example: `-scene programmer-art.scene.json`
- `-width` and `-height` to set the window size; example: `-width 3840 -height 2160 -fullscreen`
- `-fullscreen` to start in full screen mode; example: `-width 3840 -height 2160 -fullscreen`
- `-adapter` to run on a specific GPU in multi GPU environments using a substring match; example: `-adapter A3000` will select an adapter with the full name `NVIDIA RTX A3000 Laptop GPU`
- `-debug` to enable the graphics API debug layer or runtime, and the [NVRHI](https://github.com/NVIDIAGameWorks/nvrhi) validation layer.
- `-fullscreen` to start in full screen mode.
- `-no-vsync` to start without VSync (can be toggled in the GUI).
- `-print-graph` to print the scene graph into the output log on startup.
- `-width` and `-height` to set the window size.
- `<FileName>` to load any supported model or scene from the given file.


## Developer Documentation

We are working on more detailed SDK developer documentation - watch this space!


## Contact

Path Tracing SDK is under active development. Please report any issues directly through GitHub issue tracker, and for any information, suggestions or general requests please feel free to contact us at [email protected]!


## License

See [LICENSE.txt](LICENSE.txt)
15 changes: 7 additions & 8 deletions donut/compileshaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

function(donut_compile_shaders)
set(options "")
set(oneValueArgs TARGET CONFIG FOLDER DXIL DXBC SPIRV_DXC CFLAGS INCLUDE)
set(multiValueArgs SOURCES)
set(oneValueArgs TARGET CONFIG FOLDER DXIL DXBC SPIRV_DXC CFLAGS)
set(multiValueArgs SOURCES INCLUDE)
cmake_parse_arguments(params "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (NOT params_TARGET)
Expand All @@ -48,11 +48,10 @@ function(donut_compile_shaders)
DEPENDS shaderCompiler
SOURCES ${params_SOURCES})

if (NOT params_INCLUDE)
set(INCLUDE_PATH "")
else()
set(INCLUDE_PATH -I ${params_INCLUDE})
endif()
set(INCLUDE_PATH "")
foreach(path ${params_INCLUDE})
list(APPEND INCLUDE_PATH -I ${path})
endforeach()

if (params_DXIL AND (DONUT_WITH_DX12 AND DONUT_USE_DXIL_ON_DX12))
if (NOT DXC_DXIL_EXECUTABLE)
Expand All @@ -73,7 +72,7 @@ function(donut_compile_shaders)
--platform dxil
--cflags "${CFLAGS}"
-I ${DONUT_SHADER_INCLUDE_DIR}
${INCLUDE_PATH}
${INCLUDE_PATH}
--compiler ${DXC_DXIL_EXECUTABLE})
endif()

Expand Down
7 changes: 7 additions & 0 deletions donut/donut-app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ file(GLOB donut_app_vr_src
src/app/vr/*.cpp
)



add_library(donut_app STATIC EXCLUDE_FROM_ALL ${donut_app_src})
target_include_directories(donut_app PUBLIC include)
target_link_libraries(donut_app donut_core donut_engine glfw imgui)

if(STREAMLINE_INTEGRATION)
target_include_directories(donut_app PUBLIC ${CMAKE_SOURCE_DIR}/external/Streamline/include)
target_compile_definitions(donut_app PUBLIC STREAMLINE_INTEGRATION)
endif()

if(DONUT_WITH_DX11)
target_sources(donut_app PRIVATE src/app/dx11/DeviceManager_DX11.cpp)
target_compile_definitions(donut_app PUBLIC USE_DX11=1)
Expand Down
12 changes: 6 additions & 6 deletions donut/include/donut/shaders/material_cb.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ struct MaterialConstants
float occlusionStrength;
float alphaCutoff;
float transmissionFactor;
int baseOrDiffuseTextureIndex;
uint baseOrDiffuseTextureIndex;

int metalRoughOrSpecularTextureIndex;
int emissiveTextureIndex;
int normalTextureIndex;
int occlusionTextureIndex;
uint metalRoughOrSpecularTextureIndex;
uint emissiveTextureIndex;
uint normalTextureIndex;
uint occlusionTextureIndex;

int transmissionTextureIndex;
uint transmissionTextureIndex;
float ior;
float thicknessFactor;
float diffuseTransmissionFactor;
Expand Down
23 changes: 0 additions & 23 deletions donut/include/donut/shaders/utils.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,6 @@ float interpolateSphericalHarmonics(float4 sh, float3 normalizedDirection)
return 0.5 * (dot(sh.xyz, normalizedDirection) + sh.w);
}

// Smart bent normal for ray tracing
// See appendix A.3 in https://arxiv.org/pdf/1705.01263.pdf
float3 getBentNormal(float3 geometryNormal, float3 shadingNormal, float3 viewDirection)
{
// Flip the normal in case we're looking at the geometry from its back side
if (dot(geometryNormal, viewDirection) > 0)
{
geometryNormal = -geometryNormal;
shadingNormal = -shadingNormal;
}

// Specular reflection in shading normal
float3 R = reflect(viewDirection, shadingNormal);
float a = dot(geometryNormal, R);
if (a < 0) // Perturb normal
{
float b = max(0.001, dot(shadingNormal, geometryNormal));
return normalize(-viewDirection + normalize(R - shadingNormal * a / b));
}

return shadingNormal;
}

float3 computeRayIntersectionBarycentrics(float3 vertices[3], float3 rayOrigin, float3 rayDirection)
{
float3 edge1 = vertices[1] - vertices[0];
Expand Down
5 changes: 4 additions & 1 deletion donut/shaders/passes/mipmapgen_cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ groupshared VALUE_TYPE s_ReductionData[GROUP_SIZE][GROUP_SIZE];
uint2 globalIdx : SV_DispatchThreadID,
uint2 threadIdx : SV_GroupThreadID)
{
VALUE_TYPE value = t_input.mips[0][globalIdx.xy];
uint tWidth, tHeight;
t_input.GetDimensions(tWidth, tHeight);

VALUE_TYPE value = t_input.mips[0][min(globalIdx.xy, uint2(tWidth-1, tHeight-1))];

#if MODE == MODE_MINMAX
if (g_MipMapGen.dispatch==0)
Expand Down
10 changes: 10 additions & 0 deletions donut/src/app/dx12/DeviceManager_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ freely, subject to the following restrictions:

#include <sstream>

#ifdef STREAMLINE_INTEGRATION
#include "../../../../pt_sdk/Streamline/SLWrapper.h"
#endif

using nvrhi::RefCountPtr;

using namespace donut::app;
Expand Down Expand Up @@ -345,6 +349,12 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
IID_PPV_ARGS(&m_Device12));
HR_RETURN(hr)

#ifdef STREAMLINE_INTEGRATION
void* nativeDeviceHandle = NULL;
SLWrapper::Get().ProxyToNative(m_Device12, (void**)&nativeDeviceHandle);
SLWrapper::Get().SetDevice_raw(nativeDeviceHandle);
#endif

if (m_DeviceParams.enableDebugRuntime)
{
RefCountPtr<ID3D12InfoQueue> pInfoQueue;
Expand Down
2 changes: 1 addition & 1 deletion donut/src/app/vulkan/DeviceManager_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ bool DeviceManager_VK::createInstance()
auto layerVec = stringSetToVector(enabledExtensions.layers);

auto applicationInfo = vk::ApplicationInfo()
.setApiVersion(VK_MAKE_VERSION(1, 2, 0));
.setApiVersion(VK_MAKE_VERSION(1, 3, 0));

// create the vulkan instance
vk::InstanceCreateInfo info = vk::InstanceCreateInfo()
Expand Down
35 changes: 27 additions & 8 deletions donut/src/engine/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,28 @@ using namespace donut::math;

namespace donut::engine
{
static int GetBindlessTextureIndex(const std::shared_ptr<LoadedTexture>& texture)
static void GetBindlessTextureIndex(const std::shared_ptr<LoadedTexture>& texture, uint & outEncodedInfo, unsigned int & flags, unsigned int textureBit)
{
return texture ? texture->bindlessDescriptor.Get() : -1;
// if bit not set, don't set the texture; if texture unavailable - remove the texture bit!
if ((flags & textureBit) == 0 || texture==nullptr || texture->texture==nullptr)
{
outEncodedInfo = 0xFFFFFFFF;
flags &= ~textureBit; // remove flag
return;
}

uint bindlessDescIndex = texture->bindlessDescriptor.Get();
assert( bindlessDescIndex <= 0xFFFF );
bindlessDescIndex &= 0xFFFF;

const auto desc = texture->texture->getDesc();
float baseLODf = donut::math::log2f((float)desc.width * desc.height);
uint baseLOD = (uint)(baseLODf+0.5f);
uint mipLevels = desc.mipLevels;
assert( baseLOD >= 0 && baseLOD <= 255 );
assert( mipLevels >= 0 && mipLevels <= 255 );

outEncodedInfo = (baseLOD << 24) | (mipLevels << 16) | bindlessDescIndex;
}

void Material::FillConstantBuffer(MaterialConstants& constants) const
Expand Down Expand Up @@ -125,12 +144,12 @@ namespace donut::engine

// bindless textures

constants.baseOrDiffuseTextureIndex = GetBindlessTextureIndex(baseOrDiffuseTexture);
constants.metalRoughOrSpecularTextureIndex = GetBindlessTextureIndex(metalRoughOrSpecularTexture);
constants.normalTextureIndex = GetBindlessTextureIndex(normalTexture);
constants.emissiveTextureIndex = GetBindlessTextureIndex(emissiveTexture);
constants.occlusionTextureIndex = GetBindlessTextureIndex(occlusionTexture);
constants.transmissionTextureIndex = GetBindlessTextureIndex(transmissionTexture);
GetBindlessTextureIndex(baseOrDiffuseTexture, constants.baseOrDiffuseTextureIndex, constants.flags, MaterialFlags_UseBaseOrDiffuseTexture );
GetBindlessTextureIndex(metalRoughOrSpecularTexture, constants.metalRoughOrSpecularTextureIndex, constants.flags, MaterialFlags_UseMetalRoughOrSpecularTexture );
GetBindlessTextureIndex(emissiveTexture, constants.emissiveTextureIndex, constants.flags, MaterialFlags_UseEmissiveTexture );
GetBindlessTextureIndex(normalTexture, constants.normalTextureIndex, constants.flags, MaterialFlags_UseNormalTexture );
GetBindlessTextureIndex(occlusionTexture, constants.occlusionTextureIndex, constants.flags, MaterialFlags_UseOcclusionTexture );
GetBindlessTextureIndex(transmissionTexture, constants.transmissionTextureIndex, constants.flags, MaterialFlags_UseTransmissionTexture );

constants.flags |= (uint)(min(nestedPriority, kMaterialMaxNestedPriority)) << MaterialFlags_NestedPriorityShift;
constants.flags |= (uint)(clamp(psdDominantDeltaLobe+1, 0, 7)) << MaterialFlags_PSDDominantDeltaLobeP1Shift;
Expand Down
2 changes: 1 addition & 1 deletion donut/src/render/MipMapGenPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ MipMapGenPass::MipMapGenPass(
constantBufferDesc.isConstantBuffer = true;
constantBufferDesc.isVolatile = true;
constantBufferDesc.debugName = "MipMapGenPass/Constants";
constantBufferDesc.maxVersions = c_MaxRenderPassConstantBufferVersions;
constantBufferDesc.maxVersions = donut::engine::c_MaxRenderPassConstantBufferVersions;
m_ConstantBuffer = m_Device->createBuffer(constantBufferDesc);

// BindingLayout
Expand Down
7 changes: 6 additions & 1 deletion donut/thirdparty/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ set(imgui_srcs
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imstb_rectpack.h
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imstb_textedit.h
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imstb_truetype.h
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_demo.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_demo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imnodes/ImNodes.h
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imnodes/ImNodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imnodes/ImNodesEz.h
${CMAKE_CURRENT_SOURCE_DIR}/imgui/imnodes/ImNodesEz.cpp)

add_library(imgui STATIC ${imgui_srcs})
target_include_directories(imgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
target_include_directories(imgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imnodes)
Loading

0 comments on commit a0da071

Please sign in to comment.