Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 185d9d0

Browse files
null77Commit Bot
authored andcommitted
Re-land "Feedback Loop Redesign 2/3: Track bound FBOs in Texture."
Re-land fixes the crash when drawing with no bound Program executable. Currently we track feedback loops by counting the times a Texture is bound as a sampler or image in a particular context. This is a bit tricky because Texture bindings change frequently. Relative to the number of times we need to check for a feedback loop this causes excess overhead. Usually Framebuffers have a low number of Textures bound (in many cases just 1). And Textures aren't usually bound to many different FBOs. So instead of counting the number of times a Texture is bound as a sampler or image we will track the Framebuffers that the Texture is bound to. This CL adds a small vector class to gl::Texture which tracks all the Framebufer Serials of its bound Framebuffers. We can use this set to quickly check if there's any potential feedback loop between the a FBO and this Texture. We also update the feedback loop check to use this new method. We will be able to remove the old counting method when we switch the Vulkan feedback loop handling to use the new tracking in this CL. Bug: angleproject:4500 Bug: angleproject:4959 Change-Id: If2bd25b08298a99f5e64b4055137f9154b0f0860 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2365595 Reviewed-by: Jamie Madill <[email protected]> Commit-Queue: Jamie Madill <[email protected]>
1 parent a20f5b1 commit 185d9d0

File tree

15 files changed

+121
-49
lines changed

15 files changed

+121
-49
lines changed

PRESUBMIT.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _SplitIntoMultipleCommits(description_text):
6060
def _CheckTabInCommit(lines):
6161
return all([line.find("\t") == -1 for line in lines])
6262

63-
whitelist_strings = ['Revert "', 'Roll ', 'Reland ']
63+
whitelist_strings = ['Revert "', 'Roll ', 'Reland ', 'Re-land ']
6464
summary_linelength_warning_lower_limit = 65
6565
summary_linelength_warning_upper_limit = 70
6666
description_linelength_limit = 72

src/libANGLE/Framebuffer.cpp

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -796,19 +796,19 @@ void Framebuffer::onDestroy(const Context *context)
796796
{
797797
if (isDefault())
798798
{
799-
mState.mDefaultFramebufferReadAttachment.detach(context);
799+
mState.mDefaultFramebufferReadAttachment.detach(context, mState.mFramebufferSerial);
800800
mState.mDefaultFramebufferReadAttachmentInitialized = false;
801801
}
802802

803803
for (auto &attachment : mState.mColorAttachments)
804804
{
805-
attachment.detach(context);
805+
attachment.detach(context, mState.mFramebufferSerial);
806806
}
807-
mState.mDepthAttachment.detach(context);
808-
mState.mStencilAttachment.detach(context);
809-
mState.mWebGLDepthAttachment.detach(context);
810-
mState.mWebGLStencilAttachment.detach(context);
811-
mState.mWebGLDepthStencilAttachment.detach(context);
807+
mState.mDepthAttachment.detach(context, mState.mFramebufferSerial);
808+
mState.mStencilAttachment.detach(context, mState.mFramebufferSerial);
809+
mState.mWebGLDepthAttachment.detach(context, mState.mFramebufferSerial);
810+
mState.mWebGLStencilAttachment.detach(context, mState.mFramebufferSerial);
811+
mState.mWebGLDepthStencilAttachment.detach(context, mState.mFramebufferSerial);
812812

813813
mImpl->destroy(context);
814814
}
@@ -819,7 +819,7 @@ void Framebuffer::setReadSurface(const Context *context, egl::Surface *readSurfa
819819
mState.mDefaultFramebufferReadAttachment.attach(
820820
context, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex(), readSurface,
821821
FramebufferAttachment::kDefaultNumViews, FramebufferAttachment::kDefaultBaseViewIndex,
822-
false, FramebufferAttachment::kDefaultRenderToTextureSamples);
822+
false, FramebufferAttachment::kDefaultRenderToTextureSamples, mState.mFramebufferSerial);
823823
mDirtyBits.set(DIRTY_BIT_READ_BUFFER);
824824
}
825825

