From b4d7a0e20d7aa0a315af891a628c3e084749d912 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Thu, 4 Feb 2010 22:25:09 +0000 Subject: [PATCH] fixed some glitches caused by SSAA when resolving the supersampled efb to Textures. improve speed a little in games that have large viewports. please test and let me know the results git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5009 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp | 12 +++---- .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 11 +++---- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 33 +++++++++++-------- .../Plugin_VideoDX9/Src/VertexShaderCache.cpp | 8 +++-- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp index e042501242..4df7e0165e 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp @@ -371,16 +371,16 @@ void drawShadedTexQuad(IDirect3DTexture9 *texture, float v1=((float)rSource->top + 0.5f) * sh; float v2=((float)rSource->bottom + 0.5f) * sh; - struct Q2DVertex { float x,y,z,rhw,u,v,w,h; } coords[4] = { - {-1.0f, 1.0f, 0.0f,1.0f, u1, v1, sw, sh}, - { 1.0f, 1.0f, 0.0f,1.0f, u2, v1, sw, sh}, - { 1.0f,-1.0f, 0.0f,1.0f, u2, v2, sw, sh}, - {-1.0f,-1.0f, 0.0f,1.0f, u1, v2, sw, sh} + struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = { + {-1.0f, 1.0f, 0.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2}, + { 1.0f, 1.0f, 0.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}, + { 1.0f,-1.0f, 0.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2}, + {-1.0f,-1.0f, 0.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2} }; dev->SetVertexShader(Vshader); dev->SetPixelShader(PShader); D3D::SetTexture(0, texture); - dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX2); + dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2)); dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex)); RestoreShaders(); } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index dca189f3ce..a3420d4e3e 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -161,8 +161,7 @@ void PixelShaderCache::Init() "}\n",C_COLORMATRIX); s_DepthMatrixProgram = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); - sprintf(pprog, "uniform sampler samp0 : register(s0);\n" - "uniform sampler samp1 : register(s1);\n" + sprintf(pprog, "uniform sampler samp0 : register(s0);\n" "void main(\n" "out float4 ocol0 : COLOR0,\n" "in float2 uv0 : TEXCOORD0,\n" @@ -173,17 +172,17 @@ void PixelShaderCache::Init() "}\n"); s_FSAAProgram = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); - sprintf(pprog, "uniform sampler samp0 : register(s0);\n" - "uniform sampler samp1 : register(s1);\n" + sprintf(pprog, "uniform sampler samp0 : register(s0);\n" "uniform float4 cColMatrix[5] : register(c%d);\n" "void main(\n" "out float4 ocol0 : COLOR0,\n" "in float2 uv0 : TEXCOORD0,\n" "in float2 uv1 : TEXCOORD1,\n" "in float2 uv2 : TEXCOORD2,\n" - "in float2 uv3 : TEXCOORD3){\n" + "in float2 uv3 : TEXCOORD3,\n" + "in float4 uv4 : TEXCOORD4){\n" "float4 texcol = float4(0.0f,0.0f,0.0f,0.0f);\n" - "texcol = (tex2D(samp0,uv0) + tex2D(samp0,uv1) + tex2D(samp0,uv2) + tex2D(samp0,uv3))*0.25f;\n" + "texcol = (tex2D(samp0,float2(clamp(uv0.x,uv4.x,uv4.z),clamp(uv0.y,uv4.y,uv4.w))) + tex2D(samp0,float2(clamp(uv1.x,uv4.x,uv4.z),clamp(uv1.y,uv4.y,uv4.w))) + tex2D(samp0,float2(clamp(uv2.x,uv4.x,uv4.z),clamp(uv2.y,uv4.y,uv4.w))) + tex2D(samp0,float2(clamp(uv3.x,uv4.x,uv4.z),clamp(uv3.y,uv4.y,uv4.w))))*0.25f;\n" "ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n" "}\n",C_COLORMATRIX); s_FSAAColorMatrixProgram = D3D::CompileAndCreatePixelShader(pprog, (int)strlen(pprog)); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 695c050682..70a35f87f5 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -70,6 +70,7 @@ static bool s_AVIDumping; static u32 s_blendMode; static u32 s_LastAA; +static bool IS_AMD; char st[32768]; @@ -275,6 +276,7 @@ bool Renderer::Init() D3D::Create(g_ActiveConfig.iAdapter, EmuWindow::GetWnd(), false, fullScreenRes, backbuffer_ms_mode, false); + IS_AMD = D3D::IsATIDevice(); s_backbuffer_width = D3D::GetBackBufferWidth(); s_backbuffer_height = D3D::GetBackBufferHeight(); @@ -729,12 +731,12 @@ bool Renderer::SetScissorRect() if (rc.left < 0) rc.left = 0; if (rc.right < 0) rc.right = 0; - if (rc.left > s_Fulltarget_width) rc.left = s_Fulltarget_width; - if (rc.right > s_Fulltarget_width) rc.right = s_Fulltarget_width; + if (rc.left > s_target_width) rc.left = s_target_width; + if (rc.right > s_target_width) rc.right = s_target_width; if (rc.top < 0) rc.top = 0; if (rc.bottom < 0) rc.bottom = 0; - if (rc.top > s_Fulltarget_height) rc.top = s_Fulltarget_height; - if (rc.bottom > s_Fulltarget_height) rc.bottom = s_Fulltarget_height; + if (rc.top > s_target_height) rc.top = s_target_height; + if (rc.bottom > s_target_height) rc.bottom = s_target_height; if (rc.left > rc.right) { int temp = rc.right; @@ -758,8 +760,8 @@ bool Renderer::SetScissorRect() //WARN_LOG(VIDEO, "Bad scissor rectangle: %i %i %i %i", rc.left, rc.top, rc.right, rc.bottom); rc.left = Xstride; rc.top = Ystride; - rc.right = Xstride + GetTargetWidth(); - rc.bottom = Ystride + GetTargetHeight(); + rc.right = Xstride + s_target_width; + rc.bottom = Ystride + s_target_height; D3D::dev->SetScissorRect(&rc); return false; } @@ -1009,15 +1011,18 @@ void UpdateViewport() Y = 0; sizeChanged=true; } - if(X + Width > s_Fulltarget_width) + if(!IS_AMD) { - s_Fulltarget_width += (X + Width - s_Fulltarget_width) * 2; - sizeChanged=true; - } - if(Y + Height > s_Fulltarget_height) - { - s_Fulltarget_height += (Y + Height - s_Fulltarget_height) * 2; - sizeChanged=true; + if(X + Width > s_Fulltarget_width) + { + s_Fulltarget_width += (X + Width - s_Fulltarget_width) * 2; + sizeChanged=true; + } + if(Y + Height > s_Fulltarget_height) + { + s_Fulltarget_height += (Y + Height - s_Fulltarget_height) * 2; + sizeChanged=true; + } } if(sizeChanged) { diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp index feaeb5db3f..b888e5c8ff 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp @@ -178,15 +178,17 @@ void VertexShaderCache::Init() "float2 vTexCoord : TEXCOORD0;\n" "float2 vTexCoord1 : TEXCOORD1;\n" "float2 vTexCoord2 : TEXCOORD2;\n" - "float2 vTexCoord3 : TEXCOORD3;\n" + "float2 vTexCoord3 : TEXCOORD3;\n" + "float4 vTexCoord4 : TEXCOORD4;\n" "};\n" - "void main( out VSOUTPUT OUT,in float4 inPosition : POSITION,in float2 inTEX0 : TEXCOORD0,in float2 inTEX1 : TEXCOORD1)\n" + "void main( out VSOUTPUT OUT,in float4 inPosition : POSITION,in float2 inTEX0 : TEXCOORD0,in float2 inTEX1 : TEXCOORD1,in float4 inTEX2 : TEXCOORD2)\n" "{\n" "OUT.vPosition = inPosition;\n" "OUT.vTexCoord = inTEX0 + (float2(-0.1830127f,-0.6830127f) * inTEX1);\n" "OUT.vTexCoord1 = inTEX0 + (float2(-0.6830127f, 0.1830127f) * inTEX1);\n" "OUT.vTexCoord2 = inTEX0 + (float2( 0.6830127f,-0.1830127f) * inTEX1);\n" - "OUT.vTexCoord3 = inTEX0 + (float2( 0.1830127f, 0.6830127f) * inTEX1);\n" + "OUT.vTexCoord3 = inTEX0 + (float2( 0.1830127f, 0.6830127f) * inTEX1);\n" + "OUT.vTexCoord4 = inTEX2;\n" "}\n"); FSAAVertexShader = D3D::CompileAndCreateVertexShader(vFSAAProg, (int)strlen(vFSAAProg));