Skip to content

Commit

Permalink
[spline/bezier]Modify the weights cache variables to a template varia…
Browse files Browse the repository at this point in the history
…ble.
  • Loading branch information
xebra committed Oct 7, 2018
1 parent 62aaf63 commit 6683351
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
52 changes: 27 additions & 25 deletions GPU/Common/SplineCommon.cpp
Expand Up @@ -86,11 +86,11 @@ class Bezier3DWeight {
return weights;
}

u32 ToKey(int tess, int count, int type) {
static u32 ToKey(int tess, int count, int type) {
return tess;
}

int CalcSize(int tess, int count) {
static int CalcSize(int tess, int count) {
return tess + 1;
}
};
Expand Down Expand Up @@ -228,25 +228,25 @@ class Spline3DWeight {
return weights;
}

u32 ToKey(int tess, int count, int type) {
static u32 ToKey(int tess, int count, int type) {
return tess | (count << 8) | (type << 16);
}

void FromKey(u32 key, int &tess, int &count, int &type) {
static void FromKey(u32 key, int &tess, int &count, int &type) {
tess = key & 0xFF; count = (key >> 8) & 0xFF; type = (key >> 16) & 0xFF;
}

int CalcSize(int tess, int count) {
static int CalcSize(int tess, int count) {
return (count - 3) * tess + 1;
}
};

static WeightCache<Bezier3DWeight> bezierWeightsCache;
static WeightCache<Spline3DWeight> splineWeightsCache;
template <class WeightType>
static WeightCache<WeightType> weightsCache;

void DrawEngineCommon::ClearSplineBezierWeights() {
bezierWeightsCache.Clear();
splineWeightsCache.Clear();
weightsCache<Bezier3DWeight>.Clear();
weightsCache<Spline3DWeight>.Clear();
}

bool CanUseHardwareTessellation(GEPatchPrimType prim) {
Expand Down Expand Up @@ -428,25 +428,27 @@ class SubdivisionSurface {
}
};

template<class Patch, class Cache>
template<class Patch>
static void SoftwareTessellation(OutputBuffers &output, const Patch &patch, u32 origVertType,
const SimpleVertex *const *points, SimpleBufferManager &managedBuf, Cache &weightsCache) {
u32 key_u = weightsCache.ToKey(patch.tess_u, patch.count_u, patch.type_u);
u32 key_v = weightsCache.ToKey(patch.tess_v, patch.count_v, patch.type_v);
Weight2D weights(weightsCache, key_u, key_v);
const SimpleVertex *const *points, SimpleBufferManager &managedBuf) {
using WeightType = Patch::WeightType;
u32 key_u = WeightType::ToKey(patch.tess_u, patch.count_u, patch.type_u);
u32 key_v = WeightType::ToKey(patch.tess_v, patch.count_v, patch.type_v);
Weight2D weights(weightsCache<WeightType>, key_u, key_v);

SubdivisionSurface<Patch> surface(managedBuf, points, patch, weights);
surface.Tessellate(output, origVertType);
}

template<class Patch, class Cache>
template<class Patch>
static void HardwareTessellation(OutputBuffers &output, const Patch &patch, u32 origVertType,
const SimpleVertex *const *points, Cache &weightsCache, TessellationDataTransfer *tessDataTransfer) {
u32 key_u = weightsCache.ToKey(patch.tess_u, patch.count_u, patch.type_u);
u32 key_v = weightsCache.ToKey(patch.tess_v, patch.count_v, patch.type_v);
Weight2D weights(weightsCache, key_u, key_v);
weights.size_u = weightsCache.CalcSize(patch.tess_u, patch.count_u);
weights.size_v = weightsCache.CalcSize(patch.tess_v, patch.count_v);
const SimpleVertex *const *points, TessellationDataTransfer *tessDataTransfer) {
using WeightType = Patch::WeightType;
u32 key_u = WeightType::ToKey(patch.tess_u, patch.count_u, patch.type_u);
u32 key_v = WeightType::ToKey(patch.tess_v, patch.count_v, patch.type_v);
Weight2D weights(weightsCache<WeightType>, key_u, key_v);
weights.size_u = WeightType::CalcSize(patch.tess_u, patch.count_u);
weights.size_v = WeightType::CalcSize(patch.tess_v, patch.count_v);
tessDataTransfer->SendDataToShader(points, patch.count_u * patch.count_v, origVertType, weights);

// Generating simple input vertices for the spline-computing vertex shader.
Expand Down Expand Up @@ -525,11 +527,11 @@ void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indi
patch.patchFacing = patchFacing;

if (CanUseHardwareTessellation(prim_type)) {
HardwareTessellation(output, patch, origVertType, points, splineWeightsCache, tessDataTransfer);
HardwareTessellation(output, patch, origVertType, points, tessDataTransfer);
numPatches = patch.num_patches_u * patch.num_patches_v;
} else {
patch.Init(SPLINE_BUFFER_SIZE / vertexSize);
SoftwareTessellation(output, patch, origVertType, points, managedBuf, splineWeightsCache);
SoftwareTessellation(output, patch, origVertType, points, managedBuf);
}

u32 vertTypeWithIndex16 = (vertType & ~GE_VTYPE_IDX_MASK) | GE_VTYPE_IDX_16BIT;
Expand Down Expand Up @@ -616,11 +618,11 @@ void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indi
patch.patchFacing = patchFacing;

if (CanUseHardwareTessellation(prim_type)) {
HardwareTessellation(output, patch, origVertType, points, bezierWeightsCache, tessDataTransfer);
HardwareTessellation(output, patch, origVertType, points, tessDataTransfer);
numPatches = patch.num_patches_u * patch.num_patches_v;
} else {
patch.Init(SPLINE_BUFFER_SIZE / vertexSize);
SoftwareTessellation(output, patch, origVertType, points, managedBuf, bezierWeightsCache);
SoftwareTessellation(output, patch, origVertType, points, managedBuf);
}

u32 vertTypeWithIndex16 = (vertType & ~GE_VTYPE_IDX_MASK) | GE_VTYPE_IDX_16BIT;
Expand Down
7 changes: 7 additions & 0 deletions GPU/Common/SplineCommon.h
Expand Up @@ -45,9 +45,14 @@ enum SplineQuality {
HIGH_QUALITY = 2,
};

class Bezier3DWeight;
class Spline3DWeight;

// We decode all vertices into a common format for easy interpolation and stuff.
// Not fast but can be optimized later.
struct BezierPatch {
using WeightType = Bezier3DWeight;

int tess_u;
int tess_v;
int count_u;
Expand Down Expand Up @@ -104,6 +109,8 @@ struct BezierPatch {
};

struct SplinePatchLocal {
using WeightType = Spline3DWeight;

int tess_u;
int tess_v;
int count_u;
Expand Down

0 comments on commit 6683351

Please sign in to comment.