Started backport of features from OpenGL to D3D plugins (no visible effects yet). Some minor cleanup and checks. Deleted unnecessary file from SVN.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@9 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-07-15 20:11:18 +00:00
parent 982586cdc6
commit cbb3c55641
14 changed files with 2434 additions and 2120 deletions

View File

@ -233,7 +233,12 @@ LONG NTAPI Handler(PEXCEPTION_POINTERS pPtrs)
//Figure out what address was hit //Figure out what address was hit
DWORD_PTR badAddress = (DWORD_PTR)pPtrs->ExceptionRecord->ExceptionInformation[1]; DWORD_PTR badAddress = (DWORD_PTR)pPtrs->ExceptionRecord->ExceptionInformation[1];
//TODO: First examine the address, make sure it's within the emulated memory space //TODO: First examine the address, make sure it's within the emulated memory space
if (badAddress < memspaceBottom) {
PanicAlert("Exception handler - access below memory space. %08x%08x",
badAddress >> 32, badAddress);
}
u32 emAddress = (u32)(badAddress - memspaceBottom); u32 emAddress = (u32)(badAddress - memspaceBottom);
//Now we have the emulated address. //Now we have the emulated address.
//_assert_msg_(DYNA_REC,0,"MT : %08x",emAddress); //_assert_msg_(DYNA_REC,0,"MT : %08x",emAddress);

View File

