OK, now you changed something, it’s still not working and you didn’t provide the updated CMakeLists.txt and didn’t analyze the error message carefully enough.
The error message says:
Current Source Dir: E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing
NCUDA_COMPILE_MODULE DEBUG MESSAGE:
E:/workspace/cuda/cuda/bin/nvcc.exe
--optix-ir;
--machine=64;
--gpu-architecture=compute_52;
--use_fast_math;
--relocatable-device-code=true;
--generate-line-info;
-Wno-deprecated-gpu-targets;
-IE:/workspace/cuda/optix/include;E:/workspace/cuda/optix/SDK;E:/workspace/cuda/optix/SDK/build;
-IE:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing/optix
optix/Raytracing.cu
-o E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/build/gpu-code/Raytracing.optixir
See the line with -IE:/workspace/cuda/optix/include;E:/workspace/cuda/optix/SDK;E:/workspace/cuda/optix/SDK/build;
?
That is actually
-IE:/workspace/cuda/optix/include;
E:/workspace/cuda/optix/SDK;
E:/workspace/cuda/optix/SDK/build;
but you probably wanted to set include directories instead like this:
-IE:/workspace/cuda/optix/include;
-IE:/workspace/cuda/optix/SDK;
-IE:/workspace/cuda/optix/SDK/build;
instead you added multiple input files in addition to the optix/Raytracing.cu
to the NVCC command line and it complained about that rightfully.
The error is this:
set(OPTIX_INCLUDE_DIR "${OPTIX_DIRECTORY}//include"
"${OPTIX_DIRECTORY}//SDK"
"${OPTIX_DIRECTORY}//SDK//build"
)
which is incorrect with "-I${OPTIX_INCLUDE_DIR}"
inside the NVCC command line.
My scripts assume that the OPTIX_INCLUDE_DIR
is exactly the “${OPTIX_DIRECTORY}/include”, nothing else!
If you want to have additional include directories, you need to add them individually! (Shown below.)
Let’s try doing what I described multiple times.
Please read all README comments I added. There are some inconsistencies and errors inside your script.
# FindCUDA.cmake is deprecated since CMake 3.10.
# Use FindCUDAToolkit.cmake added in CMake 3.17 instead.
cmake_minimum_required(VERSION 3.17)
project( A5_OptiXRaytracing )
message("\nPROJECT_NAME = " "${PROJECT_NAME}")
# README Why are you changing the PROJECT_SOURCE_DIR here?
# That should be the source directory of the last called project() otherwise your relative file names are incorrect.
# Also note that you're not using absolute filenames inside the OptiX shader section which will screw up stepping through error messages thown by NVCC inside the Visdual Studio IDE.
# cmake_path(GET PROJECT_SOURCE_DIR PARENT_PATH PARENT_DIR)
# Verify that this points to the right
message("PROJECT_SOURCE_DIR = " "${PROJECT_SOURCE_DIR}")
find_package(CUDAToolkit 10.0 REQUIRED)
# README Are these things handled by your root project's include(Dependencies)?
#find_package(OpenGL REQUIRED)
#find_package(GLFW REQUIRED)
set(OPTIX_DIRECTORY "E:/workspace/cuda/optix/" CACHE PATH "Path to the OptiX directory")
set(OPTIX_INCLUDE_DIR "${OPTIX_DIRECTORY}/include")
message("OPTIX_INCLUDE_DIR = " "${OPTIX_INCLUDE_DIR}")
# OptiX SDK 7.5.0 and CUDA 11.7 added support for a new OptiX IR target, which is a binary intermediate format for the module input.
# The default module build target is PTX.
set(USE_OPTIX_IR FALSE)
set(OPTIX_MODULE_EXTENSION ".ptx")
set(OPTIX_PROGRAM_TARGET "--ptx")
# README Since you didn't use any find_package(OptiX<version> REQUIRED), this assumes you're using at least OptiX 7.5.0.
# Still check the CUDA version number from the find_package(CUDAToolkit 10.0 REQUIRED) above dynamically.
# Define USE_OPTIX_IR and change the target to OptiX IR if the combination of OptiX SDK and CUDA Toolkit versions supports this mode.
if ((${CUDAToolkit_VERSION_MAJOR} GREATER 11) OR ((${CUDAToolkit_VERSION_MAJOR} EQUAL 11) AND (${CUDAToolkit_VERSION_MINOR} GREATER_EQUAL 7)))
set(USE_OPTIX_IR TRUE)
set(OPTIX_MODULE_EXTENSION ".optixir")
set(OPTIX_PROGRAM_TARGET "--optix-ir")
endif()
# README If these files are NOT inside the A5_OptiXRaytracing subfolder, then you should build yourself some OTHER_PROJECT_SOURCES_PATH variables and prefix all of these with the right path.
# Something like cmake_path(GET CPP_SOURCES_PATH PARENT_PATH PARENT_DIR) maybe.
set(CPP_SOURCES
Camera.cpp
GLSLShader.cpp
OpenGLDebugger.cpp
Renderer.cpp
Texture.cpp
main.cpp
)
set(CPP_HEADERS
Camera.h
GLSLShader.h
OpenGLDebugger.h
Renderer.h
Texture.h
)
set(CG_SOURCES
cg/BufferCombo.cpp
cg/CGRenderer.cpp
cg/ConversionFunctions.cpp
cg/UI.cpp
)
set(CG_HEADERS
cg/BufferCombo.h
cg/CGRenderer.h
cg/ConversionFunctions.h
cg/EnumStringConverter.h
cg/Parameter.h
cg/ShaderEnums.h
cg/UI.h
cg/UIEventHandler.h
)
set(OPTIX_SOURCES
optix/CUDABuffer.cpp
optix/Denoiser.cpp
optix/OptixRenderer.cpp
optix/OptixUtil.cpp
)
# README Are any of these includes inside the files listed in OPTIX_SHADER_SOURCES or OPTIX_SHADER_HEADERS?
# If yes, they need to appear inside OPTIX_SHADER_HEADERS as well to have the right dependencies.
set(OPTIX_HEADERS
optix/CUDABuffer.h
optix/Denoiser.h
optix/LaunchParams.h
optix/OptixRenderer.h
optix/OptixUtil.h
optix/RandomGenerator.h
)
# README I'm assuming the optix folder is inside the current project's sub-directory.
# Seems like it because you include "-I${CMAKE_CURRENT_SOURCE_DIR}/optix" in the NVCC command line.
# Prefix the shaders with the full path name to allow stepping through errors with F8.
set(OPTIX_SHADER_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/optix/Raytracing.cu
)
set(OPTIX_SHADER_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/optix/SamplingArrays.cuh
)
# README Since these are not appearing inside the add_executable() I assume you just want them to be inside the source group but they are not actually part of the build but translated by OpenGL at runtime?
set(GLSL_SHADER
shader/CanvasFragment.glsl
shader/CanvasVertex.glsl
shader/GenerationFragment.glsl
shader/GenerationVertex.glsl
shader/ShadowpassFragment.glsl
shader/ShadowpassVertex.glsl
)
message("Parent Dir: ${PARENT_DIR}")
set(IMGUI_SOURCES
${PARENT_DIR}/Dependencies/imgui/imgui.cpp
${PARENT_DIR}/Dependencies/imgui/imgui_draw.cpp
${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_glfw.cpp
${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_opengl3.cpp
${PARENT_DIR}/Dependencies/imgui/misc/cpp/imgui_stdlib.cpp
${PARENT_DIR}/Dependencies/imgui/imgui_tables.cpp
${PARENT_DIR}/Dependencies/imgui/imgui_widgets.cpp
)
# Checking where the *.optixir files go.
message("CMAKE_BINARY_DIR = " "${CMAKE_BINARY_DIR})
# When using OptiX SDK 7.5.0 and CUDA 11.7 or higher, the modules can either be built from OptiX IR input or from PTX input.
# OPTIX_PROGRAM_TARGET and OPTIX_MODULE_EXTENSION switch the NVCC compilation between the two options.
# README Note that I'm using compute_50 to also support first generation Maxwell. compute_52 should be fine. If you don't need to support such old GPUs, use compute_60 for Pascal and up.
# README Note that "-I${OPTIX_DIRECTORY}/SDK" "-I${OPTIX_DIRECTORY}/SDK/build" have been added. See below why this is a bad idea. These files also don't appear inside the source_groups.
NVCUDA_COMPILE_MODULE(
SOURCES ${OPTIX_SHADER_SOURCES}
DEPENDENCIES ${OPTIX_SHADER_HEADERS}
TARGET_PATH "${CMAKE_BINARY_DIR}/gpu-code"
EXTENSION "${OPTIX_MODULE_EXTENSION}"
GENERATED_FILES PROGRAM_MODULES
NVCC_OPTIONS "${OPTIX_PROGRAM_TARGET}" "--machine=64" "--gpu-architecture=compute_50" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "-I${OPTIX_INCLUDE_DIR}" "-I${OPTIX_DIRECTORY}/SDK" "-I${OPTIX_DIRECTORY}/SDK/build" "-I${CMAKE_CURRENT_SOURCE_DIR}/optix"
)
source_group( "cpp_headers" FILES ${CPP_HEADERS} )
source_group( "cpp_sources" FILES ${CPP_SOURCES} )
source_group( "cg_headers" FILES ${CG_HEADERS} )
source_group( "cg_sources" FILES ${CG_SOURCES} )
source_group( "optix_headers" FILES ${OPTIX_HEADERS} )
source_group( "optix_sources" FILES ${OPTIX_SOURCES} )
source_group( "optix_shader_headers" FILES ${OPTIX_SHADER_HEADERS} )
source_group( "optix_shader_sources" FILES ${OPTIX_SHADER_SOURCES} )
source_group( "glsl_shader" FILES ${GLSL_SHADER} )
source_group( "imgui_sources" FILES ${IMGUI_SOURCES} )
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/Dependencies/imgui"
"${CMAKE_SOURCE_DIR}/Dependencies/magic_enum"
"${CMAKE_SOURCE_DIR}/Dependencies/glad"
${OPTIX_INCLUDE_DIR}
# I seriously recommend to NOT reference source files from the OptiX SDK examples like this inside applications living outside the OptiX SDK framework.
# Instead copy everything you need locally and make yout application work standalone!
"${OPTIX_DIRECTORY}/SDK" # README Added manually.
"${OPTIX_DIRECTORY}/SDK/build" # README Added manually.
# README Was missing.
${CUDAToolkit_INCLUDE_DIRS}
)
add_definitions(
# Disable warnings for file operations fopen etc.
"-D_CRT_SECURE_NO_WARNINGS"
)
if(USE_OPTIX_IR)
add_definitions(
# This define switches the OptiX program module filenames to either *.optixir or *.ptx extensions at compile time.
"-DUSE_OPTIX_IR"
)
endif()
add_executable( ${PROJECT_NAME}
${IMGUI_SOURCES}
${CPP_HEADERS}
${CPP_SOURCES}
${CG_HEADERS}
${CG_SOURCES}
${OPTIX_HEADERS}
${OPTIX_SOURCES}
${OPTIX_SHADER_HEADERS}
${OPTIX_SHADER_SOURCES}
${PROGRAM_MODULES} # README Added.
# README Why is this in ${PARENT_DIR}/Dependencies while the include directories "${CMAKE_SOURCE_DIR}/Dependencies/glad". This is inconsistent.
${PARENT_DIR}/Dependencies/glad/glad.c
)
# README How is this supposed to work?
# For example, if you're using GLFW calls inside your application, where are the GLFW include directories set to find the necessary headers?
# Also if you're using freeglut, why is there no find_package(OpenGL REQUIRED) above and OpenGL::GL inside the target_link_libraries()?
# I'm assuming your include(Dependencies) inside the root CMakeLists.txt figures these out?
# Also why is there an AntTweakBar dependency while you're using ImGUI? Are there different GUIs inside the app?
set(LIBRARIES
ObjLoader
ImageLoader
AntTweakBar
freeglut
glfw
)
target_link_libraries( ${PROJECT_NAME}
${LIBRARIES}
CUDA::cudart
CUDA::cuda_driver
)
# README Just copied from your project. Not looked at.
create_target_launcher(${PROJECT_NAME} WORKING_DIRECTORY ${${PROJECT_NAME}_SOURCE_DIR})
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Aufgaben")
install_sample(${PROJECT_NAME} ${SOURCES})
Given that this is a student assignment, I would recommend you work with your tutors to solve any CMake build problems.
If you actually have issues with OptiX itself, that would the right forum to discuss them.