Commit e4ebeb95 by apatrick@chromium.org

Do not call GetAdapterDisplayMode after Display has been initialized.

Some AMD drivers fail with D3DERR_NOTAVAILABLE after the machine has been in sleep mode and never seem to recover for a given IDirect3D9 object. I reproduced with Catalyst 9.12.0.0 and a Radeon 7700. Instead, record the display mode at the time the it was initialized and thereafter use its format as the argument to CheckDeviceFormat etc. Previously, CheckDeviceFormat was passed an uninitialized value as the format if GetAdapterDisplayMode failed. See http://crbug.com/229950 Review URL: https://codereview.appspot.com/8677044 git-svn-id: https://angleproject.googlecode.com/svn/trunk@2183 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1cae6d22
...@@ -86,6 +86,8 @@ Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool softwar ...@@ -86,6 +86,8 @@ Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool softwar
mDeviceType = D3DDEVTYPE_HAL; mDeviceType = D3DDEVTYPE_HAL;
#endif #endif
mDisplayMode = D3DDISPLAYMODE();
mMinSwapInterval = 1; mMinSwapInterval = 1;
mMaxSwapInterval = 1; mMaxSwapInterval = 1;
mSoftwareDevice = software; mSoftwareDevice = software;
...@@ -252,8 +254,11 @@ bool Display::initialize() ...@@ -252,8 +254,11 @@ bool Display::initialize()
// D3DFMT_D24FS8 // D3DFMT_D24FS8
}; };
D3DDISPLAYMODE currentDisplayMode; if (FAILED(mD3d9->GetAdapterDisplayMode(mAdapter, &mDisplayMode)))
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode); {
terminate();
return false;
}
ConfigSet configSet; ConfigSet configSet;
...@@ -261,7 +266,7 @@ bool Display::initialize() ...@@ -261,7 +266,7 @@ bool Display::initialize()
{ {
D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex]; D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex];
HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat); HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
...@@ -272,21 +277,21 @@ bool Display::initialize() ...@@ -272,21 +277,21 @@ bool Display::initialize()
if(depthStencilFormat != D3DFMT_UNKNOWN) if(depthStencilFormat != D3DFMT_UNKNOWN)
{ {
result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat); result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat);
} }
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
if(depthStencilFormat != D3DFMT_UNKNOWN) if(depthStencilFormat != D3DFMT_UNKNOWN)
{ {
result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat); result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, mDisplayMode.Format, renderTargetFormat, depthStencilFormat);
} }
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
// FIXME: enumerate multi-sampling // FIXME: enumerate multi-sampling
configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0, configSet.add(mDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0,
mDeviceCaps.MaxTextureWidth, mDeviceCaps.MaxTextureHeight); mDeviceCaps.MaxTextureWidth, mDeviceCaps.MaxTextureHeight);
} }
} }
...@@ -1032,26 +1037,17 @@ void Display::getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray) ...@@ -1032,26 +1037,17 @@ void Display::getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray)
bool Display::getDXT1TextureSupport() bool Display::getDXT1TextureSupport()
{ {
D3DDISPLAYMODE currentDisplayMode; return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1));
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1));
} }
bool Display::getDXT3TextureSupport() bool Display::getDXT3TextureSupport()
{ {
D3DDISPLAYMODE currentDisplayMode; return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3));
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3));
} }
bool Display::getDXT5TextureSupport() bool Display::getDXT5TextureSupport()
{ {
D3DDISPLAYMODE currentDisplayMode; return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5));
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5));
} }
// we use INTZ for depth textures in Direct3D9 // we use INTZ for depth textures in Direct3D9
...@@ -1059,12 +1055,9 @@ bool Display::getDXT5TextureSupport() ...@@ -1059,12 +1055,9 @@ bool Display::getDXT5TextureSupport()
// see http://aras-p.info/texts/D3D9GPUHacks.html // see http://aras-p.info/texts/D3D9GPUHacks.html
bool Display::getDepthTextureSupport() const bool Display::getDepthTextureSupport() const
{ {
D3DDISPLAYMODE currentDisplayMode; bool intz = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format,
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
bool intz = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ)); D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ));
bool null = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, bool null = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format,
D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL)); D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL));
return intz && null; return intz && null;
...@@ -1072,24 +1065,21 @@ bool Display::getDepthTextureSupport() const ...@@ -1072,24 +1065,21 @@ bool Display::getDepthTextureSupport() const
bool Display::getFloat32TextureSupport(bool *filtering, bool *renderable) bool Display::getFloat32TextureSupport(bool *filtering, bool *renderable)
{ {
D3DDISPLAYMODE currentDisplayMode; *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
*filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
*renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F))&& D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F))&&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
if (!*filtering && !*renderable) if (!*filtering && !*renderable)
{ {
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0,
D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
} }
else else
...@@ -1100,24 +1090,21 @@ bool Display::getFloat32TextureSupport(bool *filtering, bool *renderable) ...@@ -1100,24 +1090,21 @@ bool Display::getFloat32TextureSupport(bool *filtering, bool *renderable)
bool Display::getFloat16TextureSupport(bool *filtering, bool *renderable) bool Display::getFloat16TextureSupport(bool *filtering, bool *renderable)
{ {
D3DDISPLAYMODE currentDisplayMode; *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
*filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
*renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
if (!*filtering && !*renderable) if (!*filtering && !*renderable)
{ {
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0,
D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
} }
else else
...@@ -1128,18 +1115,12 @@ bool Display::getFloat16TextureSupport(bool *filtering, bool *renderable) ...@@ -1128,18 +1115,12 @@ bool Display::getFloat16TextureSupport(bool *filtering, bool *renderable)
bool Display::getLuminanceTextureSupport() bool Display::getLuminanceTextureSupport()
{ {
D3DDISPLAYMODE currentDisplayMode; return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_L8));
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_L8));
} }
bool Display::getLuminanceAlphaTextureSupport() bool Display::getLuminanceAlphaTextureSupport()
{ {
D3DDISPLAYMODE currentDisplayMode; return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8));
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8));
} }
float Display::getTextureFilterAnisotropySupport() const float Display::getTextureFilterAnisotropySupport() const
...@@ -1293,10 +1274,7 @@ bool Display::getVertexTextureSupport() const ...@@ -1293,10 +1274,7 @@ bool Display::getVertexTextureSupport() const
return false; return false;
} }
D3DDISPLAYMODE currentDisplayMode; HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, mDisplayMode.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F);
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F);
return SUCCEEDED(result); return SUCCEEDED(result);
} }
......
...@@ -125,6 +125,7 @@ class Display ...@@ -125,6 +125,7 @@ class Display
UINT mAdapter; UINT mAdapter;
D3DDEVTYPE mDeviceType; D3DDEVTYPE mDeviceType;
D3DDISPLAYMODE mDisplayMode;
IDirect3D9 *mD3d9; // Always valid after successful initialization. IDirect3D9 *mD3d9; // Always valid after successful initialization.
IDirect3D9Ex *mD3d9Ex; // Might be null if D3D9Ex is not supported. IDirect3D9Ex *mD3d9Ex; // Might be null if D3D9Ex is not supported.
IDirect3DDevice9 *mDevice; IDirect3DDevice9 *mDevice;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment