Skip to content

Commit

Permalink
v4.3.5:
Browse files Browse the repository at this point in the history
HIGHLIGHTS:
- NRD INTEGRATION: various improvements
- CMake: infrastructure improvements

DETAILS:
- NRD INTEGRATION: fixed a major bug: leaking descriptors with disabled descriptor caching
- NRD INTEGRATION: optimized allocation of descriptor pools
- NRD INTEGRATION: optimized suballocation in descriptor pools if samplers are in a dedicated register space
- NRD INTEGRATION: more and better asserts
- NRD INTEGRATION: "frameIndex" is hidden inside "NrdIntegration" instance
- NRD: optimized "DescriptorPoolDesc" if samplers are in a dedicated register space
- CMake: infrastructure improvements
- CMake: "_Build" => "_Bin", "_Compiler" => "_Build"
- updated dependencies
  • Loading branch information
dzhdanNV committed Oct 26, 2023
1 parent 2d94c1f commit fdb08f1
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ compile_commands.json
*.manifest

# generated folders
_Bin/
_Build/
_Compiler/
_NRD_SDK/
4 changes: 2 additions & 2 deletions 1-Deploy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

git submodule update --init --recursive

mkdir "_Compiler"
mkdir "_Build"

cd "_Compiler"
cd "_Build"
cmake .. -A x64
cd ..
4 changes: 2 additions & 2 deletions 1-Deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ chmod +x "4-Clean.sh"

git submodule update --init --recursive

mkdir -p "_Compiler"
mkdir -p "_Build"

cd "_Compiler"
cd "_Build"
cmake ..
cd ..
2 changes: 1 addition & 1 deletion 2-Build.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

cd "_Compiler"
cd "_Build"
cmake --build . --config Release -j 4
cmake --build . --config Debug -j 4
cd ..
4 changes: 2 additions & 2 deletions 2-Build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

mkdir -p "_Compiler"
mkdir -p "_Build"

cd "_Compiler"
cd "_Build"
cmake ..
cmake --build . --config Release -j 4
cmake --build . --config Debug -j 4
Expand Down
12 changes: 6 additions & 6 deletions 3-Prepare NRD SDK.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ mkdir "_NRD_SDK\Shaders\Include"
cd "_NRD_SDK"

copy "..\%NRD_DIR%\Include\*" "Include"
copy "..\_Build\Debug\NRD.dll" "Lib\Debug"
copy "..\_Build\Debug\NRD.lib" "Lib\Debug"
copy "..\_Build\Debug\NRD.pdb" "Lib\Debug"
copy "..\_Build\Release\NRD.dll" "Lib\Release"
copy "..\_Build\Release\NRD.lib" "Lib\Release"
copy "..\_Build\Release\NRD.pdb" "Lib\Release"
copy "..\_Bin\Debug\NRD.dll" "Lib\Debug"
copy "..\_Bin\Debug\NRD.lib" "Lib\Debug"
copy "..\_Bin\Debug\NRD.pdb" "Lib\Debug"
copy "..\_Bin\Release\NRD.dll" "Lib\Release"
copy "..\_Bin\Release\NRD.lib" "Lib\Release"
copy "..\_Bin\Release\NRD.pdb" "Lib\Release"
copy "..\%NRD_DIR%\Shaders\Include\NRD.hlsli" "Shaders\Include"
copy "..\%NRD_DIR%\Shaders\Include\NRDEncoding.hlsli" "Shaders\Include"
copy "..\%NRD_DIR%\LICENSE.txt" "."
Expand Down
4 changes: 2 additions & 2 deletions 3-Prepare NRD SDK.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mkdir -p "_NRD_SDK/Shaders/Include"
cd "_NRD_SDK"

