Skip to content

Commit 8253228

Browse files
authored
Merge pull request #19 from uos/fix/optix8-debug
Fix/optix8 debug
2 parents 3a9bbf0 + 68917c9 commit 8253228

File tree

11 files changed

+135
-92
lines changed

11 files changed

+135
-92
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22
project(rmagine
33
LANGUAGES CXX C
4-
VERSION 2.4.0)# TODO update this version when merging into main-branch
4+
VERSION 2.4.1)# TODO update this version when merging into main-branch
55

66
option(RMAGINE_BUILD_TOOLS "Build tools" ON)
77
option(RMAGINE_BUILD_TESTS "Build tests" ON)

package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<package format="2">
33
<name>rmagine</name>
4-
<version>2.4.0</version>
4+
<version>2.4.1</version>
55
<description>
66
Library for fast and accurate simulation of range sensors in large 3D environments using ray tracing. The simulations can even be computed on embedded devices installed on a robot.
77
</description>

src/rmagine_optix/src/simulation/optix/O1DnProgramRanges.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ O1DnProgramRanges::O1DnProgramRanges(OptixMapPtr map)
6161
pipeline_compile_options.numPayloadValues = 1;
6262
pipeline_compile_options.numAttributeValues = 2;
6363
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
64-
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
64+
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
65+
#if OPTIX_VERSION < 80000
66+
pipeline_compile_options.exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
67+
#endif
6568
#else
6669
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
6770
#endif

src/rmagine_optix/src/simulation/optix/OnDnProgramRanges.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ OnDnProgramRanges::OnDnProgramRanges(OptixMapPtr map)
6161
pipeline_compile_options.numPayloadValues = 1;
6262
pipeline_compile_options.numAttributeValues = 2;
6363
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
64-
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
64+
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
65+
#if OPTIX_VERSION < 80000
66+
pipeline_compile_options.exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
67+
#endif
6568
#else
6669
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
6770
#endif

src/rmagine_optix/src/simulation/optix/PinholeProgramRanges.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ PinholeProgramRanges::PinholeProgramRanges(OptixMapPtr map)
6161
pipeline_compile_options.numPayloadValues = 1;
6262
pipeline_compile_options.numAttributeValues = 2;
6363
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
64-
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
64+
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
65+
#if OPTIX_VERSION < 80000
66+
pipeline_compile_options.exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
67+
#endif
6568
#else
6669
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
6770
#endif
@@ -72,7 +75,7 @@ PinholeProgramRanges::PinholeProgramRanges(OptixMapPtr map)
7275

7376
if(ptx.empty())
7477
{
75-
throw std::runtime_error("ScanProgramRanges could not find its PTX part");
78+
throw std::runtime_error("PinholeProgramRanges could not find its PTX part");
7679
}
7780

7881
#if OPTIX_VERSION < 70700

src/rmagine_optix/src/simulation/optix/SphereProgramRanges.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ SphereProgramRanges::SphereProgramRanges(OptixMapPtr map)
6262
pipeline_compile_options.numPayloadValues = 1;
6363
pipeline_compile_options.numAttributeValues = 2;
6464
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
65-
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
65+
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
66+
#if OPTIX_VERSION < 80000
67+
pipeline_compile_options.exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
68+
#endif
6669
#else
6770
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
6871
#endif
@@ -73,7 +76,7 @@ SphereProgramRanges::SphereProgramRanges(OptixMapPtr map)
7376

7477
if(ptx.empty())
7578
{
76-
throw std::runtime_error("ScanProgramRanges could not find its PTX part");
79+
throw std::runtime_error("SphereProgramRanges could not find its PTX part");
7780
}
7881

7982
#if OPTIX_VERSION < 70700

src/rmagine_optix/src/simulation/optix/sim_modules.cpp

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <rmagine/map/optix/OptixScene.hpp>
66
#include <rmagine/simulation/optix/common.h>
77

8+
#include <optix.h>
9+
810

