Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactoring] Improve spline/bezier. #11425

Merged
merged 72 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5c7284f
[spline/bezier]Get rid of divisions in spline weights calculation.
xebra Jan 29, 2018
a9ac860
[spline/bezier]Add spline derivative calculation for normal generation.
xebra Jan 29, 2018
a4860b6
[spline/bezier]Managing buffer allocation.
xebra Jan 30, 2018
28a5005
[spline/bezier]minor fix
xebra Jan 30, 2018
1d4e8cc
[spline/bezier]minor fix
xebra Jan 30, 2018
a7754c4
[spline/bezier]minor fix
xebra Jan 30, 2018
3c2837b
[spline/bezier]minor fix
xebra Jan 30, 2018
b1289cd
[spline/bezier]minor fix
xebra Jun 27, 2018
485260c
[spline/bezier]Make a function to copy control points.
xebra Jan 30, 2018
966ff32
[spline/bezier]Improve the logic of copying control-points.
xebra Jun 27, 2018
7cbc97f
[spline/bezier]minor cleanup
xebra Jan 30, 2018
30c3c87
[spline/bezier]Make a function to build indices.
xebra Jan 30, 2018
d8ccc1c
[spline/bezier]minor fix
xebra Jan 30, 2018
15a11d5
Modify IndexConverter class to functor.
xebra Jan 30, 2018
62ad5fe
Fix namespace Vec2f.
xebra Jan 31, 2018
36ed61d
[spline/bezier]Pre-convert control-points for the accumulation of SIM…
xebra Jan 31, 2018
c8e45ae
[spline/bezier]Use real tessellation in low-quality with "fixed to 2"…
xebra Jan 31, 2018
d0682d7
[spline/bezier]Move SIMD optimization of vector operations to Math3D.h.
xebra Jan 31, 2018
a340390
[spline/bezier]Move bezier patch loops into the function and pre-conv…
xebra Jan 31, 2018
3aeb320
[spline/bezier]Improve bezier weights calculation.
xebra Jan 31, 2018
2a3210a
[spline/bezier]Make a bezier weights calculation class and precalcula…
xebra Jan 31, 2018
1b9af84
[spline/bezier]minor fix
xebra Jan 31, 2018
0c96804
[spline/bezier]minor fix
xebra Jan 31, 2018
15b409a
[spline/bezier]Make a spline weights calculation class and precalcula…
xebra Jan 31, 2018
1e84a62
[spline/bezier]Implement weights cache system.
xebra Jan 31, 2018
068cc37
[spline/bezier]Improve bezier tessellator.
xebra Feb 1, 2018
4c6098d
[spline/bezier]Improve bezier tessellator more.
xebra Feb 1, 2018
3069153
[spline/bezier]Fix bezier texcoord generation.
xebra Feb 1, 2018
f12d796
[spline/bezier]minor cleanup
xebra Feb 1, 2018
07888d7
[spline/bezier]Improve bezier tesselator more.
xebra Feb 1, 2018
ca4e246
[spline/bezier]Improve tessellator more generic.
xebra Feb 1, 2018
b11f9e6
[spline/bezier]Fix normal generation flag and some minor stuffs.
xebra Feb 1, 2018
f7ac708
[spline/bezier]Improve spline tessellation using same as bezier tesse…
xebra Feb 1, 2018
da1176f
[spline/bezier]Improve template parameter dispatch method.
xebra Feb 1, 2018
24123e6
[spline/bezier]Fix about quality.
xebra Feb 2, 2018
7d45078
[spline/bezier]minor cleanup
xebra Jun 28, 2018
0cb6331
[spline/bezier]Fix to build for GE debugger.
xebra Jun 28, 2018
3add123
thin3d: Add support for texture subimage to GLRender.
xebra Jun 29, 2018
1b076f8
[spline/bezier]Improve HW tess on Opengl to combine 3 textures into a…
xebra Jun 29, 2018
e5976f5
[spline/bezier]Unify software tessellation of bezier and spline.
xebra Feb 4, 2018
3c0fb44
[spline/bezier]Improve hwtess to use cached weights.
xebra Jul 10, 2018
a48a5b3
[spline/bezier]Unify hardware tessellation of bezier and spline.
xebra Jul 13, 2018
3d07bca
[spline/bezier]Fix spline weights calculation and get rid of using ne…
xebra Feb 11, 2018
41d6c3c
[spline/bezier]Move whole tessellation logic in the shaders into a su…
xebra Jul 13, 2018
103d180
[spline/bezier]Get rid of wasted if-checks at Graphics Processors.
xebra Jul 13, 2018
de5975f
[spline/bezier]Reduce multiplications in the shaders from 16 to 4.
xebra Jul 13, 2018
d4a6673
[spline/bezier]Improve shader uniforms a bit.
xebra Jul 14, 2018
453e274
[spline/bezier]Fix around vertex type flags.
xebra Jul 17, 2018
03b9492
[spline/bezier]Sharing textures to avoid heavily textures creation/de…
xebra Jul 20, 2018
8c279c0
[spline/bezier]Precalculate weights in the shaders using the outer pr…
xebra Jul 21, 2018
3216a83
[spline/bezier]Expand loops in the shaders.
xebra Jul 21, 2018
98ddefb
[spline/bezier]Extract an if-check in the hot loops to the template p…
xebra Jul 21, 2018
a241058
[spline/bezier]Improve TemplateParameterDispatcher class macro to a r…
xebra Jul 21, 2018
c4a8d80
[spline/bezier]Put the output buffers all in one structure.
xebra Jul 22, 2018
62aaf63
Math3D: Something wrong with hand simd optimization in vec2<float>, s…
xebra Jul 23, 2018
6683351
[spline/bezier]Modify the weights cache variables to a template varia…
xebra Jul 30, 2018
1c604d5
[spline/bezier]Put the control points stuffs all in one structure.
xebra Jul 30, 2018
019e276
[spline/bezier]Modify ControlPoints and fix VertexPreview.
xebra Aug 9, 2018
d98fa06
[spline/bezier]Fix to build for Android(clang).
xebra Aug 31, 2018
89786b9
[spline/bezier]Instanced rendering for B-Spline is very slow when usi…
xebra Sep 22, 2018
41823f8
[spline/bezier]Fix GLES texture resolution of HW tess to real 2D to a…
xebra Sep 22, 2018
c49d9e2
[spline/bezier]minor fix(referenced to c1f0e981).
xebra Sep 23, 2018
8ad38df
[spline/bezier]oops
xebra Sep 24, 2018
10afcf2
[spline/bezier]Improve basic spline/bezier structures.
xebra Sep 27, 2018
1dfb402
[spline/bezier]Remove comment.
xebra Sep 28, 2018
ef53195
[spline/bezier]Surround with namespace Spline.
xebra Sep 29, 2018
405ead8
[spline/bezier]Get rid of duplication call of Flush().
xebra Sep 29, 2018
5f9022a
[spline/bezier]minor fix
xebra Sep 30, 2018
5f07213
[spline/bezier]minor fix
xebra Sep 30, 2018
eca9386
[spline/bezier]Reduce static buffers. Get rid of the spline buffer us…
xebra Oct 1, 2018
46d30d0
[spline/bezier]minor fix
xebra Oct 2, 2018
0d7a5cd
GLES: Fix to delete subimage data since #11447.
xebra Oct 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions GPU/Common/DrawEngineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum {
};

