forked from mmp/pbrt-v4
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
1174 lines (997 loc) · 44.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# pbrt-v4 top-level CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(PBRT-V4 LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL "" FORCE)
# HIP
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
set(AMDGPU_TARGETS
"gfx1100"
CACHE STRING "List of specific machine types for library to target") # User variable
# For sanitizers
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")
# Configuration options
option(PBRT_HIPRT "Use HIPRT as backend" OFF)
option(PBRT_FLOAT_AS_DOUBLE "Use 64-bit floats" OFF)
option(PBRT_BUILD_NATIVE_EXECUTABLE "Build executable optimized for CPU architecture of system pbrt was built on" ON)
option(PBRT_DBG_LOGGING "Enable (very verbose!) debug logging" OFF)
option(PBRT_NVTX "Insert NVTX annotations for NVIDIA Profiling and Debugging Tools" OFF)
option(PBRT_NVML "Use NVML for GPU performance measurement" OFF)
option(PBRT_USE_PREGENERATED_RGB_TO_SPECTRUM_TABLES "Use pregenerated rgbspectrum_*.cpp files rather than running rgb2spec_opt to generate them at build time" OFF)
set(PBRT_OPTIX7_PATH
$ENV{PBRT_OPTIX7_PATH}
CACHE PATH "Path to OptiX 7 SDK")
set(PBRT_HIP_PATH
$ENV{PBRT_HIP_PATH}
CACHE PATH "Path to HIP SDK")
set(PBRT_GPU_SHADER_MODEL
""
CACHE STRING "")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
function(CHECK_EXT NAME DIR HASH)
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/${DIR}")
message(FATAL_ERROR "The ${NAME} submodule directory is missing! " "Either that submodule was recently added to pbrt or you did not clone the project with --recursive. "
"In order to update the submodules, run:\n" " \"git submodule update --init --recursive\"")
endif()
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/${DIR}"
RESULT_VARIABLE "git_return"
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE "git_hash")
if(NOT ${git_hash} MATCHES "^${HASH}")
message(FATAL_ERROR "The ${CMAKE_CURRENT_SOURCE_DIR}/src/ext/${DIR} " "submodule isn't up to date (${git_hash} vs ${HASH}). Please run:\n" " \"git submodule update --recursive\"")
else()
message(STATUS "${NAME} at commit: ${git_hash}")
endif()
else(GIT_FOUND)
message(STATUS "git not found: unable to verify revisions in submodules")
endif(GIT_FOUND)
endfunction()
function(APPLY_PATCH NAME DIR HASH)
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/${DIR}")
message(FATAL_ERROR "The ${NAME} submodule directory is missing! " "Either that submodule was recently added to pbrt or you did not clone the project with --recursive. "
"In order to update the submodules, run:\n" " \"git submodule update --init --recursive\"")
endif()
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/ext/${DIR}"
RESULT_VARIABLE "git_return"
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE "git_hash")
if(NOT ${git_hash} MATCHES "^${HASH}")
message(FATAL_ERROR "The ${CMAKE_CURRENT_SOURCE_DIR}/src/ext/${DIR} " "submodule isn't up to date (${git_hash} vs ${HASH}). Please run:\n" " \"git submodule update --recursive\"")
else()
message(STATUS "${NAME} at commit: ${git_hash}")
endif()
else(GIT_FOUND)
message(STATUS "git not found: unable to verify revisions in submodules")
endif(GIT_FOUND)
endfunction()
check_ext("OpenEXR" "openexr/OpenEXR" 5cfb5dab6dfada731586b0281bdb15ee75e26782)
check_ext("OpenVDB" "openvdb/nanovdb" 385516321b272c423e2a514b41bd21ce6ffdda72)
check_ext("Ptex" "ptex/src" 4cd8e9a6db2b06e478dfbbd8c26eb6df97f84483)
check_ext("double-conversion" "double-conversion/cmake" cc1f75a114aca8d2af69f73a5a959aecbab0e87a)
check_ext("filesystem" "filesystem/filesystem" c5f9de30142453eb3c6fe991e82dfc2583373116)
check_ext("glfw" "glfw/docs" 4cb36872a5fe448c205d0b46f0e8c8b57530cfe0)
check_ext("libdeflate" "libdeflate/common" 1fd0bea6ca2073c68493632dafc4b1ddda1bcbc3)
check_ext("lodepng" "lodepng/examples" 8c6a9e30576f07bf470ad6f09458a2dcd7a6a84a)
check_ext("qoi" "qoi" 028c75fd26e5e0758c7c711216c00404994c1ad3)
check_ext("stb" "stb/tools" af1a5bc352164740c1cc1354942b1c6b72eacb8a)
check_ext("utf8proc" "utf8proc/bench" 2484e2ed5e1d9c19edcccf392a7d9920ad90dfaf)
check_ext("zlib" "zlib/doc" 54d591eabf9fe0e84c725638f8d5d8d202a093fa)
add_compile_definitions("$<$<CONFIG:DEBUG>:PBRT_DEBUG_BUILD>")
enable_testing()
find_package(Sanitizers)
find_package(Threads)
find_package(OpenGL REQUIRED)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(WIN32)
list(APPEND PBRT_DEFINITIONS "PBRT_IS_MSVC" "_CRT_SECURE_NO_WARNINGS")
list(APPEND PBRT_DEFINITIONS "PBRT_IS_MSVC" "_ENABLE_EXTENDED_ALIGNED_STORAGE")
endif()
if(PBRT_FLOAT_AS_DOUBLE)
list(APPEND PBRT_DEFINITIONS "PBRT_FLOAT_AS_DOUBLE")
endif()
if(PBRT_DBG_LOGGING)
list(APPEND PBRT_DEFINITIONS "PBRT_DBG_LOGGING")
endif()
# ######################################################################################################################################################################################################
# ext
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ext)
# ######################################################################################################################################################################################################
# os/compiler-specific stuff
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
list(APPEND PBRT_DEFINITIONS "PBRT_IS_WINDOWS" "NOMINMAX")
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
list(APPEND PBRT_DEFINITIONS "PBRT_IS_OSX")
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
list(APPEND PBRT_DEFINITIONS "PBRT_IS_LINUX")
# -rdynamic so we can get backtrace symbols... --no-as-needed so libprofiler sticks around string (APPEND CMAKE_EXE_LINKER_FLAGS " -rdynamic -Wl,--no-as-needed")
else()
message(SEND_ERROR "Unknown system name: " + CMAKE_SYSTEM_NAME)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_definitions(-Wno-deprecated-declarations) # silent deprecated 'snprintf' message under MacOS arm64
endif()
# libgoogle-perftools-dev
find_library (PROFILE_LIB profiler)
if (NOT PROFILE_LIB)
message (STATUS "Unable to find -lprofiler")
else ()
message (STATUS "Found -lprofiler: ${PROFILE_LIB}")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 14)
message (STATUS "Disabling -ffp-contract (thanks, clang 14!)")
list (APPEND PBRT_CXX_FLAGS "-ffp-contract=off")
endif ()
add_library (pbrt_warnings INTERFACE)
target_compile_options (
pbrt_warnings
INTERFACE
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4244>" # int -> float conversion
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4267>" # size_t -> int conversion
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4305>" # double constant assigned to float
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4552>" # result of expression not used
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4838>" # double -> int conversion
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4843>" # double -> float conversion
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd26451>" # arithmetic on 4-byte value, then cast to 8-byte
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd26495>" # uninitialized member variable
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4334>" # 32 to 64 bit displacement
"$<$<CXX_COMPILER_ID:MSVC>:$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >/wd4146>" # NanoVDB: unary minus operator applied to unsigned type, result still unsigned
)
add_library(pbrt_opt INTERFACE)
# ######################################################################################################################################################################################################
# CUDA / OptiX / HIP
add_library(cuda_build_configuration INTERFACE)
include(CheckLanguage)
if(PBRT_HIPRT)
find_package(hip REQUIRED)
set(CUDA_COMPILE_LANGUAGE CXX)
set(PBRT_HIPRT_PATH "src/ext/hiprtSdk")
if(WIN32)
set(PBRT_HIPRT_BINARY_PATH ${PBRT_HIPRT_PATH}/hiprt/win)
else()
set(PBRT_HIPRT_BINARY_PATH ${PBRT_HIPRT_PATH}/hiprt/linux64)
endif()
link_directories(${PBRT_HIPRT_BINARY_PATH})
include_directories(${PBRT_HIPRT_PATH})
list(APPEND PBRT_DEFINITIONS "PBRT_BUILD_GPU_RENDERER")
list(APPEND PBRT_DEFINITIONS "__HIP_PLATFORM_AMD__")
list(APPEND PBRT_DEFINITIONS "GTEST_HAS_SEH=0")
list(APPEND PBRT_CXX_FLAGS "-std=c++17")
list(APPEND PBRT_CXX_FLAGS "-fgpu-rdc")
list(APPEND PBRT_LINK_FLAGS "-fgpu-rdc")
if (WIN32)
list (APPEND PBRT_LINK_FLAGS "-fuse-ld=lld")
endif()
list(APPEND PBRT_LINK_FLAGS "--hip-link")
list(APPEND PBRT_LINK_FLAGS "-Xoffload-linker")
list(APPEND PBRT_LINK_FLAGS "--whole-archive")
set(PBRT_HIP_ENABLED ON)
file(GLOB PBRT_HIPRT_BITCODES ${PBRT_HIPRT_BINARY_PATH}/*.bc)
file(GLOB PBRT_HIPRT_FATBINS ${PBRT_HIPRT_BINARY_PATH}/*.hipfb)
file(COPY ${PBRT_HIPRT_BITCODES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${PBRT_HIPRT_FATBINS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(WIN32)
file(GLOB PBRT_HIPRT_DLLS ${PBRT_HIPRT_BINARY_PATH}/*.dll)
file(COPY ${PBRT_HIPRT_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
else()
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
if(CUDA_VERSION_MAJOR LESS 11)
message(WARNING "pbrt-v4 requires CUDA version 11.0 or later but version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\
was found. GPU support is therefore disabled. If you have multiple versions\
of CUDA installed, please update your PATH.")
else()
find_package(CUDA REQUIRED)
# This seems to be necessary starting with 3.17.1, but gives an error about 17 being an unsupported version earlier...
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
set(CMAKE_CUDA_STANDARD 17)
endif()
# https://github.com/VIAME/VIAME/blob/aa6c5f56a898b08e4da102c400b453e23952199c/CMakeLists.txt#L291
if(NOT CUDA_VERSION_PATCH)
if(CUDA_NVCC_EXECUTABLE
AND CUDA_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER
AND CMAKE_CUDA_COMPILER_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
set(CUDA_VERSION_PATCH "${CMAKE_MATCH_3}")
elseif(CUDA_NVCC_EXECUTABLE)
execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NOUT)
if(NOUT MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=])
set(CUDA_VERSION_PATCH "${CMAKE_MATCH_3}")
endif()
endif()
endif()
message(STATUS "Found CUDA: ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.${CUDA_VERSION_PATCH}")
if(CUDA_VERSION_MAJOR EQUAL 11
AND CUDA_VERSION_MINOR EQUAL 3
AND CUDA_VERSION_PATCH LESS 109)
message(SEND_ERROR "Unfortunately, pbrt-v4 triggers an internal compiler error in CUDA 11.3.0. Please either use CUDA 11.0-11.2 or 11.3.1 or later.")
endif()
if("${PBRT_OPTIX7_PATH}" STREQUAL "")
message(WARNING "Found CUDA but PBRT_OPTIX7_PATH is not set. Disabling GPU compilation.")
elseif("${PBRT_HIP_PATH}" STREQUAL "")
message(WARNING "Found CUDA but PBRT_HIP_PATH is not set. Disabling GPU compilation.")
else()
enable_language(CUDA)
list(APPEND PBRT_DEFINITIONS "PBRT_BUILD_GPU_RENDERER")
if(PBRT_NVTX)
list(APPEND PBRT_DEFINITIONS "NVTX")
endif()
if(PBRT_NVML)
list(APPEND PBRT_DEFINITIONS "PBRT_USE_NVML")
endif()
set(PBRT_CUDA_ENABLED ON)
# FIXME
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) # for regular c++ compiles
# http://www.ssl.berkeley.edu/~jimm/grizzly_docs/SSL/opt/intel/cc/9.0/lib/locale/en_US/mcpcom.msg
target_compile_options(
pbrt_warnings
INTERFACE # "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xptxas --warn-on-double-precision-use>"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcudafe --diag_suppress=partial_override>"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcudafe --diag_suppress=virtual_function_decl_hidden>"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcudafe --diag_suppress=integer_sign_change>"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcudafe --diag_suppress=declared_but_not_referenced>"
# WAR invalid warnings about this with "if constexpr"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcudafe --diag_suppress=implicit_return_from_non_void_function>")
# Willie hears yeh..
string(APPEND CMAKE_CUDA_FLAGS " -Xnvlink -suppress-stack-size-warning")
target_compile_options(
cuda_build_configuration
INTERFACE "$<$<COMPILE_LANGUAGE:CUDA>:--std=c++17;--use_fast_math;--expt-relaxed-constexpr;--extended-lambda;--forward-unknown-to-host-compiler>"
# The "$<NOT:$<BOOL:$<TARGET_PROPERTY:CUDA_PTX_COMPILATION>>>" part is to not add debugging symbols when generating PTX files for OptiX; see
# https://github.com/mmp/pbrt-v4/issues/69#issuecomment-715499748.
"$<$<COMPILE_LANGUAGE:CUDA>:$<IF:$<AND:$<CONFIG:Debug>,$<NOT:$<BOOL:$<TARGET_PROPERTY:CUDA_PTX_COMPILATION>>>>,-G;-g,-lineinfo;-maxrregcount;128>>")
if(PBRT_GPU_SHADER_MODEL STREQUAL "")
# https://wagonhelm.github.io/articles/2018-03/detecting-cuda-capability-with-cmake Get CUDA compute capability
set(CHECK_CUDA_OUTPUT_EXE ${CMAKE_BINARY_DIR}/checkcuda)
if(MSVC)
execute_process(COMMAND ${CMAKE_CUDA_COMPILER} -lcuda ${CMAKE_SOURCE_DIR}/cmake/checkcuda.cu -ccbin ${CMAKE_CXX_COMPILER} -o ${CHECK_CUDA_OUTPUT_EXE}
RESULT_VARIABLE BUILD_CHECK_CUDA_RETURN_CODE)
else()
execute_process(COMMAND ${CMAKE_CUDA_COMPILER} -lcuda ${CMAKE_SOURCE_DIR}/cmake/checkcuda.cu -o ${CHECK_CUDA_OUTPUT_EXE} RESULT_VARIABLE BUILD_CHECK_CUDA_RETURN_CODE)
endif()
if(NOT ${BUILD_CHECK_CUDA_RETURN_CODE} EQUAL 0)
message(SEND_ERROR "Was unable to build checkcuda, consider manually setting PBRT_GPU_SHADER_MODEL")
endif()
execute_process(
COMMAND ${CHECK_CUDA_OUTPUT_EXE}
RESULT_VARIABLE CUDA_RETURN_CODE
OUTPUT_VARIABLE CHECK_CUDA_OUTPUT)
if(NOT ${CUDA_RETURN_CODE} EQUAL 0)
message(SEND_ERROR ${CHECK_CUDA_OUTPUT})
else()
set(ARCH "${CHECK_CUDA_OUTPUT}")
message(STATUS "Detected CUDA Architecture: ${ARCH}")
string(APPEND CMAKE_CUDA_FLAGS " --gpu-architecture=${ARCH}")
list(APPEND PBRT_DEFINITIONS "__HIP_PLATFORM_NVIDIA__")
list(APPEND PBRT_DEFINITIONS "__HIP_PLATFORM_NVCC__")
endif()
else()
set(ARCH "${PBRT_GPU_SHADER_MODEL}")
message(STATUS "Specified CUDA Architecture: ${ARCH}")
string(APPEND CMAKE_CUDA_FLAGS " --gpu-architecture=${ARCH}")
list(APPEND PBRT_DEFINITIONS "__HIP_PLATFORM_NVIDIA__")
list(APPEND PBRT_DEFINITIONS "__HIP_PLATFORM_NVCC__")
endif()
set(PBRT_CUDA_LIB cuda)
# optix FIXME
include_directories(${PBRT_OPTIX7_PATH}/include)
include_directories(${PBRT_HIP_PATH}/include)
# find CUDA's bin2c executable
get_filename_component(cuda_compiler_bin "${CMAKE_CUDA_COMPILER}" DIRECTORY)
find_program(
BIN2C
NAMES bin2c
PATHS ${cuda_compiler_bin}
DOC "Path to the CUDA SDK bin2c executable."
NO_DEFAULT_PATH)
if(NOT BIN2C)
message(FATAL_ERROR "bin2c not found:\n" " CMAKE_CUDA_COMPILER='${CMAKE_CUDA_COMPILER}'\n" " cuda_compiler_bin='${cuda_compiler_bin}'\n")
endif()
# this macro defines cmake rules that execute the following four steps: 1) compile the given cuda file ${cuda_file} to an intermediary PTX file 2) use the 'bin2c' tool (that comes with CUDA)
# to create a second intermediary (.c-)file which defines a const string variable (named '${c_var_name}') whose (constant) value is the PTX output from the previous step. 3) compile the given
# .c file to an intermediary object file (why thus has that PTX string 'embedded' as a global constant. 4) assign the name of the intermediary .o file to the cmake variable 'output_var', which
# can then be added to cmake targets.
macro(cuda_compile_and_embed output_var cuda_file lib_name)
add_library("${lib_name}" OBJECT "${cuda_file}")
set_property(TARGET "${lib_name}" PROPERTY CUDA_PTX_COMPILATION ON)
# disable "extern declaration... is treated as a static definition" warning
if(CUDA_VERSION_MAJOR EQUAL 11 AND CUDA_VERSION_MINOR LESS 2)
target_compile_options("${lib_name}" PRIVATE -Xcudafe=--display_error_number -Xcudafe=--diag_suppress=3089)
else()
target_compile_options("${lib_name}" PRIVATE -Xcudafe=--display_error_number -Xcudafe=--diag_suppress=20044)
endif()
# CUDA integration in Visual Studio seems broken as even if "Use Host Preprocessor Definitions" is checked, the host preprocessor definitions are still not used when compiling device code.
# To work around that, define the macros using --define-macro to avoid CMake identifying those as macros and using the proper (but broken) way of specifying them.
if(${CMAKE_GENERATOR} MATCHES "^Visual Studio")
# As PBRT_DEBUG_BUILD is specified globally as a definition, we need to manually add it due to the bug mentioned earlier and due to it not being found in PBRT_DEFINITIONS.
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(cuda_definitions "--define-macro=PBRT_DEBUG_BUILD")
endif()
foreach(arg ${PBRT_DEFINITIONS})
list(APPEND cuda_definitions "--define-macro=${arg}")
endforeach()
target_compile_options("${lib_name}" PRIVATE ${cuda_definitions})
else()
target_compile_definitions("${lib_name}" PRIVATE ${PBRT_DEFINITIONS})
endif()
target_include_directories("${lib_name}" PRIVATE src ${CMAKE_BINARY_DIR})
target_include_directories("${lib_name}" SYSTEM PRIVATE ${NANOVDB_INCLUDE})
target_link_libraries("${lib_name}" PRIVATE cuda_build_configuration pbrt_opt pbrt_warnings)
add_dependencies("${lib_name}" pbrt_soa_generated)
set(c_var_name ${output_var})
set(embedded_file ${cuda_file}.ptx_embedded.c)
add_custom_command(
OUTPUT "${embedded_file}"
COMMAND ${CMAKE_COMMAND} "-DBIN_TO_C_COMMAND=${BIN2C}" "-DOBJECTS=$<TARGET_OBJECTS:${lib_name}>" "-DVAR_NAME=${c_var_name}" "-DOUTPUT=${embedded_file}" -P
${CMAKE_CURRENT_SOURCE_DIR}/cmake/bin2c_wrapper.cmake
VERBATIM
DEPENDS "${lib_name}" $<TARGET_OBJECTS:${lib_name}>
COMMENT "Embedding PTX generated from ${cuda_file}")
set(${output_var} ${embedded_file})
endmacro()
endif()
endif()
else()
message(STATUS "CUDA not found")
endif()
endif()
# ######################################################################################################################################################################################################
# Annoying compiler-specific details
include(CheckCXXCompilerFlag)
if(NOT PBRT_HIP_ENABLED)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE AND PBRT_BUILD_NATIVE_EXECUTABLE)
target_compile_options(pbrt_opt INTERFACE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >-march=native")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
list(APPEND PBRT_CXX_FLAGS "-std=c++17")
find_program(XIAR xiar)
if(XIAR)
set(CMAKE_AR "${XIAR}")
endif(XIAR)
mark_as_advanced(XIAR)
find_program(XILD xild)
if(XILD)
set(CMAKE_LINKER "${XILD}")
endif(XILD)
mark_as_advanced(XILD)
# ICC will default to -fp-model fast=1, which performs value-unsafe optimizations which will cause pbrt_test to fail. For safety, -fp-model precise is explicitly set here by default.
set(FP_MODEL
"precise"
CACHE STRING "The floating point model to compile with.")
set_property(CACHE FP_MODEL PROPERTY STRINGS "precise" "fast=1" "fast=2")
list(APPEND PBRT_CXX_FLAGS "-fp-model" "${FP_MODEL}")
endif()
if(MSVC AND MSVC_VERSION LESS 1920)
message(SEND_ERROR "pbrt-v4 currently requires MSVC 2019 to build on Windows. PRs that get MSVC 2017 working as well would be welcomed. :-)")
endif()
# ######################################################################################################################################################################################################
# Check for various C++ features and set preprocessor variables or define workarounds.
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
int main() {
int fd = open(\"foo\", O_RDONLY);
struct stat s;
fstat(fd, &s);
size_t len = s.st_size;
void *ptr = mmap(0, len, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0);
munmap(ptr, len);
}
"
HAVE_MMAP)
if(HAVE_MMAP)
list(APPEND PBRT_DEFINITIONS "PBRT_HAVE_MMAP")
endif()
include(CheckIncludeFiles)
check_cxx_source_compiles(
"
#include <intrin.h>
int main() {
unsigned long lz = 0, v = 1234;
if (_BitScanReverse(&lz, v)) return lz;
return 0;
} "
HAS_INTRIN_H)
if(HAS_INTRIN_H)
list(APPEND PBRT_DEFINITIONS "PBRT_HAS_INTRIN_H")
endif()
# ######################################################################################################################################################################################################
# noinline
check_cxx_source_compiles("__declspec(noinline) void foo() { }
int main() { }" HAVE_DECLSPEC_NOINLINE)
check_cxx_source_compiles("__attribute__((noinline)) void foo() { }
int main() { }" HAVE_ATTRIBUTE_NOINLINE)
if(HAVE_ATTRIBUTE_NOINLINE)
list(APPEND PBRT_DEFINITIONS "PBRT_NOINLINE=__attribute__((noinline))")
elseif(HAVE_DECLSPEC_NOINLINE)
list(APPEND PBRT_DEFINITIONS "PBRT_NOINLINE=__declspec(noinline)")
else()
list(APPEND PBRT_DEFINITIONS "PBRT_NOINLINE")
endif()
# ######################################################################################################################################################################################################
# restrict
check_cxx_source_compiles("int * __restrict__ ptr;
int main() { }" HAVE_PRE_POST_BAR_RESTRICT)
check_cxx_source_compiles("int * __restrict ptr;
int main() { }" HAVE_PRE_BAR_RESTRICT)
if(HAVE_PRE_POST_BAR_RESTRICT)
list(APPEND PBRT_DEFINITIONS "PBRT_RESTRICT=__restrict__")
elseif(HAVE_PRE_BAR_RESTRICT)
list(APPEND PBRT_DEFINITIONS "PBRT_RESTRICT=__restrict")
else()
list(APPEND PBRT_DEFINITIONS "PBRT_RESTRICT")
endif()
# ######################################################################################################################################################################################################
# Aligned memory allocation
check_cxx_source_compiles(
"
#include <malloc.h>
int main() { void * ptr = _aligned_malloc(1024, 32); }
"
HAVE__ALIGNED_MALLOC)
check_cxx_source_compiles(
"
#include <stdlib.h>
int main() {
void *ptr;
posix_memalign(&ptr, 32, 1024);
} "
HAVE_POSIX_MEMALIGN)
if(HAVE__ALIGNED_MALLOC)
list(APPEND PBRT_DEFINITIONS "PBRT_HAVE__ALIGNED_MALLOC")
elseif(HAVE_POSIX_MEMALIGN)
list(APPEND PBRT_DEFINITIONS "PBRT_HAVE_POSIX_MEMALIGN")
else()
message(SEND_ERROR "Unable to find a way to allocate aligned memory")
endif()
# ######################################################################################################################################################################################################
# are long and int64_t the same
check_cxx_source_compiles(
"
#include <cstdint>
#include <type_traits>
static_assert(!std::is_same<long, int64_t>::value && !std::is_same<long long, int64_t>::value);
int main() { }
"
INT64_IS_OWN_TYPE)
if(INT64_IS_OWN_TYPE)
list(APPEND PBRT_DEFINITIONS "PBRT_INT64_IS_OWN_TYPE")
endif()
if(PBRT_NVTX)
add_definitions(-D NVTX)
endif()
# ######################################################################################################################################################################################################
# On to pbrt...
set (PBRT_SOURCE
src/pbrt/bsdf.cpp
src/pbrt/bssrdf.cpp
src/pbrt/bxdfs.cpp
src/pbrt/cameras.cpp
src/pbrt/film.cpp
src/pbrt/filters.cpp
src/pbrt/interaction.cpp
src/pbrt/lights.cpp
src/pbrt/lightsamplers.cpp
src/pbrt/materials.cpp
src/pbrt/media.cpp
src/pbrt/options.cpp
src/pbrt/paramdict.cpp
src/pbrt/parser.cpp
src/pbrt/pbrt.cpp
src/pbrt/ray.cpp
src/pbrt/samplers.cpp
src/pbrt/scene.cpp
src/pbrt/shapes.cpp
src/pbrt/textures.cpp
src/pbrt/cmd/pspec_gpu.cpp
)
if (MSVC)
set (PBRT_SOURCE ${PBRT_SOURCE} src/pbrt/visualstudio.natvis)
endif ()
set (PBRT_SOURCE_HEADERS
src/pbrt/bsdf.h
src/pbrt/bssrdf.h
src/pbrt/bxdfs.h
src/pbrt/cameras.h
src/pbrt/film.h
src/pbrt/filters.h
src/pbrt/interaction.h
src/pbrt/lightsamplers.h
src/pbrt/lights.h
src/pbrt/materials.h
src/pbrt/media.h
src/pbrt/options.h
src/pbrt/paramdict.h
src/pbrt/parser.h
src/pbrt/pbrt.h
src/pbrt/pbrt.soa
src/pbrt/ray.h
src/pbrt/samplers.h
src/pbrt/scene.h
src/pbrt/shapes.h
src/pbrt/textures.h
)
SET (PBRT_CPU_SOURCE
src/pbrt/cpu/aggregates.cpp
src/pbrt/cpu/integrators.cpp
src/pbrt/cpu/primitive.cpp
src/pbrt/cpu/render.cpp
)
SET (PBRT_CPU_SOURCE_HEADERS
src/pbrt/cpu/aggregates.h
src/pbrt/cpu/integrators.h
src/pbrt/cpu/primitive.h
src/pbrt/cpu/render.h
)
SET (PBRT_WAVEFRONT_SOURCE
src/pbrt/wavefront/aggregate.cpp
src/pbrt/wavefront/camera.cpp
src/pbrt/wavefront/film.cpp
src/pbrt/wavefront/integrator.cpp
src/pbrt/wavefront/media.cpp
src/pbrt/wavefront/samples.cpp
src/pbrt/wavefront/surfscatter.cpp
src/pbrt/wavefront/subsurface.cpp
src/pbrt/wavefront/wavefront.cpp
)
SET (PBRT_WAVEFRONT_SOURCE_HEADERS
src/pbrt/wavefront/aggregate.h
src/pbrt/wavefront/integrator.h
src/pbrt/wavefront/intersect.h
src/pbrt/wavefront/wavefront.h
src/pbrt/wavefront/workitems.h
src/pbrt/wavefront/workitems.soa
src/pbrt/wavefront/workqueue.h
)
SET (PBRT_UTIL_SOURCE
src/pbrt/util/args.cpp
src/pbrt/util/bluenoise.cpp
src/pbrt/util/buffercache.cpp
src/pbrt/util/check.cpp
src/pbrt/util/color.cpp
src/pbrt/util/colorspace.cpp
src/pbrt/util/display.cpp
src/pbrt/util/error.cpp
src/pbrt/util/file.cpp
src/pbrt/util/float.cpp
src/pbrt/util/gui.cpp
src/pbrt/util/image.cpp
src/pbrt/util/log.cpp
src/pbrt/util/loopsubdiv.cpp
src/pbrt/util/lowdiscrepancy.cpp
src/pbrt/util/math.cpp
src/pbrt/util/memory.cpp
src/pbrt/util/mesh.cpp
src/pbrt/util/mipmap.cpp
src/pbrt/util/noise.cpp
src/pbrt/util/parallel.cpp
src/pbrt/util/pmj02tables.cpp
src/pbrt/util/primes.cpp
src/pbrt/util/print.cpp
src/pbrt/util/progressreporter.cpp
src/pbrt/util/pstd.cpp
src/pbrt/util/rng.cpp
src/pbrt/util/sampling.cpp
src/pbrt/util/scattering.cpp
src/pbrt/util/sobolmatrices.cpp
src/pbrt/util/spectrum.cpp
src/pbrt/util/stats.cpp
src/pbrt/util/stbimage.cpp
src/pbrt/util/string.cpp
src/pbrt/util/transform.cpp
src/pbrt/util/vecmath.cpp
)
SET (PBRT_UTIL_SOURCE_HEADERS
src/pbrt/util/args.h
src/pbrt/util/bluenoise.h
src/pbrt/util/buffercache.h
src/pbrt/util/check.h
src/pbrt/util/color.h
src/pbrt/util/colorspace.h
src/pbrt/util/containers.h
src/pbrt/util/display.h
src/pbrt/util/error.h
src/pbrt/util/file.h
src/pbrt/util/float.h
src/pbrt/util/gui.h
src/pbrt/util/hash.h
src/pbrt/util/image.h
src/pbrt/util/log.h
src/pbrt/util/loopsubdiv.h
src/pbrt/util/lowdiscrepancy.h
src/pbrt/util/math.h
src/pbrt/util/memory.h
src/pbrt/util/mesh.h
src/pbrt/util/mipmap.h
src/pbrt/util/noise.h
src/pbrt/util/parallel.h
src/pbrt/util/pmj02tables.h
src/pbrt/util/primes.h
src/pbrt/util/print.h
src/pbrt/util/progressreporter.h
src/pbrt/util/pstd.h
src/pbrt/util/rng.h
src/pbrt/util/sampling.h
src/pbrt/util/scattering.h
src/pbrt/util/soa.h
src/pbrt/util/sobolmatrices.h
src/pbrt/util/spectrum.h
src/pbrt/util/splines.h
src/pbrt/util/stats.h
src/pbrt/util/string.h
src/pbrt/util/taggedptr.h
src/pbrt/util/transform.h
src/pbrt/util/vecmath.h
)
if(PBRT_CUDA_ENABLED OR PBRT_HIP_ENABLED)
if(PBRT_HIP_ENABLED)
set(PBRT_GPU_SOURCE src/pbrt/gpu/hiprt/aggregate.cpp src/pbrt/gpu/memory.cpp src/pbrt/gpu/util.cpp)
set(PBRT_GPU_SOURCE_HEADERS src/pbrt/gpu/hiprt/aggregate.h src/pbrt/gpu/common.h src/pbrt/gpu/cudagl.h src/pbrt/gpu/memory.h src/pbrt/gpu/util.h)
else()
set(PBRT_GPU_SOURCE src/pbrt/gpu/optix/aggregate.cpp src/pbrt/gpu/optix/denoiser.cpp src/pbrt/gpu/memory.cpp src/pbrt/gpu/util.cpp)
set(PBRT_GPU_SOURCE_HEADERS src/pbrt/gpu/optix/aggregate.h src/pbrt/gpu/optix/denoiser.h src/pbrt/gpu/common.h src/pbrt/gpu/cudagl.h src/pbrt/gpu/memory.h src/pbrt/gpu/util.h)
endif()
set(PBRT_GPU_SOURCE_ALL
src/pbrt/bsdf.cpp
src/pbrt/bssrdf.cpp
src/pbrt/bxdfs.cpp
src/pbrt/cameras.cpp
src/pbrt/film.cpp
src/pbrt/filters.cpp
# src/pbrt/genscene.cpp
src/pbrt/interaction.cpp
src/pbrt/lights.cpp
src/pbrt/lightsamplers.cpp
src/pbrt/materials.cpp
# src/pbrt/media.cpp
src/pbrt/options.cpp
# src/pbrt/paramdict.cpp src/pbrt/parser.cpp
src/pbrt/pbrt.cpp
src/pbrt/samplers.cpp
src/pbrt/shapes.cpp
src/pbrt/textures.cpp
src/pbrt/util/bluenoise.cpp
src/pbrt/util/check.cpp
src/pbrt/util/color.cpp
src/pbrt/util/colorspace.cpp
src/pbrt/util/error.cpp
# src/pbrt/util/file.cpp src/pbrt/util/float.cpp src/pbrt/util/image.cpp
src/pbrt/util/log.cpp
# src/pbrt/util/loopsubdiv.cpp
src/pbrt/util/lowdiscrepancy.cpp
src/pbrt/util/math.cpp
# src/pbrt/util/memory.cpp
src/pbrt/util/mesh.cpp
# src/pbrt/util/mipmap.cpp
src/pbrt/util/noise.cpp
# src/pbrt/util/parallel.cpp
src/pbrt/util/pmj02tables.cpp
src/pbrt/util/primes.cpp
# src/pbrt/util/print.cpp src/pbrt/util/progressreporter.cpp
src/pbrt/util/pstd.cpp
src/pbrt/util/rng.cpp
src/pbrt/util/sampling.cpp
src/pbrt/util/scattering.cpp
src/pbrt/util/sobolmatrices.cpp
src/pbrt/util/spectrum.cpp
src/pbrt/util/stats.cpp
# src/pbrt/util/stbimage.cpp src/pbrt/util/string.cpp
src/pbrt/util/transform.cpp
src/pbrt/util/vecmath.cpp
${PBRT_WAVEFRONT_SOURCE}
${PBRT_GPU_SOURCE}
src/pbrt/cmd/pspec_gpu.cpp)
if(PBRT_HIP_ENABLED)
set_source_files_properties(${PBRT_GPU_SOURCE_ALL} PROPERTIES LANGUAGE CXX)
else()
set_source_files_properties(${PBRT_GPU_SOURCE_ALL} PROPERTIES LANGUAGE CUDA)
cuda_compile_and_embed(PBRT_EMBEDDED_PTX src/pbrt/gpu/optix/optix.cu optix.cu)
endif()
endif()
source_group("Source Files" FILES ${PBRT_SOURCE})
source_group("Header Files" FILES ${PBRT_SOURCE_HEADERS})
source_group("Source Files/cpu" FILES ${PBRT_CPU_SOURCE})
source_group("Header Files/cpu" FILES ${PBRT_CPU_SOURCE_HEADERS})
source_group("Source Files/util" FILES ${PBRT_UTIL_SOURCE})
source_group("Header Files/util" FILES ${PBRT_UTIL_SOURCE_HEADERS})
source_group("Source Files/wavefront" FILES ${PBRT_WAVEFRONT_SOURCE})
source_group("Header Files/wavefront" FILES ${PBRT_WAVEFRONT_SOURCE_HEADERS})
if(PBRT_CUDA_ENABLED OR PBRT_HIP_ENABLED)
source_group("Source Files/gpu" FILES ${PBRT_GPU_SOURCE})
source_group("Header Files/gpu" FILES ${PBRT_GPU_SOURCE_HEADERS})
endif()
# ######################################################################################################################################################################################################
# pbrt libraries and executables
list(APPEND PBRT_DEFINITIONS "PTEX_STATIC")
# ######################################################################################################################################################################################################
# soac
add_executable(soac src/pbrt/cmd/soac.cpp)
add_executable(pbrt::soac ALIAS soac)
target_compile_definitions(soac PRIVATE ${PBRT_DEFINITIONS})
target_compile_options(soac PUBLIC ${PBRT_CXX_FLAGS})
target_link_libraries(soac PRIVATE pbrt_warnings pbrt_opt)
set_target_properties(soac PROPERTIES OUTPUT_NAME soac)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pbrt_soa.h
COMMAND soac ${CMAKE_SOURCE_DIR}/src/pbrt/pbrt.soa > ${CMAKE_CURRENT_BINARY_DIR}/pbrt_soa.h
DEPENDS soac ${CMAKE_SOURCE_DIR}/src/pbrt/pbrt.soa)
set(PBRT_SOA_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/pbrt_soa.h)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wavefront_workitems_soa.h
COMMAND soac ${CMAKE_SOURCE_DIR}/src/pbrt/wavefront/workitems.soa > ${CMAKE_CURRENT_BINARY_DIR}/wavefront_workitems_soa.h
DEPENDS soac ${CMAKE_SOURCE_DIR}/src/pbrt/wavefront/workitems.soa)
set(PBRT_SOA_GENERATED ${PBRT_SOA_GENERATED} ${CMAKE_CURRENT_BINARY_DIR}/wavefront_workitems_soa.h)
add_custom_target(pbrt_soa_generated DEPENDS ${PBRT_SOA_GENERATED})
set_property(TARGET soac PROPERTY FOLDER "cmd")
# ######################################################################################################################################################################################################
# pbrt_lib
add_library(
pbrt_lib STATIC
${CMAKE_CURRENT_BINARY_DIR}/rgbspectrum_srgb.cpp
${CMAKE_CURRENT_BINARY_DIR}/rgbspectrum_dci_p3.cpp
${CMAKE_CURRENT_BINARY_DIR}/rgbspectrum_rec2020.cpp
${CMAKE_CURRENT_BINARY_DIR}/rgbspectrum_aces.cpp
${PBRT_SOA_GENERATED}
${PBRT_SOURCE}
${PBRT_SOURCE_HEADERS}
${PBRT_CPU_SOURCE}
${PBRT_CPU_SOURCE_HEADERS}
${PBRT_UTIL_SOURCE}
${PBRT_UTIL_SOURCE_HEADERS}
${PBRT_WAVEFRONT_SOURCE}
${PBRT_WAVEFRONT_SOURCE_HEADERS}
${PBRT_GPU_SOURCE}
${PBRT_GPU_SOURCE_HEADERS}
src/ext/gtest/gtest-all.cc
src/ext/lodepng/lodepng.cpp
src/ext/rply/rply.cpp)
add_library(pbrt::pbrt_lib ALIAS pbrt_lib)
add_dependencies(pbrt_lib pbrt_soa_generated)
target_compile_definitions(pbrt_lib PRIVATE ${PBRT_DEFINITIONS})
# Attempt to work-around Windows/CUDA build issues. As per https://stackoverflow.com/a/51566919, this works around a cmake bug that leads to undefined symbols...
set_property(TARGET pbrt_lib PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)
target_include_directories(
pbrt_lib
PUBLIC src
src/ext
${STB_INCLUDE}
${QOI_INCLUDE}
${OPENEXR_INCLUDE}
${ZLIB_INCLUDE_DIRS}
${LIBDEFLATE_INCLUDE_DIRS}
${FILESYSTEM_INCLUDE}
${PTEX_INCLUDE}
${DOUBLE_CONVERSION_INCLUDE}
${NANOVDB_INCLUDE}
${CMAKE_CURRENT_BINARY_DIR}
${GLFW_INCLUDE}
${GLAD_INCLUDE})
if(PBRT_CUDA_ENABLED AND PBRT_OPTIX7_PATH AND PBRT_HIP_PATH)
target_include_directories(pbrt_lib SYSTEM PUBLIC ${PBRT_OPTIX7_PATH}/include)
target_include_directories(pbrt_lib SYSTEM PUBLIC ${PBRT_HIP_PATH}/include)
endif()
target_compile_options(pbrt_lib PUBLIC ${PBRT_CXX_FLAGS})
if(PBRT_HIP_ENABLED)
target_link_libraries(pbrt_lib PUBLIC hip::device)
target_link_libraries(pbrt_lib PRIVATE pbrt_warnings pbrt_opt)
endif()
if(PBRT_CUDA_ENABLED AND PBRT_OPTIX7_PATH AND PBRT_HIP_PATH)
target_link_libraries(pbrt_lib PRIVATE pbrt_warnings pbrt_opt $<$<BOOL:PBRT_CUDA_ENABLED>:cuda_build_configuration>)
endif()
add_sanitizers(pbrt_lib)
if(WIN32)
# Avoid a name clash when building on Visual Studio
set_target_properties(pbrt_lib PROPERTIES OUTPUT_NAME libpbrt)
endif()
set(ALL_PBRT_LIBS
pbrt_lib
${CMAKE_THREAD_LIBS_INIT}
${OPENEXR_LIBS}
Ptex_static
${ZLIB_LIBRARIES}
${LIBDEFLATE_LIBRARIES}
double-conversion
${PBRT_CUDA_LIB}
utf8proc
glfw
glad
OpenGL::GL)
if(PBRT_CUDA_ENABLED)
set_property(TARGET pbrt_lib PROPERTY CUDA_SEPARABLE_COMPILATION ON)
add_library(pbrt_embedded_ptx_lib STATIC ${PBRT_EMBEDDED_PTX})
add_dependencies(pbrt_embedded_ptx_lib pbrt_soa_generated)
list(APPEND ALL_PBRT_LIBS pbrt_embedded_ptx_lib)
if(PBRT_NVML)
list(APPEND ALL_PBRT_LIBS "nvidia-ml")
endif()
endif()
if(PBRT_HIP_ENABLED)
list(APPEND ALL_PBRT_LIBS "hiprt0200264")
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
add_custom_target(
libdeflate_msvc_patch
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/src/ext/libdeflate && git apply ${CMAKE_CURRENT_BINARY_DIR}/0001-MSVC-HIP.patch > nul 2> nul & exit 0
)
add_dependencies(pbrt_lib libdeflate_msvc_patch)
message(STATUS "Applying patch to libdeflate to support _BitScanReverse for Windows HIP build.")
add_custom_target(
hiprt_kernels ALL
DEPENDS pbrt_lib
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/hiprt.bat
COMMENT "Compiling HIP-RT kernels...")
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
add_custom_target(
hiprt_kernels ALL
DEPENDS pbrt_lib
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/hiprt.sh
COMMENT "Compiling HIP-RT kernels...")
endif()
endif()
if(WIN32)
list(APPEND ALL_PBRT_LIBS "dbghelp" "wsock32" "ws2_32")
endif()
if(PROFILE_LIB)
list(APPEND ALL_PBRT_LIBS "${PROFILE_LIB}")
endif()
# ######################################################################################################################################################################################################
# rgb2spec_opt
add_executable(rgb2spec_opt src/pbrt/cmd/rgb2spec_opt.cpp)
add_executable(pbrt::rgb2spec_opt ALIAS rgb2spec_opt)
target_compile_definitions(rgb2spec_opt PRIVATE ${PBRT_DEFINITIONS})
target_compile_options(rgb2spec_opt PUBLIC ${PBRT_CXX_FLAGS})
target_link_libraries(rgb2spec_opt PRIVATE ${CMAKE_THREAD_LIBS_INIT} pbrt_opt pbrt_warnings)
if(NOT PBRT_USE_PREGENERATED_RGB_TO_SPECTRUM_TABLES)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rgbspectrum_aces.cpp
COMMAND rgb2spec_opt 64 ${CMAKE_CURRENT_BINARY_DIR}/rgbspectrum_aces.cpp ACES2065_1
DEPENDS rgb2spec_opt)