HUGE commit :)

in general cleanup and bugfix disable pierre  patch for the moment as it causes problem in some games and hopefully fix the remaining missing textures for nvidia users in opengl.
make the code in pixelshadergen looks nice and readable.
D3D: this is a ultra experimental commit please check for regressions or error.
make the efb Scale / super sampling level customizable to improve the output quality and let the user configure quality according to his hardware.
is everyone likes this change will translate it to opengl
please test


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5612 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado
2010-06-05 00:01:18 +00:00
parent 63dbcf4f97
commit c98f8a96d2
25 changed files with 291 additions and 434 deletions

View File

@ -116,85 +116,67 @@ static const D3DBLEND d3dDestFactors[8] =
D3DBLEND_INVDESTALPHA
};
// 0 0x00
// 1 Source & destination
// 2 Source & ~destination
// 3 Source
// 4 ~Source & destination
// 5 Destination
// 6 Source ^ destination = Source & ~destination | ~Source & destination
// 7 Source | destination
// 8 ~(Source | destination)
// 9 ~(Source ^ destination) = ~Source & ~destination | Source & destination
// 10 ~Destination
// 11 Source | ~destination
// 12 ~Source
// 13 ~Source | destination
// 14 ~(Source & destination)
// 15 0xff
static const D3DBLENDOP d3dLogincOPop[16] =
{
D3DBLENDOP_ADD,//0
D3DBLENDOP_ADD,//1
D3DBLENDOP_SUBTRACT,//2
D3DBLENDOP_ADD,//3
D3DBLENDOP_REVSUBTRACT,//4
D3DBLENDOP_ADD,//5
D3DBLENDOP_MAX,//6
D3DBLENDOP_ADD,//7
D3DBLENDOP_ADD,
D3DBLENDOP_ADD,
D3DBLENDOP_SUBTRACT,
D3DBLENDOP_ADD,
D3DBLENDOP_REVSUBTRACT,
D3DBLENDOP_ADD,
D3DBLENDOP_MAX,
D3DBLENDOP_ADD,
D3DBLENDOP_MAX,//8
D3DBLENDOP_MAX,//9
D3DBLENDOP_ADD,//10
D3DBLENDOP_ADD,//11
D3DBLENDOP_ADD,//12
D3DBLENDOP_ADD,//13
D3DBLENDOP_ADD,//14
D3DBLENDOP_ADD//15
D3DBLENDOP_MAX,
D3DBLENDOP_MAX,
D3DBLENDOP_ADD,
D3DBLENDOP_ADD,
D3DBLENDOP_ADD,
D3DBLENDOP_ADD,
D3DBLENDOP_ADD,
D3DBLENDOP_ADD
};
static const D3DBLEND d3dLogicOpSrcFactors[16] =
{
D3DBLEND_ZERO,//0
D3DBLEND_DESTCOLOR,//1
D3DBLEND_ONE,//2
D3DBLEND_ONE,//3
D3DBLEND_DESTCOLOR,//4
D3DBLEND_ZERO,//5
D3DBLEND_INVDESTCOLOR,//6
D3DBLEND_INVDESTCOLOR,//7
D3DBLEND_ZERO,
D3DBLEND_DESTCOLOR,
D3DBLEND_ONE,
D3DBLEND_ONE,
D3DBLEND_DESTCOLOR,
D3DBLEND_ZERO,
D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVSRCCOLOR,//8
D3DBLEND_INVSRCCOLOR,//9
D3DBLEND_INVDESTCOLOR,//10
D3DBLEND_ONE,//11
D3DBLEND_INVSRCCOLOR,//12
D3DBLEND_INVSRCCOLOR,//13
D3DBLEND_INVDESTCOLOR,//14
D3DBLEND_ONE//15
D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVDESTCOLOR,
D3DBLEND_ONE,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_INVDESTCOLOR,
D3DBLEND_ONE
};
static const D3DBLEND d3dLogicOpDestFactors[16] =
{
D3DBLEND_ZERO,//0
D3DBLEND_ZERO,//1
D3DBLEND_INVSRCCOLOR,//2
D3DBLEND_ZERO,//3
D3DBLEND_ONE,//4
D3DBLEND_ONE,//5
D3DBLEND_INVSRCCOLOR,//6
D3DBLEND_ONE,//7
D3DBLEND_ZERO,
D3DBLEND_ZERO,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_ZERO,
D3DBLEND_ONE,
D3DBLEND_ONE,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_ONE,
D3DBLEND_INVDESTCOLOR,//8
D3DBLEND_SRCCOLOR,//9
D3DBLEND_INVDESTCOLOR,//10
D3DBLEND_INVDESTCOLOR,//11
D3DBLEND_INVSRCCOLOR,//12
D3DBLEND_ONE,//13
D3DBLEND_INVSRCCOLOR,//14
D3DBLEND_ONE//15
D3DBLEND_INVDESTCOLOR,
D3DBLEND_SRCCOLOR,
D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVDESTCOLOR,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_ONE,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_ONE
};
static const D3DCULL d3dCullModes[4] =
@ -269,8 +251,8 @@ bool Renderer::Init()
UpdateActiveConfig();
int fullScreenRes, x, y, w_temp, h_temp;
s_blendMode = 0;
// Multisample Anti-aliasing hasn't been implemented yet
int backbuffer_ms_mode = 0; // g_ActiveConfig.iMultisampleMode;
// Multisample Anti-aliasing hasn't been implemented yet use supersamling instead
int backbuffer_ms_mode = 0;
g_VideoInitialize.pRequestWindowSize(x, y, w_temp, h_temp);
@ -308,26 +290,9 @@ bool Renderer::Init()
s_LastAA = (g_ActiveConfig.iMultisampleMode > 3)?0:g_ActiveConfig.iMultisampleMode;
float SupersampleCoeficient = 1.0f;
switch (s_LastAA)
{
case 1:
break;
case 2:
SupersampleCoeficient = 2.0f;
break;
case 3:
SupersampleCoeficient = 3.0f;
break;
default:
break;
};
xScale *= SupersampleCoeficient;
yScale *= SupersampleCoeficient;
EFBxScale = ceilf(xScale);
EFByScale = ceilf(yScale);
float SupersampleCoeficient = (s_LastAA % 3) + 1;
EFBxScale = (s_LastAA / 3) + 1 * SupersampleCoeficient;
EFByScale = EFBxScale;
s_target_width = EFB_WIDTH * EFBxScale;
s_target_height = EFB_HEIGHT * EFByScale;
@ -423,16 +388,6 @@ void Renderer::DrawDebugText()
std::string T1 = "", T2 = "";
std::vector<std::string> T0;
/*
int W, H;
sscanf(g_ActiveConfig.cInternalRes, "%dx%d", &W, &H);
std::string OSDM1 =
g_ActiveConfig.bNativeResolution || g_ActiveConfig.b2xResolution ?
(g_ActiveConfig.bNativeResolution ?
StringFromFormat("%i x %i (native)", OSDInternalW, OSDInternalH)
: StringFromFormat("%i x %i (2x)", OSDInternalW, OSDInternalH))
: StringFromFormat("%i x %i (custom)", W, H);
*/
std::string OSDM1 = StringFromFormat("%i x %i", OSDInternalW, OSDInternalH);
std::string OSDM21;
switch(g_ActiveConfig.iAspectRatio)
@ -494,16 +449,6 @@ void Renderer::RenderText(const char *text, int left, int top, u32 color)
D3D::font.DrawTextScaled((float)left, (float)top, 20, 20, 0.0f, color, text, false);
}
void dumpMatrix(D3DXMATRIX &mtx)
{
for (int y = 0; y < 4; y++)
{
char temp[256];
sprintf(temp,"%4.4f %4.4f %4.4f %4.4f", mtx.m[y][0], mtx.m[y][1], mtx.m[y][2], mtx.m[y][3]);
g_VideoInitialize.pLog(temp, FALSE);
}
}
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
{
int Xstride = (s_Fulltarget_width - s_target_width) / 2;
@ -597,27 +542,14 @@ bool Renderer::SetScissorRect()
rc.right = (int)((float)bpmem.scissorBR.x - xoff - 341);
rc.bottom = (int)((float)bpmem.scissorBR.y - yoff - 341);
int Xstride = (s_Fulltarget_width - s_target_width) / 2;
int Ystride = (s_Fulltarget_height - s_target_height) / 2;
rc.left = (int)(rc.left * EFBxScale);
rc.top = (int)(rc.top * EFByScale);
rc.right = (int)(rc.right * EFBxScale);
rc.bottom = (int)(rc.bottom * EFByScale);
if (rc.left < 0) rc.left = 0;
if (rc.right < 0) rc.right = 0;
if (rc.left > s_target_width) rc.left = s_target_width;
if (rc.right > s_target_width) rc.right = s_target_width;
if (rc.left > EFB_WIDTH) rc.left = EFB_WIDTH;
if (rc.right > EFB_WIDTH) rc.right = EFB_WIDTH;
if (rc.top < 0) rc.top = 0;
if (rc.bottom < 0) rc.bottom = 0;
if (rc.top > s_target_height) rc.top = s_target_height;
if (rc.bottom > s_target_height) rc.bottom = s_target_height;
rc.left += Xstride;
rc.top += Ystride;
rc.right += Xstride;
rc.bottom += Ystride;
if (rc.top > EFB_HEIGHT) rc.top = EFB_HEIGHT;
if (rc.bottom > EFB_HEIGHT) rc.bottom = EFB_HEIGHT;
if (rc.left > rc.right)
{
@ -631,8 +563,16 @@ bool Renderer::SetScissorRect()
rc.bottom = rc.top;
rc.top = temp;
}
if (rc.right >= rc.left && rc.bottom >= rc.top)
int Xstride = (s_Fulltarget_width - s_target_width) / 2;
int Ystride = (s_Fulltarget_height - s_target_height) / 2;
rc.left = (int)(rc.left * EFBxScale) + Xstride;
rc.top = (int)(rc.top * EFByScale) + Ystride;
rc.right = (int)(rc.right * EFBxScale) + Xstride;
rc.bottom = (int)(rc.bottom * EFByScale) + Ystride;
if (rc.right != rc.left && rc.bottom != rc.top)
{
D3D::dev->SetScissorRect(&rc);
return true;
@ -761,7 +701,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
Renderer::GetFullTargetHeight(),
4,4,
(BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram(0):PixelShaderCache::GetDepthMatrixProgram(0),
VertexShaderCache::GetSimpleVertexShader());
VertexShaderCache::GetSimpleVertexShader(0));
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
@ -959,8 +899,7 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
D3D::ChangeRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
D3D::drawClearQuad(color ,(z & 0xFFFFFF) / float(0xFFFFFF),PixelShaderCache::GetClearProgram(),VertexShaderCache::GetClearVertexShader());
if (zEnable)
D3D::RefreshRenderState(D3DRS_ZFUNC);
//D3D::dev->Clear(0, NULL, (colorEnable ? D3DCLEAR_TARGET : 0)| ( zEnable ? D3DCLEAR_ZBUFFER : 0), color | ((alphaEnable)?0:0xFF000000),(z & 0xFFFFFF) / float(0xFFFFFF), 0);
D3D::RefreshRenderState(D3DRS_ZFUNC);
UpdateViewport();
SetScissorRect();
}
@ -1118,7 +1057,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
drawRc.right = 1;
}
D3D::drawShadedTexSubQuad(xfbSource->texture,&sourceRc,xfbSource->texWidth,xfbSource->texHeight,&drawRc,Width,Height,PixelShaderCache::GetColorCopyProgram(0),VertexShaderCache::GetSimpleVertexShader());
D3D::drawShadedTexSubQuad(xfbSource->texture,&sourceRc,xfbSource->texWidth,xfbSource->texHeight,&drawRc,Width,Height,PixelShaderCache::GetColorCopyProgram(0),VertexShaderCache::GetSimpleVertexShader(0));
}
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
@ -1133,7 +1072,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
if(s_bScreenshot)
{
s_criticalScreenshot.Enter();
// create a R8G8B8 surface for the screenshot (no alpha channel)
// otherwise funky screenshots get saved
LPDIRECT3DSURFACE9 screenshot_surface;
@ -1145,7 +1083,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
}
else
PanicAlert("Failed to create surface for screenshot!");
s_bScreenshot = false;
s_criticalScreenshot.Leave();
}
@ -1256,29 +1194,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
yScale = (float)(dst_rect.bottom - dst_rect.top) / (float)s_XFB_height;
}
float SupersampleCoeficient = 1.0f;
switch (s_LastAA)
{
case 1:
break;
case 2:
SupersampleCoeficient = 2.0f;
break;
case 3:
SupersampleCoeficient = 3.0f;
break;
default:
break;
};
xScale *= SupersampleCoeficient;
yScale *= SupersampleCoeficient;
EFBxScale = ceilf(xScale);
EFByScale = ceilf(yScale);
s_target_width = EFB_WIDTH * ceilf(EFBxScale);
s_target_height = EFB_HEIGHT * ceilf(EFByScale);
float SupersampleCoeficient = (s_LastAA % 3) + 1;
EFBxScale = (s_LastAA / 3) + 1 * SupersampleCoeficient;
EFByScale = EFBxScale;
s_target_width = EFB_WIDTH * EFBxScale;
s_target_height = EFB_HEIGHT * EFByScale;
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
if(WindowResized)
@ -1413,7 +1333,7 @@ void Renderer::SetSamplerState(int stage, int texindex)
min = (tm0.min_filter & 4) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT;
mip = (tm0.min_filter == 8)?D3DTEXF_NONE:d3dMipFilters[tm0.min_filter & 3];
if((tm0.min_filter & 3) && (tm0.min_filter != 8) && ((tm1.max_lod >> 4) == 0)) mip = D3DTEXF_NONE;
if((tm0.min_filter & 3) && (tm0.min_filter != 8) && ((tm1.max_lod >> 5) == 0)) mip = D3DTEXF_NONE;
}
if (texindex)
stage += 4;
@ -1429,7 +1349,6 @@ void Renderer::SetSamplerState(int stage, int texindex)
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
//just a test but it seems to work
float lodbias = tm0.lod_bias / 32.0f;
D3D::SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,*(DWORD*)&lodbias);
D3D::SetSamplerState(stage,D3DSAMP_MAXMIPLEVEL,tm1.min_lod>>5);