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:
Rodolfo Osvaldo Bogado 2010-05-22 21:58:43 +00:00
parent b1a79b822d
commit 782d9111e5
7 changed files with 234 additions and 86 deletions

View File

@ -28,8 +28,11 @@ QUAD simulator
//Init //Init
u16 *IndexGenerator::Tptr = 0; u16 *IndexGenerator::Tptr = 0;
u16 *IndexGenerator::BASETptr = 0;
u16 *IndexGenerator::Lptr = 0; u16 *IndexGenerator::Lptr = 0;
u16 *IndexGenerator::BASELptr = 0;
u16 *IndexGenerator::Pptr = 0; u16 *IndexGenerator::Pptr = 0;
u16 *IndexGenerator::BASEPptr = 0;
int IndexGenerator::numT = 0; int IndexGenerator::numT = 0;
int IndexGenerator::numL = 0; int IndexGenerator::numL = 0;
int IndexGenerator::numP = 0; int IndexGenerator::numP = 0;
@ -37,9 +40,6 @@ int IndexGenerator::index = 0;
int IndexGenerator::Tadds = 0; int IndexGenerator::Tadds = 0;
int IndexGenerator::Ladds = 0; int IndexGenerator::Ladds = 0;
int IndexGenerator::Padds = 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::LastTPrimitive = Prim_None;
IndexGenerator::IndexPrimitiveType IndexGenerator::LastLPrimitive = Prim_None; IndexGenerator::IndexPrimitiveType IndexGenerator::LastLPrimitive = Prim_None;
bool IndexGenerator::used = false; bool IndexGenerator::used = false;
@ -49,6 +49,9 @@ void IndexGenerator::Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr)
Tptr = Triangleptr; Tptr = Triangleptr;
Lptr = Lineptr; Lptr = Lineptr;
Pptr = Pointptr; Pptr = Pointptr;
BASETptr = Triangleptr;
BASELptr = Lineptr;
BASEPptr = Pointptr;
index = 0; index = 0;
numT = 0; numT = 0;
numL = 0; numL = 0;
@ -56,24 +59,62 @@ void IndexGenerator::Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr)
Tadds = 0; Tadds = 0;
Ladds = 0; Ladds = 0;
Padds = 0; Padds = 0;
TindexLen = 0;
LindexLen = 0;
PindexLen = 0;
LastTPrimitive = Prim_None; LastTPrimitive = Prim_None;
LastLPrimitive = Prim_None; LastLPrimitive = Prim_None;
} }
// Triangles // Triangles
void IndexGenerator::AddList(int numVerts) void IndexGenerator::AddList(int numVerts)
{ {
//if we have no vertices return
if(numVerts <= 0) return;
int numTris = numVerts / 3; int numTris = numVerts / 3;
if (numTris <= 0) return; if (!numTris)
{
//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++) for (int i = 0; i < numTris; i++)
{ {
*Tptr++ = index+i*3; *Tptr++ = index+i*3;
*Tptr++ = index+i*3+1; *Tptr++ = index+i*3+1;
*Tptr++ = index+i*3+2; *Tptr++ = index+i*3+2;
} }
TindexLen += numVerts; 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;
};
}
index += numVerts; index += numVerts;
numT += numTris; numT += numTris;
Tadds++; Tadds++;
@ -82,8 +123,28 @@ void IndexGenerator::AddList(int numVerts)
void IndexGenerator::AddStrip(int numVerts) void IndexGenerator::AddStrip(int numVerts)
{ {
if(numVerts <= 0) return;
int numTris = numVerts - 2; int numTris = numVerts - 2;
if (numTris <= 0) return; if (numTris < 1)
{
//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; bool wind = false;
for (int i = 0; i < numTris; i++) for (int i = 0; i < numTris; i++)
{ {
@ -92,7 +153,7 @@ void IndexGenerator::AddStrip(int numVerts)
*Tptr++ = index+i+(wind?1:2); *Tptr++ = index+i+(wind?1:2);
wind = !wind; wind = !wind;
} }
TindexLen += numTris * 3; }
index += numVerts; index += numVerts;
numT += numTris; numT += numTris;
Tadds++; Tadds++;
@ -100,15 +161,35 @@ void IndexGenerator::AddStrip(int numVerts)
} }
void IndexGenerator::AddFan(int numVerts) void IndexGenerator::AddFan(int numVerts)
{ {
if(numVerts <= 0) return;
int numTris = numVerts - 2; int numTris = numVerts - 2;
if (numTris <= 0) return; if (numTris < 1)
{
//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++) for (int i = 0; i < numTris; i++)
{ {
*Tptr++ = index; *Tptr++ = index;
*Tptr++ = index+i+1; *Tptr++ = index+i+1;
*Tptr++ = index+i+2; *Tptr++ = index+i+2;
} }
TindexLen += numTris * 3; }
index += numVerts; index += numVerts;
numT += numTris; numT += numTris;
Tadds++; Tadds++;
@ -117,8 +198,39 @@ void IndexGenerator::AddFan(int numVerts)
void IndexGenerator::AddQuads(int numVerts) void IndexGenerator::AddQuads(int numVerts)
{ {
if(numVerts <= 0) return;
int numTris = (numVerts/4)*2; int numTris = (numVerts/4)*2;
if (numTris <= 0) return; if (numTris == 0)
{
//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++) for (int i = 0; i < numTris / 2; i++)
{ {
*Tptr++ = index+i*4; *Tptr++ = index+i*4;
@ -128,7 +240,34 @@ void IndexGenerator::AddQuads(int numVerts)
*Tptr++ = index+i*4+2; *Tptr++ = index+i*4+2;
*Tptr++ = index+i*4+3; *Tptr++ = index+i*4+3;
} }
TindexLen += numTris * 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;
};
}
index += numVerts; index += numVerts;
numT += numTris; numT += numTris;
Tadds++; Tadds++;
@ -139,14 +278,28 @@ void IndexGenerator::AddQuads(int numVerts)
//Lines //Lines
void IndexGenerator::AddLineList(int numVerts) void IndexGenerator::AddLineList(int numVerts)
{ {
int numLines= numVerts / 2; if(numVerts <= 0) return;
if (numLines <= 0) return; int numLines = numVerts / 2;
if (!numLines)
{
//Discard
index++;
return;
}
else
{
for (int i = 0; i < numLines; i++) for (int i = 0; i < numLines; i++)
{ {
*Lptr++ = index+i*2; *Lptr++ = index+i*2;
*Lptr++ = index+i*2+1; *Lptr++ = index+i*2+1;
} }
LindexLen += numVerts; if(numVerts%2 != 0)
{
//use line strip for remaining vert
*Lptr++ = index + numLines * 2 - 1;
*Lptr++ = index + numLines * 2;
}
}
index += numVerts; index += numVerts;
numL += numLines; numL += numLines;
Ladds++; Ladds++;
@ -156,13 +309,19 @@ void IndexGenerator::AddLineList(int numVerts)
void IndexGenerator::AddLineStrip(int numVerts) void IndexGenerator::AddLineStrip(int numVerts)
{ {
int numLines = numVerts - 1; int numLines = numVerts - 1;
if (numLines <= 0) return; if (numLines <= 0)
{
if(numVerts == 1)
{
index++;
}
return;
}
for (int i = 0; i < numLines; i++) for (int i = 0; i < numLines; i++)
{ {
*Lptr++ = index+i; *Lptr++ = index+i;
*Lptr++ = index+i+1; *Lptr++ = index+i+1;
} }
LindexLen += numLines * 2;
index += numVerts; index += numVerts;
numL += numLines; numL += numLines;
Ladds++; Ladds++;
@ -180,7 +339,6 @@ void IndexGenerator::AddPoints(int numVerts)
} }
index += numVerts; index += numVerts;
numP += numVerts; numP += numVerts;
PindexLen+=numVerts;
Padds++; Padds++;
} }

View File

@ -43,9 +43,9 @@ public:
static int GetNumPoints() {used = true;return numP;} static int GetNumPoints() {used = true;return numP;}
static int GetNumVerts() {return index;} //returns numprimitives static int GetNumVerts() {return index;} //returns numprimitives
static int GetNumAdds() {return Tadds + Ladds + Padds;} static int GetNumAdds() {return Tadds + Ladds + Padds;}
static int GetTriangleindexLen() {return TindexLen;} static int GetTriangleindexLen() {return (int)(Tptr - BASETptr);}
static int GetLineindexLen() {return LindexLen;} static int GetLineindexLen() {return (int)(Lptr - BASELptr);}
static int GetPointindexLen() {return PindexLen;} static int GetPointindexLen() {return (int)(Pptr - BASEPptr);}
enum IndexPrimitiveType enum IndexPrimitiveType
{ {
@ -56,8 +56,11 @@ public:
} ; } ;
private: private:
static u16 *Tptr; static u16 *Tptr;
static u16 *BASETptr;
static u16 *Lptr; static u16 *Lptr;
static u16 *BASELptr;
static u16 *Pptr; static u16 *Pptr;
static u16 *BASEPptr;
static int numT; static int numT;
static int numL; static int numL;
static int numP; static int numP;
@ -65,9 +68,6 @@ private:
static int Tadds; static int Tadds;
static int Ladds; static int Ladds;
static int Padds; static int Padds;
static int TindexLen;
static int LindexLen;
static int PindexLen;
static IndexPrimitiveType LastTPrimitive; static IndexPrimitiveType LastTPrimitive;
static IndexPrimitiveType LastLPrimitive; static IndexPrimitiveType LastLPrimitive;
static bool used; static bool used;

View File

@ -111,12 +111,7 @@ void WriteSwizzler(char*& p, u32 format,bool HLSL)
if(HLSL) if(HLSL)
{ {
WRITE(p, " sampleUv = sampleUv + float2(1.0f,1.0f);\n" WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n");
" sampleUv = sampleUv / blkDims.zw;\n");
}
else
{
WRITE(p, " sampleUv = sampleUv;\n");
} }
} }
@ -168,12 +163,7 @@ void Write32BitSwizzler(char*& p, u32 format, bool HLSL)
if(HLSL) if(HLSL)
{ {
WRITE(p, " sampleUv = sampleUv + float2(1.0f,1.0f);\n" WRITE(p, " sampleUv = sampleUv / blkDims.zw;\n");
" sampleUv = sampleUv / blkDims.zw;\n");
}
else
{
WRITE(p, " sampleUv = sampleUv + float2(1.0f,-1.0f);\n");
} }
} }

