Skip to content

Commit 483f8ca

Browse files
author
Felix Igelbrink
committed
experimental support for optix 7.5
1 parent 85b61d0 commit 483f8ca

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

optix/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.1"
1+
__version__ = "0.1.2"

optix/build.pxd

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ cdef extern from "optix.h" nogil:
3333
float timeBegin
3434
float timeEnd
3535

36+
3637
cdef struct OptixAccelBuildOptions:
3738
unsigned int buildFlags
3839
OptixBuildOperation operation
3940
OptixMotionOptions motionOptions
4041

42+
4143
cdef enum OptixBuildInputType:
4244
OPTIX_BUILD_INPUT_TYPE_TRIANGLES,
4345
OPTIX_BUILD_INPUT_TYPE_CUSTOM_PRIMITIVES,
@@ -51,6 +53,7 @@ cdef extern from "optix.h" nogil:
5153
CUdeviceptr instances
5254
unsigned int numInstances
5355

56+
5457
cdef struct OptixAabb:
5558
float minX
5659
float minY
@@ -59,6 +62,7 @@ cdef extern from "optix.h" nogil:
5962
float maxY
6063
float maxZ
6164

65+
6266
cdef struct OptixBuildInputCustomPrimitiveArray:
6367
const CUdeviceptr * aabbBuffers
6468
unsigned int numPrimitives
@@ -70,6 +74,7 @@ cdef extern from "optix.h" nogil:
7074
unsigned int sbtIndexOffsetStrideInBytes
7175
unsigned int primitiveIndexOffset
7276

77+
7378
IF _OPTIX_VERSION_MAJOR == 7 and _OPTIX_VERSION_MINOR > 4: # switch to new instance flags
7479
cdef enum OptixPrimitiveType:
7580
OPTIX_PRIMITIVE_TYPE_CUSTOM,
@@ -95,11 +100,13 @@ cdef extern from "optix.h" nogil:
95100
OPTIX_PRIMITIVE_TYPE_ROUND_LINEAR,
96101
OPTIX_PRIMITIVE_TYPE_TRIANGLE,
97102

103+
98104
IF _OPTIX_VERSION_MAJOR == 7 and _OPTIX_VERSION_MINOR > 3: # switch to new instance flags
99105
cdef enum OptixCurveEndcapFlags:
100106
OPTIX_CURVE_ENDCAP_DEFAULT,
101107
OPTIX_CURVE_ENDCAP_ON
102108

109+
103110
cdef struct OptixBuildInputCurveArray:
104111
OptixPrimitiveType curveType
105112
unsigned int numPrimitives
@@ -131,11 +138,13 @@ cdef extern from "optix.h" nogil:
131138
unsigned int flag
132139
unsigned int primitiveIndexOffset
133140

141+
134142
cdef enum OptixIndicesFormat:
135143
OPTIX_INDICES_FORMAT_NONE,
136144
OPTIX_INDICES_FORMAT_UNSIGNED_SHORT3,
137145
OPTIX_INDICES_FORMAT_UNSIGNED_INT3
138146

147+
139148
cdef enum OptixVertexFormat:
140149
OPTIX_VERTEX_FORMAT_NONE,
141150
OPTIX_VERTEX_FORMAT_FLOAT3,
@@ -145,11 +154,13 @@ cdef extern from "optix.h" nogil:
145154
OPTIX_VERTEX_FORMAT_SNORM16_3,
146155
OPTIX_VERTEX_FORMAT_SNORM16_2
147156

157+
148158
cdef enum OptixTransformFormat:
149159
OPTIX_TRANSFORM_FORMAT_NONE,
150160
OPTIX_TRANSFORM_FORMAT_MATRIX_FLOAT12,
151161

152-
IF _OPTIX_VERSION_MAJOR == 7 and _OPTIX_VERSION_MINOR > 4: # switch to new geometry flags
162+
163+
IF _OPTIX_VERSION > 70400: # switch to new geometry flags
153164
cdef enum OptixGeometryFlags:
154165
OPTIX_GEOMETRY_FLAG_NONE,
155166
OPTIX_GEOMETRY_FLAG_DISABLE_ANYHIT,
@@ -179,7 +190,8 @@ cdef extern from "optix.h" nogil:
179190
unsigned int primitiveIndexOffset
180191
OptixTransformFormat transformFormat
181192

