diff options
| author | Matthew Parlane <parlane@gmail.com> | 2013-04-12 17:11:32 +1200 |
|---|---|---|
| committer | Matthew Parlane <parlane@gmail.com> | 2013-04-12 17:11:32 +1200 |
| commit | d5ef9f3e85e411e1dcad0fc1c77091ce7fc3501a (patch) | |
| tree | 6b4d74d784f9f5d7bfbb7ec7a3db04c0e49814c6 /Source/Core/VideoCommon | |
| parent | 2c51b34f3c65e1fdd8200b37deca68253308164e (diff) | |
| parent | 2c722bb04fa95143894a937577237dd1586b8dbe (diff) | |
Merge branch 'master' into wii-network
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/Src/IndexGenerator.cpp | 196 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/IndexGenerator.h | 11 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexLoader.cpp | 4 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexManagerBase.cpp | 70 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VideoConfig.h | 1 |
5 files changed, 203 insertions, 79 deletions
diff --git a/Source/Core/VideoCommon/Src/IndexGenerator.cpp b/Source/Core/VideoCommon/Src/IndexGenerator.cpp index aa1a971687..28c62193c2 100644 --- a/Source/Core/VideoCommon/Src/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/Src/IndexGenerator.cpp @@ -18,17 +18,9 @@ #include <cstddef> #include "Common.h" +#include "VideoConfig.h" #include "IndexGenerator.h" -/* -* -QUAD simulator - -0 1 4 5 -3 2 7 6 -012023 147172 ... -*/ - //Init u16 *IndexGenerator::Tptr; u16 *IndexGenerator::BASETptr; @@ -41,6 +33,32 @@ u32 IndexGenerator::numL; u32 IndexGenerator::numP; u32 IndexGenerator::index; +static const u16 s_primitive_restart = -1; + +static void (*primitive_table[8])(u32); + +void IndexGenerator::Init() +{ + if(g_Config.backend_info.bSupportsPrimitiveRestart) + { + primitive_table[0] = IndexGenerator::AddQuads<true>; + primitive_table[2] = IndexGenerator::AddList<true>; + primitive_table[3] = IndexGenerator::AddStrip<true>; + primitive_table[4] = IndexGenerator::AddFan<true>; + } + else + { + primitive_table[0] = IndexGenerator::AddQuads<false>; + primitive_table[2] = IndexGenerator::AddList<false>; + primitive_table[3] = IndexGenerator::AddStrip<false>; + primitive_table[4] = IndexGenerator::AddFan<false>; + } + primitive_table[1] = NULL; + primitive_table[5] = &IndexGenerator::AddLineList; + primitive_table[6] = &IndexGenerator::AddLineStrip; + primitive_table[7] = &IndexGenerator::AddPoints; +} + void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr) { Tptr = Triangleptr; @@ -57,82 +75,150 @@ void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr) void IndexGenerator::AddIndices(int primitive, u32 numVerts) { - //switch (primitive) - //{ - //case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVerts); break; - //case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVerts); break; - //case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVerts); break; - //case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVerts); break; - //case GX_DRAW_LINES: IndexGenerator::AddLineList(numVerts); break; - //case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVerts); break; - //case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVerts); break; - //} - - static void (*const primitive_table[])(u32) = - { - IndexGenerator::AddQuads, - NULL, - IndexGenerator::AddList, - IndexGenerator::AddStrip, - IndexGenerator::AddFan, - IndexGenerator::AddLineList, - IndexGenerator::AddLineStrip, - IndexGenerator::AddPoints, - }; - primitive_table[primitive](numVerts); index += numVerts; } // Triangles -__forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3) +template <bool pr> __forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3) { *Tptr++ = index1; *Tptr++ = index2; *Tptr++ = index3; - + if(pr) + *Tptr++ = s_primitive_restart; + ++numT; } -void IndexGenerator::AddList(u32 const numVerts) +template <bool pr> void IndexGenerator::AddList(u32 const numVerts) { auto const numTris = numVerts / 3; for (u32 i = 0; i != numTris; ++i) { - WriteTriangle(index + i * 3, index + i * 3 + 1, index + i * 3 + 2); + WriteTriangle<pr>(index + i * 3, index + i * 3 + 1, index + i * 3 + 2); } + u32 remainingVerts = numVerts - numTris*3; + if(remainingVerts) + ERROR_LOG(VIDEO, "AddList: unknown count of vertices found"); } -void IndexGenerator::AddStrip(u32 const numVerts) +template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts) { - bool wind = false; - for (u32 i = 2; i < numVerts; ++i) - { - WriteTriangle( - index + i - 2, - index + i - !wind, - index + i - wind); + if(pr) { + for (u32 i = 0; i < numVerts; ++i) + { + *Tptr++ = index + i; + } + *Tptr++ = s_primitive_restart; + numT += numVerts - 2; + + } else { + bool wind = false; + for (u32 i = 2; i < numVerts; ++i) + { + WriteTriangle<pr>( + index + i - 2, + index + i - !wind, + index + i - wind); - wind ^= true; + wind ^= true; + } } } -void IndexGenerator::AddFan(u32 numVerts) +/** + * FAN simulator: + * + * 2---3 + * / \ / \ + * 1---0---4 + * + * would generate this triangles: + * 012, 023, 034 + * + * rotated (for better striping): + * 120, 302, 034 + * + * as odd ones have to winded, following strip is fine: + * 12034 + * + * so we use 6 indices for 3 triangles + */ + +template <bool pr> void IndexGenerator::AddFan(u32 numVerts) { - for (u32 i = 2; i < numVerts; ++i) + u32 i = 2; + + if(pr) { + for(; i<=numVerts-3; i+=3) { + *Tptr++ = index + i - 1; + *Tptr++ = index + i + 0; + *Tptr++ = index; + *Tptr++ = index + i + 1; + *Tptr++ = index + i + 2; + *Tptr++ = s_primitive_restart; + numT += 3; + } + + for(; i<=numVerts-2; i+=2) { + *Tptr++ = index + i - 1; + *Tptr++ = index + i + 0; + *Tptr++ = index; + *Tptr++ = index + i + 1; + *Tptr++ = s_primitive_restart; + numT += 2; + } + } + + for (; i < numVerts; ++i) { - WriteTriangle(index, index + i - 1, index + i); + WriteTriangle<pr>(index, index + i - 1, index + i); } } -void IndexGenerator::AddQuads(u32 numVerts) +/* + * QUAD simulator + * + * 0---1 4---5 + * |\ | |\ | + * | \ | | \ | + * | \| | \| + * 3---2 7---6 + * + * 012,023, 456,467 ... + * or 120,302, 564,746 + * or as strip: 1203, 5647 + * + * Warning: + * A simple triangle has to be rendered for three vertices. + * ZWW do this for sun rays + */ +template <bool pr> void IndexGenerator::AddQuads(u32 numVerts) { auto const numQuads = numVerts / 4; for (u32 i = 0; i != numQuads; ++i) { - WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2); - WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3); + if(pr) { + *Tptr++ = index + i * 4 + 1; + *Tptr++ = index + i * 4 + 2; + *Tptr++ = index + i * 4 + 0; + *Tptr++ = index + i * 4 + 3; + *Tptr++ = s_primitive_restart; + numT += 2; + } else { + WriteTriangle<pr>(index + i * 4, index + i * 4 + 1, index + i * 4 + 2); + WriteTriangle<pr>(index + i * 4, index + i * 4 + 2, index + i * 4 + 3); + } + } + // three vertices remaining, so render a triangle + u32 remainingVerts = numVerts - numQuads*4; + if(remainingVerts == 3) + { + WriteTriangle<pr>(index+numVerts-3, index+numVerts-2, index+numVerts-1); } + else if(remainingVerts) + ERROR_LOG(VIDEO, "AddQuads: unknown count of vertices found"); } // Lines @@ -145,8 +231,14 @@ void IndexGenerator::AddLineList(u32 numVerts) *Lptr++ = index + i * 2 + 1; ++numL; } + u32 remainingVerts = numVerts - numLines*2; + if(remainingVerts) + ERROR_LOG(VIDEO, "AddLineList: unknown count of vertices found"); + } +// shouldn't be used as strips as LineLists are much more common +// so converting them to lists void IndexGenerator::AddLineStrip(u32 numVerts) { for (u32 i = 1; i < numVerts; ++i) @@ -170,6 +262,6 @@ void IndexGenerator::AddPoints(u32 numVerts) u32 IndexGenerator::GetRemainingIndices() { - u32 max_index = 65535; + u32 max_index = 65534; // -1 is reserved for primitive restart (ogl + dx11) return max_index - index; } diff --git a/Source/Core/VideoCommon/Src/IndexGenerator.h b/Source/Core/VideoCommon/Src/IndexGenerator.h index f14d3ae026..421c0aa4a8 100644 --- a/Source/Core/VideoCommon/Src/IndexGenerator.h +++ b/Source/Core/VideoCommon/Src/IndexGenerator.h @@ -26,6 +26,7 @@ class IndexGenerator { public: // Init + static void Init(); static void Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr); static void AddIndices(int primitive, u32 numVertices); @@ -54,10 +55,10 @@ public: */ private: // Triangles - static void AddList(u32 numVerts); - static void AddStrip(u32 numVerts); - static void AddFan(u32 numVerts); - static void AddQuads(u32 numVerts); + template <bool pr> static void AddList(u32 numVerts); + template <bool pr> static void AddStrip(u32 numVerts); + template <bool pr> static void AddFan(u32 numVerts); + template <bool pr> static void AddQuads(u32 numVerts); // Lines static void AddLineList(u32 numVerts); @@ -66,7 +67,7 @@ private: // Points static void AddPoints(u32 numVerts); - static void WriteTriangle(u32 index1, u32 index2, u32 index3); + template <bool pr> static void WriteTriangle(u32 index1, u32 index2, u32 index3); static u16 *Tptr; static u16 *BASETptr; diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index d1e8b14e8a..f27271efe6 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -659,6 +659,10 @@ void VertexLoader::SetVAT(u32 _group0, u32 _group1, u32 _group2) m_VtxAttr.texCoord[7].Elements = vat.g2.Tex7CoordElements; m_VtxAttr.texCoord[7].Format = vat.g2.Tex7CoordFormat; m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac; + + if(!m_VtxAttr.ByteDequant) { + ERROR_LOG(VIDEO, "ByteDequant is set to zero"); + } }; void VertexLoader::AppendToString(std::string *dest) const diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp index 3e2e88c55f..567621964f 100644 --- a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp @@ -74,28 +74,54 @@ bool VertexManager::IsFlushed() const u32 VertexManager::GetRemainingIndices(int primitive) { - switch (primitive) - { - case GX_DRAW_QUADS: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4; - case GX_DRAW_TRIANGLES: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()); - case GX_DRAW_TRIANGLE_STRIP: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; - case GX_DRAW_TRIANGLE_FAN: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; - - case GX_DRAW_LINES: - return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); - case GX_DRAW_LINE_STRIP: - return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; - - case GX_DRAW_POINTS: - return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); - - default: - return 0; - } + + if(g_Config.backend_info.bSupportsPrimitiveRestart) { + switch (primitive) + { + case GX_DRAW_QUADS: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 5 * 4; + case GX_DRAW_TRIANGLES: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 4 * 3; + case GX_DRAW_TRIANGLE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 1 - 1; + case GX_DRAW_TRIANGLE_FAN: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4 + 1; + + case GX_DRAW_LINES: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); + case GX_DRAW_LINE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; + + case GX_DRAW_POINTS: + return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); + + default: + return 0; + } + } else { + switch (primitive) + { + case GX_DRAW_QUADS: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4; + case GX_DRAW_TRIANGLES: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()); + case GX_DRAW_TRIANGLE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; + case GX_DRAW_TRIANGLE_FAN: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; + + case GX_DRAW_LINES: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); + case GX_DRAW_LINE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; + + case GX_DRAW_POINTS: + return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); + + default: + return 0; + } + } } void VertexManager::AddVertices(int primitive, u32 numVertices) diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h index 1670e47222..f282a3edeb 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.h +++ b/Source/Core/VideoCommon/Src/VideoConfig.h @@ -165,6 +165,7 @@ struct VideoConfig bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL bool bSupportsFormatReinterpretation; bool bSupportsPixelLighting; + bool bSupportsPrimitiveRestart; bool bSupportsSeparateAlphaFunction; bool bSupportsGLSLUBO; // needed by pixelShaderGen, so must stay in videoCommon } backend_info; |
