subdivpatch1base.h 6.0 KB

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