182-
IF _OPTIX_VERSION_MAJOR == 7 and _OPTIX_VERSION_MINOR > 4: # switch to new geometry flags
193+
194+
IF _OPTIX_VERSION > 70400: # switch to new geometry flags
183195
cdef struct OptixBuildInputSphereArray:
184196
const CUdeviceptr* vertexBuffers
185197
unsigned int vertexStrideInBytes
@@ -211,24 +223,30 @@ cdef extern from "optix.h" nogil:
211223
OptixBuildInputCustomPrimitiveArray customPrimitiveArray
212224
OptixBuildInputInstanceArray instanceArray
213225

226+
214227
cdef struct OptixAccelBufferSizes:
215228
size_t outputSizeInBytes
216229
size_t tempSizeInBytes
217230
size_t tempUpdateSizeInBytes
218231

232+
219233
cdef enum OptixAccelPropertyType:
220234
OPTIX_PROPERTY_TYPE_COMPACTED_SIZE,
221235
OPTIX_PROPERTY_TYPE_AABBS,
222236

237+
223238
cdef struct OptixAccelEmitDesc:
224239
CUdeviceptr result
225240
OptixAccelPropertyType type
226241

242+
227243
ctypedef uintptr_t OptixTraversableHandle
228244

245+
229246
cdef struct OptixAccelRelocationInfo:
230247
unsigned long long info[4]
231248

249+
232250
cdef enum OptixTraversableType:
233251
OPTIX_TRAVERSABLE_TYPE_STATIC_TRANSFORM,
234252
OPTIX_TRAVERSABLE_TYPE_MATRIX_MOTION_TRANSFORM,
@@ -341,6 +359,7 @@ cdef class BuildInputCurveArray(BuildInputArray):
341359
cdef vector[CUdeviceptr] _d_normal_buffer_ptrs
342360
cdef object _d_index_buffer
343361

362+
344363
IF _OPTIX_VERSION > 70400:
345364
cdef class BuildInputSphereArray(BuildInputArray):
346365
cdef OptixBuildInputSphereArray build_input
@@ -351,6 +370,7 @@ IF _OPTIX_VERSION > 70400:
351370
cdef object _d_sbt_offset_buffer
352371
cdef vector[unsigned int] _flags
353372

373+
354374
cdef class Instance(OptixObject):
355375
cdef OptixInstance instance
356376
cdef AccelerationStructure _traversable

optix/denoiser.pxd

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ cdef extern from "optix_includes.h" nogil:
4646
size_t internalGuideLayerPixelSizeInBytes
4747

4848
cdef enum OptixDenoiserAlphaMode:
49-
OPTIX_DENOISER_ALPHA_MODE_COPY
50-
OPTIX_DENOISER_ALPHA_MODE_ALPHA_AS_AOV
49+
OPTIX_DENOISER_ALPHA_MODE_COPY,
50+
OPTIX_DENOISER_ALPHA_MODE_ALPHA_AS_AOV,
5151
OPTIX_DENOISER_ALPHA_MODE_FULL_DENOISE_PASS
5252

5353
cdef struct OptixDenoiserParams:
5454
OptixDenoiserAlphaMode denoiseAlpha
5555
CUdeviceptr hdrIntensity
5656
float blendFactor
5757
CUdeviceptr hdrAverageColor
58-
unsigned int temporalModeUsePreviousLayers
58+
unsigned int temporalModeUsePreviousLayers
5959
ELSE:
6060
cdef struct OptixDenoiserSizes:
6161
size_t stateSizeInBytes
@@ -70,8 +70,6 @@ cdef extern from "optix_includes.h" nogil:
7070
CUdeviceptr hdrAverageColor
7171

7272

73-
74-
7573
cdef enum OptixPixelFormat:
7674
OPTIX_PIXEL_FORMAT_HALF2
7775
OPTIX_PIXEL_FORMAT_HALF3

