intersector_epilog_sycl.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "../common/ray.h"
  5. #include "../common/context.h"
  6. #include "filter_sycl.h"
  7. namespace embree
  8. {
  9. template<typename Ray>
  10. struct Intersect1Epilog1_HWIF;
  11. template<>
  12. struct Intersect1Epilog1_HWIF<RayHit>
  13. {
  14. RayHit& ray;
  15. sycl::private_ptr<RayQueryContext> context;
  16. const unsigned int geomID;
  17. const unsigned int primID;
  18. const bool filter;
  19. __forceinline Intersect1Epilog1_HWIF(RayHit& ray,
  20. sycl::private_ptr<RayQueryContext> context,
  21. const unsigned int geomID,
  22. const unsigned int primID,
  23. const bool filter)
  24. : ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {}
  25. template<typename Hit_i>
  26. __forceinline bool operator() (Hit_i& hit_i) const
  27. {
  28. hit_i.finalize();
  29. Scene* scene MAYBE_UNUSED = context->scene;
  30. Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
  31. /* ray mask test */
  32. #if defined(EMBREE_RAY_MASK)
  33. if ((geometry->mask & ray.mask) == 0)
  34. return false;
  35. #endif
  36. /* call intersection filter function */
  37. #if defined(EMBREE_FILTER_FUNCTION)
  38. if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter())))
  39. {
  40. Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng);
  41. float old_t = ray.tfar;
  42. ray.tfar = hit_i.t;
  43. bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
  44. if (!found) {
  45. ray.tfar = old_t;
  46. return false;
  47. }
  48. }
  49. #endif
  50. ray.tfar = hit_i.t;
  51. ray.u = hit_i.u;
  52. ray.v = hit_i.v;
  53. ray.Ng.x = hit_i.Ng.x;
  54. ray.Ng.y = hit_i.Ng.y;
  55. ray.Ng.z = hit_i.Ng.z;
  56. ray.geomID = geomID;
  57. ray.primID = primID;
  58. instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID);
  59. #if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
  60. instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID);
  61. #endif
  62. return true;
  63. }
  64. template<typename Hit_i>
  65. __forceinline bool operator() (bool, Hit_i& hit_i) const
  66. {
  67. hit_i.finalize();
  68. Scene* scene MAYBE_UNUSED = context->scene;
  69. Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
  70. /* ray mask test */
  71. #if defined(EMBREE_RAY_MASK)
  72. if ((geometry->mask & ray.mask) == 0)
  73. return false;
  74. #endif
  75. const Vec3fa Ng = hit_i.Ng();
  76. const Vec2f uv = hit_i.uv();
  77. /* call intersection filter function */
  78. #if defined(EMBREE_FILTER_FUNCTION)
  79. if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter())))
  80. {
  81. Hit h(context->user,geomID,primID,uv,Ng);
  82. float old_t = ray.tfar;
  83. ray.tfar = hit_i.t();
  84. bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
  85. if (!found) {
  86. ray.tfar = old_t;
  87. return false;
  88. }
  89. }
  90. #endif
  91. ray.tfar = hit_i.t();
  92. ray.u = uv.x;
  93. ray.v = uv.y;
  94. ray.Ng.x = Ng.x;
  95. ray.Ng.y = Ng.y;
  96. ray.Ng.z = Ng.z;
  97. ray.geomID = geomID;
  98. ray.primID = primID;
  99. instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID);
  100. #if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
  101. instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID);
  102. #endif
  103. return true;
  104. }
  105. };
  106. template<>
  107. struct Intersect1Epilog1_HWIF<Ray>
  108. {
  109. Ray& ray;
  110. sycl::private_ptr<RayQueryContext> context;
  111. const unsigned int geomID;
  112. const unsigned int primID;
  113. const bool filter;
  114. __forceinline Intersect1Epilog1_HWIF(Ray& ray,
  115. sycl::private_ptr<RayQueryContext> context,
  116. const unsigned int geomID,
  117. const unsigned int primID,
  118. const bool filter)
  119. : ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {}
  120. template<typename Hit_i>
  121. __forceinline bool operator() (Hit_i& hit_i) const
  122. {
  123. hit_i.finalize();
  124. Scene* scene MAYBE_UNUSED = context->scene;
  125. Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
  126. /* ray mask test */
  127. #if defined(EMBREE_RAY_MASK)
  128. if ((geometry->mask & ray.mask) == 0)
  129. return false;
  130. #endif
  131. /* call intersection filter function */
  132. #if defined(EMBREE_FILTER_FUNCTION)
  133. if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter())))
  134. {
  135. Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng);
  136. float old_t = ray.tfar;
  137. ray.tfar = hit_i.t;
  138. bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
  139. if (!found) {
  140. ray.tfar = old_t;
  141. return false;
  142. }
  143. }
  144. #endif
  145. ray.tfar = neg_inf;
  146. return true;
  147. }
  148. template<typename Hit_i>
  149. __forceinline bool operator() (bool, Hit_i& hit_i) const
  150. {
  151. hit_i.finalize();
  152. Scene* scene MAYBE_UNUSED = context->scene;
  153. Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
  154. /* ray mask test */
  155. #if defined(EMBREE_RAY_MASK)
  156. if ((geometry->mask & ray.mask) == 0)
  157. return false;
  158. #endif
  159. /* call intersection filter function */
  160. #if defined(EMBREE_FILTER_FUNCTION)
  161. if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter())))
  162. {
  163. const Vec3fa Ng = hit_i.Ng();
  164. const Vec2f uv = hit_i.uv();
  165. Hit h(context->user,geomID,primID,uv,Ng);
  166. float old_t = ray.tfar;
  167. ray.tfar = hit_i.t();
  168. bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
  169. if (!found) {
  170. ray.tfar = old_t;
  171. return false;
  172. }
  173. }
  174. #endif
  175. ray.tfar = neg_inf;
  176. return true;
  177. }
  178. };
  179. }