subdivpatch1eager_intersector.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "grid_soa.h"
  18. #include "grid_soa_intersector1.h"
  19. #include "grid_soa_intersector.h"
  20. #include "../common/ray.h"
  21. namespace embree
  22. {
  23. namespace isa
  24. {
  25. template<typename T>
  26. class SubdivPatch1EagerPrecalculations : public T
  27. {
  28. public:
  29. __forceinline SubdivPatch1EagerPrecalculations (const Ray& ray, const void* ptr, unsigned numTimeSteps)
  30. : T(ray,ptr,numTimeSteps) {}
  31. };
  32. template<int K, typename T>
  33. class SubdivPatch1EagerPrecalculationsK : public T
  34. {
  35. public:
  36. __forceinline SubdivPatch1EagerPrecalculationsK (const vbool<K>& valid, RayK<K>& ray, unsigned numTimeSteps)
  37. : T(valid,ray,numTimeSteps) {}
  38. };
  39. class SubdivPatch1EagerIntersector1
  40. {
  41. public:
  42. typedef GridSOA Primitive;
  43. typedef SubdivPatch1EagerPrecalculations<GridSOAIntersector1::Precalculations> Precalculations;
  44. static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim, size_t& lazy_node) {
  45. lazy_node = prim->root(0); pre.grid = (Primitive*) prim; return false;
  46. }
  47. /*! Intersect a ray with the primitive. */
  48. static __forceinline void intersect(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  49. {
  50. if (likely(ty == 0)) GridSOAIntersector1::intersect(pre,ray,context,prim,ty,lazy_node);
  51. else processLazyNode(pre,context,prim,lazy_node);
  52. }
  53. static __forceinline void intersect(Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) {
  54. intersect(pre,ray,context,prim,ty,lazy_node);
  55. }
  56. /*! Test if the ray is occluded by the primitive */
  57. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  58. {
  59. if (likely(ty == 0)) return GridSOAIntersector1::occluded(pre,ray,context,prim,ty,lazy_node);
  60. else return processLazyNode(pre,context,prim,lazy_node);
  61. }
  62. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) {
  63. return occluded(pre,ray,context,prim,ty,lazy_node);
  64. }
  65. };
  66. class SubdivPatch1EagerMBlurIntersector1
  67. {
  68. public:
  69. typedef GridSOA Primitive;
  70. typedef SubdivPatch1EagerPrecalculations<GridSOAMBlurIntersector1::Precalculations> Precalculations;
  71. static __forceinline bool processLazyNode(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node)
  72. {
  73. lazy_node = prim->root(pre.itime()); pre.grid = (Primitive*) prim; return false;
  74. }
  75. /*! Intersect a ray with the primitive. */
  76. static __forceinline void intersect(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  77. {
  78. if (likely(ty == 0)) GridSOAMBlurIntersector1::intersect(pre,ray,context,prim,ty,lazy_node);
  79. else processLazyNode(pre,ray,context,prim,lazy_node);
  80. }
  81. static __forceinline void intersect(Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) {
  82. intersect(pre,ray,context,prim,ty,lazy_node);
  83. }
  84. /*! Test if the ray is occluded by the primitive */
  85. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  86. {
  87. if (likely(ty == 0)) return GridSOAMBlurIntersector1::occluded(pre,ray,context,prim,ty,lazy_node);
  88. else return processLazyNode(pre,ray,context,prim,lazy_node);
  89. }
  90. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) {
  91. return occluded(pre,ray,context,prim,ty,lazy_node);
  92. }
  93. };
  94. template <int K>
  95. struct SubdivPatch1EagerIntersectorK
  96. {
  97. typedef GridSOA Primitive;
  98. typedef SubdivPatch1EagerPrecalculationsK<K,typename GridSOAIntersectorK<K>::Precalculations> Precalculations;
  99. static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim, size_t& lazy_node){
  100. lazy_node = prim->root(0); pre.grid = (Primitive*) prim; return false;
  101. }
  102. static __forceinline void intersect(const vbool<K>& valid, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  103. {
  104. if (likely(ty == 0)) GridSOAIntersectorK<K>::intersect(valid,pre,ray,context,prim,ty,lazy_node);
  105. else processLazyNode(pre,context,prim,lazy_node);
  106. }
  107. static __forceinline vbool<K> occluded(const vbool<K>& valid, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  108. {
  109. if (likely(ty == 0)) return GridSOAIntersectorK<K>::occluded(valid,pre,ray,context,prim,ty,lazy_node);
  110. else return processLazyNode(pre,context,prim,lazy_node);
  111. }
  112. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  113. {
  114. if (likely(ty == 0)) GridSOAIntersectorK<K>::intersect(pre,ray,k,context,prim,ty,lazy_node);
  115. else processLazyNode(pre,context,prim,lazy_node);
  116. }
  117. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  118. {
  119. if (likely(ty == 0)) return GridSOAIntersectorK<K>::occluded(pre,ray,k,context,prim,ty,lazy_node);
  120. else return processLazyNode(pre,context,prim,lazy_node);
  121. }
  122. };
  123. typedef SubdivPatch1EagerIntersectorK<4> SubdivPatch1EagerIntersector4;
  124. typedef SubdivPatch1EagerIntersectorK<8> SubdivPatch1EagerIntersector8;
  125. typedef SubdivPatch1EagerIntersectorK<16> SubdivPatch1EagerIntersector16;
  126. template <int K>
  127. struct SubdivPatch1EagerMBlurIntersectorK
  128. {
  129. typedef GridSOA Primitive;
  130. typedef SubdivPatch1EagerPrecalculationsK<K,typename GridSOAMBlurIntersectorK<K>::Precalculations> Precalculations;
  131. static __forceinline bool processLazyNode(Precalculations& pre, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) {
  132. lazy_node = prim->root(pre.itime(k)); pre.grid = (Primitive*) prim; return false;
  133. }
  134. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  135. {
  136. if (likely(ty == 0)) GridSOAMBlurIntersectorK<K>::intersect(pre,ray,k,context,prim,ty,lazy_node);
  137. else processLazyNode(pre,k,context,prim,lazy_node);
  138. }
  139. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  140. {
  141. if (likely(ty == 0)) return GridSOAMBlurIntersectorK<K>::occluded(pre,ray,k,context,prim,ty,lazy_node);
  142. else return processLazyNode(pre,k,context,prim,lazy_node);
  143. }
  144. };
  145. typedef SubdivPatch1EagerMBlurIntersectorK<4> SubdivPatch1EagerMBlurIntersector4;
  146. typedef SubdivPatch1EagerMBlurIntersectorK<8> SubdivPatch1EagerMBlurIntersector8;
  147. typedef SubdivPatch1EagerMBlurIntersectorK<16> SubdivPatch1EagerMBlurIntersector16;
  148. }
  149. }