Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/example_common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Copyright Contributors to the Open Shading Language project.
SPDX-License-Identifier: BSD-3-Clause -->

# Shared code for the example renderers

`testshade` and `testrender` are separate examples of OSL integration. Both
need the render state and free-function renderer services in this directory.
Their OptiX paths also use the CUDA renderer library in `cuda/`.

Each example compiles the shared sources into its own LLVM bitcode and PTX.
There is no library target to link: the generated code is embedded in each
executable, and each executable installs PTX under its existing filename.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include <OSL/hashes.h>
#include <OSL/oslexec.h>

#include "../raytracer.h"


OSL_NAMESPACE_BEGIN


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#pragma once

#include <cassert>
#include <cstddef>
#include <cstdint>

#include <OpenImageIO/fmath.h>

#include <OSL/hashes.h>
#include <OSL/oslconfig.h>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

Expand Down
20 changes: 16 additions & 4 deletions src/testrender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

# The 'testrender' executable
set (example_common_dir "${PROJECT_SOURCE_DIR}/src/example_common")

set (testrender_srcs
shading.cpp
simpleraytracer.cpp
Expand All @@ -13,20 +15,25 @@ set (testrender_srcs
find_package(Threads REQUIRED)

if (OSL_USE_OPTIX)
# NVCC_COMPILE and MAKE_CUDA_BITCODE use custom commands rather than the
# target's include directories.
list (APPEND OSL_CUDA_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src")
list (APPEND testrender_srcs optixraytracer.cpp)
set (testrender_cuda_srcs
cuda/optix_raytracer.cu
)

set (testrender_rend_lib_srcs
cuda/rend_lib.cu
../testshade/rs_simplerend.cpp
"${example_common_dir}/cuda/rend_lib.cu"
"${example_common_dir}/rs_simplerend.cpp"
)

# We need to make sure that the PTX files are regenerated whenever these
# files change.
set (testrender_cuda_headers
cuda/rend_lib.h
"${example_common_dir}/cuda/rend_lib.h"
"${example_common_dir}/render_state.h"
"${example_common_dir}/rs_strdecls.h"
background.h
optics.h
render_params.h
Expand All @@ -36,6 +43,10 @@ if (OSL_USE_OPTIX)
shading.cpp
simpleraytracer.cpp
)
list (APPEND exec_headers
"${example_common_dir}/cuda/rend_lib.h"
"${example_common_dir}/render_state.h"
"${example_common_dir}/rs_strdecls.h")

# Generate PTX for all of the CUDA files
foreach (cudasrc ${testrender_cuda_srcs})
Expand Down Expand Up @@ -77,7 +88,8 @@ endif ()

add_executable (testrender ${testrender_srcs})

target_include_directories (testrender BEFORE PRIVATE ${OpenImageIO_INCLUDES})
target_include_directories (testrender BEFORE PRIVATE
${OpenImageIO_INCLUDES} "${PROJECT_SOURCE_DIR}/src")

target_link_libraries (testrender
PRIVATE
Expand Down
17 changes: 9 additions & 8 deletions src/testrender/cuda/optix_raytracer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

#include <OSL/hashes.h>

#include "example_common/cuda/rend_lib.h"
#include "example_common/render_state.h"
#include "optix_raytracer.h"
#include "rend_lib.h"

#include "../background.h"
#include "../bvh.h"
#include "../raytracer.h"
#include "../render_params.h"
#include "../sampling.h"
#include "../shading.cpp"
#include "testrender/background.h"
#include "testrender/bvh.h"
#include "testrender/raytracer.h"
#include "testrender/render_params.h"
#include "testrender/sampling.h"
#include "testrender/shading.cpp"

#include <cstdint>

Expand Down Expand Up @@ -312,6 +313,6 @@ __raygen__deferred()

// We need to pull in the definition of SimpleRaytracer::subpixel_radiance(),
// which is shared between the host and CUDA renderers.
#include "../simpleraytracer.cpp"
#include "testrender/simpleraytracer.cpp"

//------------------------------------------------------------------------------
8 changes: 4 additions & 4 deletions src/testrender/cuda/optix_raytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <OSL/oslconfig.h>
#include <optix.h>

#include "../background.h"
#include "../raytracer.h"
#include "../sampling.h"
#include "rend_lib.h"
#include "example_common/cuda/rend_lib.h"
#include "testrender/background.h"
#include "testrender/raytracer.h"
#include "testrender/sampling.h"

#include <cstdint>

Expand Down
5 changes: 0 additions & 5 deletions src/testrender/raytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <OpenImageIO/fmath.h>

#include "../testshade/render_state.h"
#include "optix_compat.h"
#include "render_params.h"
#include <OSL/dual_vec.h>
Expand All @@ -21,10 +20,6 @@
# include <vector_functions.h> // from CUDA
#endif

#ifdef __CUDACC__
# include "cuda/rend_lib.h"
#endif

// The primitives don't included the intersection routines, etc., from the
// versions in testrender, since those operations are performed on the GPU.
//
Expand Down
32 changes: 23 additions & 9 deletions src/testshade/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

# The 'testshade' executable
set (example_common_dir "${PROJECT_SOURCE_DIR}/src/example_common")
list (APPEND exec_headers
"${example_common_dir}/render_state.h"
"${example_common_dir}/rs_strdecls.h")

set ( testshade_srcs
testshade.cpp
simplerend.cpp )
Expand All @@ -13,29 +18,35 @@ if (OSL_BUILD_BATCHED)
endif()

if (OSL_USE_OPTIX)
# NVCC_COMPILE and MAKE_CUDA_BITCODE use custom commands rather than the
# target's include directories.
list (APPEND OSL_CUDA_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src")
list (APPEND testshade_srcs optixgridrender.cpp)
set ( testshade_cuda_srcs
cuda/optix_grid_renderer.cu
)

set (testshade_rend_lib_srcs
../testrender/cuda/rend_lib.cu
rs_simplerend.cpp
"${example_common_dir}/cuda/rend_lib.cu"
"${example_common_dir}/rs_simplerend.cpp"
)

set ( testshade_cuda_headers
../testrender/cuda/rend_lib.h
../testrender/raytracer.h
"${example_common_dir}/cuda/rend_lib.h"
"${example_common_dir}/render_state.h"
"${example_common_dir}/rs_strdecls.h"
)
list (APPEND exec_headers "${example_common_dir}/cuda/rend_lib.h")

# We need to make sure that the PTX files are regenerated whenever these
# headers change.
set ( extra_cuda_headers
render_params.h )
render_params.h
${testshade_cuda_headers} )

# Generate PTX for all of the CUDA files
foreach (cudasrc ${testshade_cuda_srcs})
NVCC_COMPILE ( ${cudasrc} ${extra_cuda_headers} ptx_generated "-I../testrender/cuda" "")
NVCC_COMPILE ( ${cudasrc} "${extra_cuda_headers}" ptx_generated "" "")
list (APPEND ptx_list ${ptx_generated})
endforeach ()

Expand Down Expand Up @@ -65,10 +76,11 @@ if (OSL_USE_OPTIX)
endif()

set ( rs_srcs
rs_simplerend.cpp )
"${example_common_dir}/rs_simplerend.cpp" )

set(include_dirs ${CMAKE_CURRENT_SOURCE_DIR})
list(APPEND include_dirs ${CMAKE_SOURCE_DIR}/src/include)
list(APPEND include_dirs ${PROJECT_SOURCE_DIR}/src)
list(APPEND include_dirs ${CMAKE_BINARY_DIR}/include)
list(APPEND include_dirs ${IMATH_INCLUDES})
list(APPEND include_dirs ${OpenImageIO_INCLUDES})
Expand All @@ -77,7 +89,8 @@ EMBED_LLVM_BITCODE_IN_CPP ( "${rs_srcs}" "_host" "testshade_llvm_compiled_rs" te

add_executable ( testshade ${testshade_srcs} testshademain.cpp )

target_include_directories (testshade BEFORE PRIVATE ${OpenImageIO_INCLUDES})
target_include_directories (testshade BEFORE PRIVATE
${OpenImageIO_INCLUDES} "${PROJECT_SOURCE_DIR}/src")

target_link_libraries (testshade
PRIVATE
Expand Down Expand Up @@ -120,7 +133,8 @@ if (NOT CODECOV)
target_link_libraries (libtestshade
PRIVATE
oslexec oslquery oslcomp)
target_include_directories (libtestshade BEFORE PRIVATE ${OpenImageIO_INCLUDES})
target_include_directories (libtestshade BEFORE PRIVATE
${OpenImageIO_INCLUDES} "${PROJECT_SOURCE_DIR}/src")
set_target_properties (libtestshade PROPERTIES PREFIX "")

install_targets ( libtestshade )
Expand Down
8 changes: 5 additions & 3 deletions src/testshade/cuda/optix_grid_renderer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include <optix_device.h>

#include "rend_lib.h"
#include "example_common/cuda/rend_lib.h"
#include "example_common/render_state.h"


#include "render_params.h"
Expand Down Expand Up @@ -80,7 +81,8 @@ __raygen__()
uint3 launch_dims = optixGetLaunchDimensions();
uint3 launch_index = optixGetLaunchIndex();

auto sbtdata = reinterpret_cast<GenericData*>(optixGetSbtDataPointer());
auto sbtdata = reinterpret_cast<testshade::GenericData*>(
optixGetSbtDataPointer());

const float invw = render_params.invw;
const float invh = render_params.invh;
Expand Down Expand Up @@ -130,7 +132,7 @@ __raygen__()
sg.backfacing = 0;

// NB: These variables are not used in the current iteration of the sample
sg.raytype = OSL::Ray::CAMERA;
sg.raytype = 1; // "camera" is the first default OSL ray type.
sg.flipHandedness = 0;

sg.shader2common = reinterpret_cast<void*>(render_params.shader2common);
Expand Down
4 changes: 2 additions & 2 deletions src/testshade/simplerend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace RS {
namespace Strings {
#define RS_STRDECL(str, var_name) const OSL::ustring var_name { str };
#include "rs_strdecls.h"
#include "example_common/rs_strdecls.h"
#undef RS_STRDECL
} // namespace Strings
} // namespace RS
Expand All @@ -33,7 +33,7 @@ namespace {
namespace Hashes {
#define RS_STRDECL(str, var_name) \
constexpr OSL::ustringhash var_name(OSL::strhash(str));
#include "rs_strdecls.h"
#include "example_common/rs_strdecls.h"
#undef RS_STRDECL
}; //namespace Hashes
} // unnamed namespace
Expand Down
2 changes: 1 addition & 1 deletion src/testshade/simplerend.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# include "batched_simplerend.h"
#endif

#include "render_state.h"
#include "example_common/render_state.h"

OSL_NAMESPACE_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion src/testshade/testshade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# include "optixgridrender.h"
#endif

#include "render_state.h"
#include "example_common/render_state.h"
#include "simplerend.h"


Expand Down
Loading