Skip to content

Commit

Permalink
[spline/bezier]Extract an if-check in the hot loops to the template p…
Browse files Browse the repository at this point in the history
…arameter.
  • Loading branch information
xebra committed Oct 7, 2018
1 parent 3216a83 commit 98ddefb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions GPU/Common/SplineCommon.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class SubdivisionSurface {
defcolor = points[0]->color_32; defcolor = points[0]->color_32;
} }


template <bool sampleNrm, bool sampleCol, bool sampleTex, bool useSSE4> template <bool sampleNrm, bool sampleCol, bool sampleTex, bool useSSE4, bool patchFacing>
void Tessellate(SimpleVertex *vertices, u16 *indices, int &count) { void Tessellate(SimpleVertex *vertices, u16 *indices, int &count) {
const float inv_u = 1.0f / (float)patch.tess_u; const float inv_u = 1.0f / (float)patch.tess_u;
const float inv_v = 1.0f / (float)patch.tess_v; const float inv_v = 1.0f / (float)patch.tess_v;
Expand Down Expand Up @@ -396,7 +396,7 @@ class SubdivisionSurface {
const Vec3f derivV = tess_pos.SampleV(wv.deriv); const Vec3f derivV = tess_pos.SampleV(wv.deriv);


vert.nrm = Cross(derivU, derivV).Normalized(useSSE4); vert.nrm = Cross(derivU, derivV).Normalized(useSSE4);
if (patch.patchFacing) if (patchFacing)
vert.nrm *= -1.0f; vert.nrm *= -1.0f;
} else { } else {
vert.nrm.SetZero(); vert.nrm.SetZero();
Expand All @@ -414,14 +414,15 @@ class SubdivisionSurface {


void Tessellate(SimpleVertex *vertices, u16 *indices, int &count, u32 origVertType) { void Tessellate(SimpleVertex *vertices, u16 *indices, int &count, u32 origVertType) {
using TessFunc = void(SubdivisionSurface::*)(SimpleVertex *, u16 *, int &); using TessFunc = void(SubdivisionSurface::*)(SimpleVertex *, u16 *, int &);
constexpr int NumParams = 4; constexpr int NumParams = 5;
static TemplateParameterDispatcherTess<TessFunc, NumParams> dispatcher; // Initialize only once static TemplateParameterDispatcherTess<TessFunc, NumParams> dispatcher; // Initialize only once


const bool params[NumParams] = { const bool params[NumParams] = {
(origVertType & GE_VTYPE_NRM_MASK) != 0, (origVertType & GE_VTYPE_NRM_MASK) != 0,
(origVertType & GE_VTYPE_COL_MASK) != 0, (origVertType & GE_VTYPE_COL_MASK) != 0,
(origVertType & GE_VTYPE_TC_MASK) != 0, (origVertType & GE_VTYPE_TC_MASK) != 0,
cpu_info.bSSE4_1, cpu_info.bSSE4_1,
patch.patchFacing,
}; };
TessFunc func = dispatcher.GetFunc(params); TessFunc func = dispatcher.GetFunc(params);
(this->*func)(vertices, indices, count); (this->*func)(vertices, indices, count);
Expand Down

0 comments on commit 98ddefb

Please sign in to comment.