let's keep experimenting:
almost fixed real xfb in d3d, i say almost because there are some minor scalling problems. hope will fix them soon. implemented a more intelligent index generator to emulate more accurately the behavior of the gc. please give me feedback on this changes. enjoy :) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5465 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
b1a79b822d
commit
782d9111e5
|
@ -28,8 +28,11 @@ QUAD simulator
|
|||
|
||||
//Init
|
||||
u16 *IndexGenerator::Tptr = 0;
|
||||
u16 *IndexGenerator::BASETptr = 0;
|
||||
u16 *IndexGenerator::Lptr = 0;
|
||||
u16 *IndexGenerator::BASELptr = 0;
|
||||
u16 *IndexGenerator::Pptr = 0;
|
||||
u16 *IndexGenerator::BASEPptr = 0;
|
||||
int IndexGenerator::numT = 0;
|
||||
int IndexGenerator::numL = 0;
|
||||
int IndexGenerator::numP = 0;
|
||||
|
@ -37,9 +40,6 @@ int IndexGenerator::index = 0;
|
|||
int IndexGenerator::Tadds = 0;
|
||||
int IndexGenerator::Ladds = 0;
|
||||
int IndexGenerator::Padds = 0;
|
||||
int IndexGenerator::TindexLen = 0;
|
||||
int IndexGenerator::LindexLen = 0;
|
||||
int IndexGenerator::PindexLen = 0;
|
||||
IndexGenerator::IndexPrimitiveType IndexGenerator::LastTPrimitive = Prim_None;
|
||||
IndexGenerator::IndexPrimitiveType IndexGenerator::LastLPrimitive = Prim_None;
|
||||
bool IndexGenerator::used = false;
|
||||
|
@ -49,6 +49,9 @@ void IndexGenerator::Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr)
|
|||
Tptr = Triangleptr;
|
||||
Lptr = Lineptr;
|
||||
Pptr = Pointptr;
|
||||
BASETptr = Triangleptr;
|
||||
BASELptr = Lineptr;
|
||||
BASEPptr = Pointptr;
|
||||
index = 0;
|
||||
numT = 0;
|
||||
numL = 0;
|
||||
|
@ -56,24 +59,62 @@ void IndexGenerator::Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr)
|
|||
Tadds = 0;
|
||||
Ladds = 0;
|
||||
Padds = 0;
|
||||
TindexLen = 0;
|
||||
LindexLen = 0;
|
||||
PindexLen = 0;
|
||||
LastTPrimitive = Prim_None;
|
||||
LastLPrimitive = Prim_None;
|
||||
}
|
||||
// Triangles
|
||||
void IndexGenerator::AddList(int numVerts)
|
||||
{
|
||||
//if we have no vertices return
|
||||
if(numVerts <= 0) return;
|
||||
int numTris = numVerts / 3;
|
||||
if (numTris <= 0) return;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
if (!numTris)
|
||||
{
|
||||
*Tptr++ = index+i*3;
|
||||
*Tptr++ = index+i*3+1;
|
||||
*Tptr++ = index+i*3+2;
|
||||
//if we have less than 3 verts
|
||||
if(numVerts == 1)
|
||||
{
|
||||
// discard
|
||||
index++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//we have two verts render a degenerated triangle
|
||||
numTris = 1;
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index+1;
|
||||
*Tptr++ = index;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < numTris; i++)
|
||||
{
|
||||
*Tptr++ = index+i*3;
|
||||
*Tptr++ = index+i*3+1;
|
||||
*Tptr++ = index+i*3+2;
|
||||
}
|
||||
int baseRemainingverts = numVerts - numVerts % 3;
|
||||
switch (numVerts % 3)
|
||||
{
|
||||
case 2:
|
||||
//whe have 2 remaining verts use strip method
|
||||
*Tptr++ = index + baseRemainingverts - 1;
|
||||
*Tptr++ = index + baseRemainingverts;
|
||||
*Tptr++ = index + baseRemainingverts + 1;
|
||||
numTris++;
|
||||
break;
|
||||
case 1:
|
||||
//whe have 1 remaining verts use strip method this is only a conjeture
|
||||
*Tptr++ = index + baseRemainingverts - 2;
|
||||
*Tptr++ = index + baseRemainingverts - 1;
|
||||
*Tptr++ = index + baseRemainingverts;
|
||||
numTris++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
TindexLen += numVerts;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
|
@ -82,17 +123,37 @@ void IndexGenerator::AddList(int numVerts)
|
|||
|
||||
void IndexGenerator::AddStrip(int numVerts)
|
||||
{
|
||||
if(numVerts <= 0) return;
|
||||
int numTris = numVerts - 2;
|
||||
if (numTris <= 0) return;
|
||||
bool wind = false;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
if (numTris < 1)
|
||||
{
|
||||
*Tptr++ = index+i;
|
||||
*Tptr++ = index+i+(wind?2:1);
|
||||
*Tptr++ = index+i+(wind?1:2);
|
||||
wind = !wind;
|
||||
//if we have less than 3 verts
|
||||
if(numVerts == 1)
|
||||
{
|
||||
//dicard
|
||||
index++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//we have two verts render a degenerated triangle
|
||||
numTris = 1;
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index+1;
|
||||
*Tptr++ = index;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool wind = false;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
{
|
||||
*Tptr++ = index+i;
|
||||
*Tptr++ = index+i+(wind?2:1);
|
||||
*Tptr++ = index+i+(wind?1:2);
|
||||
wind = !wind;
|
||||
}
|
||||
}
|
||||
TindexLen += numTris * 3;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
|
@ -100,15 +161,35 @@ void IndexGenerator::AddStrip(int numVerts)
|
|||
}
|
||||
void IndexGenerator::AddFan(int numVerts)
|
||||
{
|
||||
if(numVerts <= 0) return;
|
||||
int numTris = numVerts - 2;
|
||||
if (numTris <= 0) return;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
if (numTris < 1)
|
||||
{
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index+i+1;
|
||||
*Tptr++ = index+i+2;
|
||||
//if we have less than 3 verts
|
||||
if(numVerts == 1)
|
||||
{
|
||||
//Discard
|
||||
index++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//we have two verts render a degenerated triangle
|
||||
numTris = 1;
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index+1;
|
||||
*Tptr++ = index;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < numTris; i++)
|
||||
{
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index+i+1;
|
||||
*Tptr++ = index+i+2;
|
||||
}
|
||||
}
|
||||
TindexLen += numTris * 3;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
|
@ -117,18 +198,76 @@ void IndexGenerator::AddFan(int numVerts)
|
|||
|
||||
void IndexGenerator::AddQuads(int numVerts)
|
||||
{
|
||||
if(numVerts <= 0) return;
|
||||
int numTris = (numVerts/4)*2;
|
||||
if (numTris <= 0) return;
|
||||
for (int i = 0; i < numTris / 2; i++)
|
||||
if (numTris == 0)
|
||||
{
|
||||
*Tptr++ = index+i*4;
|
||||
*Tptr++ = index+i*4+1;
|
||||
*Tptr++ = index+i*4+3;
|
||||
*Tptr++ = index+i*4+1;
|
||||
*Tptr++ = index+i*4+2;
|
||||
*Tptr++ = index+i*4+3;
|
||||
//if we have less than 3 verts
|
||||
if(numVerts == 1)
|
||||
{
|
||||
//discard
|
||||
index++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(numVerts == 2)
|
||||
{
|
||||
//we have two verts render a degenerated triangle
|
||||
numTris = 1;
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index + 1;
|
||||
*Tptr++ = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
//we have 3 verts render a full triangle
|
||||
numTris = 1;
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index + 1;
|
||||
*Tptr++ = index + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < numTris / 2; i++)
|
||||
{
|
||||
*Tptr++ = index+i*4;
|
||||
*Tptr++ = index+i*4+1;
|
||||
*Tptr++ = index+i*4+3;
|
||||
*Tptr++ = index+i*4+1;
|
||||
*Tptr++ = index+i*4+2;
|
||||
*Tptr++ = index+i*4+3;
|
||||
}
|
||||
int baseRemainingverts = numVerts - numVerts % 4;
|
||||
switch (numVerts % 4)
|
||||
{
|
||||
case 3:
|
||||
//whe have 3 remaining verts use strip method
|
||||
*Tptr++ = index + baseRemainingverts;
|
||||
*Tptr++ = index + baseRemainingverts + 1;
|
||||
*Tptr++ = index + baseRemainingverts + 2;
|
||||
numTris++;
|
||||
break;
|
||||
case 2:
|
||||
//whe have 2 remaining verts use strip method
|
||||
*Tptr++ = index + baseRemainingverts - 1;
|
||||
*Tptr++ = index + baseRemainingverts;
|
||||
*Tptr++ = index + baseRemainingverts + 1;
|
||||
numTris++;
|
||||
break;
|
||||
case 1:
|
||||
//whe have 1 remaining verts use strip method this is only a conjeture
|
||||
*Tptr++ = index + baseRemainingverts - 2;
|
||||
*Tptr++ = index + baseRemainingverts - 1;
|
||||
*Tptr++ = index + baseRemainingverts;
|
||||
numTris++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
TindexLen += numTris * 3;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
|
@ -139,14 +278,28 @@ void IndexGenerator::AddQuads(int numVerts)
|
|||
//Lines
|
||||
void IndexGenerator::AddLineList(int numVerts)
|
||||
{
|
||||
int numLines= numVerts / 2;
|
||||
if (numLines <= 0) return;
|
||||
for (int i = 0; i < numLines; i++)
|
||||
if(numVerts <= 0) return;
|
||||
int numLines = numVerts / 2;
|
||||
if (!numLines)
|
||||
{
|
||||
*Lptr++ = index+i*2;
|
||||
*Lptr++ = index+i*2+1;
|
||||
//Discard
|
||||
index++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < numLines; i++)
|
||||
{
|
||||
*Lptr++ = index+i*2;
|
||||
*Lptr++ = index+i*2+1;
|
||||
}
|
||||
if(numVerts%2 != 0)
|
||||
{
|
||||
//use line strip for remaining vert
|
||||
*Lptr++ = index + numLines * 2 - 1;
|
||||
*Lptr++ = index + numLines * 2;
|
||||
}
|
||||
}
|
||||
LindexLen += numVerts;
|
||||
index += numVerts;
|
||||
numL += numLines;
|
||||
Ladds++;
|
||||
|
@ -156,13 +309,19 @@ void IndexGenerator::AddLineList(int numVerts)
|
|||
void IndexGenerator::AddLineStrip(int numVerts)
|
||||
{
|
||||
int numLines = numVerts - 1;
|
||||
if (numLines <= 0) return;
|
||||
if (numLines <= 0)
|
||||
{
|
||||
if(numVerts == 1)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < numLines; i++)
|
||||
{
|
||||
*Lptr++ = index+i;
|
||||
*Lptr++ = index+i+1;
|
||||
}
|
||||
LindexLen += numLines * 2;
|
||||
index += numVerts;
|
||||
numL += numLines;
|
||||
Ladds++;
|
||||
|
@ -180,7 +339,6 @@ void IndexGenerator::AddPoints(int numVerts)
|
|||
}
|
||||
index += numVerts;
|
||||
numP += numVerts;
|
||||
PindexLen+=numVerts;
|
||||
Padds++;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ public:
|
|||
static int GetNumPoints() {used = true;return numP;}
|
||||
static int GetNumVerts() {return index;} //returns numprimitives
|
||||
static int GetNumAdds() {return Tadds + Ladds + Padds;}
|
||||
static int GetTriangleindexLen() {return TindexLen;}
|
||||
static int GetLineindexLen() {return LindexLen;}
|
||||
static int GetPointindexLen() {return PindexLen;}
|
||||
static int GetTriangleindexLen() {return (int)(Tptr - BASETptr);}
|
||||
static int GetLineindexLen() {return (int)(Lptr - BASELptr);}
|
||||
static int GetPointindexLen() {return (int)(Pptr - BASEPptr);}
|
||||
|
||||
enum IndexPrimitiveType
|
||||
{
|
||||
|
@ -56,8 +56,11 @@ public:
|
|||
} ;
|
||||
private:
|
||||
static u16 *Tptr;
|
||||
static u16 *BASETptr;
|
||||
static u16 *Lptr;
|
||||
static u16 *BASELptr;
|
||||
static u16 *Pptr;
|
||||
static u16 *BASEPptr;
|
||||
static int numT;
|
||||
static int numL;
|
||||
static int numP;
|
||||
|
@ -65,9 +68,6 @@ private:
|
|||
static int Tadds;
|
||||
static int Ladds;
|
||||
static int Padds;
|
||||
static int TindexLen;
|
||||
static int LindexLen;
|
||||
static int PindexLen;
|
||||
static IndexPrimitiveType LastTPrimitive;
|
||||
static IndexPrimitiveType LastLPrimitive;
|
||||
static bool used;
|
||||
|
|
|
@ -111,12 +111,7 @@ void WriteSwizzler(char*& p, u32 format,bool HLSL)
|
|||
|
||||
if(HLSL)
|
||||
{
|
||||
WRITE(p, " sampleUv = sampleUv + float2(1.0f,1.0f);\n"
|
||||
" sampleUv = sampleUv / blkDims.zw;\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE(p, " sampleUv = sampleUv;\n");
|
||||
WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,12 +163,7 @@ void Write32BitSwizzler(char*& p, u32 format, bool HLSL)
|
|||
|
||||
if(HLSL)
|
||||
{
|
||||
WRITE(p, " sampleUv = sampleUv + float2(1.0f,1.0f);\n"
|
||||
" sampleUv = sampleUv / blkDims.zw;\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE(p, " sampleUv = sampleUv + float2(1.0f,-1.0f);\n");
|
||||
WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1285,14 +1285,15 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
|||
// ---------------------------------------------------------------------
|
||||
// Count FPS.
|
||||
// -------------
|
||||
static int fpscount = 0;
|
||||
static int fpscount = 1;
|
||||
static unsigned long lasttime;
|
||||
++fpscount;
|
||||
if(XFBWrited)
|
||||
++fpscount;
|
||||
if (Common::Timer::GetTimeMs() - lasttime > 1000)
|
||||
{
|
||||
lasttime = Common::Timer::GetTimeMs();
|
||||
s_fps = fpscount - 1;
|
||||
fpscount = 0;
|
||||
fpscount = 1;
|
||||
}
|
||||
|
||||
// Begin new frame
|
||||
|
@ -1307,7 +1308,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
|||
D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface());
|
||||
UpdateViewport();
|
||||
VertexShaderManager::SetViewportChanged();
|
||||
g_VideoInitialize.pCopiedToXFB(true);
|
||||
g_VideoInitialize.pCopiedToXFB(XFBWrited);
|
||||
XFBWrited = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ void CreateRgbToYuyvProgram()
|
|||
" out float4 ocol0 : COLOR0,\n"
|
||||
" in float2 uv0 : TEXCOORD0)\n"
|
||||
"{\n"
|
||||
" float2 uv1 = float2(uv0.x + (1.0f/blkDims.z), uv0.y);\n"
|
||||
" float3 c0 = tex2D(samp0, uv0.xy).rgb;\n"
|
||||
" float2 uv1 = float2((uv0.x + 1.0f)/ blkDims.z, uv0.y / blkDims.w);\n"
|
||||
" float3 c0 = tex2D(samp0, uv0.xy / blkDims.zw).rgb;\n"
|
||||
" float3 c1 = tex2D(samp0, uv1).rgb;\n"
|
||||
" float3 y_const = float3(0.257f,0.504f,0.098f);\n"
|
||||
" float3 u_const = float3(-0.148f,-0.291f,0.439f);\n"
|
||||
|
@ -92,9 +92,8 @@ void CreateYuyvToRgbProgram()
|
|||
" out float4 ocol0 : COLOR0,\n"
|
||||
" in float2 uv0 : TEXCOORD0)\n"
|
||||
"{\n"
|
||||
" float4 c0 = tex2D(samp0, uv0).rgba;\n"
|
||||
|
||||
" float f = step(0.5, frac(uv0.x * blkDims.z));\n"
|
||||
" float4 c0 = tex2D(samp0, uv0 / blkDims.zw).rgba;\n"
|
||||
" float f = step(0.5, frac(uv0.x));\n"
|
||||
" float y = lerp(c0.b, c0.r, f);\n"
|
||||
" float yComp = 1.164f * (y - 0.0625f);\n"
|
||||
" float uComp = c0.g - 0.5f;\n"
|
||||
|
@ -443,12 +442,12 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
|
|||
|
||||
RECT sourcerect;
|
||||
sourcerect.bottom = srcHeight;
|
||||
sourcerect.left = 0;
|
||||
sourcerect.left = -1;
|
||||
sourcerect.right = srcFmtWidth;
|
||||
sourcerect.top = 0;
|
||||
sourcerect.top = -1;
|
||||
|
||||
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
||||
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
||||
|
||||
TextureConversionShader::SetShaderParameters(
|
||||
(float)srcFmtWidth,
|
||||
|
@ -462,8 +461,8 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
|
|||
D3D::drawShadedTexQuad(
|
||||
s_srcTexture,
|
||||
&sourcerect,
|
||||
srcFmtWidth ,
|
||||
srcHeight,
|
||||
1 ,
|
||||
1,
|
||||
s_yuyvToRgbProgram,
|
||||
VertexShaderCache::GetSimpleVertexShader());
|
||||
|
||||
|
|
|
@ -101,12 +101,12 @@ void AddIndices(int _primitive, int _numVertices)
|
|||
{
|
||||
switch (_primitive)
|
||||
{
|
||||
case GX_DRAW_QUADS: if ((_numVertices % 4) == 0 ) {IndexGenerator::AddQuads(_numVertices);} else {IndexGenerator::AddFan(_numVertices);} break;
|
||||
case GX_DRAW_TRIANGLES: if ((_numVertices % 3) == 0 ) {IndexGenerator::AddList(_numVertices);} else {IndexGenerator::AddStrip(_numVertices);} break;
|
||||
case GX_DRAW_QUADS: IndexGenerator::AddQuads(_numVertices); break;
|
||||
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(_numVertices); break;
|
||||
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(_numVertices); break;
|
||||
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(_numVertices); break;
|
||||
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(_numVertices); break;
|
||||
case GX_DRAW_LINES: if ((_numVertices % 2) == 0 ) {IndexGenerator::AddLineList(_numVertices);} else {IndexGenerator::AddLineStrip(_numVertices);} break;
|
||||
case GX_DRAW_LINES: IndexGenerator::AddLineList(_numVertices); break;
|
||||
case GX_DRAW_POINTS: IndexGenerator::AddPoints(_numVertices); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,12 +107,12 @@ void AddIndices(int primitive, int numVertices)
|
|||
{
|
||||
switch (primitive)
|
||||
{
|
||||
case GX_DRAW_QUADS: if ((numVertices % 4) == 0 ) {IndexGenerator::AddQuads(numVertices);} else {IndexGenerator::AddFan(numVertices);} break;
|
||||
case GX_DRAW_TRIANGLES: if ((numVertices % 3) == 0 ) {IndexGenerator::AddList(numVertices);} else {IndexGenerator::AddStrip(numVertices);} break;
|
||||
case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices);break;
|
||||
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices);break;
|
||||
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
|
||||
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
|
||||
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVertices); break;
|
||||
case GX_DRAW_LINES: if ((numVertices % 2) == 0 ) {IndexGenerator::AddLineList(numVertices);} else {IndexGenerator::AddLineStrip(numVertices);} break;
|
||||
case GX_DRAW_LINES: IndexGenerator::AddLineList(numVertices);break;
|
||||
case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue