1 | // Copyright 2009-2021 Intel Corporation |
2 | // SPDX-License-Identifier: Apache-2.0 |
3 | |
4 | #pragma once |
5 | |
6 | #include "../../include/embree3/rtcore.h" |
7 | RTC_NAMESPACE_USE |
8 | |
9 | namespace embree |
10 | { |
11 | /*! decoding of intersection flags */ |
12 | __forceinline bool isCoherent (RTCIntersectContextFlags flags) { return (flags & RTC_INTERSECT_CONTEXT_FLAG_COHERENT) == RTC_INTERSECT_CONTEXT_FLAG_COHERENT; } |
13 | __forceinline bool isIncoherent(RTCIntersectContextFlags flags) { return (flags & RTC_INTERSECT_CONTEXT_FLAG_COHERENT) == RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT; } |
14 | |
15 | #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8) |
16 | # define USE_TASK_ARENA 1 |
17 | #else |
18 | # define USE_TASK_ARENA 0 |
19 | #endif |
20 | |
21 | #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 9 |
22 | # define TASKING_TBB_USE_TASK_ISOLATION 1 |
23 | #else |
24 | # define TASKING_TBB_USE_TASK_ISOLATION 0 |
25 | #endif |
26 | |
27 | /*! Macros used in the rtcore API implementation */ |
28 | #define RTC_CATCH_BEGIN try { |
29 | |
30 | #define RTC_CATCH_END(device) \ |
31 | } catch (std::bad_alloc&) { \ |
32 | Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ |
33 | } catch (rtcore_error& e) { \ |
34 | Device::process_error(device,e.error,e.what()); \ |
35 | } catch (std::exception& e) { \ |
36 | Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \ |
37 | } catch (...) { \ |
38 | Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ |
39 | } |
40 | |
41 | #define RTC_CATCH_END2(scene) \ |
42 | } catch (std::bad_alloc&) { \ |
43 | Device* device = scene ? scene->device : nullptr; \ |
44 | Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ |
45 | } catch (rtcore_error& e) { \ |
46 | Device* device = scene ? scene->device : nullptr; \ |
47 | Device::process_error(device,e.error,e.what()); \ |
48 | } catch (std::exception& e) { \ |
49 | Device* device = scene ? scene->device : nullptr; \ |
50 | Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \ |
51 | } catch (...) { \ |
52 | Device* device = scene ? scene->device : nullptr; \ |
53 | Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ |
54 | } |
55 | |
56 | #define RTC_CATCH_END2_FALSE(scene) \ |
57 | } catch (std::bad_alloc&) { \ |
58 | Device* device = scene ? scene->device : nullptr; \ |
59 | Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ |
60 | return false; \ |
61 | } catch (rtcore_error& e) { \ |
62 | Device* device = scene ? scene->device : nullptr; \ |
63 | Device::process_error(device,e.error,e.what()); \ |
64 | return false; \ |
65 | } catch (std::exception& e) { \ |
66 | Device* device = scene ? scene->device : nullptr; \ |
67 | Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \ |
68 | return false; \ |
69 | } catch (...) { \ |
70 | Device* device = scene ? scene->device : nullptr; \ |
71 | Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ |
72 | return false; \ |
73 | } |
74 | |
75 | #define RTC_VERIFY_HANDLE(handle) \ |
76 | if (handle == nullptr) { \ |
77 | throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ |
78 | } |
79 | |
80 | #define RTC_VERIFY_GEOMID(id) \ |
81 | if (id == RTC_INVALID_GEOMETRY_ID) { \ |
82 | throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ |
83 | } |
84 | |
85 | #define RTC_VERIFY_UPPER(id,upper) \ |
86 | if (id > upper) { \ |
87 | throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ |
88 | } |
89 | |
90 | #define RTC_VERIFY_RANGE(id,lower,upper) \ |
91 | if (id < lower || id > upper) \ |
92 | throw_RTCError(RTC_ERROR_INVALID_OPERATION,"argument out of bounds"); |
93 | |
94 | #if 0 // enable to debug print all API calls |
95 | #define RTC_TRACE(x) std::cout << #x << std::endl; |
96 | #else |
97 | #define RTC_TRACE(x) |
98 | #endif |
99 | |
100 | /*! used to throw embree API errors */ |
101 | struct rtcore_error : public std::exception |
102 | { |
103 | __forceinline rtcore_error(RTCError error, const std::string& str) |
104 | : error(error), str(str) {} |
105 | |
106 | ~rtcore_error() throw() {} |
107 | |
108 | const char* what () const throw () { |
109 | return str.c_str(); |
110 | } |
111 | |
112 | RTCError error; |
113 | std::string str; |
114 | }; |
115 | |
116 | #if defined(DEBUG) // only report file and line in debug mode |
117 | #define throw_RTCError(error,str) \ |
118 | throw rtcore_error(error,std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str)); |
119 | #else |
120 | #define throw_RTCError(error,str) \ |
121 | throw rtcore_error(error,str); |
122 | #endif |
123 | |
124 | #define RTC_BUILD_ARGUMENTS_HAS(settings,member) \ |
125 | (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member))) |
126 | } |
127 | |