Skip to content

Commit

Permalink
Explicitly set the OptiX pipeline stack size. (AcademySoftwareFoundat…
Browse files Browse the repository at this point in the history
…ion#1254)

Co-authored-by: Tim Grant <[email protected]>
  • Loading branch information
2 people authored and lgritz committed Sep 23, 2020
1 parent 9efefc7 commit 7802ac3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
34 changes: 30 additions & 4 deletions src/testrender/optixraytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/imageworks/OpenShadingLanguage

#include <vector>

#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/sysutil.h>
Expand All @@ -14,6 +15,7 @@
#ifdef OSL_USE_OPTIX
# if (OPTIX_VERSION >= 70000)
# include <optix_function_table_definition.h>
# include <optix_stack_size.h>
# include <optix_stubs.h>
# include <cuda.h>
# include <nvrtc.h>
Expand Down Expand Up @@ -527,20 +529,18 @@ OptixRaytracer::make_optix_materials ()
size_t sizeof_msg_log;

// Make module that contains programs we'll use in this scene
OptixModuleCompileOptions module_compile_options;
OptixModuleCompileOptions module_compile_options = {};

module_compile_options.maxRegisterCount = OPTIX_COMPILE_DEFAULT_MAX_REGISTER_COUNT;
module_compile_options.optLevel = OPTIX_COMPILE_OPTIMIZATION_DEFAULT;
module_compile_options.optLevel = OPTIX_COMPILE_OPTIMIZATION_LEVEL_0;
module_compile_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_LINEINFO;
module_compile_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_FULL;

OptixPipelineCompileOptions pipeline_compile_options = {};

pipeline_compile_options.traversableGraphFlags = OPTIX_TRAVERSABLE_GRAPH_FLAG_ALLOW_ANY;
pipeline_compile_options.usesMotionBlur = false;
pipeline_compile_options.numPayloadValues = 3;
pipeline_compile_options.numAttributeValues = 3;
pipeline_compile_options.numAttributeValues = 3;
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
pipeline_compile_options.pipelineLaunchParamsVariableName = "render_params";

Expand Down Expand Up @@ -865,6 +865,32 @@ OptixRaytracer::make_optix_materials ()
//if (sizeof_msg_log > 1)
// printf ("Creating optix pipeline:\n%s\n", msg_log);

// Set the pipeline stack size
OptixStackSizes stack_sizes = {};
for( OptixProgramGroup& program_group : final_groups )
OPTIX_CHECK (optixUtilAccumulateStackSizes (program_group, &stack_sizes));

uint32_t max_trace_depth = 1;
uint32_t max_cc_depth = 1;
uint32_t max_dc_depth = 1;
uint32_t direct_callable_stack_size_from_traversal;
uint32_t direct_callable_stack_size_from_state;
uint32_t continuation_stack_size;
OPTIX_CHECK (optixUtilComputeStackSizes (&stack_sizes,
max_trace_depth,
max_cc_depth,
max_dc_depth,
&direct_callable_stack_size_from_traversal,
&direct_callable_stack_size_from_state,
&continuation_stack_size ) );

const uint32_t max_traversal_depth = 1;
OPTIX_CHECK (optixPipelineSetStackSize (m_optix_pipeline,
direct_callable_stack_size_from_traversal,
direct_callable_stack_size_from_state,
continuation_stack_size,
max_traversal_depth ));

// Build OptiX Shader Binding Table (SBT)

std::vector<GenericRecord> sbt_records(final_groups.size());
Expand Down
39 changes: 33 additions & 6 deletions src/testshade/optixgridrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/imageworks/OpenShadingLanguage

#include <vector>

#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/sysutil.h>
Expand All @@ -14,6 +15,7 @@
#ifdef OSL_USE_OPTIX
# if (OPTIX_VERSION >= 70000)
# include <optix_function_table_definition.h>
# include <optix_stack_size.h>
# include <optix_stubs.h>
# include <cuda.h>
# include <nvrtc.h>
Expand Down Expand Up @@ -440,12 +442,11 @@ OptixGridRenderer::make_optix_materials ()
size_t sizeof_msg_log;

// Make module that contains programs we'll use in this scene
OptixModuleCompileOptions module_compile_options;
OptixModuleCompileOptions module_compile_options = {};

module_compile_options.maxRegisterCount = OPTIX_COMPILE_DEFAULT_MAX_REGISTER_COUNT;
module_compile_options.optLevel = OPTIX_COMPILE_OPTIMIZATION_DEFAULT;
module_compile_options.optLevel = OPTIX_COMPILE_OPTIMIZATION_LEVEL_0;
module_compile_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_FULL;
module_compile_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_LINEINFO;

OptixPipelineCompileOptions pipeline_compile_options = {};

Expand Down Expand Up @@ -738,7 +739,7 @@ OptixGridRenderer::make_optix_materials ()
// printf ("Creating program group for string-library:\n%s\n", msg_log);

// Set up OptiX pipeline
OptixProgramGroup final_groups[] = {
std::vector<OptixProgramGroup> final_groups = {
strlib_group, // string globals
raygen_group,
miss_group,
Expand All @@ -751,13 +752,39 @@ OptixGridRenderer::make_optix_materials ()
OPTIX_CHECK (optixPipelineCreate (m_optix_ctx,
&pipeline_compile_options,
&pipeline_link_options,
&final_groups[0],
int(sizeof(final_groups)/sizeof(OptixProgramGroup)),
final_groups.data(),
int(final_groups.size()),
msg_log, &sizeof_msg_log,
&m_optix_pipeline));
//if (sizeof_msg_log > 1)
// printf ("Creating optix pipeline:\n%s\n", msg_log);

// Set the pipeline stack size
OptixStackSizes stack_sizes = {};
for( OptixProgramGroup& program_group : final_groups )
OPTIX_CHECK (optixUtilAccumulateStackSizes (program_group, &stack_sizes));

uint32_t max_trace_depth = 1;
uint32_t max_cc_depth = 1;
uint32_t max_dc_depth = 1;
uint32_t direct_callable_stack_size_from_traversal;
uint32_t direct_callable_stack_size_from_state;
uint32_t continuation_stack_size;
OPTIX_CHECK (optixUtilComputeStackSizes (&stack_sizes,
max_trace_depth,
max_cc_depth,
max_dc_depth,
&direct_callable_stack_size_from_traversal,
&direct_callable_stack_size_from_state,
&continuation_stack_size ) );

const uint32_t max_traversal_depth = 1;
OPTIX_CHECK (optixPipelineSetStackSize (m_optix_pipeline,
direct_callable_stack_size_from_traversal,
direct_callable_stack_size_from_state,
continuation_stack_size,
max_traversal_depth ));

// Build OptiX Shader Binding Table (SBT)
CUdeviceptr d_raygenRecord;
CUdeviceptr d_missRecord;
Expand Down

0 comments on commit 7802ac3

Please sign in to comment.