Commit f6b986c8 by Jiajia Qin Committed by Commit Bot

Refactor TextureStorage11

The CL includes below changes: 1. Change bool isAssociatedImageValid to void verifyAssociatedImageValid since we always required that the validation check should never be false. So ASSERT() is enough. Same to Image11::isAssociatedStorageValid->Image11::verifyAssociatedStorageValid. 2. Remove the unnecessary if checking after ASSERT 3. Use override instead of virtual if the function is virtual and is overriding a virtual function from the base class. BUG=angleproject:2006 Change-Id: I036666ae1ed4bfcaa8cef9e0e9626d375cd81a27 Reviewed-on: https://chromium-review.googlesource.com/480015Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent d22b8f72
...@@ -133,9 +133,9 @@ gl::Error Image11::copyToStorage(TextureStorage *storage, ...@@ -133,9 +133,9 @@ gl::Error Image11::copyToStorage(TextureStorage *storage,
return gl::NoError(); return gl::NoError();
} }
bool Image11::isAssociatedStorageValid(TextureStorage11 *textureStorage) const void Image11::verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const
{ {
return (mAssociatedStorage == textureStorage); ASSERT(mAssociatedStorage == textureStorage);
} }
gl::Error Image11::recoverFromAssociatedStorage() gl::Error Image11::recoverFromAssociatedStorage()
...@@ -144,22 +144,13 @@ gl::Error Image11::recoverFromAssociatedStorage() ...@@ -144,22 +144,13 @@ gl::Error Image11::recoverFromAssociatedStorage()
{ {
ANGLE_TRY(createStagingTexture()); ANGLE_TRY(createStagingTexture());
bool textureStorageCorrect = mAssociatedStorage->verifyAssociatedImageValid(mAssociatedImageIndex, this);
mAssociatedStorage->isAssociatedImageValid(mAssociatedImageIndex, this);
// This means that the cached TextureStorage has been modified after this Image11 released
// its copy of its data. This should not have happened. The TextureStorage should have told
// this Image11 to recover its data before it was overwritten.
ASSERT(textureStorageCorrect);
if (textureStorageCorrect)
{
// CopySubResource from the Storage to the Staging texture // CopySubResource from the Storage to the Staging texture
gl::Box region(0, 0, 0, mWidth, mHeight, mDepth); gl::Box region(0, 0, 0, mWidth, mHeight, mDepth);
ANGLE_TRY(mAssociatedStorage->copySubresourceLevel(mStagingTexture, mStagingSubresource, ANGLE_TRY(mAssociatedStorage->copySubresourceLevel(mStagingTexture, mStagingSubresource,
mAssociatedImageIndex, region)); mAssociatedImageIndex, region));
mRecoveredFromStorageCount += 1; mRecoveredFromStorageCount += 1;
}
// Reset all the recovery parameters, even if the texture storage association is broken. // Reset all the recovery parameters, even if the texture storage association is broken.
disassociateStorage(); disassociateStorage();
......
...@@ -58,7 +58,7 @@ class Image11 : public ImageD3D ...@@ -58,7 +58,7 @@ class Image11 : public ImageD3D
const gl::Framebuffer *source) override; const gl::Framebuffer *source) override;
gl::Error recoverFromAssociatedStorage(); gl::Error recoverFromAssociatedStorage();
bool isAssociatedStorageValid(TextureStorage11* textureStorage) const; void verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const;
void disassociateStorage(); void disassociateStorage();
protected: protected:
......
...@@ -778,11 +778,8 @@ TextureStorage11_2D::~TextureStorage11_2D() ...@@ -778,11 +778,8 @@ TextureStorage11_2D::~TextureStorage11_2D()
{ {
if (mAssociatedImages[i] != nullptr) if (mAssociatedImages[i] != nullptr)
{ {
bool imageAssociationCorrect = mAssociatedImages[i]->isAssociatedStorageValid(this); mAssociatedImages[i]->verifyAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// We must let the Images recover their data before we delete it from the // We must let the Images recover their data before we delete it from the
// TextureStorage. // TextureStorage.
gl::Error error = mAssociatedImages[i]->recoverFromAssociatedStorage(); gl::Error error = mAssociatedImages[i]->recoverFromAssociatedStorage();
...@@ -793,7 +790,6 @@ TextureStorage11_2D::~TextureStorage11_2D() ...@@ -793,7 +790,6 @@ TextureStorage11_2D::~TextureStorage11_2D()
} }
} }
} }
}
SafeRelease(mTexture); SafeRelease(mTexture);
SafeRelease(mSwizzleTexture); SafeRelease(mSwizzleTexture);
...@@ -925,21 +921,15 @@ void TextureStorage11_2D::associateImage(Image11 *image, const gl::ImageIndex &i ...@@ -925,21 +921,15 @@ void TextureStorage11_2D::associateImage(Image11 *image, const gl::ImageIndex &i
} }
} }
bool TextureStorage11_2D::isAssociatedImageValid(const gl::ImageIndex &index, void TextureStorage11_2D::verifyAssociatedImageValid(const gl::ImageIndex &index,
Image11 *expectedImage) Image11 *expectedImage)
{ {
const GLint level = index.mipIndex; const GLint level = index.mipIndex;
if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS);
{
// This validation check should never return false. It means the Image/TextureStorage // This validation check should never return false. It means the Image/TextureStorage
// association is broken. // association is broken.
bool retValue = (mAssociatedImages[level] == expectedImage); ASSERT(mAssociatedImages[level] == expectedImage);
ASSERT(retValue);
return retValue;
}
return false;
} }
// disassociateImage allows an Image to end its association with a Storage. // disassociateImage allows an Image to end its association with a Storage.
...@@ -948,16 +938,8 @@ void TextureStorage11_2D::disassociateImage(const gl::ImageIndex &index, Image11 ...@@ -948,16 +938,8 @@ void TextureStorage11_2D::disassociateImage(const gl::ImageIndex &index, Image11
const GLint level = index.mipIndex; const GLint level = index.mipIndex;
ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS);
if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
{
ASSERT(mAssociatedImages[level] == expectedImage); ASSERT(mAssociatedImages[level] == expectedImage);
if (mAssociatedImages[level] == expectedImage)
{
mAssociatedImages[level] = nullptr; mAssociatedImages[level] = nullptr;
}
}
} }
// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image // releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image
...@@ -974,19 +956,14 @@ gl::Error TextureStorage11_2D::releaseAssociatedImage(const gl::ImageIndex &inde ...@@ -974,19 +956,14 @@ gl::Error TextureStorage11_2D::releaseAssociatedImage(const gl::ImageIndex &inde
// No need to let the old Image recover its data, if it is also the incoming Image. // No need to let the old Image recover its data, if it is also the incoming Image.
if (mAssociatedImages[level] != nullptr && mAssociatedImages[level] != incomingImage) if (mAssociatedImages[level] != nullptr && mAssociatedImages[level] != incomingImage)
{ {
// Ensure that the Image is still associated with this TextureStorage. This should be // Ensure that the Image is still associated with this TextureStorage.
// true. mAssociatedImages[level]->verifyAssociatedStorageValid(this);
bool imageAssociationCorrect = mAssociatedImages[level]->isAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// Force the image to recover from storage before its data is overwritten. // Force the image to recover from storage before its data is overwritten.
// This will reset mAssociatedImages[level] to nullptr too. // This will reset mAssociatedImages[level] to nullptr too.
ANGLE_TRY(mAssociatedImages[level]->recoverFromAssociatedStorage()); ANGLE_TRY(mAssociatedImages[level]->recoverFromAssociatedStorage());
} }
} }
}
return gl::NoError(); return gl::NoError();
} }
...@@ -1398,10 +1375,10 @@ void TextureStorage11_External::associateImage(Image11 *image, const gl::ImageIn ...@@ -1398,10 +1375,10 @@ void TextureStorage11_External::associateImage(Image11 *image, const gl::ImageIn
mAssociatedImage = image; mAssociatedImage = image;
} }
bool TextureStorage11_External::isAssociatedImageValid(const gl::ImageIndex &index, void TextureStorage11_External::verifyAssociatedImageValid(const gl::ImageIndex &index,
Image11 *expectedImage) Image11 *expectedImage)
{ {
return (index.mipIndex == 0 && mAssociatedImage == expectedImage); ASSERT(index.mipIndex == 0 && mAssociatedImage == expectedImage);
} }
void TextureStorage11_External::disassociateImage(const gl::ImageIndex &index, void TextureStorage11_External::disassociateImage(const gl::ImageIndex &index,
...@@ -1419,14 +1396,10 @@ gl::Error TextureStorage11_External::releaseAssociatedImage(const gl::ImageIndex ...@@ -1419,14 +1396,10 @@ gl::Error TextureStorage11_External::releaseAssociatedImage(const gl::ImageIndex
if (mAssociatedImage != nullptr && mAssociatedImage != incomingImage) if (mAssociatedImage != nullptr && mAssociatedImage != incomingImage)
{ {
bool imageAssociationCorrect = mAssociatedImage->isAssociatedStorageValid(this); mAssociatedImage->verifyAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
ANGLE_TRY(mAssociatedImage->recoverFromAssociatedStorage()); ANGLE_TRY(mAssociatedImage->recoverFromAssociatedStorage());
} }
}
return gl::NoError(); return gl::NoError();
} }
...@@ -1592,9 +1565,8 @@ void TextureStorage11_EGLImage::disassociateImage(const gl::ImageIndex &, Image1 ...@@ -1592,9 +1565,8 @@ void TextureStorage11_EGLImage::disassociateImage(const gl::ImageIndex &, Image1
{ {
} }
bool TextureStorage11_EGLImage::isAssociatedImageValid(const gl::ImageIndex &, Image11 *) void TextureStorage11_EGLImage::verifyAssociatedImageValid(const gl::ImageIndex &, Image11 *)
{ {
return false;
} }
gl::Error TextureStorage11_EGLImage::releaseAssociatedImage(const gl::ImageIndex &, Image11 *) gl::Error TextureStorage11_EGLImage::releaseAssociatedImage(const gl::ImageIndex &, Image11 *)
...@@ -1804,19 +1776,14 @@ TextureStorage11_Cube::~TextureStorage11_Cube() ...@@ -1804,19 +1776,14 @@ TextureStorage11_Cube::~TextureStorage11_Cube()
{ {
if (mAssociatedImages[face][level] != nullptr) if (mAssociatedImages[face][level] != nullptr)
{ {
bool imageAssociationCorrect = mAssociatedImages[face][level]->verifyAssociatedStorageValid(this);
mAssociatedImages[face][level]->isAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// We must let the Images recover their data before we delete it from the // We must let the Images recover their data before we delete it from the
// TextureStorage. // TextureStorage.
mAssociatedImages[face][level]->recoverFromAssociatedStorage(); mAssociatedImages[face][level]->recoverFromAssociatedStorage();
} }
} }
} }
}
SafeRelease(mTexture); SafeRelease(mTexture);
SafeRelease(mSwizzleTexture); SafeRelease(mSwizzleTexture);
...@@ -1967,25 +1934,17 @@ void TextureStorage11_Cube::associateImage(Image11 *image, const gl::ImageIndex ...@@ -1967,25 +1934,17 @@ void TextureStorage11_Cube::associateImage(Image11 *image, const gl::ImageIndex
} }
} }
bool TextureStorage11_Cube::isAssociatedImageValid(const gl::ImageIndex &index, void TextureStorage11_Cube::verifyAssociatedImageValid(const gl::ImageIndex &index,
Image11 *expectedImage) Image11 *expectedImage)
{ {
const GLint level = index.mipIndex; const GLint level = index.mipIndex;
const GLint layerTarget = index.layerIndex; const GLint layerTarget = index.layerIndex;
if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS);
{ ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(CUBE_FACE_COUNT));
if (0 <= layerTarget && layerTarget < static_cast<GLint>(CUBE_FACE_COUNT))
{
// This validation check should never return false. It means the Image/TextureStorage // This validation check should never return false. It means the Image/TextureStorage
// association is broken. // association is broken.
bool retValue = (mAssociatedImages[layerTarget][level] == expectedImage); ASSERT(mAssociatedImages[layerTarget][level] == expectedImage);
ASSERT(retValue);
return retValue;
}
}
return false;
} }
// disassociateImage allows an Image to end its association with a Storage. // disassociateImage allows an Image to end its association with a Storage.
...@@ -1996,19 +1955,8 @@ void TextureStorage11_Cube::disassociateImage(const gl::ImageIndex &index, Image ...@@ -1996,19 +1955,8 @@ void TextureStorage11_Cube::disassociateImage(const gl::ImageIndex &index, Image
ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS);
ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(CUBE_FACE_COUNT)); ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(CUBE_FACE_COUNT));
if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
{
if (0 <= layerTarget && layerTarget < static_cast<GLint>(CUBE_FACE_COUNT))
{
ASSERT(mAssociatedImages[layerTarget][level] == expectedImage); ASSERT(mAssociatedImages[layerTarget][level] == expectedImage);
if (mAssociatedImages[layerTarget][level] == expectedImage)
{
mAssociatedImages[layerTarget][level] = nullptr; mAssociatedImages[layerTarget][level] = nullptr;
}
}
}
} }
// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image // releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image
...@@ -2030,19 +1978,12 @@ gl::Error TextureStorage11_Cube::releaseAssociatedImage(const gl::ImageIndex &in ...@@ -2030,19 +1978,12 @@ gl::Error TextureStorage11_Cube::releaseAssociatedImage(const gl::ImageIndex &in
if (mAssociatedImages[layerTarget][level] != nullptr && if (mAssociatedImages[layerTarget][level] != nullptr &&
mAssociatedImages[layerTarget][level] != incomingImage) mAssociatedImages[layerTarget][level] != incomingImage)
{ {
// Ensure that the Image is still associated with this TextureStorage. This should // Ensure that the Image is still associated with this TextureStorage.
// be true. mAssociatedImages[layerTarget][level]->verifyAssociatedStorageValid(this);
bool imageAssociationCorrect =
mAssociatedImages[layerTarget][level]->isAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// Force the image to recover from storage before its data is overwritten. // Force the image to recover from storage before its data is overwritten.
// This will reset mAssociatedImages[level] to nullptr too. // This will reset mAssociatedImages[level] to nullptr too.
ANGLE_TRY( ANGLE_TRY(mAssociatedImages[layerTarget][level]->recoverFromAssociatedStorage());
mAssociatedImages[layerTarget][level]->recoverFromAssociatedStorage());
}
} }
} }
} }
...@@ -2559,17 +2500,13 @@ TextureStorage11_3D::~TextureStorage11_3D() ...@@ -2559,17 +2500,13 @@ TextureStorage11_3D::~TextureStorage11_3D()
{ {
if (mAssociatedImages[i] != nullptr) if (mAssociatedImages[i] != nullptr)
{ {
bool imageAssociationCorrect = mAssociatedImages[i]->isAssociatedStorageValid(this); mAssociatedImages[i]->verifyAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// We must let the Images recover their data before we delete it from the // We must let the Images recover their data before we delete it from the
// TextureStorage. // TextureStorage.
mAssociatedImages[i]->recoverFromAssociatedStorage(); mAssociatedImages[i]->recoverFromAssociatedStorage();
} }
} }
}
SafeRelease(mTexture); SafeRelease(mTexture);
SafeRelease(mSwizzleTexture); SafeRelease(mSwizzleTexture);
...@@ -2600,21 +2537,15 @@ void TextureStorage11_3D::associateImage(Image11 *image, const gl::ImageIndex &i ...@@ -2600,21 +2537,15 @@ void TextureStorage11_3D::associateImage(Image11 *image, const gl::ImageIndex &i
} }
} }
bool TextureStorage11_3D::isAssociatedImageValid(const gl::ImageIndex &index, void TextureStorage11_3D::verifyAssociatedImageValid(const gl::ImageIndex &index,
Image11 *expectedImage) Image11 *expectedImage)
{ {
const GLint level = index.mipIndex; const GLint level = index.mipIndex;
if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS);
{
// This validation check should never return false. It means the Image/TextureStorage // This validation check should never return false. It means the Image/TextureStorage
// association is broken. // association is broken.
bool retValue = (mAssociatedImages[level] == expectedImage); ASSERT(mAssociatedImages[level] == expectedImage);
ASSERT(retValue);
return retValue;
}
return false;
} }
// disassociateImage allows an Image to end its association with a Storage. // disassociateImage allows an Image to end its association with a Storage.
...@@ -2623,16 +2554,8 @@ void TextureStorage11_3D::disassociateImage(const gl::ImageIndex &index, Image11 ...@@ -2623,16 +2554,8 @@ void TextureStorage11_3D::disassociateImage(const gl::ImageIndex &index, Image11
const GLint level = index.mipIndex; const GLint level = index.mipIndex;
ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS);
if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
{
ASSERT(mAssociatedImages[level] == expectedImage); ASSERT(mAssociatedImages[level] == expectedImage);
if (mAssociatedImages[level] == expectedImage)
{
mAssociatedImages[level] = nullptr; mAssociatedImages[level] = nullptr;
}
}
} }
// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image // releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image
...@@ -2649,19 +2572,14 @@ gl::Error TextureStorage11_3D::releaseAssociatedImage(const gl::ImageIndex &inde ...@@ -2649,19 +2572,14 @@ gl::Error TextureStorage11_3D::releaseAssociatedImage(const gl::ImageIndex &inde
// No need to let the old Image recover its data, if it is also the incoming Image. // No need to let the old Image recover its data, if it is also the incoming Image.
if (mAssociatedImages[level] != nullptr && mAssociatedImages[level] != incomingImage) if (mAssociatedImages[level] != nullptr && mAssociatedImages[level] != incomingImage)
{ {
// Ensure that the Image is still associated with this TextureStorage. This should be // Ensure that the Image is still associated with this TextureStorage.
// true. mAssociatedImages[level]->verifyAssociatedStorageValid(this);
bool imageAssociationCorrect = mAssociatedImages[level]->isAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// Force the image to recover from storage before its data is overwritten. // Force the image to recover from storage before its data is overwritten.
// This will reset mAssociatedImages[level] to nullptr too. // This will reset mAssociatedImages[level] to nullptr too.
ANGLE_TRY(mAssociatedImages[level]->recoverFromAssociatedStorage()); ANGLE_TRY(mAssociatedImages[level]->recoverFromAssociatedStorage());
} }
} }
}
return gl::NoError(); return gl::NoError();
} }
...@@ -2961,17 +2879,13 @@ TextureStorage11_2DArray::~TextureStorage11_2DArray() ...@@ -2961,17 +2879,13 @@ TextureStorage11_2DArray::~TextureStorage11_2DArray()
{ {
if (i->second) if (i->second)
{ {
bool imageAssociationCorrect = i->second->isAssociatedStorageValid(this); i->second->verifyAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// We must let the Images recover their data before we delete it from the // We must let the Images recover their data before we delete it from the
// TextureStorage. // TextureStorage.
i->second->recoverFromAssociatedStorage(); i->second->recoverFromAssociatedStorage();
} }
} }
}
mAssociatedImages.clear(); mAssociatedImages.clear();
SafeRelease(mTexture); SafeRelease(mTexture);
...@@ -3003,7 +2917,7 @@ void TextureStorage11_2DArray::associateImage(Image11 *image, const gl::ImageInd ...@@ -3003,7 +2917,7 @@ void TextureStorage11_2DArray::associateImage(Image11 *image, const gl::ImageInd
} }
} }
bool TextureStorage11_2DArray::isAssociatedImageValid(const gl::ImageIndex &index, void TextureStorage11_2DArray::verifyAssociatedImageValid(const gl::ImageIndex &index,
Image11 *expectedImage) Image11 *expectedImage)
{ {
const GLint level = index.mipIndex; const GLint level = index.mipIndex;
...@@ -3016,7 +2930,6 @@ bool TextureStorage11_2DArray::isAssociatedImageValid(const gl::ImageIndex &inde ...@@ -3016,7 +2930,6 @@ bool TextureStorage11_2DArray::isAssociatedImageValid(const gl::ImageIndex &inde
bool retValue = (mAssociatedImages.find(key) != mAssociatedImages.end() && bool retValue = (mAssociatedImages.find(key) != mAssociatedImages.end() &&
(mAssociatedImages[key] == expectedImage)); (mAssociatedImages[key] == expectedImage));
ASSERT(retValue); ASSERT(retValue);
return retValue;
} }
// disassociateImage allows an Image to end its association with a Storage. // disassociateImage allows an Image to end its association with a Storage.
...@@ -3031,11 +2944,7 @@ void TextureStorage11_2DArray::disassociateImage(const gl::ImageIndex &index, ...@@ -3031,11 +2944,7 @@ void TextureStorage11_2DArray::disassociateImage(const gl::ImageIndex &index,
bool imageAssociationCorrect = (mAssociatedImages.find(key) != mAssociatedImages.end() && bool imageAssociationCorrect = (mAssociatedImages.find(key) != mAssociatedImages.end() &&
(mAssociatedImages[key] == expectedImage)); (mAssociatedImages[key] == expectedImage));
ASSERT(imageAssociationCorrect); ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
mAssociatedImages[key] = nullptr; mAssociatedImages[key] = nullptr;
}
} }
// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image // releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image
...@@ -3052,19 +2961,14 @@ gl::Error TextureStorage11_2DArray::releaseAssociatedImage(const gl::ImageIndex ...@@ -3052,19 +2961,14 @@ gl::Error TextureStorage11_2DArray::releaseAssociatedImage(const gl::ImageIndex
{ {
if (mAssociatedImages[key] != nullptr && mAssociatedImages[key] != incomingImage) if (mAssociatedImages[key] != nullptr && mAssociatedImages[key] != incomingImage)
{ {
// Ensure that the Image is still associated with this TextureStorage. This should be // Ensure that the Image is still associated with this TextureStorage.
// true. mAssociatedImages[key]->verifyAssociatedStorageValid(this);
bool imageAssociationCorrect = mAssociatedImages[key]->isAssociatedStorageValid(this);
ASSERT(imageAssociationCorrect);
if (imageAssociationCorrect)
{
// Force the image to recover from storage before its data is overwritten. // Force the image to recover from storage before its data is overwritten.
// This will reset mAssociatedImages[level] to nullptr too. // This will reset mAssociatedImages[level] to nullptr too.
ANGLE_TRY(mAssociatedImages[key]->recoverFromAssociatedStorage()); ANGLE_TRY(mAssociatedImages[key]->recoverFromAssociatedStorage());
} }
} }
}
return gl::NoError(); return gl::NoError();
} }
......
...@@ -36,28 +36,15 @@ struct Renderer11DeviceCaps; ...@@ -36,28 +36,15 @@ struct Renderer11DeviceCaps;
class TextureStorage11 : public TextureStorage class TextureStorage11 : public TextureStorage
{ {
public: public:
virtual ~TextureStorage11(); ~TextureStorage11() override;
static DWORD GetTextureBindFlags(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps, bool renderTarget); static DWORD GetTextureBindFlags(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps, bool renderTarget);
static DWORD GetTextureMiscFlags(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps, bool renderTarget, int levels); static DWORD GetTextureMiscFlags(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps, bool renderTarget, int levels);
UINT getBindFlags() const; UINT getBindFlags() const;
UINT getMiscFlags() const; UINT getMiscFlags() const;
const d3d11::Format &getFormatSet() const;
virtual gl::Error getResource(ID3D11Resource **outResource) = 0; gl::Error getSRVLevels(GLint baseLevel, GLint maxLevel, ID3D11ShaderResourceView **outSRV);
virtual gl::Error getSRV(const gl::TextureState &textureState,
ID3D11ShaderResourceView **outSRV);
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT) = 0;
virtual gl::Error generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual int getTopLevel() const;
virtual bool isRenderTarget() const;
virtual bool isManaged() const;
bool supportsNativeMipmapFunction() const override;
virtual int getLevelCount() const;
virtual UINT getSubresourceIndex(const gl::ImageIndex &index) const;
gl::Error generateSwizzles(const gl::SwizzleState &swizzleTarget); gl::Error generateSwizzles(const gl::SwizzleState &swizzleTarget);
void markLevelDirty(int mipLevel); void markLevelDirty(int mipLevel);
void markDirty(); void markDirty();
...@@ -68,19 +55,32 @@ class TextureStorage11 : public TextureStorage ...@@ -68,19 +55,32 @@ class TextureStorage11 : public TextureStorage
gl::Error copySubresourceLevel(ID3D11Resource* dstTexture, unsigned int dstSubresource, gl::Error copySubresourceLevel(ID3D11Resource* dstTexture, unsigned int dstSubresource,
const gl::ImageIndex &index, const gl::Box &region); const gl::ImageIndex &index, const gl::Box &region);
// TextureStorage virtual functions
int getTopLevel() const override;
bool isRenderTarget() const override;
bool isManaged() const override;
bool supportsNativeMipmapFunction() const override;
int getLevelCount() const override;
gl::Error generateMipmap(const gl::ImageIndex &sourceIndex,
const gl::ImageIndex &destIndex) override;
gl::Error copyToStorage(TextureStorage *destStorage) override;
gl::Error setData(const gl::ImageIndex &index,
ImageD3D *image,
const gl::Box *destBox,
GLenum type,
const gl::PixelUnpackState &unpack,
const uint8_t *pixelData) override;
virtual gl::Error getSRV(const gl::TextureState &textureState,
ID3D11ShaderResourceView **outSRV);
virtual UINT getSubresourceIndex(const gl::ImageIndex &index) const;
virtual gl::Error getResource(ID3D11Resource **outResource) = 0;
virtual void associateImage(Image11* image, const gl::ImageIndex &index) = 0; virtual void associateImage(Image11* image, const gl::ImageIndex &index) = 0;
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage) = 0; virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage) = 0;
virtual bool isAssociatedImageValid(const gl::ImageIndex &index, Image11* expectedImage) = 0; virtual void verifyAssociatedImageValid(const gl::ImageIndex &index,
Image11 *expectedImage) = 0;
virtual gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11* incomingImage) = 0; virtual gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11* incomingImage) = 0;
virtual gl::Error copyToStorage(TextureStorage *destStorage);
virtual gl::Error setData(const gl::ImageIndex &index, ImageD3D *image, const gl::Box *destBox, GLenum type,
const gl::PixelUnpackState &unpack, const uint8_t *pixelData);
gl::Error getSRVLevels(GLint baseLevel, GLint maxLevel, ID3D11ShaderResourceView **outSRV);
const d3d11::Format &getFormatSet() const;
protected: protected:
TextureStorage11(Renderer11 *renderer, UINT bindFlags, UINT miscFlags, GLenum internalFormat); TextureStorage11(Renderer11 *renderer, UINT bindFlags, UINT miscFlags, GLenum internalFormat);
int getLevelWidth(int mipLevel) const; int getLevelWidth(int mipLevel) const;
...@@ -163,7 +163,7 @@ class TextureStorage11_2D : public TextureStorage11 ...@@ -163,7 +163,7 @@ class TextureStorage11_2D : public TextureStorage11
void associateImage(Image11 *image, const gl::ImageIndex &index) override; void associateImage(Image11 *image, const gl::ImageIndex &index) override;
void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override;
bool isAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override;
gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override; gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override;
gl::Error useLevelZeroWorkaroundTexture(bool useLevelZeroTexture) override; gl::Error useLevelZeroWorkaroundTexture(bool useLevelZeroTexture) override;
...@@ -223,7 +223,7 @@ class TextureStorage11_External : public TextureStorage11 ...@@ -223,7 +223,7 @@ class TextureStorage11_External : public TextureStorage11
void associateImage(Image11 *image, const gl::ImageIndex &index) override; void associateImage(Image11 *image, const gl::ImageIndex &index) override;
void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override;
bool isAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override;
gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override; gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override;
protected: protected:
...@@ -262,7 +262,7 @@ class TextureStorage11_EGLImage final : public TextureStorage11 ...@@ -262,7 +262,7 @@ class TextureStorage11_EGLImage final : public TextureStorage11
void associateImage(Image11 *image, const gl::ImageIndex &index) override; void associateImage(Image11 *image, const gl::ImageIndex &index) override;
void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override;
bool isAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override;
gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override; gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override;
gl::Error useLevelZeroWorkaroundTexture(bool useLevelZeroTexture) override; gl::Error useLevelZeroWorkaroundTexture(bool useLevelZeroTexture) override;
...@@ -296,34 +296,37 @@ class TextureStorage11_Cube : public TextureStorage11 ...@@ -296,34 +296,37 @@ class TextureStorage11_Cube : public TextureStorage11
{ {
public: public:
TextureStorage11_Cube(Renderer11 *renderer, GLenum internalformat, bool renderTarget, int size, int levels, bool hintLevelZeroOnly); TextureStorage11_Cube(Renderer11 *renderer, GLenum internalformat, bool renderTarget, int size, int levels, bool hintLevelZeroOnly);
virtual ~TextureStorage11_Cube(); ~TextureStorage11_Cube() override;
virtual UINT getSubresourceIndex(const gl::ImageIndex &index) const; UINT getSubresourceIndex(const gl::ImageIndex &index) const override;
virtual gl::Error getResource(ID3D11Resource **outResource); gl::Error getResource(ID3D11Resource **outResource) override;
virtual gl::Error getMippedResource(ID3D11Resource **outResource); gl::Error getMippedResource(ID3D11Resource **outResource) override;
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT); gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT) override;
virtual gl::Error copyToStorage(TextureStorage *destStorage); gl::Error copyToStorage(TextureStorage *destStorage) override;
virtual void associateImage(Image11* image, const gl::ImageIndex &index); void associateImage(Image11 *image, const gl::ImageIndex &index) override;
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override;
virtual bool isAssociatedImageValid(const gl::ImageIndex &index, Image11* expectedImage); void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override;
virtual gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11* incomingImage); gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override;
virtual gl::Error useLevelZeroWorkaroundTexture(bool useLevelZeroTexture); gl::Error useLevelZeroWorkaroundTexture(bool useLevelZeroTexture) override;
protected: protected:
virtual gl::Error getSwizzleTexture(ID3D11Resource **outTexture); gl::Error getSwizzleTexture(ID3D11Resource **outTexture) override;
virtual gl::Error getSwizzleRenderTarget(int mipLevel, ID3D11RenderTargetView **outRTV); gl::Error getSwizzleRenderTarget(int mipLevel, ID3D11RenderTargetView **outRTV) override;
gl::ErrorOrResult<DropStencil> ensureDropStencilTexture() override; gl::ErrorOrResult<DropStencil> ensureDropStencilTexture() override;
gl::Error ensureTextureExists(int mipLevels); gl::Error ensureTextureExists(int mipLevels);
private: private:
virtual gl::Error createSRV(int baseLevel, int mipLevels, DXGI_FORMAT format, ID3D11Resource *texture, gl::Error createSRV(int baseLevel,
ID3D11ShaderResourceView **outSRV) const; int mipLevels,
DXGI_FORMAT format,
ID3D11Resource *texture,
ID3D11ShaderResourceView **outSRV) const override;
gl::Error createRenderTargetSRV(ID3D11Resource *texture, gl::Error createRenderTargetSRV(ID3D11Resource *texture,
const gl::ImageIndex &index, const gl::ImageIndex &index,
DXGI_FORMAT resourceFormat, DXGI_FORMAT resourceFormat,
...@@ -350,25 +353,28 @@ class TextureStorage11_3D : public TextureStorage11 ...@@ -350,25 +353,28 @@ class TextureStorage11_3D : public TextureStorage11
public: public:
TextureStorage11_3D(Renderer11 *renderer, GLenum internalformat, bool renderTarget, TextureStorage11_3D(Renderer11 *renderer, GLenum internalformat, bool renderTarget,
GLsizei width, GLsizei height, GLsizei depth, int levels); GLsizei width, GLsizei height, GLsizei depth, int levels);
virtual ~TextureStorage11_3D(); ~TextureStorage11_3D() override;
virtual gl::Error getResource(ID3D11Resource **outResource); gl::Error getResource(ID3D11Resource **outResource) override;
// Handles both layer and non-layer RTs // Handles both layer and non-layer RTs
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT); gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT) override;
virtual void associateImage(Image11* image, const gl::ImageIndex &index); void associateImage(Image11 *image, const gl::ImageIndex &index) override;
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override;
virtual bool isAssociatedImageValid(const gl::ImageIndex &index, Image11* expectedImage); void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override;
virtual gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11* incomingImage); gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override;
protected: protected:
virtual gl::Error getSwizzleTexture(ID3D11Resource **outTexture); gl::Error getSwizzleTexture(ID3D11Resource **outTexture) override;
virtual gl::Error getSwizzleRenderTarget(int mipLevel, ID3D11RenderTargetView **outRTV); gl::Error getSwizzleRenderTarget(int mipLevel, ID3D11RenderTargetView **outRTV) override;
private: private:
virtual gl::Error createSRV(int baseLevel, int mipLevels, DXGI_FORMAT format, ID3D11Resource *texture, gl::Error createSRV(int baseLevel,
ID3D11ShaderResourceView **outSRV) const; int mipLevels,
DXGI_FORMAT format,
ID3D11Resource *texture,
ID3D11ShaderResourceView **outSRV) const override;
typedef std::pair<int, int> LevelLayerKey; typedef std::pair<int, int> LevelLayerKey;
typedef std::map<LevelLayerKey, RenderTarget11*> RenderTargetMap; typedef std::map<LevelLayerKey, RenderTarget11*> RenderTargetMap;
...@@ -388,25 +394,28 @@ class TextureStorage11_2DArray : public TextureStorage11 ...@@ -388,25 +394,28 @@ class TextureStorage11_2DArray : public TextureStorage11
public: public:
TextureStorage11_2DArray(Renderer11 *renderer, GLenum internalformat, bool renderTarget, TextureStorage11_2DArray(Renderer11 *renderer, GLenum internalformat, bool renderTarget,
GLsizei width, GLsizei height, GLsizei depth, int levels); GLsizei width, GLsizei height, GLsizei depth, int levels);
virtual ~TextureStorage11_2DArray(); ~TextureStorage11_2DArray() override;
virtual gl::Error getResource(ID3D11Resource **outResource); gl::Error getResource(ID3D11Resource **outResource) override;
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT); gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTargetD3D **outRT) override;
virtual void associateImage(Image11* image, const gl::ImageIndex &index); void associateImage(Image11 *image, const gl::ImageIndex &index) override;
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override;
virtual bool isAssociatedImageValid(const gl::ImageIndex &index, Image11* expectedImage); void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override;
virtual gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11* incomingImage); gl::Error releaseAssociatedImage(const gl::ImageIndex &index, Image11 *incomingImage) override;
protected: protected:
virtual gl::Error getSwizzleTexture(ID3D11Resource **outTexture); gl::Error getSwizzleTexture(ID3D11Resource **outTexture) override;
virtual gl::Error getSwizzleRenderTarget(int mipLevel, ID3D11RenderTargetView **outRTV); gl::Error getSwizzleRenderTarget(int mipLevel, ID3D11RenderTargetView **outRTV) override;
gl::ErrorOrResult<DropStencil> ensureDropStencilTexture() override; gl::ErrorOrResult<DropStencil> ensureDropStencilTexture() override;
private: private:
virtual gl::Error createSRV(int baseLevel, int mipLevels, DXGI_FORMAT format, ID3D11Resource *texture, gl::Error createSRV(int baseLevel,
ID3D11ShaderResourceView **outSRV) const; int mipLevels,
DXGI_FORMAT format,
ID3D11Resource *texture,
ID3D11ShaderResourceView **outSRV) const override;
gl::Error createRenderTargetSRV(ID3D11Resource *texture, gl::Error createRenderTargetSRV(ID3D11Resource *texture,
const gl::ImageIndex &index, const gl::ImageIndex &index,
DXGI_FORMAT resourceFormat, DXGI_FORMAT resourceFormat,
......
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