Skip to content

Commit

Permalink
Merge pull request #11 from sergeneren/feature/fix-dependencies
Browse files Browse the repository at this point in the history
Fix Dependencies and automate build
  • Loading branch information
sergeneren authored Jan 19, 2024
2 parents 830b0bd + 24714e7 commit 8708189
Show file tree
Hide file tree
Showing 53 changed files with 6,660 additions and 2,635 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
[Aa]ssets/[Tt]emp
thirdparty/gvdb-voxels/

instancer_hda/scenes/backup
instancer_hda/scenes/backup

*.pdb
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "thirdparty/cuda-noise"]
path = thirdparty/cuda-noise
url = https://github.com/sergeneren/cuda-noise
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR)
project(VPT LANGUAGES CXX CUDA)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(_VCPKG_INCLUDE_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/")

##################################################################

## Set output directories

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/vpt/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/vpt/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/vpt/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/vpt/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/vpt/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/vpt/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/vpt/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/vpt/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/vpt/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/bin)

##################################################################

set(_VCPKG_INCLUDE_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
set(_VCPKG_LIB_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib")
set(_VCPKG_BIN_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin")

option (BUILD_VPT "Builds Volumetric Path Tracer" ON)
option (BUILD_INSTANCER "Builds Houdini plugin to save instance files" OFF)

Expand All @@ -39,7 +45,6 @@ elseif(${DebugLevel} STREQUAL "Log")
endif()



if(BUILD_VPT)
add_subdirectory(${CMAKE_SOURCE_DIR}/source)
endif(BUILD_VPT)
Expand Down
41 changes: 41 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 4,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "Default",
"displayName": "Development Configuration",
"description": "Default configuration for dev environment",
"binaryDir": "${sourceDir}/build/",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
},
"BUILD_VPT": {
"type": "BOOLEAN",
"value": "ON"
},
"OpenImageDenoise_DIR": "${sourceDir}/thirdparty/OpenImageDenoise/lib/cmake/OpenImageDenoise-2.1.0",
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg/vcpkg_installed",
"VCPKG_BUILD_TYPE": "release",
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
}
],
"buildPresets": [
{
"name": "Default",
"configurePreset": "Default",
"displayName": "Build RelWithDebInfo",
"description": "Build RelWithDebInfo configuration",
"configuration": "RelWithDebInfo"
}
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ v 1.0.2 Alpha

## Installation, Build and Usage

Please see [this](https://sergeneren.com/2020/01/07/using-vpt/) detailed article for installing building and using VPT
Use the `build_windows.cmd` file for building automatically on windows. Also see [this](https://sergeneren.com/2020/01/07/using-vpt/) detailed article for using VPT.
This repo is tested with Cuda 12.1 and Nvidia Driver 546.65

## Author

Expand Down
32 changes: 32 additions & 0 deletions build_windows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@echo off

setlocal

git submodule init
git submodule update

if not exist ./vcpkg/vcpkg.exe (
call ./vcpkg/bootstrap-vcpkg.bat
)

if not exist ./vcpkg/vcpkg.exe (
echo Unable to bootstrap vcpkg!
exit 1
)

if exist build rmdir /s /q build

cmake --preset Default .
if errorlevel 1 (
echo failed to configure
exit 1
)


cmake --build ./build --preset Default
if errorlevel 1 (
echo failed to build
exit 1
)

echo Successfully built VPT! You can find the executable under build/bin directory
55 changes: 39 additions & 16 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(glfw3 CONFIG REQUIRED)
find_package(glew CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(OpenVDB CONFIG REQUIRED)
find_package(OpenImageIO CONFIG REQUIRED)
find_package(tinyexr CONFIG REQUIRED)
find_package(tbb CONFIG REQUIRED)
find_package(OpenImageDenoise CONFIG REQUIRED)

include(${CMAKE_CURRENT_SOURCE_DIR}/Helpers.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/CompileObj.cmake)

##################################################################

# set external directories

set(THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/thirdparty/")

#set OIDN libraries
set(OID_DIR "${THIRDPARTY_DIR}/OpenImageDenoise")
find_library(OIDN_LIB "OpenImageDenoise" "${OID_DIR}/lib")
find_library(OIDN_MKLDNN_LIB "mkldnn" "${OID_DIR}/lib")
find_library(OIDN_COMMON_LIB "common" "${OID_DIR}/lib")

set(OIDN_LIBRARIES ${OIDN_LIB} ${OIDN_MKLDNN_LIB} ${OIDN_COMMON_LIB})
set(THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/thirdparty")

##Set env mapping renders variable

Expand Down Expand Up @@ -83,6 +83,9 @@ file ( GLOB GEOMETRY
file ( GLOB BVH
"${CMAKE_CURRENT_SOURCE_DIR}/bvh/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/bvh/*.cpp"
)

file ( GLOB CUDA_FUNCTIONS
"${CMAKE_CURRENT_SOURCE_DIR}/bvh/*.cu"
)

Expand All @@ -102,6 +105,7 @@ file( GLOB IMGUI_IMPL_SOURCES
set(SOURCE_FILES
${HEADERS}
${CUDA_SOURCES}
${CUDA_FUNCTIONS}
${SOURCE_CPP}
${BVH}
${IMGUI_IMPL_SOURCES}
Expand All @@ -113,7 +117,7 @@ set(SOURCE_FILES
## Group source files

source_group(Cuda FILES ${CUDA_SOURCES})
source_group(bvh FILES ${BVH})
source_group(bvh FILES ${BVH} ${CUDA_FUNCTIONS})
source_group(Imgui FILES ${IMGUI_IMPL_SOURCES})
source_group(Helpers FILES ${COMMON} ${UTIL})
source_group(Atmosphere FILES ${ATMOSPHERE})
Expand All @@ -123,28 +127,47 @@ source_group(Geometry FILES ${GEOMETRY})

find_program(CUDA_NVCC_EXECUTABLE nvcc)
message ( STATUS "Build CUDA kernels: ${CUDA_SOURCES}" )
_COMPILEPTX ( SOURCES ${CUDA_SOURCES}
COMPILE_PTX ( SOURCES ${CUDA_SOURCES}
TARGET_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
GENERATED CUDA_PTX GENPATHS CUDA_PTX_PATHS
INCLUDE "${CMAKE_CURRENT_SOURCE_DIR},${_VCPKG_INCLUDE_DIR},${CMAKE_CURRENT_SOURCE_DIR}/common, ${THIRDPARTY_DIR}/cuda-noise/include, ${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb"
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR} ${_VCPKG_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common ${THIRDPARTY_DIR}/cuda-noise/include ${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb
OPTIONS -arch=compute_61 -code=sm_61 --ptxas-options=-v -O3 --use_fast_math --maxrregcount=128)


COMPILE_OBJ(
SOURCES ${CUDA_FUNCTIONS}
TYPE ${CMAKE_BUILD_TYPE}
TARGET_PATH ${CMAKE_BINARY_DIR}/lib
GENPATHS GEN_CUDA_FUNC_OBJS
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR} ${_VCPKG_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common ${THIRDPARTY_DIR}/cuda-noise/include ${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb
)
message(STATUS "Genrated cuda functions objects ${GEN_CUDA_FUNC_OBJS}")

###################################################################

###################################################################
add_executable(vpt ${SOURCE_FILES})
target_link_libraries(vpt PRIVATE glfw imgui::imgui cudart cuda openvdb ${OIDN_LIBRARIES})
target_link_libraries(vpt PRIVATE glfw GLEW::GLEW imgui::imgui cudart cuda OpenImageDenoise
TBB::tbb OpenVDB::openvdb opengl32 OpenImageIO::OpenImageIO ${OIDN_LIBRARIES} ${_VCPKG_LIB_DIR}/tinyexr.lib ${GEN_CUDA_FUNC_OBJS})

set_target_properties(vpt PROPERTIES VS_GLOBAL_VcpkgEnabled true)
set_target_properties(vpt PROPERTIES VS_GLOBAL_VcpkgEnableManifest true)
target_compile_features(vpt PUBLIC cxx_std_17)

set_target_properties(vpt PROPERTIES CUDA_ARCHITECTURES "61;75;86")


file ( GLOB OIDN_DLLS "${THIRDPARTY_DIR}/OpenImageDenoise/bin/*.dll" )
add_custom_command(
TARGET vpt PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${OIDN_DLLS} ${CMAKE_BINARY_DIR}/bin)

include_directories(${_VCPKG_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/imgui)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/atmosphere)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/bvh)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/geometry)
include_directories(${THIRDPARTY_DIR}/cuda-noise/include)
include_directories(${OID_DIR}/include)
include_directories(${THIRDPARTY_DIR}/OpenImageDenoise/include)
72 changes: 72 additions & 0 deletions source/CompileObj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

#------------------------------------ CROSS-PLATFORM OBJ COMPILE

FUNCTION( COMPILE_OBJ )
set(options "")
set(oneValueArgs TARGET_PATH TYPE GENERATED GENPATHS)
set(multiValueArgs OPTIONS SOURCES ARCHS INCLUDE)
CMAKE_PARSE_ARGUMENTS( _FUNCTION "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Match the bitness of the ptx to the bitness of the application
set( MACHINE "--machine=32" )
if( CMAKE_SIZEOF_VOID_P EQUAL 8)
set( MACHINE "--machine=64" )
endif()
unset ( CUBIN_FILES CACHE )
unset ( CUBIN_FILES_PATH CACHE )
unset ( EMBEDDED_FILES CACHE )

FOREACH(INCLUDE_DIR ${_FUNCTION_INCLUDE})
set ( INCL ${INCL} "-I\"${INCLUDE_DIR}\"" )
ENDFOREACH()

set ( ARCHS -arch=sm_61 )

message(STATUS "Compiling for architecture ${ARCH}")

file ( MAKE_DIRECTORY "${_FUNCTION_TARGET_PATH}" )
string (REPLACE ";" " " _FUNCTION_OPTIONS "${_FUNCTION_OPTIONS}")
separate_arguments( _OPTS WINDOWS_COMMAND "${_FUNCTION_OPTIONS}" )
message ( STATUS "NVCC Options: ${_FUNCTION_OPTIONS}" )
message ( STATUS "NVCC Include: ${_FUNCTION_INCLUDE}" )

#Set initial options
set(_OPTS ${_OPTS} -Xcompiler "/EHsc,/Od,/Zi,/RTC1" ${ARCHS})

#Set debug or relase linking
if(_FUNCTION_TYPE MATCHES "Debug")
set(_OPTS ${_OPTS} -Xcompiler "/MDd")
else()
set(_OPTS ${_OPTS} -Xcompiler "/MD")
endif()

set(_OPTS ${_OPTS} -w)

FOREACH( input ${_FUNCTION_SOURCES} )
get_filename_component( input_ext ${input} EXT )
get_filename_component( input_without_ext ${input} NAME_WE )
if ( ${input_ext} STREQUAL ".cu" )
set(_EXT .lib)

set( output "${input_without_ext}.lib" )
set( output_with_path "${_FUNCTION_TARGET_PATH}/${input_without_ext}${_EXT}" )
set( output_with_quote "\"${output_with_path}\"" )
LIST( APPEND OBJ_FILES ${output} )
LIST( APPEND OBJ_FILES_PATH ${output_with_path} )

message( STATUS "NVCC Compile: ${CUDA_NVCC_EXECUTABLE} ${MACHINE} --lib -cudart static ${DEBUG_FLAGS} ${_OPTS} ${input} -o ${output_with_path} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_command(
OUTPUT ${output_with_path}
MAIN_DEPENDENCY ${input}
DEPENDS ${_FILE_DEPENDENCY}
COMMAND ${CUDA_NVCC_EXECUTABLE} ${MACHINE} --compile ${DEBUG_FLAGS} ${OPT_FLAGS} ${_OPTS} ${input} ${INCL} -o ${output_with_quote}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

endif()
ENDFOREACH( )

set( ${_FUNCTION_GENERATED} ${OBJ_FILES} PARENT_SCOPE)
set( ${_FUNCTION_GENPATHS} ${OBJ_FILES_PATH} PARENT_SCOPE)

ENDFUNCTION()
Loading

0 comments on commit 8708189

Please sign in to comment.