optix/module.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ cdef class Module(OptixContextObject):
217217
"""
218218
Class representing a Optix Cuda program that will be called during pipeline execution. Wraps the OptixModule struct.
219219
220+
TODO: support creating modules through nvcc instead of nvrtc as well to support the new optix-ir format in 7.5
221+
220222
Parameters
221223
----------
222224
context: DeviceContext
@@ -406,6 +408,7 @@ cdef class Module(OptixContextObject):
406408
flags = list(compile_flags)
407409
# get cuda and optix_include_paths
408410
cuda_include_path = get_cuda_include_path()
411+
print("cuda path", cuda_include_path)
409412
optix_include_path = get_optix_include_path()
410413

411414
flags.extend([f'-I{cuda_include_path}', f'-I{optix_include_path}'])

optix/path_utility.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def get_path(key):
3838
return tuple()
3939

4040

41-
def search_on_path(filenames, keys=('PATH',)):
41+
def search_on_path(filenames, keys=None):
42+
if keys is None:
43+
keys = ('PATH',)
4244
for p in chain(*[get_path(key) for key in keys]):
4345
for filename in filenames:
4446
full = os.path.abspath(os.path.join(p, filename))
@@ -47,15 +49,16 @@ def search_on_path(filenames, keys=('PATH',)):
4749
return None
4850

4951

50-
def get_cuda_path(environment_variable='CUDA_ROOT'):
52+
def get_cuda_path(environment_variable=None):
5153
global _cuda_path_cache
5254

5355
# Use a magic word to represent the cache not filled because None is a
5456
# valid return value.
5557
if _cuda_path_cache != 'NOT_INITIALIZED':
5658
return _cuda_path_cache
5759

58-
nvcc_path = search_on_path(('nvcc', 'nvcc.exe'), keys=(environment_variable, 'PATH'))
60+
nvcc_path = search_on_path(('nvcc', 'nvcc.exe'), keys=(environment_variable, 'PATH') if environment_variable is not
61+
None else ('PATH',))
5962
cuda_path_default = None
6063
if nvcc_path is not None:
6164
cuda_path_default = os.path.normpath(
@@ -70,7 +73,7 @@ def get_cuda_path(environment_variable='CUDA_ROOT'):
7073
return _cuda_path_cache
7174

7275

73-
def get_cuda_include_path(environment_variable='CUDA_ROOT'):
76+
def get_cuda_include_path(environment_variable=None):
7477
cuda_path = get_cuda_path(environment_variable=environment_variable)
7578
if cuda_path is None:
7679
return None
@@ -81,22 +84,28 @@ def get_cuda_include_path(environment_variable='CUDA_ROOT'):
8184
return None
8285

8386

84-
def get_optix_path(environment_variable='OPTIX_PATH'):
87+
def get_optix_path(path_hint=None, environment_variable=None):
8588
global _optix_path_cache
8689

8790
# Use a magic word to represent the cache not filled because None is a
8891
# valid return value.
8992
if _optix_path_cache != 'NOT_INITIALIZED':
9093
return _optix_path_cache
9194

92-
# prefer the dedicated environment variable
93-
optix_header_path = search_on_path(('include/optix.h',), keys=(environment_variable,))
94-
if optix_header_path is None:
95-
# search on the default path
96-
optix_header_path = search_on_path(('../optix/include/optix.h',), keys=('PATH',))
95+
if path_hint is None:
96+
# prefer the dedicated environment variable
97+
optix_header_path = search_on_path(('include/optix.h',), keys=(environment_variable,) if environment_variable is not
98+
None else None)
99+
if optix_header_path is None:
100+
# search on the default path
101+
optix_header_path = search_on_path(('../optix/include/optix.h',), keys=('PATH',))
97102

98-
if optix_header_path is not None:
99-
optix_header_path = os.path.normpath(os.path.join(os.path.dirname(optix_header_path), '..'))
103+
if optix_header_path is not None:
104+
optix_header_path = os.path.normpath(os.path.join(os.path.dirname(optix_header_path), '..'))
105+
else:
106+
optix_header_path = path_hint
107+
if not os.path.exists(os.path.join(optix_header_path, "include/optix.h")):
108+
raise ValueError(f"Path {optix_header_path} does not contain an optix installation.")
100109

101110
if optix_header_path is not None:
102111
_optix_path_cache = optix_header_path
@@ -106,7 +115,7 @@ def get_optix_path(environment_variable='OPTIX_PATH'):
106115
return _optix_path_cache
107116

108117

109-
def get_optix_include_path(environment_variable='OPTIX_PATH'):
118+
def get_optix_include_path(environment_variable=None):
110119
optix_path = get_optix_path(environment_variable=environment_variable)
111120
if optix_path is None:
112121
return None

0 commit comments

Comments
 (0)