Make puzzy pinky fuzzywuzzy about threads

This commit is contained in:
Magnus Norddahl 2016-12-06 15:29:04 +01:00
parent c16506bf59
commit 6054db0d86
2 changed files with 63 additions and 56 deletions

View file

@ -1733,76 +1733,81 @@ namespace swrenderer
_x = dc_x; _x = dc_x;
_destorg = dc_destorg; _destorg = dc_destorg;
_pitch = dc_pitch; _pitch = dc_pitch;
_fuzzpos = fuzzpos;
_fuzzviewheight = fuzzviewheight;
} }
void DrawFuzzColumnPalCommand::Execute(DrawerThread *thread) void DrawFuzzColumnPalCommand::Execute(DrawerThread *thread)
{ {
int count; int yl = MAX(_yl, 1);
uint8_t *dest; int yh = MIN(_yh, _fuzzviewheight);
// Adjust borders. Low... int count = thread->count_for_thread(yl, yh - yl + 1);
if (_yl == 0)
_yl = 1;
// .. and high.
if (_yh > fuzzviewheight)
_yh = fuzzviewheight;
count = _yh - _yl;
// Zero length. // Zero length.
if (count < 0) if (count <= 0)
return; return;
count++;
dest = ylookup[_yl] + _x + _destorg;
// colormap #6 is used for shading (of 0-31, a bit brighter than average)
{
// [RH] Make local copies of global vars to try and improve
// the optimizations made by the compiler.
int pitch = _pitch;
int fuzz = fuzzpos;
int cnt;
uint8_t *map = &NormalLight.Maps[6 * 256]; uint8_t *map = &NormalLight.Maps[6 * 256];
// [RH] Split this into three separate loops to minimize uint8_t *dest = thread->dest_for_thread(yl, _pitch, ylookup[yl] + _x + _destorg);
// the number of times fuzzpos needs to be clamped.
if (fuzz) int pitch = _pitch * thread->num_cores;
int fuzzstep = thread->num_cores;
int fuzz = (_fuzzpos + thread->skipped_by_thread(yl)) % FUZZTABLE;
yl += thread->skipped_by_thread(yl);
// Handle the case where we would go out of bounds at the top:
if (yl < fuzzstep)
{ {
cnt = MIN(FUZZTABLE - fuzz, count); uint8_t *srcdest = dest + fuzzoffset[fuzz] * fuzzstep + pitch;
//assert(static_cast<int>((srcdest - (uint8_t*)dc_destorg) / (_pitch)) < viewheight);
*dest = map[*srcdest];
dest += pitch;
fuzz += fuzzstep;
fuzz %= FUZZTABLE;
count--;
if (count == 0)
return;
}
bool lowerbounds = (yl + (count + fuzzstep - 1) * fuzzstep > _fuzzviewheight);
if (lowerbounds)
count--;
// Fuzz where fuzzoffset stays within bounds
while (count > 0)
{
int available = (FUZZTABLE - fuzz);
int next_wrap = available / fuzzstep;
if (available % fuzzstep != 0)
next_wrap++;
int cnt = MIN(count, next_wrap);
count -= cnt; count -= cnt;
do do
{ {
*dest = map[dest[fuzzoffset[fuzz++]]]; uint8_t *srcdest = dest + fuzzoffset[fuzz] * fuzzstep;
//assert(static_cast<int>((srcdest - (uint8_t*)dc_destorg) / (_pitch)) < viewheight);
*dest = map[*srcdest];
dest += pitch; dest += pitch;
fuzz += fuzzstep;
} while (--cnt); } while (--cnt);
fuzz %= FUZZTABLE;
} }
if (fuzz == FUZZTABLE || count > 0)
// Handle the case where we would go out of bounds at the bottom
if (lowerbounds)
{ {
while (count >= FUZZTABLE) uint8_t *srcdest = dest + fuzzoffset[fuzz] * fuzzstep - pitch;
{ //assert(static_cast<int>((srcdest - (uint8_t*)dc_destorg) / (_pitch)) < viewheight);
fuzz = 0;
cnt = FUZZTABLE; *dest = map[*srcdest];
count -= FUZZTABLE;
do
{
*dest = map[dest[fuzzoffset[fuzz++]]];
dest += pitch;
} while (--cnt);
}
fuzz = 0;
if (count > 0)
{
do
{
*dest = map[dest[fuzzoffset[fuzz++]]];
dest += pitch;
} while (--count);
}
}
fuzzpos = fuzz;
} }
} }

View file

@ -138,6 +138,8 @@ namespace swrenderer
int _x; int _x;
uint8_t *_destorg; uint8_t *_destorg;
int _pitch; int _pitch;
int _fuzzpos;
int _fuzzviewheight;
}; };
class PalSpanCommand : public DrawerCommand class PalSpanCommand : public DrawerCommand