SetGate() rescheduled the sysclk event without updating the counters
first when the gated timer was GPU-clocked, so the next IRQ got pushed
back by however long it had been since the last update. Gate changes
that were more frequent than the IRQ stopped it from firing at all.
The PixelVectors/TriangleVectors constructors were the only vector
helpers left to the compiler's discretion. Clang already outlines the
textured ones at -Os, which forces every field through memory.
- The base of the texture page is ORed in with the texture window for
Y, since the result always fits in VRAM, the mask did nothing. Same
for the X mask with 4-bit textures.
- Green only needs a single shift to end up in the high word.
- blend8() is used to select between the new and existing pixels.
- Bit 15 is not set before blending for textured pixels, as they are
only blended when it is already set. It was also being set before
shifting it out again for quarter foreground blending.
Semi-transparent primitives are around 5-10% faster, the rest is
within noise.
Every copy with the destination to the right of the source was taking
the reverse path, which is not vectorized. Since rows are always copied
from top to bottom, the direction within a row only matters when the
source and destination overlap within the same row, so everything else
can use the forward path.
A 320x240 copy to the right goes from 40us to 2.4us.
Bit 15 is passed through from the texture as-is, so there is no need
to unpack it, carry it through modulation, and pack it again. That
leaves the high half of BA as zero, which along with the components
already being clamped means most of the masking when packing can go.
For modulation, the dither is shifted up to line up with the colour
instead of shifting the colour down before adding it, so only one
shift is needed afterwards: ((x >> 4) + d) >> 3 == (x + (d << 4)) >> 7.
Around 3-15% faster for modulated textures.
Spans are clipped to the drawing area before the loop, so the test for
each vector never masked any additional pixels, and since the loop only
runs for as many vectors as the span covers, there was never a vector
with nothing to draw either.
Around 4-17% faster for triangles, depending on size.
Texture coordinates increase by one for each pixel of a sprite, so
unless the texture window is rearranging them, the texels for each
vector are next to each other in VRAM, and can be loaded together
instead of being gathered one at a time.
16-bit textures turn into a single load, and 4-bit textures a single
load followed by the palette shuffle. 8-bit indices still have to be
looked up individually, so those keep using the gather.
Sampling is split out of ShadePixel() so that it can be skipped.
Around 25% faster for 16-bit sprites and 20-45% faster for 4-bit
sprites. Small 8-bit sprites are up to 10% slower because of the extra
check for each vector.
The CLUT only has 16 entries in 4-bit mode, so split into low and high
bytes it fits in a pair of registers, and can be looked up with a byte
shuffle, instead of extracting each index and loading the colour from
memory.
Without variable shifts, the index is moved to the top of the word by
multiplying, which replaces the scalar shifts as well.
Around 5-20% faster for 4-bit textured primitives.
Each index is exactly one byte, so it can be read straight out of VRAM
and used to index the CLUT. Previously, the word containing the index
was gathered into a vector, then extracted again along with the shift
to get at the index, which without variable shifts (i.e. SSE4) meant
12 extracts and 4 scalar shifts for every 4 pixels.
Around 13-25% faster for small/medium 8-bit textured triangles, and
40-65% faster for large triangles and sprites.
Rectangles and axis-aligned quads are compared against a simple
per-pixel version of the pixel pipeline, clipped triangles against
the same triangle drawn without clipping, and VRAM copies against a
row-by-row copy.
The step is a fixed-point value which is expected to wrap around when
multiplied by the coordinate, but the multiplication was signed, which
makes the overflow undefined behaviour.
Multiply as unsigned instead, the result is the same.
The scalar loop only advanced the source pointer when the destination
pixel was not masked, so every pixel after a masked one was written
with the wrong source data for the rest of the transfer.
The vectorized loop always advances, so this only affected the trailing
pixels of each row, writes which wrap around, and the scalar
implementation.
I've done this to avoid disturbing any existing strings with the machine
translation pipeline, but also to avoid translating all the new Android
strings...