DrawEngineCommon::DrawEngineCommon() : decoderMap_(16) {
quadIndices_ = new u16[6 * QUAD_INDICES_MAX];
decJitCache_ = new VertexDecoderJitCache();
transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
transformedExpanded = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
Expand All @@ -43,11 +42,11 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(16) {
DrawEngineCommon::~DrawEngineCommon() {
FreeMemoryPages(transformed, TRANSFORMED_VERTEX_BUFFER_SIZE);
FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
delete[] quadIndices_;
delete decJitCache_;
decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) {
delete decoder;
});
ClearSplineBezierWeights();
}

VertexDecoder *DrawEngineCommon::GetVertexDecoder(u32 vtype) {
Expand Down Expand Up @@ -739,3 +738,25 @@ void DrawEngineCommon::SubmitPrim(void *verts, void *inds, GEPrimitiveType prim,
}
}
}

void TessellationDataTransfer::CopyControlPoints(float *pos, float *tex, float *col, int posStride, int texStride, int colStride, const SimpleVertex *const *points, int size, u32 vertType) {
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
bool hasTexCoord = (vertType & GE_VTYPE_TC_MASK) != 0;

for (int i = 0; i < size; ++i) {
memcpy(pos, points[i]->pos.AsArray(), 3 * sizeof(float));
pos += posStride;
}
if (hasTexCoord) {
for (int i = 0; i < size; ++i) {
memcpy(tex, points[i]->uv, 2 * sizeof(float));
tex += texStride;
}
}
if (hasColor) {
for (int i = 0; i < size; ++i) {
memcpy(col, Vec4f::FromRGBA(points[i]->color_32).AsArray(), 4 * sizeof(float));
col += colStride;
}
}
}
32 changes: 10 additions & 22 deletions GPU/Common/DrawEngineCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum {
VERTEX_BUFFER_MAX = 65536,
DECODED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 64,
DECODED_INDEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 16,
SPLINE_BUFFER_SIZE = VERTEX_BUFFER_MAX * 26, // At least, this buffer needs greater than 1679616 bytes for Mist Dragon morphing in FF4CC.
};

// Avoiding the full include of TextureDecoder.h.
Expand All @@ -50,6 +49,15 @@ inline uint32_t GetVertTypeID(uint32_t vertType, int uvGenMode) {
return (vertType & 0xFFFFFF) | (uvGenMode << 24);
}

struct SimpleVertex;
namespace Spline { struct Weight2D; }

