Skip to content

Commit

Permalink
[spline/bezier]minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xebra committed Oct 7, 2018
1 parent 2a3210a commit 1b9af84
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions GPU/Common/SplineCommon.cpp
Expand Up @@ -109,9 +109,7 @@ struct KnotDiv {
float _3_2 = 1.0f; // Always 1 float _3_2 = 1.0f; // Always 1
}; };


static void spline_n_4(int i, float t, float *knot, const KnotDiv &div, float *splineVal, float *derivs) { static void spline_n_4(float t, float *knot, const KnotDiv &div, float *splineVal, float *derivs) {
knot += i;

#ifdef _M_SSE #ifdef _M_SSE
const __m128 knot012 = _mm_loadu_ps(knot); const __m128 knot012 = _mm_loadu_ps(knot);
const __m128 t012 = _mm_sub_ps(_mm_set_ps1(t), knot012); const __m128 t012 = _mm_sub_ps(_mm_set_ps1(t), knot012);
Expand Down Expand Up @@ -177,34 +175,34 @@ static void spline_n_4(int i, float t, float *knot, const KnotDiv &div, float *s


// knot should be an array sized n + 5 (n + 1 + 1 + degree (cubic)) // knot should be an array sized n + 5 (n + 1 + 1 + degree (cubic))
static void spline_knot(int n, int type, float *knots, KnotDiv *divs) { static void spline_knot(int n, int type, float *knots, KnotDiv *divs) {
// Basic theory (-2 to +3), optimized with KnotDiv (-2 to +0) // Basic theory (-2 to +3), optimized with KnotDiv (-2 to +0)
// for (int i = 0; i < n + 5; ++i) { // for (int i = 0; i < n + 5; ++i) {
for (int i = 0; i < n + 2; ++i) { for (int i = 0; i < n + 2; ++i) {
knots[i] = (float)i - 2; knots[i] = (float)i - 2;
} }


// The first edge is open // The first edge is open
if ((type & 1) != 0) { if ((type & 1) != 0) {
knots[0] = 0; knots[0] = 0;
knots[1] = 0; knots[1] = 0;


divs[0]._3_0 = 1.0f; divs[0]._3_0 = 1.0f;
divs[0]._4_1 = 1.0f / 2.0f; divs[0]._4_1 = 1.0f / 2.0f;
divs[0]._3_1 = 1.0f; divs[0]._3_1 = 1.0f;
if (n > 1) if (n > 1)
divs[1]._3_0 = 1.0f / 2.0f; divs[1]._3_0 = 1.0f / 2.0f;
} }
// The last edge is open // The last edge is open
if ((type & 2) != 0) { if ((type & 2) != 0) {
// knots[n + 2] = (float)n; // Got rid of this line optimized with KnotDiv // knots[n + 2] = (float)n; // Got rid of this line optimized with KnotDiv
// knots[n + 3] = (float)n; // Got rid of this line optimized with KnotDiv // knots[n + 3] = (float)n; // Got rid of this line optimized with KnotDiv
// knots[n + 4] = (float)n; // Got rid of this line optimized with KnotDiv // knots[n + 4] = (float)n; // Got rid of this line optimized with KnotDiv
divs[n - 1]._4_1 = 1.0f / 2.0f; divs[n - 1]._4_1 = 1.0f / 2.0f;
divs[n - 1]._5_2 = 1.0f; divs[n - 1]._5_2 = 1.0f;
divs[n - 1]._4_2 = 1.0f; divs[n - 1]._4_2 = 1.0f;
if (n > 1) if (n > 1)
divs[n - 2]._5_2 = 1.0f / 2.0f; divs[n - 2]._5_2 = 1.0f / 2.0f;
} }
} }


bool CanUseHardwareTessellation(GEPatchPrimType prim) { bool CanUseHardwareTessellation(GEPatchPrimType prim) {
Expand Down Expand Up @@ -335,8 +333,8 @@ static void SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const Sp
if (iu >= spatch.count_u - 3) iu = spatch.count_u - 4; if (iu >= spatch.count_u - 3) iu = spatch.count_u - 4;
if (iv >= spatch.count_v - 3) iv = spatch.count_v - 4; if (iv >= spatch.count_v - 3) iv = spatch.count_v - 4;


spline_n_4(iu, u, knot_u, divs_u[iu], u_weights, u_derivs); spline_n_4(u, knot_u + iu, divs_u[iu], u_weights, u_derivs);
spline_n_4(iv, v, knot_v, divs_v[iv], v_weights, v_derivs); spline_n_4(v, knot_v + iv, divs_v[iv], v_weights, v_derivs);


// Handle degenerate patches. without this, spatch.points[] may read outside the number of initialized points. // Handle degenerate patches. without this, spatch.points[] may read outside the number of initialized points.
int patch_w = std::min(spatch.count_u - iu, 4); int patch_w = std::min(spatch.count_u - iu, 4);
Expand Down

0 comments on commit 1b9af84

Please sign in to comment.