cp -r ../$NRD_DIR/Include/ "Include"
cp -H ../_Build/Debug/libNRD.so "Lib/Debug"
cp -H ../_Build/Release/libNRD.so "Lib/Release"
cp -H ../_Bin/Debug/libNRD.so "Lib/Debug"
cp -H ../_Bin/Release/libNRD.so "Lib/Release"
cp ../$NRD_DIR/Shaders/Include/NRD.hlsli "Shaders/Include"
cp ../$NRD_DIR/Shaders/Include/NRDEncoding.hlsli "Shaders/Include"
cp ../$NRD_DIR/LICENSE.txt "."
Expand Down
2 changes: 1 addition & 1 deletion 4-Clean.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if exist "build" rd /q /s "build"

if exist "_Bin" rd /q /s "_Bin"
if exist "_Build" rd /q /s "_Build"
if exist "_Compiler" rd /q /s "_Compiler"
if exist "_Shaders" rd /q /s "_Shaders"
if exist "_NRD_SDK" rd /q /s "_NRD_SDK"
2 changes: 1 addition & 1 deletion 4-Clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

rm -rf "build"

rm -rf "_Bin"
rm -rf "_Build"
rm -rf "_Compiler"
rm -rf "_Shaders"
rm -rf "_NRD_SDK"
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ endif ()
# Cached
if (NOT IS_SUBMODULE)
set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_Bin" CACHE STRING "")
endif ()

# Generate PDB for Release builds
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")

set (NRD_DXC_CUSTOM_PATH "custom/path/to/dxc" CACHE STRING "Custom DXC to use if Vulkan SDK is not installed")
set (NRD_SHADERS_PATH "" CACHE STRING "Shader output path override")
set (NRD_NORMAL_ENCODING "2" CACHE STRING "Normal encoding variant (0-4, matches nrd::NormalEncoding)")
set (NRD_ROUGHNESS_ENCODING "1" CACHE STRING "Roughness encoding variant (0-2, matches nrd::RoughnessEncoding)")
set (GLOBAL_BIN_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/_Build" CACHE STRING "")

# Generate PDB for Release builds
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")

# Create project
file (READ "Include/NRD.h" ver_h)
Expand Down Expand Up @@ -149,8 +149,8 @@ target_compile_options (${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})

set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "${PROJECT_NAME}")

