curveNv.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "curveNi.h"
  5. namespace embree
  6. {
  7. template<int M>
  8. struct CurveNv : public CurveNi<M>
  9. {
  10. using CurveNi<M>::N;
  11. struct Type : public PrimitiveType {
  12. const char* name() const;
  13. size_t sizeActive(const char* This) const;
  14. size_t sizeTotal(const char* This) const;
  15. size_t getBytes(const char* This) const;
  16. };
  17. static Type type;
  18. public:
  19. /* Returns maximum number of stored primitives */
  20. static __forceinline size_t max_size() { return M; }
  21. /* Returns required number of primitive blocks for N primitives */
  22. static __forceinline size_t blocks(size_t N) { return (N+M-1)/M; }
  23. static __forceinline size_t bytes(size_t N)
  24. {
  25. const size_t f = N/M, r = N%M;
  26. static_assert(sizeof(CurveNv) == 22+25*M+4*16*M, "internal data layout issue");
  27. return f*sizeof(CurveNv) + (r!=0)*(22 + 25*r + 4*16*r);
  28. }
  29. public:
  30. /*! Default constructor. */
  31. __forceinline CurveNv () {}
  32. /*! fill curve from curve list */
  33. __forceinline void fill(const PrimRef* prims, size_t& begin, size_t _end, Scene* scene)
  34. {
  35. size_t end = min(begin+M,_end);
  36. size_t N = end-begin;
  37. /* encode all primitives */
  38. for (size_t i=0; i<N; i++)
  39. {
  40. const PrimRef& prim = prims[begin+i];
  41. const unsigned int geomID = prim.geomID();
  42. const unsigned int primID = prim.primID();
  43. CurveGeometry* mesh = (CurveGeometry*) scene->get(geomID);
  44. const unsigned vtxID = mesh->curve(primID);
  45. Vec3fa::storeu(&this->vertices(i,N)[0],mesh->vertex(vtxID+0));
  46. Vec3fa::storeu(&this->vertices(i,N)[1],mesh->vertex(vtxID+1));
  47. Vec3fa::storeu(&this->vertices(i,N)[2],mesh->vertex(vtxID+2));
  48. Vec3fa::storeu(&this->vertices(i,N)[3],mesh->vertex(vtxID+3));
  49. }
  50. }
  51. template<typename BVH, typename Allocator>
  52. __forceinline static typename BVH::NodeRef createLeaf (BVH* bvh, const PrimRef* prims, const range<size_t>& set, const Allocator& alloc)
  53. {
  54. if (set.size() == 0)
  55. return BVH::emptyNode;
  56. /* fall back to CurveNi for oriented curves */
  57. unsigned int geomID = prims[set.begin()].geomID();
  58. if (bvh->scene->get(geomID)->getCurveType() == Geometry::GTY_SUBTYPE_ORIENTED_CURVE) {
  59. return CurveNi<M>::createLeaf(bvh,prims,set,alloc);
  60. }
  61. if (bvh->scene->get(geomID)->getCurveBasis() == Geometry::GTY_BASIS_HERMITE) {
  62. return CurveNi<M>::createLeaf(bvh,prims,set,alloc);
  63. }
  64. size_t start = set.begin();
  65. size_t items = CurveNv::blocks(set.size());
  66. size_t numbytes = CurveNv::bytes(set.size());
  67. CurveNv* accel = (CurveNv*) alloc.malloc1(numbytes,BVH::byteAlignment);
  68. for (size_t i=0; i<items; i++) {
  69. accel[i].CurveNv<M>::fill(prims,start,set.end(),bvh->scene);
  70. accel[i].CurveNi<M>::fill(prims,start,set.end(),bvh->scene);
  71. }
  72. return bvh->encodeLeaf((char*)accel,items);
  73. };
  74. public:
  75. unsigned char data[4*16*M];
  76. __forceinline Vec3fa* vertices(size_t i, size_t N) { return (Vec3fa*)CurveNi<M>::end(N)+4*i; }
  77. __forceinline const Vec3fa* vertices(size_t i, size_t N) const { return (Vec3fa*)CurveNi<M>::end(N)+4*i; }
  78. };
  79. template<int M>
  80. typename CurveNv<M>::Type CurveNv<M>::type;
  81. typedef CurveNv<4> Curve4v;
  82. typedef CurveNv<8> Curve8v;
  83. }