pbrt-v4
pbrt-v4 copied to clipboard
Windows build improvements
There are a number of ways the Windows build could be improved:
- Parallel builds would be nice
- The organization of the source files in the MSVC project browser could be improved. (Among other things, the headers don't seem to appearing even though there's a
source_group
directive that should be putting them there.) - There are a fair number of warnings in the build, especially from OpenEXR. It would be nice to fix and or suppress those...
(Among other things, the headers don't seem to appearing even though there's a source_group directive that should be putting them there.)
Only the files that are added to the targets will show up, even if they are part of a source_group()
. If you add ${PBRT_SOURCE_HEADERS}
to add_library (pbrt_lib)
, those headers will then be listed under "pbrt_lib" -> "Header Files" in Visual Studio; I just tried it out.
Thank you so much Matt and the PBRT team for sharing the v4 source code with us early on. I want to share my bit in this if I may. I have managed to successfully build pbrt v4 on a 64-bit Windows 8.1 machine. As you would know the default Cmake setup requires CUDA v> 11.0 and Optix v>7 and if you dont have those, the pbrtv4 visual studio project is not generated. The reason for this is because line 163 of CMakeLists.txt flags unavailability of CUDA 11 and Optix 7 as an error. I have listed my changes below for others as reference.
-
change the cmake version in zlib/CMakeLists.txt and ptex/CMakeLists.txt to 3.12. [This will remove a few CMake warnings]
-
update the pbrtv4 root CMakeLists.txt line 163 from this [Already addressed in 995d9e]
message(SEND_ERROR "pbrt-v4 requires CUDA version 11.0 or later. If you have multiple versions installed, please update your PATH.")
to thismessage(WARNING "pbrt-v4 requires CUDA version 11.0 or later. If you have multiple versions installed, please update your PATH.")
-
[This is not required as the default includes should include the appropriate headers as mentioned by mmp below] add the following lines to math.h before the Log2Int function (lines 370-389)
//Ref: https://stackoverflow.com/questions/355967/how-to-use-msvc-intrinsics-to-get-the-equivalent-of-this-gcc-code
#ifdef _MSC_VER
#include <intrin.h>
unsigned long __inline __builtin_ctz(uint32_t value) {
unsigned long trailing_zero = 0;
if (_BitScanForward(&trailing_zero, value)) {
return trailing_zero;
} else {
// This is undefined, I better choose 32 than 0
return 32;
}
}
unsigned long __inline __builtin_clz(uint32_t value) {
unsigned long leading_zero = 0;
if (_BitScanReverse(&leading_zero, value)) {
return 31 - leading_zero;
} else {
// Same remarks as above
return 32;
}
}
unsigned long long __inline __builtin_clzll(uint64_t value) {
unsigned long leading_zero = 0;
if (_BitScanReverse64(&leading_zero, value)) {
return 31UL - leading_zero;
} else {
// Same remarks as above
return 32UL;
}
}
#endif
Thanks, MMMovania
Thanks for working on this! I just pushed an update to the CMakeLists.txt file (in 995d9e0c2c7094361f6f20cc900ddff7e84af977) that addresses the second issue (in a slightly different way).
I am curious why that change to math.h
was necessary and why the changes to the other CMakeLists.txt
files was necessary. For math.h
, those __builtin_*
functions shouldn't be called in the first place in Windows (note the code in there that does #elif defined(PBRT_HAS_INTRIN_H)
, etc. Also, I'm not sure why requiring a newer version of CMake than those packages currently require makes a difference. Any clarification would be much appreciated!
Thanks for a prompt response Matt. Let me address your questions.
- Regarding the changes in math.h, you are absolutely correct, apparently for me the intrinsics were not defined while I was trying to compile the code and I had to add those functions in. Now that I cleaned and rebuild the code it does indeed take the correct headers in. I can confirm that it works fine without adding these intrinisics definitions in as PBRT_HAS_INTRIN_H does indeed pull the correct header.
- Regarding the version no. issue this is just to remove the warning during CMake build process. I like a clean CMake log :)