128 changes: 61 additions & 67 deletions Source/Core/VideoCommon/Src/GenericTextureDecoder.cpp

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions Source/Core/VideoCommon/Src/ImageWrite.cpp
Expand Up @@ -25,22 +25,22 @@

struct TGA_HEADER
{
u8 identsize; // size of ID field that follows 18 u8 header (0 usually)
u8 colourmaptype; // type of colour map 0=none, 1=has palette
u8 imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed

s16 colourmapstart; // first colour map entry in palette
s16 colourmaplength; // number of colours in palette
u8 colourmapbits; // number of bits per palette entry 15,16,24,32

s16 xstart; // image x origin
s16 ystart; // image y origin
s16 width; // image width in pixels
s16 height; // image height in pixels
u8 bits; // image bits per pixel 8,16,24,32
u8 descriptor; // image descriptor bits (vh flip bits)
// pixel data follows header
u8 identsize; // size of ID field that follows 18 u8 header (0 usually)
u8 colourmaptype; // type of colour map 0=none, 1=has palette
u8 imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed

s16 colourmapstart; // first colour map entry in palette
s16 colourmaplength; // number of colours in palette
u8 colourmapbits; // number of bits per palette entry 15,16,24,32

s16 xstart; // image x origin
s16 ystart; // image y origin
s16 width; // image width in pixels
s16 height; // image height in pixels
u8 bits; // image bits per pixel 8,16,24,32
u8 descriptor; // image descriptor bits (vh flip bits)
// pixel data follows header
};

#pragma pack(pop)
Expand All @@ -53,7 +53,7 @@ bool SaveTGA(const char* filename, int width, int height, void* pdata)
return false;

_assert_(sizeof(TGA_HEADER) == 18 && sizeof(hdr) == 18);

memset(&hdr, 0, sizeof(hdr));
hdr.imagetype = 2;
hdr.bits = 32;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/IndexGenerator.cpp
Expand Up @@ -63,7 +63,7 @@ void IndexGenerator::AddIndices(int primitive, u32 numVerts)
//case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVerts); break;
//case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVerts); break;
//case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVerts); break;
//case GX_DRAW_LINES: IndexGenerator::AddLineList(numVerts); break;
//case GX_DRAW_LINES: IndexGenerator::AddLineList(numVerts); break;
//case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVerts); break;
//case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVerts); break;
//}
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/VideoCommon/Src/IndexGenerator.h
Expand Up @@ -27,17 +27,17 @@ class IndexGenerator
public:
// Init
static void Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr);

static void AddIndices(int primitive, u32 numVertices);

// Interface
static u32 GetNumTriangles() {return numT;}
static u32 GetNumLines() {return numL;}
static u32 GetNumPoints() {return numP;}

// returns numprimitives
static u32 GetNumVerts() {return index;}

static u32 GetTriangleindexLen() {return (u32)(Tptr - BASETptr);}
static u32 GetLineindexLen() {return (u32)(Lptr - BASELptr);}
static u32 GetPointindexLen() {return (u32)(Pptr - BASEPptr);}
Expand All @@ -56,16 +56,16 @@ class IndexGenerator
static void AddStrip(u32 numVerts);
static void AddFan(u32 numVerts);
static void AddQuads(u32 numVerts);

// Lines
static void AddLineList(u32 numVerts);
static void AddLineStrip(u32 numVerts);

// Points
static void AddPoints(u32 numVerts);

static void WriteTriangle(u32 index1, u32 index2, u32 index3);

static u16 *Tptr;
static u16 *BASETptr;
static u16 *Lptr;
Expand Down
390 changes: 195 additions & 195 deletions Source/Core/VideoCommon/Src/OpcodeDecoding.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/OpcodeDecoding.h
Expand Up @@ -44,7 +44,7 @@
#define GX_DRAW_LINES 0x5 // 0xA8
#define GX_DRAW_LINE_STRIP 0x6 // 0xB0
#define GX_DRAW_POINTS 0x7 // 0xB8
#define GX_DRAW_NONE 0x1; //Tis is a fake value to used in the backends
#define GX_DRAW_NONE 0x1; //Tis is a fake value to used in the backends

extern bool g_bRecordFifoData;

Expand Down
30 changes: 15 additions & 15 deletions Source/Core/VideoCommon/Src/OpenCL.cpp
Expand Up @@ -148,25 +148,25 @@ cl_program CompileProgram(const char *Kernel)
// Build the program executable
err = clBuildProgram(program , 0, NULL, NULL, NULL, NULL);
if(err != CL_SUCCESS) {
HandleCLError(err, "Error: failed to build program");
HandleCLError(err, "Error: failed to build program");

char *buildlog = NULL;
size_t buildlog_size = 0;
size_t buildlog_size = 0;

clGetProgramBuildInfo(program, OpenCL::device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &buildlog_size);
buildlog = new char[buildlog_size + 1];
err = clGetProgramBuildInfo(program, OpenCL::device_id, CL_PROGRAM_BUILD_LOG, buildlog_size, buildlog, NULL);
buildlog[buildlog_size] = 0;
if(err != CL_SUCCESS)
{
HandleCLError(err, "Error: can't get build log");
} else
{
ERROR_LOG(COMMON, "Error log:\n%s\n", buildlog);
}

delete[] buildlog;
buildlog = new char[buildlog_size + 1];
err = clGetProgramBuildInfo(program, OpenCL::device_id, CL_PROGRAM_BUILD_LOG, buildlog_size, buildlog, NULL);
buildlog[buildlog_size] = 0;
if(err != CL_SUCCESS)
{
HandleCLError(err, "Error: can't get build log");
} else
{
ERROR_LOG(COMMON, "Error log:\n%s\n", buildlog);
}

delete[] buildlog;
return NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp
Expand Up @@ -98,7 +98,7 @@ void TexDecoder_OpenCL_Initialize()
size_t nDevices = 0;
cl_device_id *devices = NULL;
size_t *binary_sizes = NULL;
char **binaries = NULL;
char **binaries = NULL;
std::string filename;
char dolphin_rev[HEADER_SIZE];

Expand Down Expand Up @@ -132,7 +132,7 @@ void TexDecoder_OpenCL_Initialize()
{
OpenCL::HandleCLError(err, "clCreateProgramWithBinary");
}

if (!err)
{
err = clBuildProgram(g_program, 1, &OpenCL::device_id, NULL, NULL, NULL);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/Src/PixelEngine.cpp
Expand Up @@ -126,8 +126,8 @@ bool bbox_active;

enum
{
INT_CAUSE_PE_TOKEN = 0x200, // GP Token
INT_CAUSE_PE_FINISH = 0x400, // GP Finished
INT_CAUSE_PE_TOKEN = 0x200, // GP Token
INT_CAUSE_PE_FINISH = 0x400, // GP Finished
};

void DoState(PointerWrap &p)
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/VideoCommon/Src/PixelEngine.h
Expand Up @@ -24,13 +24,13 @@ class PointerWrap;
// internal hardware addresses
enum
{
PE_ZCONF = 0x00, // Z Config
PE_ALPHACONF = 0x02, // Alpha Config
PE_DSTALPHACONF = 0x04, // Destination Alpha Config
PE_ALPHAMODE = 0x06, // Alpha Mode Config
PE_ALPHAREAD = 0x08, // Alpha Read
PE_ZCONF = 0x00, // Z Config
PE_ALPHACONF = 0x02, // Alpha Config
PE_DSTALPHACONF = 0x04, // Destination Alpha Config
PE_ALPHAMODE = 0x06, // Alpha Mode Config
PE_ALPHAREAD = 0x08, // Alpha Read
PE_CTRL_REGISTER = 0x0a, // Control
PE_TOKEN_REG = 0x0e, // Token
PE_TOKEN_REG = 0x0e, // Token
PE_BBOX_LEFT = 0x10, // Flip Left
PE_BBOX_RIGHT = 0x12, // Flip Right
PE_BBOX_TOP = 0x14, // Flip Top
Expand Down
44 changes: 22 additions & 22 deletions Source/Core/VideoCommon/Src/PixelShaderGen.cpp
Expand Up @@ -374,38 +374,38 @@ static const char *tevOpTable[] = { // TEV

static const char *tevCInputTable[] = // CC
{
"(prev.rgb)", // CPREV,
"(prev.rgb)", // CPREV,
"(prev.aaa)", // APREV,
"(c0.rgb)", // C0,
"(c0.rgb)", // C0,
"(c0.aaa)", // A0,
"(c1.rgb)", // C1,
"(c1.rgb)", // C1,
"(c1.aaa)", // A1,
"(c2.rgb)", // C2,
"(c2.rgb)", // C2,
"(c2.aaa)", // A2,
"(textemp.rgb)", // TEXC,
"(textemp.rgb)", // TEXC,
"(textemp.aaa)", // TEXA,
"(rastemp.rgb)", // RASC,
"(rastemp.rgb)", // RASC,
"(rastemp.aaa)", // RASA,
"float3(1.0f, 1.0f, 1.0f)", // ONE
"float3(0.5f, 0.5f, 0.5f)", // HALF
"(konsttemp.rgb)", //"konsttemp.rgb", // KONST
"float3(0.5f, 0.5f, 0.5f)", // HALF
"(konsttemp.rgb)", //"konsttemp.rgb", // KONST
"float3(0.0f, 0.0f, 0.0f)", // ZERO
///aded extra values to map clamped values
"(cprev.rgb)", // CPREV,
"(cprev.aaa)", // APREV,
"(cc0.rgb)", // C0,
"(cc0.aaa)", // A0,
"(cc1.rgb)", // C1,
"(cc1.aaa)", // A1,
"(cc2.rgb)", // C2,
"(cc2.aaa)", // A2,
"(textemp.rgb)", // TEXC,
"(cprev.rgb)", // CPREV,
"(cprev.aaa)", // APREV,
"(cc0.rgb)", // C0,
"(cc0.aaa)", // A0,
"(cc1.rgb)", // C1,
"(cc1.aaa)", // A1,
"(cc2.rgb)", // C2,
"(cc2.aaa)", // A2,
"(textemp.rgb)", // TEXC,
"(textemp.aaa)", // TEXA,
"(crastemp.rgb)", // RASC,
"(crastemp.aaa)", // RASA,
"(crastemp.rgb)", // RASC,
"(crastemp.aaa)", // RASA,
"float3(1.0f, 1.0f, 1.0f)", // ONE
"float3(0.5f, 0.5f, 0.5f)", // HALF
"(ckonsttemp.rgb)", //"konsttemp.rgb", // KONST
"float3(0.5f, 0.5f, 0.5f)", // HALF
"(ckonsttemp.rgb)", //"konsttemp.rgb", // KONST
"float3(0.0f, 0.0f, 0.0f)", // ZERO
"PADERROR1", "PADERROR2", "PADERROR3", "PADERROR4"
};
Expand All @@ -425,7 +425,7 @@ static const char *tevAInputTable[] = // CA
"cc0", // A0,
"cc1", // A1,
"cc2", // A2,
"textemp", // TEXA,
"textemp", // TEXA,
"crastemp", // RASA,
"ckonsttemp", // KONST, (hw1 had quarter)
"float4(0.0f, 0.0f, 0.0f, 0.0f)", // ZERO
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/Src/PixelShaderGen.h
Expand Up @@ -28,8 +28,8 @@
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOG "cfog"
#define I_PLIGHTS "cPLights"
#define I_PMATERIALS "cPmtrl"
#define I_PLIGHTS "cPLights"
#define I_PMATERIALS "cPmtrl"

#define C_COLORMATRIX 0 // 0
#define C_COLORS 0 // 0
Expand Down
222 changes: 111 additions & 111 deletions Source/Core/VideoCommon/Src/PixelShaderManager.cpp
Expand Up @@ -87,61 +87,61 @@ void PixelShaderManager::SetConstants()
{
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
Dirty();
for (int i = 0; i < 2; ++i)
for (int i = 0; i < 2; ++i)
{
if (s_nColorsChanged[i])
if (s_nColorsChanged[i])
{
int baseind = i ? C_KCOLORS : C_COLORS;
for (int j = 0; j < 4; ++j)
int baseind = i ? C_KCOLORS : C_COLORS;
for (int j = 0; j < 4; ++j)
{
if (s_nColorsChanged[i] & (1 << j))
SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]);
}
s_nColorsChanged[i] = 0;
}
}

if (s_nTexDimsChanged)
if (s_nColorsChanged[i] & (1 << j))
SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]);
}
s_nColorsChanged[i] = 0;
}
}

