Remove dependency on OptiX SDK for building core OSL with OptiX support #1627
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
OSL currently includes the OptiX header in several places, but without actually making any use of its contents. OptiX support is implemented soly using LLVM and its NVPTX backend, without any types or functions used from the OptiX SDK, making these includes superfluous. The only part of the codebase that does need them are the tests, so this patch makes finding the SDK dependent on whether tests are enabled or not.
Avoiding including the OptiX headers in the core makes it possible still to build OSL with OptiX support (
USE_OPTIX=ON;OSL_BUILD_TESTS=OFF;), but without needing the OptiX SDK in the process, simplifying the build process on build systems where having the OptiX SDK installed is a challenge.Additionally this patch also makes it possible to use OSL in OptiX without pre-built LLVM bitcode containing OSL intrinsics (
USE_LLVM_BITCODE=OFF;). Building that bitcode module requires the CUDA toolkit, which too can be a challenge to have available on build systems, but it's not technically needed if the renderer implementing OSL does provide an implementation for all the OSL intrinsics declared inbuiltindecl.hitself (and it already had to do so for some of them right now anyway). In that case only have to initialize the now empty LLVM module OSL creates with a proper target and data layout (which would normally be inherited from the pre-built bitcode), otherwise compiling shader groups will later fail, as the NVPTX backend is looked up based on the target triple set on the module (see implementation ofLLVM_Util::ptx_compile_group()).CMake previously errored when attempting to build with OptiX support and without the LLVM bitcode, but due to the previous change it only does that when tests are enabled too now, making the following a valid combination of build options when no CUDA/OptiX SDK is available, but OptiX support is still desired:
USE_OPTIX=ON;USE_LLVM_BITCODE=OFF;OSL_BUILD_TESTS=OFF;. This is e.g. the case with Blender (more discussion regarding this on https://developer.blender.org/D15902).Note: The change to externalpackages.cmake looks larger than it is due whitespace changes caused by the new if clause.
Checklist: