Fully implemented codegen for DrawSpan

This commit is contained in:
Magnus Norddahl 2016-09-28 18:49:39 +02:00
commit 3aea3a0bee
7 changed files with 275 additions and 1163 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
#pragma once
#include "r_compiler/ssa/ssa_value.h"
#include "r_compiler/ssa/ssa_vec4f.h"
#include "r_compiler/ssa/ssa_vec4i.h"
#include "r_compiler/ssa/ssa_vec8s.h"
@ -84,16 +85,9 @@ public:
SSAInt desaturate;
};
class FixedFunction
class DrawerCodegen
{
public:
FixedFunction();
void(*DrawSpan)(const RenderArgs *) = nullptr;
private:
void CodegenDrawSpan();
// LightBgra
SSAInt calc_light_multiplier(SSAInt light);
SSAVec4i shade_pal_index_simple(SSAInt index, SSAInt light, SSAUBytePtr basecolors);
@ -111,89 +105,57 @@ private:
// SampleBgra
SSAVec4i sample_linear(SSAUBytePtr col0, SSAUBytePtr col1, SSAInt texturefracx, SSAInt texturefracy, SSAInt one, SSAInt height);
SSAVec4i sample_linear(SSAUBytePtr texture, SSAInt xfrac, SSAInt yfrac, SSAInt xbits, SSAInt ybits);
};
class DrawSpanCodegen : public DrawerCodegen
{
public:
void Generate(SSAValue args);
private:
void LoopShade(bool isSimpleShade);
void LoopFilter(bool isSimpleShade, bool isNearestFilter);
SSAInt Loop4x(bool isSimpleShade, bool isNearestFilter, bool is64x64);
void Loop(SSAInt start, bool isSimpleShade, bool isNearestFilter, bool is64x64);
SSAVec4i Sample(SSAInt xfrac, SSAInt yfrac, bool isNearestFilter, bool is64x64);
SSAStack<SSAInt> stack_index, stack_xfrac, stack_yfrac;
SSAUBytePtr destorg;
SSAUBytePtr source;
SSAInt destpitch;
SSAInt xstep;
SSAInt ystep;
SSAInt x1;
SSAInt x2;
SSAInt y;
SSAInt xbits;
SSAInt ybits;
SSAInt light;
SSAInt srcalpha;
SSAInt destalpha;
SSAInt count;
SSAUBytePtr data;
SSAInt yshift;
SSAInt xshift;
SSAInt xmask;
SSABool is_64x64;
SSABool is_simple_shade;
SSABool is_nearest_filter;
SSAShadeConstants shade_constants;
};
class FixedFunction
{
public:
FixedFunction();
void(*DrawSpan)(const RenderArgs *) = nullptr;
private:
void CodegenDrawSpan();
static llvm::Type *GetRenderArgsStruct(llvm::LLVMContext &context);
RenderProgram mProgram;
};
#if 0
class GlslProgram;
class GlslCodeGen;
class GlslFixedFunction
{
public:
GlslFixedFunction(GlslProgram &program, GlslCodeGen &vertex_codegen, GlslCodeGen &fragment_codegen);
void codegen();
static llvm::Type *get_sampler_struct(llvm::LLVMContext &context);
private:
void codegen_draw_triangles(int num_vertex_in, int num_vertex_out);
void codegen_calc_window_positions();
void codegen_calc_polygon_face_direction();
void codegen_calc_polygon_y_range();
void codegen_update_polygon_edge();
void codegen_texture();
void codegen_normalize();
void codegen_reflect();
void codegen_max();
void codegen_pow();
void codegen_dot();
void codegen_mix();
struct OuterData
{
OuterData() : sampler() { }
SSAInt start;
SSAInt end;
SSAInt input_width;
SSAInt input_height;
SSAInt output_width;
SSAInt output_height;
SSAUBytePtr input_pixels;
SSAUBytePtr output_pixels_line;
SSAVec4fPtr sse_left_varying_in;
SSAVec4fPtr sse_right_varying_in;
int num_varyings;
SSAVec4f viewport_x;
SSAVec4f viewport_rcp_half_width;
SSAVec4f dx;
SSAVec4f dw;
SSAVec4f v1w;
SSAVec4f v1x;
llvm::Value *sampler;
};
void render_polygon(
SSAInt input_width,
SSAInt input_height,
SSAUBytePtr input_data,
SSAInt output_width,
SSAInt output_height,
SSAUBytePtr output_data,
SSAInt viewport_x,
SSAInt viewport_y,
SSAInt viewport_width,
SSAInt viewport_height,
SSAInt num_vertices,
std::vector<SSAVec4fPtr> fragment_ins,
SSAInt core,
SSAInt num_cores);
void codegen_render_scanline(int num_varyings);
void process_first_pixels(OuterData &outer_data, SSAStack<SSAInt> &stack_x, SSAStack<SSAVec4f> &stack_xnormalized);
void process_last_pixels(OuterData &outer_data, SSAStack<SSAInt> &stack_x, SSAStack<SSAVec4f> &stack_xnormalized);
void inner_block(OuterData &data, SSAVec4f xnormalized, SSAVec4f *out_frag_colors);
void blend(SSAVec4f frag_colors[4], SSAVec16ub &dest);
GlslProgram &program;
GlslCodeGen &vertex_codegen;
GlslCodeGen &fragment_codegen;
};
#endif