if (s_nTexDimsChanged)
{
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 8; ++i)
{
if (s_nTexDimsChanged & (1<<i))
if (s_nTexDimsChanged & (1<<i))
SetPSTextureDims(i);
}
s_nTexDimsChanged = 0;
}
}
s_nTexDimsChanged = 0;
}

if (s_bAlphaChanged)
if (s_bAlphaChanged)
{
SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f);
s_bAlphaChanged = false;
}
}

if (s_bZTextureTypeChanged)
{
float ftemp[4];
switch (bpmem.ztex2.type)
float ftemp[4];
switch (bpmem.ztex2.type)
{
case 0:
// 8 bits
ftemp[0] = 0; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 255.0f/16777215.0f;
break;
case 1:
// 16 bits
ftemp[0] = 255.0f/16777215.0f; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 65280.0f/16777215.0f;
break;
case 2:
// 24 bits
case 0:
// 8 bits
ftemp[0] = 0; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 255.0f/16777215.0f;
break;
case 1:
// 16 bits
ftemp[0] = 255.0f/16777215.0f; ftemp[1] = 0; ftemp[2] = 0; ftemp[3] = 65280.0f/16777215.0f;
break;
case 2:
// 24 bits
ftemp[0] = 16711680.0f/16777215.0f; ftemp[1] = 65280.0f/16777215.0f; ftemp[2] = 255.0f/16777215.0f; ftemp[3] = 0;
break;
}
break;
}
SetPSConstant4fv(C_ZBIAS, ftemp);
s_bZTextureTypeChanged = false;
}

if (s_bZBiasChanged || s_bDepthRangeChanged)
{
// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
// [0] = width/2
// [1] = height/2
// [2] = 16777215 * (farz - nearz)
Expand All @@ -152,78 +152,78 @@ void PixelShaderManager::SetConstants()
//ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias);
SetPSConstant4f(C_ZBIAS+1, xfregs.viewport.farZ / 16777216.0f, xfregs.viewport.zRange / 16777216.0f, 0, (float)(lastZBias)/16777215.0f);
s_bZBiasChanged = s_bDepthRangeChanged = false;
}
}

// indirect incoming texture scales
if (s_nIndTexScaleChanged)
// indirect incoming texture scales
if (s_nIndTexScaleChanged)
{
// set as two sets of vec4s, each containing S and T of two ind stages.
float f[8];
float f[8];

if (s_nIndTexScaleChanged & 0x03)
if (s_nIndTexScaleChanged & 0x03)
{
for (u32 i = 0; i < 2; ++i)
for (u32 i = 0; i < 2; ++i)
{
f[2 * i] = bpmem.texscale[0].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[0].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
}
f[2 * i] = bpmem.texscale[0].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[0].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
}
SetPSConstant4fv(C_INDTEXSCALE, f);
}

if (s_nIndTexScaleChanged & 0x0c) {
for (u32 i = 2; i < 4; ++i) {
f[2 * i] = bpmem.texscale[1].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[1].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
}
}

if (s_nIndTexScaleChanged & 0x0c) {
for (u32 i = 2; i < 4; ++i) {
f[2 * i] = bpmem.texscale[1].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[1].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
}
SetPSConstant4fv(C_INDTEXSCALE+1, &f[4]);
}
}

s_nIndTexScaleChanged = 0;
}
s_nIndTexScaleChanged = 0;
}

if (s_nIndTexMtxChanged)
if (s_nIndTexMtxChanged)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i)
{
if (s_nIndTexMtxChanged & (1 << i))
if (s_nIndTexMtxChanged & (1 << i))
{
int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) |
((u32)bpmem.indmtx[i].col1.s1 << 2) |
((u32)bpmem.indmtx[i].col2.s2 << 4);
float fscale = powf(2.0f, (float)(scale - 17)) / 1024.0f;

// xyz - static matrix
// TODO w - dynamic matrix scale / 256...... somehow / 4 works better
// rev 2972 - now using / 256.... verify that this works
int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) |
((u32)bpmem.indmtx[i].col1.s1 << 2) |
((u32)bpmem.indmtx[i].col2.s2 << 4);
float fscale = powf(2.0f, (float)(scale - 17)) / 1024.0f;

// xyz - static matrix
// TODO w - dynamic matrix scale / 256...... somehow / 4 works better
// rev 2972 - now using / 256.... verify that this works
SetPSConstant4f(C_INDTEXMTX + 2 * i,
bpmem.indmtx[i].col0.ma * fscale,
bpmem.indmtx[i].col0.ma * fscale,
bpmem.indmtx[i].col1.mc * fscale,
bpmem.indmtx[i].col2.me * fscale,
fscale * 4.0f);
SetPSConstant4f(C_INDTEXMTX + 2 * i + 1,
bpmem.indmtx[i].col0.mb * fscale,
SetPSConstant4f(C_INDTEXMTX + 2 * i + 1,
bpmem.indmtx[i].col0.mb * fscale,
bpmem.indmtx[i].col1.md * fscale,
bpmem.indmtx[i].col2.mf * fscale,
fscale * 4.0f);

PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n",
i, 1024.0f*fscale,
bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, bpmem.indmtx[i].col2.me * fscale,
bpmem.indmtx[i].col0.mb * fscale, bpmem.indmtx[i].col1.md * fscale, bpmem.indmtx[i].col2.mf * fscale);
}
}
s_nIndTexMtxChanged = 0;
}
PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n",
i, 1024.0f*fscale,
bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, bpmem.indmtx[i].col2.me * fscale,
bpmem.indmtx[i].col0.mb * fscale, bpmem.indmtx[i].col1.md * fscale, bpmem.indmtx[i].col2.mf * fscale);
}
}
s_nIndTexMtxChanged = 0;
}

if (s_bFogColorChanged)
if (s_bFogColorChanged)
{
SetPSConstant4f(C_FOG, bpmem.fog.color.r / 255.0f, bpmem.fog.color.g / 255.0f, bpmem.fog.color.b / 255.0f, 0);
s_bFogColorChanged = false;
}
}

if (s_bFogParamChanged)
if (s_bFogParamChanged)
{
if(!g_ActiveConfig.bDisableFog)
{
Expand All @@ -236,8 +236,8 @@ void PixelShaderManager::SetConstants()
else
SetPSConstant4f(C_FOG + 1, 0.0, 1.0, 0.0, 1.0);

s_bFogParamChanged = false;
}
s_bFogParamChanged = false;
}

if (s_bFogRangeAdjustChanged)
{
Expand Down Expand Up @@ -341,11 +341,11 @@ void PixelShaderManager::SetConstants()

void PixelShaderManager::SetPSTextureDims(int texid)
{
// texdims.xy are reciprocals of the real texture dimensions
// texdims.zw are the scaled dimensions
float fdims[4];
// texdims.xy are reciprocals of the real texture dimensions
// texdims.zw are the scaled dimensions
float fdims[4];

TCoordInfo& tc = bpmem.texcoords[texid];
TCoordInfo& tc = bpmem.texcoords[texid];
fdims[0] = 1.0f / (float)(lastTexDims[texid] & 0xffff);
fdims[1] = 1.0f / (float)((lastTexDims[texid] >> 16) & 0xfff);
fdims[2] = (float)(tc.s.scale_minus_1 + 1);
Expand All @@ -359,7 +359,7 @@ void PixelShaderManager::SetPSTextureDims(int texid)
// and update it when the shader constant is set, only.
void PixelShaderManager::SetColorChanged(int type, int num, bool high)
{
float *pf = &lastRGBAfull[type][num][0];
float *pf = &lastRGBAfull[type][num][0];
if (!high) {
int r = bpmem.tevregs[num].low.a;
int a = bpmem.tevregs[num].low.b;
Expand All @@ -371,45 +371,45 @@ void PixelShaderManager::SetColorChanged(int type, int num, bool high)
pf[1] = (float)g * (1.0f / 255.0f);
pf[2] = (float)b * (1.0f / 255.0f);
}
s_nColorsChanged[type] |= 1 << num;
PRIM_LOG("pixel %scolor%d: %f %f %f %f\n", type?"k":"", num, pf[0], pf[1], pf[2], pf[3]);
s_nColorsChanged[type] |= 1 << num;
PRIM_LOG("pixel %scolor%d: %f %f %f %f\n", type?"k":"", num, pf[0], pf[1], pf[2], pf[3]);
}

void PixelShaderManager::SetAlpha(const AlphaTest& alpha)
{
if ((alpha.hex & 0xffff) != lastAlpha)
if ((alpha.hex & 0xffff) != lastAlpha)
{
lastAlpha = (lastAlpha & ~0xffff) | (alpha.hex & 0xffff);
s_bAlphaChanged = true;
}
lastAlpha = (lastAlpha & ~0xffff) | (alpha.hex & 0xffff);
s_bAlphaChanged = true;
}
}

void PixelShaderManager::SetDestAlpha(const ConstantAlpha& alpha)
{
if (alpha.alpha != (lastAlpha >> 16))
if (alpha.alpha != (lastAlpha >> 16))
{
lastAlpha = (lastAlpha & ~0xff0000) | ((alpha.hex & 0xff) << 16);
s_bAlphaChanged = true;
}
lastAlpha = (lastAlpha & ~0xff0000) | ((alpha.hex & 0xff) << 16);
s_bAlphaChanged = true;
}
}

