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++; uint8_t *map = &NormalLight.Maps[6 * 256];
dest = ylookup[_yl] + _x + _destorg; uint8_t *dest = thread->dest_for_thread(yl, _pitch, ylookup[yl] + _x + _destorg);
// colormap #6 is used for shading (of 0-31, a bit brighter than average) 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)
{ {
// [RH] Make local copies of global vars to try and improve uint8_t *srcdest = dest + fuzzoffset[fuzz] * fuzzstep + pitch;
// the optimizations made by the compiler. //assert(static_cast<int>((srcdest - (uint8_t*)dc_destorg) / (_pitch)) < viewheight);
int pitch = _pitch;
int fuzz = fuzzpos;
int cnt;
uint8_t *map = &NormalLight.Maps[6 * 256];
// [RH] Split this into three separate loops to minimize *dest = map[*srcdest];
// the number of times fuzzpos needs to be clamped. dest += pitch;
if (fuzz) 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;
do
{ {
cnt = MIN(FUZZTABLE - fuzz, count); uint8_t *srcdest = dest + fuzzoffset[fuzz] * fuzzstep;
count -= cnt; //assert(static_cast<int>((srcdest - (uint8_t*)dc_destorg) / (_pitch)) < viewheight);
do
{ *dest = map[*srcdest];
*dest = map[dest[fuzzoffset[fuzz++]]]; dest += pitch;
dest += pitch; fuzz += fuzzstep;
} while (--cnt); } while (--cnt);
}
if (fuzz == FUZZTABLE || count > 0) fuzz %= FUZZTABLE;
{ }
while (count >= FUZZTABLE)
{ // Handle the case where we would go out of bounds at the bottom
fuzz = 0; if (lowerbounds)
cnt = FUZZTABLE; {
count -= FUZZTABLE; uint8_t *srcdest = dest + fuzzoffset[fuzz] * fuzzstep - pitch;
do //assert(static_cast<int>((srcdest - (uint8_t*)dc_destorg) / (_pitch)) < viewheight);
{
*dest = map[dest[fuzzoffset[fuzz++]]]; *dest = map[*srcdest];
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