diff options
| author | degasus <wickmarkus@web.de> | 2014-01-16 14:30:17 +0100 |
|---|---|---|
| committer | degasus <wickmarkus@web.de> | 2014-01-17 16:34:53 +0100 |
| commit | 304adc6e0ddef6411739d0fb577a63108a362c6a (patch) | |
| tree | f6f54f75fe8a676933b7af48f2de0af1e7b6e115 /Source/Core/VideoCommon/IndexGenerator.cpp | |
| parent | 1d6425bd5e580c396cc8f25f14207a4e97e92572 (diff) | |
IndexGenerator: inline all variables
As we do lots of writes to *Iptr, the compiler isn't allowed to cache any shared variable (neither index nor Iptr itself).
This commit inlines Iptr + index into the index generator functions, so the compiler know that they are const.
Diffstat (limited to 'Source/Core/VideoCommon/IndexGenerator.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/IndexGenerator.cpp | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/Source/Core/VideoCommon/IndexGenerator.cpp b/Source/Core/VideoCommon/IndexGenerator.cpp index 884db29aee..0789ec1e1a 100644 --- a/Source/Core/VideoCommon/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/IndexGenerator.cpp @@ -9,13 +9,13 @@ #include "IndexGenerator.h" //Init -u16 *IndexGenerator::Iptr; +u16 *IndexGenerator::index_buffer_current; u16 *IndexGenerator::BASEIptr; -u32 IndexGenerator::index; +u32 IndexGenerator::base_index; static const u16 s_primitive_restart = -1; -static void (*primitive_table[8])(u32); +static u16* (*primitive_table[8])(u16*, u32, u32); void IndexGenerator::Init() { @@ -41,36 +41,38 @@ void IndexGenerator::Init() void IndexGenerator::Start(u16* Indexptr) { - Iptr = Indexptr; + index_buffer_current = Indexptr; BASEIptr = Indexptr; - index = 0; + base_index = 0; } void IndexGenerator::AddIndices(int primitive, u32 numVerts) { - primitive_table[primitive](numVerts); - index += numVerts; + index_buffer_current = primitive_table[primitive](index_buffer_current, numVerts, base_index); + base_index += numVerts; } // Triangles -template <bool pr> __forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3) +template <bool pr> __forceinline u16* IndexGenerator::WriteTriangle(u16 *Iptr, u32 index1, u32 index2, u32 index3) { *Iptr++ = index1; *Iptr++ = index2; *Iptr++ = index3; if(pr) *Iptr++ = s_primitive_restart; + return Iptr; } -template <bool pr> void IndexGenerator::AddList(u32 const numVerts) +template <bool pr> u16* IndexGenerator::AddList(u16 *Iptr, u32 const numVerts, u32 index) { for (u32 i = 2; i < numVerts; i+=3) { - WriteTriangle<pr>(index + i - 2, index + i - 1, index + i); + Iptr = WriteTriangle<pr>(Iptr, index + i - 2, index + i - 1, index + i); } + return Iptr; } -template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts) +template <bool pr> u16* IndexGenerator::AddStrip(u16 *Iptr, u32 const numVerts, u32 index) { if(pr) { @@ -86,7 +88,7 @@ template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts) bool wind = false; for (u32 i = 2; i < numVerts; ++i) { - WriteTriangle<pr>( + Iptr = WriteTriangle<pr>(Iptr, index + i - 2, index + i - !wind, index + i - wind); @@ -94,6 +96,7 @@ template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts) wind ^= true; } } + return Iptr; } /** @@ -115,7 +118,7 @@ template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts) * so we use 6 indices for 3 triangles */ -template <bool pr> void IndexGenerator::AddFan(u32 numVerts) +template <bool pr> u16* IndexGenerator::AddFan(u16 *Iptr, u32 numVerts, u32 index) { u32 i = 2; @@ -143,8 +146,9 @@ template <bool pr> void IndexGenerator::AddFan(u32 numVerts) for (; i < numVerts; ++i) { - WriteTriangle<pr>(index, index + i - 1, index + i); + Iptr = WriteTriangle<pr>(Iptr, index, index + i - 1, index + i); } + return Iptr; } /* @@ -164,7 +168,7 @@ template <bool pr> void IndexGenerator::AddFan(u32 numVerts) * A simple triangle has to be rendered for three vertices. * ZWW do this for sun rays */ -template <bool pr> void IndexGenerator::AddQuads(u32 numVerts) +template <bool pr> u16* IndexGenerator::AddQuads(u16 *Iptr, u32 numVerts, u32 index) { u32 i = 3; for (; i < numVerts; i+=4) @@ -179,52 +183,56 @@ template <bool pr> void IndexGenerator::AddQuads(u32 numVerts) } else { - WriteTriangle<pr>(index + i - 3, index + i - 2, index + i - 1); - WriteTriangle<pr>(index + i - 3, index + i - 1, index + i - 0); + Iptr = WriteTriangle<pr>(Iptr, index + i - 3, index + i - 2, index + i - 1); + Iptr = WriteTriangle<pr>(Iptr, index + i - 3, index + i - 1, index + i - 0); } } // three vertices remaining, so render a triangle if(i == numVerts) { - WriteTriangle<pr>(index+numVerts-3, index+numVerts-2, index+numVerts-1); + Iptr = WriteTriangle<pr>(Iptr, index+numVerts-3, index+numVerts-2, index+numVerts-1); } + return Iptr; } // Lines -void IndexGenerator::AddLineList(u32 numVerts) +u16* IndexGenerator::AddLineList(u16 *Iptr, u32 numVerts, u32 index) { for (u32 i = 1; i < numVerts; i+=2) { *Iptr++ = index + i - 1; *Iptr++ = index + i; } + return Iptr; } // shouldn't be used as strips as LineLists are much more common // so converting them to lists -void IndexGenerator::AddLineStrip(u32 numVerts) +u16* IndexGenerator::AddLineStrip(u16 *Iptr, u32 numVerts, u32 index) { for (u32 i = 1; i < numVerts; ++i) { *Iptr++ = index + i - 1; *Iptr++ = index + i; } + return Iptr; } // Points -void IndexGenerator::AddPoints(u32 numVerts) +u16* IndexGenerator::AddPoints(u16 *Iptr, u32 numVerts, u32 index) { for (u32 i = 0; i != numVerts; ++i) { *Iptr++ = index + i; } + return Iptr; } u32 IndexGenerator::GetRemainingIndices() { u32 max_index = 65534; // -1 is reserved for primitive restart (ogl + dx11) - return max_index - index; + return max_index - base_index; } |