void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt)
{
u32 wh = width | (height << 16) | (wraps << 28) | (wrapt << 30);
if (lastTexDims[texmapid] != wh)
u32 wh = width | (height << 16) | (wraps << 28) | (wrapt << 30);
if (lastTexDims[texmapid] != wh)
{
lastTexDims[texmapid] = wh;
lastTexDims[texmapid] = wh;
s_nTexDimsChanged |= 1 << texmapid;
}
}
}

void PixelShaderManager::SetZTextureBias(u32 bias)
{
if (lastZBias != bias)
if (lastZBias != bias)
{
s_bZBiasChanged = true;
lastZBias = bias;
}
s_bZBiasChanged = true;
lastZBias = bias;
}
}

void PixelShaderManager::SetViewportChanged()
Expand All @@ -420,12 +420,12 @@ void PixelShaderManager::SetViewportChanged()

void PixelShaderManager::SetIndTexScaleChanged(u8 stagemask)
{
s_nIndTexScaleChanged |= stagemask;
s_nIndTexScaleChanged |= stagemask;
}

void PixelShaderManager::SetIndMatrixChanged(int matrixidx)
{
s_nIndTexMtxChanged |= 1 << matrixidx;
s_nIndTexMtxChanged |= 1 << matrixidx;
}

void PixelShaderManager::SetZTextureTypeChanged()
Expand All @@ -435,22 +435,22 @@ void PixelShaderManager::SetZTextureTypeChanged()

void PixelShaderManager::SetTexCoordChanged(u8 texmapid)
{
s_nTexDimsChanged |= 1 << texmapid;
s_nTexDimsChanged |= 1 << texmapid;
}

void PixelShaderManager::SetFogColorChanged()
{
s_bFogColorChanged = true;
s_bFogColorChanged = true;
}

void PixelShaderManager::SetFogParamChanged()
{
s_bFogParamChanged = true;
s_bFogParamChanged = true;
}

void PixelShaderManager::SetFogRangeAdjustChanged()
{
s_bFogRangeAdjustChanged = true;
s_bFogRangeAdjustChanged = true;
}

void PixelShaderManager::SetColorMatrix(const float* pmatrix)
Expand Down
1 change: 0 additions & 1 deletion Source/Core/VideoCommon/Src/PixelShaderManager.h
Expand Up @@ -54,7 +54,6 @@ class PixelShaderManager
static void SetColorMatrix(const float* pmatrix);
static void InvalidateXFRange(int start, int end);
static void SetMaterialColorChanged(int index);

};


Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/Src/Statistics.cpp
Expand Up @@ -53,8 +53,8 @@ char *Statistics::ToString(char *ptr)
ptr+=sprintf(ptr,"pshaders (unique, delete cache first): %i\n",stats.numUniquePixelShaders);
ptr+=sprintf(ptr,"vshaders created: %i\n",stats.numVertexShadersCreated);
ptr+=sprintf(ptr,"vshaders alive: %i\n",stats.numVertexShadersAlive);
ptr+=sprintf(ptr,"dlists called: %i\n",stats.numDListsCalled);
ptr+=sprintf(ptr,"dlists called(f): %i\n",stats.thisFrame.numDListsCalled);
ptr+=sprintf(ptr,"dlists called: %i\n",stats.numDListsCalled);
ptr+=sprintf(ptr,"dlists called(f): %i\n",stats.thisFrame.numDListsCalled);
ptr+=sprintf(ptr,"dlists alive: %i\n",stats.numDListsAlive);
ptr+=sprintf(ptr,"primitive joins: %i\n",stats.thisFrame.numPrimitiveJoins);
ptr+=sprintf(ptr,"draw calls: %i\n",stats.thisFrame.numDrawCalls);
Expand Down
68 changes: 34 additions & 34 deletions Source/Core/VideoCommon/Src/Statistics.h
Expand Up @@ -24,20 +24,20 @@

struct Statistics
{
int numPixelShadersCreated;
int numPixelShadersAlive;
int numVertexShadersCreated;
int numVertexShadersAlive;
int numPixelShadersCreated;
int numPixelShadersAlive;
int numVertexShadersCreated;
int numVertexShadersAlive;

int numTexturesCreated;
int numTexturesAlive;
int numTexturesCreated;
int numTexturesAlive;

int numRenderTargetsCreated;
int numRenderTargetsAlive;
int numDListsCalled;
int numDListsCreated;
int numDListsAlive;
int numRenderTargetsCreated;
int numRenderTargetsAlive;
int numDListsCalled;
int numDListsCreated;
int numDListsAlive;

int numVertexLoaders;

Expand All @@ -52,30 +52,30 @@ struct Statistics

std::vector<EFBRectangle> efb_regions;

struct ThisFrame
{
int numBPLoads;
int numCPLoads;
int numXFLoads;
int numBPLoadsInDL;
int numCPLoadsInDL;
int numXFLoadsInDL;
int numDLs;
int numPrims;
int numDLPrims;
int numShaderChanges;

int numPrimitiveJoins;
int numDrawCalls;
int numIndexedDrawCalls;
int numBufferSplits;
struct ThisFrame
{
int numBPLoads;
int numCPLoads;
int numXFLoads;
int numBPLoadsInDL;
int numCPLoadsInDL;
int numXFLoadsInDL;
int numDLs;
int numPrims;
int numDLPrims;
int numShaderChanges;

int numPrimitiveJoins;
int numDrawCalls;
int numIndexedDrawCalls;
int numBufferSplits;

int numDListsCalled;
};
ThisFrame thisFrame;
void ResetFrame();
};
ThisFrame thisFrame;
void ResetFrame();
static void SwapDL();

// Yeah, this is unsafe, but we really don't wanna faff around allocating
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoCommon/Src/TextureCacheBase.cpp
Expand Up @@ -56,7 +56,7 @@ TextureCache::TextureCache()
if (!temp)
temp = (u8*)AllocateAlignedMemory(temp_size, 16);
TexDecoder_SetTexFmtOverlayOptions(g_ActiveConfig.bTexFmtOverlayEnable, g_ActiveConfig.bTexFmtOverlayCenter);
if(g_ActiveConfig.bHiresTextures && !g_ActiveConfig.bDumpTextures)
if(g_ActiveConfig.bHiresTextures && !g_ActiveConfig.bDumpTextures)
HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
SetHash64Function(g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures);
}
Expand Down Expand Up @@ -725,7 +725,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
case 1: // R8
case 8: // R8
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
cbufid = 13;
cbufid = 13;
break;

case 2: // RA4
Expand All @@ -746,11 +746,11 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat

case 9: // G8
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1.0f;
cbufid = 17;
cbufid = 17;
break;
case 10: // B8
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1.0f;
cbufid = 18;
cbufid = 18;
break;

case 11: // RG8
Expand All @@ -759,7 +759,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
break;

case 12: // GB8
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1.0f;
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1.0f;
cbufid = 20;
break;

Expand Down
249 changes: 124 additions & 125 deletions Source/Core/VideoCommon/Src/TextureConversionShader.cpp

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions Source/Core/VideoCommon/Src/TextureDecoder.h
Expand Up @@ -27,41 +27,41 @@ extern GC_ALIGNED16(u8 texMem[TMEM_SIZE]);

enum TextureFormat
{
GX_TF_I4 = 0x0,
GX_TF_I8 = 0x1,
GX_TF_IA4 = 0x2,
GX_TF_IA8 = 0x3,
GX_TF_RGB565 = 0x4,
GX_TF_RGB5A3 = 0x5,
GX_TF_RGBA8 = 0x6,
GX_TF_C4 = 0x8,
GX_TF_C8 = 0x9,
GX_TF_C14X2 = 0xA,
GX_TF_CMPR = 0xE,
GX_TF_I4 = 0x0,
GX_TF_I8 = 0x1,
GX_TF_IA4 = 0x2,
GX_TF_IA8 = 0x3,
GX_TF_RGB565 = 0x4,
GX_TF_RGB5A3 = 0x5,
GX_TF_RGBA8 = 0x6,
GX_TF_C4 = 0x8,
GX_TF_C8 = 0x9,
GX_TF_C14X2 = 0xA,
GX_TF_CMPR = 0xE,

_GX_TF_CTF = 0x20, // copy-texture-format only (simply means linear?)
_GX_TF_ZTF = 0x10, // Z-texture-format
_GX_TF_CTF = 0x20, // copy-texture-format only (simply means linear?)
_GX_TF_ZTF = 0x10, // Z-texture-format

// these formats are also valid when copying targets
GX_CTF_R4 = 0x0 | _GX_TF_CTF,
GX_CTF_RA4 = 0x2 | _GX_TF_CTF,
GX_CTF_RA8 = 0x3 | _GX_TF_CTF,
GX_CTF_YUVA8 = 0x6 | _GX_TF_CTF,
GX_CTF_A8 = 0x7 | _GX_TF_CTF,
GX_CTF_R8 = 0x8 | _GX_TF_CTF,
GX_CTF_G8 = 0x9 | _GX_TF_CTF,
GX_CTF_B8 = 0xA | _GX_TF_CTF,
GX_CTF_RG8 = 0xB | _GX_TF_CTF,
GX_CTF_GB8 = 0xC | _GX_TF_CTF,
// these formats are also valid when copying targets
GX_CTF_R4 = 0x0 | _GX_TF_CTF,
GX_CTF_RA4 = 0x2 | _GX_TF_CTF,
GX_CTF_RA8 = 0x3 | _GX_TF_CTF,
GX_CTF_YUVA8 = 0x6 | _GX_TF_CTF,
GX_CTF_A8 = 0x7 | _GX_TF_CTF,
GX_CTF_R8 = 0x8 | _GX_TF_CTF,
GX_CTF_G8 = 0x9 | _GX_TF_CTF,
GX_CTF_B8 = 0xA | _GX_TF_CTF,
GX_CTF_RG8 = 0xB | _GX_TF_CTF,
GX_CTF_GB8 = 0xC | _GX_TF_CTF,

GX_TF_Z8 = 0x1 | _GX_TF_ZTF,
GX_TF_Z16 = 0x3 | _GX_TF_ZTF,
GX_TF_Z24X8 = 0x6 | _GX_TF_ZTF,
GX_TF_Z8 = 0x1 | _GX_TF_ZTF,
GX_TF_Z16 = 0x3 | _GX_TF_ZTF,
GX_TF_Z24X8 = 0x6 | _GX_TF_ZTF,

GX_CTF_Z4 = 0x0 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8M = 0x9 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8L = 0xA | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z16L = 0xC | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z4 = 0x0 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8M = 0x9 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8L = 0xA | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z16L = 0xC | _GX_TF_ZTF | _GX_TF_CTF,
};

int TexDecoder_GetTexelSizeInNibbles(int format);
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/VideoCommon/Src/VertexLoader.cpp
Expand Up @@ -121,10 +121,10 @@ void LOADERDECL UpdateBoundingBox()
{
if (!PixelEngine::bbox_active)
return;

// reset videodata pointer
VertexManager::s_pCurBufferPointer = s_bbox_pCurBufferPointer_orig;

// copy vertex pointers
memcpy(VertexManager::s_pCurBufferPointer, s_bbox_vertex_buffer, 12);
VertexManager::s_pCurBufferPointer += 12;
Expand Down Expand Up @@ -335,7 +335,7 @@ void VertexLoader::CompileVertexTranslator()
nat_offset += 12;
vtx_decl.normal_offset[2] = nat_offset;
nat_offset += 12;
}
}

int numNormals = (m_VtxAttr.NormalElements == 1) ? NRM_THREE : NRM_ONE;
m_NativeFmt->m_components |= VB_HAS_NRM0;
Expand Down Expand Up @@ -367,7 +367,7 @@ void VertexLoader::CompileVertexTranslator()
default: _assert_(0); break;
}
break;
case INDEX8:
case INDEX8:
m_VertexSize += 1;
switch (m_VtxAttr.color[i].Comp)
{
Expand Down Expand Up @@ -558,7 +558,7 @@ int VertexLoader::SetupRunVertices(int vtx_attr_group, int primitive, int const
m_VtxAttr.texCoord[0].Frac = g_VtxAttr[vtx_attr_group].g0.Tex0Frac;
m_VtxAttr.texCoord[1].Frac = g_VtxAttr[vtx_attr_group].g1.Tex1Frac;
m_VtxAttr.texCoord[2].Frac = g_VtxAttr[vtx_attr_group].g1.Tex2Frac;
m_VtxAttr.texCoord[3].Frac = g_VtxAttr[vtx_attr_group].g1.Tex3Frac;
m_VtxAttr.texCoord[3].Frac = g_VtxAttr[vtx_attr_group].g1.Tex3Frac;
m_VtxAttr.texCoord[4].Frac = g_VtxAttr[vtx_attr_group].g2.Tex4Frac;
m_VtxAttr.texCoord[5].Frac = g_VtxAttr[vtx_attr_group].g2.Tex5Frac;
m_VtxAttr.texCoord[6].Frac = g_VtxAttr[vtx_attr_group].g2.Tex6Frac;
Expand Down Expand Up @@ -607,11 +607,11 @@ void VertexLoader::ConvertVertices ( int count )
void VertexLoader::RunCompiledVertices(int vtx_attr_group, int primitive, int const count, u8* Data)
{
auto const new_count = SetupRunVertices(vtx_attr_group, primitive, count);

memcpy_gc(VertexManager::s_pCurBufferPointer, Data, native_stride * new_count);
VertexManager::s_pCurBufferPointer += native_stride * new_count;
DataSkip(new_count * m_VertexSize);

VertexManager::AddVertices(primitive, new_count);
}

Expand Down Expand Up @@ -645,7 +645,7 @@ void VertexLoader::SetVAT(u32 _group0, u32 _group1, u32 _group2)
m_VtxAttr.texCoord[2].Frac = vat.g1.Tex2Frac;
m_VtxAttr.texCoord[3].Elements = vat.g1.Tex3CoordElements;
m_VtxAttr.texCoord[3].Format = vat.g1.Tex3CoordFormat;
m_VtxAttr.texCoord[3].Frac = vat.g1.Tex3Frac;
m_VtxAttr.texCoord[3].Frac = vat.g1.Tex3Frac;
m_VtxAttr.texCoord[4].Elements = vat.g1.Tex4CoordElements;
m_VtxAttr.texCoord[4].Format = vat.g1.Tex4CoordFormat;

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/VertexLoader.h
Expand Up @@ -134,6 +134,6 @@ class VertexLoader
void WriteGetVariable(int bits, Gen::OpArg dest, void *address);
void WriteSetVariable(int bits, void *address, Gen::OpArg dest);
#endif
};
};

#endif
10 changes: 5 additions & 5 deletions Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp
Expand Up @@ -46,7 +46,7 @@ __forceinline float FracAdjust(T val)
//auto const U8FRAC = 1.f / (1u << 7);
//auto const S16FRAC = 1.f / (1u << 14);
//auto const U16FRAC = 1.f / (1u << 15);

// TODO: is this right?
return val / float(1u << (sizeof(T) * 8 - std::numeric_limits<T>::is_signed - 1));
}
Expand All @@ -64,7 +64,7 @@ __forceinline void ReadIndirect(const T* data)
{
DataWrite(FracAdjust(Common::FromBigEndian(data[i])));
}

LOG_NORM();
}

Expand All @@ -77,7 +77,7 @@ struct Normal_Direct
ReadIndirect<T, N * 3>(source);
DataSkip<N * 3 * sizeof(T)>();
}

static const int size = sizeof(T) * N * 3;
};

Expand All @@ -99,7 +99,7 @@ struct Normal_Index
{
Normal_Index_Offset<I, T, N, 0>();
}

static const int size = sizeof(I);
};

Expand All @@ -112,7 +112,7 @@ struct Normal_Index_Indices3
Normal_Index_Offset<I, T, 1, 1>();
Normal_Index_Offset<I, T, 1, 2>();
}

static const int size = sizeof(I) * 3;
};

Expand Down
62 changes: 31 additions & 31 deletions Source/Core/VideoCommon/Src/VertexLoader_Normal.h
Expand Up @@ -25,43 +25,43 @@ class VertexLoader_Normal
{
public:

// Init
static void Init(void);
// Init
static void Init(void);

// GetSize
static unsigned int GetSize(unsigned int _type, unsigned int _format,
// GetSize
static unsigned int GetSize(unsigned int _type, unsigned int _format,
unsigned int _elements, unsigned int _index3);

// GetFunction
static TPipelineFunction GetFunction(unsigned int _type,
// GetFunction
static TPipelineFunction GetFunction(unsigned int _type,
unsigned int _format, unsigned int _elements, unsigned int _index3);

private:
enum ENormalType
{
NRM_NOT_PRESENT = 0,
NRM_DIRECT = 1,
NRM_INDEX8 = 2,
NRM_INDEX16 = 3,
NUM_NRM_TYPE
};

enum ENormalFormat
{
FORMAT_UBYTE = 0,
FORMAT_BYTE = 1,
FORMAT_USHORT = 2,
FORMAT_SHORT = 3,
FORMAT_FLOAT = 4,
NUM_NRM_FORMAT
};

enum ENormalElements
{
NRM_NBT = 0,
NRM_NBT3 = 1,
NUM_NRM_ELEMENTS
};
enum ENormalType
{
NRM_NOT_PRESENT = 0,
NRM_DIRECT = 1,
NRM_INDEX8 = 2,
NRM_INDEX16 = 3,
NUM_NRM_TYPE
};

enum ENormalFormat
{
FORMAT_UBYTE = 0,
FORMAT_BYTE = 1,
FORMAT_USHORT = 2,
FORMAT_SHORT = 3,
FORMAT_FLOAT = 4,
NUM_NRM_FORMAT
};

enum ENormalElements
{
NRM_NBT = 0,
NRM_NBT3 = 1,
NUM_NRM_ELEMENTS
};

enum ENormalIndices
{
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoCommon/Src/VertexLoader_Position.cpp
Expand Up @@ -87,10 +87,10 @@ template <typename T, int N>
void LOADERDECL Pos_ReadDirect()
{
static_assert(N <= 3, "N > 3 is not sane!");

for (int i = 0; i < 3; ++i)
DataWrite(i<N ? PosScale(DataRead<T>()) : 0.f);

LOG_VTX();
}

Expand All @@ -99,15 +99,15 @@ void LOADERDECL Pos_ReadIndex()
{
static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!");
static_assert(N <= 3, "N > 3 is not sane!");

auto const index = DataRead<I>();
if (index < std::numeric_limits<I>::max())
{
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION]));

for (int i = 0; i < 3; ++i)
DataWrite(i<N ? PosScale(Common::FromBigEndian(data[i])) : 0.f);

LOG_VTX();
}
}
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/VideoCommon/Src/VertexLoader_Position.h
Expand Up @@ -21,14 +21,14 @@
class VertexLoader_Position {
public:

// Init
static void Init(void);
// Init
static void Init(void);

// GetSize
static unsigned int GetSize(unsigned int _type, unsigned int _format, unsigned int _elements);
// GetSize
static unsigned int GetSize(unsigned int _type, unsigned int _format, unsigned int _elements);

// GetFunction
static TPipelineFunction GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements);
// GetFunction
static TPipelineFunction GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements);
};

#endif
10 changes: 5 additions & 5 deletions Source/Core/VideoCommon/Src/VertexLoader_TextCoord.cpp
Expand Up @@ -70,7 +70,7 @@ void LOADERDECL TexCoord_ReadDirect()
DataWrite(TCScale(DataRead<T>()));

LOG_TEX<N>();

++tcIndex;
}

Expand All @@ -82,10 +82,10 @@ void LOADERDECL TexCoord_ReadIndex()
auto const index = DataRead<I>();
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex]
+ (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex]));

for (int i = 0; i != N; ++i)
DataWrite(TCScale(Common::FromBigEndian(data[i])));

LOG_TEX<N>();
++tcIndex;
}
Expand All @@ -97,7 +97,7 @@ template <typename I>
void LOADERDECL TexCoord_ReadIndex_Short2_SSE4()
{
static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!");

// Heavy in ZWW
auto const index = DataRead<I>();
const s32 *pData = (const s32*)(cached_arraybases[ARRAY_TEXCOORD0+tcIndex] + (index * arraystrides[ARRAY_TEXCOORD0+tcIndex]));
Expand All @@ -121,7 +121,7 @@ template <typename I>
void LOADERDECL TexCoord_ReadIndex_Float2_SSSE3()
{
static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!");

auto const index = DataRead<I>();
const u32 *pData = (const u32 *)(cached_arraybases[ARRAY_TEXCOORD0+tcIndex] + (index * arraystrides[ARRAY_TEXCOORD0+tcIndex]));
GC_ALIGNED128(const __m128i a = _mm_loadl_epi64((__m128i*)pData));
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/VideoCommon/Src/VertexLoader_TextCoord.h
Expand Up @@ -24,18 +24,18 @@ class VertexLoader_TextCoord
{
public:

// Init
static void Init(void);
// Init
static void Init(void);

// GetSize
static unsigned int GetSize(unsigned int _type, unsigned int _format, unsigned int _elements);
// GetSize
static unsigned int GetSize(unsigned int _type, unsigned int _format, unsigned int _elements);

// GetFunction
static TPipelineFunction GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements);
// GetFunction
static TPipelineFunction GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements);

// GetDummyFunction
// GetDummyFunction
// It is important to synchronize tcIndex.
static TPipelineFunction GetDummyFunction();
static TPipelineFunction GetDummyFunction();
};

