Skip to content

Commit

Permalink
v3.1.0:
Browse files Browse the repository at this point in the history
- NRD: refactoring of Reflection & Delta MV methods
- NRD: reduced code entropy in .resources files
- NRD: added ability to control normal encoding via Cmake
- NRD: fixes for SLANG
- REBLUR: improved error compensation in areas with low specular reprojection confidence
- REBLUR: moved anti-firefly filter to work better with signals with high energy fireflies
- REBLUR: removed IsInScreen2x2
- REBLUR: introduced always-active firefly suppressor
- REBLUR: improved roughness weight in temporal reprojection
- REBLUR: disabled specular-related code for diffuse-only denoisers
- REBLUR: reference mode doesn't change parameters under the hood
- REFLECTION_MV: fixed number of constants
- NRD INTEGRATION: added mode without descriptors caching
- CMAKE: refactoring
- updated UPDATE.md
  • Loading branch information
dzhdanNV committed Mar 25, 2022
1 parent a793238 commit d10b533
Show file tree
Hide file tree
Showing 298 changed files with 4,569 additions and 3,892 deletions.
5 changes: 2 additions & 3 deletions 3-Prepare NRD SDK.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ if /I "%M%" neq "y" goto END

mkdir "Shaders"

xcopy "..\%NRD_DIR%\Source\Shaders\" "Shaders" /s
copy "..\%NRD_DIR%\External\MathLib\*.hlsli" "Shaders\Include"
copy "..\%NRD_DIR%\Include\*.hlsli" "Shaders\Include"
xcopy "..\%NRD_DIR%\Shaders\" "Shaders" /s
copy "..\%NRD_DIR%\External\MathLib\*.hlsli" "Shaders\Source"

:END

Expand Down
5 changes: 2 additions & 3 deletions 3-Prepare NRD SDK.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ if [[ $REPLY =~ ^[Yy]$ ]]
then
mkdir -p "Shaders"

