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.
This commit is contained in:
parent
1d6425bd5e
commit
304adc6e0d
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -19,31 +19,31 @@ public:
|
|||
static void AddIndices(int primitive, u32 numVertices);
|
||||
|
||||
// returns numprimitives
|
||||
static u32 GetNumVerts() {return index;}
|
||||
static u32 GetNumVerts() {return base_index;}
|
||||
|
||||
static u32 GetIndexLen() {return (u32)(Iptr - BASEIptr);}
|
||||
static u32 GetIndexLen() {return (u32)(index_buffer_current - BASEIptr);}
|
||||
|
||||
static u32 GetRemainingIndices();
|
||||
|
||||
private:
|
||||
// Triangles
|
||||
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);
|
||||
template <bool pr> static u16* AddList(u16 *Iptr, u32 numVerts, u32 index);
|
||||
template <bool pr> static u16* AddStrip(u16 *Iptr, u32 numVerts, u32 index);
|
||||
template <bool pr> static u16* AddFan(u16 *Iptr, u32 numVerts, u32 index);
|
||||
template <bool pr> static u16* AddQuads(u16 *Iptr, u32 numVerts, u32 index);
|
||||
|
||||
// Lines
|
||||
static void AddLineList(u32 numVerts);
|
||||
static void AddLineStrip(u32 numVerts);
|
||||
static u16* AddLineList(u16 *Iptr, u32 numVerts, u32 index);
|
||||
static u16* AddLineStrip(u16 *Iptr, u32 numVerts, u32 index);
|
||||
|
||||
// Points
|
||||
static void AddPoints(u32 numVerts);
|
||||
static u16* AddPoints(u16 *Iptr, u32 numVerts, u32 index);
|
||||
|
||||
template <bool pr> static void WriteTriangle(u32 index1, u32 index2, u32 index3);
|
||||
template <bool pr> static u16* WriteTriangle(u16 *Iptr, u32 index1, u32 index2, u32 index3);
|
||||
|
||||
static u16 *Iptr;
|
||||
static u16 *index_buffer_current;
|
||||
static u16 *BASEIptr;
|
||||
static u32 index;
|
||||
static u32 base_index;
|
||||
};
|
||||
|
||||
#endif // _INDEXGENERATOR_H
|
||||
|
|
Loading…
Reference in New Issue