class TessellationDataTransfer {
public:
void CopyControlPoints(float *pos, float *tex, float *col, int posStride, int texStride, int colStride, const SimpleVertex *const *points, int size, u32 vertType);
virtual void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) = 0;
};

class DrawEngineCommon {
public:
DrawEngineCommon();
Expand All @@ -75,6 +83,7 @@ class DrawEngineCommon {
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead);
void SubmitSpline(const void *control_points, const void *indices, int tess_u, int tess_v, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, bool computeNormals, bool patchFacing, u32 vertType, int *bytesRead);
void SubmitBezier(const void *control_points, const void *indices, int tess_u, int tess_v, int count_u, int count_v, GEPatchPrimType prim_type, bool computeNormals, bool patchFacing, u32 vertType, int *bytesRead);
void ClearSplineBezierWeights();

std::vector<std::string> DebugGetVertexLoaderIDs();
std::string DebugGetVertexLoaderString(std::string id, DebugShaderStringType stringType);
Expand Down Expand Up @@ -160,31 +169,10 @@ class DrawEngineCommon {
int decodedVerts_ = 0;
GEPrimitiveType prevPrim_ = GE_PRIM_INVALID;

// Fixed index buffer for easy quad generation from spline/bezier
u16 *quadIndices_ = nullptr;

// Shader blending state
bool fboTexNeedBind_ = false;
bool fboTexBound_ = false;

// Hardware tessellation
int numPatches;
class TessellationDataTransfer {
protected:
// TODO: These aren't used by all backends.
int prevSize;
int prevSizeTex;
int prevSizeCol;
public:
virtual ~TessellationDataTransfer() {}
// Send spline/bezier's control points to vertex shader through floating point texture.
virtual void PrepareBuffers(float *&pos, float *&tex, float *&col, int &posStride, int &texStride, int &colStride, int size, bool hasColor, bool hasTexCoords) {
posStride = 4;
texStride = 4;
colStride = 4;
}
virtual void SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) = 0;
virtual void EndFrame() {}
};
TessellationDataTransfer *tessDataTransfer;
};
3 changes: 3 additions & 0 deletions GPU/Common/ShaderId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ std::string VertexShaderDesc(const ShaderID &id) {
if (id.Bit(VS_BIT_SPLINE)) desc << "Spline ";
if (id.Bit(VS_BIT_HAS_COLOR_TESS)) desc << "TessC ";
if (id.Bit(VS_BIT_HAS_TEXCOORD_TESS)) desc << "TessT ";
if (id.Bit(VS_BIT_HAS_NORMAL_TESS)) desc << "TessN ";
if (id.Bit(VS_BIT_NORM_REVERSE_TESS)) desc << "TessRevN ";

return desc.str();
Expand All @@ -73,6 +74,7 @@ void ComputeVertexShaderID(ShaderID *id_out, u32 vertType, bool useHWTransform)
bool doSpline = gstate_c.spline;
bool hasColorTess = (gstate.vertType & GE_VTYPE_COL_MASK) != 0 && (doBezier || doSpline);
bool hasTexcoordTess = (gstate.vertType & GE_VTYPE_TC_MASK) != 0 && (doBezier || doSpline);
bool hasNormalTess = (gstate.vertType & GE_VTYPE_NRM_MASK) != 0 && (doBezier || doSpline);

bool enableFog = gstate.isFogEnabled() && !isModeThrough && !gstate.isModeClear();
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled() && !isModeThrough;
Expand Down Expand Up @@ -139,6 +141,7 @@ void ComputeVertexShaderID(ShaderID *id_out, u32 vertType, bool useHWTransform)
id.SetBit(VS_BIT_SPLINE, doSpline);
id.SetBit(VS_BIT_HAS_COLOR_TESS, hasColorTess);
id.SetBit(VS_BIT_HAS_TEXCOORD_TESS, hasTexcoordTess);
id.SetBit(VS_BIT_HAS_NORMAL_TESS, hasNormalTess);
id.SetBit(VS_BIT_NORM_REVERSE_TESS, gstate.isPatchNormalsReversed());
}
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/ShaderId.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum {
VS_BIT_HAS_COLOR_TESS = 12, // 1 bit
VS_BIT_HAS_TEXCOORD_TESS = 13, // 1 bit
VS_BIT_NORM_REVERSE_TESS = 14, // 1 bit
// 15 is free.
VS_BIT_HAS_NORMAL_TESS = 15, // 1 bit
VS_BIT_UVGEN_MODE = 16,
VS_BIT_UVPROJ_MODE = 18, // 2, can overlap with LS0
VS_BIT_LS0 = 18, // 2
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
}

if (dirtyUniforms & DIRTY_BEZIERSPLINE) {
ub->spline_counts = BytesToUint32(gstate_c.spline_count_u, gstate_c.spline_count_v, gstate_c.spline_type_u, gstate_c.spline_type_v);
ub->spline_counts = gstate_c.spline_num_points_u;
}

if (dirtyUniforms & DIRTY_DEPAL) {
Expand Down
Loading