Commit 80da4214 by Geoff Lang Committed by Commit Bot

D3D11: Copy from Image objects instead of TextureStorage when possible.

glCopyTextureCHROMIUM calls in D3D11 would call getNativeTexture on the copy source which would allocate a TextureStorage11 if one did not already exist. This caused full mip-chain allocations in some cases when we could have just copied directly from the staging Image11. When navigating to wikipedia.org: Peak memory | Stable memory Passthrough (before): 142 mb | 119 mb Passthrough (after): 138 mb | 106 mb Validating: 139 mb | 110 mb No mip-mapped textures were allocated after this change. BUG=chromium:1030835 Change-Id: Icd14afaec445299423cfea293cba501d774f6ade Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2028147 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarRafael Cintron <rafael.cintron@microsoft.com>
parent 053929ac
...@@ -94,6 +94,7 @@ class TextureD3D : public TextureImpl, public angle::ObserverInterface ...@@ -94,6 +94,7 @@ class TextureD3D : public TextureImpl, public angle::ObserverInterface
egl::Stream *stream, egl::Stream *stream,
const egl::Stream::GLTextureDescription &desc) override; const egl::Stream::GLTextureDescription &desc) override;
angle::Result generateMipmap(const gl::Context *context) override; angle::Result generateMipmap(const gl::Context *context) override;
bool hasStorage() const { return mTexStorage != nullptr; }
TextureStorage *getStorage(); TextureStorage *getStorage();
ImageD3D *getBaseLevelImage() const; ImageD3D *getBaseLevelImage() const;
......
...@@ -90,6 +90,10 @@ class Image11 : public ImageD3D ...@@ -90,6 +90,10 @@ class Image11 : public ImageD3D
void verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const; void verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const;
void disassociateStorage(); void disassociateStorage();
angle::Result getStagingTexture(const gl::Context *context,
const TextureHelper11 **outStagingTexture,
unsigned int *outSubresourceIndex);
protected: protected:
template <typename T> template <typename T>
friend class d3d11::ScopedUnmapper; friend class d3d11::ScopedUnmapper;
...@@ -103,9 +107,6 @@ class Image11 : public ImageD3D ...@@ -103,9 +107,6 @@ class Image11 : public ImageD3D
const TextureHelper11 &textureHelper, const TextureHelper11 &textureHelper,
UINT sourceSubResource); UINT sourceSubResource);
angle::Result getStagingTexture(const gl::Context *context,
const TextureHelper11 **outStagingTexture,
unsigned int *outSubresourceIndex);
angle::Result createStagingTexture(const gl::Context *context); angle::Result createStagingTexture(const gl::Context *context);
void releaseStagingTexture(); void releaseStagingTexture();
......
...@@ -369,6 +369,33 @@ void PopulateFormatDeviceCaps(ID3D11Device *device, ...@@ -369,6 +369,33 @@ void PopulateFormatDeviceCaps(ID3D11Device *device,
} }
} }
angle::Result GetTextureD3DResourceFromStorageOrImage(const gl::Context *context,
TextureD3D *texture,
const gl::ImageIndex &index,
const TextureHelper11 **outResource,
UINT *outSubresource)
{
// If the storage exists, use it. Otherwise, copy directly from the images to avoid
// allocating a new storage.
if (texture->hasStorage())
{
TextureStorage *storage = nullptr;
ANGLE_TRY(texture->getNativeTexture(context, &storage));
TextureStorage11 *storage11 = GetAs<TextureStorage11>(storage);
ANGLE_TRY(storage11->getResource(context, outResource));
ANGLE_TRY(storage11->getSubresourceIndex(context, index, outSubresource));
}
else
{
ImageD3D *image = texture->getImage(index);
Image11 *image11 = GetAs<Image11>(image);
ANGLE_TRY(image11->getStagingTexture(context, outResource, outSubresource));
}
return angle::Result::Continue;
}
} // anonymous namespace } // anonymous namespace
Renderer11DeviceCaps::Renderer11DeviceCaps() = default; Renderer11DeviceCaps::Renderer11DeviceCaps() = default;
...@@ -2498,36 +2525,29 @@ angle::Result Renderer11::copyTexture(const gl::Context *context, ...@@ -2498,36 +2525,29 @@ angle::Result Renderer11::copyTexture(const gl::Context *context,
bool unpackPremultiplyAlpha, bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha) bool unpackUnmultiplyAlpha)
{ {
TextureD3D *sourceD3D = GetImplAs<TextureD3D>(source);
TextureStorage *sourceStorage = nullptr;
ANGLE_TRY(sourceD3D->getNativeTexture(context, &sourceStorage));
TextureStorage11 *sourceStorage11 = GetAs<TextureStorage11>(sourceStorage); TextureD3D *sourceD3D = GetImplAs<TextureD3D>(source);
ASSERT(sourceStorage11); const gl::ImageDesc &sourceImageDesc = source->getTextureState().getImageDesc(
NonCubeTextureTypeToTarget(source->getType()), sourceLevel);
TextureStorage11 *destStorage11 = GetAs<TextureStorage11>(storage); TextureStorage11 *destStorage11 = GetAs<TextureStorage11>(storage);
ASSERT(destStorage11); ASSERT(destStorage11);
// Check for fast path where a CopySubresourceRegion can be used. // Check for fast path where a CopySubresourceRegion can be used.
if (unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !unpackFlipY && if (unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !unpackFlipY &&
source->getFormat(srcTarget, sourceLevel).info->format == destFormat && sourceImageDesc.format.info->sizedInternalFormat ==
sourceStorage11->getFormatSet().internalFormat ==
destStorage11->getFormatSet().internalFormat) destStorage11->getFormatSet().internalFormat)
{ {
const TextureHelper11 *sourceResource = nullptr;
ANGLE_TRY(sourceStorage11->getResource(context, &sourceResource));
const TextureHelper11 *destResource = nullptr; const TextureHelper11 *destResource = nullptr;
ANGLE_TRY(destStorage11->getResource(context, &destResource)); ANGLE_TRY(destStorage11->getResource(context, &destResource));
if (srcTarget == gl::TextureTarget::_2D || srcTarget == gl::TextureTarget::_3D) if (srcTarget == gl::TextureTarget::_2D || srcTarget == gl::TextureTarget::_3D)
{ {
gl::ImageIndex sourceIndex = gl::ImageIndex::MakeFromTarget(srcTarget, sourceLevel, 1); gl::ImageIndex sourceIndex = gl::ImageIndex::MakeFromTarget(srcTarget, sourceLevel, 1);
const TextureHelper11 *sourceResource = nullptr;
UINT sourceSubresource = 0; UINT sourceSubresource = 0;
ANGLE_TRY( ANGLE_TRY(GetTextureD3DResourceFromStorageOrImage(context, sourceD3D, sourceIndex,
sourceStorage11->getSubresourceIndex(context, sourceIndex, &sourceSubresource)); &sourceResource, &sourceSubresource));
gl::ImageIndex destIndex = gl::ImageIndex::MakeFromTarget(destTarget, destLevel, 1); gl::ImageIndex destIndex = gl::ImageIndex::MakeFromTarget(destTarget, destLevel, 1);
...@@ -2547,7 +2567,6 @@ angle::Result Renderer11::copyTexture(const gl::Context *context, ...@@ -2547,7 +2567,6 @@ angle::Result Renderer11::copyTexture(const gl::Context *context,
} }
else if (srcTarget == gl::TextureTarget::_2DArray) else if (srcTarget == gl::TextureTarget::_2DArray)
{ {
D3D11_BOX d3dBox{static_cast<UINT>(sourceBox.x), D3D11_BOX d3dBox{static_cast<UINT>(sourceBox.x),
static_cast<UINT>(sourceBox.y), static_cast<UINT>(sourceBox.y),
0, 0,
...@@ -2557,10 +2576,12 @@ angle::Result Renderer11::copyTexture(const gl::Context *context, ...@@ -2557,10 +2576,12 @@ angle::Result Renderer11::copyTexture(const gl::Context *context,
for (int i = 0; i < sourceBox.depth; i++) for (int i = 0; i < sourceBox.depth; i++)
{ {
gl::ImageIndex srcIndex = gl::ImageIndex::Make2DArray(sourceLevel, i + sourceBox.z); gl::ImageIndex sourceIndex =
UINT sourceSubresource = 0; gl::ImageIndex::Make2DArray(sourceLevel, i + sourceBox.z);
ANGLE_TRY( const TextureHelper11 *sourceResource = nullptr;
sourceStorage11->getSubresourceIndex(context, srcIndex, &sourceSubresource)); UINT sourceSubresource = 0;
ANGLE_TRY(GetTextureD3DResourceFromStorageOrImage(
context, sourceD3D, sourceIndex, &sourceResource, &sourceSubresource));
gl::ImageIndex dIndex = gl::ImageIndex::Make2DArray(destLevel, i + destOffset.z); gl::ImageIndex dIndex = gl::ImageIndex::Make2DArray(destLevel, i + destOffset.z);
UINT destSubresource = 0; UINT destSubresource = 0;
...@@ -2578,16 +2599,15 @@ angle::Result Renderer11::copyTexture(const gl::Context *context, ...@@ -2578,16 +2599,15 @@ angle::Result Renderer11::copyTexture(const gl::Context *context,
} }
else else
{ {
TextureStorage *sourceStorage = nullptr;
ANGLE_TRY(sourceD3D->getNativeTexture(context, &sourceStorage));
TextureStorage11 *sourceStorage11 = GetAs<TextureStorage11>(sourceStorage);
ASSERT(sourceStorage11);
const d3d11::SharedSRV *sourceSRV = nullptr; const d3d11::SharedSRV *sourceSRV = nullptr;
ANGLE_TRY(sourceStorage11->getSRVLevels(context, sourceLevel, sourceLevel, &sourceSRV)); ANGLE_TRY(sourceStorage11->getSRVLevels(context, sourceLevel, sourceLevel, &sourceSRV));
gl::Extents sourceSize(static_cast<int>(source->getWidth(
NonCubeTextureTypeToTarget(source->getType()), sourceLevel)),
static_cast<int>(source->getHeight(
NonCubeTextureTypeToTarget(source->getType()), sourceLevel)),
static_cast<int>(source->getDepth(
NonCubeTextureTypeToTarget(source->getType()), sourceLevel)));
gl::ImageIndex destIndex; gl::ImageIndex destIndex;
if (destTarget == gl::TextureTarget::_2D || destTarget == gl::TextureTarget::_3D || if (destTarget == gl::TextureTarget::_2D || destTarget == gl::TextureTarget::_3D ||
gl::IsCubeMapFaceTarget(destTarget)) gl::IsCubeMapFaceTarget(destTarget))
...@@ -2596,7 +2616,7 @@ angle::Result Renderer11::copyTexture(const gl::Context *context, ...@@ -2596,7 +2616,7 @@ angle::Result Renderer11::copyTexture(const gl::Context *context,
} }
else if (destTarget == gl::TextureTarget::_2DArray) else if (destTarget == gl::TextureTarget::_2DArray)
{ {
destIndex = gl::ImageIndex::Make2DArrayRange(destLevel, 0, sourceSize.depth); destIndex = gl::ImageIndex::Make2DArrayRange(destLevel, 0, sourceImageDesc.size.depth);
} }
else else
{ {
...@@ -2630,9 +2650,9 @@ angle::Result Renderer11::copyTexture(const gl::Context *context, ...@@ -2630,9 +2650,9 @@ angle::Result Renderer11::copyTexture(const gl::Context *context,
// Use nearest filtering because source and destination are the same size for the direct // Use nearest filtering because source and destination are the same size for the direct
// copy // copy
GLenum sourceFormat = source->getFormat(srcTarget, sourceLevel).info->format; GLenum sourceFormat = source->getFormat(srcTarget, sourceLevel).info->format;
ANGLE_TRY(mBlit->copyTexture(context, *sourceSRV, sourceArea, sourceSize, sourceFormat, ANGLE_TRY(mBlit->copyTexture(context, *sourceSRV, sourceArea, sourceImageDesc.size,
destRTV, destArea, destSize, nullptr, destFormat, destType, sourceFormat, destRTV, destArea, destSize, nullptr, destFormat,
GL_NEAREST, false, unpackPremultiplyAlpha, destType, GL_NEAREST, false, unpackPremultiplyAlpha,
unpackUnmultiplyAlpha)); unpackUnmultiplyAlpha));
} }
......
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