Commit b1eb44bf by Jamie Madill Committed by Commit Bot

Track if a Texture is bound as a sampler.

This will more easily allow us to detect rendering feedback loops. We'll need to support feedback loops to enable Manhattan. Bug: angleproject:4490 Change-Id: I442deebd89dcf0139411688eaa204c5e5b2c2799 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2109334 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent baecb7d5
...@@ -544,16 +544,36 @@ void State::reset(const Context *context) ...@@ -544,16 +544,36 @@ void State::reset(const Context *context)
setAllDirtyBits(); setAllDirtyBits();
} }
ANGLE_INLINE void State::unsetActiveTexture(size_t textureIndex)
{
if (mActiveTexturesCache[textureIndex])
{
mActiveTexturesCache[textureIndex]->onUnbindAsSamplerTexture();
mActiveTexturesCache[textureIndex] = nullptr;
}
}
ANGLE_INLINE void State::unsetActiveTextures(ActiveTextureMask textureMask) ANGLE_INLINE void State::unsetActiveTextures(ActiveTextureMask textureMask)
{ {
// Unset any relevant bound textures. // Unset any relevant bound textures.
for (size_t textureIndex : mProgram->getActiveSamplersMask()) for (size_t textureIndex : mProgram->getActiveSamplersMask())
{ {
mActiveTexturesCache[textureIndex] = nullptr; unsetActiveTexture(textureIndex);
mCompleteTextureBindings[textureIndex].reset(); mCompleteTextureBindings[textureIndex].reset();
} }
} }
ANGLE_INLINE void State::setActiveTexture(size_t textureIndex, Texture *texture)
{
if (mActiveTexturesCache[textureIndex])
{
mActiveTexturesCache[textureIndex]->onUnbindAsSamplerTexture();
}
texture->onBindAsSamplerTexture();
mActiveTexturesCache[textureIndex] = texture;
}
ANGLE_INLINE void State::updateActiveTextureState(const Context *context, ANGLE_INLINE void State::updateActiveTextureState(const Context *context,
size_t textureIndex, size_t textureIndex,
const Sampler *sampler, const Sampler *sampler,
...@@ -561,11 +581,11 @@ ANGLE_INLINE void State::updateActiveTextureState(const Context *context, ...@@ -561,11 +581,11 @@ ANGLE_INLINE void State::updateActiveTextureState(const Context *context,
{ {
if (!texture->isSamplerComplete(context, sampler)) if (!texture->isSamplerComplete(context, sampler))
{ {
mActiveTexturesCache[textureIndex] = nullptr; unsetActiveTexture(textureIndex);
} }
else else
{ {
mActiveTexturesCache[textureIndex] = texture; setActiveTexture(textureIndex, texture);
if (texture->hasAnyDirtyBit()) if (texture->hasAnyDirtyBit())
{ {
...@@ -605,7 +625,7 @@ ANGLE_INLINE void State::updateActiveTexture(const Context *context, ...@@ -605,7 +625,7 @@ ANGLE_INLINE void State::updateActiveTexture(const Context *context,
if (!texture) if (!texture)
{ {
mActiveTexturesCache[textureIndex] = nullptr; unsetActiveTexture(textureIndex);
mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
return; return;
} }
...@@ -3124,18 +3144,24 @@ void State::setImageUnit(const Context *context, ...@@ -3124,18 +3144,24 @@ void State::setImageUnit(const Context *context,
GLenum access, GLenum access,
GLenum format) GLenum format)
{ {
mImageUnits[unit].texture.set(context, texture); ImageUnit &imageUnit = mImageUnits[unit];
mImageUnits[unit].level = level;
mImageUnits[unit].layered = layered;
mImageUnits[unit].layer = layer;
mImageUnits[unit].access = access;
mImageUnits[unit].format = format;
mDirtyBits.set(DIRTY_BIT_IMAGE_BINDINGS);
if (imageUnit.texture.get())
{
imageUnit.texture->onUnbindAsImageTexture();
}
if (texture) if (texture)
{ {
texture->onBindImageTexture(); texture->onBindAsImageTexture();
} }
imageUnit.texture.set(context, texture);
imageUnit.level = level;
imageUnit.layered = layered;
imageUnit.layer = layer;
imageUnit.access = access;
imageUnit.format = format;
mDirtyBits.set(DIRTY_BIT_IMAGE_BINDINGS);
onImageStateChange(context, unit); onImageStateChange(context, unit);
} }
......
...@@ -759,7 +759,9 @@ class State : angle::NonCopyable ...@@ -759,7 +759,9 @@ class State : angle::NonCopyable
private: private:
friend class Context; friend class Context;
void unsetActiveTexture(size_t textureIndex);
void unsetActiveTextures(ActiveTextureMask textureMask); void unsetActiveTextures(ActiveTextureMask textureMask);
void setActiveTexture(size_t textureIndex, Texture *texture);
void updateActiveTexture(const Context *context, size_t textureIndex, Texture *texture); void updateActiveTexture(const Context *context, size_t textureIndex, Texture *texture);
void updateActiveTextureState(const Context *context, void updateActiveTextureState(const Context *context,
size_t textureIndex, size_t textureIndex,
......
...@@ -99,7 +99,8 @@ TextureState::TextureState(TextureType type) ...@@ -99,7 +99,8 @@ TextureState::TextureState(TextureType type)
mBaseLevel(0), mBaseLevel(0),
mMaxLevel(1000), mMaxLevel(1000),
mDepthStencilTextureMode(GL_DEPTH_COMPONENT), mDepthStencilTextureMode(GL_DEPTH_COMPONENT),
mBoundAsImageTexture(false), mSamplerBindingCount(0),
mImageBindingCount(0),
mImmutableFormat(false), mImmutableFormat(false),
mImmutableLevels(0), mImmutableLevels(0),
mUsage(GL_NONE), mUsage(GL_NONE),
...@@ -1920,13 +1921,13 @@ angle::Result Texture::getTexImage(const Context *context, ...@@ -1920,13 +1921,13 @@ angle::Result Texture::getTexImage(const Context *context,
pixels); pixels);
} }
void Texture::onBindImageTexture() void Texture::onBindAsImageTexture()
{ {
if (!mState.mBoundAsImageTexture) if (!mState.isBoundAsImageTexture())
{ {
mDirtyBits.set(DIRTY_BIT_BOUND_AS_IMAGE); mDirtyBits.set(DIRTY_BIT_BOUND_AS_IMAGE);
mState.mBoundAsImageTexture = true;
} }
mState.mImageBindingCount++;
} }
} // namespace gl } // namespace gl
...@@ -135,7 +135,8 @@ class TextureState final : private angle::NonCopyable ...@@ -135,7 +135,8 @@ class TextureState final : private angle::NonCopyable
GLenum getUsage() const { return mUsage; } GLenum getUsage() const { return mUsage; }
GLenum getDepthStencilTextureMode() const { return mDepthStencilTextureMode; } GLenum getDepthStencilTextureMode() const { return mDepthStencilTextureMode; }
bool isStencilMode() const { return mDepthStencilTextureMode == GL_STENCIL_INDEX; } bool isStencilMode() const { return mDepthStencilTextureMode == GL_STENCIL_INDEX; }
bool isBoundAsImageTexture() const { return mBoundAsImageTexture; } bool isBoundAsSamplerTexture() const { return mSamplerBindingCount > 0; }
bool isBoundAsImageTexture() const { return mImageBindingCount > 0; }
// Returns the desc of the base level. Only valid for cube-complete/mip-complete textures. // Returns the desc of the base level. Only valid for cube-complete/mip-complete textures.
const ImageDesc &getBaseLevelDesc() const; const ImageDesc &getBaseLevelDesc() const;
...@@ -191,7 +192,8 @@ class TextureState final : private angle::NonCopyable ...@@ -191,7 +192,8 @@ class TextureState final : private angle::NonCopyable
GLenum mDepthStencilTextureMode; GLenum mDepthStencilTextureMode;
bool mBoundAsImageTexture; uint32_t mSamplerBindingCount;
uint32_t mImageBindingCount;
bool mImmutableFormat; bool mImmutableFormat;
GLuint mImmutableLevels; GLuint mImmutableLevels;
...@@ -415,7 +417,22 @@ class Texture final : public RefCountObject<TextureID>, ...@@ -415,7 +417,22 @@ class Texture final : public RefCountObject<TextureID>,
angle::Result setEGLImageTarget(Context *context, TextureType type, egl::Image *imageTarget); angle::Result setEGLImageTarget(Context *context, TextureType type, egl::Image *imageTarget);
angle::Result generateMipmap(Context *context); angle::Result generateMipmap(Context *context);
void onBindImageTexture();
void onBindAsImageTexture();
ANGLE_INLINE void onUnbindAsImageTexture()
{
ASSERT(mState.isBoundAsImageTexture());
mState.mImageBindingCount--;
}
ANGLE_INLINE void onBindAsSamplerTexture() { mState.mSamplerBindingCount++; }
ANGLE_INLINE void onUnbindAsSamplerTexture()
{
ASSERT(mState.isBoundAsSamplerTexture());
mState.mSamplerBindingCount--;
}
egl::Surface *getBoundSurface() const; egl::Surface *getBoundSurface() const;
egl::Stream *getBoundStream() const; egl::Stream *getBoundStream() const;
......
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