Skip to content

Commit 2581dd6

Browse files
rtabbaranjroussel
authored andcommitted
Add OptiX debug/validation level as CMake options
1 parent 883e26e commit 2581dd6

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ option(DRJIT_ENABLE_TESTS "Build Dr.Jit-Core test suite?" OFF)
2020
if (NOT APPLE)
2121
option(DRJIT_DYNAMIC_CUDA "Resolve CUDA dynamically at run time?" ON)
2222
option(DRJIT_ENABLE_OPTIX "Allow the use of OptiX ray tracing calls in kernels?" ON)
23+
option(DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION "Enable debug and validation flags for OptiX" OFF)
2324
endif()
2425

2526
# ----------------------------------------------------------
@@ -60,6 +61,12 @@ if (NOT APPLE)
6061
else()
6162
message(STATUS "Dr.Jit-Core: OptiX support disabled.")
6263
endif()
64+
65+
if (DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION)
66+
message(STATUS "Dr.Jit-Core: OptiX debug and validation flags enabled.")
67+
else()
68+
message(STATUS "Dr.Jit-Core: OptiX debug and validation flags disabled.")
69+
endif()
6370
endif()
6471

6572
# ----------------------------------------------------------
@@ -193,6 +200,10 @@ if (DRJIT_ENABLE_OPTIX)
193200
endif()
194201
endif()
195202

203+
if (DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION)
204+
target_compile_definitions(drjit-core PRIVATE -DDRJIT_ENABLE_OPTIX_DEBUG_VALIDATION)
205+
endif()
206+
196207
# Generate ITT notifications (e.g. for VTune) if part of a larger project
197208
# that provides an 'ittnotify' target
198209
if (TARGET ittnotify)

src/optix_core.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include "op.h"
1010
#include "util.h"
1111

12-
#define ENABLE_OPTIX_VALIDATION_MODE 0
12+
#if !defined(NDEBUG) || defined(DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION)
13+
#define DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION_ON
14+
#endif
1315

1416
#define jitc_optix_check(err) jitc_optix_check_impl((err), __FILE__, __LINE__)
1517
extern void jitc_optix_check_impl(OptixResult errval, const char *file, const int line);
@@ -37,7 +39,7 @@ static OptixPipelineCompileOptions jitc_optix_default_compile_options() {
3739
pco.numAttributeValues = 2;
3840
pco.pipelineLaunchParamsVariableName = "params";
3941

40-
#if defined(NDEBUG)
42+
#ifndef DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION_ON
4143
pco.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE;
4244
#else
4345
pco.exceptionFlags = OPTIX_EXCEPTION_FLAG_DEBUG |
@@ -58,7 +60,7 @@ OptixDeviceContext jitc_optix_context() {
5860

5961
OptixDeviceContextOptions ctx_opts {
6062
jitc_optix_log, nullptr, 4,
61-
#if defined(NDEBUG) || !ENABLE_OPTIX_VALIDATION_MODE
63+
#ifndef DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION_ON
6264
OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_OFF
6365
#else
6466
OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_ALL
@@ -85,11 +87,11 @@ OptixDeviceContext jitc_optix_context() {
8587
if (!state.optix_default_sbt_index) {
8688
OptixPipelineCompileOptions pco = jitc_optix_default_compile_options();
8789
OptixModuleCompileOptions mco { };
88-
#if 1
90+
#ifndef DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION_ON
8991
mco.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_NONE;
9092
mco.optLevel = OPTIX_COMPILE_OPTIMIZATION_LEVEL_3;
9193
#else
92-
mco.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_MINIMAL;
94+
mco.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_FULL;
9395
mco.optLevel = OPTIX_COMPILE_OPTIMIZATION_LEVEL_0;
9496
#endif
9597

@@ -239,11 +241,11 @@ bool jitc_optix_compile(ThreadState *ts, const char *buf, size_t buf_size,
239241
// =====================================================
240242

241243
OptixModuleCompileOptions mco { };
242-
#if 1
244+
#ifndef DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION_ON
243245
mco.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_NONE;
244246
mco.optLevel = OPTIX_COMPILE_OPTIMIZATION_LEVEL_3;
245247
#else
246-
mco.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_MINIMAL;
248+
mco.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_FULL;
247249
mco.optLevel = OPTIX_COMPILE_OPTIMIZATION_LEVEL_0;
248250
#endif
249251

@@ -356,7 +358,11 @@ bool jitc_optix_compile(ThreadState *ts, const char *buf, size_t buf_size,
356358

357359
OptixPipelineLinkOptions link_options {};
358360
link_options.maxTraceDepth = 1;
361+
#ifndef DRJIT_ENABLE_OPTIX_DEBUG_VALIDATION_ON
359362
link_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_NONE;
363+
#else
364+
link_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_FULL;
365+
#endif
360366

361367
size_t size_before = pipeline.program_groups.size();
362368
#if 0

0 commit comments

Comments
 (0)