NVIDIA OptiX 7.1 API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
optix_7_device_impl_exception.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2020 NVIDIA Corporation. All rights reserved.
3 *
4 * NVIDIA Corporation and its licensors retain all intellectual property and proprietary
5 * rights in and to this software, related documentation and any modifications thereto.
6 * Any use, reproduction, disclosure or distribution of this software and related
7 * documentation without an express license agreement from NVIDIA Corporation is strictly
8 * prohibited.
9 *
10 * TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
11 * AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
12 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
13 * PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
14 * SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
15 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
16 * BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
17 * INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
18 * SUCH DAMAGES
19 */
20 
29 #if !defined( __OPTIX_INCLUDE_INTERNAL_HEADERS__ )
30 #error("optix_7_device_impl_exception.h is an internal header file and must not be used directly. Please use optix_device.h or optix.h instead.")
31 #endif
32 
33 #ifndef __optix_optix_7_device_impl_exception_h__
34 #define __optix_optix_7_device_impl_exception_h__
35 
36 #if !defined(__CUDACC_RTC__)
37 #include <cstdio> /* for printf */
38 #endif
39 
40 namespace optix_impl {
41 
42  static __forceinline__ __device__ void optixDumpStaticTransformFromHandle( OptixTraversableHandle handle )
43  {
44  const OptixStaticTransform* traversable = optixGetStaticTransformFromHandle( handle );
45  if( traversable )
46  {
47  const uint3 index = optixGetLaunchIndex();
48  printf( "(%4i,%4i,%4i) OptixStaticTransform@%p = {\n"
49  " child = %p,\n"
50  " transform = { %f,%f,%f,%f,\n"
51  " %f,%f,%f,%f,\n"
52  " %f,%f,%f,%f } }\n",
53  index.x,index.y,index.z,
54  traversable,
55  (void*)traversable->child,
56  traversable->transform[0], traversable->transform[1], traversable->transform[2], traversable->transform[3],
57  traversable->transform[4], traversable->transform[5], traversable->transform[6], traversable->transform[7],
58  traversable->transform[8], traversable->transform[9], traversable->transform[10], traversable->transform[11] );
59  }
60  }
61 
62  static __forceinline__ __device__ void optixDumpMotionMatrixTransformFromHandle( OptixTraversableHandle handle )
63  {
65  if( traversable )
66  {
67  const uint3 index = optixGetLaunchIndex();
68  printf( "(%4i,%4i,%4i) OptixMatrixMotionTransform@%p = {\n"
69  " child = %p,\n"
70  " motionOptions = { numKeys = %i, flags = %i, timeBegin = %f, timeEnd = %f },\n"
71  " transform = { { %f,%f,%f,%f,\n"
72  " %f,%f,%f,%f,\n"
73  " %f,%f,%f,%f }, ... }\n",
74  index.x,index.y,index.z,
75  traversable,
76  (void*)traversable->child,
77  (int)traversable->motionOptions.numKeys, (int)traversable->motionOptions.flags, traversable->motionOptions.timeBegin, traversable->motionOptions.timeEnd,
78  traversable->transform[0][0], traversable->transform[0][1], traversable->transform[0][2], traversable->transform[0][3],
79  traversable->transform[0][4], traversable->transform[0][5], traversable->transform[0][6], traversable->transform[0][7],
80  traversable->transform[0][8], traversable->transform[0][9], traversable->transform[0][10], traversable->transform[0][11] );
81  }
82  }
83 
84  static __forceinline__ __device__ void optixDumpSrtMatrixTransformFromHandle( OptixTraversableHandle handle )
85  {
87  if( traversable )
88  {
89  const uint3 index = optixGetLaunchIndex();
90  printf( "(%4i,%4i,%4i) OptixSRTMotionTransform@%p = {\n"
91  " child = %p,\n"
92  " motionOptions = { numKeys = %i, flags = %i, timeBegin = %f, timeEnd = %f },\n"
93  " srtData = { { sx = %f, a = %f, b = %f, pvx = %f,\n"
94  " sy = %f, c = %f, pvy = %f, sz = %f,\n"
95  " pvz = %f, qx = %f, qy = %f, qz = %f,\n"
96  " qw = %f, tx = %f, ty = %f, tz = %f }, ... }\n",
97  index.x,index.y,index.z,
98  traversable,
99  (void*)traversable->child,
100  (int)traversable->motionOptions.numKeys, (int)traversable->motionOptions.flags, traversable->motionOptions.timeBegin, traversable->motionOptions.timeEnd,
101  traversable->srtData[0].sx, traversable->srtData[0].a, traversable->srtData[0].b, traversable->srtData[0].pvx,
102  traversable->srtData[0].sy, traversable->srtData[0].c, traversable->srtData[0].pvy,traversable->srtData[0].sz,
103  traversable->srtData[0].pvz,traversable->srtData[0].qx,traversable->srtData[0].qy, traversable->srtData[0].qz,
104  traversable->srtData[0].qw, traversable->srtData[0].tx,traversable->srtData[0].ty, traversable->srtData[0].tz );
105  }
106  }
107 
108  static __forceinline__ __device__ void optixDumpInstanceFromHandle( OptixTraversableHandle handle )
109  {
111  {
112  unsigned int instanceId = optixGetInstanceIdFromHandle( handle );
113  const float4* transform = optixGetInstanceTransformFromHandle( handle );
114 
115  const uint3 index = optixGetLaunchIndex();
116  printf( "(%4i,%4i,%4i) OptixInstance = {\n"
117  " instanceId = %i,\n"
118  " transform = { %f,%f,%f,%f,\n"
119  " %f,%f,%f,%f,\n"
120  " %f,%f,%f,%f } }\n",
121  index.x,index.y,index.z,
122  instanceId,
123  transform[0].x, transform[0].y, transform[0].z, transform[0].w,
124  transform[1].x, transform[1].y, transform[1].z, transform[1].w,
125  transform[2].x, transform[2].y, transform[2].z, transform[2].w );
126  }
127  }
128 
129  static __forceinline__ __device__ void optixDumpTransform( OptixTraversableHandle handle )
130  {
132  const uint3 index = optixGetLaunchIndex();
133 
134  switch( type )
135  {
137  break;
140  break;
143  break;
146  break;
148  optixDumpInstanceFromHandle( handle );
149  break;
150  default:
151  break;
152  }
153  }
154 
155  static __forceinline__ __device__ void optixDumpTransformList()
156  {
157  const int tlistSize = optixGetTransformListSize();
158  const uint3 index = optixGetLaunchIndex();
159 
160  printf("(%4i,%4i,%4i) transform list of size %i:\n", index.x,index.y,index.z, tlistSize);
161 
162  for( unsigned int i = 0 ; i < tlistSize ; ++i )
163  {
165  printf("(%4i,%4i,%4i) transform[%i] = %p\n", index.x, index.y, index.z, i, (void*)handle);
166  optixDumpTransform(handle);
167  }
168  }
169 
170  static __forceinline__ __device__ void optixDumpExceptionDetails()
171  {
172  bool dumpTlist = false;
173  const int exceptionCode = optixGetExceptionCode();
174  const uint3 index = optixGetLaunchIndex();
175 
176  if( exceptionCode == OPTIX_EXCEPTION_CODE_STACK_OVERFLOW )
177  {
178  printf("(%4i,%4i,%4i) error: stack overflow\n", index.x,index.y,index.z);
179  }
180  else if( exceptionCode == OPTIX_EXCEPTION_CODE_TRACE_DEPTH_EXCEEDED )
181  {
182  printf("(%4i,%4i,%4i) error: trace depth exceeded\n", index.x,index.y,index.z);
183  }
184  else if( exceptionCode == OPTIX_EXCEPTION_CODE_TRAVERSAL_DEPTH_EXCEEDED )
185  {
186  printf("(%4i,%4i,%4i) error: traversal depth exceeded\n", index.x,index.y,index.z);
187  dumpTlist = true;
188  }
189  else if( exceptionCode == OPTIX_EXCEPTION_CODE_TRAVERSAL_INVALID_TRAVERSABLE )
190  {
192  printf("(%4i,%4i,%4i) error: invalid traversable %p\n", index.x,index.y,index.z, (void*)handle);
193  dumpTlist = true;
194  }
195  else if( exceptionCode == OPTIX_EXCEPTION_CODE_TRAVERSAL_INVALID_MISS_SBT )
196  {
197  int sbtOffset = optixGetExceptionInvalidSbtOffset();
198  printf("(%4i,%4i,%4i) error: invalid miss sbt of %i\n", index.x,index.y,index.z, sbtOffset);
199  }
200  else if( exceptionCode == OPTIX_EXCEPTION_CODE_TRAVERSAL_INVALID_HIT_SBT )
201  {
202  int sbtOffset = optixGetExceptionInvalidSbtOffset();
203  printf("(%4i,%4i,%4i) error: invalid hit sbt of %i at primitive with gas sbt index %i\n", index.x,index.y,index.z, sbtOffset, optixGetSbtGASIndex() );
204  dumpTlist = true;
205  }
206  else if( exceptionCode == OPTIX_EXCEPTION_CODE_UNSUPPORTED_PRIMITIVE_TYPE )
207  {
208  dumpTlist = true;
209  printf( "(%4i,%4i,%4i) error: shader encountered unsupported builtin type\n"
210  " call location: %s\n", index.x, index.y, index.z, optixGetExceptionLineInfo() );
211  }
212  else if( exceptionCode == OPTIX_EXCEPTION_CODE_INVALID_RAY )
213  {
214  OptixInvalidRayExceptionDetails ray = optixGetExceptionInvalidRay();
215  printf( "(%4i,%4i,%4i) error: encountered ray with nan or inf values:\n", index.x, index.y, index.z );
216  printf(
217  " origin: [%f, %f, %f]\n"
218  " direction: [%f, %f, %f]\n"
219  " tmin: %f\n"
220  " tmax: %f\n"
221  " rayTime: %f\n"
222  " call location: %s\n",
223  ray.origin.x, ray.origin.y, ray.origin.z, ray.direction.x, ray.direction.y,
224  ray.direction.z, ray.tmin, ray.tmax, ray.time, optixGetExceptionLineInfo() );
225  }
226  else if( exceptionCode == OPTIX_EXCEPTION_CODE_CALLABLE_PARAMETER_MISMATCH )
227  {
228  OptixParameterMismatchExceptionDetails details = optixGetExceptionParameterMismatch();
229  printf( "(%4i,%4i,%4i) error: parameter mismatch in callable call.\n", index.x, index.y, index.z );
230  printf(
231  " passed packed arguments: %u 32 Bit values\n"
232  " expected packed parameters: %u 32 Bit values\n"
233  " SBT index: %u\n"
234  " called function: %s\n"
235  " call location: %s\n",
236  details.passedArgumentCount, details.expectedParameterCount, details.sbtIndex,
237  details.callableName, optixGetExceptionLineInfo() );
238  }
239  else if( exceptionCode == OPTIX_EXCEPTION_CODE_BUILTIN_IS_MISMATCH )
240  {
241  dumpTlist = true;
242  printf("(%4i,%4i,%4i) error: mismatch between builtin IS shader and build input\n"
243  " call location: %s\n", index.x,index.y,index.z, optixGetExceptionLineInfo() );
244  }
245  else if( exceptionCode == OPTIX_EXCEPTION_CODE_UNSUPPORTED_SINGLE_LEVEL_GAS )
246  {
248  printf("(%4i,%4i,%4i) error: unsupported single GAS traversable graph %p\n", index.x,index.y,index.z, (void*)handle);
249  dumpTlist = true;
250  }
251  else if( exceptionCode >= 0 )
252  {
253  dumpTlist = true;
254  printf( "(%4i,%4i,%4i) error: user exception with error code %i\n"
255  " call location: %s\n", index.x, index.y, index.z, exceptionCode, optixGetExceptionLineInfo() );
256  }
257  else
258  {
259  printf("(%4i,%4i,%4i) error: unknown exception with error code %i\n", index.x,index.y,index.z, exceptionCode);
260  }
261 
262  if( dumpTlist )
264  }
265 
266 } // namespace optix_impl
267 
268 #endif
269