Commit 218ffc49 by Jamie Madill Committed by Commit Bot

SwapChain11: Create SRV copy texture lazily.

We would allocate this texture for devices that don't need it. Instead do this lazily. This was showing up in the profiles for the MotionMark benchmark, possibly due to re-creating the surface. BUG=angleproject:1155 Change-Id: I28b5eda29e21899fc8afef054e1b8063e3cc2e00 Reviewed-on: https://chromium-review.googlesource.com/655479Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 3667dbd6
...@@ -77,6 +77,8 @@ SwapChain11::SwapChain11(Renderer11 *renderer, ...@@ -77,6 +77,8 @@ SwapChain11::SwapChain11(Renderer11 *renderer,
mOffscreenTexture(), mOffscreenTexture(),
mOffscreenRTView(), mOffscreenRTView(),
mOffscreenSRView(), mOffscreenSRView(),
mNeedsOffscreenTextureCopy(false),
mOffscreenTextureCopyForSRV(),
mDepthStencilTexture(), mDepthStencilTexture(),
mDepthStencilDSView(), mDepthStencilDSView(),
mDepthStencilSRView(), mDepthStencilSRView(),
...@@ -138,6 +140,8 @@ void SwapChain11::releaseOffscreenColorBuffer() ...@@ -138,6 +140,8 @@ void SwapChain11::releaseOffscreenColorBuffer()
mOffscreenTexture.reset(); mOffscreenTexture.reset();
mOffscreenRTView.reset(); mOffscreenRTView.reset();
mOffscreenSRView.reset(); mOffscreenSRView.reset();
mNeedsOffscreenTextureCopy = false;
mOffscreenTextureCopyForSRV.reset();
} }
void SwapChain11::releaseOffscreenDepthBuffer() void SwapChain11::releaseOffscreenDepthBuffer()
...@@ -319,18 +323,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(const gl::Context *context, ...@@ -319,18 +323,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(const gl::Context *context,
{ {
// Special case for external textures that cannot support sampling. Since internally we // Special case for external textures that cannot support sampling. Since internally we
// assume our SwapChain is always readable, we make a copy texture that is compatible. // assume our SwapChain is always readable, we make a copy texture that is compatible.
D3D11_TEXTURE2D_DESC offscreenCopyDesc = offscreenTextureDesc; mNeedsOffscreenTextureCopy = true;
offscreenCopyDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
offscreenCopyDesc.MiscFlags = 0;
offscreenCopyDesc.CPUAccessFlags = 0;
err = mRenderer->allocateTexture(offscreenCopyDesc, backbufferFormatInfo,
&mOffscreenTextureCopyForSRV);
ASSERT(!err.isError());
mOffscreenTextureCopyForSRV.setDebugName("Offscreen back buffer copy for SRV");
err = mRenderer->allocateResource(offscreenSRVDesc, mOffscreenTextureCopyForSRV.get(),
&mOffscreenSRView);
ASSERT(!err.isError());
mOffscreenSRView.setDebugName("Offscreen back buffer shader resource");
} }
if (previousOffscreenTexture.valid()) if (previousOffscreenTexture.valid())
...@@ -964,12 +957,41 @@ const d3d11::SharedSRV &SwapChain11::getRenderTargetShaderResource() ...@@ -964,12 +957,41 @@ const d3d11::SharedSRV &SwapChain11::getRenderTargetShaderResource()
return mBackBufferSRView; return mBackBufferSRView;
} }
if (!mOffscreenTextureCopyForSRV.valid()) if (!mNeedsOffscreenTextureCopy)
{ {
ASSERT(mOffscreenSRView.valid()); ASSERT(mOffscreenSRView.valid());
return mOffscreenSRView; return mOffscreenSRView;
} }
if (!mOffscreenTextureCopyForSRV.valid())
{
const d3d11::Format &backbufferFormatInfo =
d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps());
D3D11_TEXTURE2D_DESC offscreenCopyDesc;
mOffscreenTexture.getDesc(&offscreenCopyDesc);
offscreenCopyDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
offscreenCopyDesc.MiscFlags = 0;
offscreenCopyDesc.CPUAccessFlags = 0;
gl::Error err = mRenderer->allocateTexture(offscreenCopyDesc, backbufferFormatInfo,
&mOffscreenTextureCopyForSRV);
ASSERT(!err.isError());
mOffscreenTextureCopyForSRV.setDebugName("Offscreen back buffer copy for SRV");
D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc;
offscreenSRVDesc.Format = backbufferFormatInfo.srvFormat;
offscreenSRVDesc.ViewDimension =
(mEGLSamples <= 1) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;
offscreenSRVDesc.Texture2D.MostDetailedMip = 0;
offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1);
err = mRenderer->allocateResource(offscreenSRVDesc, mOffscreenTextureCopyForSRV.get(),
&mOffscreenSRView);
ASSERT(!err.isError());
mOffscreenSRView.setDebugName("Offscreen back buffer shader resource");
}
// Need to copy the offscreen texture into the shader-readable copy, since it's external and // Need to copy the offscreen texture into the shader-readable copy, since it's external and
// we don't know if the copy is up-to-date. This works around the problem we have when the app // we don't know if the copy is up-to-date. This works around the problem we have when the app
// passes in a texture that isn't shader-readable. // passes in a texture that isn't shader-readable.
......
...@@ -110,6 +110,7 @@ class SwapChain11 final : public SwapChainD3D ...@@ -110,6 +110,7 @@ class SwapChain11 final : public SwapChainD3D
TextureHelper11 mOffscreenTexture; TextureHelper11 mOffscreenTexture;
d3d11::RenderTargetView mOffscreenRTView; d3d11::RenderTargetView mOffscreenRTView;
d3d11::SharedSRV mOffscreenSRView; d3d11::SharedSRV mOffscreenSRView;
bool mNeedsOffscreenTextureCopy;
TextureHelper11 mOffscreenTextureCopyForSRV; TextureHelper11 mOffscreenTextureCopyForSRV;
TextureHelper11 mDepthStencilTexture; TextureHelper11 mDepthStencilTexture;
......
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