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