Bug 1079400. Limit the maximum render target size to avoid crashes. r=jgilbert

This avoids crashes with certain NVIDIA drivers.

--HG--
extra : rebase_source : 38eb492063e29a23c3278bbef73020d90204d607
This commit is contained in:
Jeff Muizelaar 2014-12-08 19:53:26 -05:00
parent 85fb200107
commit 198e161e60
3 changed files with 27 additions and 1 deletions

View File

@ -275,6 +275,15 @@ RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11DepthStencilView *dsv,
}
}
UINT64 EstimateSize(D3D11_TEXTURE2D_DESC &desc)
{
//XXX: handle overflow (64 bits should be enough for anyone...)
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(desc.Format);
// NVIDIA seems to align the width of buffers by 8 and the height by 64, so we do the same.
UINT64 total = UINT64(rx::roundUp(desc.Width, UINT(8))) * rx::roundUp(desc.Height, UINT(64)) * desc.SampleDesc.Count * dxgiFormatInfo.pixelBytes;
return total;
}
RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height, GLenum internalFormat, GLsizei samples)
{
mRenderer = Renderer11::makeRenderer11(renderer);
@ -324,7 +333,17 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
ID3D11Device *device = mRenderer->getDevice();
ID3D11Texture2D *texture = NULL;
HRESULT result = device->CreateTexture2D(&desc, NULL, &texture);
HRESULT result;
// Some Nvidia drivers (GeForce GT 610 w/ 9.18.13.3523) crash with very large render targets
if (EstimateSize(desc) > mRenderer->getMaxResourceSize())
{
result = E_OUTOFMEMORY;
}
else
{
result = device->CreateTexture2D(&desc, NULL, &texture);
}
mTexture = texture;
if (result == E_OUTOFMEMORY)

View File

@ -1817,6 +1817,12 @@ DWORD Renderer11::getAdapterVendor() const
return mAdapterDescription.VendorId;
}
SIZE_T Renderer11::getMaxResourceSize() const
{
// This formula comes from http://msdn.microsoft.com/en-us/library/windows/desktop/ff819065%28v=vs.85%29.aspx
return std::min(std::max(SIZE_T(128 * 1024 * 1024), mAdapterDescription.DedicatedVideoMemory), SIZE_T(2048) * 1024 * 1024);
}
std::string Renderer11::getRendererDescription() const
{
std::ostringstream rendererString;

View File

@ -101,6 +101,7 @@ class Renderer11 : public Renderer
virtual bool testDeviceResettable();
virtual DWORD getAdapterVendor() const;
SIZE_T getMaxResourceSize() const;
virtual std::string getRendererDescription() const;
virtual GUID getAdapterIdentifier() const;