| 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 | // -- GODOT start -- |
| 29 | #define RTC_CATCH_BEGIN |
| 30 | #define RTC_CATCH_END(device) |
| 31 | #define RTC_CATCH_END2(scene) |
| 32 | #define RTC_CATCH_END2_FALSE(scene) return false; |
| 33 | |
| 34 | #if 0 |
| 35 | #define RTC_CATCH_BEGIN try { |
| 36 | |
| 37 | #define RTC_CATCH_END(device) \ |
| 38 | } catch (std::bad_alloc&) { \ |
| 39 | Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ |
| 40 | } catch (rtcore_error& e) { \ |
| 41 | Device::process_error(device,e.error,e.what()); \ |
| 42 | } catch (std::exception& e) { \ |
| 43 | Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \ |
| 44 | } catch (...) { \ |
| 45 | Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ |
| 46 | } |
| 47 | |
| 48 | #define RTC_CATCH_END2(scene) \ |
| 49 | } catch (std::bad_alloc&) { \ |
| 50 | Device* device = scene ? scene->device : nullptr; \ |
| 51 | Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ |
| 52 | } catch (rtcore_error& e) { \ |
| 53 | Device* device = scene ? scene->device : nullptr; \ |
| 54 | Device::process_error(device,e.error,e.what()); \ |
| 55 | } catch (std::exception& e) { \ |
| 56 | Device* device = scene ? scene->device : nullptr; \ |
| 57 | Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \ |
| 58 | } catch (...) { \ |
| 59 | Device* device = scene ? scene->device : nullptr; \ |
| 60 | Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ |
| 61 | } |
| 62 | |
| 63 | #define RTC_CATCH_END2_FALSE(scene) \ |
| 64 | } catch (std::bad_alloc&) { \ |
| 65 | Device* device = scene ? scene->device : nullptr; \ |
| 66 | Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ |
| 67 | return false; \ |
| 68 | } catch (rtcore_error& e) { \ |
| 69 | Device* device = scene ? scene->device : nullptr; \ |
| 70 | Device::process_error(device,e.error,e.what()); \ |
| 71 | return false; \ |
| 72 | } catch (std::exception& e) { \ |
| 73 | Device* device = scene ? scene->device : nullptr; \ |
| 74 | Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \ |
| 75 | return false; \ |
| 76 | } catch (...) { \ |
| 77 | Device* device = scene ? scene->device : nullptr; \ |
| 78 | Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ |
| 79 | return false; \ |
| 80 | } |
| 81 | #endif |
| 82 | // -- GODOT end -- |
| 83 | |
| 84 | #define RTC_VERIFY_HANDLE(handle) \ |
| 85 | if (handle == nullptr) { \ |
| 86 | throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ |
| 87 | } |
| 88 | |
| 89 | #define RTC_VERIFY_GEOMID(id) \ |
| 90 | if (id == RTC_INVALID_GEOMETRY_ID) { \ |
| 91 | throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ |
| 92 | } |
| 93 | |
| 94 | #define RTC_VERIFY_UPPER(id,upper) \ |
| 95 | if (id > upper) { \ |
| 96 | throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ |
| 97 | } |
| 98 | |
| 99 | #define RTC_VERIFY_RANGE(id,lower,upper) \ |
| 100 | if (id < lower || id > upper) \ |
| 101 | throw_RTCError(RTC_ERROR_INVALID_OPERATION,"argument out of bounds"); |
| 102 | |
| 103 | #if 0 // enable to debug print all API calls |
| 104 | #define RTC_TRACE(x) std::cout << #x << std::endl; |
| 105 | #else |
| 106 | #define RTC_TRACE(x) |
| 107 | #endif |
| 108 | |
| 109 | // -- GODOT start -- |
| 110 | #if 0 |
| 111 | /*! used to throw embree API errors */ |
| 112 | struct rtcore_error : public std::exception |
| 113 | { |
| 114 | __forceinline rtcore_error(RTCError error, const std::string& str) |
| 115 | : error(error), str(str) {} |
| 116 | |
| 117 | ~rtcore_error() throw() {} |
| 118 | |
| 119 | const char* what () const throw () { |
| 120 | return str.c_str(); |
| 121 | } |
| 122 | |
| 123 | RTCError error; |
| 124 | std::string str; |
| 125 | }; |
| 126 | #endif |
| 127 | |
| 128 | #if defined(DEBUG) // only report file and line in debug mode |
| 129 | #define throw_RTCError(error,str) \ |
| 130 | printf("%s (%d): %s", __FILE__, __LINE__, std::string(str).c_str()), abort(); |
| 131 | // throw rtcore_error(error,std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str)); |
| 132 | #else |
| 133 | #define throw_RTCError(error,str) \ |
| 134 | abort(); |
| 135 | // throw rtcore_error(error,str); |
| 136 | #endif |
| 137 | // -- GODOT end -- |
| 138 | |
| 139 | #define RTC_BUILD_ARGUMENTS_HAS(settings,member) \ |
| 140 | (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member))) |
| 141 | } |
| 142 | |