Skip to content

Commit

Permalink
v4.2.0:
Browse files Browse the repository at this point in the history
HIGHLIGHTS (BREAKING CHANGES - please read UPDATE.md):
- NRD: a single NRD instance can now include any combination of denoisers, including repeating ones
- NRD: the transient memory pool is internally optimized to reduce memory consumption if an instance has several denoisers
- NRD: fixed behavior for y-inverted projection matrices (m11 < 0)
- NRD: accelerated sky only rendering
- REBLUR: rewritten anti-firefly filter (significantly less biased, good cleaner of undenoised sporadic bright samples)
- REBLUR: several fixes
- RELAX: significantly reduced memory usage

DETAILS:
- NRD: a single NRD instance can now include any combination of denoisers, including repeating ones
- NRD: the transient memory pool is internally optimized to reduce memory consumption if an instance has several denoisers
- NRD: fixed behavior for y-inverted projection matrices (m11 < 0)
- NRD: DLL version string now includes encoding information to avoid confusion
- NRD INTEGRATION: introduced `NewFrame` & `SetCommonSettings` to reflect changes in NRD API
- NRD: accelerated sky only rendering
- REBLUR: rewritten anti-firefly filter (significantly less biased, good cleaner of undenoised sporadic bright samples)
- REBLUR: fixed broken specular occlusion only denoiser
- REBLUR: slightly improved disocclusion test in some corner cases
- RELAX: significantly reduced memory usage
- CMAKE: fixed usage outside of NRD
- updated README
- updated UPDATE
- updated dependencies
  • Loading branch information
dzhdanNV committed May 23, 2023
1 parent 4cca79a commit 40906c5
Show file tree
Hide file tree
Showing 91 changed files with 3,087 additions and 2,238 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ file (GLOB GLOB_INCUDE "Include/*")
source_group ("Include" FILES ${GLOB_INCUDE})
file (GLOB GLOB_SOURCE "Source/*.cpp" "Source/*.h" "Source/*.hpp")
source_group ("Source" FILES ${GLOB_SOURCE})
file (GLOB GLOB_METHODS "Source/Methods/*.cpp" "Source/Methods/*.h" "Source/Methods/*.hpp")
source_group ("Methods" FILES ${GLOB_METHODS})
file (GLOB GLOB_DENOISERS "Source/Denoisers/*.cpp" "Source/Denoisers/*.h" "Source/Denoisers/*.hpp")
source_group ("Denoisers" FILES ${GLOB_DENOISERS})
file (GLOB GLOB_RESOURCES "Resources/*")
source_group ("Resources" FILES ${GLOB_RESOURCES})

if (NRD_STATIC_LIBRARY)
add_library (${PROJECT_NAME} STATIC ${GLOB_SOURCE} ${GLOB_METHODS} ${MATHLIB_FILES} ${GLOB_RESOURCES} ${GLOB_INCUDE})
add_library (${PROJECT_NAME} STATIC ${GLOB_SOURCE} ${GLOB_DENOISERS} ${MATHLIB_FILES} ${GLOB_RESOURCES} ${GLOB_INCUDE})
else ()
add_library (${PROJECT_NAME} SHARED ${GLOB_SOURCE} ${GLOB_METHODS} ${MATHLIB_FILES} ${GLOB_RESOURCES} ${GLOB_INCUDE})
add_library (${PROJECT_NAME} SHARED ${GLOB_SOURCE} ${GLOB_DENOISERS} ${MATHLIB_FILES} ${GLOB_RESOURCES} ${GLOB_INCUDE})

if (WIN32)
target_compile_definitions (${PROJECT_NAME} PRIVATE "NRD_API=extern \"C\" __declspec(dllexport)")
Expand All @@ -119,7 +119,8 @@ if (NRD_USE_PRECOMPILED_SHADERS)
target_compile_definitions (${PROJECT_NAME} PRIVATE NRD_USE_PRECOMPILED_SHADERS)
endif ()

