normalize the efb to texture process for color textures to make it work the same in all the plugins and with the same accuracy as real hardware (almost :))

please test for regressions and fixes.
some little changes to make pixel shader more dx9 sm2.0 friendly. the condition is not to use pixel lighting ( sorry no hardware support for the quantity of parameters needed).

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6777 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado
2011-01-07 19:23:57 +00:00
parent 62b79028ef
commit f869281301
14 changed files with 185 additions and 181 deletions

View File

@ -26,7 +26,7 @@
// shader cache for every revision, graphics-related or not, which is simply annoying.
enum
{
LINEAR_DISKCACHE_VER = 6622
LINEAR_DISKCACHE_VER = 6777
};
// On disk format:

View File

@ -31,16 +31,17 @@
#define I_PLIGHTS "cLights"
#define I_PMATERIALS "cmtrl"
#define C_COLORS 0
#define C_KCOLORS (C_COLORS + 4)
#define C_ALPHA (C_KCOLORS + 4)
#define C_TEXDIMS (C_ALPHA + 1)
#define C_ZBIAS (C_TEXDIMS + 8)
#define C_INDTEXSCALE (C_ZBIAS + 2)
#define C_INDTEXMTX (C_INDTEXSCALE + 2)
#define C_FOG (C_INDTEXMTX + 6)
#define C_COLORMATRIX (C_FOG + 2)
#define C_PLIGHTS (C_COLORMATRIX + 5)
#define C_COLORMATRIX 0 // 0
#define C_COLORS 0 // 0
#define C_KCOLORS (C_COLORS + 4) // 4
#define C_ALPHA (C_KCOLORS + 4) // 8
#define C_TEXDIMS (C_ALPHA + 1) // 9
#define C_ZBIAS (C_TEXDIMS + 8) //17
#define C_INDTEXSCALE (C_ZBIAS + 2) //19
#define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
#define C_FOG (C_INDTEXMTX + 6) //27
#define C_PLIGHTS (C_FOG + 2)
#define C_PMATERIALS (C_PLIGHTS + 40)
#define C_PENVCONST_END (C_PMATERIALS + 4)
#define PIXELSHADERUID_MAX_VALUES (5 + 32 + 6 + 11 + 2)

View File

@ -395,10 +395,10 @@ void PixelShaderManager::SetFogParamChanged()
s_bFogParamChanged = true;
}
void PixelShaderManager::SetColorMatrix(const float* pmatrix, const float* pfConstAdd)
void PixelShaderManager::SetColorMatrix(const float* pmatrix)
{
SetMultiPSConstant4fv(C_COLORMATRIX,4,pmatrix);
SetPSConstant4fv(C_COLORMATRIX+4, pfConstAdd);
SetMultiPSConstant4fv(C_COLORMATRIX,7,pmatrix);
s_nColorsChanged[0] = s_nColorsChanged[1] = 15;
}
void PixelShaderManager::InvalidateXFRange(int start, int end)

View File

@ -51,7 +51,7 @@ public:
static void SetTexCoordChanged(u8 texmapid);
static void SetFogColorChanged();
static void SetFogParamChanged();
static void SetColorMatrix(const float* pmatrix, const float* pfConstAdd);
static void SetColorMatrix(const float* pmatrix);
static void InvalidateXFRange(int start, int end);
static void SetMaterialColor(int index, u32 data);
};

View File

