D3D9: Fall back to just creating a depth surface instead of a depth texture if the latter one isn't supported by the hardware.

This is a workaround for issue 3256.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6737 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2011-01-04 12:56:52 +00:00
parent efe555fc16
commit 599020ef99
4 changed files with 59 additions and 27 deletions

View file

@ -82,6 +82,22 @@ LPDIRECT3DVERTEXDECLARATION9 m_VtxDecl;
LPDIRECT3DPIXELSHADER9 m_PixelShader;
LPDIRECT3DVERTEXSHADER9 m_VertexShader;
// Z buffer formats to be used for EFB depth surface
D3DFORMAT DepthFormats[] = {
FOURCC_INTZ,
FOURCC_DF24,
FOURCC_RAWZ,
FOURCC_DF16,
D3DFMT_D24X8,
D3DFMT_D24X4S4,
D3DFMT_D24S8,
D3DFMT_D24FS8,
D3DFMT_D32, // too much precision, but who cares
D3DFMT_D16, // much lower precision, but better than nothing
D3DFMT_D15S1,
};
void Enumerate();
int GetNumAdapters() { return numAdapters; }
@ -469,6 +485,24 @@ bool CheckDepthStencilSupport(D3DFORMAT target_format, D3DFORMAT depth_format)
return D3D_OK == D3D->CheckDepthStencilMatch(cur_adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, target_format, depth_format);
}
D3DFORMAT GetSupportedDepthTextureFormat()
{
for (int i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
if (D3D::CheckTextureSupport(D3DUSAGE_DEPTHSTENCIL, DepthFormats[i]))
return DepthFormats[i];
return D3DFMT_UNKNOWN;
}
D3DFORMAT GetSupportedDepthSurfaceFormat(D3DFORMAT target_format)
{
for (int i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
if (D3D::CheckDepthStencilSupport(target_format, DepthFormats[i]))
return DepthFormats[i];
return D3DFMT_UNKNOWN;
}
const char *VertexShaderVersionString()
{
static const char *versions[5] = {"ERROR", "vs_1_4", "vs_2_0", "vs_3_0", "vs_4_0"};

View file

@ -78,6 +78,9 @@ bool FixTextureSize(int& width, int& height);
bool CheckTextureSupport(DWORD usage, D3DFORMAT tex_format);
bool CheckDepthStencilSupport(D3DFORMAT target_format, D3DFORMAT depth_format);
D3DFORMAT GetSupportedDepthTextureFormat();
D3DFORMAT GetSupportedDepthSurfaceFormat(D3DFORMAT target_format);
// The following are "filtered" versions of the corresponding D3Ddev-> functions.
void SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture);
void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);

View file

@ -39,6 +39,7 @@ FramebufferManager::Efb FramebufferManager::s_efb;
FramebufferManager::FramebufferManager()
{
bool depth_textures_supported = true;
int target_width = Renderer::GetFullTargetWidth();
int target_height = Renderer::GetFullTargetHeight();
s_efb.color_surface_Format = D3DFMT_A8R8G8B8;
@ -59,35 +60,17 @@ FramebufferManager::FramebufferManager()
hr = D3D::dev->CreateOffscreenPlainSurface(1, 1, s_efb.color_surface_Format, D3DPOOL_SYSTEMMEM, &s_efb.color_OffScreenReadBuffer, NULL);
CHECK(hr, "Create offscreen color surface (hr=%#x)", hr);
// Select a Z-buffer format with hardware support
D3DFORMAT DepthTexFormats[] = {
FOURCC_INTZ,
FOURCC_DF24,
FOURCC_RAWZ,
FOURCC_DF16,
D3DFMT_D24X8,
D3DFMT_D24X4S4,
D3DFMT_D24S8,
D3DFMT_D24FS8,
D3DFMT_D32, // too much precision, but who cares
D3DFMT_D16, // much lower precision, but better than nothing
D3DFMT_D15S1,
};
// check format support
for (int i = 0; i < sizeof(DepthTexFormats)/sizeof(D3DFORMAT); ++i)
{
if (D3D::CheckTextureSupport(D3DUSAGE_DEPTHSTENCIL, DepthTexFormats[i]))
{
s_efb.depth_surface_Format = DepthTexFormats[i];
break;
}
}
// Select a Z-buffer texture format with hardware support
s_efb.depth_surface_Format = D3D::GetSupportedDepthTextureFormat();
if (s_efb.depth_surface_Format == D3DFMT_UNKNOWN)
{
PanicAlert("No supported depth format found, disabling depth buffers.\nExpect glitches.");
// workaround for Intel GPUs etc: only create a depth _surface_
depth_textures_supported = false;
s_efb.depth_surface_Format = D3D::GetSupportedDepthSurfaceFormat(s_efb.color_surface_Format);
ERROR_LOG(VIDEO, "No supported depth texture format found, disabling Z peeks for EFB access.");
}
else
if (depth_textures_supported)
{
// EFB depth buffer - primary depth buffer
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_DEPTHSTENCIL, s_efb.depth_surface_Format,
@ -96,6 +79,7 @@ FramebufferManager::FramebufferManager()
CHECK(hr, "Framebuffer depth texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
// Render buffer for AccessEFB (depth data)
D3DFORMAT DepthTexFormats[2];
if (s_efb.depth_surface_Format == FOURCC_RAWZ || s_efb.depth_surface_Format == D3DFMT_D24X8)
DepthTexFormats[0] = D3DFMT_A8R8G8B8;
else
@ -120,6 +104,12 @@ FramebufferManager::FramebufferManager()
hr = D3D::dev->CreateOffscreenPlainSurface(4, 4, s_efb.depth_ReadBuffer_Format, D3DPOOL_SYSTEMMEM, &s_efb.depth_OffScreenReadBuffer, NULL);
CHECK(hr, "Create depth offscreen surface (hr=%#x)", hr);
}
else if (s_efb.depth_surface_Format)
{
// just create a depth surface
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, s_efb.depth_surface_Format, D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb.depth_surface, NULL);
CHECK(hr, "Framebuffer depth surface (size: %dx%d; hr=%#x)", target_width, target_height, hr);
}
// ReinterpretPixelData - EFB color data will be copy-converted to this texture and the buffers are swapped then
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb.color_surface_Format,

View file

@ -513,6 +513,11 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
return 0;
}
// if depth textures aren't supported by the hardware, just return
if (type == PEEK_Z)
if (FramebufferManager::GetEFBDepthTexture() == NULL)
return 0;
// We're using three surfaces here:
// - pEFBSurf: EFB Surface. Source surface when peeking, destination surface when poking.
// - pBufferRT: A render target surface. When peeking, we render a textured quad to this surface.
@ -646,7 +651,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
val += ((float)(z & 0xFF)) * ffrac;
break;
};
pSystemBuf->UnlockRect();
// TODO: in RE0 this value is often off by one, which causes lighting to disappear