Backport Donko's hackfix to DX9 plugin. Move some code around. Add a couple of sanity checks.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@937 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-10-22 18:39:46 +00:00
parent ae0f0f8dcd
commit 32820d2036
8 changed files with 83 additions and 74 deletions

View File

@ -283,14 +283,13 @@ char swapModeTable[4][5];
void BuildSwapModeTable()
{
//bpmem.tevregs[0].
for (int i = 0; i < 4; i++)
{
swapModeTable[i][0]=swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1]=swapColors[bpmem.tevksel[i*2].swap2];
swapModeTable[i][2]=swapColors[bpmem.tevksel[i*2+1].swap1];
swapModeTable[i][3]=swapColors[bpmem.tevksel[i*2+1].swap2];
swapModeTable[i][4]=0;
swapModeTable[i][0] = swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1] = swapColors[bpmem.tevksel[i*2].swap2];
swapModeTable[i][2] = swapColors[bpmem.tevksel[i*2+1].swap1];
swapModeTable[i][3] = swapColors[bpmem.tevksel[i*2+1].swap2];
swapModeTable[i][4] = 0;
}
}
@ -336,9 +335,11 @@ float3 comp16 = float3(1,255,0), comp24 = float3(1,255,255*255);\n\
WriteAlphaTest(p);
/* see GL shader generator - this is Donko's hack
if (bpmem.dstalpha.enable)
WRITE(p," return float4(prev.rgb,constalpha.x);\n");
else
*/
WRITE(p," return prev;\n");
WRITE(p,"}\n\0");
@ -348,8 +349,8 @@ float3 comp16 = float3(1,255,0), comp24 = float3(1,255,255*255);\n\
void WriteStage(char *&p, int n)
{
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
const char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
const char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
int texfun = xfregs.texcoords[n].texmtxinfo.projection;

View File

@ -118,7 +118,7 @@ void PShaderCache::Cleanup()
PSCache::iterator iter;
iter = pshaders.begin();
while(iter != pshaders.end())
while (iter != pshaders.end())
{
PSCacheEntry &entry = iter->second;
if (entry.frameCount < frameCount-30)
@ -128,7 +128,7 @@ void PShaderCache::Cleanup()
}
else
{
iter++;
iter++;
}
}
SETSTAT(stats.numPixelShadersAlive, (int)pshaders.size());
@ -145,7 +145,7 @@ void VShaderCache::Init()
void VShaderCache::Shutdown()
{
VSCache::iterator iter = vshaders.begin();
for (;iter!=vshaders.end();iter++)
for (; iter != vshaders.end(); iter++)
iter->second.Destroy();
vshaders.clear();
}
@ -157,7 +157,7 @@ void VShaderCache::SetShader()
if (D3D::GetShaderVersion() < 2)
return; // we are screwed
if(shader) {
if (shader) {
//D3D::dev->SetVertexShader(shader);
return;
}

View File

@ -65,8 +65,9 @@ void BPInit()
bpmem.bpMask = 0xFFFFFF;
}
// Called att the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
// Called at the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
// TODO - turn into function table. The (future) DL jit can then call the functions directly,
// getting rid of dynamic dispatch.
void BPWritten(int addr, int changes, int newval)
{
//static int count = 0;
@ -448,7 +449,7 @@ void BPWritten(int addr, int changes, int newval)
// EFB to XFB
if(g_Config.bUseXFB)
{
XFB_Write(Memory_GetPtr(bpmem.copyTexDest<<5), multirc, (bpmem.copyMipMapStrideChannels << 4), bpmem.copyTexSrcWH.y + 1, bpmem.dispcopyyscale/256.0f);
XFB_Write(Memory_GetPtr(bpmem.copyTexDest<<5), multirc, (bpmem.copyMipMapStrideChannels << 4), bpmem.copyTexSrcWH.y + 1, bpmem.dispcopyyscale / 256.0f);
}
else
{

View File

@ -35,10 +35,10 @@
// output is given by .outreg
// tevtemp is set according to swapmodetables and
void WriteStage(char *&p, int n, u32 texture_mask);
void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask);
void WriteAlphaCompare(char *&p, int num, int comp);
bool WriteAlphaTest(char *&p);
static void WriteStage(char *&p, int n, u32 texture_mask);
static void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask);
static void WriteAlphaCompare(char *&p, int num, int comp);
static bool WriteAlphaTest(char *&p);
const float epsilon8bit = 1.0f / 255.0f;
@ -257,23 +257,25 @@ static const char* tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" };
static const char *swapColors = "rgba";
static char swapModeTable[4][5];
static char text[16384];
void BuildSwapModeTable()
static void BuildSwapModeTable()
{
//bpmem.tevregs[0].
for (int i = 0; i < 4; i++)
{
swapModeTable[i][0]=swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1]=swapColors[bpmem.tevksel[i*2].swap2];
swapModeTable[i][2]=swapColors[bpmem.tevksel[i*2+1].swap1];
swapModeTable[i][3]=swapColors[bpmem.tevksel[i*2+1].swap2];
swapModeTable[i][4]=0;
swapModeTable[i][0] = swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1] = swapColors[bpmem.tevksel[i*2].swap2];
swapModeTable[i][2] = swapColors[bpmem.tevksel[i*2+1].swap1];
swapModeTable[i][3] = swapColors[bpmem.tevksel[i*2+1].swap2];
swapModeTable[i][4] = 0;
}
}
char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0)
{
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE();
BuildSwapModeTable();
@ -283,7 +285,7 @@ char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRende
char *p = text;
WRITE(p, "//Pixel Shader for TEV stages\n");
WRITE(p, "//%i TEV stages, %i texgens, %i IND stages\n",
numStages,numTexgen,bpmem.genMode.numindstages);
numStages, numTexgen, bpmem.genMode.numindstages);
bool bRenderZ = has_zbuffer_target && bpmem.zmode.updateenable;
bool bOutputZ = bpmem.ztex2.op != ZTEXTURE_DISABLE;
@ -305,7 +307,7 @@ char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRende
}
}
// samplers
// Declare samplers
if (texture_mask) {
WRITE(p, "uniform samplerRECT ");
bool bfirst = true;
@ -455,11 +457,12 @@ char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRende
}
}
WRITE(p, "}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("PixelShader generator - buffer too small, canary has been eaten!");
return text;
}
void WriteStage(char *&p, int n, u32 texture_mask)
static void WriteStage(char *&p, int n, u32 texture_mask)
{
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
@ -775,7 +778,7 @@ void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask)
}
}
void WriteAlphaCompare(char *&p, int num, int comp)
static void WriteAlphaCompare(char *&p, int num, int comp)
{
switch(comp) {
case ALPHACMP_ALWAYS: WRITE(p, "(false)"); break;
@ -789,7 +792,7 @@ void WriteAlphaCompare(char *&p, int num, int comp)
}
}
bool WriteAlphaTest(char *&p)
static bool WriteAlphaTest(char *&p)
{
u32 op = bpmem.alphaFunc.logic;
u32 comp[2] = {bpmem.alphaFunc.comp0,bpmem.alphaFunc.comp1};

View File

@ -98,7 +98,7 @@ void TextureMngr::TCacheEntry::Destroy()
*ptr = oldpixel;
}
texture = 0;
}
}
void TextureMngr::Init()
{
@ -509,10 +509,10 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
GL_REPORT_ERRORD();
// create and attach the render target
std::map<u32, DEPTHTARGET>::iterator itdepth = mapDepthTargets.find((h<<16)|w);
std::map<u32, DEPTHTARGET>::iterator itdepth = mapDepthTargets.find((h << 16) | w);
if( itdepth == mapDepthTargets.end() ) {
DEPTHTARGET& depth = mapDepthTargets[(h<<16)|w];
if (itdepth == mapDepthTargets.end()) {
DEPTHTARGET& depth = mapDepthTargets[(h << 16) | w];
depth.framecount = frameCount;
glGenRenderbuffersEXT( 1, &depth.targ);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth.targ);

View File

@ -18,10 +18,6 @@
#ifndef _VERTEXLOADER_H
#define _VERTEXLOADER_H
#define SHADER_POSMTX_ATTRIB 1
#define SHADER_NORM1_ATTRIB 6
#define SHADER_NORM2_ATTRIB 7
using namespace std;
#include "CPMemory.h"
@ -30,39 +26,6 @@ using namespace std;
#define LOADERDECL __cdecl
typedef void (LOADERDECL *TPipelineFunction)(void*);
// m_components
enum {
VB_HAS_POSMTXIDX =(1<<1),
VB_HAS_TEXMTXIDX0=(1<<2),
VB_HAS_TEXMTXIDX1=(1<<3),
VB_HAS_TEXMTXIDX2=(1<<4),
VB_HAS_TEXMTXIDX3=(1<<5),
VB_HAS_TEXMTXIDX4=(1<<6),
VB_HAS_TEXMTXIDX5=(1<<7),
VB_HAS_TEXMTXIDX6=(1<<8),
VB_HAS_TEXMTXIDX7=(1<<9),
VB_HAS_TEXMTXIDXALL=(0xff<<2),
//VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
VB_HAS_NRM0=(1<<10),
VB_HAS_NRM1=(1<<11),
VB_HAS_NRM2=(1<<12),
VB_HAS_NRMALL=(7<<10),
VB_HAS_COL0=(1<<13),
VB_HAS_COL1=(1<<14),
VB_HAS_UV0=(1<<15),
VB_HAS_UV1=(1<<16),
VB_HAS_UV2=(1<<17),
VB_HAS_UV3=(1<<18),
VB_HAS_UV4=(1<<19),
VB_HAS_UV5=(1<<20),
VB_HAS_UV6=(1<<21),
VB_HAS_UV7=(1<<22),
VB_HAS_UVALL=(0xff<<15),
VB_HAS_UVTEXMTXSHIFT=13,
};
// There are 8 of these. Most games only use the first, and just reconfigure it all the time
// as needed, unfortunately.
// TODO - clarify the role of this class. It seems to have taken on some irrelevant stuff.

View File

@ -23,9 +23,10 @@
#include "VertexShader.h"
// This is the tricky one to get rid off.
#include "VertexLoader.h"
// #include "VertexLoader.h"
static char text[16384];
#define WRITE p+=sprintf
#define LIGHTS_POS ""
@ -34,6 +35,7 @@ char *GenerateLightShader(char* p, int index, const LitChannel& chan, const char
char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
{
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE();
_assert_( bpmem.genMode.numtexgens == xfregs.numTexGens);
@ -405,6 +407,8 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
return text;
}
@ -415,7 +419,7 @@ char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char
if (coloralpha == 1 ) swizzle = "xyz";
else if (coloralpha == 2 ) swizzle = "w";
if (!(chan.attnfunc&1)) {
if (!(chan.attnfunc & 1)) {
// atten disabled
switch (chan.diffusefunc) {
case LIGHTDIF_NONE:

View File

@ -20,6 +20,43 @@
#include "XFMemory.h"
#define SHADER_POSMTX_ATTRIB 1
#define SHADER_NORM1_ATTRIB 6
#define SHADER_NORM2_ATTRIB 7
// m_components
enum {
VB_HAS_POSMTXIDX =(1<<1),
VB_HAS_TEXMTXIDX0=(1<<2),
VB_HAS_TEXMTXIDX1=(1<<3),
VB_HAS_TEXMTXIDX2=(1<<4),
VB_HAS_TEXMTXIDX3=(1<<5),
VB_HAS_TEXMTXIDX4=(1<<6),
VB_HAS_TEXMTXIDX5=(1<<7),
VB_HAS_TEXMTXIDX6=(1<<8),
VB_HAS_TEXMTXIDX7=(1<<9),
VB_HAS_TEXMTXIDXALL=(0xff<<2),
//VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
VB_HAS_NRM0=(1<<10),
VB_HAS_NRM1=(1<<11),
VB_HAS_NRM2=(1<<12),
VB_HAS_NRMALL=(7<<10),
VB_HAS_COL0=(1<<13),
VB_HAS_COL1=(1<<14),
VB_HAS_UV0=(1<<15),
VB_HAS_UV1=(1<<16),
VB_HAS_UV2=(1<<17),
VB_HAS_UV3=(1<<18),
VB_HAS_UV4=(1<<19),
VB_HAS_UV5=(1<<20),
VB_HAS_UV6=(1<<21),
VB_HAS_UV7=(1<<22),
VB_HAS_UVALL=(0xff<<15),
VB_HAS_UVTEXMTXSHIFT=13,
};
// shader variables
#define I_POSNORMALMATRIX "cpnmtx"
#define I_PROJECTION "cproj"