@@ -1674,19 +1674,21 @@ void Framebuffer::setAttachment(const Context *context,
16741674
{
16751675
case GL_DEPTH_STENCIL:
16761676
case GL_DEPTH_STENCIL_ATTACHMENT:
1677-
mState.mWebGLDepthStencilAttachment.attach(context, type, binding, textureIndex,
1678-
resource, numViews, baseViewIndex,
1679-
isMultiview, samples);
1677+
mState.mWebGLDepthStencilAttachment.attach(
1678+
context, type, binding, textureIndex, resource, numViews, baseViewIndex,
1679+
isMultiview, samples, mState.mFramebufferSerial);
16801680
break;
16811681
case GL_DEPTH:
16821682
case GL_DEPTH_ATTACHMENT:
16831683
mState.mWebGLDepthAttachment.attach(context, type, binding, textureIndex, resource,
1684-
numViews, baseViewIndex, isMultiview, samples);
1684+
numViews, baseViewIndex, isMultiview, samples,
1685+
mState.mFramebufferSerial);
16851686
break;
16861687
case GL_STENCIL:
16871688
case GL_STENCIL_ATTACHMENT:
16881689
mState.mWebGLStencilAttachment.attach(context, type, binding, textureIndex, resource,
1689-
numViews, baseViewIndex, isMultiview, samples);
1690+
numViews, baseViewIndex, isMultiview, samples,
1691+
mState.mFramebufferSerial);
16901692
break;
16911693
default:
16921694
setAttachmentImpl(context, type, binding, textureIndex, resource, numViews,
@@ -1869,7 +1871,7 @@ void Framebuffer::updateAttachment(const Context *context,
18691871
GLsizei samples)
18701872
{
18711873
attachment->attach(context, type, binding, textureIndex, resource, numViews, baseViewIndex,
1872-
isMultiview, samples);
1874+
isMultiview, samples, mState.mFramebufferSerial);
18731875
mDirtyBits.set(dirtyBit);
18741876
mState.mResourceNeedsInit.set(dirtyBit, attachment->initState() == InitState::MayNeedInit);
18751877
onDirtyBinding->bind(resource);
@@ -1967,6 +1969,34 @@ FramebufferAttachment *Framebuffer::getAttachmentFromSubjectIndex(angle::Subject
19671969
}
19681970
}
19691971

1972+
bool Framebuffer::formsRenderingFeedbackLoopWith(const Context *context) const
1973+
{
1974+
const State &glState = context->getState();
1975+
const ProgramExecutable *executable = glState.getProgramExecutable();
1976+
1977+
// In some error cases there may be no bound program or executable.
1978+
if (!executable)
1979+
return false;
1980+
1981+
const ActiveTextureMask &activeTextures = executable->getActiveSamplersMask();
1982+
const ActiveTextureTypeArray &textureTypes = executable->getActiveSamplerTypes();
1983+
1984+
for (size_t textureIndex : activeTextures)
1985+
{
1986+
unsigned int uintIndex = static_cast<unsigned int>(textureIndex);
1987+
Texture *texture = glState.getSamplerTexture(uintIndex, textureTypes[textureIndex]);
1988+
const Sampler *sampler = glState.getSampler(uintIndex);
1989+
if (texture && texture->isSamplerComplete(context, sampler) &&
1990+
texture->isBoundToFramebuffer(mState.mFramebufferSerial))
1991+
{
1992+
// TODO(jmadill): Subresource check. http://anglebug.com/4500
1993+
return true;
1994+
}
1995+
}
1996+
1997+
return false;
1998+
}
1999+
19702000
bool Framebuffer::formsCopyingFeedbackLoopWith(TextureID copyTextureID,
19712001
GLint copyTextureLevel,
19722002
GLint copyTextureLayer) const

src/libANGLE/Framebuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class FramebufferState final : angle::NonCopyable
171171
bool mWebGLDepthStencilConsistent;
172172

173173
// Tracks rendering feedback loops.
174+
// TODO(jmadill): Remove. http://anglebug.com/4500
174175
DrawBufferMask mDrawBufferFeedbackLoops;
175176
bool mDepthBufferFeedbackLoop;
176177
bool mStencilBufferFeedbackLoop;
@@ -409,7 +410,10 @@ class Framebuffer final : public angle::ObserverInterface,
409410
// Observer implementation
410411
void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
411412

413+
// TODO(jmadill): Remove. http://anglebug.com/4500
412414
bool hasRenderingFeedbackLoop() const { return mState.mHasRenderingFeedbackLoop; }
415+
416+
bool formsRenderingFeedbackLoopWith(const Context *context) const;
413417
bool formsCopyingFeedbackLoopWith(TextureID copyTextureID,
414418
GLint copyTextureLevel,
415419
GLint copyTextureLayer) const;

src/libANGLE/FramebufferAttachment.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ FramebufferAttachment::FramebufferAttachment(const Context *context,
6060
GLenum type,
6161
GLenum binding,
6262
const ImageIndex &textureIndex,
63-
FramebufferAttachmentObject *resource)
63+
FramebufferAttachmentObject *resource,
64+
rx::Serial framebufferSerial)
6465
: mResource(nullptr)
6566
{
6667
attach(context, type, binding, textureIndex, resource, kDefaultNumViews, kDefaultBaseViewIndex,
67-
false, kDefaultRenderToTextureSamples);
68+
false, kDefaultRenderToTextureSamples, framebufferSerial);
6869
}
6970

7071
FramebufferAttachment::FramebufferAttachment(FramebufferAttachment &&other)
@@ -90,12 +91,12 @@ FramebufferAttachment::~FramebufferAttachment()
9091
ASSERT(!isAttached());
9192
}
9293

93-
void FramebufferAttachment::detach(const Context *context)
94+
void FramebufferAttachment::detach(const Context *context, rx::Serial framebufferSerial)
9495
{
9596
mType = GL_NONE;
9697
if (mResource != nullptr)
9798
{
98-
mResource->onDetach(context);
99+
mResource->onDetach(context, framebufferSerial);
99100
mResource = nullptr;
100101
}
101102
mNumViews = kDefaultNumViews;
@@ -114,11 +115,12 @@ void FramebufferAttachment::attach(const Context *context,
114115
GLsizei numViews,
115116
GLuint baseViewIndex,
116117
bool isMultiview,
117-
GLsizei samples)
118+
GLsizei samples,
119+
rx::Serial framebufferSerial)
118120
{
119121
if (resource == nullptr)
120122
{
121-
detach(context);
123+
detach(context, framebufferSerial);
122124
return;
123125
}
124126

@@ -128,11 +130,11 @@ void FramebufferAttachment::attach(const Context *context,
128130
mBaseViewIndex = baseViewIndex;
129131
mIsMultiview = isMultiview;
130132
mRenderToTextureSamples = samples;
131-
resource->onAttach(context);
133+
resource->onAttach(context, framebufferSerial);
132134

133135
if (mResource != nullptr)
134136
{
135-
mResource->onDetach(context);
137+
mResource->onDetach(context, framebufferSerial);
136138
}
137139

138140
mResource = resource;

src/libANGLE/FramebufferAttachment.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ class FramebufferAttachment final
6464
GLenum type,
6565
GLenum binding,
6666
const ImageIndex &textureIndex,
67-
FramebufferAttachmentObject *resource);
67+
FramebufferAttachmentObject *resource,
68+
rx::Serial framebufferSerial);
6869

6970
FramebufferAttachment(FramebufferAttachment &&other);
7071
FramebufferAttachment &operator=(FramebufferAttachment &&other);
7172

7273
~FramebufferAttachment();
7374

74-
void detach(const Context *context);
75+
void detach(const Context *context, rx::Serial framebufferSerial);
7576
void attach(const Context *context,
7677
GLenum type,
7778
GLenum binding,
@@ -80,7 +81,8 @@ class FramebufferAttachment final
8081
GLsizei numViews,
8182
GLuint baseViewIndex,
8283
bool isMultiview,
83-
GLsizei samples);
84+
GLsizei samples,
85+
rx::Serial framebufferSerial);
8486

8587
// Helper methods
8688
GLuint getRedSize() const;
@@ -208,9 +210,9 @@ class FramebufferAttachmentObject : public angle::Subject, public angle::Observe
208210
GLenum binding,
209211
const ImageIndex &imageIndex) const = 0;
210212

211-
virtual void onAttach(const Context *context) = 0;
212-
virtual void onDetach(const Context *context) = 0;
213-
virtual GLuint getId() const = 0;
213+
virtual void onAttach(const Context *context, rx::Serial framebufferSerial) = 0;
214+
virtual void onDetach(const Context *context, rx::Serial framebufferSerial) = 0;
215+
virtual GLuint getId() const = 0;
214216

215217
// These are used for robust resource initialization.
216218
virtual InitState initState(const ImageIndex &imageIndex) const = 0;

src/libANGLE/Image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ bool ExternalImageSibling::isTextureable(const gl::Context *context) const
193193
return mImplementation->isTexturable(context);
194194
}
195195

196-
void ExternalImageSibling::onAttach(const gl::Context *context) {}
196+
void ExternalImageSibling::onAttach(const gl::Context *context, rx::Serial framebufferSerial) {}
197197

198-
void ExternalImageSibling::onDetach(const gl::Context *context) {}
198+
void ExternalImageSibling::onDetach(const gl::Context *context, rx::Serial framebufferSerial) {}
199199

200200
GLuint ExternalImageSibling::getId() const
201201
{

src/libANGLE/Image.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class ExternalImageSibling : public ImageSibling
9898
const gl::ImageIndex &imageIndex) const override;
9999
bool isTextureable(const gl::Context *context) const;
100100

101-
void onAttach(const gl::Context *context) override;
102-
void onDetach(const gl::Context *context) override;
101+
void onAttach(const gl::Context *context, rx::Serial framebufferSerial) override;
102+
void onDetach(const gl::Context *context, rx::Serial framebufferSerial) override;
103103
GLuint getId() const override;
104104

105105
gl::InitState initState(const gl::ImageIndex &imageIndex) const override;

src/libANGLE/Renderbuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ GLint Renderbuffer::getMemorySize() const
234234
return size.ValueOrDefault(std::numeric_limits<GLint>::max());
235235
}
236236

237-
void Renderbuffer::onAttach(const Context *context)
237+
void Renderbuffer::onAttach(const Context *context, rx::Serial framebufferSerial)
238238
{
239239
addRef();
240240
}
241241

242-
void Renderbuffer::onDetach(const Context *context)
242+
void Renderbuffer::onDetach(const Context *context, rx::Serial framebufferSerial)
243243
{
244244
release(context);
245245
}

src/libANGLE/Renderbuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class Renderbuffer final : public RefCountObject<RenderbufferID>,
110110
GLenum binding,
111111
const ImageIndex &imageIndex) const override;
112112

113-
void onAttach(const Context *context) override;
114-
void onDetach(const Context *context) override;
113+
void onAttach(const Context *context, rx::Serial framebufferSerial) override;
114+
void onDetach(const Context *context, rx::Serial framebufferSerial) override;
115115
GLuint getId() const override;
116116

117117
InitState initState(const ImageIndex &imageIndex) const override;

src/libANGLE/Surface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class Surface : public LabeledObject, public gl::FramebufferAttachmentObject
143143
GLenum binding,
144144
const gl::ImageIndex &imageIndex) const override;
145145

146-
void onAttach(const gl::Context *context) override {}
147-
void onDetach(const gl::Context *context) override {}
146+
void onAttach(const gl::Context *context, rx::Serial framebufferSerial) override {}
147+
void onDetach(const gl::Context *context, rx::Serial framebufferSerial) override {}
148148
GLuint getId() const override;
149149

150150
bool flexibleSurfaceCompatibilityRequested() const

0 commit comments

Comments
 (0)