Skip to content

Commit

Permalink
Help the compiler out a little bit in IndexGenerator::AddStrip.
Browse files Browse the repository at this point in the history
The generated code wasn't good - this helps break long register
dependency chains.

Speed boost is measurable but small on x86, but might be bigger on simpler CPUs.
  • Loading branch information
hrydgard committed Sep 16, 2020
1 parent ce46adb commit c1194dc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions GPU/Common/IndexGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,22 @@ void IndexGenerator::AddStrip(int numVerts, bool clockwise) {
const int numTris = numVerts - 2;
u16 *outInds = inds_;
int ibase = index_;
for (int i = 0; i < numTris; i++) {
size_t numPairs = numTris / 2;
while (numPairs > 0) {
*outInds++ = ibase;
*outInds++ = ibase + wind;
*outInds++ = ibase + (wind ^ 3);
*outInds++ = ibase + 1;
*outInds++ = ibase + 1 + (wind ^ 3);
*outInds++ = ibase + 1 + wind;
ibase += 2;
numPairs--;
}
if (numTris & 1) {
*outInds++ = ibase;
*outInds++ = ibase + wind;
wind ^= 3; // toggle between 1 and 2
*outInds++ = ibase + wind;
ibase++;
}
inds_ = outInds;
index_ += numVerts;
Expand Down

0 comments on commit c1194dc

Please sign in to comment.