target_include_directories (${PROJECT_NAME} PRIVATE "Include" "External")
target_include_directories (${PROJECT_NAME} PUBLIC "Include")
target_include_directories (${PROJECT_NAME} PRIVATE "External")
target_compile_definitions (${PROJECT_NAME} PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options (${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})

Expand Down
2 changes: 1 addition & 1 deletion External/MathLib
2 changes: 1 addition & 1 deletion External/ShaderMake
29 changes: 20 additions & 9 deletions Include/NRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <cstddef>

#define NRD_VERSION_MAJOR 4
#define NRD_VERSION_MINOR 1
#define NRD_VERSION_BUILD 2
#define NRD_VERSION_DATE "5 April 2023"
#define NRD_VERSION_MINOR 2
#define NRD_VERSION_BUILD 0
#define NRD_VERSION_DATE "23 May 2023"

#if defined(_MSC_VER)
#define NRD_CALL __fastcall
Expand All @@ -53,14 +53,25 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

namespace nrd
{
// Create and destroy
NRD_API Result NRD_CALL CreateInstance(const InstanceCreationDesc& instanceCreationDesc, Instance*& instance);
NRD_API void NRD_CALL DestroyInstance(Instance& instance);

// Get
NRD_API const LibraryDesc& NRD_CALL GetLibraryDesc();
NRD_API Result NRD_CALL CreateDenoiser(const DenoiserCreationDesc& denoiserCreationDesc, Denoiser*& denoiser);
NRD_API const DenoiserDesc& NRD_CALL GetDenoiserDesc(const Denoiser& denoiser);
NRD_API Result NRD_CALL SetMethodSettings(Denoiser& denoiser, Method method, const void* methodSettings);
NRD_API void NRD_CALL GetComputeDispatches(Denoiser& denoiser, const CommonSettings& commonSettings, const DispatchDesc*& dispatchDescs, uint32_t& dispatchDescNum);
NRD_API void NRD_CALL DestroyDenoiser(Denoiser& denoiser);
NRD_API const InstanceDesc& NRD_CALL GetInstanceDesc(const Instance& instance);

// Typically needs to be called once per frame
NRD_API Result NRD_CALL SetCommonSettings(Instance& instance, const CommonSettings& commonSettings);

// Typically needs to be called at least once per denoiser (not necessarily on each frame)
NRD_API Result NRD_CALL SetDenoiserSettings(Instance& instance, Identifier identifier, const void* denoiserSettings);

// Retrieves dispatches for the list of identifiers (if they are parts of the instance)
// IMPORTANT: returned memory is owned by the "instance" and will be overwritten by the next "GetComputeDispatches" call
NRD_API Result NRD_CALL GetComputeDispatches(Instance& instance, const Identifier* identifiers, uint32_t identifiersNum, const DispatchDesc*& dispatchDescs, uint32_t& dispatchDescsNum);

// Helpers
NRD_API const char* GetResourceTypeString(ResourceType resourceType);
NRD_API const char* GetMethodString(Method method);
NRD_API const char* GetDenoiserString(Denoiser denoiser);
}
34 changes: 20 additions & 14 deletions Include/NRDDescs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once

#define NRD_DESCS_VERSION_MAJOR 4
#define NRD_DESCS_VERSION_MINOR 1
#define NRD_DESCS_VERSION_MINOR 2

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

namespace nrd
{
struct Denoiser;
typedef uint32_t Identifier;

struct Instance;

enum class Result : uint32_t
{
SUCCESS,
FAILURE,
INVALID_ARGUMENT,
UNSUPPORTED,
NON_UNIQUE_IDENTIFIER,

MAX_NUM
};

enum class Method : uint32_t
enum class Denoiser : uint32_t
{
// =============================================================================================================================
// REBLUR
Expand Down Expand Up @@ -224,6 +228,7 @@ namespace nrd
//=============================================================================================================================

// IMPORTANT: These textures can be potentially used as history buffers!
// IMPORTANT: Most of denoisers do not write into output pixels outside of "CommonSettings::denoisingRange"!

// Denoised radiance and hit distance
// REBLUR: use "REBLUR_BackEnd_UnpackRadianceAndNormHitDist" for decoding (RGBA16f+)
Expand Down Expand Up @@ -261,7 +266,7 @@ namespace nrd
OUT_DELTA_MV,

// (Optional) Debug output (RGBA8+), .w = transparency
// Written to if "DenoiserCreationDesc::allowValidation = true" and "CommonSettings::enableValidation = true"
// Written to if "InstanceCreationDesc::allowValidation = true" and "CommonSettings::enableValidation = true"
OUT_VALIDATION,

//=============================================================================================================================
Expand Down Expand Up @@ -409,27 +414,28 @@ namespace nrd
struct LibraryDesc
{
SPIRVBindingOffsets spirvBindingOffsets;
const Method* supportedMethods;
uint32_t supportedMethodsNum;
const Denoiser* supportedDenoisers;
uint32_t supportedDenoisersNum;
uint8_t versionMajor;
uint8_t versionMinor;
uint8_t versionBuild;
NormalEncoding normalEncoding;
RoughnessEncoding roughnessEncoding;
};

struct MethodDesc
struct DenoiserDesc
{
Method method;
uint16_t fullResolutionWidth;
uint16_t fullResolutionHeight;
Identifier identifier;
Denoiser denoiser;
uint16_t renderWidth;
uint16_t renderHeight;
};

struct DenoiserCreationDesc
struct InstanceCreationDesc
{
MemoryAllocatorInterface memoryAllocatorInterface;
const MethodDesc* requestedMethods;
uint32_t requestedMethodsNum;
const DenoiserDesc* denoisers;
uint32_t denoisersNum;
};

struct TextureDesc
Expand Down Expand Up @@ -483,7 +489,7 @@ namespace nrd
uint32_t storageTexturesMaxNum;
};

struct DenoiserDesc
struct InstanceDesc
{
// Constant buffer (shared)
uint32_t constantBufferMaxDataSize;
Expand Down
6 changes: 4 additions & 2 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 4
#define NRD_SETTINGS_VERSION_MINOR 1
#define NRD_SETTINGS_VERSION_MINOR 2

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 @@ -101,9 +101,11 @@ namespace nrd

// [-0.5; 0.5] - sampleUv = pixelUv + cameraJitter
float cameraJitter[2] = {};
float cameraJitterPrev[2] = {};

// (0; 1] - dynamic resolution scaling
float resolutionScale[2] = {1.0f, 1.0f};
float resolutionScalePrev[2] = {1.0f, 1.0f};

// (ms) - user provided if > 0, otherwise - tracked internally
float timeDeltaBetweenFrames = 0.0f;
Expand Down Expand Up @@ -145,7 +147,7 @@ namespace nrd
// If "true" IN_BASECOLOR_METALNESS is available
bool isBaseColorMetalnessAvailable = false;

// Enables debug overlay in OUT_VALIDATION, requires "DenoiserCreationDesc::allowValidation = true"
// Enables debug overlay in OUT_VALIDATION, requires "InstanceCreationDesc::allowValidation = true"
bool enableValidation = false;
};

Expand Down
35 changes: 19 additions & 16 deletions Integration/NRDIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

// IMPORTANT: these files must be included beforehand:
// NRD.h
// NRIDescs.hpp
// NRIDescs.h
// Extensions/NRIHelper.h
// Extensions/NRIWrapperD3D11.h
// Extensions/NRIWrapperD3D12.h
Expand All @@ -23,8 +23,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <map>

#define NRD_INTEGRATION_MAJOR 1
#define NRD_INTEGRATION_MINOR 5
#define NRD_INTEGRATION_DATE "23 March 2022"
#define NRD_INTEGRATION_MINOR 6
#define NRD_INTEGRATION_DATE "30 April 2023"
#define NRD_INTEGRATION 1

#define NRD_INTEGRATION_DEBUG_LOGGING 0
Expand All @@ -45,7 +45,7 @@ struct NrdIntegrationTexture

typedef std::array<NrdIntegrationTexture, (size_t)nrd::ResourceType::MAX_NUM - 2> NrdUserPool;

// User pool must contain valid entries only for resources, which are required for requested denoising methods, but
// User pool must contain valid entries only for resources, which are required for requested denoisers, but
// the entire pool must be zero-ed during initialization
inline void NrdIntegration_SetResource(NrdUserPool& pool, nrd::ResourceType slot, const NrdIntegrationTexture& texture)
{
Expand All @@ -61,9 +61,9 @@ class NrdIntegration
// The application must provide number of buffered frames, it's needed to guarantee that
// constant data and descriptor sets are not overwritten while being executed on the GPU.
// Usually it's 2-3 frames.
NrdIntegration(uint32_t bufferedFrameMaxNum, const char* persistentName = "") :
NrdIntegration(uint32_t bufferedFramesNum, const char* persistentName = "") :
m_Name(persistentName)
, m_BufferedFrameMaxNum(bufferedFrameMaxNum)
, m_BufferedFramesNum(bufferedFramesNum)
{}

~NrdIntegration()
Expand All @@ -72,18 +72,20 @@ class NrdIntegration
// There is no "Resize" functionality, because NRD full recreation costs nothing.
// The main cost comes from render targets resizing, which needs to be done in any case
// (call Destroy beforehand)
bool Initialize(const nrd::DenoiserCreationDesc& denoiserCreationDesc, nri::Device& nriDevice,
bool Initialize(const nrd::InstanceCreationDesc& instanceCreationDesc, nri::Device& nriDevice,
const nri::CoreInterface& nriCore, const nri::HelperInterface& nriHelper);

// Just calls "nrd::SetMethodSettings"
bool SetMethodSettings(nrd::Method method, const void* methodSettings);
// Must be called once on a frame start
void NewFrame(uint32_t frameIndex);

// Explcitly calls eponymous NRD API functions
bool SetCommonSettings(const nrd::CommonSettings& commonSettings);
bool SetDenoiserSettings(nrd::Identifier denoiser, const void* denoiserSettings);

// Better use "enableDescriptorCaching = true" if resources are not changing between frames
// (i.e. are not suballocated from a heap)
void Denoise
(
uint32_t consecutiveFrameIndex, nri::CommandBuffer& commandBuffer,
const nrd::CommonSettings& commonSettings, const NrdUserPool& userPool,
// (i.e. not suballocated from a heap)
void Denoise(const nrd::Identifier* denoisers, uint32_t denoisersNum,
nri::CommandBuffer& commandBuffer, const NrdUserPool& userPool,
bool enableDescriptorCaching
);

Expand Down Expand Up @@ -129,14 +131,15 @@ class NrdIntegration
nri::Device* m_Device = nullptr;
nri::Buffer* m_ConstantBuffer = nullptr;
nri::Descriptor* m_ConstantBufferView = nullptr;
nrd::Denoiser* m_Denoiser = nullptr;
nrd::Instance* m_Instance = nullptr;
const char* m_Name = nullptr;
uint64_t m_PermanentPoolSize = 0;
uint64_t m_TransientPoolSize = 0;
uint64_t m_ConstantBufferSize = 0;
uint32_t m_ConstantBufferViewSize = 0;
uint32_t m_ConstantBufferOffset = 0;
uint32_t m_BufferedFrameMaxNum = 0;
uint32_t m_BufferedFramesNum = 0;
uint32_t m_DescriptorPoolIndex = 0;
bool m_IsShadersReloadRequested = false;
};

Expand Down
Loading

0 comments on commit 40906c5

Please sign in to comment.