@ -347,7 +347,6 @@ namespace Jit64
SetCodePtr(prev_code); SetCodePtr(prev_code);
} }
#define BLR_OP 0x4e800020 #define BLR_OP 0x4e800020
void InvalidateCodeRange(u32 address, u32 length) void InvalidateCodeRange(u32 address, u32 length)
@ -368,7 +367,6 @@ namespace Jit64
void ClearCache() void ClearCache()
{ {
// Is destroying the blocks really necessary? // Is destroying the blocks really necessary?
for (int i = 0; i < numBlocks; i++) for (int i = 0; i < numBlocks; i++)
{ {
@ -393,8 +391,8 @@ namespace Jit64
++counter; ++counter;
if (counter == 30) if (counter == 30)
{ {
counter ++; counter++;
counter --; counter--;
} }
// TODO: also mark and remember the instruction address as known HW memory access, for use in later compiles. // TODO: also mark and remember the instruction address as known HW memory access, for use in later compiles.

View File

@ -2,19 +2,18 @@ Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005 # Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "Core\Core\Core.vcproj", "{F0B874CB-4476-4199-9315-8343D05AE684}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "Core\Core\Core.vcproj", "{F0B874CB-4476-4199-9315-8343D05AE684}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{B7F1A9FB-BEA8-416E-9460-AE35A6A5165C} = {B7F1A9FB-BEA8-416E-9460-AE35A6A5165C}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510} {29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
{B7F1A9FB-BEA8-416E-9460-AE35A6A5165C} = {B7F1A9FB-BEA8-416E-9460-AE35A6A5165C}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_VideoDX9", "Plugins\Plugin_VideoDX9\Plugin_VideoDX9.vcproj", "{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_VideoDX9", "Plugins\Plugin_VideoDX9\Plugin_VideoDX9.vcproj", "{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{9A183B48-ECC2-4121-876A-9B3793686073} = {9A183B48-ECC2-4121-876A-9B3793686073}
{3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63}
{C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8} = {C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{F0B874CB-4476-4199-9315-8343D05AE684} = {F0B874CB-4476-4199-9315-8343D05AE684}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
{F0B874CB-4476-4199-9315-8343D05AE684} = {F0B874CB-4476-4199-9315-8343D05AE684}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8} = {C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8}
{3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_PadSimple", "Plugins\Plugin_PadSimple\Plugin_PadSimple.vcproj", "{9A183B48-ECC2-4121-876A-9B3793686073}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_PadSimple", "Plugins\Plugin_PadSimple\Plugin_PadSimple.vcproj", "{9A183B48-ECC2-4121-876A-9B3793686073}"
@ -40,21 +39,21 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_VideoOGL", "Plugins\
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Core\Common\Common.vcproj", "{C573CAF7-EE6A-458E-8049-16C0BF34C2E9}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Core\Common\Common.vcproj", "{C573CAF7-EE6A-458E-8049-16C0BF34C2E9}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxDolphin", "Core\DolphinWX\DolphinWX.vcproj", "{A72606EF-C5C1-4954-90AD-F0F93A8D97D9}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DolphinWX", "Core\DolphinWX\DolphinWX.vcproj", "{A72606EF-C5C1-4954-90AD-F0F93A8D97D9}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F} = {9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}
{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18} = {636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}
{C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8} = {C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160} = {CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}
{9A183B48-ECC2-4121-876A-9B3793686073} = {9A183B48-ECC2-4121-876A-9B3793686073}
{3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77} = {4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}
{F0B874CB-4476-4199-9315-8343D05AE684} = {F0B874CB-4476-4199-9315-8343D05AE684}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
{B7F1A9FB-BEA8-416E-9460-AE35A6A5165C} = {B7F1A9FB-BEA8-416E-9460-AE35A6A5165C} {B7F1A9FB-BEA8-416E-9460-AE35A6A5165C} = {B7F1A9FB-BEA8-416E-9460-AE35A6A5165C}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
{F0B874CB-4476-4199-9315-8343D05AE684} = {F0B874CB-4476-4199-9315-8343D05AE684}
{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77} = {4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63}
{9A183B48-ECC2-4121-876A-9B3793686073} = {9A183B48-ECC2-4121-876A-9B3793686073}
{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160} = {CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8} = {C60D0E7A-ED05-4C67-9EE7-3A6C0D7801C8}
{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18} = {636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}
{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F} = {9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxBase28", "..\Externals\wxWidgets\build\msw\wx_base.vcproj", "{48AD7E0A-25B1-4974-A1E3-03F8C438D34F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxBase28", "..\Externals\wxWidgets\build\msw\wx_base.vcproj", "{48AD7E0A-25B1-4974-A1E3-03F8C438D34F}"
@ -63,11 +62,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxCore28", "..\Externals\wx
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DebuggerWX", "Core\DebuggerWX\DebuggerWX.vcproj", "{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DebuggerWX", "Core\DebuggerWX\DebuggerWX.vcproj", "{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{F0B874CB-4476-4199-9315-8343D05AE684} = {F0B874CB-4476-4199-9315-8343D05AE684}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
{F0B874CB-4476-4199-9315-8343D05AE684} = {F0B874CB-4476-4199-9315-8343D05AE684}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_DSP_NULL", "Plugins\Plugin_DSP_NULL\Plugin_DSP_NULL.vcproj", "{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_DSP_NULL", "Plugins\Plugin_DSP_NULL\Plugin_DSP_NULL.vcproj", "{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}"

Binary file not shown.

View File

@ -18,6 +18,9 @@ BPMemory bpmem;
bool textureChanged[8]; bool textureChanged[8];
#define BPMEM_GENMODE 0x00 #define BPMEM_GENMODE 0x00
#define BPMEM_IND_MTX 0x06
#define BPMEM_RAS1_SS0 0x25 // ind tex coord scale 0
#define BPMEM_RAS1_SS1 0x26 // ind tex coord scale 1
#define BPMEM_ZMODE 0x40 #define BPMEM_ZMODE 0x40
#define BPMEM_BLENDMODE 0x41 #define BPMEM_BLENDMODE 0x41
#define BPMEM_CONSTANTALPHA 0x42 #define BPMEM_CONSTANTALPHA 0x42
@ -138,6 +141,29 @@ void BPWritten(int addr, int changes, int newval)
} }
} }
break; break;
case BPMEM_IND_MTX+0:
case BPMEM_IND_MTX+1:
case BPMEM_IND_MTX+2:
case BPMEM_IND_MTX+3:
case BPMEM_IND_MTX+4:
case BPMEM_IND_MTX+5:
case BPMEM_IND_MTX+6:
case BPMEM_IND_MTX+7:
case BPMEM_IND_MTX+8:
if (changes) {
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
// PixelShaderMngr::SetIndMatrixChanged((addr-BPMEM_IND_MTX)/3);
}
break;
case BPMEM_RAS1_SS0:
case BPMEM_RAS1_SS1:
if (changes) {
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
// PixelShaderMngr::SetIndTexScaleChanged();
}
break;
case BPMEM_ZMODE: case BPMEM_ZMODE:
if (changes) if (changes)
@ -195,63 +221,91 @@ void BPWritten(int addr, int changes, int newval)
break; break;
case BPMEM_LINEPTWIDTH: case BPMEM_LINEPTWIDTH:
// glPointSize(1); //bpmem.lineptwidth.pointsize); // We can't change line width in D3D. However, we can change point size. TODO
// glLineWidth(1); //bpmem.lineptwidth.linesize); //bpmem.lineptwidth.pointsize);
//bpmem.lineptwidth.linesize);
break; break;
case 0x43:
if (changes) {
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
}
break;
case BPMEM_BLENDMODE: case BPMEM_BLENDMODE:
if (changes & 0xFFFF) if (changes & 0xFFFF)
{ {
CVertexHandler::Flush(); CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval; ((u32*)&bpmem)[addr] = newval;
if (changes & 1) dev->SetRenderState(D3DRS_ALPHABLENDENABLE,bpmem.blendmode.blendenable); if (changes & 1) dev->SetRenderState(D3DRS_ALPHABLENDENABLE,bpmem.blendmode.blendenable);
if (changes & 4) dev->SetRenderState(D3DRS_DITHERENABLE,bpmem.blendmode.dither); if (changes & 2) ; // Logic op blending. D3D can't do this but can fake some modes.
if (changes & 4) {
// Dithering is pointless. Will make things uglier and will be different from GC.
// dev->SetRenderState(D3DRS_DITHERENABLE,bpmem.blendmode.dither);
}
D3DBLEND src = d3dSrcFactors[bpmem.blendmode.srcfactor]; D3DBLEND src = d3dSrcFactors[bpmem.blendmode.srcfactor];
D3DBLEND dst = d3dDestFactors[bpmem.blendmode.dstfactor]; D3DBLEND dst = d3dDestFactors[bpmem.blendmode.dstfactor];
if (changes & 0x700) dev->SetRenderState(D3DRS_SRCBLEND, src);
if (changes & 0xE0) dev->SetRenderState(D3DRS_DESTBLEND, dst);
if (changes & 0x800)
dev->SetRenderState(D3DRS_BLENDOP,bpmem.blendmode.subtract?D3DBLENDOP_SUBTRACT:D3DBLENDOP_ADD);
if (changes & 0x700) {
dev->SetRenderState(D3DRS_SRCBLEND, src);
}
if (changes & 0xE0) {
if (!bpmem.blendmode.subtract)
dev->SetRenderState(D3DRS_DESTBLEND, dst);
else
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
}
if (changes & 0x800) {
if (bpmem.blendmode.subtract) {
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
} else {
dev->SetRenderState(D3DRS_SRCBLEND, src);
dev->SetRenderState(D3DRS_DESTBLEND, dst);
}
dev->SetRenderState(D3DRS_BLENDOP,bpmem.blendmode.subtract?D3DBLENDOP_SUBTRACT:D3DBLENDOP_ADD);
}
//if (bpmem.blendmode.logicopenable) // && bpmem.blendmode.logicmode == 4) //if (bpmem.blendmode.logicopenable) // && bpmem.blendmode.logicmode == 4)
// MessageBox(0,"LOGIC",0,0); // MessageBox(0,"LOGIC",0,0);
if (changes & 0x18) if (changes & 0x18)
{ {
// Color Mask
DWORD write = 0; DWORD write = 0;
if (bpmem.blendmode.alphaupdate) if (bpmem.blendmode.alphaupdate)
write = D3DCOLORWRITEENABLE_ALPHA; write = D3DCOLORWRITEENABLE_ALPHA;
if (bpmem.blendmode.colorupdate) if (bpmem.blendmode.colorupdate)
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE; write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
dev->SetRenderState(D3DRS_COLORWRITEENABLE,write); dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
} }
} }
break; break;
case BPMEM_FOGPARAM0: case BPMEM_FOGPARAM0:
{ {
u32 fogATemp = bpmem.fog.a<<12; // u32 fogATemp = bpmem.fog.a<<12;
float fogA = *(float*)(&fogATemp); // float fogA = *(float*)(&fogATemp);
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
} }
break; break;
case BPMEM_FOGBEXPONENT: case BPMEM_FOGBEXPONENT:
{
}
break;
case BPMEM_FOGBMAGNITUDE: case BPMEM_FOGBMAGNITUDE:
{ {
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
} }
break; break;
case BPMEM_FOGPARAM3: case BPMEM_FOGPARAM3:
//fog settings //fog settings
{ {
u32 fogCTemp = bpmem.fog.c_proj_fsel.cShifted12 << 12; /// u32 fogCTemp = bpmem.fog.c_proj_fsel.cShifted12 << 12;
float fogC = *(float*)(&fogCTemp); // float fogC = *(float*)(&fogCTemp);
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
} }
break; break;
@ -272,11 +326,6 @@ void BPWritten(int addr, int changes, int newval)
{ {
CVertexHandler::Flush(); CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval; ((u32*)&bpmem)[addr] = newval;
int x=bpmem.scissorOffset.x*2-342;
int y=bpmem.scissorOffset.y*2-342;
char temp[256];
sprintf(temp,"ScissorOffset: %i %i",x,y);
g_VideoInitialize.pLog(temp, FALSE);
} }
break; break;
@ -304,9 +353,41 @@ void BPWritten(int addr, int changes, int newval)
} }
break; break;
case BPMEM_ZTEX1: case BPMEM_ZTEX1:
if (changes) {
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
//PRIM_LOG("ztex bias=0x%x\n", bpmem.ztex1.bias);
//PixelShaderMngr::SetZTextureBias(bpmem.ztex1.bias);
}
break; break;
case BPMEM_ZTEX2: case BPMEM_ZTEX2:
if (changes) {
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
#ifdef _DEBUG
const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"};
const char* pztype[] = {"Z8", "Z16", "Z24", "?"};
PRIM_LOG("ztex op=%s, type=%s\n", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]);
#endif
}
break; break;
case 0xf6: // ksel0
case 0xf7: // ksel1
case 0xf8: // ksel2
case 0xf9: // ksel3
case 0xfa: // ksel4
case 0xfb: // ksel5
case 0xfc: // ksel6
case 0xfd: // ksel7
if (changes)
{
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
// PixelShaderMngr::SetTevKSelChanged(addr-0xf6);
}
break;
default: default:
switch(addr & 0xF8) //texture sampler filter switch(addr & 0xF8) //texture sampler filter
{ {
@ -412,6 +493,15 @@ void BPWritten(int addr, int changes, int newval)
//dev->SetRenderState(D3DRS_WRAP0+stage, D3DWRAPCOORD_0); //dev->SetRenderState(D3DRS_WRAP0+stage, D3DWRAPCOORD_0);
} }
break; break;
case 0xC0:
case 0xD0:
if (changes)
{
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
// PixelShaderMngr::SetTevCombinerChanged((addr&0x1f)/2);
}
break;
case 0xE0: case 0xE0:
if (addr<0xe8) if (addr<0xe8)
@ -446,8 +536,6 @@ void BPWritten(int addr, int changes, int newval)
} }
break; break;
case 0x20: case 0x20:
case 0xC0:
case 0xD0:
case 0x80: case 0x80:
case 0x90: case 0x90:
case 0xA0: case 0xA0:
@ -510,14 +598,8 @@ void LoadBPReg(u32 value0)
DebugLog("SetPEToken + INT 0x%04x", (value0 & 0xFFFF)); DebugLog("SetPEToken + INT 0x%04x", (value0 & 0xFFFF));
break; break;
case 0x67: case 0x67: // set gp metric?
{ break;
// char test[256];
// sprintf(test, "Setgpmetric: 0x%08x", value0);
// MessageBox(0, test, "Setgpmetric", 0);
}
//Setgpmetric
break;
case 0x52: case 0x52:
{ {
@ -551,6 +633,7 @@ void LoadBPReg(u32 value0)
if (PE_copy.copy_to_xfb == 0) // bpmem.triggerEFBCopy & EFBCOPY_EFBTOTEXTURE) if (PE_copy.copy_to_xfb == 0) // bpmem.triggerEFBCopy & EFBCOPY_EFBTOTEXTURE)
{ {
// EFB to texture // EFB to texture
// for some reason it sets bpmem.zcontrol.pixel_format to PIXELFMT_Z24 every time a zbuffer format is given as a dest to GXSetTexCopyDst
TextureCache::CopyEFBToRenderTarget(bpmem.copyTexDest<<5, &rc); TextureCache::CopyEFBToRenderTarget(bpmem.copyTexDest<<5, &rc);
} }
else else

View File

@ -36,6 +36,17 @@ enum Compare
COMPARE_ALWAYS COMPARE_ALWAYS
}; };
#define TEVCMP_R8_GT 8
#define TEVCMP_R8_EQ 9
#define TEVCMP_GR16_GT 10
#define TEVCMP_GR16_EQ 11
#define TEVCMP_BGR24_GT 12
#define TEVCMP_BGR24_EQ 13
#define TEVCMP_RGB8_GT 14
#define TEVCMP_RGB8_EQ 15
#define TEVCMP_A8_GT 14
#define TEVCMP_A8_EQ 15
//color chan above: //color chan above:
// rasterized color selections // rasterized color selections
#define RAS1_CC_0 0x00000000 /* color channel 0 */ #define RAS1_CC_0 0x00000000 /* color channel 0 */
@ -49,6 +60,63 @@ enum Compare
#define TEV_Z_TYPE_U16 0x00000001 #define TEV_Z_TYPE_U16 0x00000001
#define TEV_Z_TYPE_U24 0x00000002 #define TEV_Z_TYPE_U24 0x00000002
#define ZTEXTURE_DISABLE 0
#define ZTEXTURE_ADD 1
#define ZTEXTURE_REPLACE 2
union IND_MTXA
{
struct
{
signed ma : 11;
signed mb : 11;
unsigned s0 : 2; // bits 0-1 of scale factor
unsigned rid : 8;
};
u32 hex;
};
union IND_MTXB
{
struct
{
signed mc : 11;
signed md : 11;
unsigned s1 : 2; // bits 2-3 of scale factor
unsigned rid : 8;
};
u32 hex;
};
union IND_MTXC
{
struct
{
signed me : 11;
signed mf : 11;
unsigned s2 : 2; // bits 4-5 of scale factor
unsigned rid : 8;
};
u32 hex;
};
struct IND_MTX
{
IND_MTXA col0;
IND_MTXB col1;
IND_MTXC col2;
};
union IND_IMASK
{
struct
{
unsigned mask : 24;
unsigned rid : 8;
};
u32 hex;
};
struct TevStageCombiner struct TevStageCombiner
{ {
@ -65,7 +133,7 @@ struct TevStageCombiner
unsigned op : 1; unsigned op : 1;
unsigned clamp : 1; unsigned clamp : 1;
unsigned scale : 2; unsigned shift : 2;
unsigned outreg : 2; //1,2,3 unsigned outreg : 2; //1,2,3
}; };
@ -86,7 +154,7 @@ struct TevStageCombiner
unsigned op : 1; unsigned op : 1;
unsigned clamp : 1; unsigned clamp : 1;
unsigned scale : 2; unsigned shift : 2;
unsigned outreg : 2; //1,2,3 unsigned outreg : 2; //1,2,3
}; };
u32 hex; u32 hex;
@ -96,6 +164,68 @@ struct TevStageCombiner
AlphaCombiner alphaC; AlphaCombiner alphaC;
}; };
#define ITF_8 0
#define ITF_5 1
#define ITF_4 2
#define ITF_3 3
#define ITB_NONE 0
#define ITB_S 1
#define ITB_T 2
#define ITB_ST 3
#define ITB_U 4
#define ITB_SU 5
#define ITB_TU 6
#define ITB_STU 7
#define ITBA_OFF 0
#define ITBA_S 1
#define ITBA_T 2
#define ITBA_U 3
#define ITW_OFF 0
#define ITW_256 1
#define ITW_128 2
#define ITW_64 3
#define ITW_32 4
#define ITW_16 5
#define ITW_0 6
// several discoveries:
// GXSetTevIndBumpST(tevstage, indstage, matrixind)
// if( matrix == 2 ) realmat = 6; // 10
// else if( matrix == 3 ) realmat = 7; // 11
// else if( matrix == 1 ) realmat = 5; // 9
// GXSetTevIndirect(tevstage, indstage, 0, 3, realmat, 6, 6, 0, 0, 0)
// GXSetTevIndirect(tevstage+1, indstage, 0, 3, realmat+4, 6, 6, 1, 0, 0)
// GXSetTevIndirect(tevstage+2, indstage, 0, 0, 0, 0, 0, 1, 0, 0)
union TevStageIndirect
{
// if mid, sw, tw, and addprev are 0, then no indirect stage is used, mask = 0x17fe00
struct
{
unsigned bt : 2; // indirect tex stage ID
unsigned fmt : 2; // format: ITF_X
unsigned bias : 3; // ITB_X
unsigned bs : 2; // ITBA_X, indicates which coordinate will become the 'bump alpha'
unsigned mid : 4; // matrix id to multiply offsets with
unsigned sw : 3; // ITW_X, wrapping factor for S of regular coord
unsigned tw : 3; // ITW_X, wrapping factor for T of regular coord
unsigned lb_utclod : 1; // use modified or unmodified texture coordinates for LOD computation
unsigned fb_addprev : 1; // 1 if the texture coordinate results from the previous TEV stage should be added
unsigned pad0 : 3;
unsigned rid : 8;
};
struct
{
u32 hex : 21;
u32 unused : 11;
};
bool IsActive() { return (hex&0x17fe00)!=0; }
};
union TwoTevStageOrders union TwoTevStageOrders
{ {
struct struct
@ -121,7 +251,42 @@ union TwoTevStageOrders
int getColorChan(int i){return i?colorchan1:colorchan0;} int getColorChan(int i){return i?colorchan1:colorchan0;}
}; };
union TEXSCALE
{
struct
{
unsigned ss0 : 4; // indirect tex stage 0, 2^(-ss0)
unsigned ts0 : 4; // indirect tex stage 0
unsigned ss1 : 4; // indirect tex stage 1
unsigned ts1 : 4; // indirect tex stage 1
unsigned pad : 8;
unsigned rid : 8;
};
u32 hex;
float getScaleS(int i){return 1.0f/(float)(1<<(i?ss1:ss0));}
float getScaleT(int i){return 1.0f/(float)(1<<(i?ts1:ts0));}
};
union RAS1_IREF
{
struct
{
unsigned bi0 : 3; // indirect tex stage 0 ntexmap
unsigned bc0 : 3; // indirect tex stage 0 ntexcoord
unsigned bi1 : 3;
unsigned bc1 : 3;
unsigned bi2 : 3;
unsigned bc3 : 3;
unsigned bi4 : 3;
unsigned bc4 : 3;
unsigned rid : 8;
};
u32 hex;
u32 getTexCoord(int i) { return (hex>>(6*i+3))&3; }
u32 getTexMap(int i) { return (hex>>(6*i))&3; }
};
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Texture structs // Texture structs
@ -328,17 +493,27 @@ union FogParam0
}; };
union FogParam3 union FogParam3
{ {
struct struct
{ {
unsigned cShifted12 : 20; unsigned c_mant : 11;
unsigned proj : 1; unsigned c_exp : 8;
unsigned fsel : 3; unsigned c_sign : 1;
}; unsigned proj : 1; // 0 - perspective, 1 - orthographic
u32 hex; unsigned fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
};
// amount to subtract from eyespacez after range adjustment
float GetC() {
union { u32 i; float f; } dummy;
dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12);
return dummy.f;
}
u32 hex;
}; };
struct FogParams struct FogParams
{ {
u32 a; FogParam0 a;
u32 b_magnitude; u32 b_magnitude;
u32 b_exponent; u32 b_exponent;
FogParam3 c_proj_fsel; FogParam3 c_proj_fsel;
@ -366,6 +541,29 @@ union ConstantAlpha
u32 hex; u32 hex;
}; };
#define PIXELFMT_RGB8_Z24 0
#define PIXELFMT_RGBA6_Z24 1
#define PIXELFMT_RGB565_Z16 2
#define PIXELFMT_Z24 3
#define PIXELFMT_Y8 4
#define PIXELFMT_U8 5
#define PIXELFMT_V8 6
#define PIXELFMT_YUV420 7
union PE_CONTROL
{
struct
{
unsigned pixel_format : 3; // PIXELFMT_X
unsigned zformat : 3; // 0 - linear, 1 - near, 2 - mid, 3 - far
unsigned zcomploc : 1; // 1: before tex stage
unsigned unused : 17;
unsigned rid : 8;
};
u32 hex;
};
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Texture coordinate stuff // Texture coordinate stuff
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -385,11 +583,6 @@ struct TCoordInfo
TCInfo t; TCInfo t;
}; };
//////////////////////////////////////////////////////////////////////////
// All of BP memory
//////////////////////////////////////////////////////////////////////////
union ColReg union ColReg
{ {
u32 hex; u32 hex;
@ -460,31 +653,48 @@ union UPE_Copy
#define EFBCOPY_CLEAR 0x800 #define EFBCOPY_CLEAR 0x800
#define EFBCOPY_GENERATEMIPS 0x200 #define EFBCOPY_GENERATEMIPS 0x200
//////////////////////////////////////////////////////////////////////////
// All of BP memory
//////////////////////////////////////////////////////////////////////////
struct BPMemory struct BPMemory
{ {
GenMode genMode; GenMode genMode;
u32 unknown[15]; //0f = flushtexturestate u32 display_copy_filter[4]; //01-04
u32 tevind[16]; u32 unknown; //05
// indirect matrices (set by GXSetIndTexMtx, selected by TevStageIndirect::mid)
// abc form a 2x3 offset matrix, there's 3 such matrices
// the 3 offset matrices can either be indirect type, S-type, or T-type
// 6bit scale factor s is distributed across IND_MTXA/B/C.
// before using matrices scale by 2^-(s-17)
IND_MTX indmtx[3];//06-0e GXSetIndTexMtx, 2x3 matrices
IND_IMASK imask;//0f
TevStageIndirect tevind[16];//10 GXSetTevIndirect
X12Y12 scissorTL; //20 X12Y12 scissorTL; //20
X12Y12 scissorBR; //21 X12Y12 scissorBR; //21
LPSize lineptwidth; //22 line and point width LPSize lineptwidth; //22 line and point width
u32 unknown1[2]; //23-24 u32 sucounter; //23
u32 unknown2[3]; //25-27 u32 rascounter; //24
TEXSCALE texscale[2]; //25-26 GXSetIndTexCoordScale
RAS1_IREF tevindref; //27 GXSetIndTexOrder
TwoTevStageOrders tevorders[8]; //28-2F TwoTevStageOrders tevorders[8]; //28-2F
TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t... TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t...
ZMode zmode; //40 ZMode zmode; //40
BlendMode blendmode; //41 BlendMode blendmode; //41
ConstantAlpha dstalpha; //42 ConstantAlpha dstalpha; //42
u32 unknown4; //43 // GXSetZCompLoc, GXPixModeSync PE_CONTROL zcontrol; //43 GXSetZCompLoc, GXPixModeSync
u32 fieldmask; //44 u32 fieldmask; //44
u32 drawdone; //45 u32 drawdone; //45, bit1=1 if end of list
u32 unknown5; //46 u32 unknown5; //46 clock?
u32 drawsync1; //47 u32 petoken; //47
u32 drawsync2; //48 u32 petokenint; //48
X10Y10 copyTexSrcXY; //49 X10Y10 copyTexSrcXY; //49
X10Y10 copyTexSrcWH; //4a X10Y10 copyTexSrcWH; //4a
u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it) u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it)
u32 unknown6[2]; //4c, 4d u32 unknown6; //4c, 4d
u32 copyMipMapStrideChannels; // 4d usually set to 4 when dest is single channel, 8 when dest is 2 channel, 16 when dest is RGBA
// also, doubles whenever mipmap box filter option is set (excent on RGBA). Probably to do with number of bytes to look at when smoothing
u32 dispcopyyscale; //4e u32 dispcopyyscale; //4e
u32 clearcolorAR; //4f u32 clearcolorAR; //4f
u32 clearcolorGB; //50 u32 clearcolorGB; //50
@ -500,13 +710,16 @@ struct BPMemory
u32 tlutXferDest; //65 u32 tlutXferDest; //65
u32 texinvalidate;//66 u32 texinvalidate;//66
u32 unknown9; //67 u32 unknown9; //67
u32 unknown10[8];//68-6F u32 fieldmode; //68
u32 unknown10[7];//69-6F
u32 unknown11[16];//70-7F u32 unknown11[16];//70-7F
FourTexUnits tex[2]; //80-bf FourTexUnits tex[2]; //80-bf
TevStageCombiner combiners[16]; //0xC0-0xDF TevStageCombiner combiners[16]; //0xC0-0xDF
TevReg tevregs[4]; //0xE0 TevReg tevregs[4]; //0xE0
u32 fogRangeAdj; //0xE8 u32 fogRangeAdj; //0xE8
u32 unknown15[5]; //0xe9,0xea,0xeb,0xec,0xed u32 unknown15[3]; //0xe9,0xea,0xeb,0xec,0xed
u32 tev_range_adj_c; //0xec - screenx center for range adjustment, range adjustment enable
u32 tev_range_adj_k; //0xed - specifies range adjustment function = sqrt(x*x+k*k)/k
FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2 FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2
AlphaFunc alphaFunc; //0xF3 AlphaFunc alphaFunc; //0xF3
ZTex1 ztex1; //0xf4,0xf5 ZTex1 ztex1; //0xf4,0xf5

View File

@ -1,4 +1,5 @@
#include <d3dx9.h> #include <d3dx9.h>
#include <string>
#include "Globals.h" #include "Globals.h"
#include "D3DShader.h" #include "D3DShader.h"
@ -9,7 +10,7 @@ namespace D3D
LPDIRECT3DVERTEXSHADER9 CompileVShader(const char *code, int len) LPDIRECT3DVERTEXSHADER9 CompileVShader(const char *code, int len)
{ {
//try to compile //try to compile
LPD3DXBUFFER shaderBuffer=0,errorBuffer=0; LPD3DXBUFFER shaderBuffer = 0, errorBuffer = 0;
LPDIRECT3DVERTEXSHADER9 vShader = 0; LPDIRECT3DVERTEXSHADER9 vShader = 0;
HRESULT hr = D3DXCompileShader(code,len,0,0,"main","vs_1_1",0,&shaderBuffer,&errorBuffer,0); HRESULT hr = D3DXCompileShader(code,len,0,0,"main","vs_1_1",0,&shaderBuffer,&errorBuffer,0);
if (FAILED(hr)) if (FAILED(hr))
@ -20,10 +21,13 @@ namespace D3D
if (FAILED(hr)) if (FAILED(hr))
{ {
//compilation error, damnit //compilation error
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
if (g_Config.bShowShaderErrors) if (g_Config.bShowShaderErrors)
MessageBox(0,(char*)errorBuffer->GetBufferPointer(),"VS compilation error",MB_ICONERROR); MessageBox(0, hello.c_str(), "Error compiling vertex shader", MB_ICONERROR);
vShader=0; vShader = 0;
} }
else if (SUCCEEDED(hr)) else if (SUCCEEDED(hr))
{ {
@ -72,7 +76,7 @@ namespace D3D
LPDIRECT3DPIXELSHADER9 CompilePShader(const char *code, int len) LPDIRECT3DPIXELSHADER9 CompilePShader(const char *code, int len)
{ {
LPD3DXBUFFER shaderBuffer=0,errorBuffer=0; LPD3DXBUFFER shaderBuffer = 0, errorBuffer = 0;
LPDIRECT3DPIXELSHADER9 pShader = 0; LPDIRECT3DPIXELSHADER9 pShader = 0;
static char *versions[6] = {"ERROR","ps_1_1","ps_1_4","ps_2_0","ps_3_0","ps_4_0"}; static char *versions[6] = {"ERROR","ps_1_1","ps_1_4","ps_2_0","ps_3_0","ps_4_0"};
HRESULT hr = D3DXCompileShader(code,len,0,0, HRESULT hr = D3DXCompileShader(code,len,0,0,
@ -81,10 +85,12 @@ namespace D3D
if (FAILED(hr)) if (FAILED(hr))
{ {
// We should not be getting these std::string hello = (char*)errorBuffer->GetBufferPointer();
MessageBox(0,code,(char*)errorBuffer->GetBufferPointer(),MB_ICONERROR); hello += "\n\n";
hello += code;
pShader=0; if (g_Config.bShowShaderErrors)
MessageBox(0, hello.c_str(), "Error compiling pixel shader", MB_ICONERROR);
pShader = 0;
} }
else else
{ {

View File

@ -183,22 +183,26 @@ const char *tevAInputTable[] =
"rastemp.a", //RASA, "rastemp.a", //RASA,
"konsttemp.a", //KONST, (hw1 had quarter) "konsttemp.a", //KONST, (hw1 had quarter)
"0.0", //ZERO "0.0", //ZERO
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", };
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
"PADERROR",
const char *tevAInputTable2[] =
{
"prev", //APREV,
"c0", //A0,
"c1", //A1,
"c2", //A2,
"textemp", //TEXA,
"rastemp", //RASA,
"konsttemp", //KONST, (hw1 had quarter)
"0.0", //ZERO
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
}; };
const char *tevRasTable[] = const char *tevRasTable[] =
@ -208,48 +212,49 @@ const char *tevRasTable[] =
"ERROR", //2 "ERROR", //2
"ERROR", //3 "ERROR", //3
"ERROR", //4 "ERROR", //4
"float4(0,1,0,1)", //RAS1_CC_B 0x00000005 /* indirect texture bump alpha */ //green cuz unsupported "alphabump", //RAS1_CC_B 0x00000005 /* indirect texture bump alpha */ //green cuz unsupported
"float4(0,1,0,1)", //RAS1_CC_BN 0x00000006 /* ind tex bump alpha, normalized 0-255 *///green cuz unsupported "(alphabump*(255.0f/248.0f))", //RAS1_CC_BN 0x00000006 /* ind tex bump alpha, normalized 0-255 *///green cuz unsupported
"float4(0,0,0,0)", //RAS1_CC_Z 0x00000007 /* set color value to zero */ "float4(0,0,0,0)", //RAS1_CC_Z 0x00000007 /* set color value to zero */
}; };
const char *tevCOutputTable[] = const char *tevCOutputTable[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" };
{ const char *tevAOutputTable[] = { "prev.a", "c0.a", "c1.a", "c2.a" };
"prev.rgb", const char *tevIndAlphaSel[] = {"", "x", "y", "z"};
"c0.rgb", const char *tevIndAlphaScale[] = {"", "*32","*16","*8"};
"c1.rgb", const char *tevIndBiasField[] = {"", "x", "y", "xy", "z", "xz", "yz", "xyz"}; // indexed by bias
"c2.rgb", const char *tevIndBiasAdd[] = {"-128.0f", "1.0f", "1.0f", "1.0f" }; // indexed by fmt
}; const char *tevIndWrapStart[] = {"0", "256", "128", "64", "32", "16", "0.001" };
const char *tevAOutputTable[] = const char *tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" };
{
"prev.a",
"c0.a",
"c1.a",
"c2.a",
};
const char *texFuncs[] = const char *tevTexFuncs[] =
{ {
"tex2D", "tex2D",
"tex2Dproj" "tex2Dproj"
}; };
const char *alphaRef[2] =
{
"alphaRef.x",
"alphaRef.y"
};
//I hope we don't get too many hash collisions :p //I hope we don't get too many hash collisions :p
//all these magic numbers are primes, it should help a bit //all these magic numbers are primes, it should help a bit
tevhash GetCurrentTEV() tevhash GetCurrentTEV()
{ {
u32 hash = bpmem.genMode.numindstages + bpmem.genMode.numtevstages*11 + bpmem.genMode.numtexgens*8*17; u32 hash = bpmem.genMode.numindstages + bpmem.genMode.numtevstages*11 + bpmem.genMode.numtexgens*8*17;
for (int i=0; i<(int)bpmem.genMode.numtevstages+1; i++) for (int i = 0; i < (int)bpmem.genMode.numtevstages+1; i++)
{ {
hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13); hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13);
hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3); hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3);
hash = _rotl(hash,9) ^ texcoords[i].texmtxinfo.projection*451; hash = _rotl(hash,9) ^ texcoords[i].texmtxinfo.projection*451;
} }
for (int i=0; i<(int)bpmem.genMode.numtevstages/2+1; i++) for (int i = 0; i < (int)bpmem.genMode.numtevstages/2+1; i++)
{ {
hash = _rotl(hash,13) ^ (bpmem.tevorders[i].hex*7); hash = _rotl(hash,13) ^ (bpmem.tevorders[i].hex*7);
} }
for (int i=0; i<8; i++) for (int i = 0; i < 8; i++)
{ {
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap1; hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap1;
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap2; hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap2;
@ -275,7 +280,7 @@ char swapModeTable[4][5];
void BuildSwapModeTable() void BuildSwapModeTable()
{ {
//bpmem.tevregs[0]. //bpmem.tevregs[0].
for (int i=0; i<4; i++) for (int i = 0; i < 4; i++)
{ {
swapModeTable[i][0]=swapColors[bpmem.tevksel[i*2].swap1]; swapModeTable[i][0]=swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1]=swapColors[bpmem.tevksel[i*2].swap2]; swapModeTable[i][1]=swapColors[bpmem.tevksel[i*2].swap2];
@ -302,10 +307,10 @@ LPDIRECT3DPIXELSHADER9 GeneratePixelShader()
bpmem.genMode.numtevstages,bpmem.genMode.numtexgens,bpmem.genMode.numindstages,bpmem.genMode.numcolchans); bpmem.genMode.numtevstages,bpmem.genMode.numtexgens,bpmem.genMode.numindstages,bpmem.genMode.numcolchans);
//write kcolor declarations //write kcolor declarations
for (int i=0; i<4; i++) for (int i = 0; i < 4; i++)
WRITE(p,"float4 k%i : register(c%i);\n",i,PS_CONST_KCOLORS+i); WRITE(p,"float4 k%i : register(c%i);\n",i,PS_CONST_KCOLORS+i);
for (int i=0; i<3; i++) for (int i = 0; i < 3; i++)
WRITE(p,"float4 color%i : register(c%i);\n",i,PS_CONST_COLORS+i+1); WRITE(p,"float4 color%i : register(c%i);\n",i,PS_CONST_COLORS+i+1);
WRITE(p,"float constalpha : register(c%i);\n",PS_CONST_CONSTALPHA); WRITE(p,"float constalpha : register(c%i);\n",PS_CONST_CONSTALPHA);
@ -330,7 +335,7 @@ LPDIRECT3DPIXELSHADER9 GeneratePixelShader()
//WRITE(p, "return 1;}\n"); //WRITE(p, "return 1;}\n");
//return D3D::CompilePShader(text,(int)(p-text)); //return D3D::CompilePShader(text,(int)(p-text));
for (int i=0; i<numStages; i++) for (int i = 0; i < numStages; i++)
WriteStage(p,i); //build the equation for this stage WriteStage(p,i); //build the equation for this stage
//WRITE(p, "prev = textemp;\n"); //WRITE(p, "prev = textemp;\n");
@ -369,7 +374,7 @@ void WriteStage(char *&p, int n)
WRITE(p,"rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap); WRITE(p,"rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap);
if (bpmem.tevorders[n/2].getEnable(n&1)) if (bpmem.tevorders[n/2].getEnable(n&1))
WRITE(p,"textemp=%s(samp[%i],uv[%i]).%s;\n", WRITE(p,"textemp=%s(samp[%i],uv[%i]).%s;\n",
texFuncs[texfun], tevTexFuncs[texfun],
bpmem.tevorders[n/2].getTexMap(n&1), bpmem.tevorders[n/2].getTexMap(n&1),
bpmem.tevorders[n/2].getTexCoord(n&1),texswap); bpmem.tevorders[n/2].getTexCoord(n&1),texswap);
else else
@ -393,7 +398,7 @@ void WriteStage(char *&p, int n)
if (cc.bias != TB_COMPARE) if (cc.bias != TB_COMPARE)
{ {
//normal color combiner goes here //normal color combiner goes here
WRITE(p," %s*(%s%s",tevScaleTable[cc.scale],tevCInputTable[cc.d],tevOpTable[cc.op]); WRITE(p," %s*(%s%s",tevScaleTable[cc.shift],tevCInputTable[cc.d],tevOpTable[cc.op]);
WRITE(p,"(lerp(%s,%s,%s)%s)),\n", WRITE(p,"(lerp(%s,%s,%s)%s)),\n",
tevCInputTable[cc.a],tevCInputTable[cc.b], tevCInputTable[cc.a],tevCInputTable[cc.b],
tevCInputTable[cc.c],tevBiasTable[cc.bias]); tevCInputTable[cc.c],tevBiasTable[cc.bias]);
@ -401,7 +406,7 @@ void WriteStage(char *&p, int n)
else else
{ {
//compare color combiner goes here //compare color combiner goes here
switch(cc.scale) // yep comparemode stored here :P switch(cc.shift) // yep comparemode stored here :P
{ {
case TEV_COMP_R8: case TEV_COMP_R8:
if (cc.op == 0) //equality check needs tolerance, fp in gpu has drawbacks :( if (cc.op == 0) //equality check needs tolerance, fp in gpu has drawbacks :(
@ -426,35 +431,48 @@ void WriteStage(char *&p, int n)
if (ac.bias != TB_COMPARE) if (ac.bias != TB_COMPARE)
{ {
//normal alpha combiner goes here //normal alpha combiner goes here
WRITE(p," %s*(%s%s",tevScaleTable[ac.scale],tevAInputTable[ac.d],tevOpTable[ac.op]); WRITE(p," %s*(%s%s",tevScaleTable[ac.shift],tevAInputTable[ac.d],tevOpTable[ac.op]);
WRITE(p,"(lerp(%s,%s,%s)%s))\n", WRITE(p,"lerp(%s,%s,%s) %s)\n",
tevAInputTable[ac.a],tevAInputTable[ac.b], tevAInputTable[ac.a],tevAInputTable[ac.b],
tevAInputTable[ac.c],tevBiasTable[ac.bias]); tevAInputTable[ac.c],tevBiasTable[ac.bias]);
} }
else else
{ {
int cmp = (ac.shift<<1)|ac.op|8; // comparemode stored here
//compare alpha combiner goes here //compare alpha combiner goes here
if (ac.op==0) switch(cmp) {
WRITE(p," %s + ((%s > %s) ? %s : 0)\n", case TEVCMP_R8_GT:
tevAInputTable[ac.d],tevAInputTable[ac.a], case TEVCMP_A8_GT:
tevAInputTable[ac.b],tevAInputTable[ac.c]); WRITE(p," %s + ((%s.%s > %s.%s) ? %s : 0)\n",
else tevAInputTable[ac.d],tevAInputTable2[ac.a], cmp==TEVCMP_R8_GT?"r":"a", tevAInputTable2[ac.b], cmp==TEVCMP_R8_GT?"r":"a", tevAInputTable[ac.c]);
WRITE(p," %s + (abs(%s - %s)<%f ? %s : 0)\n", break;
tevAInputTable[ac.d],tevAInputTable[ac.a], case TEVCMP_R8_EQ:
tevAInputTable[ac.b],epsilon,tevAInputTable[ac.c]); case TEVCMP_A8_EQ:
WRITE(p," %s + (abs(%s.r - %s.r)<%f ? %s : 0)\n",
tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b],epsilon,tevAInputTable[ac.c]);
break;
case TEVCMP_GR16_GT: // 16 bit compares: 255*g+r (probably used for ztextures, so make sure in ztextures, g is the most significant byte)
case TEVCMP_BGR24_GT: // 24 bit compares: 255*255*b+255*g+r
WRITE(p," %s + (( dot(%s.rgb-%s.rgb, comp%s) > 0) ? %s : 0)\n",
tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b], cmp==TEVCMP_GR16_GT?"16":"24", tevAInputTable[ac.c]);
break;
case TEVCMP_GR16_EQ:
case TEVCMP_BGR24_EQ:
WRITE(p," %s + (abs(dot(%s.rgb - %s.rgb, comp%s))<%f ? %s : 0)\n",
tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b],cmp==TEVCMP_GR16_GT?"16":"24",epsilon,tevAInputTable[ac.c]);
break;
default:
WRITE(p,"0)\n");
break;
}
} }
WRITE(p,");"); WRITE(p, ");");
//end of alpha if (ac.clamp)
WRITE(p,"\n"); WRITE(p, "%s = clamp(%s, 0.0f, 1.0f);\n", tevAOutputTable[ac.outreg], tevAOutputTable[ac.outreg]);
WRITE(p, "\n");
} }
char *alphaRef[2] =
{
"alphaRef.x",
"alphaRef.y"
};
void WriteAlphaCompare(char *&p, int num, int comp) void WriteAlphaCompare(char *&p, int num, int comp)
{ {
WRITE(p," res%i = ",num); WRITE(p," res%i = ",num);
@ -478,7 +496,7 @@ void WriteAlphaTest(char *&p)
//first kill all the simple cases //first kill all the simple cases
if (op == ALPHAOP_AND && (comp[0] == COMPARE_ALWAYS && comp[1] == COMPARE_ALWAYS)) return; if (op == ALPHAOP_AND && (comp[0] == COMPARE_ALWAYS && comp[1] == COMPARE_ALWAYS)) return;
if (op == ALPHAOP_OR && (comp[0] == COMPARE_ALWAYS || comp[1] == COMPARE_ALWAYS)) return; if (op == ALPHAOP_OR && (comp[0] == COMPARE_ALWAYS || comp[1] == COMPARE_ALWAYS)) return;
for (int i=0; i<2; i++) for (int i = 0; i < 2; i++)
{ {
int one = i; int one = i;
int other = 1-i; int other = 1-i;
@ -495,11 +513,11 @@ void WriteAlphaTest(char *&p)
//Ok, didn't get to do the easy way out :P //Ok, didn't get to do the easy way out :P
// do the general way // do the general way
WRITE(p,"float res0,res1;\n"); WRITE(p,"float res0, res1;\n");
WriteAlphaCompare(p,0,bpmem.alphaFunc.comp0); WriteAlphaCompare(p, 0, bpmem.alphaFunc.comp0);
WriteAlphaCompare(p,1,bpmem.alphaFunc.comp1); WriteAlphaCompare(p, 1, bpmem.alphaFunc.comp1);
WRITE(p,"res0=max(res0,0);\n"); WRITE(p,"res0 = max(res0, 0);\n");
WRITE(p,"res1=max(res1,0);\n"); WRITE(p,"res1 = max(res1, 0);\n");
//probably should use lookup textures for some of these :P //probably should use lookup textures for some of these :P
switch(bpmem.alphaFunc.logic) { switch(bpmem.alphaFunc.logic) {
case ALPHAOP_AND: // if both are 0 case ALPHAOP_AND: // if both are 0

View File

@ -37,7 +37,7 @@ void PShaderCache::SetShader()
if (iter != pshaders.end()) if (iter != pshaders.end())
{ {
iter->second.frameCount=frameCount; iter->second.frameCount = frameCount;
PSCacheEntry &entry = iter->second; PSCacheEntry &entry = iter->second;
if (!lastShader || entry.shader != lastShader) if (!lastShader || entry.shader != lastShader)
{ {
@ -54,7 +54,7 @@ void PShaderCache::SetShader()
//Make an entry in the table //Make an entry in the table
PSCacheEntry newentry; PSCacheEntry newentry;
newentry.shader = shader; newentry.shader = shader;
newentry.frameCount=frameCount; newentry.frameCount = frameCount;
pshaders[currentHash] = newentry; pshaders[currentHash] = newentry;
} }
@ -66,13 +66,13 @@ void PShaderCache::SetShader()
void PShaderCache::Cleanup() void PShaderCache::Cleanup()
{ {
PSCache::iterator iter; PSCache::iterator iter;
iter = pshaders.begin(); iter = pshaders.begin();
while(iter!=pshaders.end()) while(iter != pshaders.end())
{ {
PSCacheEntry &entry = iter->second; PSCacheEntry &entry = iter->second;
if (entry.frameCount<frameCount-30) if (entry.frameCount < frameCount-30)
{ {
entry.Destroy(); entry.Destroy();
iter = pshaders.erase(iter); iter = pshaders.erase(iter);

View File

@ -124,14 +124,14 @@ void VertexLoader::Setup()
} }
// Texture matrix indices // Texture matrix indices
if (m_VtxDesc.Tex0MatIdx) {m_components|=VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte0); m_VertexSize+=1;} if (m_VtxDesc.Tex0MatIdx) {m_components|=VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex1MatIdx) {m_components|=VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte1); m_VertexSize+=1;} if (m_VtxDesc.Tex1MatIdx) {m_components|=VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex2MatIdx) {m_components|=VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte2); m_VertexSize+=1;} if (m_VtxDesc.Tex2MatIdx) {m_components|=VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex3MatIdx) {m_components|=VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte3); m_VertexSize+=1;} if (m_VtxDesc.Tex3MatIdx) {m_components|=VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex4MatIdx) {m_components|=VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte4); m_VertexSize+=1;} if (m_VtxDesc.Tex4MatIdx) {m_components|=VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex5MatIdx) {m_components|=VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte5); m_VertexSize+=1;} if (m_VtxDesc.Tex5MatIdx) {m_components|=VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex6MatIdx) {m_components|=VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte6); m_VertexSize+=1;} if (m_VtxDesc.Tex6MatIdx) {m_components|=VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
if (m_VtxDesc.Tex7MatIdx) {m_components|=VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte7); m_VertexSize+=1;} if (m_VtxDesc.Tex7MatIdx) {m_components|=VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); m_VertexSize+=1;}
// Position // Position
switch (m_VtxDesc.Position) switch (m_VtxDesc.Position)
@ -388,6 +388,7 @@ void VertexLoader::RunVertices(int count)
{ {
tcIndex = 0; tcIndex = 0;
colIndex = 0; colIndex = 0;
s_texmtxread = 0;
for (int i = 0; i < m_numPipelineStates; i++) for (int i = 0; i < m_numPipelineStates; i++)
{ {
m_PipelineStates[i](&m_VtxAttr); m_PipelineStates[i](&m_VtxAttr);

View File

@ -10,24 +10,15 @@
void LOADERDECL PosMtx_ReadDirect_UByte(void* _p) void LOADERDECL PosMtx_ReadDirect_UByte(void* _p)
{ {
TVtxAttr* pVtxAttr = (TVtxAttr*)_p; TVtxAttr* pVtxAttr = (TVtxAttr*)_p;
int index = ReadBuffer8(); int index = ReadBuffer8() & 0x3f;
float *flipmem = (float *)xfmem; float *flipmem = (float *)xfmem;
varray->SetPosNrmIdx(index); varray->SetPosNrmIdx(index);
} }
#define MAKETEX(n) \ int s_texmtxread = 0, s_texmtxwrite = 0;
void LOADERDECL TexMtx_ReadDirect_UByte##n(void* _p) \ void LOADERDECL TexMtx_ReadDirect_UByte(void* _p)
{ \ {
TVtxAttr* pVtxAttr = (TVtxAttr*)_p; \ TVtxAttr* pVtxAttr = (TVtxAttr*)_p;
int index = ReadBuffer8(); \ int index = ReadBuffer8() & 0x3f;
varray->SetTcIdx(n, index); \ varray->SetTcIdx(s_texmtxread++, index);
} }
MAKETEX(0)
MAKETEX(1)
MAKETEX(2)
MAKETEX(3)
MAKETEX(4)
MAKETEX(5)
MAKETEX(6)
MAKETEX(7)

View File

@ -630,10 +630,6 @@ struct TCoordInfo
}; };
//////////////////////////////////////////////////////////////////////////
// All of BP memory
//////////////////////////////////////////////////////////////////////////
union ColReg union ColReg
{ {
u32 hex; u32 hex;
@ -701,6 +697,10 @@ union UPE_Copy
}; };
}; };
//////////////////////////////////////////////////////////////////////////
// All of BP memory
//////////////////////////////////////////////////////////////////////////
struct BPMemory struct BPMemory
{ {
GenMode genMode; GenMode genMode;

View File

@ -693,7 +693,7 @@ const char *tevAInputTable2[] = // CA
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR", "PADERROR",
}; };
const char *tevRasTable[] = const char *tevRasTable[] =
@ -708,14 +708,14 @@ const char *tevRasTable[] =
"float4(0,0,0,0)", // zero "float4(0,0,0,0)", // zero
}; };
const char* tevTexFunc[] = { "tex2D", "texRECT" }; const char *tevTexFunc[] = { "tex2D", "texRECT" };
const char *tevCOutputTable[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" }; const char *tevCOutputTable[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" };
const char *tevAOutputTable[] = { "prev.a", "c0.a", "c1.a", "c2.a" }; const char *tevAOutputTable[] = { "prev.a", "c0.a", "c1.a", "c2.a" };
const char* tevIndAlphaSel[] = {"", "x", "y", "z"}; const char* tevIndAlphaSel[] = {"", "x", "y", "z"};
const char* tevIndAlphaScale[] = {"", "*32","*16","*8"}; const char* tevIndAlphaScale[] = {"", "*32","*16","*8"};
const char* tevIndBiasField[] = {"", "x", "y", "xy", "z", "xz", "yz", "xyz"}; // indexed by bias const char* tevIndBiasField[] = {"", "x", "y", "xy", "z", "xz", "yz", "xyz"}; // indexed by bias
const char* tevIndBiasAdd[] = {"-128.0f", "1.0f", "1.0f", "1.0f" }; // indexecd by fmt const char* tevIndBiasAdd[] = {"-128.0f", "1.0f", "1.0f", "1.0f" }; // indexed by fmt
const char* tevIndWrapStart[] = {"0", "256", "128", "64", "32", "16", "0.001" }; const char* tevIndWrapStart[] = {"0", "256", "128", "64", "32", "16", "0.001" };
const char* tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" }; const char* tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" };