#endif
10 changes: 5 additions & 5 deletions Source/Core/VideoCommon/Src/VertexManagerBase.cpp
Expand Up @@ -103,22 +103,22 @@ void VertexManager::AddVertices(int primitive, u32 numVertices)

ADDSTAT(stats.thisFrame.numPrims, numVertices);
INCSTAT(stats.thisFrame.numPrimitiveJoins);

IndexGenerator::AddIndices(primitive, numVertices);
}

void VertexManager::Flush()
{
if (g_vertex_manager->IsFlushed())
return;

// loading a state will invalidate BP, so check for it
g_video_backend->CheckInvalidState();

VideoFifo_CheckEFBAccess();

g_vertex_manager->vFlush();

g_vertex_manager->ResetBuffer();
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Core/VideoCommon/Src/VertexManagerBase.h
Expand Up @@ -45,10 +45,10 @@ class VertexManager
virtual void DestroyDeviceObjects(){};

protected:
u16* GetTriangleIndexBuffer() { return &TIBuffer[0]; }
u16* GetLineIndexBuffer() { return &LIBuffer[0]; }
u16* GetPointIndexBuffer() { return &PIBuffer[0]; }
u8* GetVertexBuffer() { return &s_pBaseBufferPointer[0]; }
u16* GetTriangleIndexBuffer() { return &TIBuffer[0]; }
u16* GetLineIndexBuffer() { return &LIBuffer[0]; }
u16* GetPointIndexBuffer() { return &PIBuffer[0]; }
u8* GetVertexBuffer() { return &s_pBaseBufferPointer[0]; }

virtual void vDoState(PointerWrap& p) { DoStateShared(p); }
void DoStateShared(PointerWrap& p);
Expand Down
63 changes: 30 additions & 33 deletions Source/Core/VideoCommon/Src/VertexShaderGen.cpp
Expand Up @@ -174,7 +174,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)

_assert_(bpmem.genMode.numtexgens == xfregs.numTexGen.numTexGens);
_assert_(bpmem.genMode.numcolchans == xfregs.numChan.numColorChans);

bool is_d3d = (ApiType & API_D3D9 || ApiType == API_D3D11);
u32 lightMask = 0;
if (xfregs.numChan.numColorChans > 0)
Expand All @@ -184,11 +184,11 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)

char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components);

// uniforms
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform VSBlock {\n");

WRITE(p, "%sfloat4 " I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
WRITE(p, "%sfloat4 " I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
WRITE(p, "%sfloat4 " I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
Expand All @@ -198,10 +198,9 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "%sfloat4 " I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
WRITE(p, "%sfloat4 " I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
WRITE(p, "%sfloat4 " I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));

if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");


p = GenerateVSOutputStruct(p, components, ApiType);

Expand All @@ -221,7 +220,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "ATTRIN float4 color0; // ATTR%d,\n", SHADER_COLOR0_ATTRIB);
if (components & VB_HAS_COL1)
WRITE(p, "ATTRIN float4 color1; // ATTR%d,\n", SHADER_COLOR1_ATTRIB);

for (int i = 0; i < 8; ++i) {
u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
if ((components & (VB_HAS_UV0<<i)) || hastexmtx)
Expand Down Expand Up @@ -258,8 +257,8 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
}
else
{
WRITE(p, "VS_OUTPUT main(\n");
WRITE(p, "VS_OUTPUT main(\n");

// inputs
if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 : NORMAL0,\n");
Expand Down Expand Up @@ -335,8 +334,6 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if (!(components & VB_HAS_NRM0))
WRITE(p, "float3 _norm0 = float3(0.0f, 0.0f, 0.0f);\n");



WRITE(p, "o.pos = float4(dot(" I_PROJECTION"[0], pos), dot(" I_PROJECTION"[1], pos), dot(" I_PROJECTION"[2], pos), dot(" I_PROJECTION"[3], pos));\n");

WRITE(p, "float4 mat, lacc;\n"
Expand Down Expand Up @@ -506,9 +503,9 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "o.tex7 = pos.xyzz;\n");
else
WRITE(p, "o.tex7.w = pos.z;\n");
}
}
if (components & VB_HAS_COL0)
WRITE(p, "o.colors_0 = color0;\n");
WRITE(p, "o.colors_0 = color0;\n");

if (components & VB_HAS_COL1)
WRITE(p, "o.colors_1 = color1;\n");
Expand All @@ -522,26 +519,26 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
}
else
{
// this results in a scale from -1..0 to -1..1 after perspective
// divide
WRITE(p, "o.pos.z = o.pos.w + o.pos.z * 2.0f;\n");

// Sonic Unleashed puts its final rendering at the near or
// far plane of the viewing frustrum(actually box, they use
// orthogonal projection for that), and we end up putting it
// just beyond, and the rendering gets clipped away. (The
// primitive gets dropped)
WRITE(p, "o.pos.z = o.pos.z * 1048575.0f/1048576.0f;\n");

// the next steps of the OGL pipeline are:
// (x_c,y_c,z_c,w_c) = o.pos //switch to OGL spec terminology
// clipping to -w_c <= (x_c,y_c,z_c) <= w_c
// (x_d,y_d,z_d) = (x_c,y_c,z_c)/w_c//perspective divide
// z_w = (f-n)/2*z_d + (n+f)/2
// z_w now contains the value to go to the 0..1 depth buffer
//trying to get the correct semantic while not using glDepthRange
//seems to get rather complicated
// this results in a scale from -1..0 to -1..1 after perspective
// divide
WRITE(p, "o.pos.z = o.pos.w + o.pos.z * 2.0f;\n");

// Sonic Unleashed puts its final rendering at the near or
// far plane of the viewing frustrum(actually box, they use
// orthogonal projection for that), and we end up putting it
// just beyond, and the rendering gets clipped away. (The
// primitive gets dropped)
WRITE(p, "o.pos.z = o.pos.z * 1048575.0f/1048576.0f;\n");

// the next steps of the OGL pipeline are:
// (x_c,y_c,z_c,w_c) = o.pos //switch to OGL spec terminology
// clipping to -w_c <= (x_c,y_c,z_c) <= w_c
// (x_d,y_d,z_d) = (x_c,y_c,z_c)/w_c//perspective divide
// z_w = (f-n)/2*z_d + (n+f)/2
// z_w now contains the value to go to the 0..1 depth buffer

//trying to get the correct semantic while not using glDepthRange
//seems to get rather complicated
}

if (ApiType & API_D3D9)
Expand Down Expand Up @@ -579,7 +576,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " uv%d_2%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i);
}
}
}
WRITE(p, "colors_02 = o.colors_0;\n");
WRITE(p, "colors_12 = o.colors_1;\n");
WRITE(p, "gl_Position = o.pos;\n");
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/VertexShaderGen.h
Expand Up @@ -61,7 +61,7 @@
#define C_NORMALMATRICES (C_TRANSFORMMATRICES + 64)
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
#define C_VENVCONST_END (C_DEPTHPARAMS + 1)
#define C_VENVCONST_END (C_DEPTHPARAMS + 1)
const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
{I_PROJECTION , C_PROJECTION, 4 },
{I_MATERIALS, C_MATERIALS, 4 },
Expand Down
36 changes: 18 additions & 18 deletions Source/Core/VideoCommon/Src/VertexShaderManager.cpp
Expand Up @@ -102,7 +102,7 @@ float PHackValue(std::string sValue)
c[i] = (cStr[i] == ',') ? '.' : *(cStr+i);
if (c[i] == '.')
fp = true;
}
}
cStr = c;
sTof.str(cStr);
sTof >> f;
Expand All @@ -119,22 +119,22 @@ void UpdateProjectionHack(int iPhackvalue[], std::string sPhackvalue[])
float fhacksign1 = 1.0, fhacksign2 = 1.0;
bool bProjHack3 = false;
const char *sTemp[2];

if (iPhackvalue[0] == 1)
{
NOTICE_LOG(VIDEO, "\t\t--- Ortographic Projection Hack ON ---");

fhacksign1 *= (iPhackvalue[1] == 1) ? -1.0f : fhacksign1;
sTemp[0] = (iPhackvalue[1] == 1) ? " * (-1)" : "";
fhacksign2 *= (iPhackvalue[2] == 1) ? -1.0f : fhacksign2;
sTemp[1] = (iPhackvalue[2] == 1) ? " * (-1)" : "";

fhackvalue1 = PHackValue(sPhackvalue[0]);
NOTICE_LOG(VIDEO, "- zNear Correction = (%f + zNear)%s", fhackvalue1, sTemp[0]);

fhackvalue2 = PHackValue(sPhackvalue[1]);
NOTICE_LOG(VIDEO, "- zFar Correction = (%f + zFar)%s", fhackvalue2, sTemp[1]);

sTemp[0] = "DISABLED";
bProjHack3 = (iPhackvalue[3] == 1) ? true : bProjHack3;
if (bProjHack3)
Expand Down Expand Up @@ -171,22 +171,22 @@ void VertexShaderManager::Dirty()
{
nTransformMatricesChanged[0] = 0;
nTransformMatricesChanged[1] = 256;

nNormalMatricesChanged[0] = 0;
nNormalMatricesChanged[1] = 96;

nPostTransformMatricesChanged[0] = 0;
nPostTransformMatricesChanged[1] = 256;

nLightsChanged[0] = 0;
nLightsChanged[1] = 0x80;

bPosNormalMatrixChanged = true;
bTexMatricesChanged[0] = true;
bTexMatricesChanged[1] = true;

bProjectionChanged = true;

nMaterialsChanged = 15;
}

Expand Down Expand Up @@ -358,7 +358,7 @@ void VertexShaderManager::SetConstants()
switch(xfregs.projection.type)
{
case GX_PERSPECTIVE:

g_fProjectionMatrix[0] = rawProjection[0] * g_ActiveConfig.fAspectRatioHackW;
g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] = rawProjection[1];
Expand All @@ -374,7 +374,7 @@ void VertexShaderManager::SetConstants()
g_fProjectionMatrix[10] = rawProjection[4];

g_fProjectionMatrix[11] = rawProjection[5];

g_fProjectionMatrix[12] = 0.0f;
g_fProjectionMatrix[13] = 0.0f;
// donkopunchstania: GC GPU rounds differently?
Expand All @@ -399,9 +399,9 @@ void VertexShaderManager::SetConstants()
SETSTAT_FT(stats.gproj_14, g_fProjectionMatrix[14]);
SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]);
break;

case GX_ORTHOGRAPHIC:

