GPU/SW: Specialize rasterizing functions further

This commit is contained in:
Connor McLaughlin 2021-07-10 14:28:27 +10:00
parent 0ff1402fcd
commit 1405ba8a6b
3 changed files with 1317 additions and 111 deletions

View File

@ -0,0 +1,73 @@
texmode = [
"GPUTextureMode::Palette4Bit",
"GPUTextureMode::Palette8Bit",
"GPUTextureMode::Direct16Bit",
"GPUTextureMode::Direct16Bit",
"GPUTextureMode::RawPalette4Bit",
"GPUTextureMode::RawPalette8Bit",
"GPUTextureMode::RawDirect16Bit",
"GPUTextureMode::RawDirect16Bit",
"GPUTextureMode::Disabled"
]
transparentmode = [
"GPUTransparencyMode::HalfBackgroundPlusHalfForeground",
"GPUTransparencyMode::BackgroundPlusForeground",
"GPUTransparencyMode::BackgroundMinusForeground",
"GPUTransparencyMode::BackgroundPlusQuarterForeground",
"GPUTransparencyMode::Disabled"
]
bools = ["false", "true"]
"""
print("const GPU_SW_Backend::DrawRectangleFunction GPU_SW_Backend::s_rectangle_draw_functions[%d][%d][2] = {" % (len(texmode), len(transparentmode)))
for texture in range(len(texmode)):
print(" { // %s" % texmode[texture])
for transparency in range(len(transparentmode)):
print(" { // %s" % transparentmode[transparency])
for check_mask in range(2):
line = "&GPU_SW_Backend::DrawRectangle<%s, %s, %s>" % (texmode[texture], transparentmode[transparency], bools[check_mask])
print(" %s%s" % (line, "," if check_mask == 0 else ""))
print(" }%s" % ("," if transparency < (len(transparentmode) - 1) else ""))
print(" }%s" % ("," if texture < (len(texmode) - 1) else ""))
print("};")
"""
"""
print("const GPU_SW_Backend::DrawTriangleFunction GPU_SW_Backend::s_triangle_draw_functions[2][%d][%d][2][2] = {" % (len(texmode), len(transparentmode)))
for shading in range(2):
print(" { // shading %s" % bools[shading])
for texture in range(len(texmode)):
print(" { // %s" % texmode[texture])
for transparency in range(len(transparentmode)):
print(" { // %s" % transparentmode[transparency])
for dither in range(2):
print(" { // dither %s" % bools[dither])
for check_mask in range(2):
line = "&GPU_SW_Backend::DrawTriangle<%s, %s, %s, %s, %s>" % (bools[shading], texmode[texture], transparentmode[transparency], bools[dither], bools[check_mask])
print(" %s%s" % (line, "," if check_mask == 0 else ""))
print(" }%s" % ("," if dither == 0 else ""))
print(" }%s" % ("," if transparency < (len(transparentmode) - 1) else ""))
print(" }%s" % ("," if texture < (len(texmode) - 1) else ""))
print(" }%s" % ("," if shading == 0 else ""))
print("};")
"""
print("const GPU_SW_Backend::DrawLineFunction GPU_SW_Backend::s_line_draw_functions[2][%d][2][2] = {" % (len(transparentmode)))
for shading in range(2):
print(" { // shading %s" % bools[shading])
for transparency in range(len(transparentmode)):
print(" { // %s" % transparentmode[transparency])
for dither in range(2):
print(" { // dither %s" % bools[dither])
for check_mask in range(2):
line = "&GPU_SW_Backend::DrawLine<%s, %s, %s, %s>" % (bools[shading], transparentmode[transparency], bools[dither], bools[check_mask])
print(" %s%s" % (line, "," if check_mask == 0 else ""))
print(" }%s" % ("," if dither == 0 else ""))
print(" }%s" % ("," if transparency < (len(transparentmode) - 1) else ""))
print(" }%s" % ("," if shading == 0 else ""))
print("};")

File diff suppressed because it is too large Load Diff

View File

