grid_soa_intersector1.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 "../common/ray.h"
  19. #include "triangle_intersector_pluecker.h"
  20. namespace embree
  21. {
  22. namespace isa
  23. {
  24. class GridSOAIntersector1
  25. {
  26. public:
  27. typedef void Primitive;
  28. class PrecalculationsBase
  29. {
  30. public:
  31. __forceinline PrecalculationsBase (const Ray& ray, const void* ptr)
  32. : grid(nullptr) {}
  33. public:
  34. GridSOA* grid;
  35. };
  36. typedef Intersector1Precalculations<PrecalculationsBase> Precalculations;
  37. template<typename Loader>
  38. static __forceinline void intersect(Ray& ray,
  39. IntersectContext* context,
  40. const float* const grid_x,
  41. const size_t line_offset,
  42. const size_t lines,
  43. Precalculations& pre)
  44. {
  45. typedef typename Loader::vfloat vfloat;
  46. const size_t dim_offset = pre.grid->dim_offset;
  47. const float* const grid_y = grid_x + 1 * dim_offset;
  48. const float* const grid_z = grid_x + 2 * dim_offset;
  49. const float* const grid_uv = grid_x + 3 * dim_offset;
  50. Vec3<vfloat> v0, v1, v2;
  51. Loader::gather(grid_x,grid_y,grid_z,line_offset,lines,v0,v1,v2);
  52. GridSOA::MapUV<Loader> mapUV(grid_uv,line_offset,lines);
  53. PlueckerIntersector1<Loader::M> intersector(ray,nullptr);
  54. intersector.intersect(ray,v0,v1,v2,mapUV,Intersect1EpilogMU<Loader::M,true>(ray,context,pre.grid->geomID,pre.grid->primID));
  55. };
  56. template<typename Loader>
  57. static __forceinline bool occluded(Ray& ray,
  58. IntersectContext* context,
  59. const float* const grid_x,
  60. const size_t line_offset,
  61. const size_t lines,
  62. Precalculations& pre)
  63. {
  64. typedef typename Loader::vfloat vfloat;
  65. const size_t dim_offset = pre.grid->dim_offset;
  66. const float* const grid_y = grid_x + 1 * dim_offset;
  67. const float* const grid_z = grid_x + 2 * dim_offset;
  68. const float* const grid_uv = grid_x + 3 * dim_offset;
  69. Vec3<vfloat> v0, v1, v2;
  70. Loader::gather(grid_x,grid_y,grid_z,line_offset,lines,v0,v1,v2);
  71. GridSOA::MapUV<Loader> mapUV(grid_uv,line_offset,lines);
  72. PlueckerIntersector1<Loader::M> intersector(ray,nullptr);
  73. return intersector.intersect(ray,v0,v1,v2,mapUV,Occluded1EpilogMU<Loader::M,true>(ray,context,pre.grid->geomID,pre.grid->primID));
  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. const size_t line_offset = pre.grid->width;
  79. const size_t lines = pre.grid->height;
  80. const float* const grid_x = pre.grid->decodeLeaf(0,prim);
  81. #if defined(__AVX__)
  82. intersect<GridSOA::Gather3x3>( ray, context, grid_x, line_offset, lines, pre);
  83. #else
  84. intersect<GridSOA::Gather2x3>(ray, context, grid_x , line_offset, lines, pre);
  85. if (likely(lines > 2))
  86. intersect<GridSOA::Gather2x3>(ray, context, grid_x+line_offset, line_offset, lines, pre);
  87. #endif
  88. }
  89. /*! Test if the ray is occluded by the primitive */
  90. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  91. {
  92. const size_t line_offset = pre.grid->width;
  93. const size_t lines = pre.grid->height;
  94. const float* const grid_x = pre.grid->decodeLeaf(0,prim);
  95. #if defined(__AVX__)
  96. return occluded<GridSOA::Gather3x3>( ray, context, grid_x, line_offset, lines, pre);
  97. #else
  98. if (occluded<GridSOA::Gather2x3>(ray, context, grid_x , line_offset, lines, pre)) return true;
  99. if (likely(lines > 2))
  100. if (occluded<GridSOA::Gather2x3>(ray, context, grid_x+line_offset, line_offset, lines, pre)) return true;
  101. #endif
  102. return false;
  103. }
  104. };
  105. class GridSOAMBlurIntersector1
  106. {
  107. public:
  108. typedef void Primitive;
  109. typedef GridSOAIntersector1::PrecalculationsBase PrecalculationsBase;
  110. typedef Intersector1PrecalculationsMB<PrecalculationsBase> Precalculations;
  111. template<typename Loader>
  112. static __forceinline void intersect(Ray& ray, const float ftime,
  113. IntersectContext* context,
  114. const float* const grid_x,
  115. const size_t line_offset,
  116. const size_t lines,
  117. Precalculations& pre)
  118. {
  119. typedef typename Loader::vfloat vfloat;
  120. const size_t dim_offset = pre.grid->dim_offset;
  121. const size_t grid_offset = pre.grid->gridBytes >> 2;
  122. const float* const grid_y = grid_x + 1 * dim_offset;
  123. const float* const grid_z = grid_x + 2 * dim_offset;
  124. const float* const grid_uv = grid_x + 3 * dim_offset;
  125. Vec3<vfloat> a0, a1, a2;
  126. Loader::gather(grid_x,grid_y,grid_z,line_offset,lines,a0,a1,a2);
  127. Vec3<vfloat> b0, b1, b2;
  128. Loader::gather(grid_x+grid_offset,grid_y+grid_offset,grid_z+grid_offset,line_offset,lines,b0,b1,b2);
  129. Vec3<vfloat> v0 = lerp(a0,b0,vfloat(ftime));
  130. Vec3<vfloat> v1 = lerp(a1,b1,vfloat(ftime));
  131. Vec3<vfloat> v2 = lerp(a2,b2,vfloat(ftime));
  132. GridSOA::MapUV<Loader> mapUV(grid_uv,line_offset,lines);
  133. PlueckerIntersector1<Loader::M> intersector(ray,nullptr);
  134. intersector.intersect(ray,v0,v1,v2,mapUV,Intersect1EpilogMU<Loader::M,true>(ray,context,pre.grid->geomID,pre.grid->primID));
  135. };
  136. template<typename Loader>
  137. static __forceinline bool occluded(Ray& ray, const float ftime,
  138. IntersectContext* context,
  139. const float* const grid_x,
  140. const size_t line_offset,
  141. const size_t lines,
  142. Precalculations& pre)
  143. {
  144. typedef typename Loader::vfloat vfloat;
  145. const size_t dim_offset = pre.grid->dim_offset;
  146. const size_t grid_offset = pre.grid->gridBytes >> 2;
  147. const float* const grid_y = grid_x + 1 * dim_offset;
  148. const float* const grid_z = grid_x + 2 * dim_offset;
  149. const float* const grid_uv = grid_x + 3 * dim_offset;
  150. Vec3<vfloat> a0, a1, a2;
  151. Loader::gather(grid_x,grid_y,grid_z,line_offset,lines,a0,a1,a2);
  152. Vec3<vfloat> b0, b1, b2;
  153. Loader::gather(grid_x+grid_offset,grid_y+grid_offset,grid_z+grid_offset,line_offset,lines,b0,b1,b2);
  154. Vec3<vfloat> v0 = lerp(a0,b0,vfloat(ftime));
  155. Vec3<vfloat> v1 = lerp(a1,b1,vfloat(ftime));
  156. Vec3<vfloat> v2 = lerp(a2,b2,vfloat(ftime));
  157. GridSOA::MapUV<Loader> mapUV(grid_uv,line_offset,lines);
  158. PlueckerIntersector1<Loader::M> intersector(ray,nullptr);
  159. return intersector.intersect(ray,v0,v1,v2,mapUV,Occluded1EpilogMU<Loader::M,true>(ray,context,pre.grid->geomID,pre.grid->primID));
  160. }
  161. /*! Intersect a ray with the primitive. */
  162. static __forceinline void intersect(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  163. {
  164. float ftime;
  165. const size_t itime = getTimeSegment(ray.time, float(pre.grid->time_steps-1), ftime);
  166. const size_t line_offset = pre.grid->width;
  167. const size_t lines = pre.grid->height;
  168. const float* const grid_x = pre.grid->decodeLeaf(itime,prim);
  169. #if defined(__AVX__)
  170. intersect<GridSOA::Gather3x3>( ray, ftime, context, grid_x, line_offset, lines, pre);
  171. #else
  172. intersect<GridSOA::Gather2x3>(ray, ftime, context, grid_x , line_offset, lines, pre);
  173. if (likely(lines > 2))
  174. intersect<GridSOA::Gather2x3>(ray, ftime, context, grid_x+line_offset, line_offset, lines, pre);
  175. #endif
  176. }
  177. /*! Test if the ray is occluded by the primitive */
  178. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node)
  179. {
  180. float ftime;
  181. const size_t itime = getTimeSegment(ray.time, float(pre.grid->time_steps-1), ftime);
  182. const size_t line_offset = pre.grid->width;
  183. const size_t lines = pre.grid->height;
  184. const float* const grid_x = pre.grid->decodeLeaf(itime,prim);
  185. #if defined(__AVX__)
  186. return occluded<GridSOA::Gather3x3>( ray, ftime, context, grid_x, line_offset, lines, pre);
  187. #else
  188. if (occluded<GridSOA::Gather2x3>(ray, ftime, context, grid_x , line_offset, lines, pre)) return true;
  189. if (likely(lines > 2))
  190. if (occluded<GridSOA::Gather2x3>(ray, ftime, context, grid_x+line_offset, line_offset, lines, pre)) return true;
  191. #endif
  192. return false;
  193. }
  194. };
  195. }
  196. }