From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 502 ++++++++++++++++++++++ 1 file changed, 502 insertions(+) create mode 100644 Source/Core/VideoBackends/Software/Rasterizer.cpp (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp new file mode 100644 index 0000000000..377a437c64 --- /dev/null +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -0,0 +1,502 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "Common.h" + +#include "Rasterizer.h" +#include "HwRasterizer.h" +#include "EfbInterface.h" +#include "BPMemLoader.h" +#include "XFMemLoader.h" +#include "Tev.h" +#include "SWPixelEngine.h" +#include "SWStatistics.h" +#include "SWVideoConfig.h" + + +#define BLOCK_SIZE 2 + +#define CLAMP(x, a, b) (x>b)?b:(x> 19) - 2032; // integer part + s32 logFract = (*x & 0x007fffff) >> 19; // approximate fractional part + + return logInt + logFract; +} + +namespace Rasterizer +{ +Slope ZSlope; +Slope WSlope; +Slope ColorSlopes[2][4]; +Slope TexSlopes[8][3]; + +s32 vertex0X; +s32 vertex0Y; +float vertexOffsetX; +float vertexOffsetY; + +s32 scissorLeft = 0; +s32 scissorTop = 0; +s32 scissorRight = 0; +s32 scissorBottom = 0; + +Tev tev; +RasterBlock rasterBlock; + +void DoState(PointerWrap &p) +{ + ZSlope.DoState(p); + WSlope.DoState(p); + for (auto& ColorSlope : ColorSlopes) + for (int n=0; n<4; ++n) + ColorSlope[n].DoState(p); + for (auto& TexSlope : TexSlopes) + for (int n=0; n<3; ++n) + TexSlope[n].DoState(p); + p.Do(vertex0X); + p.Do(vertex0Y); + p.Do(vertexOffsetX); + p.Do(vertexOffsetY); + p.Do(scissorLeft); + p.Do(scissorTop); + p.Do(scissorRight); + p.Do(scissorBottom); + tev.DoState(p); + p.Do(rasterBlock); +} + +void Init() +{ + tev.Init(); + + // Set initial z reference plane in the unlikely case that zfreeze is enabled when drawing the first primitive. + // TODO: This is just a guess! + ZSlope.dfdx = ZSlope.dfdy = 0.f; + ZSlope.f0 = 1.f; +} + +inline int iround(float x) +{ + int t; + +#if defined(_WIN32) && !defined(_M_X64) + __asm + { + fld x + fistp t + } +#else + t = (int)x; + if((x - t) >= 0.5) + return t + 1; +#endif + + return t; +} + +void SetScissor() +{ + int xoff = bpmem.scissorOffset.x * 2 - 342; + int yoff = bpmem.scissorOffset.y * 2 - 342; + + scissorLeft = bpmem.scissorTL.x - xoff - 342; + if (scissorLeft < 0) scissorLeft = 0; + + scissorTop = bpmem.scissorTL.y - yoff - 342; + if (scissorTop < 0) scissorTop = 0; + + scissorRight = bpmem.scissorBR.x - xoff - 341; + if (scissorRight > EFB_WIDTH) scissorRight = EFB_WIDTH; + + scissorBottom = bpmem.scissorBR.y - yoff - 341; + if (scissorBottom > EFB_HEIGHT) scissorBottom = EFB_HEIGHT; +} + +void SetTevReg(int reg, int comp, bool konst, s16 color) +{ + tev.SetRegColor(reg, comp, konst, color); +} + +inline void Draw(s32 x, s32 y, s32 xi, s32 yi) +{ + INCSTAT(swstats.thisFrame.rasterizedPixels); + + float dx = vertexOffsetX + (float)(x - vertex0X); + float dy = vertexOffsetY + (float)(y - vertex0Y); + + s32 z = (s32)ZSlope.GetValue(dx, dy); + if (z < 0 || z > 0x00ffffff) + return; + + if (bpmem.UseEarlyDepthTest() && g_SWVideoConfig.bZComploc) + { + // TODO: Test if perf regs are incremented even if test is disabled + SWPixelEngine::pereg.IncZInputQuadCount(true); + if (bpmem.zmode.testenable) + { + // early z + if (!EfbInterface::ZCompare(x, y, z)) + return; + } + SWPixelEngine::pereg.IncZOutputQuadCount(true); + } + + RasterBlockPixel& pixel = rasterBlock.Pixel[xi][yi]; + + tev.Position[0] = x; + tev.Position[1] = y; + tev.Position[2] = z; + + // colors + for (unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) + { + for(int comp = 0; comp < 4; comp++) + { + u16 color = (u16)ColorSlopes[i][comp].GetValue(dx, dy); + + // clamp color value to 0 + u16 mask = ~(color >> 8); + + tev.Color[i][comp] = color & mask; + } + } + + // tex coords + for (unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) + { + // multiply by 128 because TEV stores UVs as s17.7 + tev.Uv[i].s = (s32)(pixel.Uv[i][0] * 128); + tev.Uv[i].t = (s32)(pixel.Uv[i][1] * 128); + } + + for (unsigned int i = 0; i < bpmem.genMode.numindstages; i++) + { + tev.IndirectLod[i] = rasterBlock.IndirectLod[i]; + tev.IndirectLinear[i] = rasterBlock.IndirectLinear[i]; + } + + for (unsigned int i = 0; i <= bpmem.genMode.numtevstages; i++) + { + tev.TextureLod[i] = rasterBlock.TextureLod[i]; + tev.TextureLinear[i] = rasterBlock.TextureLinear[i]; + } + + tev.Draw(); +} + +void InitTriangle(float X1, float Y1, s32 xi, s32 yi) +{ + vertex0X = xi; + vertex0Y = yi; + + // adjust a little less than 0.5 + const float adjust = 0.495f; + + vertexOffsetX = ((float)xi - X1) + adjust; + vertexOffsetY = ((float)yi - Y1) + adjust; +} + +void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, float DX12, float DY12, float DY31) +{ + float DF31 = f3 - f1; + float DF21 = f2 - f1; + float a = DF31 * -DY12 - DF21 * DY31; + float b = DX31 * DF21 + DX12 * DF31; + float c = -DX12 * DY31 - DX31 * -DY12; + slope->dfdx = -a / c; + slope->dfdy = -b / c; + slope->f0 = f1; +} + +inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) +{ + FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1]; + u8 subTexmap = texmap & 3; + + // LOD calculation requires data from the texture mode for bias, etc. + // it does not seem to use the actual texture size + TexMode0& tm0 = texUnit.texMode0[subTexmap]; + TexMode1& tm1 = texUnit.texMode1[subTexmap]; + + float sDelta, tDelta; + if (tm0.diag_lod) + { + float *uv0 = rasterBlock.Pixel[0][0].Uv[texcoord]; + float *uv1 = rasterBlock.Pixel[1][1].Uv[texcoord]; + + sDelta = fabsf(uv0[0] - uv1[0]); + tDelta = fabsf(uv0[1] - uv1[1]); + } + else + { + float *uv0 = rasterBlock.Pixel[0][0].Uv[texcoord]; + float *uv1 = rasterBlock.Pixel[1][0].Uv[texcoord]; + float *uv2 = rasterBlock.Pixel[0][1].Uv[texcoord]; + + sDelta = max(fabsf(uv0[0] - uv1[0]), fabsf(uv0[0] - uv2[0])); + tDelta = max(fabsf(uv0[1] - uv1[1]), fabsf(uv0[1] - uv2[1])); + } + + // get LOD in s28.4 + lod = FixedLog2(max(sDelta, tDelta)); + + // bias is s2.5 + int bias = tm0.lod_bias; + bias >>= 1; + lod += bias; + + linear = ((lod > 0 && (tm0.min_filter & 4)) || (lod <= 0 && tm0.mag_filter)); + + // order of checks matters + // should be: + // if lod > max then max + // else if lod < min then min + lod = CLAMP(lod, (s32)tm1.min_lod, (s32)tm1.max_lod); +} + +void BuildBlock(s32 blockX, s32 blockY) +{ + for (s32 yi = 0; yi < BLOCK_SIZE; yi++) + { + for (s32 xi = 0; xi < BLOCK_SIZE; xi++) + { + RasterBlockPixel& pixel = rasterBlock.Pixel[xi][yi]; + + float dx = vertexOffsetX + (float)(xi + blockX - vertex0X); + float dy = vertexOffsetY + (float)(yi + blockY - vertex0Y); + + float invW = 1.0f / WSlope.GetValue(dx, dy); + pixel.InvW = invW; + + // tex coords + for (unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) + { + float projection = invW; + if (swxfregs.texMtxInfo[i].projection) + { + float q = TexSlopes[i][2].GetValue(dx, dy) * invW; + if (q != 0.0f) + projection = invW / q; + } + + pixel.Uv[i][0] = TexSlopes[i][0].GetValue(dx, dy) * projection; + pixel.Uv[i][1] = TexSlopes[i][1].GetValue(dx, dy) * projection; + } + } + } + + u32 indref = bpmem.tevindref.hex; + for (unsigned int i = 0; i < bpmem.genMode.numindstages; i++) + { + u32 texmap = indref & 3; + indref >>= 3; + u32 texcoord = indref & 3; + indref >>= 3; + + CalculateLOD(rasterBlock.IndirectLod[i], rasterBlock.IndirectLinear[i], texmap, texcoord); + } + + for (unsigned int i = 0; i <= bpmem.genMode.numtevstages; i++) + { + int stageOdd = i&1; + TwoTevStageOrders &order = bpmem.tevorders[i >> 1]; + if(order.getEnable(stageOdd)) + { + u32 texmap = order.getTexMap(stageOdd); + u32 texcoord = order.getTexCoord(stageOdd); + + CalculateLOD(rasterBlock.TextureLod[i], rasterBlock.TextureLinear[i], texmap, texcoord); + } + } +} + +void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2) +{ + INCSTAT(swstats.thisFrame.numTrianglesDrawn); + + if (g_SWVideoConfig.bHwRasterizer) + { + HwRasterizer::DrawTriangleFrontFace(v0, v1, v2); + return; + } + + // adapted from http://www.devmaster.net/forums/showthread.php?t=1884 + + // 28.4 fixed-pou32 coordinates. rounded to nearest and adjusted to match hardware output + // could also take floor and adjust -8 + const s32 Y1 = iround(16.0f * v0->screenPosition[1]) - 9; + const s32 Y2 = iround(16.0f * v1->screenPosition[1]) - 9; + const s32 Y3 = iround(16.0f * v2->screenPosition[1]) - 9; + + const s32 X1 = iround(16.0f * v0->screenPosition[0]) - 9; + const s32 X2 = iround(16.0f * v1->screenPosition[0]) - 9; + const s32 X3 = iround(16.0f * v2->screenPosition[0]) - 9; + + // Deltas + const s32 DX12 = X1 - X2; + const s32 DX23 = X2 - X3; + const s32 DX31 = X3 - X1; + + const s32 DY12 = Y1 - Y2; + const s32 DY23 = Y2 - Y3; + const s32 DY31 = Y3 - Y1; + + // Fixed-pos32 deltas + const s32 FDX12 = DX12 << 4; + const s32 FDX23 = DX23 << 4; + const s32 FDX31 = DX31 << 4; + + const s32 FDY12 = DY12 << 4; + const s32 FDY23 = DY23 << 4; + const s32 FDY31 = DY31 << 4; + + // Bounding rectangle + s32 minx = (min(min(X1, X2), X3) + 0xF) >> 4; + s32 maxx = (max(max(X1, X2), X3) + 0xF) >> 4; + s32 miny = (min(min(Y1, Y2), Y3) + 0xF) >> 4; + s32 maxy = (max(max(Y1, Y2), Y3) + 0xF) >> 4; + + // scissor + minx = max(minx, scissorLeft); + maxx = min(maxx, scissorRight); + miny = max(miny, scissorTop); + maxy = min(maxy, scissorBottom); + + if (minx >= maxx || miny >= maxy) + return; + + // Setup slopes + float fltx1 = v0->screenPosition.x; + float flty1 = v0->screenPosition.y; + float fltdx31 = v2->screenPosition.x - fltx1; + float fltdx12 = fltx1 - v1->screenPosition.x; + float fltdy12 = flty1 - v1->screenPosition.y; + float fltdy31 = v2->screenPosition.y - flty1; + + InitTriangle(fltx1, flty1, (X1 + 0xF) >> 4, (Y1 + 0xF) >> 4); + + float w[3] = { 1.0f / v0->projectedPosition.w, 1.0f / v1->projectedPosition.w, 1.0f / v2->projectedPosition.w }; + InitSlope(&WSlope, w[0], w[1], w[2], fltdx31, fltdx12, fltdy12, fltdy31); + + // TODO: The zfreeze emulation is not quite correct, yet! + // Many things might prevent us from reaching this line (culling, clipping, scissoring). + // However, the zslope is always guaranteed to be calculated unless all vertices are trivially rejected during clipping! + // We're currently sloppy at this since we abort early if any of the culling/clipping/scissoring tests fail. + if (!bpmem.genMode.zfreeze || !g_SWVideoConfig.bZFreeze) + InitSlope(&ZSlope, v0->screenPosition[2], v1->screenPosition[2], v2->screenPosition[2], fltdx31, fltdx12, fltdy12, fltdy31); + + for(unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) + { + for(int comp = 0; comp < 4; comp++) + InitSlope(&ColorSlopes[i][comp], v0->color[i][comp], v1->color[i][comp], v2->color[i][comp], fltdx31, fltdx12, fltdy12, fltdy31); + } + + for(unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) + { + for(int comp = 0; comp < 3; comp++) + InitSlope(&TexSlopes[i][comp], v0->texCoords[i][comp] * w[0], v1->texCoords[i][comp] * w[1], v2->texCoords[i][comp] * w[2], fltdx31, fltdx12, fltdy12, fltdy31); + } + + // Start in corner of 8x8 block + minx &= ~(BLOCK_SIZE - 1); + miny &= ~(BLOCK_SIZE - 1); + + // Half-edge constants + s32 C1 = DY12 * X1 - DX12 * Y1; + s32 C2 = DY23 * X2 - DX23 * Y2; + s32 C3 = DY31 * X3 - DX31 * Y3; + + // Correct for fill convention + if(DY12 < 0 || (DY12 == 0 && DX12 > 0)) C1++; + if(DY23 < 0 || (DY23 == 0 && DX23 > 0)) C2++; + if(DY31 < 0 || (DY31 == 0 && DX31 > 0)) C3++; + + // Loop through blocks + for(s32 y = miny; y < maxy; y += BLOCK_SIZE) + { + for(s32 x = minx; x < maxx; x += BLOCK_SIZE) + { + // Corners of block + s32 x0 = x << 4; + s32 x1 = (x + BLOCK_SIZE - 1) << 4; + s32 y0 = y << 4; + s32 y1 = (y + BLOCK_SIZE - 1) << 4; + + // Evaluate half-space functions + bool a00 = C1 + DX12 * y0 - DY12 * x0 > 0; + bool a10 = C1 + DX12 * y0 - DY12 * x1 > 0; + bool a01 = C1 + DX12 * y1 - DY12 * x0 > 0; + bool a11 = C1 + DX12 * y1 - DY12 * x1 > 0; + int a = (a00 << 0) | (a10 << 1) | (a01 << 2) | (a11 << 3); + + bool b00 = C2 + DX23 * y0 - DY23 * x0 > 0; + bool b10 = C2 + DX23 * y0 - DY23 * x1 > 0; + bool b01 = C2 + DX23 * y1 - DY23 * x0 > 0; + bool b11 = C2 + DX23 * y1 - DY23 * x1 > 0; + int b = (b00 << 0) | (b10 << 1) | (b01 << 2) | (b11 << 3); + + bool c00 = C3 + DX31 * y0 - DY31 * x0 > 0; + bool c10 = C3 + DX31 * y0 - DY31 * x1 > 0; + bool c01 = C3 + DX31 * y1 - DY31 * x0 > 0; + bool c11 = C3 + DX31 * y1 - DY31 * x1 > 0; + int c = (c00 << 0) | (c10 << 1) | (c01 << 2) | (c11 << 3); + + // Skip block when outside an edge + if(a == 0x0 || b == 0x0 || c == 0x0) + continue; + + BuildBlock(x, y); + + // Accept whole block when totally covered + if(a == 0xF && b == 0xF && c == 0xF) + { + for(s32 iy = 0; iy < BLOCK_SIZE; iy++) + { + for(s32 ix = 0; ix < BLOCK_SIZE; ix++) + { + Draw(x + ix, y + iy, ix, iy); + } + } + } + else // Partially covered block + { + s32 CY1 = C1 + DX12 * y0 - DY12 * x0; + s32 CY2 = C2 + DX23 * y0 - DY23 * x0; + s32 CY3 = C3 + DX31 * y0 - DY31 * x0; + + for(s32 iy = 0; iy < BLOCK_SIZE; iy++) + { + s32 CX1 = CY1; + s32 CX2 = CY2; + s32 CX3 = CY3; + + for(s32 ix = 0; ix < BLOCK_SIZE; ix++) + { + if(CX1 > 0 && CX2 > 0 && CX3 > 0) + { + Draw(x + ix, y + iy, ix, iy); + } + + CX1 -= FDY12; + CX2 -= FDY23; + CX3 -= FDY31; + } + + CY1 += FDX12; + CY2 += FDX23; + CY3 += FDX31; + } + } + } + } +} + + +} -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 377a437c64..8c59455531 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -2,17 +2,17 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "Common.h" - -#include "Rasterizer.h" -#include "HwRasterizer.h" -#include "EfbInterface.h" -#include "BPMemLoader.h" -#include "XFMemLoader.h" -#include "Tev.h" -#include "SWPixelEngine.h" -#include "SWStatistics.h" -#include "SWVideoConfig.h" +#include "Common/Common.h" + +#include "VideoBackends/Software/BPMemLoader.h" +#include "VideoBackends/Software/EfbInterface.h" +#include "VideoBackends/Software/HwRasterizer.h" +#include "VideoBackends/Software/Rasterizer.h" +#include "VideoBackends/Software/SWPixelEngine.h" +#include "VideoBackends/Software/SWStatistics.h" +#include "VideoBackends/Software/SWVideoConfig.h" +#include "VideoBackends/Software/Tev.h" +#include "VideoBackends/Software/XFMemLoader.h" #define BLOCK_SIZE 2 -- cgit v1.2.3 From 4f02132f9323a147c68b7dc1a79a62be33c1f170 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sun, 2 Mar 2014 05:21:50 -0600 Subject: Make our architecture defines less stupid. Our defines were never clear between what meant 64bit or x86_64 This makes a clear cut between bitness and architecture. This commit also has the side effect of bringing up aarch64 compiling support. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 8c59455531..13f1d89642 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -86,17 +86,9 @@ inline int iround(float x) { int t; -#if defined(_WIN32) && !defined(_M_X64) - __asm - { - fld x - fistp t - } -#else t = (int)x; if((x - t) >= 0.5) return t + 1; -#endif return t; } -- cgit v1.2.3 From c89f04a7c5256d92b75e9868df9af6cfb7050559 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 3 Mar 2014 06:25:15 +0100 Subject: clang-modernize -loop-convert and some manual adjustments --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 13f1d89642..80be2adada 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -54,12 +54,12 @@ void DoState(PointerWrap &p) { ZSlope.DoState(p); WSlope.DoState(p); - for (auto& ColorSlope : ColorSlopes) - for (int n=0; n<4; ++n) - ColorSlope[n].DoState(p); - for (auto& TexSlope : TexSlopes) - for (int n=0; n<3; ++n) - TexSlope[n].DoState(p); + for (auto& color_slopes_1d : ColorSlopes) + for (Slope& color_slope : color_slopes_1d) + color_slope.DoState(p); + for (auto& tex_slopes_1d : TexSlopes) + for (Slope& tex_slope : tex_slopes_1d) + tex_slope.DoState(p); p.Do(vertex0X); p.Do(vertex0Y); p.Do(vertexOffsetX); -- cgit v1.2.3 From 31cfc73a09a8685cbab20502b4bc132e98e2feb5 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 11 Mar 2014 00:30:55 +1300 Subject: Fixes spacing for "for", "while", "switch" and "if" Also moved && and || to ends of lines instead of start. Fixed misc vertical alignments and some { needed newlining. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 80be2adada..7054fab304 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -87,7 +87,7 @@ inline int iround(float x) int t; t = (int)x; - if((x - t) >= 0.5) + if ((x - t) >= 0.5) return t + 1; return t; @@ -149,7 +149,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) // colors for (unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) { - for(int comp = 0; comp < 4; comp++) + for (int comp = 0; comp < 4; comp++) { u16 color = (u16)ColorSlopes[i][comp].GetValue(dx, dy); @@ -299,7 +299,7 @@ void BuildBlock(s32 blockX, s32 blockY) { int stageOdd = i&1; TwoTevStageOrders &order = bpmem.tevorders[i >> 1]; - if(order.getEnable(stageOdd)) + if (order.getEnable(stageOdd)) { u32 texmap = order.getTexMap(stageOdd); u32 texcoord = order.getTexCoord(stageOdd); @@ -384,15 +384,15 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (!bpmem.genMode.zfreeze || !g_SWVideoConfig.bZFreeze) InitSlope(&ZSlope, v0->screenPosition[2], v1->screenPosition[2], v2->screenPosition[2], fltdx31, fltdx12, fltdy12, fltdy31); - for(unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) + for (unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) { - for(int comp = 0; comp < 4; comp++) + for (int comp = 0; comp < 4; comp++) InitSlope(&ColorSlopes[i][comp], v0->color[i][comp], v1->color[i][comp], v2->color[i][comp], fltdx31, fltdx12, fltdy12, fltdy31); } - for(unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) + for (unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) { - for(int comp = 0; comp < 3; comp++) + for (int comp = 0; comp < 3; comp++) InitSlope(&TexSlopes[i][comp], v0->texCoords[i][comp] * w[0], v1->texCoords[i][comp] * w[1], v2->texCoords[i][comp] * w[2], fltdx31, fltdx12, fltdy12, fltdy31); } @@ -406,14 +406,14 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer s32 C3 = DY31 * X3 - DX31 * Y3; // Correct for fill convention - if(DY12 < 0 || (DY12 == 0 && DX12 > 0)) C1++; - if(DY23 < 0 || (DY23 == 0 && DX23 > 0)) C2++; - if(DY31 < 0 || (DY31 == 0 && DX31 > 0)) C3++; + if (DY12 < 0 || (DY12 == 0 && DX12 > 0)) C1++; + if (DY23 < 0 || (DY23 == 0 && DX23 > 0)) C2++; + if (DY31 < 0 || (DY31 == 0 && DX31 > 0)) C3++; // Loop through blocks - for(s32 y = miny; y < maxy; y += BLOCK_SIZE) + for (s32 y = miny; y < maxy; y += BLOCK_SIZE) { - for(s32 x = minx; x < maxx; x += BLOCK_SIZE) + for (s32 x = minx; x < maxx; x += BLOCK_SIZE) { // Corners of block s32 x0 = x << 4; @@ -441,17 +441,17 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer int c = (c00 << 0) | (c10 << 1) | (c01 << 2) | (c11 << 3); // Skip block when outside an edge - if(a == 0x0 || b == 0x0 || c == 0x0) + if (a == 0x0 || b == 0x0 || c == 0x0) continue; BuildBlock(x, y); // Accept whole block when totally covered - if(a == 0xF && b == 0xF && c == 0xF) + if (a == 0xF && b == 0xF && c == 0xF) { - for(s32 iy = 0; iy < BLOCK_SIZE; iy++) + for (s32 iy = 0; iy < BLOCK_SIZE; iy++) { - for(s32 ix = 0; ix < BLOCK_SIZE; ix++) + for (s32 ix = 0; ix < BLOCK_SIZE; ix++) { Draw(x + ix, y + iy, ix, iy); } @@ -463,15 +463,15 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer s32 CY2 = C2 + DX23 * y0 - DY23 * x0; s32 CY3 = C3 + DX31 * y0 - DY31 * x0; - for(s32 iy = 0; iy < BLOCK_SIZE; iy++) + for (s32 iy = 0; iy < BLOCK_SIZE; iy++) { s32 CX1 = CY1; s32 CX2 = CY2; s32 CX3 = CY3; - for(s32 ix = 0; ix < BLOCK_SIZE; ix++) + for (s32 ix = 0; ix < BLOCK_SIZE; ix++) { - if(CX1 > 0 && CX2 > 0 && CX3 > 0) + if (CX1 > 0 && CX2 > 0 && CX3 > 0) { Draw(x + ix, y + iy, ix, iy); } -- cgit v1.2.3 From 0661efea8456b32d88fa13103f8ed68509f2b69f Mon Sep 17 00:00:00 2001 From: magumagu Date: Fri, 28 Mar 2014 19:22:15 -0700 Subject: Software backend: Delete forked PixelEngine. Mostly just zapping a bunch of duplicated code; the only interesting thing going on here is the changes to the performance counter implementation. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 7054fab304..26ac9d6c7b 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -8,7 +8,6 @@ #include "VideoBackends/Software/EfbInterface.h" #include "VideoBackends/Software/HwRasterizer.h" #include "VideoBackends/Software/Rasterizer.h" -#include "VideoBackends/Software/SWPixelEngine.h" #include "VideoBackends/Software/SWStatistics.h" #include "VideoBackends/Software/SWVideoConfig.h" #include "VideoBackends/Software/Tev.h" @@ -130,14 +129,14 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) if (bpmem.UseEarlyDepthTest() && g_SWVideoConfig.bZComploc) { // TODO: Test if perf regs are incremented even if test is disabled - SWPixelEngine::pereg.IncZInputQuadCount(true); + EfbInterface::IncPerfCounterQuadCount(PQ_ZCOMP_INPUT_ZCOMPLOC); if (bpmem.zmode.testenable) { // early z if (!EfbInterface::ZCompare(x, y, z)) return; } - SWPixelEngine::pereg.IncZOutputQuadCount(true); + EfbInterface::IncPerfCounterQuadCount(PQ_ZCOMP_OUTPUT_ZCOMPLOC); } RasterBlockPixel& pixel = rasterBlock.Pixel[xi][yi]; -- cgit v1.2.3 From fe65474cc40ef2e3830007a784b9c03b6deec6de Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Mon, 21 Apr 2014 22:54:09 +0200 Subject: Software renderer: Update a reference link. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 26ac9d6c7b..bf90d5a862 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -318,7 +318,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer return; } - // adapted from http://www.devmaster.net/forums/showthread.php?t=1884 + // adapted from http://devmaster.net/posts/6145/advanced-rasterization // 28.4 fixed-pou32 coordinates. rounded to nearest and adjusted to match hardware output // could also take floor and adjust -8 -- cgit v1.2.3 From 818c89313e54bcf3de98b976c0da57c88a8588d2 Mon Sep 17 00:00:00 2001 From: magumagu Date: Wed, 16 Apr 2014 14:51:18 -0700 Subject: Video backends: unify xfregs/xfmem structures. Removes the duplicate swxfregs global variable/struct from the software backend in favor of the ones from VideoCommon. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index bf90d5a862..6334a300f5 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -270,7 +270,7 @@ void BuildBlock(s32 blockX, s32 blockY) for (unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) { float projection = invW; - if (swxfregs.texMtxInfo[i].projection) + if (xfregs.texMtxInfo[i].projection) { float q = TexSlopes[i][2].GetValue(dx, dy) * invW; if (q != 0.0f) -- cgit v1.2.3 From 1357277f40166683a3ac4eb9979010c3038d2db8 Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 27 Apr 2014 11:59:04 -0700 Subject: Video backends: mass-replace "xfregs" with "xfmem". --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 6334a300f5..67f80047cc 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -270,7 +270,7 @@ void BuildBlock(s32 blockX, s32 blockY) for (unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) { float projection = invW; - if (xfregs.texMtxInfo[i].projection) + if (xfmem.texMtxInfo[i].projection) { float q = TexSlopes[i][2].GetValue(dx, dy) * invW; if (q != 0.0f) -- cgit v1.2.3 From 49b0eef393f4d321928fb0b6093d58a7637cf1da Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 2 May 2014 22:47:04 -0400 Subject: Remove the min/max functions in CommonFuncs. The algorithm header has the same functions. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 67f80047cc..915757f766 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -2,8 +2,9 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "Common/Common.h" +#include +#include "Common/Common.h" #include "VideoBackends/Software/BPMemLoader.h" #include "VideoBackends/Software/EfbInterface.h" #include "VideoBackends/Software/HwRasterizer.h" @@ -231,12 +232,12 @@ inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) float *uv1 = rasterBlock.Pixel[1][0].Uv[texcoord]; float *uv2 = rasterBlock.Pixel[0][1].Uv[texcoord]; - sDelta = max(fabsf(uv0[0] - uv1[0]), fabsf(uv0[0] - uv2[0])); - tDelta = max(fabsf(uv0[1] - uv1[1]), fabsf(uv0[1] - uv2[1])); + sDelta = std::max(fabsf(uv0[0] - uv1[0]), fabsf(uv0[0] - uv2[0])); + tDelta = std::max(fabsf(uv0[1] - uv1[1]), fabsf(uv0[1] - uv2[1])); } // get LOD in s28.4 - lod = FixedLog2(max(sDelta, tDelta)); + lod = FixedLog2(std::max(sDelta, tDelta)); // bias is s2.5 int bias = tm0.lod_bias; @@ -349,16 +350,16 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer const s32 FDY31 = DY31 << 4; // Bounding rectangle - s32 minx = (min(min(X1, X2), X3) + 0xF) >> 4; - s32 maxx = (max(max(X1, X2), X3) + 0xF) >> 4; - s32 miny = (min(min(Y1, Y2), Y3) + 0xF) >> 4; - s32 maxy = (max(max(Y1, Y2), Y3) + 0xF) >> 4; + s32 minx = (std::min(std::min(X1, X2), X3) + 0xF) >> 4; + s32 maxx = (std::max(std::max(X1, X2), X3) + 0xF) >> 4; + s32 miny = (std::min(std::min(Y1, Y2), Y3) + 0xF) >> 4; + s32 maxy = (std::max(std::max(Y1, Y2), Y3) + 0xF) >> 4; // scissor - minx = max(minx, scissorLeft); - maxx = min(maxx, scissorRight); - miny = max(miny, scissorTop); - maxy = min(maxy, scissorBottom); + minx = std::max(minx, scissorLeft); + maxx = std::min(maxx, scissorRight); + miny = std::max(miny, scissorTop); + maxy = std::min(maxy, scissorBottom); if (minx >= maxx || miny >= maxy) return; -- cgit v1.2.3 From 22e1aa5bb4a159d6d66a321f978917614aa36331 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 8 Jul 2014 14:29:26 +0200 Subject: mark all local functions as static --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 915757f766..90fe84ffee 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -183,7 +183,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) tev.Draw(); } -void InitTriangle(float X1, float Y1, s32 xi, s32 yi) +static void InitTriangle(float X1, float Y1, s32 xi, s32 yi) { vertex0X = xi; vertex0Y = yi; @@ -195,7 +195,7 @@ void InitTriangle(float X1, float Y1, s32 xi, s32 yi) vertexOffsetY = ((float)yi - Y1) + adjust; } -void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, float DX12, float DY12, float DY31) +static void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, float DX12, float DY12, float DY31) { float DF31 = f3 - f1; float DF21 = f2 - f1; @@ -253,7 +253,7 @@ inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) lod = CLAMP(lod, (s32)tm1.min_lod, (s32)tm1.max_lod); } -void BuildBlock(s32 blockX, s32 blockY) +static void BuildBlock(s32 blockX, s32 blockY) { for (s32 yi = 0; yi < BLOCK_SIZE; yi++) { -- cgit v1.2.3 From 6d3f249dcc746cc7845ef88ddb8ce3bcc9221aca Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 8 Jul 2014 15:58:25 +0200 Subject: mark all local variables as static --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 90fe84ffee..1a5e469435 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -32,23 +32,23 @@ static inline s32 FixedLog2(float f) namespace Rasterizer { -Slope ZSlope; -Slope WSlope; -Slope ColorSlopes[2][4]; -Slope TexSlopes[8][3]; - -s32 vertex0X; -s32 vertex0Y; -float vertexOffsetX; -float vertexOffsetY; - -s32 scissorLeft = 0; -s32 scissorTop = 0; -s32 scissorRight = 0; -s32 scissorBottom = 0; - -Tev tev; -RasterBlock rasterBlock; +static Slope ZSlope; +static Slope WSlope; +static Slope ColorSlopes[2][4]; +static Slope TexSlopes[8][3]; + +static s32 vertex0X; +static s32 vertex0Y; +static float vertexOffsetX; +static float vertexOffsetY; + +static s32 scissorLeft = 0; +static s32 scissorTop = 0; +static s32 scissorRight = 0; +static s32 scissorBottom = 0; + +static Tev tev; +static RasterBlock rasterBlock; void DoState(PointerWrap &p) { -- cgit v1.2.3 From 522a5c35ad97718478ccdc75ae519ce910dd6dcb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Jul 2014 20:55:07 -0400 Subject: Convert some more header inclusions into forward declarations --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 1a5e469435..cfe038b0ea 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -8,6 +8,7 @@ #include "VideoBackends/Software/BPMemLoader.h" #include "VideoBackends/Software/EfbInterface.h" #include "VideoBackends/Software/HwRasterizer.h" +#include "VideoBackends/Software/NativeVertexFormat.h" #include "VideoBackends/Software/Rasterizer.h" #include "VideoBackends/Software/SWStatistics.h" #include "VideoBackends/Software/SWVideoConfig.h" -- cgit v1.2.3 From 4129cdeb4d1e3969aba64cf2dad25b3864eedccb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 10 Aug 2014 21:51:05 -0400 Subject: Software: Apply static to some functions --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index cfe038b0ea..5b764fcc7a 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -83,11 +83,9 @@ void Init() ZSlope.f0 = 1.f; } -inline int iround(float x) +static inline int iround(float x) { - int t; - - t = (int)x; + int t = (int)x; if ((x - t) >= 0.5) return t + 1; @@ -208,7 +206,7 @@ static void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, fl slope->f0 = f1; } -inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) +static inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) { FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1]; u8 subTexmap = texmap & 3; -- cgit v1.2.3 From f9f46f33d6a12f5e57e0c0a4b6d66ed3c22952e1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 10 Aug 2014 21:55:30 -0400 Subject: Software: Fix some if-statement body placements --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 5b764fcc7a..3d002da810 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -98,16 +98,20 @@ void SetScissor() int yoff = bpmem.scissorOffset.y * 2 - 342; scissorLeft = bpmem.scissorTL.x - xoff - 342; - if (scissorLeft < 0) scissorLeft = 0; + if (scissorLeft < 0) + scissorLeft = 0; scissorTop = bpmem.scissorTL.y - yoff - 342; - if (scissorTop < 0) scissorTop = 0; + if (scissorTop < 0) + scissorTop = 0; scissorRight = bpmem.scissorBR.x - xoff - 341; - if (scissorRight > EFB_WIDTH) scissorRight = EFB_WIDTH; + if (scissorRight > EFB_WIDTH) + scissorRight = EFB_WIDTH; scissorBottom = bpmem.scissorBR.y - yoff - 341; - if (scissorBottom > EFB_HEIGHT) scissorBottom = EFB_HEIGHT; + if (scissorBottom > EFB_HEIGHT) + scissorBottom = EFB_HEIGHT; } void SetTevReg(int reg, int comp, bool konst, s16 color) -- cgit v1.2.3 From fbc64984ca7de7db10b1a8a4f49002f260c93569 Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Sun, 7 Sep 2014 20:06:58 -0500 Subject: Include CommonTypes.h instead of Common.h. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 3d002da810..4220bbb005 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -4,7 +4,7 @@ #include -#include "Common/Common.h" +#include "Common/CommonTypes.h" #include "VideoBackends/Software/BPMemLoader.h" #include "VideoBackends/Software/EfbInterface.h" #include "VideoBackends/Software/HwRasterizer.h" -- cgit v1.2.3 From 7f6284c2fcea9d543b0eec44ea0f3ad36bd0c0aa Mon Sep 17 00:00:00 2001 From: comex Date: Thu, 2 Oct 2014 02:20:46 -0400 Subject: Change a bunch of reference function arguments to pointers. Per the coding style and sanity. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 4220bbb005..5e8fdffd50 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -210,7 +210,7 @@ static void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, fl slope->f0 = f1; } -static inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) +static inline void CalculateLOD(s32* lodp, bool* linear, u32 texmap, u32 texcoord) { FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1]; u8 subTexmap = texmap & 3; @@ -240,20 +240,21 @@ static inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord } // get LOD in s28.4 - lod = FixedLog2(std::max(sDelta, tDelta)); + s32 lod = FixedLog2(std::max(sDelta, tDelta)); // bias is s2.5 int bias = tm0.lod_bias; bias >>= 1; lod += bias; - linear = ((lod > 0 && (tm0.min_filter & 4)) || (lod <= 0 && tm0.mag_filter)); + *linear = ((lod > 0 && (tm0.min_filter & 4)) || (lod <= 0 && tm0.mag_filter)); // order of checks matters // should be: // if lod > max then max // else if lod < min then min lod = CLAMP(lod, (s32)tm1.min_lod, (s32)tm1.max_lod); + *lodp = lod; } static void BuildBlock(s32 blockX, s32 blockY) @@ -295,7 +296,7 @@ static void BuildBlock(s32 blockX, s32 blockY) u32 texcoord = indref & 3; indref >>= 3; - CalculateLOD(rasterBlock.IndirectLod[i], rasterBlock.IndirectLinear[i], texmap, texcoord); + CalculateLOD(&rasterBlock.IndirectLod[i], &rasterBlock.IndirectLinear[i], texmap, texcoord); } for (unsigned int i = 0; i <= bpmem.genMode.numtevstages; i++) @@ -307,7 +308,7 @@ static void BuildBlock(s32 blockX, s32 blockY) u32 texmap = order.getTexMap(stageOdd); u32 texcoord = order.getTexCoord(stageOdd); - CalculateLOD(rasterBlock.TextureLod[i], rasterBlock.TextureLinear[i], texmap, texcoord); + CalculateLOD(&rasterBlock.TextureLod[i], &rasterBlock.TextureLinear[i], texmap, texcoord); } } } -- cgit v1.2.3 From 2d4b7e3f3f67f48ec2fb3d8eb8b2af3b70e4afcc Mon Sep 17 00:00:00 2001 From: crudelios Date: Sun, 14 Sep 2014 17:52:51 +0100 Subject: Reimplement Bounding Box calculation using the software renderer. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 293 +++++++++++++++++----- 1 file changed, 232 insertions(+), 61 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 5e8fdffd50..d797b9158e 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -14,6 +14,7 @@ #include "VideoBackends/Software/SWVideoConfig.h" #include "VideoBackends/Software/Tev.h" #include "VideoBackends/Software/XFMemLoader.h" +#include "VideoCommon/BoundingBox.h" #define BLOCK_SIZE 2 @@ -130,7 +131,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) if (z < 0 || z > 0x00ffffff) return; - if (bpmem.UseEarlyDepthTest() && g_SWVideoConfig.bZComploc) + if (!BoundingBox::active && bpmem.UseEarlyDepthTest() && g_SWVideoConfig.bZComploc) { // TODO: Test if perf regs are incremented even if test is disabled EfbInterface::IncPerfCounterQuadCount(PQ_ZCOMP_INPUT_ZCOMPLOC); @@ -317,7 +318,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer { INCSTAT(swstats.thisFrame.numTrianglesDrawn); - if (g_SWVideoConfig.bHwRasterizer) + if (g_SWVideoConfig.bHwRasterizer && !BoundingBox::active) { HwRasterizer::DrawTriangleFrontFace(v0, v1, v2); return; @@ -414,82 +415,252 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (DY23 < 0 || (DY23 == 0 && DX23 > 0)) C2++; if (DY31 < 0 || (DY31 == 0 && DX31 > 0)) C3++; - // Loop through blocks - for (s32 y = miny; y < maxy; y += BLOCK_SIZE) + // If drawing, rasterize every block + if (!BoundingBox::active) { - for (s32 x = minx; x < maxx; x += BLOCK_SIZE) + // Loop through blocks + for (s32 y = miny; y < maxy; y += BLOCK_SIZE) { - // Corners of block - s32 x0 = x << 4; - s32 x1 = (x + BLOCK_SIZE - 1) << 4; - s32 y0 = y << 4; - s32 y1 = (y + BLOCK_SIZE - 1) << 4; - - // Evaluate half-space functions - bool a00 = C1 + DX12 * y0 - DY12 * x0 > 0; - bool a10 = C1 + DX12 * y0 - DY12 * x1 > 0; - bool a01 = C1 + DX12 * y1 - DY12 * x0 > 0; - bool a11 = C1 + DX12 * y1 - DY12 * x1 > 0; - int a = (a00 << 0) | (a10 << 1) | (a01 << 2) | (a11 << 3); - - bool b00 = C2 + DX23 * y0 - DY23 * x0 > 0; - bool b10 = C2 + DX23 * y0 - DY23 * x1 > 0; - bool b01 = C2 + DX23 * y1 - DY23 * x0 > 0; - bool b11 = C2 + DX23 * y1 - DY23 * x1 > 0; - int b = (b00 << 0) | (b10 << 1) | (b01 << 2) | (b11 << 3); - - bool c00 = C3 + DX31 * y0 - DY31 * x0 > 0; - bool c10 = C3 + DX31 * y0 - DY31 * x1 > 0; - bool c01 = C3 + DX31 * y1 - DY31 * x0 > 0; - bool c11 = C3 + DX31 * y1 - DY31 * x1 > 0; - int c = (c00 << 0) | (c10 << 1) | (c01 << 2) | (c11 << 3); - - // Skip block when outside an edge - if (a == 0x0 || b == 0x0 || c == 0x0) - continue; - - BuildBlock(x, y); - - // Accept whole block when totally covered - if (a == 0xF && b == 0xF && c == 0xF) + for (s32 x = minx; x < maxx; x += BLOCK_SIZE) { - for (s32 iy = 0; iy < BLOCK_SIZE; iy++) + // Corners of block + s32 x0 = x << 4; + s32 x1 = (x + BLOCK_SIZE - 1) << 4; + s32 y0 = y << 4; + s32 y1 = (y + BLOCK_SIZE - 1) << 4; + + // Evaluate half-space functions + bool a00 = C1 + DX12 * y0 - DY12 * x0 > 0; + bool a10 = C1 + DX12 * y0 - DY12 * x1 > 0; + bool a01 = C1 + DX12 * y1 - DY12 * x0 > 0; + bool a11 = C1 + DX12 * y1 - DY12 * x1 > 0; + int a = (a00 << 0) | (a10 << 1) | (a01 << 2) | (a11 << 3); + + bool b00 = C2 + DX23 * y0 - DY23 * x0 > 0; + bool b10 = C2 + DX23 * y0 - DY23 * x1 > 0; + bool b01 = C2 + DX23 * y1 - DY23 * x0 > 0; + bool b11 = C2 + DX23 * y1 - DY23 * x1 > 0; + int b = (b00 << 0) | (b10 << 1) | (b01 << 2) | (b11 << 3); + + bool c00 = C3 + DX31 * y0 - DY31 * x0 > 0; + bool c10 = C3 + DX31 * y0 - DY31 * x1 > 0; + bool c01 = C3 + DX31 * y1 - DY31 * x0 > 0; + bool c11 = C3 + DX31 * y1 - DY31 * x1 > 0; + int c = (c00 << 0) | (c10 << 1) | (c01 << 2) | (c11 << 3); + + // Skip block when outside an edge + if (a == 0x0 || b == 0x0 || c == 0x0) + continue; + + BuildBlock(x, y); + + // Accept whole block when totally covered + if (a == 0xF && b == 0xF && c == 0xF) { - for (s32 ix = 0; ix < BLOCK_SIZE; ix++) + for (s32 iy = 0; iy < BLOCK_SIZE; iy++) { - Draw(x + ix, y + iy, ix, iy); + for (s32 ix = 0; ix < BLOCK_SIZE; ix++) + { + Draw(x + ix, y + iy, ix, iy); + } } } - } - else // Partially covered block - { - s32 CY1 = C1 + DX12 * y0 - DY12 * x0; - s32 CY2 = C2 + DX23 * y0 - DY23 * x0; - s32 CY3 = C3 + DX31 * y0 - DY31 * x0; - - for (s32 iy = 0; iy < BLOCK_SIZE; iy++) + else // Partially covered block { - s32 CX1 = CY1; - s32 CX2 = CY2; - s32 CX3 = CY3; + s32 CY1 = C1 + DX12 * y0 - DY12 * x0; + s32 CY2 = C2 + DX23 * y0 - DY23 * x0; + s32 CY3 = C3 + DX31 * y0 - DY31 * x0; - for (s32 ix = 0; ix < BLOCK_SIZE; ix++) + for (s32 iy = 0; iy < BLOCK_SIZE; iy++) { - if (CX1 > 0 && CX2 > 0 && CX3 > 0) + s32 CX1 = CY1; + s32 CX2 = CY2; + s32 CX3 = CY3; + + for (s32 ix = 0; ix < BLOCK_SIZE; ix++) { - Draw(x + ix, y + iy, ix, iy); + if (CX1 > 0 && CX2 > 0 && CX3 > 0) + { + Draw(x + ix, y + iy, ix, iy); + } + + CX1 -= FDY12; + CX2 -= FDY23; + CX3 -= FDY31; } - CX1 -= FDY12; - CX2 -= FDY23; - CX3 -= FDY31; + CY1 += FDX12; + CY2 += FDX23; + CY3 += FDX31; } + } + } + } + } + else + { + // If we are only calculating bbox, we only need to find the topmost, + // leftmost, bottom most and rightmost pixels to be drawn. + // So instead of drawing every single one of the triangle's pixels, + // four loops are run: one for the top pixel, one for the left, one for + // the bottom and one for the right. As soon as a pixel that is to be + // drawn is found, the loop breaks. This enables a ~150% speedbost in + // bbox calculation, albeit at the cost of some ugly repetitive code. + const s32 FTOP = miny << 4; + const s32 FLEFT = minx << 4; + const s32 FBOTTOM = maxy << 4; + const s32 FRIGHT = maxx << 4; + + // Start checking for bbox top + s32 CY1 = C1 + DX12 * FTOP - DY12 * FLEFT; + s32 CY2 = C2 + DX23 * FTOP - DY23 * FLEFT; + s32 CY3 = C3 + DX31 * FTOP - DY31 * FLEFT; + + // Loop + for (s32 y = miny; y <= maxy; ++y) + { + if (y >= BoundingBox::coords[BoundingBox::TOP]) + break; + + s32 CX1 = CY1; + s32 CX2 = CY2; + s32 CX3 = CY3; + + for (s32 x = minx; x <= maxx; ++x) + { + if (CX1 > 0 && CX2 > 0 && CX3 > 0) + { + // Build the new raster block every other pixel + BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); + + Draw(x, y, x & 1, y & 1); + + if (y >= BoundingBox::coords[BoundingBox::TOP]) + break; + } + + CX1 -= FDY12; + CX2 -= FDY23; + CX3 -= FDY31; + } + + CY1 += FDX12; + CY2 += FDX23; + CY3 += FDX31; + } + + // Checking for bbox left + s32 CX1 = C1 + DX12 * FTOP - DY12 * FLEFT; + s32 CX2 = C2 + DX23 * FTOP - DY23 * FLEFT; + s32 CX3 = C3 + DX31 * FTOP - DY31 * FLEFT; + + // Loop + for (s32 x = minx; x <= maxx; ++x) + { + if (x >= BoundingBox::coords[BoundingBox::LEFT]) + break; + + s32 CY1 = CX1; + s32 CY2 = CX2; + s32 CY3 = CX3; + + for (s32 y = miny; y <= maxy; ++y) + { + if (CY1 > 0 && CY2 > 0 && CY3 > 0) + { + // Build the new raster block every other pixel + BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); + + Draw(x, y, x & 1, y & 1); + + if (x >= BoundingBox::coords[BoundingBox::LEFT]) + break; + } + + CY1 += FDX12; + CY2 += FDX23; + CY3 += FDX31; + } + + CX1 -= FDY12; + CX2 -= FDY23; + CX3 -= FDY31; + } + + // Checking for bbox bottom + CY1 = C1 + DX12 * FBOTTOM - DY12 * FRIGHT; + CY2 = C2 + DX23 * FBOTTOM - DY23 * FRIGHT; + CY3 = C3 + DX31 * FBOTTOM - DY31 * FRIGHT; + + // Loop + for (s32 y = maxy; y >= miny; --y) + { + s32 CX1 = CY1; + s32 CX2 = CY2; + s32 CX3 = CY3; + + if (y <= BoundingBox::coords[BoundingBox::BOTTOM]) + break; + + for (s32 x = maxx; x >= minx; --x) + { + if (CX1 > 0 && CX2 > 0 && CX3 > 0) + { + // Build the new raster block every other pixel + BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); + + Draw(x, y, x & 1, y & 1); - CY1 += FDX12; - CY2 += FDX23; - CY3 += FDX31; + if (y <= BoundingBox::coords[BoundingBox::BOTTOM]) + break; } + + CX1 += FDY12; + CX2 += FDY23; + CX3 += FDY31; + } + + CY1 -= FDX12; + CY2 -= FDX23; + CY3 -= FDX31; + } + + // Checking for bbox right + CX1 = C1 + DX12 * FBOTTOM - DY12 * FRIGHT; + CX2 = C2 + DX23 * FBOTTOM - DY23 * FRIGHT; + CX3 = C3 + DX31 * FBOTTOM - DY31 * FRIGHT; + + // Loop + for (s32 x = maxx; x >= minx; --x) + { + if (x <= BoundingBox::coords[BoundingBox::RIGHT]) + break; + + s32 CY1 = CX1; + s32 CY2 = CX2; + s32 CY3 = CX3; + + for (s32 y = maxy; y >= miny; --y) + { + if (CY1 > 0 && CY2 > 0 && CY3 > 0) + { + // Build the new raster block every other pixel + BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); + + Draw(x, y, x & 1, y & 1); + + if (x <= BoundingBox::coords[BoundingBox::RIGHT]) + break; + } + + CY1 -= FDX12; + CY2 -= FDX23; + CY3 -= FDX31; } + + CX1 += FDY12; + CX2 += FDY23; + CX3 += FDY31; } } } -- cgit v1.2.3 From 47c67f014f9f882e27e29203eab97dc3c7753f6a Mon Sep 17 00:00:00 2001 From: crudelios Date: Tue, 16 Sep 2014 20:18:15 +0100 Subject: Fix linux build and various warnings. Increase savestate version. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index d797b9158e..6dfc61f9c5 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -533,7 +533,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Build the new raster block every other pixel BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - Draw(x, y, x & 1, y & 1); + Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (y >= BoundingBox::coords[BoundingBox::TOP]) break; @@ -560,9 +560,9 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (x >= BoundingBox::coords[BoundingBox::LEFT]) break; - s32 CY1 = CX1; - s32 CY2 = CX2; - s32 CY3 = CX3; + CY1 = CX1; + CY2 = CX2; + CY3 = CX3; for (s32 y = miny; y <= maxy; ++y) { @@ -571,7 +571,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Build the new raster block every other pixel BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - Draw(x, y, x & 1, y & 1); + Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (x >= BoundingBox::coords[BoundingBox::LEFT]) break; @@ -595,9 +595,9 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Loop for (s32 y = maxy; y >= miny; --y) { - s32 CX1 = CY1; - s32 CX2 = CY2; - s32 CX3 = CY3; + CX1 = CY1; + CX2 = CY2; + CX3 = CY3; if (y <= BoundingBox::coords[BoundingBox::BOTTOM]) break; @@ -609,7 +609,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Build the new raster block every other pixel BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - Draw(x, y, x & 1, y & 1); + Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (y <= BoundingBox::coords[BoundingBox::BOTTOM]) break; @@ -636,9 +636,9 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (x <= BoundingBox::coords[BoundingBox::RIGHT]) break; - s32 CY1 = CX1; - s32 CY2 = CX2; - s32 CY3 = CX3; + CY1 = CX1; + CY2 = CX2; + CY3 = CX3; for (s32 y = maxy; y >= miny; --y) { @@ -647,7 +647,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Build the new raster block every other pixel BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - Draw(x, y, x & 1, y & 1); + Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (x <= BoundingBox::coords[BoundingBox::RIGHT]) break; -- cgit v1.2.3 From 987bd8bb8fde2ed8c70384b8b3c38c5ba54b0227 Mon Sep 17 00:00:00 2001 From: crudelios Date: Fri, 26 Sep 2014 11:37:32 +0100 Subject: Several small optimizations. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 67 ++++++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 6dfc61f9c5..bd50c86e75 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -314,6 +314,22 @@ static void BuildBlock(s32 blockX, s32 blockY) } } +inline void PrepareBlock(s32 blockX, s32 blockY) +{ + static s32 x = -1; + static s32 y = -1; + + blockX &= ~(BLOCK_SIZE - 1); + blockY &= ~(BLOCK_SIZE - 1); + + if (x != blockX || y != blockY) + { + x = blockX; + y = blockY; + BuildBlock(x, y); + } +} + void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2) { INCSTAT(swstats.thisFrame.numTrianglesDrawn); @@ -401,10 +417,6 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer InitSlope(&TexSlopes[i][comp], v0->texCoords[i][comp] * w[0], v1->texCoords[i][comp] * w[1], v2->texCoords[i][comp] * w[2], fltdx31, fltdx12, fltdy12, fltdy31); } - // Start in corner of 8x8 block - minx &= ~(BLOCK_SIZE - 1); - miny &= ~(BLOCK_SIZE - 1); - // Half-edge constants s32 C1 = DY12 * X1 - DX12 * Y1; s32 C2 = DY23 * X2 - DX23 * Y2; @@ -418,6 +430,10 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // If drawing, rasterize every block if (!BoundingBox::active) { + // Start in corner of 8x8 block + minx &= ~(BLOCK_SIZE - 1); + miny &= ~(BLOCK_SIZE - 1); + // Loop through blocks for (s32 y = miny; y < maxy; y += BLOCK_SIZE) { @@ -499,8 +515,25 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer } else { - // If we are only calculating bbox, we only need to find the topmost, - // leftmost, bottom most and rightmost pixels to be drawn. + // Calculating bbox + // First check for alpha channel - don't do anything it if always fails, + // Change bbox to primitive size if it always passes + AlphaTest::TEST_RESULT alphaRes = bpmem.alpha_test.TestResult(); + + if (alphaRes != AlphaTest::UNDETERMINED) + { + if (alphaRes == AlphaTest::PASS) + { + BoundingBox::coords[BoundingBox::TOP] = std::min(BoundingBox::coords[BoundingBox::TOP], (u16) miny); + BoundingBox::coords[BoundingBox::LEFT] = std::min(BoundingBox::coords[BoundingBox::LEFT], (u16) minx); + BoundingBox::coords[BoundingBox::BOTTOM] = std::max(BoundingBox::coords[BoundingBox::BOTTOM], (u16) maxy); + BoundingBox::coords[BoundingBox::RIGHT] = std::max(BoundingBox::coords[BoundingBox::RIGHT], (u16) maxx); + } + return; + } + + // If we are calculating bbox with alpha, we only need to find the + // topmost, leftmost, bottom most and rightmost pixels to be drawn. // So instead of drawing every single one of the triangle's pixels, // four loops are run: one for the top pixel, one for the left, one for // the bottom and one for the right. As soon as a pixel that is to be @@ -531,8 +564,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (CX1 > 0 && CX2 > 0 && CX3 > 0) { // Build the new raster block every other pixel - BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - + PrepareBlock(x, y); Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (y >= BoundingBox::coords[BoundingBox::TOP]) @@ -549,6 +581,9 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer CY3 += FDX31; } + // Update top limit + miny = std::max((s32) BoundingBox::coords[BoundingBox::TOP], miny); + // Checking for bbox left s32 CX1 = C1 + DX12 * FTOP - DY12 * FLEFT; s32 CX2 = C2 + DX23 * FTOP - DY23 * FLEFT; @@ -568,9 +603,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer { if (CY1 > 0 && CY2 > 0 && CY3 > 0) { - // Build the new raster block every other pixel - BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - + PrepareBlock(x, y); Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (x >= BoundingBox::coords[BoundingBox::LEFT]) @@ -587,6 +620,9 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer CX3 -= FDY31; } + // Update left limit + minx = std::max((s32) BoundingBox::coords[BoundingBox::LEFT], minx); + // Checking for bbox bottom CY1 = C1 + DX12 * FBOTTOM - DY12 * FRIGHT; CY2 = C2 + DX23 * FBOTTOM - DY23 * FRIGHT; @@ -607,8 +643,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (CX1 > 0 && CX2 > 0 && CX3 > 0) { // Build the new raster block every other pixel - BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - + PrepareBlock(x, y); Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (y <= BoundingBox::coords[BoundingBox::BOTTOM]) @@ -625,6 +660,9 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer CY3 -= FDX31; } + // Update bottom limit + maxy = std::min((s32) BoundingBox::coords[BoundingBox::BOTTOM], maxy); + // Checking for bbox right CX1 = C1 + DX12 * FBOTTOM - DY12 * FRIGHT; CX2 = C2 + DX23 * FBOTTOM - DY23 * FRIGHT; @@ -645,8 +683,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer if (CY1 > 0 && CY2 > 0 && CY3 > 0) { // Build the new raster block every other pixel - BuildBlock((x & ~(BLOCK_SIZE - 1)), y & ~(BLOCK_SIZE - 1)); - + PrepareBlock(x, y); Draw(x, y, x & (BLOCK_SIZE - 1), y & (BLOCK_SIZE - 1)); if (x <= BoundingBox::coords[BoundingBox::RIGHT]) -- cgit v1.2.3 From 9786f5441467e2103ed07cfe387fe6029f84f200 Mon Sep 17 00:00:00 2001 From: crudelios Date: Mon, 6 Oct 2014 22:19:12 +0100 Subject: Fixed a small bug. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index bd50c86e75..c03062134b 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -314,7 +314,7 @@ static void BuildBlock(s32 blockX, s32 blockY) } } -inline void PrepareBlock(s32 blockX, s32 blockY) +static inline void PrepareBlock(s32 blockX, s32 blockY) { static s32 x = -1; static s32 y = -1; @@ -539,10 +539,10 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // the bottom and one for the right. As soon as a pixel that is to be // drawn is found, the loop breaks. This enables a ~150% speedbost in // bbox calculation, albeit at the cost of some ugly repetitive code. - const s32 FTOP = miny << 4; const s32 FLEFT = minx << 4; - const s32 FBOTTOM = maxy << 4; const s32 FRIGHT = maxx << 4; + s32 FTOP = miny << 4; + s32 FBOTTOM = maxy << 4; // Start checking for bbox top s32 CY1 = C1 + DX12 * FTOP - DY12 * FLEFT; @@ -583,6 +583,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Update top limit miny = std::max((s32) BoundingBox::coords[BoundingBox::TOP], miny); + FTOP = miny << 4; // Checking for bbox left s32 CX1 = C1 + DX12 * FTOP - DY12 * FLEFT; @@ -662,6 +663,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // Update bottom limit maxy = std::min((s32) BoundingBox::coords[BoundingBox::BOTTOM], maxy); + FBOTTOM = maxy << 4; // Checking for bbox right CX1 = C1 + DX12 * FBOTTOM - DY12 * FRIGHT; -- cgit v1.2.3 From ef789410429d0fc20a68fd8f7aca0ecc42695bf6 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 16 May 2015 21:25:52 +0200 Subject: VideoBackends: Clamp depth to uint24 range. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index c03062134b..b7877dcaaa 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -127,9 +127,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) float dx = vertexOffsetX + (float)(x - vertex0X); float dy = vertexOffsetY + (float)(y - vertex0Y); - s32 z = (s32)ZSlope.GetValue(dx, dy); - if (z < 0 || z > 0x00ffffff) - return; + s32 z = (s32)MathUtil::Clamp(ZSlope.GetValue(dx, dy), 0.0f, 16777215.0f); if (!BoundingBox::active && bpmem.UseEarlyDepthTest() && g_SWVideoConfig.bZComploc) { -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index b7877dcaaa..98c8fe4723 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/Software/Rasterizer.cpp') diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 98c8fe4723..4a04e02f7c 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2009 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3