DX9/DX11: Workaround the viewpoint/EFB creation issues in e.g. SMG2 on NVIDIA hardware or when using HD. Will most likely cause glitches, but prevents crashing. Correct behavior can't be implemented in Direct3D, so this is the best option we have.

Also two little changes which don't affect functionality or performance:
Change an IUnknown* cast to a T* cast.
Improve some error messages.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5870 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2010-07-11 16:26:46 +00:00
parent 3997243143
commit ff917cb0c9
6 changed files with 51 additions and 3 deletions

View File

@ -238,6 +238,27 @@ unsigned int GetBackBufferHeight() { return yres; }
bool BGRATexturesSupported() { return bgra_textures_supported; }
// Returns the maximum width/height of a texture. This value only depends upon the feature level in DX11
unsigned int GetMaxTextureSize()
{
switch (featlevel)
{
case D3D_FEATURE_LEVEL_11_0:
return 16384;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 8192;
case D3D_FEATURE_LEVEL_9_3:
return 4096;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 2048;
}
}
void Reset()
{
// release all back buffer references

View File

@ -51,6 +51,8 @@ const char* PixelShaderVersionString();
const char* VertexShaderVersionString();
bool BGRATexturesSupported();
unsigned int GetMaxTextureSize();
// Ihis function will assign a name to the given resource.
// The DirectX debug layer will make it easier to identify resources that way,
// e.g. when listing up all resources who have unreleased references.

View File

@ -311,7 +311,7 @@ template<typename T> AutoState<T>::AutoState(const T* object) : state(object)
template<typename T> AutoState<T>::AutoState(const AutoState<T> &source)
{
state = source.GetPtr();
((IUnknown*)state)->AddRef();
((T*)state)->AddRef();
}
template<typename T> AutoState<T>::~AutoState()

View File

@ -700,6 +700,9 @@ void UpdateViewport()
// [3] = xorig + width/2 + 342
// [4] = yorig + height/2 + 342
// [5] = 16777215 * farz
const int old_fulltarget_w = s_Fulltarget_width;
const int old_fulltarget_h = s_Fulltarget_height;
int scissorXOff = bpmem.scissorOffset.x * 2;
int scissorYOff = bpmem.scissorOffset.y * 2;
@ -739,6 +742,15 @@ void UpdateViewport()
}
if (sizeChanged)
{
// Make sure that the requested size is actually supported by the GFX driver
if (s_Fulltarget_width > (int)D3D::GetMaxTextureSize() || s_Fulltarget_height > (int)D3D::GetMaxTextureSize())
{
// Skip EFB recreation and viewport setting. Most likely cause glitches in this case, but prevents crashes at least
ERROR_LOG(VIDEO, "Tried to set a viewport which is too wide to emulate with Direct3D11. Requested EFB size is %dx%d\n", s_Fulltarget_width, s_Fulltarget_height);
s_Fulltarget_width = old_fulltarget_w;
s_Fulltarget_height = old_fulltarget_h;
return;
}
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL);
FBManager.Destroy();
FBManager.Create();

View File

@ -97,7 +97,7 @@ void FramebufferManager::Create()
{
hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface);
}
CHECK(hr, "Create Color Texture (hr=%#x)", hr);
CHECK(hr, "Create Color Texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
hr = D3D::dev->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &s_efb_colorRead_texture, NULL);
CHECK(hr, "Create Color Read Texture (hr=%#x)", hr);
@ -128,7 +128,7 @@ void FramebufferManager::Create()
if (!FAILED(hr))
break;
}
CHECK(hr, "Depth Color Texture (hr=%#x)", hr);
CHECK(hr, "Depth Color Texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
// Get the Surface
if(s_efb_depth_texture)
{

View File

@ -823,6 +823,9 @@ void UpdateViewport()
// [3] = xorig + width/2 + 342
// [4] = yorig + height/2 + 342
// [5] = 16777215 * farz
const int old_fulltarget_w = s_Fulltarget_width;
const int old_fulltarget_h = s_Fulltarget_height;
int scissorXOff = bpmem.scissorOffset.x * 2;
int scissorYOff = bpmem.scissorOffset.y * 2;
@ -877,6 +880,16 @@ void UpdateViewport()
}
if (sizeChanged)
{
D3DCAPS9 caps = D3D::GetCaps();
// Make sure that the requested size is actually supported by the GFX driver
if (s_Fulltarget_width > caps.MaxTextureWidth || s_Fulltarget_height > caps.MaxTextureHeight)
{
// Skip EFB recreation and viewport setting. Most likely cause glitches in this case, but prevents crashes at least
ERROR_LOG(VIDEO, "Tried to set a viewport which is too wide to emulate with Direct3D9. Requested EFB size is %dx%d\n", s_Fulltarget_width, s_Fulltarget_height);
s_Fulltarget_width = old_fulltarget_w;
s_Fulltarget_height = old_fulltarget_h;
return;
}
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
FBManager.Destroy();