Skip to content

Commit 97271ef

Browse files
committed
Add DLSS support using CUDA API in DLSS 310.5.3
1 parent 3be3a46 commit 97271ef

39 files changed

+2218
-533
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.cursorrules
2+
.cursor/
3+
.claude/
14
.editorconfig
25
*.ncu-rep
36
*~
@@ -8,19 +11,18 @@ assets/**
811
benchmark-*/
912
build*/
1013
imgui.ini
11-
.projectile
1214
optix.props
1315
private.cmake
1416
tmp*.png
1517
tmp/
1618
__pycache__/
1719
vs-chromium-project.txt
18-
ClusterApi/codegen/input/*/*.ppm
19-
ClusterApi/codegen/input/*/*.log
2020
scenes
2121
scenes/**
2222
data
2323
data/**
24+
reference
25+
reference/**
2426
hooks/
2527
lfs/
2628
log

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "extern/osd_lite"]
2-
path = extern/osd_lite
3-
url = https://github.com/NVIDIA-RTX/OSD-Lite

CMake/FetchDLSS.cmake

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#
2+
# FetchDLSS.cmake
3+
#
4+
# Fetches the NVIDIA DLSS loader package (aka NGX SDK) via FetchContent.
5+
# This library is used to load the DLSS-RR model at runtime.
6+
#
7+
# Creates imported target:
8+
# DLSS::DLSS - The DLSS loader library
9+
#
10+
# CRT Selection (Windows):
11+
# The SDK provides both static (/MT) and dynamic (/MD) CRT versions.
12+
# This module automatically uses the version matching your project's CRT setting.
13+
#
14+
# Runtime Dependencies:
15+
# The DLSS runtime library (DLL/SO) must be beside the executable.
16+
# Use dlss_setup_runtime_dependencies(TARGET) after linking to set this up.
17+
#
18+
# Local Override:
19+
# Set DLSS_ROOT to use a local SDK instead of fetching.
20+
#
21+
22+
include(FetchContent)
23+
24+
set(DLSS_VERSION "310.5.3" CACHE STRING "DLSS SDK version")
25+
set(DLSS_URL "https://github.com/NVIDIA/DLSS/archive/refs/tags/v${DLSS_VERSION}.tar.gz" CACHE STRING "URL for DLSS SDK archive")
26+
set(DLSS_URL_HASH "6b54a684b5b31e819a51742ad534abb4e8cdada76572f061a5d3149c7432a0a1" CACHE STRING "SHA256 hash for DLSS archive")
27+
28+
# Folder name for IDE organization
29+
set(DLSS_FOLDER_NAME "external/dlss" CACHE STRING "Folder name for grouping DLSS in IDEs")
30+
31+
# If a local source is specified, prefer it (e.g., for offline builds or existing SDK installs)
32+
if(DEFINED DLSS_ROOT AND EXISTS "${DLSS_ROOT}/include/nvsdk_ngx.h")
33+
get_filename_component(DLSS_ROOT "${DLSS_ROOT}" ABSOLUTE)
34+
message(STATUS "DLSS: Using local SDK at: ${DLSS_ROOT}")
35+
set(_dlss_source_dir "${DLSS_ROOT}")
36+
else()
37+
# Fetch from archive
38+
message(STATUS "DLSS: Fetching SDK v${DLSS_VERSION} from GitHub...")
39+
if(DLSS_URL_HASH)
40+
FetchContent_Declare(dlss URL "${DLSS_URL}" URL_HASH SHA256=${DLSS_URL_HASH})
41+
else()
42+
FetchContent_Declare(dlss URL "${DLSS_URL}")
43+
endif()
44+
FetchContent_MakeAvailable(dlss)
45+
FetchContent_GetProperties(dlss)
46+
set(_dlss_source_dir "${dlss_SOURCE_DIR}")
47+
message(STATUS "DLSS: Fetched to: ${_dlss_source_dir}")
48+
endif()
49+
50+
# Locate components within the SDK
51+
set(DLSS_INCLUDE_DIR "${_dlss_source_dir}/include")
52+
53+
if(WIN32)
54+
# Determine CRT flavor (dynamic /MD vs static /MT)
55+
set(_dlss_crt_flavor "d") # dynamic by default
56+
if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "MultiThreaded[^D]*$")
57+
set(_dlss_crt_flavor "s")
58+
endif()
59+
60+
set(DLSS_LIBRARY_RELEASE "${_dlss_source_dir}/lib/Windows_x86_64/x64/nvsdk_ngx_${_dlss_crt_flavor}.lib")
61+
set(DLSS_LIBRARY_DEBUG "${_dlss_source_dir}/lib/Windows_x86_64/x64/nvsdk_ngx_${_dlss_crt_flavor}_dbg.lib")
62+
set(DLSS_RUNTIME_LIBRARY_DEVELOP "${_dlss_source_dir}/lib/Windows_x86_64/dev/nvngx_dlssd.dll")
63+
set(DLSS_RUNTIME_LIBRARY_RELEASE "${_dlss_source_dir}/lib/Windows_x86_64/rel/nvngx_dlssd.dll")
64+
else()
65+
set(DLSS_LIBRARY_RELEASE "${_dlss_source_dir}/lib/Linux_x86_64/libnvsdk_ngx.a")
66+
set(DLSS_LIBRARY_DEBUG "${DLSS_LIBRARY_RELEASE}")
67+
file(GLOB _dlss_dev_so "${_dlss_source_dir}/lib/Linux_x86_64/dev/libnvidia-ngx-dlssd.so*")
68+
file(GLOB _dlss_rel_so "${_dlss_source_dir}/lib/Linux_x86_64/rel/libnvidia-ngx-dlssd.so*")
69+
if(_dlss_dev_so)
70+
list(GET _dlss_dev_so 0 DLSS_RUNTIME_LIBRARY_DEVELOP)
71+
endif()
72+
if(_dlss_rel_so)
73+
list(GET _dlss_rel_so 0 DLSS_RUNTIME_LIBRARY_RELEASE)
74+
endif()
75+
endif()
76+
77+
# Validate we found the essentials
78+
if(EXISTS "${DLSS_INCLUDE_DIR}/nvsdk_ngx.h" AND EXISTS "${DLSS_LIBRARY_RELEASE}")
79+
set(DLSS_FOUND TRUE)
80+
else()
81+
set(DLSS_FOUND FALSE)
82+
message(WARNING "DLSS: SDK structure not as expected. Include: ${DLSS_INCLUDE_DIR}, Lib: ${DLSS_LIBRARY_RELEASE}")
83+
return()
84+
endif()
85+
86+
# Create imported target
87+
if(NOT TARGET DLSS::DLSS)
88+
add_library(DLSS::DLSS STATIC IMPORTED GLOBAL)
89+
set_target_properties(DLSS::DLSS PROPERTIES
90+
IMPORTED_CONFIGURATIONS "Debug;Release;RelWithDebInfo"
91+
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX;CUDA"
92+
INTERFACE_COMPILE_DEFINITIONS "DLSS_ENABLED"
93+
INTERFACE_INCLUDE_DIRECTORIES "${DLSS_INCLUDE_DIR}"
94+
IMPORTED_LOCATION_RELEASE "${DLSS_LIBRARY_RELEASE}"
95+
IMPORTED_LOCATION_RELWITHDEBINFO "${DLSS_LIBRARY_RELEASE}"
96+
IMPORTED_LOCATION_DEBUG "${DLSS_LIBRARY_DEBUG}"
97+
)
98+
endif()
99+
100+
message(STATUS "DLSS: Found SDK v${DLSS_VERSION}")
101+
message(STATUS "DLSS: Release library: ${DLSS_LIBRARY_RELEASE}")
102+
message(STATUS "DLSS: Debug library: ${DLSS_LIBRARY_DEBUG}")
103+
104+
# Function to copy runtime library beside executable
105+
function(dlss_setup_runtime_dependencies TARGET)
106+
if(NOT DLSS_RUNTIME_LIBRARY_DEVELOP AND NOT DLSS_RUNTIME_LIBRARY_RELEASE)
107+
message(WARNING "DLSS: Runtime libraries not found, skipping runtime setup")
108+
return()
109+
endif()
110+
111+
add_custom_command(TARGET ${TARGET} POST_BUILD
112+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
113+
"$<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>,${DLSS_RUNTIME_LIBRARY_DEVELOP},${DLSS_RUNTIME_LIBRARY_RELEASE}>"
114+
"$<TARGET_FILE_DIR:${TARGET}>/$<IF:$<PLATFORM_ID:Windows>,nvngx_dlssd.dll,libnvidia-ngx-dlssd.so>"
115+
COMMENT "DLSS: Copying runtime library"
116+
)
117+
endfunction()

CMake/FetchOsdLite.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Helper to bring in OSD-Lite via CMake FetchContent, with local override
3+
#
4+
5+
include(FetchContent)
6+
7+
set(OSD_LITE_GIT_REPOSITORY "https://github.com/NVIDIA-RTX/OSD-Lite.git" CACHE STRING "Git repository for osd_lite")
8+
set(OSD_LITE_GIT_TAG "c0c3404b62ee4b39c1a7c77d72a13ee9712f37ca" CACHE STRING "Git tag/branch/commit for osd_lite")
9+
10+
# Folder name for IDE organization of osd_lite targets
11+
set(OSD_LITE_FOLDER_NAME "external/osd_lite" CACHE STRING "Folder name for grouping osd_lite targets in IDEs")
12+
13+
# If a local source is specified, prefer it (e.g., for offline builds)
14+
if(DEFINED OSD_LITE_SOURCE_DIR AND EXISTS "${OSD_LITE_SOURCE_DIR}/CMakeLists.txt")
15+
# Normalize to absolute path
16+
get_filename_component(OSD_LITE_SOURCE_DIR "${OSD_LITE_SOURCE_DIR}" ABSOLUTE)
17+
message(STATUS "Using local OSD-Lite at: ${OSD_LITE_SOURCE_DIR}")
18+
add_subdirectory("${OSD_LITE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/_deps/osd_lite-build" EXCLUDE_FROM_ALL)
19+
# Ensure OSD-Lite headers are treated as system to avoid third-party warnings
20+
include_directories(SYSTEM
21+
${OSD_LITE_SOURCE_DIR}
22+
${OSD_LITE_SOURCE_DIR}/opensubdiv
23+
${OSD_LITE_SOURCE_DIR}/opensubdiv/tmr)
24+
else()
25+
# Fetch from git
26+
message(STATUS "Fetching OSD-Lite from: ${OSD_LITE_GIT_REPOSITORY} @ ${OSD_LITE_GIT_TAG}")
27+
FetchContent_Declare(
28+
osd_lite
29+
GIT_REPOSITORY "${OSD_LITE_GIT_REPOSITORY}"
30+
GIT_TAG "${OSD_LITE_GIT_TAG}"
31+
GIT_PROGRESS TRUE
32+
)
33+
FetchContent_MakeAvailable(osd_lite)
34+
35+
# Resolve source dir for include path adjustments
36+
FetchContent_GetProperties(osd_lite)
37+
if(osd_lite_SOURCE_DIR)
38+
message(STATUS "Using fetched OSD-Lite at: ${osd_lite_SOURCE_DIR}")
39+
# Ensure OSD-Lite headers are treated as system to avoid third-party warnings
40+
include_directories(SYSTEM
41+
${osd_lite_SOURCE_DIR}
42+
${osd_lite_SOURCE_DIR}/opensubdiv
43+
${osd_lite_SOURCE_DIR}/opensubdiv/tmr)
44+
endif()
45+
endif()
46+
47+

CMake/embed_cuda.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ function(embed_cuda)
104104
if(EMBED_CUDA_PTX)
105105
set_property(TARGET ${CUDA_TARGET} PROPERTY CUDA_PTX_COMPILATION ON)
106106
else()
107-
set_property(TARGET ${CUDA_TARGET} PROPERTY CUDA_OPTIX_COMPILATION ON)
107+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27.7")
108+
set_property(TARGET ${CUDA_TARGET} PROPERTY CUDA_OPTIX_COMPILATION ON)
109+
else()
110+
target_compile_options(${CUDA_TARGET} PRIVATE "-optix-ir")
111+
endif()
108112
endif()
109113

110114

CMake/run_bin2c.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ foreach(obj ${OBJECTS})
5454
if(NOT EXISTS ${obj})
5555
message(FATAL_ERORR "${obj} does not exist.")
5656
set(file_contents "${file_contents}\n#error ${obj} does not exist.\n")
57-
elseif(obj_ext MATCHES ".ptx" OR obj_ext MATCHES ".optixir")
57+
elseif(obj_ext MATCHES ".ptx" OR obj_ext MATCHES ".optixir" OR obj_ext MATCHES ".o")
5858
set(args --name ${obj_name} ${obj})
5959
if(obj_ext MATCHES ".ptx")
6060
list(APPEND(args --padd 0,0))

CMakeLists.txt

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232
# Include developer's "private.cmake" (if any) for ad hoc customization.
3333
include( "private.cmake" OPTIONAL )
3434

35-
# Minimum version of cmake to support OptiXIR compilation
36-
cmake_minimum_required(VERSION 3.27.7 FATAL_ERROR)
35+
36+
if(WIN32)
37+
# newer cmake has better optixir support with MSVC
38+
cmake_minimum_required(VERSION 3.27.7 FATAL_ERROR)
39+
else()
40+
cmake_minimum_required(VERSION 3.25.3 FATAL_ERROR)
41+
endif()
3742

3843
# Temporarily quiet some warnings related to FetchContent usage
3944
if(POLICY CMP0169)
@@ -56,10 +61,20 @@ endif()
5661
# default CUDA arch. This needs to be declared before any project(... CUDA) lines
5762
set(CMAKE_CUDA_ARCHITECTURES "86" CACHE STRING "")
5863

64+
5965
project(OptixSubd LANGUAGES C CXX CUDA VERSION 1.13.0)
6066

67+
find_package(CUDAToolkit 12.0 REQUIRED)
68+
6169
message(STATUS "CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}")
6270

71+
# Dynamically link against the CUDA runtime
72+
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL "13.0")
73+
set(CMAKE_CUDA_RUNTIME_LIBRARY "Hybrid")
74+
else()
75+
set(CMAKE_CUDA_RUNTIME_LIBRARY "Shared")
76+
endif()
77+
6378
# C++ standards
6479

6580
set(CMAKE_CXX_STANDARD 20)
@@ -93,9 +108,6 @@ if(MSVC)
93108
else()
94109
# Ignore warnings from some third party headers by including them with -isystem
95110
include_directories(SYSTEM
96-
${CMAKE_CURRENT_LIST_DIR}/extern/osd_lite
97-
${CMAKE_CURRENT_LIST_DIR}/extern/osd_lite/opensubdiv
98-
${CMAKE_CURRENT_LIST_DIR}/extern/osd_lite/opensubdiv/tmr
99111
${CMAKE_CURRENT_LIST_DIR}/texture
100112
${CMAKE_BINARY_DIR}/_deps/implot-src
101113
${CMAKE_BINARY_DIR}/_deps/imgui-src
@@ -129,7 +141,6 @@ add_compile_options($<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CUDA>>:-lineinfo>
129141
add_compile_options($<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:CUDA>>:-lineinfo>)
130142

131143

132-
find_package( CUDAToolkit 12.0 REQUIRED )
133144

134145

135146
# TBB (optional) needed for C++17 parallel algorithms on gcc
@@ -157,11 +168,19 @@ add_library(glad::glad ALIAS glad)
157168

158169
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/optix-toolkit EXCLUDE_FROM_ALL)
159170

171+
# Make OptiX Toolkit use dynamic CUDA runtime
172+
set(OTK_LINK_CUDA_STATIC OFF CACHE BOOL "Enable static linking against the cuda run-time" FORCE)
160173

161174
# OSD
162175
add_definitions(-D_USE_MATH_DEFINES)
163-
set(OSD_LITE_FOLDER_NAME "external/osd_lite")
164-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/extern/osd_lite EXCLUDE_FROM_ALL)
176+
include(CMake/FetchOsdLite.cmake)
177+
178+
# optional DLSS
179+
180+
option(ENABLE_DLSS "Enable DLSS support if found" ON)
181+
if(ENABLE_DLSS)
182+
include(CMake/FetchDLSS.cmake)
183+
endif()
165184

166185

167186
# Build configuration
@@ -207,6 +226,7 @@ if (MSVC)
207226
endif()
208227

209228
add_subdirectory(cluster_builder)
229+
add_subdirectory(depth)
210230
add_subdirectory(material)
211231
add_subdirectory(motionvec)
212232
add_subdirectory(profiler)
@@ -219,8 +239,8 @@ set( optixSubd_SOURCES )
219239
list( APPEND optixSubd_SOURCES
220240
args.cpp
221241
args.h
222-
denoiserstub.h
223-
denoiserstub.cu
242+
denoiser.h
243+
denoiserAccum.cu
224244
GBuffer.cu
225245
GBuffer.h
226246
GBuffer.cuh
@@ -241,10 +261,14 @@ list( APPEND optixSubd_SOURCES
241261
version.cpp
242262
)
243263

264+
if(DLSS_FOUND AND ENABLE_DLSS)
265+
list(APPEND optixSubd_SOURCES denoiserDlss.cu)
266+
endif()
244267

245268
add_executable( optixSubd
246269
${optixSubd_SOURCES}
247270
$<TARGET_OBJECTS:cluster_builder>
271+
$<TARGET_OBJECTS:depth>
248272
$<TARGET_OBJECTS:material>
249273
$<TARGET_OBJECTS:motionvec>
250274
$<TARGET_OBJECTS:profiler>
@@ -256,11 +280,13 @@ add_executable( optixSubd
256280
target_include_directories( optixSubd PRIVATE
257281
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/EmbeddedDeviceCode
258282
${CMAKE_CURRENT_SOURCE_DIR}
283+
${CUDAToolkit_INCLUDE_DIRS} # Add CUDA include paths to help find system headers
259284
)
260285

261286
target_link_libraries( optixSubd
262287
PRIVATE
263288
EmbeddedDeviceCode
289+
DepthPassDeviceCode
264290
OptiXToolkit::Gui
265291
OptiXToolkit::Util
266292
OptiXToolkit::ShaderUtil
@@ -274,6 +300,11 @@ target_link_libraries( optixSubd
274300
${CMAKE_DL_LIBS}
275301
)
276302

303+
if(DLSS_FOUND AND ENABLE_DLSS)
304+
target_compile_definitions(optixSubd PRIVATE DLSS_ENABLED)
305+
target_link_libraries(optixSubd PRIVATE DLSS::DLSS)
306+
dlss_setup_runtime_dependencies(optixSubd)
307+
endif()
277308

278309
# Optionally link tbb for parallel C++17 algorithms on gcc
279310
if ( TBB_FOUND )
@@ -301,6 +332,7 @@ endif()
301332
# dependencies are not compatible with more strict warnings.
302333
foreach(TARGET
303334
#cluster_builder
335+
depth
304336
material
305337
motionvec
306338
profiler

GBuffer.cu

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ GBuffer::GBuffer( uint2 rendersize, uint2 targetsize )
190190
::create( m_motionvecs, rendersize );
191191
::create( m_color, rendersize );
192192
::create( m_depth, rendersize );
193+
::create( m_specular, rendersize );
194+
::create( m_roughness, rendersize );
195+
::create( m_specularHitT, rendersize );
193196

194197
::create( m_depthHires, targetsize );
195198
::create( m_denoised, targetsize );
@@ -284,9 +287,11 @@ void GBuffer::blit( Channel channel, uchar4* output, uint2 outputSize, CUstream
284287
case Channel::MOTIONVECS: launchKernel( m_motionvecs ); break;
285288
case Channel::DEPTH: launchKernel( m_depth ); break;
286289
case Channel::DEPTH_HIRES: launchKernel( m_depthHires ); break;
287-
288290
case Channel::DENOISED: launchKernel( m_denoised, sRGB_Operator{} ); break;
289291
case Channel::COLOR: launchKernel( m_color, sRGB_Operator{} ); break;
292+
case Channel::SPECULAR: launchKernel( m_specular ); break;
293+
case Channel::ROUGHNESS: launchKernel( m_roughness ); break;
294+
case Channel::SPECULAR_HIT_T: launchKernel( m_specularHitT ); break;
290295
}
291296
}
292297

0 commit comments

Comments
 (0)