Commit 22416868 by Geoff Lang Committed by Commit Bot

Add dirty bits for internal texture state.

Synchronize TextureGL internal state using the dirty bits. TexturesBenchmark scores: Before: 5051 After: 7639 Diff: +51.2% BUG=angleproject:1386 Change-Id: Id04aef778a47175d1a284564495a646045855b4b Reviewed-on: https://chromium-review.googlesource.com/393866 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 47110bf4
......@@ -516,6 +516,7 @@ Texture::~Texture()
void Texture::setLabel(const std::string &label)
{
mLabel = label;
mDirtyBits.set(DIRTY_BIT_LABEL);
}
const std::string &Texture::getLabel() const
......@@ -531,6 +532,7 @@ GLenum Texture::getTarget() const
void Texture::setSwizzleRed(GLenum swizzleRed)
{
mState.mSwizzleState.swizzleRed = swizzleRed;
mDirtyBits.set(DIRTY_BIT_SWIZZLE_RED);
}
GLenum Texture::getSwizzleRed() const
......@@ -541,6 +543,7 @@ GLenum Texture::getSwizzleRed() const
void Texture::setSwizzleGreen(GLenum swizzleGreen)
{
mState.mSwizzleState.swizzleGreen = swizzleGreen;
mDirtyBits.set(DIRTY_BIT_SWIZZLE_GREEN);
}
GLenum Texture::getSwizzleGreen() const
......@@ -551,6 +554,7 @@ GLenum Texture::getSwizzleGreen() const
void Texture::setSwizzleBlue(GLenum swizzleBlue)
{
mState.mSwizzleState.swizzleBlue = swizzleBlue;
mDirtyBits.set(DIRTY_BIT_SWIZZLE_BLUE);
}
GLenum Texture::getSwizzleBlue() const
......@@ -561,6 +565,7 @@ GLenum Texture::getSwizzleBlue() const
void Texture::setSwizzleAlpha(GLenum swizzleAlpha)
{
mState.mSwizzleState.swizzleAlpha = swizzleAlpha;
mDirtyBits.set(DIRTY_BIT_SWIZZLE_ALPHA);
}
GLenum Texture::getSwizzleAlpha() const
......@@ -571,6 +576,7 @@ GLenum Texture::getSwizzleAlpha() const
void Texture::setMinFilter(GLenum minFilter)
{
mState.mSamplerState.minFilter = minFilter;
mDirtyBits.set(DIRTY_BIT_MIN_FILTER);
}
GLenum Texture::getMinFilter() const
......@@ -581,6 +587,7 @@ GLenum Texture::getMinFilter() const
void Texture::setMagFilter(GLenum magFilter)
{
mState.mSamplerState.magFilter = magFilter;
mDirtyBits.set(DIRTY_BIT_MAG_FILTER);
}
GLenum Texture::getMagFilter() const
......@@ -591,6 +598,7 @@ GLenum Texture::getMagFilter() const
void Texture::setWrapS(GLenum wrapS)
{
mState.mSamplerState.wrapS = wrapS;
mDirtyBits.set(DIRTY_BIT_WRAP_S);
}
GLenum Texture::getWrapS() const
......@@ -601,6 +609,7 @@ GLenum Texture::getWrapS() const
void Texture::setWrapT(GLenum wrapT)
{
mState.mSamplerState.wrapT = wrapT;
mDirtyBits.set(DIRTY_BIT_WRAP_T);
}
GLenum Texture::getWrapT() const
......@@ -611,6 +620,7 @@ GLenum Texture::getWrapT() const
void Texture::setWrapR(GLenum wrapR)
{
mState.mSamplerState.wrapR = wrapR;
mDirtyBits.set(DIRTY_BIT_WRAP_R);
}
GLenum Texture::getWrapR() const
......@@ -621,6 +631,7 @@ GLenum Texture::getWrapR() const
void Texture::setMaxAnisotropy(float maxAnisotropy)
{
mState.mSamplerState.maxAnisotropy = maxAnisotropy;
mDirtyBits.set(DIRTY_BIT_MAX_ANISOTROPY);
}
float Texture::getMaxAnisotropy() const
......@@ -631,6 +642,7 @@ float Texture::getMaxAnisotropy() const
void Texture::setMinLod(GLfloat minLod)
{
mState.mSamplerState.minLod = minLod;
mDirtyBits.set(DIRTY_BIT_MIN_LOD);
}
GLfloat Texture::getMinLod() const
......@@ -641,6 +653,7 @@ GLfloat Texture::getMinLod() const
void Texture::setMaxLod(GLfloat maxLod)
{
mState.mSamplerState.maxLod = maxLod;
mDirtyBits.set(DIRTY_BIT_MAX_LOD);
}
GLfloat Texture::getMaxLod() const
......@@ -651,6 +664,7 @@ GLfloat Texture::getMaxLod() const
void Texture::setCompareMode(GLenum compareMode)
{
mState.mSamplerState.compareMode = compareMode;
mDirtyBits.set(DIRTY_BIT_COMPARE_MODE);
}
GLenum Texture::getCompareMode() const
......@@ -661,6 +675,7 @@ GLenum Texture::getCompareMode() const
void Texture::setCompareFunc(GLenum compareFunc)
{
mState.mSamplerState.compareFunc = compareFunc;
mDirtyBits.set(DIRTY_BIT_COMPARE_FUNC);
}
GLenum Texture::getCompareFunc() const
......@@ -678,6 +693,7 @@ void Texture::setBaseLevel(GLuint baseLevel)
if (mState.setBaseLevel(baseLevel))
{
mTexture->setBaseLevel(mState.getEffectiveBaseLevel());
mDirtyBits.set(DIRTY_BIT_BASE_LEVEL);
}
}
......@@ -689,6 +705,7 @@ GLuint Texture::getBaseLevel() const
void Texture::setMaxLevel(GLuint maxLevel)
{
mState.setMaxLevel(maxLevel);
mDirtyBits.set(DIRTY_BIT_MAX_LEVEL);
}
GLuint Texture::getMaxLevel() const
......@@ -709,6 +726,7 @@ GLuint Texture::getImmutableLevels() const
void Texture::setUsage(GLenum usage)
{
mState.mUsage = usage;
mDirtyBits.set(DIRTY_BIT_USAGE);
}
GLenum Texture::getUsage() const
......@@ -932,6 +950,14 @@ Error Texture::setStorage(GLenum target, GLsizei levels, GLenum internalFormat,
mState.mImmutableLevels = static_cast<GLuint>(levels);
mState.clearImageDescs();
mState.setImageDescChain(0, static_cast<GLuint>(levels - 1), size, Format(internalFormat));
// Changing the texture to immutable can trigger a change in the base and max levels:
// GLES 3.0.4 section 3.8.10 pg 158:
// "For immutable-format textures, levelbase is clamped to the range[0;levels],levelmax is then
// clamped to the range[levelbase;levels].
mDirtyBits.set(DIRTY_BIT_BASE_LEVEL);
mDirtyBits.set(DIRTY_BIT_MAX_LEVEL);
mDirtyChannel.signal();
return NoError();
......@@ -954,6 +980,7 @@ Error Texture::generateMipmap()
if (maxLevel > baseLevel)
{
syncImplState();
ANGLE_TRY(mTexture->generateMipmap());
const ImageDesc &baseImageInfo =
......@@ -1102,6 +1129,15 @@ GLuint Texture::getId() const
return id();
}
void Texture::syncImplState()
{
if (mDirtyBits.any())
{
mTexture->syncState(mDirtyBits);
mDirtyBits.reset();
}
}
rx::FramebufferAttachmentObjectImpl *Texture::getAttachmentImpl() const
{
return mTexture;
......
......@@ -317,6 +317,39 @@ class Texture final : public egl::ImageSibling,
void onDetach() override;
GLuint getId() const override;
enum DirtyBitType
{
// Sampler state
DIRTY_BIT_MIN_FILTER,
DIRTY_BIT_MAG_FILTER,
DIRTY_BIT_WRAP_S,
DIRTY_BIT_WRAP_T,
DIRTY_BIT_WRAP_R,
DIRTY_BIT_MAX_ANISOTROPY,
DIRTY_BIT_MIN_LOD,
DIRTY_BIT_MAX_LOD,
DIRTY_BIT_COMPARE_MODE,
DIRTY_BIT_COMPARE_FUNC,
// Texture state
DIRTY_BIT_SWIZZLE_RED,
DIRTY_BIT_SWIZZLE_GREEN,
DIRTY_BIT_SWIZZLE_BLUE,
DIRTY_BIT_SWIZZLE_ALPHA,
DIRTY_BIT_BASE_LEVEL,
DIRTY_BIT_MAX_LEVEL,
// Misc
DIRTY_BIT_LABEL,
DIRTY_BIT_USAGE,
DIRTY_BIT_COUNT,
};
using DirtyBits = std::bitset<DIRTY_BIT_COUNT>;
void syncImplState();
bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
private:
rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override;
......@@ -333,6 +366,7 @@ class Texture final : public egl::ImageSibling,
void releaseImageFromStream();
TextureState mState;
DirtyBits mDirtyBits;
rx::TextureImpl *mTexture;
std::string mLabel;
......
......@@ -16,6 +16,7 @@
#include "libANGLE/Error.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/Stream.h"
#include "libANGLE/Texture.h"
#include "libANGLE/renderer/FramebufferAttachmentObjectImpl.h"
namespace egl
......@@ -89,6 +90,8 @@ class TextureImpl : public FramebufferAttachmentObjectImpl
virtual void bindTexImage(egl::Surface *surface) = 0;
virtual void releaseTexImage() = 0;
virtual void syncState(const gl::Texture::DirtyBits &dirtyBits) = 0;
protected:
const gl::TextureState &mState;
};
......
......@@ -48,6 +48,8 @@ class MockTextureImpl : public TextureImpl
MOCK_METHOD1(setBaseLevel, void(GLuint));
MOCK_METHOD1(syncState, void(const gl::Texture::DirtyBits &));
MOCK_METHOD0(destructor, void());
};
......
......@@ -663,6 +663,11 @@ void TextureD3D::setBaseLevel(GLuint baseLevel)
}
}
void TextureD3D::syncState(const gl::Texture::DirtyBits &dirtyBits)
{
// TODO(geofflang): Use dirty bits
}
TextureD3D_2D::TextureD3D_2D(const gl::TextureState &state, RendererD3D *renderer)
: TextureD3D(state, renderer)
{
......
......@@ -69,6 +69,8 @@ class TextureD3D : public TextureImpl
void setBaseLevel(GLuint baseLevel) override;
void syncState(const gl::Texture::DirtyBits &dirtyBits) override;
protected:
gl::Error setImageImpl(const gl::ImageIndex &index,
GLenum type,
......
......@@ -743,18 +743,21 @@ gl::Error StateManagerGL::setGenericDrawState(const gl::ContextState &data)
GLenum textureType = samplerUniform.textureType;
for (GLuint textureUnitIndex : samplerUniform.boundTextureUnits)
{
const gl::Texture *texture = state.getSamplerTexture(textureUnitIndex, textureType);
gl::Texture *texture = state.getSamplerTexture(textureUnitIndex, textureType);
if (texture != nullptr)
{
const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID() ||
texture->hasAnyDirtyBit())
{
activeTexture(textureUnitIndex);
bindTexture(textureType, textureGL->getTextureID());
}
textureGL->syncState(textureUnitIndex);
// TODO: Call this from the gl:: layer once other backends use dirty bits for
// texture state.
texture->syncImplState();
}
}
else
{
......
......@@ -87,11 +87,12 @@ class TextureGL : public TextureImpl
gl::Error setEGLImageTarget(GLenum target, egl::Image *image) override;
void syncState(size_t textureUnit) const;
GLuint getTextureID() const;
void setBaseLevel(GLuint) override {}
void syncState(const gl::Texture::DirtyBits &dirtyBits) override;
private:
void setImageHelper(GLenum target,
size_t level,
......@@ -122,12 +123,17 @@ class TextureGL : public TextureImpl
const gl::PixelUnpackState &unpack,
const uint8_t *pixels);
void syncTextureStateSwizzle(const FunctionsGL *functions, GLenum name, GLenum value);
void setLevelInfo(size_t level, size_t levelCount, const LevelInfoGL &levelInfo);
const FunctionsGL *mFunctions;
const WorkaroundsGL &mWorkarounds;
StateManagerGL *mStateManager;
BlitGL *mBlitter;
std::vector<LevelInfoGL> mLevelInfo;
gl::Texture::DirtyBits mLocalDirtyBits;
mutable gl::TextureState mAppliedTextureState;
GLuint mTextureID;
......
......@@ -135,4 +135,9 @@ void TextureNULL::releaseTexImage()
UNIMPLEMENTED();
}
void TextureNULL::syncState(const gl::Texture::DirtyBits &dirtyBits)
{
UNIMPLEMENTED();
}
} // namespace rx
......@@ -80,6 +80,8 @@ class TextureNULL : public TextureImpl
void bindTexImage(egl::Surface *surface) override;
void releaseTexImage() override;
void syncState(const gl::Texture::DirtyBits &dirtyBits) override;
};
} // namespace rx
......
......@@ -142,4 +142,9 @@ gl::Error TextureVk::getAttachmentRenderTarget(const gl::FramebufferAttachment::
return gl::Error(GL_INVALID_OPERATION);
}
void TextureVk::syncState(const gl::Texture::DirtyBits &dirtyBits)
{
UNIMPLEMENTED();
}
} // namespace rx
......@@ -83,6 +83,8 @@ class TextureVk : public TextureImpl
gl::Error getAttachmentRenderTarget(const gl::FramebufferAttachment::Target &target,
FramebufferAttachmentRenderTarget **rtOut) override;
void syncState(const gl::Texture::DirtyBits &dirtyBits) override;
};
} // namespace rx
......
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