rtcore.h 6.4 KB

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