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,7 +283,6 @@ char swapModeTable[4][5];
void BuildSwapModeTable() void BuildSwapModeTable()
{ {
//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];
@ -336,9 +335,11 @@ float3 comp16 = float3(1,255,0), comp24 = float3(1,255,255*255);\n\
WriteAlphaTest(p); WriteAlphaTest(p);
/* see GL shader generator - this is Donko's hack
if (bpmem.dstalpha.enable) if (bpmem.dstalpha.enable)
WRITE(p," return float4(prev.rgb,constalpha.x);\n"); WRITE(p," return float4(prev.rgb,constalpha.x);\n");
else else
*/
WRITE(p," return prev;\n"); WRITE(p," return prev;\n");
WRITE(p,"}\n\0"); 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) void WriteStage(char *&p, int n)
{ {
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap]; const char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap]; const char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
int texfun = xfregs.texcoords[n].texmtxinfo.projection; int texfun = xfregs.texcoords[n].texmtxinfo.projection;

View File

@ -65,8 +65,9 @@ void BPInit()
bpmem.bpMask = 0xFFFFFF; bpmem.bpMask = 0xFFFFFF;
} }
// Called at the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
// Called att 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) void BPWritten(int addr, int changes, int newval)
{ {
//static int count = 0; //static int count = 0;

View File

@ -35,10 +35,10 @@
// output is given by .outreg // output is given by .outreg
// tevtemp is set according to swapmodetables and // tevtemp is set according to swapmodetables and
void WriteStage(char *&p, int n, u32 texture_mask); static void WriteStage(char *&p, int n, u32 texture_mask);
void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask); static 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);
bool WriteAlphaTest(char *&p); static bool WriteAlphaTest(char *&p);
const float epsilon8bit = 1.0f / 255.0f; const float epsilon8bit = 1.0f / 255.0f;
@ -257,9 +257,10 @@ static const char* tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" };
static const char *swapColors = "rgba"; static const char *swapColors = "rgba";
static char swapModeTable[4][5]; static char swapModeTable[4][5];
static char text[16384]; static char text[16384];
void BuildSwapModeTable() static void BuildSwapModeTable()
{ {
//bpmem.tevregs[0]. //bpmem.tevregs[0].
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -274,6 +275,7 @@ void BuildSwapModeTable()
char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0) char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0)
{ {
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE(); DVSTARTPROFILE();
BuildSwapModeTable(); BuildSwapModeTable();
@ -305,7 +307,7 @@ char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRende
} }
} }
// samplers // Declare samplers
if (texture_mask) { if (texture_mask) {
WRITE(p, "uniform samplerRECT "); WRITE(p, "uniform samplerRECT ");
bool bfirst = true; bool bfirst = true;
@ -455,11 +457,12 @@ char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRende
} }
} }
WRITE(p, "}\n"); WRITE(p, "}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("PixelShader generator - buffer too small, canary has been eaten!");
return text; 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 *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap]; 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) { switch(comp) {
case ALPHACMP_ALWAYS: WRITE(p, "(false)"); break; 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 op = bpmem.alphaFunc.logic;
u32 comp[2] = {bpmem.alphaFunc.comp0,bpmem.alphaFunc.comp1}; u32 comp[2] = {bpmem.alphaFunc.comp0,bpmem.alphaFunc.comp1};

View File

@ -18,10 +18,6 @@
#ifndef _VERTEXLOADER_H #ifndef _VERTEXLOADER_H
#define _VERTEXLOADER_H #define _VERTEXLOADER_H
#define SHADER_POSMTX_ATTRIB 1
#define SHADER_NORM1_ATTRIB 6
#define SHADER_NORM2_ATTRIB 7
using namespace std; using namespace std;
#include "CPMemory.h" #include "CPMemory.h"
@ -30,39 +26,6 @@ using namespace std;
#define LOADERDECL __cdecl #define LOADERDECL __cdecl
typedef void (LOADERDECL *TPipelineFunction)(void*); 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 // There are 8 of these. Most games only use the first, and just reconfigure it all the time
// as needed, unfortunately. // as needed, unfortunately.
// TODO - clarify the role of this class. It seems to have taken on some irrelevant stuff. // 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" #include "VertexShader.h"
// This is the tricky one to get rid off. // This is the tricky one to get rid off.
#include "VertexLoader.h" // #include "VertexLoader.h"
static char text[16384]; static char text[16384];
#define WRITE p+=sprintf #define WRITE p+=sprintf
#define LIGHTS_POS "" #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) char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
{ {
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE(); DVSTARTPROFILE();
_assert_( bpmem.genMode.numtexgens == xfregs.numTexGens); _assert_( bpmem.genMode.numtexgens == xfregs.numTexGens);
@ -405,6 +407,8 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
WRITE(p, "return o;\n}\n"); WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
return text; return text;
} }

View File

@ -20,6 +20,43 @@
#include "XFMemory.h" #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 // shader variables
#define I_POSNORMALMATRIX "cpnmtx" #define I_POSNORMALMATRIX "cpnmtx"
#define I_PROJECTION "cproj" #define I_PROJECTION "cproj"