set_target_properties (${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${GLOBAL_BIN_OUTPUT_PATH}/$<CONFIG>")
message ("NRD output path: '${GLOBAL_BIN_OUTPUT_PATH}'")
set_target_properties (${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message ("NRD output path: '${CMAKE_RUNTIME_OUTPUT_DIRECTORY}'")

# Shaders
if (NOT NRD_DISABLE_SHADER_COMPILATION)
Expand All @@ -161,7 +161,7 @@ if (NOT NRD_DISABLE_SHADER_COMPILATION)

# External/ShaderMake
if (NOT TARGET ShaderMake)
set (SHADERMAKE_BIN_OUTPUT_PATH ${GLOBAL_BIN_OUTPUT_PATH} CACHE STRING "")
set (SHADERMAKE_BIN_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} CACHE STRING "")
add_subdirectory (External/ShaderMake)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion External/ShaderMake
4 changes: 2 additions & 2 deletions Include/NRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#define NRD_VERSION_MAJOR 4
#define NRD_VERSION_MINOR 3
#define NRD_VERSION_BUILD 4
#define NRD_VERSION_DATE "20 October 2023"
#define NRD_VERSION_BUILD 5
#define NRD_VERSION_DATE "25 October 2023"

#if defined(_MSC_VER)
#define NRD_CALL __fastcall
Expand Down
47 changes: 22 additions & 25 deletions Integration/NRDIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <map>

#define NRD_INTEGRATION_MAJOR 1
#define NRD_INTEGRATION_MINOR 6
#define NRD_INTEGRATION_DATE "30 April 2023"
#define NRD_INTEGRATION_MINOR 7
#define NRD_INTEGRATION_DATE "25 October 2023"
#define NRD_INTEGRATION 1

#define NRD_INTEGRATION_DEBUG_LOGGING 0

#ifndef NRD_INTEGRATION_ASSERT
#include <assert.h>
#define NRD_INTEGRATION_ASSERT(expr, msg) (assert(expr && msg))
#define NRD_INTEGRATION_ASSERT(expr, msg) assert(expr && msg)
#endif

// User inputs / outputs are not mipmapped, thus only 1 entry is needed.
Expand All @@ -58,12 +58,16 @@ inline void NrdIntegration_SetResource(NrdUserPool& pool, nrd::ResourceType slot
class NrdIntegration
{
public:
// 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 bufferedFramesNum, const char* persistentName = "") :
// bufferedFramesNum (usually 2-3 frames):
// 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.
// enableDescriptorCaching:
// true - enables descriptor caching for the whole lifetime of an NrdIntegration instance
// false - descriptors are cached only within a single "Denoise" call
NrdIntegration(uint32_t bufferedFramesNum, bool enableDescriptorCaching, const char* persistentName = "") :
m_Name(persistentName)
, m_BufferedFramesNum(bufferedFramesNum)
, m_IsDescriptorCachingEnabled(enableDescriptorCaching)
{}

~NrdIntegration()
Expand All @@ -72,22 +76,16 @@ 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::InstanceCreationDesc& instanceCreationDesc, nri::Device& nriDevice,
const nri::CoreInterface& nriCore, const nri::HelperInterface& nriHelper);
bool Initialize(const nrd::InstanceCreationDesc& instanceCreationDesc, nri::Device& nriDevice, const nri::CoreInterface& nriCore, const nri::HelperInterface& nriHelper);

// Must be called once on a frame start
void NewFrame(uint32_t frameIndex);
void NewFrame();

// Explcitly calls eponymous NRD API functions
// Explicitly 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. not suballocated from a heap)
void Denoise(const nrd::Identifier* denoisers, uint32_t denoisersNum,
nri::CommandBuffer& commandBuffer, const NrdUserPool& userPool,
bool enableDescriptorCaching
);
void Denoise(const nrd::Identifier* denoisers, uint32_t denoisersNum, nri::CommandBuffer& commandBuffer, const NrdUserPool& userPool);

// This function assumes that the device is in the IDLE state, i.e. there is no work in flight
void Destroy();
Expand All @@ -110,22 +108,19 @@ class NrdIntegration

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

private:
std::vector<NrdIntegrationTexture> m_TexturePool;
std::map<uint64_t, nri::Descriptor*> m_Descriptors;
std::map<uint64_t, nri::Descriptor*> m_CachedDescriptors;
std::vector<std::vector<nri::Descriptor*>> m_DescriptorsInFlight;
std::vector<nri::TextureTransitionBarrierDesc> m_ResourceState;
std::vector<nri::PipelineLayout*> m_PipelineLayouts;
std::vector<nri::Pipeline*> m_Pipelines;
std::vector<nri::Memory*> m_MemoryAllocations;
std::vector<nri::Descriptor*> m_Samplers;
std::array<nri::DescriptorPool*, 16> m_DescriptorPools = {};
std::vector<nri::DescriptorPool*> m_DescriptorPools = {};
std::vector<nri::DescriptorSet*> m_DescriptorSetSamplers = {};
const nri::CoreInterface* m_NRI = nullptr;
const nri::HelperInterface* m_NRIHelper = nullptr;
nri::Device* m_Device = nullptr;
Expand All @@ -140,7 +135,9 @@ class NrdIntegration
uint32_t m_ConstantBufferOffset = 0;
uint32_t m_BufferedFramesNum = 0;
uint32_t m_DescriptorPoolIndex = 0;
uint32_t m_FrameIndex = 0;
bool m_IsShadersReloadRequested = false;
bool m_IsDescriptorCachingEnabled = false;
};

#define NRD_INTEGRATION_ABORT_ON_FAILURE(result) if ((result) != nri::Result::SUCCESS) NRD_INTEGRATION_ASSERT(false, "Abort on failure!")

0 comments on commit fdb08f1

Please sign in to comment.