subdivpatch1base.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "../geometry/primitive.h"
  5. #include "bspline_patch.h"
  6. #include "bezier_patch.h"
  7. #include "gregory_patch.h"
  8. #include "gregory_patch_dense.h"
  9. #include "tessellation.h"
  10. #include "tessellation_cache.h"
  11. #include "gridrange.h"
  12. #include "patch_eval_grid.h"
  13. #include "feature_adaptive_eval_grid.h"
  14. #include "../common/scene_subdiv_mesh.h"
  15. namespace embree
  16. {
  17. struct __aligned(64) SubdivPatch1Base
  18. {
  19. public:
  20. enum Type {
  21. INVALID_PATCH = 0,
  22. BSPLINE_PATCH = 1,
  23. BEZIER_PATCH = 2,
  24. GREGORY_PATCH = 3,
  25. EVAL_PATCH = 5,
  26. BILINEAR_PATCH = 6,
  27. };
  28. enum Flags {
  29. TRANSITION_PATCH = 16,
  30. };
  31. /*! Default constructor. */
  32. __forceinline SubdivPatch1Base () {}
  33. SubdivPatch1Base (const unsigned int gID,
  34. const unsigned int pID,
  35. const unsigned int subPatch,
  36. const SubdivMesh *const mesh,
  37. const size_t time,
  38. const Vec2f uv[4],
  39. const float edge_level[4],
  40. const int subdiv[4],
  41. const int simd_width);
  42. __forceinline bool needsStitching() const {
  43. return flags & TRANSITION_PATCH;
  44. }
  45. __forceinline Vec2f getUV(const size_t i) const {
  46. return Vec2f((float)u[i],(float)v[i]) * (8.0f/0x10000);
  47. }
  48. static void computeEdgeLevels(const float edge_level[4], const int subdiv[4], float level[4]);
  49. static Vec2i computeGridSize(const float level[4]);
  50. bool updateEdgeLevels(const float edge_level[4], const int subdiv[4], const SubdivMesh *const mesh, const int simd_width);
  51. public:
  52. __forceinline size_t getGridBytes() const {
  53. const size_t grid_size_xyzuv = (grid_size_simd_blocks * VSIZEX) * 4;
  54. return 64*((grid_size_xyzuv+15) / 16);
  55. }
  56. __forceinline void write_lock() { mtx.lock(); }
  57. __forceinline void write_unlock() { mtx.unlock(); }
  58. __forceinline bool try_write_lock() { return mtx.try_lock(); }
  59. //__forceinline bool try_read_lock() { return mtx.try_read_lock(); }
  60. __forceinline void resetRootRef() {
  61. //assert( mtx.hasInitialState() );
  62. root_ref = SharedLazyTessellationCache::Tag();
  63. }
  64. __forceinline SharedLazyTessellationCache::CacheEntry& entry() {
  65. return (SharedLazyTessellationCache::CacheEntry&) root_ref;
  66. }
  67. public:
  68. __forceinline unsigned int geomID() const {
  69. return geom;
  70. }
  71. __forceinline unsigned int primID() const {
  72. return prim;
  73. }
  74. public:
  75. SharedLazyTessellationCache::Tag root_ref;
  76. SpinLock mtx;
  77. unsigned short u[4]; //!< 16bit discretized u,v coordinates
  78. unsigned short v[4];
  79. float level[4];
  80. unsigned char flags;
  81. unsigned char type;
  82. unsigned short grid_u_res;
  83. unsigned int geom; //!< geometry ID of the subdivision mesh this patch belongs to
  84. unsigned int prim; //!< primitive ID of this subdivision patch
  85. unsigned short grid_v_res;
  86. unsigned short grid_size_simd_blocks;
  87. unsigned int time_;
  88. struct PatchHalfEdge {
  89. const HalfEdge* edge;
  90. unsigned subPatch;
  91. };
  92. Vec3fa patch_v[4][4];
  93. const HalfEdge *edge() const { return ((PatchHalfEdge*)patch_v)->edge; }
  94. unsigned time() const { return time_; }
  95. unsigned subPatch() const { return ((PatchHalfEdge*)patch_v)->subPatch; }
  96. void set_edge(const HalfEdge *h) const { ((PatchHalfEdge*)patch_v)->edge = h; }
  97. void set_subPatch(const unsigned s) const { ((PatchHalfEdge*)patch_v)->subPatch = s; }
  98. };
  99. namespace isa
  100. {
  101. Vec3fa patchEval(const SubdivPatch1Base& patch, const float uu, const float vv);
  102. Vec3fa patchNormal(const SubdivPatch1Base& patch, const float uu, const float vv);
  103. template<typename simdf>
  104. Vec3<simdf> patchEval(const SubdivPatch1Base& patch, const simdf& uu, const simdf& vv);
  105. template<typename simdf>
  106. Vec3<simdf> patchNormal(const SubdivPatch1Base& patch, const simdf& uu, const simdf& vv);
  107. /* eval grid over patch and stich edges when required */
  108. void evalGrid(const SubdivPatch1Base& patch,
  109. const unsigned x0, const unsigned x1,
  110. const unsigned y0, const unsigned y1,
  111. const unsigned swidth, const unsigned sheight,
  112. float *__restrict__ const grid_x,
  113. float *__restrict__ const grid_y,
  114. float *__restrict__ const grid_z,
  115. float *__restrict__ const grid_u,
  116. float *__restrict__ const grid_v,
  117. const SubdivMesh* const geom);
  118. /* eval grid over patch and stich edges when required */
  119. BBox3fa evalGridBounds(const SubdivPatch1Base& patch,
  120. const unsigned x0, const unsigned x1,
  121. const unsigned y0, const unsigned y1,
  122. const unsigned swidth, const unsigned sheight,
  123. const SubdivMesh* const geom);
  124. }
  125. }