911
namespace rmagine
1012
{
@@ -114,22 +116,24 @@ ProgramModulePtr make_program_module_sim_gen(
114116
#endif
115117

116118

117-
#if OPTIX_VERSION >= 70400
118-
ret->compile_options->numPayloadTypes = 1;
119-
RM_CUDA_CHECK(cudaMallocHost(&ret->compile_options->payloadTypes, sizeof(OptixPayloadType) ) );
119+
// TODO (amock): After adding optix.h, OPTIX_VERSION was showing up and triggering this. However, this was not compiling
120+
// ... my fix was to comment this. All tests are running fine. I don't know why
121+
// #if OPTIX_VERSION >= 70400
122+
// ret->compile_options->numPayloadTypes = 1;
123+
// RM_CUDA_CHECK(cudaMallocHost(&ret->compile_options->payloadTypes, sizeof(OptixPayloadType) ) );
120124

121-
ret->compile_options->payloadTypes[0].numPayloadValues = 8;
122-
ret->compile_options->payloadTypes[0].payloadSemantics = (const unsigned int[8]) {
123-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
124-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
125-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
126-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
127-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
128-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
129-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
130-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ
131-
};
132-
#endif
125+
// ret->compile_options->payloadTypes[0].numPayloadValues = 8;
126+
// ret->compile_options->payloadTypes[0].payloadSemantics = (const unsigned int[8]) {
127+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
128+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
129+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
130+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
131+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
132+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
133+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
134+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ
135+
// };
136+
// #endif
133137

134138
ProgramModulePtr module = std::make_shared<ProgramModule>();
135139

@@ -170,8 +174,6 @@ ProgramModulePtr make_program_module_sim_gen(
170174
OptixPipelineCompileOptions pipeline_compile_options = {};
171175
{
172176
pipeline_compile_options.usesMotionBlur = false;
173-
174-
175177
pipeline_compile_options.traversableGraphFlags = traversable_graph_flags;
176178

177179
// max payload values: 32
@@ -183,7 +185,10 @@ ProgramModulePtr make_program_module_sim_gen(
183185
#endif
184186
pipeline_compile_options.numAttributeValues = 2;
185187
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
186-
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
188+
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
189+
#if OPTIX_VERSION < 80000
190+
pipeline_compile_options.exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
191+
#endif
187192
#else
188193
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
189194
#endif
@@ -247,22 +252,24 @@ ProgramModulePtr make_program_module_sim_hit_miss(
247252
ret->compile_options->boundValues = &bounds[0];
248253
ret->compile_options->numBoundValues = bounds.size();
249254

250-
#if OPTIX_VERSION >= 70400
251-
ret->compile_options->numPayloadTypes = 1;
252-
RM_CUDA_CHECK(cudaMallocHost(&ret->compile_options->payloadTypes, sizeof(OptixPayloadType) ) );
255+
// TODO (amock): After adding optix.h, OPTIX_VERSION was showing up and triggering this. However, this was not compiling
256+
// ... my fix was to comment this. All tests are running fine. I don't know why
257+
// #if OPTIX_VERSION >= 70400
258+
// ret->compile_options->numPayloadTypes = 1;
259+
// RM_CUDA_CHECK(cudaMallocHost(&ret->compile_options->payloadTypes, sizeof(OptixPayloadType) ) );
253260

254-
ret->compile_options->payloadTypes[0]->numPayloadValues = 8;
255-
ret->compile_options->payloadTypes[0]->payloadSemantics = (const unsigned int[8]) {
256-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
257-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
258-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
259-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
260-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
261-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
262-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
263-
OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ
264-
};
265-
#endif
261+
// ret->compile_options->payloadTypes[0]->numPayloadValues = 8;
262+
// ret->compile_options->payloadTypes[0]->payloadSemantics = (const unsigned int[8]) {
263+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
264+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
265+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
266+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
267+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
268+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
269+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ,
270+
// OPTIX_PAYLOAD_SEMANTICS_TRACE_CALLER_WRITE | OPTIX_PAYLOAD_SEMANTICS_CH_READ | OPTIX_PAYLOAD_SEMANTICS_MS_READ
271+
// };
272+
// #endif
266273

267274
ret->ptx = std::string(kernel);
268275

@@ -291,7 +298,12 @@ ProgramModulePtr make_program_module_sim_hit_miss(
291298
// pipeline_compile_options.numPayloadValues = 8;
292299
pipeline_compile_options.numAttributeValues = 2;
293300
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
294-
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
301+
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
302+
303+
// #pragma message "The value of ABC is: " XSTR(OPTIX_VERSION)
304+
#if OPTIX_VERSION < 80000
305+
pipeline_compile_options.exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
306+
#endif
295307
#else
296308
pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
297309
#endif

src/rmagine_optix/src/simulation/optix/sim_pipelines.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <rmagine/map/optix/OptixScene.hpp>
88
#include <rmagine/simulation/optix/common.h>
99

10+
#include <optix.h>
11+
1012
namespace rmagine
1113
{
1214

@@ -113,7 +115,12 @@ SimPipelinePtr make_pipeline_sim(
113115
// pipeline_compile_options.numPayloadValues = 8;
114116
ret->compile_options->numAttributeValues = 2;
115117
#ifndef NDEBUG // Enables debug exceptions during optix launches. This may incur significant performance cost and should only be done during development.
116-
ret->compile_options->exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
118+
ret->compile_options->exceptionFlags = OPTIX_EXCEPTION_FLAG_USER | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH | OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
119+
120+
#if OPTIX_VERSION < 80000
121+
ret->compile_options->exceptionFlags |= OPTIX_EXCEPTION_FLAG_DEBUG;
122+
#endif
123+
117124
#else
118125
ret->compile_options->exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
119126
#endif

src/rmagine_optix/src/simulation/optix/sim_program_groups.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "rmagine/util/optix/OptixDebug.hpp"
66

77
#include <optix_stubs.h>
8+
#include <optix.h>
89

910
namespace rmagine
1011
{

src/rmagine_optix/src/util/optix/OptixContext.cpp

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ std::map<unsigned int, unsigned int> optix_driver_map = {
1616

1717
static void context_log_cb( unsigned int level, const char* tag, const char* message, void* /*cbdata */)
1818
{
19-
std::cerr << "[" << std::setw( 2 ) << level << "][" << std::setw( 12 ) << tag << "]: "
20-
<< message << "\n";
19+
std::cerr << "[" << std::setw( 2 ) << level << "][" << std::setw( 12 ) << tag << "]: "
20+
<< message << "\n";
2121
}
2222

2323
namespace rmagine {
@@ -26,78 +26,86 @@ bool optix_initialized_ = false;
2626

2727
bool optix_initialized()
2828
{
29-
return optix_initialized_;
29+
return optix_initialized_;
3030
}
3131

3232
void optix_initialize()
3333
{
34-
std::stringstream optix_version_str;
35-
optix_version_str << OPTIX_VERSION / 10000 << "." << (OPTIX_VERSION % 10000) / 100 << "." << OPTIX_VERSION % 100;
36-
37-
auto driver_it = optix_driver_map.upper_bound(OPTIX_VERSION);
38-
unsigned int required_driver_version = 0;
39-
if(driver_it == optix_driver_map.begin())
40-
{
41-
required_driver_version = 45671;
42-
} else {
43-
--driver_it;
44-
}
45-
46-
required_driver_version = driver_it->second;
47-
48-
std::cout << "[RMagine - OptixContext] Init Optix (" << optix_version_str.str() << "). Required GPU driver >= " << driver_it->second / 100 << "." << driver_it->second % 100;
49-
50-
if(driver_it->first != OPTIX_VERSION)
51-
{
52-
std::cout << " for Optix " << driver_it->first / 10000 << "." << (driver_it->first % 10000) / 100 << "." << driver_it->first % 100;
53-
}
54-
55-
std::cout << std::endl;
56-
RM_OPTIX_CHECK( optixInit() );
57-
optix_initialized_ = true;
34+
std::stringstream optix_version_str;
35+
optix_version_str << OPTIX_VERSION / 10000 << "." << (OPTIX_VERSION % 10000) / 100 << "." << OPTIX_VERSION % 100;
36+
37+
auto driver_it = optix_driver_map.upper_bound(OPTIX_VERSION);
38+
unsigned int required_driver_version = 0;
39+
if(driver_it == optix_driver_map.begin())
40+
{
41+
required_driver_version = 45671;
42+
} else {
43+
--driver_it;
44+
}
45+
46+
required_driver_version = driver_it->second;
47+
48+
std::cout << "[RMagine - OptixContext] Init Optix (" << optix_version_str.str() << "). Required GPU driver >= " << driver_it->second / 100 << "." << driver_it->second % 100;
49+
50+
if(driver_it->first != OPTIX_VERSION)
51+
{
52+
std::cout << " for Optix " << driver_it->first / 10000 << "." << (driver_it->first % 10000) / 100 << "." << driver_it->first % 100;
53+
}
54+
55+
std::cout << std::endl;
56+
RM_OPTIX_CHECK( optixInit() );
57+
optix_initialized_ = true;
5858
}
5959

6060
OptixContext::OptixContext(CudaContextPtr cuda_context)
6161
:m_cuda_context(cuda_context)
6262
{
63-
init(cuda_context);
64-
// std::cout << "[OptixContext::OptixContext()] constructed." << std::endl;
63+
init(cuda_context);
64+
// std::cout << "[OptixContext::OptixContext()] constructed." << std::endl;
6565
}
6666

6767
OptixContext::~OptixContext()
6868
{
69-
optixDeviceContextDestroy( m_optix_context );
70-
// std::cout << "[OptixContext::~OptixContext()] destroyed." << std::endl;
69+
optixDeviceContextDestroy( m_optix_context );
70+
// std::cout << "[OptixContext::~OptixContext()] destroyed." << std::endl;
7171
}
7272

7373
CudaContextPtr OptixContext::getCudaContext()
7474
{
75-
return m_cuda_context;
75+
return m_cuda_context;
7676
}
7777

7878
OptixDeviceContext OptixContext::ref()
7979
{
80-
return m_optix_context;
80+
return m_optix_context;
8181
}
8282

8383
void OptixContext::init(CudaContextPtr cuda_context)
8484
{
85-
if(!optix_initialized())
86-
{
87-
optix_initialize();
88-
}
89-
90-
// Specify context options
91-
OptixDeviceContextOptions options = {};
92-
options.logCallbackFunction = &context_log_cb;
93-
options.logCallbackLevel = 3;
94-
// 0: disable Setting the callback level will disable all messages. The callback function will not be called in this case
95-
// 1: fatal A non-recoverable error. The context and/or OptiX itself might no longer be in a usable state.
96-
// 2: error A recoverable error, e.g., when passing invalid call parameters.
97-
// 3: warning Hints that OptiX might not behave exactly as requested by the user or may perform slower than expected.
98-
// 4: print Status or progress messages.
99-
100-
RM_OPTIX_CHECK( optixDeviceContextCreate( cuda_context->ref(), &options, &m_optix_context ) );
85+
if(!optix_initialized())
86+
{
87+
optix_initialize();
88+
}
89+
90+
// Specify context options
91+
OptixDeviceContextOptions options = {};
92+
options.logCallbackFunction = &context_log_cb;
93+
options.logCallbackLevel = 3;
94+
// 0: disable Setting the callback level will disable all messages. The callback function will not be called in this case
95+
// 1: fatal A non-recoverable error. The context and/or OptiX itself might no longer be in a usable state.
96+
// 2: error A recoverable error, e.g., when passing invalid call parameters.
97+
// 3: warning Hints that OptiX might not behave exactly as requested by the user or may perform slower than expected.
98+
// 4: print Status or progress messages.
99+
100+
#if OPTIX_VERSION >= 80000
101+
#if !defined(NDEBUG)
102+
options.validationMode = OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_ALL;
103+
#else
104+
options.validationMode = OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_OFF;
105+
#endif
106+
#endif
107+
108+
RM_OPTIX_CHECK( optixDeviceContextCreate( cuda_context->ref(), &options, &m_optix_context ) );
101109
}
102110

103111
OptixContextPtr optix_def_ctx(new OptixContext(cuda_current_context()) );

0 commit comments

Comments
 (0)