cp -r ../$NRD_DIR/Source/Shaders/ "Shaders"
cp ../$NRD_DIR/External/MathLib/*.hlsli "Shaders"
cp ../$NRD_DIR/Include/*.hlsli "Shaders"
cp -r ../$NRD_DIR/Shaders/ "Shaders"
cp ../$NRD_DIR/External/MathLib/*.hlsli "Shaders\Source"
fi

cd ..
23 changes: 12 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ message("Processing 'NRD'...")

set(NRD_DXC_CUSTOM_PATH "custom/path/to/dxc" CACHE STRING "This DXC will be used if Vulkan SDK is not installed")
set(NRD_SHADER_OUTPUT_PATH "" CACHE STRING "Shader output path override")
set(NRD_USE_OCT_NORMAL_ENCODING "0" CACHE STRING "NRD_USE_OCT_NORMAL_ENCODING")
set(NRD_USE_MATERIAL_ID "0" CACHE STRING "NRD_USE_MATERIAL_ID")

# Settings
option(NRD_DISABLE_INTERPROCEDURAL_OPTIMIZATION "disable interprocedural optimization" OFF)
option(NRD_DISABLE_SHADER_COMPILATION "disable compilation of shaders" OFF)
option(NRD_USE_PRECOMPILED_SHADERS "use precompiled shaders" ON)
option(NRD_STATIC_LIBRARY "build static lib" OFF)
option(NRD_CROSSCOMPILE_AARCH64 "cross compilation for aarch64" OFF)
option(NRD_CROSSCOMPILE_X86_64 "cross compilation for x86_64" OFF)
option(NRD_DISABLE_INTERPROCEDURAL_OPTIMIZATION "Disable interprocedural optimization" OFF)
option(NRD_DISABLE_SHADER_COMPILATION "Disable compilation of shaders" OFF)
option(NRD_USE_PRECOMPILED_SHADERS "Use precompiled shaders" ON)
option(NRD_STATIC_LIBRARY "Build static lib" OFF)
option(NRD_CROSSCOMPILE_AARCH64 "Cross compilation for aarch64" OFF)
option(NRD_CROSSCOMPILE_X86_64 "Cross compilation for x86_64" OFF)

file(READ "${CMAKE_CURRENT_SOURCE_DIR}/Include/NRD.h" ver_h)
string(REGEX MATCH "NRD_VERSION_MAJOR ([0-9]*)" _ ${ver_h})
Expand Down Expand Up @@ -51,17 +53,16 @@ if ("${NRD_SHADER_OUTPUT_PATH}" STREQUAL "")
set(NRD_SHADER_OUTPUT_PATH "${PROJECT_BINARY_DIR}/Shaders")
endif()
message(STATUS "NRD shaders output path: '${NRD_SHADER_OUTPUT_PATH}'")
message(STATUS "NRD.hlsli definitions: NRD_USE_OCT_NORMAL_ENCODING = ${NRD_USE_OCT_NORMAL_ENCODING}; NRD_USE_MATERIAL_ID = ${NRD_USE_MATERIAL_ID}")

if (NOT NRD_DISABLE_SHADER_COMPILATION)
# include path for DXC and FXC (used in ShaderCompilation.cmake)
set(NRD_SHADER_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Source/Shaders")
set(NRD_HEADER_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Include")
# Non-NRD include paths
set(NRD_MATHLIB_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/External/MathLib")

# list HLSL shaders and headers
file(GLOB_RECURSE NRD_HLSL_FILES "Source/Shaders/*.hlsl" "Source/Shaders/*.hlsli")
file(GLOB_RECURSE NRD_HLSL_MATHLIB_HEADER_FILES "${NRD_MATHLIB_INCLUDE_PATH}/*.hlsli")
file(GLOB_RECURSE NRD_HLSL_INCLUDE "Include/*.hlsli")
file(GLOB_RECURSE NRD_HLSL_INCLUDE "Shaders/*.hlsli" )
file(GLOB_RECURSE NRD_HLSL_FILES "Shaders/*.hlsl")

file(MAKE_DIRECTORY ${NRD_SHADER_OUTPUT_PATH})
include(ShaderCompilation.cmake)
Expand Down
2 changes: 1 addition & 1 deletion External/MathLib
Submodule MathLib updated 1 files
+1 −1 External/sse2neon
4 changes: 2 additions & 2 deletions Include/NRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <cstddef>

#define NRD_VERSION_MAJOR 3
#define NRD_VERSION_MINOR 0
#define NRD_VERSION_MINOR 1
#define NRD_VERSION_BUILD 0
#define NRD_VERSION_DATE "21 March 2022"
#define NRD_VERSION_DATE "25 March 2022"

#if defined(_MSC_VER)
#define NRD_CALL __fastcall
Expand Down
50 changes: 24 additions & 26 deletions Include/NRDDescs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once

#define NRD_DESCS_VERSION_MAJOR 3
#define NRD_DESCS_VERSION_MINOR 0
#define NRD_DESCS_VERSION_MINOR 1

static_assert (NRD_VERSION_MAJOR == NRD_DESCS_VERSION_MAJOR && NRD_VERSION_MINOR == NRD_DESCS_VERSION_MINOR, "Please, update all NRD SDK files");

Expand Down Expand Up @@ -108,12 +108,12 @@ namespace nrd
// =============================================================================================================================

// INPUTS - IN_MV, IN_NORMAL_ROUGHNESS, IN_VIEWZ, IN_SPEC_HITDIST
// OUTPUTS - OUT_SPEC_REFLECTION_MV
SPEC_REFLECTION_MV,
// OUTPUTS - OUT_REFLECTION_MV
SPECULAR_REFLECTION_MV,

// INPUTS - IN_MV, IN_DELTA_PRIMARY_POSW, IN_DELTA_SECONDARY_POSW
// INPUTS - IN_MV, IN_DELTA_PRIMARY_POS, IN_DELTA_SECONDARY_POS
// OUTPUT - OUT_DELTA_MV
DELTA_OPTIMIZATION_MV,
SPECULAR_DELTA_MV,

MAX_NUM
};
Expand All @@ -136,10 +136,10 @@ namespace nrd

// RELAX: Data must be packed using "RELAX_FrontEnd_PackRadianceAndHitDist"
// REBLUR: Data must be packed using "REBLUR_FrontEnd_PackRadianceAndHitDist" (and "REBLUR_FrontEnd_GetNormHitDist" for hit distance) (RGBA16f+)
// Noisy and weighted sum of hit distances along a path (using NRD_GetCorrectedHitDist), excluding primary hit distance.
// REBLUR works with normalized hit distances. It's recommended to use REBLUR_FrontEnd_GetNormHitDist for hit distance normalization.
// Normalization parameters should be passed into NRD as HitDistanceParameters for diffuse and specular separately for internal
// hit distance denormalization.
// Noisy and weighted sum of hit distances along a path (using NRD_GetCorrectedHitDist), excluding primary hit distance.
// REBLUR works with normalized hit distances. It's recommended to use REBLUR_FrontEnd_GetNormHitDist for hit distance normalization.
// Normalization parameters should be passed into NRD as HitDistanceParameters for diffuse and specular separately for internal
// hit distance denormalization.
IN_DIFF_RADIANCE_HITDIST,
IN_SPEC_RADIANCE_HITDIST,

Expand All @@ -151,34 +151,32 @@ namespace nrd
IN_DIFF_DIRECTION_HITDIST,

// (Optional) Data must be packed using "NRD_FrontEnd_PackDirectionAndPdf" (RGBA8+)
// These inputs are needed only if PrePassMode::ADVANCED is used. The data can be averaged or weighted in case of many RPP. Encoding / decoding
// can be changed in "NRD_FrontEnd_PackDirectionAndPdf" and "NRD_FrontEnd_UnpackDirectionAndPdf" functions.
// These inputs are needed only if PrePassMode::ADVANCED is used. The data can be averaged or weighted in case of many RPP. Encoding / decoding
// can be changed in "NRD_FrontEnd_PackDirectionAndPdf" and "NRD_FrontEnd_UnpackDirectionAndPdf" functions.
IN_DIFF_DIRECTION_PDF,
IN_SPEC_DIRECTION_PDF,

// (Optional) User-provided history confidence in range 0-1, i.e. antilag (R8+)
// Used only if "CommonSettings::isHistoryConfidenceInputsAvailable = true".
// Used only if "CommonSettings::isHistoryConfidenceInputsAvailable = true".
IN_DIFF_CONFIDENCE,
IN_SPEC_CONFIDENCE,

// SIGMA: Data must be packed using "SIGMA_FrontEnd_PackShadow" (3-args) (RG16+)
// SIGMA: Data must be packed using "SIGMA_FrontEnd_PackShadow" (3/5-args) (RG16+/RGBA8+)
IN_SHADOWDATA,

// SIGMA: Data must be packed using "SIGMA_FrontEnd_PackShadow" (5-args) (RGBA8+)
IN_SHADOW_TRANSLUCENCY,

// REFERENCE: input
// Any signal
IN_RADIANCE,

// DELTA_OPTIMIZATION_MV: input
IN_DELTA_PRIMARY_POSW,
IN_DELTA_SECONDARY_POSW,
// Primary and secondary world space positions
IN_DELTA_PRIMARY_POS,
IN_DELTA_SECONDARY_POS,

//=============================================================================================================================
// OUTPUTS
//=============================================================================================================================

// IMPORTANT: These textures can potentially be used as history buffers
// IMPORTANT: These textures can potentially be used as history buffers!

// REBLUR: Data must be unpacked using "REBLUR_BackEnd_UnpackRadianceAndHitDist"
// .xyz - radiance, .w - normalized hit distance (RGBA16f+)
Expand All @@ -187,11 +185,11 @@ namespace nrd
OUT_DIFF_RADIANCE_HITDIST,
OUT_SPEC_RADIANCE_HITDIST,

// REBLUR: .x - normalized hit distance (R8+)
// .x - normalized hit distance (R8+)
OUT_DIFF_HITDIST,
OUT_SPEC_HITDIST,

// REBLUR: .xyz - direction, .w - normalized hit distance (RGBA8+)
// .xyz - direction, .w - normalized hit distance (RGBA8+)
OUT_DIFF_DIRECTION_HITDIST,

// SIGMA: Data must be unpacked using "SIGMA_BackEnd_UnpackShadow"
Expand All @@ -204,13 +202,13 @@ namespace nrd
// float3 finalShadowMoreExotic = shadowData.yzw;
OUT_SHADOW_TRANSLUCENCY,

// REFERENCE: output
// .xyz - accumulated signal
OUT_RADIANCE,

// SPEC_REFLECTION_MV: .xy - 2D screen space virtual motion (RG16f+), MV = previous - current
OUT_SPEC_REFLECTION_MV,
// .xy - 2D screen space virtual motion (RG16f+), MV = previous - current
OUT_REFLECTION_MV,

// DELTA_OPTIMIZATION_MV: .xy - 2D screen space motion (RG16f+), MV = previous - current
// .xy - 2D screen space motion (RG16f+), MV = previous - current
OUT_DELTA_MV,

//=============================================================================================================================
Expand Down
8 changes: 4 additions & 4 deletions Include/NRDSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once

#define NRD_SETTINGS_VERSION_MAJOR 3
#define NRD_SETTINGS_VERSION_MINOR 0
#define NRD_SETTINGS_VERSION_MINOR 1

static_assert (NRD_VERSION_MAJOR == NRD_SETTINGS_VERSION_MAJOR && NRD_VERSION_MINOR == NRD_SETTINGS_VERSION_MINOR, "Please, update all NRD SDK files");

Expand Down Expand Up @@ -441,16 +441,16 @@ namespace nrd
uint32_t maxAccumulatedFrameNum = 3600;
};

// SPEC_REFLECTION_MV
// SPECULAR_REFLECTION_MV

struct SpecularReflectionMvSettings
{
float unused;
};

// DELTA_OPTIMIZATION_MV
// SPECULAR_DELTA_MV

struct DeltaOptimizationMvSettings
struct SpecularDeltaMvSettings
{
float unused;
};
Expand Down
20 changes: 14 additions & 6 deletions Integration/NRDIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#define NRD_INTEGRATION 1
#define NRD_INTEGRATION_MAJOR 2
#define NRD_INTEGRATION_MINOR 0
#define NRD_INTEGRATION_DATE "21 March 2022"
#define NRD_INTEGRATION_MINOR 1
#define NRD_INTEGRATION_DATE "23 March 2022"

// Settings
#ifndef NRD_INTEGRATION_ASSERT
Expand Down Expand Up @@ -78,8 +78,12 @@ class NrdIntegration

// User pool must contain valid entries only for resources which required for the set of
// requested resources
void Denoise(uint32_t consecutiveFrameIndex, nri::CommandBuffer& commandBuffer,
const nrd::CommonSettings& commonSettings, const NrdUserPool& userPool);
void Denoise
(
uint32_t consecutiveFrameIndex, nri::CommandBuffer& commandBuffer,
const nrd::CommonSettings& commonSettings, const NrdUserPool& userPool,
bool enableDescriptorCaching = true
);

// This function assums that the device is in the IDLE state, i.e. there is no work in flight
void Destroy();
Expand All @@ -92,8 +96,12 @@ class NrdIntegration

void CreateResources();
void AllocateAndBindMemory();
void Dispatch(nri::CommandBuffer& commandBuffer, nri::DescriptorPool& descriptorPool,
const nrd::DispatchDesc& dispatchDesc, const NrdUserPool& userPool);
void Dispatch
(
nri::CommandBuffer& commandBuffer, nri::DescriptorPool& descriptorPool,
const nrd::DispatchDesc& dispatchDesc, const NrdUserPool& userPool,
bool enableDescriptorCaching
);

private:
std::vector<NrdIntegrationTexture> m_TexturePool;
Expand Down
22 changes: 15 additions & 7 deletions Integration/NRDIntegration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ constexpr const char* g_NRD_PermanentPoolNames[] =
"IN_SHADOWDATA ",
"IN_SHADOW_TRANSLUCENCY ",
"IN_RADIANCE ",
"IN_DELTA_PRIMARY_POSW ",
"IN_DELTA_SECONDARY_POSW ",
"IN_DELTA_PRIMARY_POS ",
"IN_DELTA_SECONDARY_POS ",

"OUT_DIFF_RADIANCE_HITDIST ",
"OUT_SPEC_RADIANCE_HITDIST ",
Expand All @@ -93,7 +93,7 @@ constexpr const char* g_NRD_PermanentPoolNames[] =
"OUT_DIFF_DIRECTION_HITDIST ",
"OUT_SHADOW_TRANSLUCENCY ",
"OUT_RADIANCE ",
"OUT_SPEC_REFLECTION_MV ",
"OUT_REFLECTION_MV ",
"OUT_DELTA_MV "
};

Expand Down Expand Up @@ -398,7 +398,7 @@ bool NrdIntegration::SetMethodSettings(nrd::Method method, const void* methodSet
return result == nrd::Result::SUCCESS;
}

void NrdIntegration::Denoise(uint32_t consecutiveFrameIndex, nri::CommandBuffer& commandBuffer, const nrd::CommonSettings& commonSettings, const NrdUserPool& userPool)
void NrdIntegration::Denoise(uint32_t consecutiveFrameIndex, nri::CommandBuffer& commandBuffer, const nrd::CommonSettings& commonSettings, const NrdUserPool& userPool, bool enableDescriptorCaching)
{
#if( NRD_INTEGRATION_DEBUG_LOGGING == 1 )
printf("Frame %u ==============================================================================\n", consecutiveFrameIndex);
Expand All @@ -419,13 +419,13 @@ void NrdIntegration::Denoise(uint32_t consecutiveFrameIndex, nri::CommandBuffer&
const nrd::DispatchDesc& dispatchDesc = dispatchDescs[i];
m_NRI->CmdBeginAnnotation(commandBuffer, dispatchDesc.name);

Dispatch(commandBuffer, *descriptorPool, dispatchDesc, userPool);
Dispatch(commandBuffer, *descriptorPool, dispatchDesc, userPool, enableDescriptorCaching);

m_NRI->CmdEndAnnotation(commandBuffer);
}
}

void NrdIntegration::Dispatch(nri::CommandBuffer& commandBuffer, nri::DescriptorPool& descriptorPool, const nrd::DispatchDesc& dispatchDesc, const NrdUserPool& userPool)
void NrdIntegration::Dispatch(nri::CommandBuffer& commandBuffer, nri::DescriptorPool& descriptorPool, const nrd::DispatchDesc& dispatchDesc, const NrdUserPool& userPool, bool enableDescriptorCaching)
{
const nrd::DenoiserDesc& denoiserDesc = nrd::GetDenoiserDesc(*m_Denoiser);
const nrd::PipelineDesc& pipelineDesc = denoiserDesc.pipelines[dispatchDesc.pipelineIndex];
Expand Down Expand Up @@ -484,7 +484,7 @@ void NrdIntegration::Dispatch(nri::CommandBuffer& commandBuffer, nri::Descriptor

const bool isStorage = descriptorRangeDesc.descriptorType == nrd::DescriptorType::STORAGE_TEXTURE;
uint64_t key = NRD_CreateDescriptorKey(nrdTexture->subresourceStates->texture, isStorage, (uint8_t)nrdResource.mipOffset, (uint8_t)nrdResource.mipNum);
const auto& entry = m_Descriptors.find(key);
const auto& entry = enableDescriptorCaching ? m_Descriptors.find(key) : m_Descriptors.end();

nri::Descriptor* descriptor = nullptr;
if (entry == m_Descriptors.end())
Expand Down Expand Up @@ -532,6 +532,14 @@ void NrdIntegration::Dispatch(nri::CommandBuffer& commandBuffer, nri::Descriptor
m_NRI->CmdSetDescriptorSets(commandBuffer, 0, 1, &descriptorSet, &dynamicConstantBufferOffset);
m_NRI->CmdDispatch(commandBuffer, dispatchDesc.gridWidth, dispatchDesc.gridHeight, 1);

// Cleanup
if (!enableDescriptorCaching)
{
for (const auto& entry : m_Descriptors)
m_NRI->DestroyDescriptor(*entry.second);
m_Descriptors.clear();
}

// Debug logging
#if( NRD_INTEGRATION_DEBUG_LOGGING == 1 )
printf("Pipeline #%u : %s\n\t", dispatchDesc.pipelineIndex, dispatchDesc.name);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NVIDIA Real-time Denoisers v3.0.0 (NRD)
# NVIDIA Real-time Denoisers v3.1.0 (NRD)

## SAMPLE APP

Expand Down
2 changes: 1 addition & 1 deletion Resources/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Versioning rules:
*/

#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 0
#define VERSION_REVISION 0

Expand Down
Loading

0 comments on commit d10b533

Please sign in to comment.