forked from NVIDIAGameWorks/RTXGI-DDGI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
315 lines (262 loc) · 10.9 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#
# Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
cmake_minimum_required(VERSION 3.10)
# --------------------------------------
# RTXGI SDK Project
# --------------------------------------
project(RTXGI)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /MP")
endif()
set(RTXGI_SDK_VERSION_MAJOR 1)
set(RTXGI_SDK_VERSION_MINOR 3)
set(RTXGI_SDK_VERSION_REVISION 5)
# Only 64-bit platforms are supported
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4" )
message(FATAL_ERROR "The RTXGI SDK requires a 64-bit toolset. GPU ray tracing does not support 32-bit platforms.")
endif()
# Look for Windows and Vulkan SDKs
include("FindSDKs.cmake")
# Library type (static lib or dll)
option(RTXGI_STATIC_LIB "Generate a Static Library (*.lib)" OFF)
# D3D12, only available on Windows
if(WIN32 AND RTXGI_API_D3D12_DXIL_PATH)
option(RTXGI_API_D3D12_ENABLE "Enable D3D12 support" ON)
endif()
# Vulkan
if(RTXGI_API_VULKAN_SDK)
option(RTXGI_API_VULKAN_ENABLE "Enable Vulkan support" ON)
if(NOT Vulkan_INCLUDE_DIR)
set(RTXGI_API_VULKAN_HEADERS_INCLUDE "" CACHE STRING "Path to the Vulkan Headers include directory.")
if(NOT RTXGI_API_VULKAN_HEADERS_INCLUDE STREQUAL "")
set(Vulkan_INCLUDE_DIR "${RTXGI_API_VULKAN_HEADERS_INCLUDE}")
endif()
endif()
endif()
# RTXGI Coordinate System
set(RTXGI_COORDINATE_SYSTEM "Right Hand, Y-Up" CACHE STRING "The 3D coordinate system to use")
set(RTXGI_COORDINATE_SYSTEM "Right Hand, Z-Up" CACHE STRING "The 3D coordinate system to use")
set(RTXGI_COORDINATE_SYSTEM "Left Hand, Y-Up" CACHE STRING "The 3D coordinate system to use")
set(RTXGI_COORDINATE_SYSTEM "Left Hand, Z-Up" CACHE STRING "The 3D coordinate system to use")
set_property(CACHE RTXGI_COORDINATE_SYSTEM PROPERTY STRINGS "Right Hand, Y-Up" "Right Hand, Z-Up" "Left Hand, Y-Up" "Left Hand, Z-Up")
# RTXGI features
option(RTXGI_GFX_NAME_OBJECTS "Enable naming of graphics objects (for debugging)" ON)
# RTXGI DDGI features
option(RTXGI_DDGI_RESOURCE_MANAGEMENT "Enable SDK resource management" OFF)
option(RTXGI_DDGI_USE_SHADER_CONFIG_FILE "Enable using a config file to specify shader defines" OFF)
file(GLOB SOURCE
"include/rtxgi/Common.h"
"include/rtxgi/Defines.h"
"include/rtxgi/Math.h"
"include/rtxgi/Types.h"
"src/Math.cpp"
)
file(GLOB GFX_VULKAN_SOURCE
"include/rtxgi/VulkanExtensions.h"
"src/VulkanExtensions.cpp"
)
file(GLOB DDGI_HEADERS
"include/rtxgi/ddgi/DDGIVolume.h"
"include/rtxgi/ddgi/DDGIRootConstants.h"
"include/rtxgi/ddgi/DDGIVolumeDescGPU.h"
)
file(GLOB DDGI_HEADERS_D3D12
"include/rtxgi/ddgi/gfx/DDGIVolume_D3D12.h"
)
file(GLOB DDGI_HEADERS_VULKAN
"include/rtxgi/ddgi/gfx/DDGIVolume_VK.h"
)
file(GLOB DDGI_SOURCE
"src/ddgi/DDGIVolume.cpp"
)
file(GLOB DDGI_SOURCE_D3D12
"src/ddgi/gfx/DDGIVolume_D3D12.cpp"
)
file(GLOB DDGI_SOURCE_VULKAN
"src/ddgi/gfx/DDGIVolume_VK.cpp"
)
file(GLOB SHADER_SOURCE
"shaders/Common.hlsl"
"shaders/Platform.hlsl"
)
file(GLOB DDGI_SHADER_INCLUDE
"shaders/ddgi/include/Common.hlsl"
"shaders/ddgi/include/ProbeCommon.hlsl"
"shaders/ddgi/include/ProbeDataCommon.hlsl"
"shaders/ddgi/include/ProbeIndexing.hlsl"
"shaders/ddgi/include/ProbeOctahedral.hlsl"
"shaders/ddgi/include/ProbeRayCommon.hlsl"
"shaders/ddgi/include/DDGIRootConstants.hlsl"
)
file(GLOB DDGI_SHADER_INCLUDE_VALIDATION
"shaders/ddgi/include/validation/ProbeBlendingDefines.hlsl"
"shaders/ddgi/include/validation/ProbeClassificationDefines.hlsl"
"shaders/ddgi/include/validation/ProbeRelocationDefines.hlsl"
"shaders/ddgi/include/validation/ReductionDefines.hlsl"
)
file(GLOB DDGI_SHADER_SOURCE
"shaders/ddgi/Irradiance.hlsl"
"shaders/ddgi/ProbeBlendingCS.hlsl"
"shaders/ddgi/ProbeClassificationCS.hlsl"
"shaders/ddgi/ProbeRelocationCS.hlsl"
"shaders/ddgi/ReductionCS.hlsl"
)
# Shaders do not participate in the build
set_source_files_properties(${SHADER_SOURCE} PROPERTIES VS_TOOL_OVERRIDE "None")
set_source_files_properties(${DDGI_SHADER_INCLUDE} ${DDGI_SHADER_INCLUDE_VALIDATION} ${DDGI_SHADER_SOURCE} PROPERTIES VS_TOOL_OVERRIDE "None")
# Setup the RTXGI library target and options
function(SetupRTXGIOptions ARG_TARGET_LIB )
# Add include directories
target_include_directories(${ARG_TARGET_LIB} PUBLIC "include")
# Set Coordinate System
if(${RTXGI_COORDINATE_SYSTEM} MATCHES "Left Hand, Y-Up")
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_COORDINATE_SYSTEM=0)
elseif(${RTXGI_COORDINATE_SYSTEM} MATCHES "Left Hand, Z-Up")
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_COORDINATE_SYSTEM=1)
elseif(${RTXGI_COORDINATE_SYSTEM} MATCHES "Right Hand, Y-Up")
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_COORDINATE_SYSTEM=2)
elseif(${RTXGI_COORDINATE_SYSTEM} MATCHES "Right Hand, Z-Up")
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_COORDINATE_SYSTEM=3)
else()
# Default to right hand, y-up (if they write in some unsupported option)
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_COORDINATE_SYSTEM=2)
endif()
# Set GFX Object Naming
if(RTXGI_GFX_NAME_OBJECTS)
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_GFX_NAME_OBJECTS)
endif()
# Set Resource Management Mode
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_DDGI_RESOURCE_MANAGEMENT=$<BOOL:${RTXGI_DDGI_RESOURCE_MANAGEMENT}>)
# Set config file use
target_compile_definitions(${ARG_TARGET_LIB} PUBLIC RTXGI_DDGI_USE_SHADER_CONFIG_FILE=$<BOOL:${RTXGI_DDGI_USE_SHADER_CONFIG_FILE}>)
endfunction()
# Setup the D3D12 library
if(WIN32 AND RTXGI_API_D3D12_ENABLE)
# Set the target library's name
set(TARGET_LIB RTXGI-D3D12)
if(RTXGI_STATIC_LIB)
# Add the static library output target
add_library(${TARGET_LIB} STATIC
${SOURCE}
${DDGI_HEADERS}
${DDGI_HEADERS_D3D12}
${DDGI_SOURCE}
${DDGI_SOURCE_D3D12}
${SHADER_SOURCE}
${DDGI_SHADER_INCLUDE}
${DDGI_SHADER_INCLUDE_VALIDATION}
${DDGI_SHADER_SOURCE})
else()
# Add the dynamic library output target
add_library(${TARGET_LIB} SHARED
${SOURCE}
${DDGI_HEADERS}
${DDGI_HEADERS_D3D12}
${DDGI_SOURCE}
${DDGI_SOURCE_D3D12}
${SHADER_SOURCE}
${DDGI_SHADER_INCLUDE}
${DDGI_SHADER_INCLUDE_VALIDATION}
${DDGI_SHADER_SOURCE})
endif()
# Setup the library and its options
SetupRTXGIOptions(${TARGET_LIB})
# Add statically linked libs
target_link_libraries(${TARGET_LIB} PRIVATE d3d12)
# Set the lib's filename
set_target_properties(${TARGET_LIB} PROPERTIES OUTPUT_NAME "rtxgi-d3d12")
# Add the project to a folder
set_target_properties(${TARGET_LIB} PROPERTIES FOLDER "RTXGI SDK")
if(NOT RTXGI_STATIC_LIB)
target_compile_definitions(${TARGET_LIB} PUBLIC RTXGI_EXPORT_DLL)
set(RTXGI_SDK_D3D12_BINARY ${CMAKE_CURRENT_BINARY_DIR}/bin/$<CONFIG>/rtxgi-d3d12.dll PARENT_SCOPE)
set(RTXGI_SDK_D3D12_SYMBOLS ${CMAKE_CURRENT_BINARY_DIR}/bin/$<CONFIG>/rtxgi-d3d12.pdb PARENT_SCOPE)
endif()
endif()
# Setup the Vulkan library
if(RTXGI_API_VULKAN_ENABLE)
# Set the target library's name
set(TARGET_LIB RTXGI-VK)
if(RTXGI_STATIC_LIB)
# Add the static library output target
add_library(${TARGET_LIB} STATIC
${SOURCE}
${GFX_VULKAN_SOURCE}
${DDGI_HEADERS}
${DDGI_HEADERS_VULKAN}
${DDGI_SOURCE}
${DDGI_SOURCE_VULKAN}
${SHADER_SOURCE}
${DDGI_SHADER_INCLUDE}
${DDGI_SHADER_INCLUDE_VALIDATION}
${DDGI_SHADER_SOURCE})
else()
# Add the dynamic library output target
add_library(${TARGET_LIB} SHARED
${SOURCE}
${GFX_VULKAN_SOURCE}
${DDGI_HEADERS}
${DDGI_HEADERS_VULKAN}
${DDGI_SOURCE}
${DDGI_SOURCE_VULKAN}
${SHADER_SOURCE}
${DDGI_SHADER_INCLUDE}
${DDGI_SHADER_INCLUDE_VALIDATION}
${DDGI_SHADER_SOURCE})
endif()
# Setup the library and its options
SetupRTXGIOptions(${TARGET_LIB})
# Set compiler options
if(NOT MSVC)
target_compile_options(${TARGET_LIB} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wconversion)
endif()
# Add the include directories
target_include_directories(${TARGET_LIB} PUBLIC ${Vulkan_INCLUDE_DIR})
# Add statically linked libs
if(WIN32)
target_link_libraries(${TARGET_LIB} PRIVATE ${Vulkan_LIBRARY})
elseif(UNIX AND NOT APPLE)
target_link_libraries(${TARGET_LIB} PRIVATE -lvulkan)
endif()
# Set the lib's filename
set_target_properties(${TARGET_LIB} PROPERTIES OUTPUT_NAME "rtxgi-vulkan")
# Add the project to a folder
set_target_properties(${TARGET_LIB} PROPERTIES FOLDER "RTXGI SDK")
if(NOT RTXGI_STATIC_LIB)
target_compile_definitions(${TARGET_LIB} PUBLIC RTXGI_EXPORT_DLL)
if(WIN32)
set(RTXGI_SDK_VK_BINARY ${CMAKE_CURRENT_BINARY_DIR}/bin/$<CONFIG>/rtxgi-vulkan.dll PARENT_SCOPE)
set(RTXGI_SDK_VK_SYMBOLS ${CMAKE_CURRENT_BINARY_DIR}/bin/$<CONFIG>/rtxgi-vulkan.pdb PARENT_SCOPE)
elseif(UNIX AND NOT APPLE)
set(RTXGI_SDK_VK_BINARY ${CMAKE_CURRENT_BINARY_DIR}/librtxgi-vulkan.so PARENT_SCOPE)
endif()
endif()
endif()
if(WIN32)
# Add Visual Studio filters
source_group("Header Files/rtxgi/ddgi" FILES ${DDGI_HEADERS})
source_group("Header Files/rtxgi/ddgi/gfx" FILES ${DDGI_HEADERS_D3D12} ${DDGI_HEADERS_VULKAN})
source_group("Source Files/ddgi" FILES ${DDGI_SOURCE})
source_group("Source Files/ddgi/gfx" FILES ${DDGI_SOURCE_D3D12} ${DDGI_SOURCE_VULKAN})
source_group("Shaders" FILES ${SHADER_SOURCE})
source_group("Shaders/ddgi" FILES ${DDGI_SHADER_SOURCE})
source_group("Shaders/ddgi/include" FILES ${DDGI_SHADER_INCLUDE})
source_group("Shaders/ddgi/include/validation" FILES ${DDGI_SHADER_INCLUDE_VALIDATION})
# Set the default project. If D3D12 is an option, set it as default.
if(RTXGI_API_D3D12_ENABLE)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT RTXGI-D3D12)
elseif(NOT RTXGI_API_D3D12_ENABLE AND RTXGI_API_VULKAN_ENABLE)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT RTXGI-VK)
endif()
endif()