@ -414,106 +414,64 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer,
{
DVSTARTPROFILE();
float colmat[20] = {};
// last four floats of colmat for fConstAdd
float colmat[28] = {0};
float *const fConstAdd = colmat + 16;
float *const ColorMask = colmat + 20;
ColorMask[0] = ColorMask[1] = ColorMask[2] = ColorMask[3] = 255.0f;
ColorMask[4] = ColorMask[5] = ColorMask[6] = ColorMask[7] = 1.0f / 255.0f;
unsigned int cbufid = -1;
if (bFromZBuffer)
{
// TODO: these values differ slightly from the DX9/11 values,
// do they need to? or can this be removed
if (g_ActiveConfig.backend_info.APIType == API_OPENGL)
switch (copyfmt)
{
switch(copyfmt)
{
case 0: // Z4
case 1: // Z8
case 8: // Z8
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
break;
case 0: // Z4
colmat[3] = colmat[7] = colmat[11] = colmat[15] = 1.0f;
cbufid = 0;
break;
case 1: // Z8
case 8: // Z8
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1.0f;
cbufid = 1;
break;
case 3: // Z16 //?
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1;
break;
case 3: // Z16
colmat[1] = colmat[5] = colmat[9] = colmat[12] = 1.0f;
cbufid = 13;
break;
case 11: // Z16 (reverse order)
colmat[2] = colmat[6] = colmat[10] = colmat[13] = 1;
break;
case 11: // Z16 (reverse order)
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1.0f;
cbufid = 2;
break;
case 6: // Z24X8
colmat[2] = colmat[5] = colmat[8] = colmat[15] = 1;
break;
case 6: // Z24X8
colmat[0] = colmat[5] = colmat[10] = 1.0f;
cbufid = 3;
break;
case 9: // Z8M
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1;
break;
case 9: // Z8M
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1.0f;
cbufid = 4;
break;
case 10: // Z8L
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
break;
case 10: // Z8L
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1.0f;
cbufid = 5;
break;
case 12: // Z16L
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1;
break;
case 12: // Z16L
colmat[2] = colmat[6] = colmat[10] = colmat[13] = 1.0f;
cbufid = 6;
break;
default:
ERROR_LOG(VIDEO, "Unknown copy zbuf format: 0x%x", copyfmt);
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
break;
}
}
else
{
switch (copyfmt)
{
case 0: // Z4
colmat[3] = colmat[7] = colmat[11] = colmat[15] = 1;
cbufid = 20;
break;
case 1: // Z8
case 8: // Z8
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1.0f;
cbufid = 12;
break;
case 3: // Z16
colmat[1] = colmat[5] = colmat[9] = colmat[12] = 1.0f;
cbufid = 13;
break;
case 11: // Z16 (reverse order)
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1.0f;
cbufid = 14;
break;
case 6: // Z24X8
colmat[0] = colmat[5] = colmat[10] = 1.0f;
cbufid = 15;
break;
case 9: // Z8M
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1.0f;
cbufid = 16;
break;
case 10: // Z8L
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1.0f;
cbufid = 17;
break;
case 12: // Z16L
colmat[2] = colmat[6] = colmat[10] = colmat[13] = 1.0f;
cbufid = 18;
break;
default:
ERROR_LOG(VIDEO, "Unknown copy zbuf format: 0x%x", copyfmt);
colmat[2] = colmat[5] = colmat[8] = 1.0f;
cbufid = 19;
break;
}
default:
ERROR_LOG(VIDEO, "Unknown copy zbuf format: 0x%x", copyfmt);
colmat[2] = colmat[5] = colmat[8] = 1.0f;
cbufid = 7;
break;
}
}
else if (bIsIntensityFmt)
{
@ -532,21 +490,40 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer,
if (copyfmt < 2 || copyfmt == 8)
{
fConstAdd[3] = 16.0f / 255.0f;
colmat[12] = 0.257f; colmat[13] = 0.504f; colmat[14] = 0.098f;
cbufid = 0;
fConstAdd[3] = 16.0f/255.0f;
if (copyfmt == 0)
{
ColorMask[0] = ColorMask[1] = ColorMask[2] = 15.0f;
ColorMask[4] = ColorMask[5] = ColorMask[6] = 1.0f / 15.0f;
cbufid = 8;
}
else
{
cbufid = 9;
}
}
else// alpha
{
colmat[15] = 1;
cbufid = 1;
if (copyfmt == 2)
{
ColorMask[0] = ColorMask[1] = ColorMask[2] = ColorMask[3] = 15.0f;
ColorMask[4] = ColorMask[5] = ColorMask[6] = ColorMask[7] = 1.0f / 15.0f;
cbufid = 10;
}
else
{
cbufid = 11;
}
}
break;
default:
ERROR_LOG(VIDEO, "Unknown copy intensity format: 0x%x", copyfmt);
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1.0f;
cbufid = 23;
break;
}
}
@ -555,59 +532,79 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer,
switch (copyfmt)
{
case 0: // R4
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
ColorMask[0] = 15.0f;
ColorMask[4] = 1.0f / 15.0f;
cbufid = 12;
break;
case 1: // R8
case 8: // R8
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
cbufid = 2;
cbufid = 13;
break;
case 2: // RA4
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1.0f;
ColorMask[0] = ColorMask[3] = 15.0f;
ColorMask[4] = ColorMask[7] = 1.0f / 15.0f;
cbufid = 14;
break;
case 3: // RA8
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1;
cbufid = 3;
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1.0f;
cbufid = 15;
break;
case 7: // A8
colmat[3] = colmat[7] = colmat[11] = colmat[15] = 1;
cbufid = 4;
colmat[3] = colmat[7] = colmat[11] = colmat[15] = 1.0f;
cbufid = 16;
break;
case 9: // G8
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1;
cbufid = 5;
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1.0f;
cbufid = 17;
break;
case 10: // B8
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
cbufid = 6;
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1.0f;
cbufid = 18;
break;
case 11: // RG8
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1;
cbufid = 7;
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1.0f;
cbufid = 19;
break;
case 12: // GB8
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1;
cbufid = 8;
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1.0f;
cbufid = 20;
break;
case 4: // RGB565
colmat[0] = colmat[5] = colmat[10] = 1;
fConstAdd[3] = 1; // set alpha to 1
cbufid = 9;
colmat[0] = colmat[5] = colmat[10] = 1.0f;
ColorMask[0] = ColorMask[2] = 31.0f;
ColorMask[4] = ColorMask[6] = 1.0f / 31.0f;
ColorMask[1] = 63.0f;
ColorMask[5] = 1.0f / 63.0f;
fConstAdd[3] = 1.0f; // set alpha to 1
cbufid = 21;
break;
case 5: // RGB5A3
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1.0f;
ColorMask[0] = ColorMask[1] = ColorMask[2] = 31.0f;
ColorMask[4] = ColorMask[5] = ColorMask[6] = 1.0f / 31.0f;
ColorMask[3] = 7.0f;
ColorMask[7] = 1.0f / 7.0f;
cbufid = 22;
break;
case 6: // RGBA8
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
cbufid = 10;
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1.0f;
cbufid = 23;
break;
default:
ERROR_LOG(VIDEO, "Unknown copy color format: 0x%x", copyfmt);
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
cbufid = 11;
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1.0f;
cbufid = 23;
break;
}
}