g_fProjectionMatrix[0] = rawProjection[0];
g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] = 0.0f;
Expand All @@ -426,10 +426,10 @@ void VertexShaderManager::SetConstants()
this hack was added...setting g_fProjectionMatrix[14] to -1 might make the hack more stable, needs more testing.
Only works for OGL and DX9...this is not helping DX11
*/

g_fProjectionMatrix[14] = 0.0f;
g_fProjectionMatrix[15] = (g_ProjHack3 && rawProjection[0] == 2.0f ? 0.0f : 1.0f); //causes either the efb copy or bloom layer not to show if proj hack enabled

SETSTAT_FT(stats.g2proj_0, g_fProjectionMatrix[0]);
SETSTAT_FT(stats.g2proj_1, g_fProjectionMatrix[1]);
SETSTAT_FT(stats.g2proj_2, g_fProjectionMatrix[2]);
Expand All @@ -453,7 +453,7 @@ void VertexShaderManager::SetConstants()
SETSTAT_FT(stats.proj_4, rawProjection[4]);
SETSTAT_FT(stats.proj_5, rawProjection[5]);
break;

default:
ERROR_LOG(VIDEO, "unknown projection type: %d", xfregs.projection.type);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/VertexShaderManager.h
Expand Up @@ -43,7 +43,7 @@ class VertexShaderManager
static void Dirty();
static void Shutdown();
static void DoState(PointerWrap &p);
;

// constant management
static void SetConstants();

Expand Down
18 changes: 9 additions & 9 deletions Source/Core/VideoCommon/Src/VideoConfig.cpp
Expand Up @@ -52,7 +52,7 @@ void VideoConfig::Load(const char *ini_file)
std::string temp;
IniFile iniFile;
iniFile.Load(ini_file);

iniFile.Get("Hardware", "VSync", &bVSync, 0); // Hardware
iniFile.Get("Settings", "wideScreenHack", &bWidescreenHack, false);
iniFile.Get("Settings", "AspectRatio", &iAspectRatio, (int)ASPECT_AUTO);
Expand All @@ -78,17 +78,17 @@ void VideoConfig::Load(const char *ini_file)
iniFile.Get("Settings", "AnaglyphFocalAngle", &iAnaglyphFocalAngle, 0);
iniFile.Get("Settings", "EnablePixelLighting", &bEnablePixelLighting, 0);
iniFile.Get("Settings", "HackedBufferUpload", &bHackedBufferUpload, 0);

iniFile.Get("Settings", "MSAA", &iMultisampleMode, 0);
iniFile.Get("Settings", "EFBScale", &iEFBScale, 2); // native

iniFile.Get("Settings", "DstAlphaPass", &bDstAlphaPass, false);

iniFile.Get("Settings", "TexFmtOverlayEnable", &bTexFmtOverlayEnable, 0);
iniFile.Get("Settings", "TexFmtOverlayCenter", &bTexFmtOverlayCenter, 0);
iniFile.Get("Settings", "WireFrame", &bWireFrame, 0);
iniFile.Get("Settings", "DisableFog", &bDisableFog, 0);

iniFile.Get("Settings", "EnableOpenCL", &bEnableOpenCL, false);
iniFile.Get("Settings", "OMPDecoder", &bOMPDecoder, false);

Expand All @@ -98,7 +98,7 @@ void VideoConfig::Load(const char *ini_file)
iniFile.Get("Enhancements", "MaxAnisotropy", &iMaxAnisotropy, 0); // NOTE - this is x in (1 << x)
iniFile.Get("Enhancements", "PostProcessingShader", &sPostProcessingShader, "");
iniFile.Get("Enhancements", "Enable3dVision", &b3DVision, false);

iniFile.Get("Hacks", "EFBAccessEnable", &bEFBAccessEnable, true);
iniFile.Get("Hacks", "DlistCachingEnable", &bDlistCachingEnable,false);
iniFile.Get("Hacks", "EFBCopyEnable", &bEFBCopyEnable, true);
Expand Down Expand Up @@ -219,14 +219,14 @@ void VideoConfig::Save(const char *ini_file)

iniFile.Set("Settings", "EnableOpenCL", bEnableOpenCL);
iniFile.Set("Settings", "OMPDecoder", bOMPDecoder);

iniFile.Set("Settings", "EnableShaderDebugging", bEnableShaderDebugging);

iniFile.Set("Enhancements", "ForceFiltering", bForceFiltering);
iniFile.Set("Enhancements", "MaxAnisotropy", iMaxAnisotropy);
iniFile.Set("Enhancements", "PostProcessingShader", sPostProcessingShader);
iniFile.Set("Enhancements", "Enable3dVision", b3DVision);

iniFile.Set("Hacks", "EFBAccessEnable", bEFBAccessEnable);
iniFile.Set("Hacks", "DlistCachingEnable", bDlistCachingEnable);
iniFile.Set("Hacks", "EFBCopyEnable", bEFBCopyEnable);
Expand All @@ -237,7 +237,7 @@ void VideoConfig::Save(const char *ini_file)
iniFile.Set("Hacks", "EFBEmulateFormatChanges", bEFBEmulateFormatChanges);

iniFile.Set("Hardware", "Adapter", iAdapter);

iniFile.Save(ini_file);
}

Expand Down
16 changes: 8 additions & 8 deletions Source/Core/VideoCommon/Src/VideoConfig.h
Expand Up @@ -99,12 +99,12 @@ struct VideoConfig
bool bTexFmtOverlayCenter;
bool bShowEFBCopyRegions;
bool bLogFPSToFile;

// Render
bool bWireFrame;
bool bDstAlphaPass;
bool bDisableFog;

// Utility
bool bDumpTextures;
bool bHiresTextures;
Expand Down Expand Up @@ -164,19 +164,19 @@ struct VideoConfig
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
bool bSupportsFormatReinterpretation;
bool bSupportsPixelLighting;

bool bSupportsGLSLUBO;
bool bSupportsGLSLCache;
bool bSupportsGLPinnedMemory;
bool bSupportsGLSync;
bool bSupportsGLBaseVertex;
} backend_info;

// Utility
bool RealXFBEnabled() const { return bUseXFB && bUseRealXFB; }
bool VirtualXFBEnabled() const { return bUseXFB && !bUseRealXFB; }
bool EFBCopiesToTextureEnabled() const { return bEFBCopyEnable && bCopyEFBToTexture; }
bool EFBCopiesToRamEnabled() const { return bEFBCopyEnable && !bCopyEFBToTexture; }
// Utility
bool RealXFBEnabled() const { return bUseXFB && bUseRealXFB; }
bool VirtualXFBEnabled() const { return bUseXFB && !bUseRealXFB; }
bool EFBCopiesToTextureEnabled() const { return bEFBCopyEnable && bCopyEFBToTexture; }
bool EFBCopiesToRamEnabled() const { return bEFBCopyEnable && !bCopyEFBToTexture; }
};

extern VideoConfig g_Config;
Expand Down
30 changes: 15 additions & 15 deletions Source/Core/VideoCommon/Src/VideoState.cpp
Expand Up @@ -30,33 +30,33 @@

