diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-26 17:51:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-26 17:51:54 +0300 |
commit | 79111f92463c05f05d3765bff2b3c15b56df0731 (patch) | |
tree | 9e6b42e316e802acbbbe486b8eb2d946f373c850 /intern | |
parent | ae04e27bfa579d04c0c78705e1aa57f57f309fd1 (diff) | |
parent | 7e43210edbd9ff3148f9564a9c90d0687dde9363 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 28 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh4.cpp | 24 | ||||
-rw-r--r-- | intern/cycles/device/device_cpu.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/filter/filter_prefilter.h | 87 | ||||
-rw-r--r-- | intern/cycles/util/util_time.h | 7 | ||||
-rw-r--r-- | intern/mikktspace/mikktspace.c | 62 |
6 files changed, 123 insertions, 87 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 2e3271c735f..9375662bbd5 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -64,6 +64,8 @@ inline void face_split_tri_indices(const int face_flag, tri_b[2] = 1; } else /*if(face_flag & FACE_FLAG_DIVIDE_13)*/ { + assert(face_flag & FACE_FLAG_DIVIDE_13); + tri_a[0] = 0; tri_a[1] = 1; tri_a[2] = 2; @@ -77,15 +79,17 @@ inline void face_split_tri_indices(const int face_flag, /* Tangent Space */ struct MikkUserData { - MikkUserData(const BL::Mesh& mesh_, - BL::MeshTextureFaceLayer *layer_, - int num_faces_) - : mesh(mesh_), layer(layer_), num_faces(num_faces_) + MikkUserData(const BL::Mesh& b_mesh, + BL::MeshTextureFaceLayer *layer, + int num_faces) + : b_mesh(b_mesh), + layer(layer), + num_faces(num_faces) { tangent.resize(num_faces*4); } - BL::Mesh mesh; + BL::Mesh b_mesh; BL::MeshTextureFaceLayer *layer; int num_faces; vector<float4> tangent; @@ -100,7 +104,7 @@ static int mikk_get_num_faces(const SMikkTSpaceContext *context) static int mikk_get_num_verts_of_face(const SMikkTSpaceContext *context, const int face_num) { MikkUserData *userdata = (MikkUserData*)context->m_pUserData; - BL::MeshTessFace f = userdata->mesh.tessfaces[face_num]; + BL::MeshTessFace f = userdata->b_mesh.tessfaces[face_num]; int4 vi = get_int4(f.vertices_raw()); return (vi[3] == 0)? 3: 4; @@ -109,9 +113,9 @@ static int mikk_get_num_verts_of_face(const SMikkTSpaceContext *context, const i static void mikk_get_position(const SMikkTSpaceContext *context, float P[3], const int face_num, const int vert_num) { MikkUserData *userdata = (MikkUserData*)context->m_pUserData; - BL::MeshTessFace f = userdata->mesh.tessfaces[face_num]; + BL::MeshTessFace f = userdata->b_mesh.tessfaces[face_num]; int4 vi = get_int4(f.vertices_raw()); - BL::MeshVertex v = userdata->mesh.vertices[vi[vert_num]]; + BL::MeshVertex v = userdata->b_mesh.vertices[vi[vert_num]]; float3 vP = get_float3(v.co()); P[0] = vP.x; @@ -145,9 +149,9 @@ static void mikk_get_texture_coordinate(const SMikkTSpaceContext *context, float uv[1] = tfuv.y; } else { - int vert_idx = userdata->mesh.tessfaces[face_num].vertices()[vert_num]; + int vert_idx = userdata->b_mesh.tessfaces[face_num].vertices()[vert_num]; float3 orco = - get_float3(userdata->mesh.vertices[vert_idx].undeformed_co()); + get_float3(userdata->b_mesh.vertices[vert_idx].undeformed_co()); float2 tmp = map_to_sphere(make_float3(orco[0], orco[1], orco[2])); uv[0] = tmp.x; uv[1] = tmp.y; @@ -157,12 +161,12 @@ static void mikk_get_texture_coordinate(const SMikkTSpaceContext *context, float static void mikk_get_normal(const SMikkTSpaceContext *context, float N[3], const int face_num, const int vert_num) { MikkUserData *userdata = (MikkUserData*)context->m_pUserData; - BL::MeshTessFace f = userdata->mesh.tessfaces[face_num]; + BL::MeshTessFace f = userdata->b_mesh.tessfaces[face_num]; float3 vN; if(f.use_smooth()) { int4 vi = get_int4(f.vertices_raw()); - BL::MeshVertex v = userdata->mesh.vertices[vi[vert_num]]; + BL::MeshVertex v = userdata->b_mesh.vertices[vi[vert_num]]; vN = get_float3(v.normal()); } else { diff --git a/intern/cycles/bvh/bvh4.cpp b/intern/cycles/bvh/bvh4.cpp index aeedd802f49..777de20423b 100644 --- a/intern/cycles/bvh/bvh4.cpp +++ b/intern/cycles/bvh/bvh4.cpp @@ -242,21 +242,21 @@ void BVH4::pack_unaligned_node(int idx, * so kernel might safely assume there are always 4 child nodes. */ - data[1][i] = 1.0f; - data[2][i] = 0.0f; - data[3][i] = 0.0f; + data[1][i] = NAN; + data[2][i] = NAN; + data[3][i] = NAN; - data[4][i] = 0.0f; - data[5][i] = 0.0f; - data[6][i] = 0.0f; + data[4][i] = NAN; + data[5][i] = NAN; + data[6][i] = NAN; - data[7][i] = 0.0f; - data[8][i] = 0.0f; - data[9][i] = 0.0f; + data[7][i] = NAN; + data[8][i] = NAN; + data[9][i] = NAN; - data[10][i] = -FLT_MAX; - data[11][i] = -FLT_MAX; - data[12][i] = -FLT_MAX; + data[10][i] = NAN; + data[11][i] = NAN; + data[12][i] = NAN; data[13][i] = __int_as_float(0); } diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 6e09c5f88c2..6a1106328fb 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -120,7 +120,7 @@ public: } #endif - if(strstr(architecture_name, logged_architecture) != 0) { + if(strcmp(architecture_name, logged_architecture) != 0) { VLOG(1) << "Will be using " << architecture_name << " kernels."; logged_architecture = architecture_name; } diff --git a/intern/cycles/kernel/filter/filter_prefilter.h b/intern/cycles/kernel/filter/filter_prefilter.h index c6a70cbeab5..2aeb54a62be 100644 --- a/intern/cycles/kernel/filter/filter_prefilter.h +++ b/intern/cycles/kernel/filter/filter_prefilter.h @@ -120,49 +120,56 @@ ccl_device void kernel_filter_detect_outliers(int x, int y, { int buffer_w = align_up(rect.z - rect.x, 4); - int n = 0; - float values[25]; - for(int y1 = max(y-2, rect.y); y1 < min(y+3, rect.w); y1++) { - for(int x1 = max(x-2, rect.x); x1 < min(x+3, rect.z); x1++) { - int idx = (y1-rect.y)*buffer_w + (x1-rect.x); - float L = average(make_float3(image[idx], image[idx+pass_stride], image[idx+2*pass_stride])); - - /* Find the position of L. */ - int i; - for(i = 0; i < n; i++) { - if(values[i] > L) break; - } - /* Make space for L by shifting all following values to the right. */ - for(int j = n; j > i; j--) { - values[j] = values[j-1]; - } - /* Insert L. */ - values[i] = L; - n++; - } - } - int idx = (y-rect.y)*buffer_w + (x-rect.x); - float L = average(make_float3(image[idx], image[idx+pass_stride], image[idx+2*pass_stride])); + float3 color = make_float3(image[idx], image[idx+pass_stride], image[idx+2*pass_stride]); - float ref = 2.0f*values[(int)(n*0.75f)]; float fac = 1.0f; - if(L > ref) { - /* The pixel appears to be an outlier. - * However, it may just be a legitimate highlight. Therefore, it is checked how likely it is that the pixel - * should actually be at the reference value: - * If the reference is within the 3-sigma interval, the pixel is assumed to be a statistical outlier. - * Otherwise, it is very unlikely that the pixel should be darker, which indicates a legitimate highlight. - */ - float stddev = sqrtf(average(make_float3(variance[idx], variance[idx+pass_stride], variance[idx+2*pass_stride]))); - if(L - 3*stddev < ref) { - /* The pixel is an outlier, so negate the depth value to mark it as one. - * Also, scale its brightness down to the outlier threshold to avoid trouble with the NLM weights. */ - depth[idx] = -depth[idx]; - fac = ref/L; - variance[idx ] *= fac*fac; - variance[idx + pass_stride] *= fac*fac; - variance[idx+2*pass_stride] *= fac*fac; + if(color.x < 0.0f || color.y < 0.0f || color.z < 0.0f) { + depth[idx] = -depth[idx]; + fac = 0.0f; + } + else { + float L = average(color); + int n = 0; + float values[25]; + for(int y1 = max(y-2, rect.y); y1 < min(y+3, rect.w); y1++) { + for(int x1 = max(x-2, rect.x); x1 < min(x+3, rect.z); x1++) { + int idx = (y1-rect.y)*buffer_w + (x1-rect.x); + float L = average(make_float3(image[idx], image[idx+pass_stride], image[idx+2*pass_stride])); + + /* Find the position of L. */ + int i; + for(i = 0; i < n; i++) { + if(values[i] > L) break; + } + /* Make space for L by shifting all following values to the right. */ + for(int j = n; j > i; j--) { + values[j] = values[j-1]; + } + /* Insert L. */ + values[i] = L; + n++; + } + } + + float ref = 2.0f*values[(int)(n*0.75f)]; + if(L > ref) { + /* The pixel appears to be an outlier. + * However, it may just be a legitimate highlight. Therefore, it is checked how likely it is that the pixel + * should actually be at the reference value: + * If the reference is within the 3-sigma interval, the pixel is assumed to be a statistical outlier. + * Otherwise, it is very unlikely that the pixel should be darker, which indicates a legitimate highlight. + */ + float stddev = sqrtf(average(make_float3(variance[idx], variance[idx+pass_stride], variance[idx+2*pass_stride]))); + if(L - 3*stddev < ref) { + /* The pixel is an outlier, so negate the depth value to mark it as one. + * Also, scale its brightness down to the outlier threshold to avoid trouble with the NLM weights. */ + depth[idx] = -depth[idx]; + fac = ref/L; + variance[idx ] *= fac*fac; + variance[idx + pass_stride] *= fac*fac; + variance[idx+2*pass_stride] *= fac*fac; + } } } out[idx ] = fac*image[idx]; diff --git a/intern/cycles/util/util_time.h b/intern/cycles/util/util_time.h index 65798244111..f03aa590e9b 100644 --- a/intern/cycles/util/util_time.h +++ b/intern/cycles/util/util_time.h @@ -37,7 +37,7 @@ public: ~scoped_timer() { if(value_ != NULL) { - *value_ = time_dt() - time_start_; + *value_ = get_time(); } } @@ -46,6 +46,11 @@ public: return time_start_; } + double get_time() const + { + return time_dt() - time_start_; + } + protected: double *value_; double time_start_; diff --git a/intern/mikktspace/mikktspace.c b/intern/mikktspace/mikktspace.c index 7fbfe57be5c..c52494a49f8 100644 --- a/intern/mikktspace/mikktspace.c +++ b/intern/mikktspace/mikktspace.c @@ -39,17 +39,23 @@ #define INTERNAL_RND_SORT_SEED 39871946 +#ifdef _MSC_VER +# define MIKK_INLINE static __forceinline +#else +# define MIKK_INLINE static inline __attribute__((always_inline)) __attribute__((unused)) +#endif + // internal structure typedef struct { float x, y, z; } SVec3; -static tbool veq( const SVec3 v1, const SVec3 v2 ) +MIKK_INLINE tbool veq( const SVec3 v1, const SVec3 v2 ) { return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z); } -static SVec3 vadd( const SVec3 v1, const SVec3 v2 ) +MIKK_INLINE SVec3 vadd( const SVec3 v1, const SVec3 v2 ) { SVec3 vRes; @@ -61,7 +67,7 @@ static SVec3 vadd( const SVec3 v1, const SVec3 v2 ) } -static SVec3 vsub( const SVec3 v1, const SVec3 v2 ) +MIKK_INLINE SVec3 vsub( const SVec3 v1, const SVec3 v2 ) { SVec3 vRes; @@ -72,7 +78,7 @@ static SVec3 vsub( const SVec3 v1, const SVec3 v2 ) return vRes; } -static SVec3 vscale(const float fS, const SVec3 v) +MIKK_INLINE SVec3 vscale(const float fS, const SVec3 v) { SVec3 vRes; @@ -83,24 +89,24 @@ static SVec3 vscale(const float fS, const SVec3 v) return vRes; } -static float LengthSquared( const SVec3 v ) +MIKK_INLINE float LengthSquared( const SVec3 v ) { return v.x*v.x + v.y*v.y + v.z*v.z; } -static float Length( const SVec3 v ) +MIKK_INLINE float Length( const SVec3 v ) { return sqrtf(LengthSquared(v)); } #if 0 // UNUSED -static SVec3 Normalize( const SVec3 v ) +MIKK_INLINE SVec3 Normalize( const SVec3 v ) { return vscale(1.0f / Length(v), v); } #endif -static SVec3 NormalizeSafe( const SVec3 v ) +MIKK_INLINE SVec3 NormalizeSafe( const SVec3 v ) { const float len = Length(v); if (len != 0.0f) { @@ -112,20 +118,20 @@ static SVec3 NormalizeSafe( const SVec3 v ) } } -static float vdot( const SVec3 v1, const SVec3 v2) +MIKK_INLINE float vdot( const SVec3 v1, const SVec3 v2) { return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; } -static tbool NotZero(const float fX) +MIKK_INLINE tbool NotZero(const float fX) { // could possibly use FLT_EPSILON instead return fabsf(fX) > FLT_MIN; } #if 0 // UNUSED -static tbool VNotZero(const SVec3 v) +MIKK_INLINE tbool VNotZero(const SVec3 v) { // might change this to an epsilon based test return NotZero(v.x) || NotZero(v.y) || NotZero(v.z); @@ -184,13 +190,13 @@ static tbool GenerateTSpaces(STSpace psTspace[], const STriInfo pTriInfos[], con const int iNrActiveGroups, const int piTriListIn[], const float fThresCos, const SMikkTSpaceContext * pContext); -static int MakeIndex(const int iFace, const int iVert) +MIKK_INLINE int MakeIndex(const int iFace, const int iVert) { assert(iVert>=0 && iVert<4 && iFace>=0); return (iFace<<2) | (iVert&0x3); } -static void IndexToData(int * piFace, int * piVert, const int iIndexIn) +MIKK_INLINE void IndexToData(int * piFace, int * piVert, const int iIndexIn) { piVert[0] = iIndexIn&0x3; piFace[0] = iIndexIn>>2; @@ -226,9 +232,9 @@ static STSpace AvgTSpace(const STSpace * pTS0, const STSpace * pTS1) -static SVec3 GetPosition(const SMikkTSpaceContext * pContext, const int index); -static SVec3 GetNormal(const SMikkTSpaceContext * pContext, const int index); -static SVec3 GetTexCoord(const SMikkTSpaceContext * pContext, const int index); +MIKK_INLINE SVec3 GetPosition(const SMikkTSpaceContext * pContext, const int index); +MIKK_INLINE SVec3 GetNormal(const SMikkTSpaceContext * pContext, const int index); +MIKK_INLINE SVec3 GetTexCoord(const SMikkTSpaceContext * pContext, const int index); // degen triangles @@ -896,7 +902,7 @@ static int GenerateInitialVerticesIndexList(STriInfo pTriInfos[], int piTriList_ return iTSpacesOffs; } -static SVec3 GetPosition(const SMikkTSpaceContext * pContext, const int index) +MIKK_INLINE SVec3 GetPosition(const SMikkTSpaceContext * pContext, const int index) { int iF, iI; SVec3 res; float pos[3]; @@ -906,7 +912,7 @@ static SVec3 GetPosition(const SMikkTSpaceContext * pContext, const int index) return res; } -static SVec3 GetNormal(const SMikkTSpaceContext * pContext, const int index) +MIKK_INLINE SVec3 GetNormal(const SMikkTSpaceContext * pContext, const int index) { int iF, iI; SVec3 res; float norm[3]; @@ -916,7 +922,7 @@ static SVec3 GetNormal(const SMikkTSpaceContext * pContext, const int index) return res; } -static SVec3 GetTexCoord(const SMikkTSpaceContext * pContext, const int index) +MIKK_INLINE SVec3 GetTexCoord(const SMikkTSpaceContext * pContext, const int index) { int iF, iI; SVec3 res; float texc[2]; @@ -1080,7 +1086,7 @@ static void InitTriInfo(STriInfo pTriInfos[], const int piTriListIn[], const SMi ///////////////////////////////////////////////////////////////////////////////////////////////////// static tbool AssignRecur(const int piTriListIn[], STriInfo psTriInfos[], const int iMyTriIndex, SGroup * pGroup); -static void AddTriToGroup(SGroup * pGroup, const int iTriIndex); +MIKK_INLINE void AddTriToGroup(SGroup * pGroup, const int iTriIndex); static int Build4RuleGroups(STriInfo pTriInfos[], SGroup pGroups[], int piGroupTrianglesBuffer[], const int piTriListIn[], const int iNrTrianglesIn) { @@ -1146,7 +1152,7 @@ static int Build4RuleGroups(STriInfo pTriInfos[], SGroup pGroups[], int piGroupT return iNrActiveGroups; } -static void AddTriToGroup(SGroup * pGroup, const int iTriIndex) +MIKK_INLINE void AddTriToGroup(SGroup * pGroup, const int iTriIndex) { pGroup->pFaceIndices[pGroup->iNrFaces] = iTriIndex; ++pGroup->iNrFaces; @@ -1671,6 +1677,20 @@ static void QuickSortEdges(SEdge * pSortBuffer, int iLeft, int iRight, const int } return; } + else if(iElems < 16) { + int i, j; + for (i = 0; i < iElems - 1; i++) { + for (j = 0; j < iElems - i - 1; j++) { + int index = iLeft + j; + if (pSortBuffer[index].array[channel] > pSortBuffer[index + 1].array[channel]) { + sTmp = pSortBuffer[index]; + pSortBuffer[index] = pSortBuffer[index + 1]; + pSortBuffer[index + 1] = sTmp; + } + } + } + return; + } // Random t=uSeed&31; |