Commit 0a82f2fa by Jamie Madill Committed by Commit Bot

D3D11: Don't copy SharedSRVs around.

This was causing a very large performance regression in Texture re-binding. Instead pass by const &, which should be fine, since values in std::map (and unordered_map) are not reallocated when the map changes. Also make the SharedResource type non-copyable, and add an explicit makeCopy method for when we need to clone the shared pointer. BUG=angleproject:2034 BUG=chromium:727318 Change-Id: I39508a6ca4b41e4da31fe68899caa4464138cada Reviewed-on: https://chromium-review.googlesource.com/517670 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent df7d13eb
......@@ -231,8 +231,8 @@ TextureRenderTarget11::TextureRenderTarget11(d3d11::RenderTargetView &&rtv,
mTexture(resource),
mRenderTarget(std::move(rtv)),
mDepthStencil(),
mShaderResource(srv),
mBlitShaderResource(blitSRV)
mShaderResource(srv.makeCopy()),
mBlitShaderResource(blitSRV.makeCopy())
{
if (mRenderTarget.valid() && mTexture.valid())
{
......@@ -260,7 +260,7 @@ TextureRenderTarget11::TextureRenderTarget11(d3d11::DepthStencilView &&dsv,
mTexture(resource),
mRenderTarget(),
mDepthStencil(std::move(dsv)),
mShaderResource(srv),
mShaderResource(srv.makeCopy()),
mBlitShaderResource()
{
if (mDepthStencil.valid() && mTexture.valid())
......
......@@ -1508,7 +1508,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type,
gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
{
d3d11::SharedSRV textureSRV;
const d3d11::SharedSRV *textureSRV = nullptr;
if (texture)
{
......@@ -1524,9 +1524,9 @@ gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *t
ANGLE_TRY(storage11->getSRV(texture->getTextureState(), &textureSRV));
// If we get NULL back from getSRV here, something went wrong in the texture class and we're
// unexpectedly missing the shader resource view
ASSERT(textureSRV.valid());
// If we get an invalid SRV here, something went wrong in the texture class and we're
// unexpectedly missing the shader resource view.
ASSERT(textureSRV->valid());
textureImpl->resetDirty();
}
......@@ -1536,7 +1536,7 @@ gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *t
(type == gl::SAMPLER_VERTEX &&
static_cast<unsigned int>(index) < getNativeCaps().maxVertexTextureImageUnits));
mStateManager.setShaderResource(type, index, textureSRV.get());
mStateManager.setShaderResource(type, index, textureSRV->get());
return gl::NoError();
}
......@@ -3421,7 +3421,7 @@ gl::Error Renderer11::copyTexture(const gl::Texture *source,
}
else
{
d3d11::SharedSRV sourceSRV;
const d3d11::SharedSRV *sourceSRV = nullptr;
ANGLE_TRY(sourceStorage11->getSRVLevels(sourceLevel, sourceLevel, &sourceSRV));
gl::ImageIndex destIndex = gl::ImageIndex::MakeGeneric(destTarget, destLevel);
......@@ -3449,7 +3449,7 @@ gl::Error Renderer11::copyTexture(const gl::Texture *source,
// Use nearest filtering because source and destination are the same size for the direct
// copy
GLenum sourceFormat = source->getFormat(GL_TEXTURE_2D, sourceLevel).info->format;
ANGLE_TRY(mBlit->copyTexture(sourceSRV, sourceArea, sourceSize, sourceFormat, destRTV,
ANGLE_TRY(mBlit->copyTexture(*sourceSRV, sourceArea, sourceSize, sourceFormat, destRTV,
destArea, destSize, nullptr, destFormat, GL_NEAREST, false,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha));
}
......@@ -3575,7 +3575,7 @@ gl::Error Renderer11::createRenderTarget(int width,
}
else
{
blitSRV = srv;
blitSRV = srv.makeCopy();
}
}
......@@ -3957,11 +3957,11 @@ gl::Error Renderer11::generateMipmapUsingD3D(TextureStorage *storage,
ASSERT(storage11->isRenderTarget());
ASSERT(storage11->supportsNativeMipmapFunction());
d3d11::SharedSRV srv;
const d3d11::SharedSRV *srv = nullptr;
ANGLE_TRY(storage11->getSRVLevels(textureState.getEffectiveBaseLevel(),
textureState.getEffectiveMaxLevel(), &srv));
mDeviceContext->GenerateMips(srv.get());
mDeviceContext->GenerateMips(srv->get());
return gl::NoError();
}
......@@ -4255,11 +4255,11 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
ASSERT(readRenderTarget11);
readTexture = readRenderTarget11->getTexture();
readSubresource = readRenderTarget11->getSubresourceIndex();
readSRV = readRenderTarget11->getBlitShaderResourceView();
readSRV = readRenderTarget11->getBlitShaderResourceView().makeCopy();
if (!readSRV.valid())
{
ASSERT(depthBlit || stencilBlit);
readSRV = readRenderTarget11->getShaderResourceView();
readSRV = readRenderTarget11->getShaderResourceView().makeCopy();
}
ASSERT(readSRV.valid());
}
......
......@@ -231,12 +231,11 @@ class SharedResource11 : public Resource11Base<T, std::shared_ptr, TypedData<T>>
return *this;
}
SharedResource11(const SharedResource11 &sharedObj) { this->mData = sharedObj.mData; }
SharedResource11 &operator=(const SharedResource11 &sharedObj)
SharedResource11 makeCopy() const
{
this->mData = sharedObj.mData;
return *this;
SharedResource11 copy;
copy.mData = this->mData;
return std::move(copy);
}
private:
......
......@@ -167,7 +167,8 @@ UINT TextureStorage11::getSubresourceIndex(const gl::ImageIndex &index) const
return subresource;
}
gl::Error TextureStorage11::getSRV(const gl::TextureState &textureState, d3d11::SharedSRV *outSRV)
gl::Error TextureStorage11::getSRV(const gl::TextureState &textureState,
const d3d11::SharedSRV **outSRV)
{
// Make sure to add the level offset for our tiny compressed texture workaround
const GLuint effectiveBaseLevel = textureState.getEffectiveBaseLevel();
......@@ -229,12 +230,12 @@ gl::Error TextureStorage11::getSRV(const gl::TextureState &textureState, d3d11::
return gl::NoError();
}
gl::Error TextureStorage11::getCachedOrCreateSRV(const SRVKey &key, d3d11::SharedSRV *outSRV)
gl::Error TextureStorage11::getCachedOrCreateSRV(const SRVKey &key, const d3d11::SharedSRV **outSRV)
{
auto iter = mSrvCache.find(key);
if (iter != mSrvCache.end())
{
*outSRV = iter->second;
*outSRV = &iter->second;
return gl::NoError();
}
......@@ -265,8 +266,8 @@ gl::Error TextureStorage11::getCachedOrCreateSRV(const SRVKey &key, d3d11::Share
ANGLE_TRY(createSRV(key.baseLevel, key.mipLevels, format, *texture, &srv));
mSrvCache.insert(std::make_pair(key, srv));
*outSRV = srv;
const auto &insertIt = mSrvCache.insert(std::make_pair(key, std::move(srv)));
*outSRV = &insertIt.first->second;
return gl::NoError();
}
......@@ -283,7 +284,7 @@ gl::Error TextureStorage11::getSRVLevel(int mipLevel, bool blitSRV, const d3d11:
// Only create a different SRV for blit if blit format is different from regular srv format
if (otherLevelSRVs[mipLevel].valid() && mFormatInfo.srvFormat == mFormatInfo.blitSRVFormat)
{
levelSRVs[mipLevel] = otherLevelSRVs[mipLevel];
levelSRVs[mipLevel] = otherLevelSRVs[mipLevel].makeCopy();
}
else
{
......@@ -301,7 +302,9 @@ gl::Error TextureStorage11::getSRVLevel(int mipLevel, bool blitSRV, const d3d11:
return gl::NoError();
}
gl::Error TextureStorage11::getSRVLevels(GLint baseLevel, GLint maxLevel, d3d11::SharedSRV *outSRV)
gl::Error TextureStorage11::getSRVLevels(GLint baseLevel,
GLint maxLevel,
const d3d11::SharedSRV **outSRV)
{
unsigned int mipLevels = maxLevel - baseLevel + 1;
......@@ -1371,7 +1374,7 @@ gl::Error TextureStorage11_EGLImage::getResource(const TextureHelper11 **outReso
}
gl::Error TextureStorage11_EGLImage::getSRV(const gl::TextureState &textureState,
d3d11::SharedSRV *outSRV)
const d3d11::SharedSRV **outSRV)
{
ANGLE_TRY(checkForUpdatedRenderTarget());
return TextureStorage11::getSRV(textureState, outSRV);
......@@ -1535,7 +1538,7 @@ gl::Error TextureStorage11_EGLImage::createSRV(int baseLevel,
ASSERT(texture == renderTarget->getTexture());
*outSRV = renderTarget->getShaderResourceView();
*outSRV = renderTarget->getShaderResourceView().makeCopy();
}
return gl::NoError();
......@@ -1949,7 +1952,7 @@ gl::Error TextureStorage11_Cube::getRenderTarget(const gl::ImageIndex &index,
}
else
{
blitSRV = srv;
blitSRV = srv.makeCopy();
}
srv.setDebugName("TexStorageCube.RenderTargetSRV");
......@@ -2668,7 +2671,7 @@ gl::Error TextureStorage11_2DArray::getRenderTarget(const gl::ImageIndex &index,
}
else
{
blitSRV = srv;
blitSRV = srv.makeCopy();
}
srv.setDebugName("TexStorage2DArray.RenderTargetSRV");
......
......@@ -45,7 +45,7 @@ class TextureStorage11 : public TextureStorage
UINT getBindFlags() const;
UINT getMiscFlags() const;
const d3d11::Format &getFormatSet() const;
gl::Error getSRVLevels(GLint baseLevel, GLint maxLevel, d3d11::SharedSRV *outSRV);
gl::Error getSRVLevels(GLint baseLevel, GLint maxLevel, const d3d11::SharedSRV **outSRV);
gl::Error generateSwizzles(const gl::SwizzleState &swizzleTarget);
void markLevelDirty(int mipLevel);
void markDirty();
......@@ -76,7 +76,7 @@ class TextureStorage11 : public TextureStorage
const gl::PixelUnpackState &unpack,
const uint8_t *pixelData) override;
virtual gl::Error getSRV(const gl::TextureState &textureState, d3d11::SharedSRV *outSRV);
virtual gl::Error getSRV(const gl::TextureState &textureState, const d3d11::SharedSRV **outSRV);
virtual UINT getSubresourceIndex(const gl::ImageIndex &index) const;
virtual gl::Error getResource(const TextureHelper11 **outResource) = 0;
virtual void associateImage(Image11* image, const gl::ImageIndex &index) = 0;
......@@ -152,7 +152,7 @@ class TextureStorage11 : public TextureStorage
};
typedef std::map<SRVKey, d3d11::SharedSRV> SRVCache;
gl::Error getCachedOrCreateSRV(const SRVKey &key, d3d11::SharedSRV *outSRV);
gl::Error getCachedOrCreateSRV(const SRVKey &key, const d3d11::SharedSRV **outSRV);
SRVCache mSrvCache;
std::array<d3d11::SharedSRV, gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS> mLevelSRVs;
......@@ -264,7 +264,8 @@ class TextureStorage11_EGLImage final : public TextureStorage11
~TextureStorage11_EGLImage() override;
gl::Error getResource(const TextureHelper11 **outResource) override;
gl::Error getSRV(const gl::TextureState &textureState, d3d11::SharedSRV *outSRV) override;
gl::Error getSRV(const gl::TextureState &textureState,
const d3d11::SharedSRV **outSRV) override;
gl::Error getMippedResource(const TextureHelper11 **outResource) override;
gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT) override;
......
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