Hooked up LLVM wall drawers

This commit is contained in:
Magnus Norddahl 2016-09-30 07:27:25 +02:00
commit 28bb5da181
9 changed files with 411 additions and 48 deletions

View file

@ -10,6 +10,31 @@
#include "r_compiler/ssa/ssa_struct_type.h"
#include "r_compiler/ssa/ssa_value.h"
SSABool DrawerCodegen::line_skipped_by_thread(SSAInt line, SSAWorkerThread thread)
{
return line < thread.pass_start_y || line >= thread.pass_end_y || !(line % thread.num_cores == thread.core);
}
SSAInt DrawerCodegen::skipped_by_thread(SSAInt first_line, SSAWorkerThread thread)
{
SSAInt pass_skip = SSAInt::MAX(thread.pass_start_y - first_line, 0);
SSAInt core_skip = (thread.num_cores - (first_line + pass_skip - thread.core) % thread.num_cores) % thread.num_cores;
return pass_skip + core_skip;
}
SSAInt DrawerCodegen::count_for_thread(SSAInt first_line, SSAInt count, SSAWorkerThread thread)
{
SSAInt lines_until_pass_end = SSAInt::MAX(thread.pass_end_y - first_line, 0);
count = SSAInt::MIN(count, lines_until_pass_end);
SSAInt c = (count - skipped_by_thread(first_line, thread) + thread.num_cores - 1) / thread.num_cores;
return SSAInt::MAX(c, 0);
}
SSAUBytePtr DrawerCodegen::dest_for_thread(SSAInt first_line, SSAInt pitch, SSAUBytePtr dest, SSAWorkerThread thread)
{
return dest[skipped_by_thread(first_line, thread) * pitch * 4];
}
SSAInt DrawerCodegen::calc_light_multiplier(SSAInt light)
{
return 256 - (light >> (FRACBITS - 8));
@ -105,8 +130,8 @@ SSAVec4i DrawerCodegen::sample_linear(SSAUBytePtr col0, SSAUBytePtr col1, SSAInt
SSAVec4i p11 = col1[y1 * 4].load_vec4ub();
SSAInt inv_b = texturefracx;
SSAInt inv_a = (frac_y1 >> (FRACBITS - 4)) & 15;
SSAInt a = 16 - inv_a;
SSAInt a = (frac_y1 >> (FRACBITS - 4)) & 15;
SSAInt inv_a = 16 - a;
SSAInt b = 16 - inv_b;
return (p00 * (a * b) + p01 * (inv_a * b) + p10 * (a * inv_b) + p11 * (inv_a * inv_b) + 127) >> 8;

View file

@ -18,6 +18,15 @@
#include "r_compiler/ssa/ssa_barycentric_weight.h"
#include "r_compiler/llvm_include.h"
class SSAWorkerThread
{
public:
SSAInt core;
SSAInt num_cores;
SSAInt pass_start_y;
SSAInt pass_end_y;
};
class SSAShadeConstants
{
public:
@ -29,6 +38,18 @@ public:
class DrawerCodegen
{
public:
// Checks if a line is rendered by this thread
SSABool line_skipped_by_thread(SSAInt line, SSAWorkerThread thread);
// The number of lines to skip to reach the first line to be rendered by this thread
SSAInt skipped_by_thread(SSAInt first_line, SSAWorkerThread thread);
// The number of lines to be rendered by this thread
SSAInt count_for_thread(SSAInt first_line, SSAInt count, SSAWorkerThread thread);
// Calculate the dest address for the first line to be rendered by this thread
SSAUBytePtr dest_for_thread(SSAInt first_line, SSAInt pitch, SSAUBytePtr dest, SSAWorkerThread thread);
// LightBgra
SSAInt calc_light_multiplier(SSAInt light);
SSAVec4i shade_pal_index_simple(SSAInt index, SSAInt light, SSAUBytePtr basecolors);

View file

@ -10,7 +10,7 @@
#include "r_compiler/ssa/ssa_struct_type.h"
#include "r_compiler/ssa/ssa_value.h"
void DrawWallCodegen::Generate(DrawWallVariant variant, bool fourColumns, SSAValue args)
void DrawWallCodegen::Generate(DrawWallVariant variant, bool fourColumns, SSAValue args, SSAValue thread_data)
{
dest = args[0][0].load();
source[0] = args[0][1].load();
@ -60,24 +60,24 @@ void DrawWallCodegen::Generate(DrawWallVariant variant, bool fourColumns, SSAVal
shade_constants.fade = SSAVec4i(fade_blue.zext_int(), fade_green.zext_int(), fade_red.zext_int(), fade_alpha.zext_int());
shade_constants.desaturate = desaturate.zext_int();
thread.core = thread_data[0][0].load();
thread.num_cores = thread_data[0][1].load();
thread.pass_start_y = thread_data[0][2].load();
thread.pass_end_y = thread_data[0][3].load();
is_simple_shade = (flags & DrawWallArgs::simple_shade) == DrawWallArgs::simple_shade;
is_nearest_filter = (flags & DrawWallArgs::nearest_filter) == DrawWallArgs::nearest_filter;
/*
count = thread->count_for_thread(command->_dest_y, command->_count);
fracstep = command->_iscale * thread->num_cores;
frac = command->_texturefrac + command->_iscale * thread->skipped_by_thread(command->_dest_y);
texturefracx = command->_texturefracx;
dest = thread->dest_for_thread(command->_dest_y, command->_pitch, (uint32_t*)command->_dest);
pitch = command->_pitch * thread->num_cores;
height = command->_textureheight;
one = ((0x80000000 + height - 1) / height) * 2 + 1;
*/
count = count_for_thread(dest_y, count, thread);
dest = dest_for_thread(dest_y, pitch, dest, thread);
pitch = pitch * thread.num_cores;
int numColumns = fourColumns ? 4 : 1;
for (int i = 0; i < numColumns; i++)
{
stack_frac[i].store(texturefrac[i] + iscale[i]);// * skipped_by_thread(dest_y);
fracstep[i] = iscale[i];// * num_cores;
stack_frac[i].store(texturefrac[i] + iscale[i] * skipped_by_thread(dest_y, thread));
fracstep[i] = iscale[i] * thread.num_cores;
one[i] = ((0x80000000 + textureheight[i] - 1) / textureheight[i]) * 2 + 1;
}
@ -113,16 +113,32 @@ void DrawWallCodegen::Loop(DrawWallVariant variant, bool fourColumns, bool isSim
for (int i = 0; i < numColumns; i++)
frac[i] = stack_frac[i].load();
SSAInt offset = (dest_y + index) * pitch * 4;
SSAInt offset = index * pitch * 4;
if (fourColumns)
{
SSAVec16ub bg = dest[offset].load_unaligned_vec16ub();
SSAVec8s bg0 = SSAVec8s::extendlo(bg);
SSAVec8s bg1 = SSAVec8s::extendhi(bg);
SSAVec4i bgcolors[4] =
{
SSAVec4i::extendlo(bg0),
SSAVec4i::extendhi(bg0),
SSAVec4i::extendlo(bg1),
SSAVec4i::extendhi(bg1)
};
SSAVec4i colors[4];
for (int i = 0; i < 4; i++)
colors[i] = Blend(Shade(Sample(frac[i], i, isNearestFilter), i, isSimpleShade), bgcolors[i], variant);
SSAVec16ub color(SSAVec8s(colors[0], colors[1]), SSAVec8s(colors[2], colors[3]));
dest[offset].store_unaligned_vec16ub(color);
}
else
{
SSAVec4i bgcolor = dest[offset].load_vec4ub();
SSAVec4i color = Blend(Shade(Sample(frac[0], isNearestFilter), 0, isSimpleShade), bgcolor, variant);
SSAVec4i color = Blend(Shade(Sample(frac[0], 0, isNearestFilter), 0, isSimpleShade), bgcolor, variant);
dest[offset].store_vec4ub(color);
}
@ -133,10 +149,17 @@ void DrawWallCodegen::Loop(DrawWallVariant variant, bool fourColumns, bool isSim
}
}
SSAVec4i DrawWallCodegen::Sample(SSAInt frac, bool isNearestFilter)
SSAVec4i DrawWallCodegen::Sample(SSAInt frac, int index, bool isNearestFilter)
{
// int sample_index() { return ((frac >> FRACBITS) * height) >> FRACBITS; }
return SSAVec4i(0);
if (isNearestFilter)
{
SSAInt sample_index = ((frac >> FRACBITS) * textureheight[index]) >> FRACBITS;
return source[index][sample_index * 4].load_vec4ub();
}
else
{
return sample_linear(source[index], source2[index], texturefracx[index], frac, one[index], textureheight[index]);
}
}
SSAVec4i DrawWallCodegen::Shade(SSAVec4i fg, int index, bool isSimpleShade)

View file

@ -16,12 +16,12 @@ enum class DrawWallVariant
class DrawWallCodegen : public DrawerCodegen
{
public:
void Generate(DrawWallVariant variant, bool fourColumns, SSAValue args);
void Generate(DrawWallVariant variant, bool fourColumns, SSAValue args, SSAValue thread_data);
private:
void LoopShade(DrawWallVariant variant, bool fourColumns, bool isSimpleShade);
void Loop(DrawWallVariant variant, bool fourColumns, bool isSimpleShade, bool isNearestFilter);
SSAVec4i Sample(SSAInt frac, bool isNearestFilter);
SSAVec4i Sample(SSAInt frac, int index, bool isNearestFilter);
SSAVec4i Shade(SSAVec4i fg, int index, bool isSimpleShade);
SSAVec4i Blend(SSAVec4i fg, SSAVec4i bg, DrawWallVariant variant);
@ -43,6 +43,7 @@ private:
SSABool is_simple_shade;
SSABool is_nearest_filter;
SSAShadeConstants shade_constants;
SSAWorkerThread thread;
SSAInt fracstep[4];
SSAInt one[4];