static void DoState(PointerWrap &p)
{
// BP Memory
p.Do(bpmem);
// BP Memory
p.Do(bpmem);
p.DoMarker("BP Memory");

// CP Memory
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
p.Do(g_VtxDesc.Hex);
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
p.Do(g_VtxDesc.Hex);
p.DoArray(g_VtxAttr, 8);
p.DoMarker("CP Memory");

// XF Memory
p.Do(xfregs);
p.DoArray(xfmem, XFMEM_SIZE);
// XF Memory
p.Do(xfregs);
p.DoArray(xfmem, XFMEM_SIZE);
p.DoMarker("XF Memory");

// Texture decoder
p.DoArray(texMem, TMEM_SIZE);
p.DoArray(texMem, TMEM_SIZE);
p.DoMarker("texMem");

// FIFO
Fifo_DoState(p);
// FIFO
Fifo_DoState(p);
p.DoMarker("Fifo");

CommandProcessor::DoState(p);
CommandProcessor::DoState(p);
p.DoMarker("CommandProcessor");

PixelEngine::DoState(p);
Expand All @@ -77,7 +77,7 @@ static void DoState(PointerWrap &p)

void VideoCommon_DoState(PointerWrap &p)
{
DoState(p);
DoState(p);
}

void VideoCommon_RunLoop(bool enable)
Expand Down
196 changes: 98 additions & 98 deletions Source/Core/VideoCommon/Src/XFMemory.h
Expand Up @@ -110,70 +110,70 @@

union LitChannel
{
struct
{
u32 matsource : 1;
u32 enablelighting : 1;
u32 lightMask0_3 : 4;
u32 ambsource : 1;
u32 diffusefunc : 2; // LIGHTDIF_X
u32 attnfunc : 2; // LIGHTATTN_X
u32 lightMask4_7 : 4;
};
struct
{
u32 hex : 15;
u32 unused : 17;
};
struct
{
u32 dummy0 : 7;
u32 lightparams : 4;
u32 dummy1 : 21;
};
unsigned int GetFullLightMask() const
{
return enablelighting ? (lightMask0_3 | (lightMask4_7 << 4)) : 0;
}
struct
{
u32 matsource : 1;
u32 enablelighting : 1;
u32 lightMask0_3 : 4;
u32 ambsource : 1;
u32 diffusefunc : 2; // LIGHTDIF_X
u32 attnfunc : 2; // LIGHTATTN_X
u32 lightMask4_7 : 4;
};
struct
{
u32 hex : 15;
u32 unused : 17;
};
struct
{
u32 dummy0 : 7;
u32 lightparams : 4;
u32 dummy1 : 21;
};
unsigned int GetFullLightMask() const
{
return enablelighting ? (lightMask0_3 | (lightMask4_7 << 4)) : 0;
}
};


union INVTXSPEC
{
struct
{
u32 numcolors : 2;
u32 numnormals : 2; // 0 - nothing, 1 - just normal, 2 - normals and binormals
u32 numtextures : 4;
u32 unused : 24;
};
u32 hex;
struct
{
u32 numcolors : 2;
u32 numnormals : 2; // 0 - nothing, 1 - just normal, 2 - normals and binormals
u32 numtextures : 4;
u32 unused : 24;
};
u32 hex;
};

union TexMtxInfo
{
struct
{
u32 unknown : 1;
u32 projection : 1; // XF_TEXPROJ_X
u32 inputform : 2; // XF_TEXINPUT_X
u32 texgentype : 3; // XF_TEXGEN_X
u32 sourcerow : 5; // XF_SRCGEOM_X
u32 embosssourceshift : 3; // what generated texcoord to use
u32 embosslightshift : 3; // light index that is used
};
u32 hex;
struct
{
u32 unknown : 1;
u32 projection : 1; // XF_TEXPROJ_X
u32 inputform : 2; // XF_TEXINPUT_X
u32 texgentype : 3; // XF_TEXGEN_X
u32 sourcerow : 5; // XF_SRCGEOM_X
u32 embosssourceshift : 3; // what generated texcoord to use
u32 embosslightshift : 3; // light index that is used
};
u32 hex;
};

union PostMtxInfo
{
struct
{
u32 index : 6; // base row of dual transform matrix
u32 unused : 2;
u32 normalize : 1; // normalize before send operation
};
u32 hex;
struct
{
u32 index : 6; // base row of dual transform matrix
u32 unused : 2;
u32 normalize : 1; // normalize before send operation
};
u32 hex;
};

union NumColorChannel
Expand Down Expand Up @@ -207,25 +207,25 @@ union DualTexInfo

struct Light
{
u32 useless[3];
u32 color; //rgba
float a0; //attenuation
float a1;
float a2;
float k0; //k stuff
float k1;
float k2;
union
{
struct {
u32 useless[3];
u32 color; //rgba
float a0; //attenuation
float a1;
float a2;
float k0; //k stuff
float k1;
float k2;
union
{
struct {
float dpos[3];
float ddir[3]; // specular lights only
};
struct {
float sdir[3];
float shalfangle[3]; // specular lights only
};
};
float ddir[3]; // specular lights only
};
struct {
float sdir[3];
float shalfangle[3]; // specular lights only
};
};
};

struct Viewport
Expand All @@ -246,35 +246,35 @@ struct Projection

struct XFRegisters
{
u32 error; // 0x1000
u32 diag; // 0x1001
u32 state0; // 0x1002
u32 state1; // 0x1003
u32 xfClock; // 0x1004
u32 clipDisable; // 0x1005
u32 perf0; // 0x1006
u32 perf1; // 0x1007
INVTXSPEC hostinfo; // 0x1008 number of textures,colors,normals from vertex input
NumColorChannel numChan; // 0x1009
u32 ambColor[2]; // 0x100a, 0x100b
u32 matColor[2]; // 0x100c, 0x100d
LitChannel color[2]; // 0x100e, 0x100f
LitChannel alpha[2]; // 0x1010, 0x1011
DualTexInfo dualTexTrans; // 0x1012
u32 unk3; // 0x1013
u32 unk4; // 0x1014
u32 unk5; // 0x1015
u32 unk6; // 0x1016
u32 unk7; // 0x1017
u32 MatrixIndexA; // 0x1018
u32 MatrixIndexB; // 0x1019
Viewport viewport; // 0x101a - 0x101f
Projection projection; // 0x1020 - 0x1026
u32 unk8[24]; // 0x1027 - 0x103e
NumTexGen numTexGen; // 0x103f
TexMtxInfo texMtxInfo[8]; // 0x1040 - 0x1047
u32 unk9[8]; // 0x1048 - 0x104f
PostMtxInfo postMtxInfo[8]; // 0x1050 - 0x1057
u32 error; // 0x1000
u32 diag; // 0x1001
u32 state0; // 0x1002
u32 state1; // 0x1003
u32 xfClock; // 0x1004
u32 clipDisable; // 0x1005
u32 perf0; // 0x1006
u32 perf1; // 0x1007
INVTXSPEC hostinfo; // 0x1008 number of textures,colors,normals from vertex input
NumColorChannel numChan; // 0x1009
u32 ambColor[2]; // 0x100a, 0x100b
u32 matColor[2]; // 0x100c, 0x100d
LitChannel color[2]; // 0x100e, 0x100f
LitChannel alpha[2]; // 0x1010, 0x1011
DualTexInfo dualTexTrans; // 0x1012
u32 unk3; // 0x1013
u32 unk4; // 0x1014
u32 unk5; // 0x1015
u32 unk6; // 0x1016
u32 unk7; // 0x1017
u32 MatrixIndexA; // 0x1018
u32 MatrixIndexB; // 0x1019
Viewport viewport; // 0x101a - 0x101f
Projection projection; // 0x1020 - 0x1026
u32 unk8[24]; // 0x1027 - 0x103e
NumTexGen numTexGen; // 0x103f
TexMtxInfo texMtxInfo[8]; // 0x1040 - 0x1047
u32 unk9[8]; // 0x1048 - 0x104f
PostMtxInfo postMtxInfo[8]; // 0x1050 - 0x1057
};


Expand Down
128 changes: 64 additions & 64 deletions Source/Core/VideoCommon/Src/XFStructs.cpp
Expand Up @@ -36,37 +36,37 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
u32 address = baseAddress;
u32 dataIndex = 0;

while (transferSize > 0 && address < 0x1058)
{
u32 newValue = pData[dataIndex];
while (transferSize > 0 && address < 0x1058)
{
u32 newValue = pData[dataIndex];
u32 nextAddress = address + 1;

switch (address)
{
case XFMEM_ERROR:
case XFMEM_DIAG:
case XFMEM_STATE0: // internal state 0
case XFMEM_STATE1: // internal state 1
case XFMEM_CLOCK:
switch (address)
{
case XFMEM_ERROR:
case XFMEM_DIAG:
case XFMEM_STATE0: // internal state 0
case XFMEM_STATE1: // internal state 1
case XFMEM_CLOCK:
case XFMEM_SETGPMETRIC:
nextAddress = 0x1007;
break;
break;

case XFMEM_CLIPDISABLE:
case XFMEM_CLIPDISABLE:
//if (data & 1) {} // disable clipping detection
//if (data & 2) {} // disable trivial rejection
//if (data & 4) {} // disable cpoly clipping acceleration
break;
break;

case XFMEM_VTXSPECS: //__GXXfVtxSpecs, wrote 0004
break;
case XFMEM_VTXSPECS: //__GXXfVtxSpecs, wrote 0004
break;

case XFMEM_SETNUMCHAN:
case XFMEM_SETNUMCHAN:
if (xfregs.numChan.numColorChans != (newValue & 3))
VertexManager::Flush();
break;
VertexManager::Flush();
break;

case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
case XFMEM_SETCHAN1_AMBCOLOR:
{
u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR;
Expand All @@ -75,11 +75,11 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
VertexManager::Flush();
VertexShaderManager::SetMaterialColorChanged(chan);
PixelShaderManager::SetMaterialColorChanged(chan);
}
}
break;
}

case XFMEM_SETCHAN0_MATCOLOR: // Channel Material Color
case XFMEM_SETCHAN0_MATCOLOR: // Channel Material Color
case XFMEM_SETCHAN1_MATCOLOR:
{
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
Expand All @@ -92,28 +92,28 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
break;
}

case XFMEM_SETCHAN0_COLOR: // Channel Color
case XFMEM_SETCHAN0_COLOR: // Channel Color
case XFMEM_SETCHAN1_COLOR:
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
case XFMEM_SETCHAN1_ALPHA:
case XFMEM_SETCHAN1_ALPHA:
if (((u32*)&xfregs)[address - 0x1000] != (newValue & 0x7fff))
VertexManager::Flush();
VertexManager::Flush();
break;

case XFMEM_DUALTEX:
case XFMEM_DUALTEX:
if (xfregs.dualTexTrans.enabled != (newValue & 1))
VertexManager::Flush();
break;
VertexManager::Flush();
break;


case XFMEM_SETMATRIXINDA:
//_assert_msg_(GX_XF, 0, "XF matrixindex0");
case XFMEM_SETMATRIXINDA:
//_assert_msg_(GX_XF, 0, "XF matrixindex0");
VertexShaderManager::SetTexMatrixChangedA(newValue);
break;
case XFMEM_SETMATRIXINDB:
//_assert_msg_(GX_XF, 0, "XF matrixindex1");
VertexShaderManager::SetTexMatrixChangedB(newValue);
break;
break;
case XFMEM_SETMATRIXINDB:
//_assert_msg_(GX_XF, 0, "XF matrixindex1");
VertexShaderManager::SetTexMatrixChangedB(newValue);
break;

case XFMEM_SETVIEWPORT:
case XFMEM_SETVIEWPORT+1:
Expand All @@ -135,16 +135,16 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
case XFMEM_SETPROJECTION+4:
case XFMEM_SETPROJECTION+5:
case XFMEM_SETPROJECTION+6:
VertexManager::Flush();
VertexManager::Flush();
VertexShaderManager::SetProjectionChanged();

nextAddress = XFMEM_SETPROJECTION + 7;
break;

case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
if (xfregs.numTexGen.numTexGens != (newValue & 15))
VertexManager::Flush();
break;
break;

case XFMEM_SETTEXMTXINFO:
case XFMEM_SETTEXMTXINFO+1:
Expand Down Expand Up @@ -178,47 +178,47 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)

// Maybe these are for Normals?
case 0x1048: //xfregs.texcoords[0].nrmmtxinfo.hex = data; break; ??
case 0x1049:
case 0x104a:
case 0x104b:
case 0x104c:
case 0x104d:
case 0x104e:
case 0x104f:
case 0x1049:
case 0x104a:
case 0x104b:
case 0x104c:
case 0x104d:
case 0x104e:
case 0x104f:
DEBUG_LOG(VIDEO, "Possible Normal Mtx XF reg?: %x=%x\n", address, newValue);
break;

case 0x1013:
case 0x1014:
case 0x1015:
case 0x1016:
case 0x1017:
case 0x1014:
case 0x1015:
case 0x1016:
case 0x1017:

default:
WARN_LOG(VIDEO, "Unknown XF Reg: %x=%x\n", address, newValue);
break;
}
default:
WARN_LOG(VIDEO, "Unknown XF Reg: %x=%x\n", address, newValue);
break;
}

int transferred = nextAddress - address;
address = nextAddress;

transferSize -= transferred;
dataIndex += transferred;
}
}
}

void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
{
// do not allow writes past registers
if (baseAddress + transferSize > 0x1058)
{
INFO_LOG(VIDEO, "xf load exceeds address space: %x %d bytes\n", baseAddress, transferSize);
// do not allow writes past registers
if (baseAddress + transferSize > 0x1058)
{
INFO_LOG(VIDEO, "xf load exceeds address space: %x %d bytes\n", baseAddress, transferSize);

if (baseAddress >= 0x1058)
transferSize = 0;
else
transferSize = 0x1058 - baseAddress;
}
if (baseAddress >= 0x1058)
transferSize = 0;
else
transferSize = 0x1058 - baseAddress;
}

// write to XF mem
if (baseAddress < 0x1000 && transferSize > 0)
Expand Down Expand Up @@ -247,11 +247,11 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
}

// write to XF regs
if (transferSize > 0)
if (transferSize > 0)
{
XFRegWritten(transferSize, baseAddress, pData);
memcpy_gc((u32*)(&xfregs) + (baseAddress - 0x1000), pData, transferSize * 4);
}
}
}

