curveNv_intersector.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "curveNv.h"
  5. #include "curveNi_intersector.h"
  6. namespace embree
  7. {
  8. namespace isa
  9. {
  10. template<int M>
  11. struct CurveNvIntersector1 : public CurveNiIntersector1<M>
  12. {
  13. typedef CurveNv<M> Primitive;
  14. typedef CurvePrecalculations1 Precalculations;
  15. template<typename Intersector, typename Epilog>
  16. static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim)
  17. {
  18. vfloat<M> tNear;
  19. vbool<M> valid = CurveNiIntersector1<M>::intersect(ray,prim,tNear);
  20. const size_t N = prim.N;
  21. size_t mask = movemask(valid);
  22. while (mask)
  23. {
  24. const size_t i = bscf(mask);
  25. STAT3(normal.trav_prims,1,1,1);
  26. const unsigned int geomID = prim.geomID(N);
  27. const unsigned int primID = prim.primID(N)[i];
  28. const CurveGeometry* geom = (CurveGeometry*) context->scene->get(geomID);
  29. const Vec3ff a0 = Vec3ff::loadu(&prim.vertices(i,N)[0]);
  30. const Vec3ff a1 = Vec3ff::loadu(&prim.vertices(i,N)[1]);
  31. const Vec3ff a2 = Vec3ff::loadu(&prim.vertices(i,N)[2]);
  32. const Vec3ff a3 = Vec3ff::loadu(&prim.vertices(i,N)[3]);
  33. size_t mask1 = mask;
  34. const size_t i1 = bscf(mask1);
  35. if (mask) {
  36. prefetchL1(&prim.vertices(i1,N)[0]);
  37. prefetchL1(&prim.vertices(i1,N)[4]);
  38. if (mask1) {
  39. const size_t i2 = bsf(mask1);
  40. prefetchL2(&prim.vertices(i2,N)[0]);
  41. prefetchL2(&prim.vertices(i2,N)[4]);
  42. }
  43. }
  44. Intersector().intersect(pre,ray,context,geom,primID,a0,a1,a2,a3,Epilog(ray,context,geomID,primID));
  45. mask &= movemask(tNear <= vfloat<M>(ray.tfar));
  46. }
  47. }
  48. template<typename Intersector, typename Epilog>
  49. static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  50. {
  51. vfloat<M> tNear;
  52. vbool<M> valid = CurveNiIntersector1<M>::intersect(ray,prim,tNear);
  53. const size_t N = prim.N;
  54. size_t mask = movemask(valid);
  55. while (mask)
  56. {
  57. const size_t i = bscf(mask);
  58. STAT3(shadow.trav_prims,1,1,1);
  59. const unsigned int geomID = prim.geomID(N);
  60. const unsigned int primID = prim.primID(N)[i];
  61. const CurveGeometry* geom = (CurveGeometry*) context->scene->get(geomID);
  62. const Vec3ff a0 = Vec3ff::loadu(&prim.vertices(i,N)[0]);
  63. const Vec3ff a1 = Vec3ff::loadu(&prim.vertices(i,N)[1]);
  64. const Vec3ff a2 = Vec3ff::loadu(&prim.vertices(i,N)[2]);
  65. const Vec3ff a3 = Vec3ff::loadu(&prim.vertices(i,N)[3]);
  66. size_t mask1 = mask;
  67. const size_t i1 = bscf(mask1);
  68. if (mask) {
  69. prefetchL1(&prim.vertices(i1,N)[0]);
  70. prefetchL1(&prim.vertices(i1,N)[4]);
  71. if (mask1) {
  72. const size_t i2 = bsf(mask1);
  73. prefetchL2(&prim.vertices(i2,N)[0]);
  74. prefetchL2(&prim.vertices(i2,N)[4]);
  75. }
  76. }
  77. if (Intersector().intersect(pre,ray,context,geom,primID,a0,a1,a2,a3,Epilog(ray,context,geomID,primID)))
  78. return true;
  79. mask &= movemask(tNear <= vfloat<M>(ray.tfar));
  80. }
  81. return false;
  82. }
  83. };
  84. template<int M, int K>
  85. struct CurveNvIntersectorK : public CurveNiIntersectorK<M,K>
  86. {
  87. typedef CurveNv<M> Primitive;
  88. typedef CurvePrecalculationsK<K> Precalculations;
  89. template<typename Intersector, typename Epilog>
  90. static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  91. {
  92. vfloat<M> tNear;
  93. vbool<M> valid = CurveNiIntersectorK<M,K>::intersect(ray,k,prim,tNear);
  94. const size_t N = prim.N;
  95. size_t mask = movemask(valid);
  96. while (mask)
  97. {
  98. const size_t i = bscf(mask);
  99. STAT3(normal.trav_prims,1,1,1);
  100. const unsigned int geomID = prim.geomID(N);
  101. const unsigned int primID = prim.primID(N)[i];
  102. const CurveGeometry* geom = (CurveGeometry*) context->scene->get(geomID);
  103. const Vec3ff a0 = Vec3ff::loadu(&prim.vertices(i,N)[0]);
  104. const Vec3ff a1 = Vec3ff::loadu(&prim.vertices(i,N)[1]);
  105. const Vec3ff a2 = Vec3ff::loadu(&prim.vertices(i,N)[2]);
  106. const Vec3ff a3 = Vec3ff::loadu(&prim.vertices(i,N)[3]);
  107. size_t mask1 = mask;
  108. const size_t i1 = bscf(mask1);
  109. if (mask) {
  110. prefetchL1(&prim.vertices(i1,N)[0]);
  111. prefetchL1(&prim.vertices(i1,N)[4]);
  112. if (mask1) {
  113. const size_t i2 = bsf(mask1);
  114. prefetchL2(&prim.vertices(i2,N)[0]);
  115. prefetchL2(&prim.vertices(i2,N)[4]);
  116. }
  117. }
  118. Intersector().intersect(pre,ray,k,context,geom,primID,a0,a1,a2,a3,Epilog(ray,k,context,geomID,primID));
  119. mask &= movemask(tNear <= vfloat<M>(ray.tfar[k]));
  120. }
  121. }
  122. template<typename Intersector, typename Epilog>
  123. static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  124. {
  125. vfloat<M> tNear;
  126. vbool<M> valid = CurveNiIntersectorK<M,K>::intersect(ray,k,prim,tNear);
  127. const size_t N = prim.N;
  128. size_t mask = movemask(valid);
  129. while (mask)
  130. {
  131. const size_t i = bscf(mask);
  132. STAT3(shadow.trav_prims,1,1,1);
  133. const unsigned int geomID = prim.geomID(N);
  134. const unsigned int primID = prim.primID(N)[i];
  135. const CurveGeometry* geom = (CurveGeometry*) context->scene->get(geomID);
  136. const Vec3ff a0 = Vec3ff::loadu(&prim.vertices(i,N)[0]);
  137. const Vec3ff a1 = Vec3ff::loadu(&prim.vertices(i,N)[1]);
  138. const Vec3ff a2 = Vec3ff::loadu(&prim.vertices(i,N)[2]);
  139. const Vec3ff a3 = Vec3ff::loadu(&prim.vertices(i,N)[3]);
  140. size_t mask1 = mask;
  141. const size_t i1 = bscf(mask1);
  142. if (mask) {
  143. prefetchL1(&prim.vertices(i1,N)[0]);
  144. prefetchL1(&prim.vertices(i1,N)[4]);
  145. if (mask1) {
  146. const size_t i2 = bsf(mask1);
  147. prefetchL2(&prim.vertices(i2,N)[0]);
  148. prefetchL2(&prim.vertices(i2,N)[4]);
  149. }
  150. }
  151. if (Intersector().intersect(pre,ray,k,context,geom,primID,a0,a1,a2,a3,Epilog(ray,k,context,geomID,primID)))
  152. return true;
  153. mask &= movemask(tNear <= vfloat<M>(ray.tfar[k]));
  154. }
  155. return false;
  156. }
  157. };
  158. }
  159. }