View File

@ -1285,14 +1285,15 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Count FPS. // Count FPS.
// ------------- // -------------
static int fpscount = 0; static int fpscount = 1;
static unsigned long lasttime; static unsigned long lasttime;
if(XFBWrited)
++fpscount; ++fpscount;
if (Common::Timer::GetTimeMs() - lasttime > 1000) if (Common::Timer::GetTimeMs() - lasttime > 1000)
{ {
lasttime = Common::Timer::GetTimeMs(); lasttime = Common::Timer::GetTimeMs();
s_fps = fpscount - 1; s_fps = fpscount - 1;
fpscount = 0; fpscount = 1;
} }
// Begin new frame // Begin new frame
@ -1307,7 +1308,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface()); D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface());
UpdateViewport(); UpdateViewport();
VertexShaderManager::SetViewportChanged(); VertexShaderManager::SetViewportChanged();
g_VideoInitialize.pCopiedToXFB(true); g_VideoInitialize.pCopiedToXFB(XFBWrited);
XFBWrited = false; XFBWrited = false;
} }

View File

@ -64,8 +64,8 @@ void CreateRgbToYuyvProgram()
" out float4 ocol0 : COLOR0,\n" " out float4 ocol0 : COLOR0,\n"
" in float2 uv0 : TEXCOORD0)\n" " in float2 uv0 : TEXCOORD0)\n"
"{\n" "{\n"
" float2 uv1 = float2(uv0.x + (1.0f/blkDims.z), uv0.y);\n" " float2 uv1 = float2((uv0.x + 1.0f)/ blkDims.z, uv0.y / blkDims.w);\n"
" float3 c0 = tex2D(samp0, uv0.xy).rgb;\n" " float3 c0 = tex2D(samp0, uv0.xy / blkDims.zw).rgb;\n"
" float3 c1 = tex2D(samp0, uv1).rgb;\n" " float3 c1 = tex2D(samp0, uv1).rgb;\n"
" float3 y_const = float3(0.257f,0.504f,0.098f);\n" " float3 y_const = float3(0.257f,0.504f,0.098f);\n"
" float3 u_const = float3(-0.148f,-0.291f,0.439f);\n" " float3 u_const = float3(-0.148f,-0.291f,0.439f);\n"
@ -92,9 +92,8 @@ void CreateYuyvToRgbProgram()
" out float4 ocol0 : COLOR0,\n" " out float4 ocol0 : COLOR0,\n"
" in float2 uv0 : TEXCOORD0)\n" " in float2 uv0 : TEXCOORD0)\n"
"{\n" "{\n"
" float4 c0 = tex2D(samp0, uv0).rgba;\n" " float4 c0 = tex2D(samp0, uv0 / blkDims.zw).rgba;\n"
" float f = step(0.5, frac(uv0.x));\n"
" float f = step(0.5, frac(uv0.x * blkDims.z));\n"
" float y = lerp(c0.b, c0.r, f);\n" " float y = lerp(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n" " float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n" " float uComp = c0.g - 0.5f;\n"
@ -443,12 +442,12 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
RECT sourcerect; RECT sourcerect;
sourcerect.bottom = srcHeight; sourcerect.bottom = srcHeight;
sourcerect.left = 0; sourcerect.left = -1;
sourcerect.right = srcFmtWidth; sourcerect.right = srcFmtWidth;
sourcerect.top = 0; sourcerect.top = -1;
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
TextureConversionShader::SetShaderParameters( TextureConversionShader::SetShaderParameters(
(float)srcFmtWidth, (float)srcFmtWidth,
@ -462,8 +461,8 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
D3D::drawShadedTexQuad( D3D::drawShadedTexQuad(
s_srcTexture, s_srcTexture,
&sourcerect, &sourcerect,
srcFmtWidth , 1 ,
srcHeight, 1,
s_yuyvToRgbProgram, s_yuyvToRgbProgram,
VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader());

View File

@ -101,12 +101,12 @@ void AddIndices(int _primitive, int _numVertices)
{ {
switch (_primitive) switch (_primitive)
{ {
case GX_DRAW_QUADS: if ((_numVertices % 4) == 0 ) {IndexGenerator::AddQuads(_numVertices);} else {IndexGenerator::AddFan(_numVertices);} break; case GX_DRAW_QUADS: IndexGenerator::AddQuads(_numVertices); break;
case GX_DRAW_TRIANGLES: if ((_numVertices % 3) == 0 ) {IndexGenerator::AddList(_numVertices);} else {IndexGenerator::AddStrip(_numVertices);} break; case GX_DRAW_TRIANGLES: IndexGenerator::AddList(_numVertices); break;
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(_numVertices); break; case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(_numVertices); break;
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(_numVertices); break; case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(_numVertices); break;
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(_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; case GX_DRAW_POINTS: IndexGenerator::AddPoints(_numVertices); break;
} }
} }

View File

@ -107,12 +107,12 @@ void AddIndices(int primitive, int numVertices)
{ {
switch (primitive) switch (primitive)
{ {
case GX_DRAW_QUADS: if ((numVertices % 4) == 0 ) {IndexGenerator::AddQuads(numVertices);} else {IndexGenerator::AddFan(numVertices);} break; case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices);break;
case GX_DRAW_TRIANGLES: if ((numVertices % 3) == 0 ) {IndexGenerator::AddList(numVertices);} else {IndexGenerator::AddStrip(numVertices);} break; case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices);break;
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break; case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break; case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(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; case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
} }
} }