// TODO - verify that it is correct. Seems to work, though.
Expand Down
33 changes: 15 additions & 18 deletions Source/Core/VideoCommon/Src/x64DLCache.cpp
Expand Up @@ -111,17 +111,17 @@ struct CachedDisplayList
u32 num_cp_reg;
u32 num_bp_reg;
u32 num_index_xf;
u32 num_draw_call;
u32 num_draw_call;
u32 pass;
u32 check;
int frame_count;
int frame_count;
u32 BufferCount;

void InsertRegion(ReferencedDataRegion* NewRegion)
{
if(LastRegion)
{
LastRegion->NextRegion = NewRegion;
LastRegion->NextRegion = NewRegion;
}
LastRegion = NewRegion;
if(!Regions)
Expand Down Expand Up @@ -174,15 +174,15 @@ struct CachedDisplayList
Current = Current->NextRegion;
}
return true;
}
}

ReferencedDataRegion* FindOverlapingRegion(u8* RegionStart, u32 Regionsize)
{
ReferencedDataRegion* Current = Regions;
while(Current)
{
if(!Current->IntersectsMemoryRange(RegionStart, Regionsize))
return Current;
return Current;
Current = Current->NextRegion;
}
return Current;
Expand Down Expand Up @@ -330,7 +330,7 @@ u32 AnalyzeAndRunDisplayList(u32 address, u32 size, CachedDisplayList *dl)
u32 addr = DataReadU32();
u32 count = DataReadU32();
ExecuteDisplayList(addr, count);
}
}
break;
case GX_CMD_UNKNOWN_METRICS: // zelda 4 swords calls it and checks the metrics registers after that
DEBUG_LOG(VIDEO, "GX 0x44: %08x", cmd_byte);
Expand Down Expand Up @@ -392,7 +392,7 @@ u32 AnalyzeAndRunDisplayList(u32 address, u32 size, CachedDisplayList *dl)
dl->num_draw_call = num_draw_call;
dl->num_index_xf = num_index_xf;
dl->num_xf_reg = num_xf_reg;
// reset to the old pointer
// reset to the old pointer
g_pVideoData = old_pVideoData;
return result;
}
Expand Down Expand Up @@ -458,7 +458,7 @@ void CompileAndRunDisplayList(u32 address, u32 size, CachedDisplayList *dl)
NewRegion->MustClean = true;
NewRegion->size = transfer_size * 4;
NewRegion->start_address = (u8*) new u8[NewRegion->size+15+12]; // alignment and guaranteed space
NewRegion->hash = 0;
NewRegion->hash = 0;
dl->InsertRegion(NewRegion);
u32 *data_buffer = (u32*)(u8*)(((size_t)NewRegion->start_address+0xf)&~0xf);
DataReadU32xFuncs[transfer_size-1](data_buffer);
Expand Down Expand Up @@ -539,7 +539,6 @@ void CompileAndRunDisplayList(u32 address, u32 size, CachedDisplayList *dl)
if (cmd_byte & 0x80)
{
// load vertices (use computed vertex size from FifoCommandRunnable above)

u16 numVertices = DataReadU16();
if(numVertices > 0)
{
Expand All @@ -558,7 +557,7 @@ void CompileAndRunDisplayList(u32 address, u32 size, CachedDisplayList *dl)
NewRegion->MustClean = true;
NewRegion->size = Vdatasize;
NewRegion->start_address = (u8*)new u8[Vdatasize];
NewRegion->hash = 0;
NewRegion->hash = 0;
dl->InsertRegion(NewRegion);
memcpy(NewRegion->start_address, StartAddress, Vdatasize);
emitter.ABI_CallFunctionCCCP((void *)&VertexLoaderManager::RunCompiledVertices, cmd_byte & GX_VAT_MASK, (cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, numVertices, NewRegion->start_address);
Expand All @@ -577,7 +576,6 @@ void CompileAndRunDisplayList(u32 address, u32 size, CachedDisplayList *dl)
}
}
}

}
else
{
Expand Down Expand Up @@ -626,7 +624,7 @@ void Clear()
}
dl_map.clear();
// Reset the cache pointers.
emitter.SetCodePtr(dlcode_cache);
emitter.SetCodePtr(dlcode_cache);
}

void ProgressiveCleanup()
Expand Down Expand Up @@ -684,14 +682,14 @@ bool HandleDisplayList(u32 address, u32 size)
{
vhash = DLCache::CreateVMapId(Parentiter->second.VATUsed);
iter = Parentiter->second.dl_map.find(vhash);
childexist = iter != Parentiter->second.dl_map.end();
childexist = iter != Parentiter->second.dl_map.end();
}
if (Parentiter != DLCache::dl_map.end() && childexist)
{
DLCache::CachedDisplayList &dl = iter->second;
if (dl.uncachable)
{
return false;
return false;
}

switch (dl.pass)
Expand All @@ -700,7 +698,7 @@ bool HandleDisplayList(u32 address, u32 size)
// First, check that the hash is the same as the last time.
if (dl.dl_hash != GetHash64(Memory::GetPointer(address), size, 0))
{
dl.uncachable = true;
dl.uncachable = true;
return false;
}
DLCache::CompileAndRunDisplayList(address, size, &dl);
Expand All @@ -717,7 +715,7 @@ bool HandleDisplayList(u32 address, u32 size)
if (DlistChanged)
{
dl.uncachable = true;
dl.ClearRegions();
dl.ClearRegions();
return false;
}
dl.frame_count= frameCount;
Expand Down Expand Up @@ -764,10 +762,9 @@ bool HandleDisplayList(u32 address, u32 size)
vdl.VATUsed = dlvatused;
vdl.count = 1;
DLCache::dl_map[dl_id] = vdl;

}

return true;

}

void IncrementCheckContextId()
Expand Down
36 changes: 18 additions & 18 deletions Source/Core/VideoCommon/Src/x64TextureDecoder.cpp
Expand Up @@ -517,7 +517,7 @@ inline void decodebytesARGB8_4ToRgba(u32 *dst, const u16 *src, const u16 * src2)
{
#if 0
for (int x = 0; x < 4; x++) {
dst[x] = ((src[x] & 0xFF) << 24) | ((src[x] & 0xFF00)>>8) | (src2[x] << 8);
dst[x] = ((src[x] & 0xFF) << 24) | ((src[x] & 0xFF00)>>8) | (src2[x] << 8);
}
#else
dst[0] = ((src[0] & 0xFF) << 24) | ((src[0] & 0xFF00)>>8) | (src2[0] << 8);
Expand Down Expand Up @@ -556,7 +556,7 @@ void decodeDXTBlock(u32 *dst, const DXTBlock *src, int pitch)
{
int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3);
int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3);
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3);
colors[2] = makecol(red1 + red3, green1 + green3, blue1 + blue3, 255);
colors[3] = makecol(red2 - red3, green2 - green3, blue2 - blue3, 255);
}
Expand Down Expand Up @@ -2140,7 +2140,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u32 base = (tBlk * widthBlks + sBlk) * blockWidth * blockHeight;
u16 blkS = s & (blockWidth - 1);
u16 blkT = t & (blockHeight - 1);
u32 blkOff = blkT * blockWidth + blkS;
u32 blkOff = blkT * blockWidth + blkS;
*/

switch (texformat)
Expand All @@ -2154,9 +2154,9 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 7;
u16 blkT = t & 7;
u32 blkOff = (blkT << 3) + blkS;

int rs = (blkOff & 1)?0:4;
u32 offset = base + (blkOff >> 1);
u32 offset = base + (blkOff >> 1);

u8 val = (*(src + offset) >> rs) & 0xF;
u16 *tlut = (u16*)(texMem + tlutaddr);
Expand All @@ -2166,7 +2166,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
case 0:
*((u32*)dst) = decodeIA8Swapped(tlut[val]);
break;
case 1:
case 1:
*((u32*)dst) = decode565RGBA(Common::swap16(tlut[val]));
break;
case 2:
Expand All @@ -2184,9 +2184,9 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 7;
u16 blkT = t & 7;
u32 blkOff = (blkT << 3) + blkS;

int rs = (blkOff & 1)?0:4;
u32 offset = base + (blkOff >> 1);
u32 offset = base + (blkOff >> 1);

u8 val = (*(src + offset) >> rs) & 0xF;
val = Convert4To8(val);
Expand All @@ -2205,7 +2205,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 7;
u16 blkT = t & 3;
u32 blkOff = (blkT << 3) + blkS;

u8 val = *(src + base + blkOff);
dst[0] = val;
dst[1] = val;
Expand All @@ -2222,7 +2222,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 7;
u16 blkT = t & 3;
u32 blkOff = (blkT << 3) + blkS;

u8 val = *(src + base + blkOff);
u16 *tlut = (u16*)(texMem + tlutaddr);

Expand All @@ -2231,7 +2231,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
case 0:
*((u32*)dst) = decodeIA8Swapped(tlut[val]);
break;
case 1:
case 1:
*((u32*)dst) = decode565RGBA(Common::swap16(tlut[val]));
break;
case 2:
Expand All @@ -2249,7 +2249,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 7;
u16 blkT = t & 3;
u32 blkOff = (blkT << 3) + blkS;

u8 val = *(src + base + blkOff);
const u8 a = Convert4To8(val>>4);
const u8 l = Convert4To8(val&0xF);
Expand All @@ -2268,7 +2268,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 3;
u16 blkT = t & 3;
u32 blkOff = (blkT << 2) + blkS;

u32 offset = (base + blkOff) << 1;
const u16* valAddr = (u16*)(src + offset);

Expand All @@ -2284,7 +2284,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 3;
u16 blkT = t & 3;
u32 blkOff = (blkT << 2) + blkS;

u32 offset = (base + blkOff) << 1;
const u16* valAddr = (u16*)(src + offset);

Expand All @@ -2296,7 +2296,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
case 0:
*((u32*)dst) = decodeIA8Swapped(tlut[val]);
break;
case 1:
case 1:
*((u32*)dst) = decode565RGBA(Common::swap16(tlut[val]));
break;
case 2:
Expand All @@ -2314,7 +2314,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u16 blkS = s & 3;
u16 blkT = t & 3;
u32 blkOff = (blkT << 2) + blkS;

u32 offset = (base + blkOff) << 1;
const u16* valAddr = (u16*)(src + offset);

Expand Down Expand Up @@ -2372,7 +2372,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
u32 offset = (base + blkOff) << 3;

const DXTBlock* dxtBlock = (const DXTBlock*)(src + offset);

u16 c1 = Common::swap16(dxtBlock->color1);
u16 c2 = Common::swap16(dxtBlock->color2);
int blue1 = Convert5To8(c1 & 0x1F);
Expand All @@ -2391,7 +2391,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth
colorSel |= c1 > c2?0:4;

u32 color = 0;

switch (colorSel)
{
case 0:
Expand Down