Skip to content

Commit

Permalink
Added apps bench_shared, bench_shared_offscreen, MDL_sdf (by Detlef R…
Browse files Browse the repository at this point in the history
…oettger).
  • Loading branch information
lspanonv committed Sep 2, 2024
1 parent f8c3765 commit 3807f47
Show file tree
Hide file tree
Showing 272 changed files with 177,808 additions and 8 deletions.
26 changes: 19 additions & 7 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,34 @@ add_subdirectory( rtigo10 )
# Also homogeneous volume scattering is implemented in this example the same way as inside the MDL_renderer. (See scene_rtigo12_*.txt files for examples.)
add_subdirectory( rtigo12 )

# Based on rtigo9, but replacing all material handling with MDL materials.
# The MDL SDK is used to generate the minimal amount of direct callable programs per MDL material shader.
# The closesthit and anyhit programs inside hit.cu call the valid direct callable programs to handle the input values
# from MDL expressions and the sampling and evaluation of the material's distribution functions.
if (MDL_SDK_FOUND)
# Based on rtigo9, but replacing all material handling with MDL materials.
# The MDL SDK is used to generate the minimal amount of direct callable programs per MDL material shader.
# The closesthit and anyhit programs inside hit.cu call the valid direct callable programs to handle the input values
# from MDL expressions and the sampling and evaluation of the material's distribution functions.
add_subdirectory( MDL_renderer )
# Based on MDL_renderer, but adding support for a custom Signed-Distance-Field (SDF) primitive
# which is defined by a box inside which a SDF as 3D texture is sampled.
# The 3D texture data can either be single-component fp16 (*.bin) or fp32 (any other extension than *.bin) formats.
# Supports any MDL material without emission or cutout-opacity.
add_subdirectory( MDL_sdf )
else()
message("WARNING: MDL_renderer requires the MDL_SDK. Set the MDL_SDK_PATH variable. Example excluded from build.")
message("WARNING: MDL_renderer and MDL_sdf require the MDL_SDK. Set the MDL_SDK_PATH variable. Examples excluded from build.")
endif()

# Note that the GLTF_renderer/CMakeLists.txt is now a standalone solution!
# That's because it is an example for using the native CMake LANGUAGES CUDA feature and
# a CMake Object Library for the OptiX device code translation.
# That's because it is an example for using the native CMake LANGUAGE CUDA feature and
# a CMake "Object Library" for the OptiX device code translation.
# This allows running native CUDA kernels with the CUDA Runtime API chevron <<<>>> operator
# which is used for the expensive skinning animations so far.
# Unfortunately that CMake LANGUAGE CUDA feature affects all projects inside a solution and
# would break the build for all examples using the custom build rules for the OptiX device code *.cu files.
message("The GLTF_renderer example is a standalone solution now! Details inside the README.md files.")


# Derived from nvlink_shared but adjusted to allow dynamic control about the resource sharing via the new system option peerToPeer bitfield.
# Allows selective sharing of resources via NVLINK or PCI-E (new), texture data, GAS and vertex attribute data, HDR environment CDFs.
add_subdirectory( bench_shared )

# Same as bench_shared without any window or OpenGL handling.
add_subdirectory( bench_shared_offscreen )
298 changes: 298 additions & 0 deletions apps/MDL_sdf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
# Copyright (c) 2013-2022, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# FindCUDA.cmake is deprecated since CMake 3.10.
# Use FindCUDAToolkit.cmake added in CMake 3.17 instead.
cmake_minimum_required(VERSION 3.17)

project( MDL_sdf )
message("\nPROJECT_NAME = " "${PROJECT_NAME}")

find_package(OpenGL REQUIRED)
find_package(GLFW REQUIRED)
find_package(GLEW REQUIRED)
find_package(CUDAToolkit 10.0 REQUIRED)
find_package(DevIL_1_8_0 REQUIRED)
find_package(ASSIMP REQUIRED)

if(MDL_SDK_FOUND)
message("MDL_SDK_INCLUDE_DIRS = " "${MDL_SDK_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "MDL SDK not found.")
endif()

# OptiX SDK 7.x and 8.x versions are searched inside the top-level CMakeLists.txt.
# Make the build work with all currently released OptiX SDK 7.x and 8.x versions.
if(OptiX80_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX80_INCLUDE_DIR}")
elseif(OptiX77_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX77_INCLUDE_DIR}")
elseif(OptiX76_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX76_INCLUDE_DIR}")
elseif(OptiX75_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX75_INCLUDE_DIR}")
elseif(OptiX74_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX74_INCLUDE_DIR}")
elseif(OptiX73_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX73_INCLUDE_DIR}")
elseif(OptiX72_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX72_INCLUDE_DIR}")
elseif(OptiX71_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX71_INCLUDE_DIR}")
elseif(OptiX70_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX70_INCLUDE_DIR}")
else()
message(FATAL_ERROR "No OptiX SDK 8.x or 7.x found.")
endif()
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")

if (OptiX80_FOUND OR OptiX77_FOUND OR OptiX76_FOUND OR OptiX75_FOUND)
# 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()
endif()

set( IMGUI
imgui/imconfig.h
imgui/imgui.h
imgui/imgui_impl_glfw_gl3.h
imgui/imgui_internal.h
imgui/stb_rect_pack.h
imgui/stb_textedit.h
imgui/stb_truetype.h
imgui/imgui.cpp
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp
imgui/imgui_impl_glfw_gl3.cpp
)

# Reusing some routines from the NVIDIA nvpro-pipeline https://github.com/nvpro-pipeline/pipeline
# Not built as a library, just using classes and functions directly.
# Asserts replaced with my own versions.
set( NVPRO_MATH
# Math functions:
dp/math/Config.h
dp/math/math.h
dp/math/Matmnt.h
dp/math/Quatt.h
dp/math/Trafo.h
dp/math/Vecnt.h
dp/math/src/Math.cpp
dp/math/src/Matmnt.cpp
dp/math/src/Quatt.cpp
dp/math/src/Trafo.cpp
)

set( HEADERS
inc/Application.h
inc/Arena.h
inc/Camera.h
inc/CheckMacros.h
inc/CompileResult.h
inc/Device.h
inc/Hair.h
inc/LightGUI.h
inc/LoaderIES.h
inc/MaterialMDL.h
inc/MyAssert.h
inc/NVMLImpl.h
inc/Options.h
inc/Parser.h
inc/Picture.h
inc/Rasterizer.h
inc/Raytracer.h
inc/SceneGraph.h
inc/Texture.h
inc/Timer.h
inc/TonemapperGUI.h
inc/ShaderConfiguration.h
)

set( SOURCES
src/Application.cpp
src/Arena.cpp
src/Assimp.cpp
src/Box.cpp
src/Camera.cpp
src/Curves.cpp
src/Device.cpp
src/Hair.cpp
src/LoaderIES.cpp
src/main.cpp
src/MaterialMDL.cpp
src/NVMLImpl.cpp
src/Options.cpp
src/Parser.cpp
src/Picture.cpp
src/Plane.cpp
src/Rasterizer.cpp
src/Raytracer.cpp
src/SceneGraph.cpp
src/SignedDistanceField.cpp
src/Sphere.cpp
src/Texture.cpp
src/Timer.cpp
src/Torus.cpp
)

# Prefix the shaders with the full path name to allow stepping through errors with F8.
set( SHADERS
# Core shaders.
${CMAKE_CURRENT_SOURCE_DIR}/shaders/hit.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/intersection.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/exception.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/miss.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/raygeneration.cu

# Direct callables
${CMAKE_CURRENT_SOURCE_DIR}/shaders/lens_shader.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/light_sample.cu
)

set( KERNELS
# Native CUDA kernels
${CMAKE_CURRENT_SOURCE_DIR}/shaders/compositor.cu
)

set( SHADERS_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/shaders/camera_definition.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/compositor_data.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/config.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/curve.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/curve_attributes.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/function_indices.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/half_common.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/light_definition.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/material_definition_mdl.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/per_ray_data.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/random_number_generators.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/sdf_attributes.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_common.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_configuration.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/system_data.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/transform.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/texture_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/texture_lookup.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/vector_math.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/vertex_attributes.h
)

# 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.
NVCUDA_COMPILE_MODULE(
SOURCES ${SHADERS}
DEPENDENCIES ${SHADERS_HEADERS}
TARGET_PATH "${MODULE_TARGET_DIR}/MDL_sdf_core"
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" "--allow-unsupported-compiler" "-I${OPTIX_INCLUDE_DIR}" "-I${MDL_SDK_INCLUDE_DIRS}" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"
)

# The native CUDA Kernels will be translated to *.ptx unconditionally.
NVCUDA_COMPILE_MODULE(
SOURCES ${KERNELS}
DEPENDENCIES ${SHADERS_HEADERS}
TARGET_PATH "${MODULE_TARGET_DIR}/MDL_sdf_core"
EXTENSION ".ptx"
GENERATED_FILES KERNEL_MODULES
NVCC_OPTIONS "--ptx" "--machine=64" "--gpu-architecture=compute_50" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "--allow-unsupported-compiler" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"
)

source_group( "imgui" FILES ${IMGUI} )
source_group( "nvpro_math" FILES ${NVPRO_MATH} )
source_group( "headers" FILES ${HEADERS} )
source_group( "sources" FILES ${SOURCES} )
source_group( "shaders" FILES ${SHADERS} )
source_group( "shaders_headers" FILES ${SHADERS_HEADERS} )
source_group( "prg" FILES ${PROGRAM_MODULES} )
source_group( "kernels" FILES ${KERNELS} )
source_group( "ptx" FILES ${KERNEL_MODULES} )

include_directories(
"."
"inc"
"imgui"
${GLEW_INCLUDE_DIRS}
${GLFW_INCLUDE_DIR}
${OPTIX_INCLUDE_DIR}
${CUDAToolkit_INCLUDE_DIRS}
${IL_INCLUDE_DIR}
${ASSIMP_INCLUDE_DIRS}
${MDL_SDK_INCLUDE_DIRS}
)

add_definitions(
# Disable warnings for file operations fopen etc.
"-D_CRT_SECURE_NO_WARNINGS"
# DAR HACK Set this when building against the MDL SDK open-source version.
# There is some case inside the load_plugin() function which special cases the nv_freeimage.dll loading, but that is actually not reached.
"-DMDL_SOURCE_RELEASE"
)

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( MDL_sdf
${IMGUI}
${NVPRO_MATH}
${HEADERS}
${SOURCES}
${SHADERS_HEADERS}
${SHADERS}
${PROGRAM_MODULES}
${KERNEL_MODULES}
)

target_link_libraries( MDL_sdf
OpenGL::GL
${GLEW_LIBRARIES}
${GLFW_LIBRARIES}
CUDA::cuda_driver
${IL_LIBRARIES}
${ILU_LIBRARIES}
${ILUT_LIBRARIES}
${ASSIMP_LIBRARIES}
)

if (UNIX)
target_link_libraries( MDL_sdf dl )
endif()

set_target_properties( MDL_sdf PROPERTIES FOLDER "apps")

40 changes: 40 additions & 0 deletions apps/MDL_sdf/dp/math/Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#pragma once

// #include <dp/util/Config.h>

//#ifdef DP_OS_WINDOWS
//// microsoft specific storage-class defines
//# ifdef DP_MATH_EXPORTS
//# define DP_MATH_API __declspec(dllexport)
//# else
//# define DP_MATH_API __declspec(dllimport)
//# endif
//#else
// No need for a library, just use the dp::math functions as inline code.
# define DP_MATH_API
//#endif
Loading

0 comments on commit 3807f47

Please sign in to comment.