Skip to content

Commit

Permalink
Merge pull request #779 from lioncash/software-cleanup
Browse files Browse the repository at this point in the history
Small software backend cleanup.
  • Loading branch information
neobrain committed Aug 12, 2014
2 parents a46151e + bcd10bf commit d03e919
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 191 deletions.
45 changes: 33 additions & 12 deletions Source/Core/VideoBackends/Software/Clipper.cpp
Expand Up @@ -45,7 +45,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace Clipper
{
enum { NUM_CLIPPED_VERTICES = 33, NUM_INDICES = NUM_CLIPPED_VERTICES + 3 };
enum
{
NUM_CLIPPED_VERTICES = 33,
NUM_INDICES = NUM_CLIPPED_VERTICES + 3
};

static float m_ViewOffset[2];

Expand All @@ -72,7 +76,8 @@ namespace Clipper
}


enum {
enum
{
SKIP_FLAG = -1,
CLIP_POS_X_BIT = 0x01,
CLIP_NEG_X_BIT = 0x02,
Expand All @@ -86,12 +91,25 @@ namespace Clipper
{
int cmask = 0;
Vec4 pos = v->projectedPosition;
if (pos.w - pos.x < 0) cmask |= CLIP_POS_X_BIT;
if (pos.x + pos.w < 0) cmask |= CLIP_NEG_X_BIT;
if (pos.w - pos.y < 0) cmask |= CLIP_POS_Y_BIT;
if (pos.y + pos.w < 0) cmask |= CLIP_NEG_Y_BIT;
if (pos.w * pos.z > 0) cmask |= CLIP_POS_Z_BIT;
if (pos.z + pos.w < 0) cmask |= CLIP_NEG_Z_BIT;

if (pos.w - pos.x < 0)
cmask |= CLIP_POS_X_BIT;

if (pos.x + pos.w < 0)
cmask |= CLIP_NEG_X_BIT;

if (pos.w - pos.y < 0)
cmask |= CLIP_POS_Y_BIT;

if (pos.y + pos.w < 0)
cmask |= CLIP_NEG_Y_BIT;

if (pos.w * pos.z > 0)
cmask |= CLIP_POS_Z_BIT;

if (pos.z + pos.w < 0)
cmask |= CLIP_NEG_Z_BIT;

return cmask;
}

Expand Down Expand Up @@ -209,7 +227,8 @@ namespace Clipper
indices[0] = inlist[0];
indices[1] = inlist[1];
indices[2] = inlist[2];
for (int j = 3; j < n; ++j) {
for (int j = 3; j < n; ++j)
{
indices[numIndices++] = inlist[0];
indices[numIndices++] = inlist[j - 1];
indices[numIndices++] = inlist[j];
Expand Down Expand Up @@ -276,9 +295,11 @@ namespace Clipper
if (!CullTest(v0, v1, v2, backface))
return;

int indices[NUM_INDICES] = { 0, 1, 2, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG };
int indices[NUM_INDICES] = {
0, 1, 2, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG
};
int numIndices = 3;

if (backface)
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/VideoBackends/Software/DebugUtil.cpp
Expand Up @@ -25,18 +25,18 @@ namespace DebugUtil

static bool drawingHwTriangles = false;

enum { NumObjectBuffers = 40};
static const int NUM_OBJECT_BUFFERS = 40;

static u32 *ObjectBuffer[NumObjectBuffers];
static u32 TempBuffer[NumObjectBuffers];
static u32 *ObjectBuffer[NUM_OBJECT_BUFFERS];
static u32 TempBuffer[NUM_OBJECT_BUFFERS];

static bool DrawnToBuffer[NumObjectBuffers];
static const char* ObjectBufferName[NumObjectBuffers];
static int BufferBase[NumObjectBuffers];
static bool DrawnToBuffer[NUM_OBJECT_BUFFERS];
static const char* ObjectBufferName[NUM_OBJECT_BUFFERS];
static int BufferBase[NUM_OBJECT_BUFFERS];

void Init()
{
for (int i = 0; i < NumObjectBuffers; i++)
for (int i = 0; i < NUM_OBJECT_BUFFERS; i++)
{
ObjectBuffer[i] = new u32[EFB_WIDTH*EFB_HEIGHT]();
DrawnToBuffer[i] = false;
Expand All @@ -47,7 +47,7 @@ void Init()

void Shutdown()
{
for (int i = 0; i < NumObjectBuffers; i++)
for (int i = 0; i < NUM_OBJECT_BUFFERS; i++)
{
delete[] ObjectBuffer[i];
}
Expand Down Expand Up @@ -159,7 +159,7 @@ static void DumpEfb(const std::string& filename)

static void DumpColorTexture(const std::string& filename, u32 width, u32 height)
{
TextureToPng(SWRenderer::getCurrentColorTexture(), width * 4, filename, width, height, true);
TextureToPng(SWRenderer::GetCurrentColorTexture(), width * 4, filename, width, height, true);
}

void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name)
Expand Down Expand Up @@ -229,7 +229,7 @@ void OnObjectEnd()
drawingHwTriangles = false;
}

for (int i = 0; i < NumObjectBuffers; i++)
for (int i = 0; i < NUM_OBJECT_BUFFERS; i++)
{
if (DrawnToBuffer[i])
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Software/EfbCopy.cpp
Expand Up @@ -45,12 +45,12 @@ namespace EfbCopy
else
{
// Ask SWRenderer for the next color texture
u8 *colorTexture = SWRenderer::getNextColorTexture();
u8 *colorTexture = SWRenderer::GetNextColorTexture();

EfbInterface::BypassXFB(colorTexture, fbWidth, fbHeight, sourceRc, Gamma);

// Tell SWRenderer we are now finished with it.
SWRenderer::swapColorTexture();
SWRenderer::SwapColorTexture();

// FifoPlayer is broken and never calls BeginFrame/EndFrame.
// Hence, we manually force a swap now. This emulates the behavior
Expand Down
16 changes: 10 additions & 6 deletions Source/Core/VideoBackends/Software/EfbInterface.cpp
Expand Up @@ -20,12 +20,12 @@ namespace EfbInterface
{
u32 perf_values[PQ_NUM_MEMBERS];

inline u32 GetColorOffset(u16 x, u16 y)
static inline u32 GetColorOffset(u16 x, u16 y)
{
return (x + y * EFB_WIDTH) * 3;
}

inline u32 GetDepthOffset(u16 x, u16 y)
static inline u32 GetDepthOffset(u16 x, u16 y)
{
return (x + y * EFB_WIDTH) * 3 + DEPTH_BUFFER_START;
}
Expand Down Expand Up @@ -498,7 +498,8 @@ namespace EfbInterface
return &efb[GetColorOffset(x, y)];
}

void CopyToXFB(yuv422_packed* xfb_in_ram, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma) {
void CopyToXFB(yuv422_packed* xfb_in_ram, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
{
// FIXME: We should do Gamma correction

if (!xfb_in_ram)
Expand All @@ -512,7 +513,8 @@ namespace EfbInterface

// this assumes copies will always start on an even (YU) pixel and the
// copy always has an even width, which might not be true.
if (left & 1 || right & 1) {
if (left & 1 || right & 1)
{
WARN_LOG(VIDEO, "Trying to copy XFB to from unaligned EFB source");
// this will show up as wrongly encoded
}
Expand Down Expand Up @@ -557,8 +559,10 @@ namespace EfbInterface
}

// Like CopyToXFB, but we copy directly into the opengl colour texture without going via GameCube main memory or doing a yuyv conversion
void BypassXFB(u8* texture, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma) {
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT) {
void BypassXFB(u8* texture, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
{
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT)
{
ERROR_LOG(VIDEO, "Framebuffer is too large: %ix%i", fbWidth, fbHeight);
return;
}
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/VideoBackends/Software/EfbInterface.h
Expand Up @@ -27,7 +27,13 @@ namespace EfbInterface
s8 V;
};

enum { ALP_C, BLU_C, GRN_C, RED_C };
enum
{
ALP_C,
BLU_C,
GRN_C,
RED_C
};

// color order is ABGR in order to emulate RGBA on little-endian hardware

Expand Down
8 changes: 7 additions & 1 deletion Source/Core/VideoBackends/Software/NativeVertexFormat.h
Expand Up @@ -37,7 +37,13 @@ struct InputVertexData
struct OutputVertexData
{
// components in color channels
enum { RED_C, GRN_C, BLU_C, ALP_C };
enum
{
RED_C,
GRN_C,
BLU_C,
ALP_C
};

Vec3 mvPosition;
Vec4 projectedPosition;
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/VideoBackends/Software/RasterFont.cpp
Expand Up @@ -161,7 +161,7 @@ void RasterFont::printString(const char *s, double x, double y, double z)
void RasterFont::printCenteredString(const char *s, double y, int screen_width, double z)
{
int length = (int)strlen(s);
int x = (int)(screen_width/2.0 - (length/2.0)*char_width);
int x = (int)(screen_width/2.0 - (length/2.0) * CHAR_WIDTH);
printString(s, x, y, z);
}

Expand All @@ -177,7 +177,7 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
{
*t = 0;
printString(temp, x, y, z);
y -= char_height * 2.0f / bbHeight;
y -= CHAR_HEIGHT * 2.0f / bbHeight;
x = start_x;
t = temp;
}
Expand All @@ -187,12 +187,12 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
}
else if (*text == '\t')
{
//todo: add tabs every something like 4*char_width
//todo: add tabs every something like 4 * CHAR_WIDTH
*t = 0;
int cpos = (int)strlen(temp);
int newpos = (cpos + 4) & (~3);
printString(temp, x, y, z);
x = start_x + (char_width*newpos) * 2.0f / bbWidth;
x = start_x + (CHAR_WIDTH * newpos) * 2.0f / bbWidth;
t = temp;
*t++ = ' ';
}
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoBackends/Software/RasterFont.h
Expand Up @@ -11,17 +11,17 @@ class RasterFont
~RasterFont(void);
static int debug;

// some useful constants
enum {char_width = 10};
enum {char_height = 15};

// and the happy helper functions
void printString(const char *s, double x, double y, double z=0.0);
void printCenteredString(const char *s, double y, int screen_width, double z=0.0);

void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight);

private:
int fontOffset;
char *temp_buffer;
enum {TEMP_BUFFER_SIZE = 64 * 1024};

static const int TEMP_BUFFER_SIZE = 64 * 1024;
static const int CHAR_WIDTH = 10;
static const int CHAR_HEIGHT = 15;
};
20 changes: 11 additions & 9 deletions Source/Core/VideoBackends/Software/Rasterizer.cpp
Expand Up @@ -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;

Expand All @@ -100,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)
Expand Down Expand Up @@ -208,7 +210,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;
Expand Down
23 changes: 17 additions & 6 deletions Source/Core/VideoBackends/Software/SWCommandProcessor.cpp
Expand Up @@ -61,19 +61,30 @@ void DoState(PointerWrap &p)
}

// does it matter that there is no synchronization between threads during writes?
inline void WriteLow (u32& _reg, u16 lowbits) {_reg = (_reg & 0xFFFF0000) | lowbits;}
inline void WriteHigh(u32& _reg, u16 highbits) {_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);}

inline u16 ReadLow (u32 _reg) {return (u16)(_reg & 0xFFFF);}
inline u16 ReadHigh (u32 _reg) {return (u16)(_reg >> 16);}
static inline void WriteLow (u32& _reg, u16 lowbits)
{
_reg = (_reg & 0xFFFF0000) | lowbits;
}
static inline void WriteHigh(u32& _reg, u16 highbits)
{
_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);
}

static inline u16 ReadLow(u32 _reg)
{
return (u16)(_reg & 0xFFFF);
}
static inline u16 ReadHigh(u32 _reg)
{
return (u16)(_reg >> 16);
}

static void UpdateInterrupts_Wrapper(u64 userdata, int cyclesLate)
{
UpdateInterrupts(userdata);
}

inline bool AtBreakpoint()
static inline bool AtBreakpoint()
{
return cpreg.ctrl.BPEnable && (cpreg.readptr == cpreg.breakpt);
}
Expand Down

0 comments on commit d03e919

Please sign in to comment.