@ -98,17 +98,13 @@ protected:
//////////////////////////////////////////////////////////////////////////
// Rasterization
//////////////////////////////////////////////////////////////////////////
template<bool texture_enable, bool raw_texture_enable, bool transparency_enable, bool dithering_enable>
template<GPUTextureMode texture_mode, GPUTransparencyMode transparency_mode, bool dithering_enable, bool check_mask>
void ShadePixel(const GPUBackendDrawCommand* cmd, u32 x, u32 y, u8 color_r, u8 color_g, u8 color_b, u8 texcoord_x,
u8 texcoord_y);
template<bool texture_enable, bool raw_texture_enable, bool transparency_enable>
template<GPUTextureMode texture_mode, GPUTransparencyMode transparency_mode, bool check_mask>
void DrawRectangle(const GPUBackendDrawRectangleCommand* cmd);
using DrawRectangleFunction = void (GPU_SW_Backend::*)(const GPUBackendDrawRectangleCommand* cmd);
DrawRectangleFunction GetDrawRectangleFunction(bool texture_enable, bool raw_texture_enable,
bool transparency_enable);
//////////////////////////////////////////////////////////////////////////
// Polygon and line rasterization ported from Mednafen
//////////////////////////////////////////////////////////////////////////
@ -137,31 +133,36 @@ protected:
template<bool shading_enable, bool texture_enable>
void AddIDeltas_DY(i_group& ig, const i_deltas& idl, u32 count = 1);
template<bool shading_enable, bool texture_enable, bool raw_texture_enable, bool transparency_enable,
bool dithering_enable>
template<bool shading_enable, GPUTextureMode texture_mode, GPUTransparencyMode transparency_mode,
bool dithering_enable, bool check_mask>
void DrawSpan(const GPUBackendDrawPolygonCommand* cmd, s32 y, s32 x_start, s32 x_bound, i_group ig,
const i_deltas& idl);
template<bool shading_enable, bool texture_enable, bool raw_texture_enable, bool transparency_enable,
bool dithering_enable>
template<bool shading_enable, GPUTextureMode texture_mode, GPUTransparencyMode transparency_mode,
bool dithering_enable, bool check_mask>
void DrawTriangle(const GPUBackendDrawPolygonCommand* cmd, const GPUBackendDrawPolygonCommand::Vertex* v0,
const GPUBackendDrawPolygonCommand::Vertex* v1, const GPUBackendDrawPolygonCommand::Vertex* v2);
template<bool shading_enable, GPUTransparencyMode transparency_mode, bool dithering_enable, bool check_mask>
void DrawLine(const GPUBackendDrawLineCommand* cmd, const GPUBackendDrawLineCommand::Vertex* p0,
const GPUBackendDrawLineCommand::Vertex* p1);
#if 0
std::array<u16, VRAM_WIDTH * VRAM_HEIGHT> m_vram;
#else
u16 m_vram[VRAM_WIDTH * VRAM_HEIGHT];
#endif
using DrawRectangleFunction = void (GPU_SW_Backend::*)(const GPUBackendDrawRectangleCommand* cmd);
using DrawTriangleFunction = void (GPU_SW_Backend::*)(const GPUBackendDrawPolygonCommand* cmd,
const GPUBackendDrawPolygonCommand::Vertex* v0,
const GPUBackendDrawPolygonCommand::Vertex* v1,
const GPUBackendDrawPolygonCommand::Vertex* v2);
DrawTriangleFunction GetDrawTriangleFunction(bool shading_enable, bool texture_enable, bool raw_texture_enable,
bool transparency_enable, bool dithering_enable);
template<bool shading_enable, bool transparency_enable, bool dithering_enable>
void DrawLine(const GPUBackendDrawLineCommand* cmd, const GPUBackendDrawLineCommand::Vertex* p0,
const GPUBackendDrawLineCommand::Vertex* p1);
using DrawLineFunction = void (GPU_SW_Backend::*)(const GPUBackendDrawLineCommand* cmd,
const GPUBackendDrawLineCommand::Vertex* p0,
const GPUBackendDrawLineCommand::Vertex* p1);
DrawLineFunction GetDrawLineFunction(bool shading_enable, bool transparency_enable, bool dithering_enable);
std::array<u16, VRAM_WIDTH * VRAM_HEIGHT> m_vram;
static const DrawRectangleFunction s_rectangle_draw_functions[9][5][2];
static const DrawTriangleFunction s_triangle_draw_functions[2][9][5][2][2];
static const DrawLineFunction s_line_draw_functions[2][5][2][2];
};