Skip to content

Commit

Permalink
[ANGLE] Clear pending program linking in Context::onDestroy
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263429
rdar://117242201

Reviewed by Kimmo Kinnunen.

When destroying Context, ANGLE resets any internal state before releasing
allocated objects, such as Programs and Shaders. When destroying a program, any
pending program linking is resolved via Program::resolveLink. This results in
trying to access the Context state that’s just been reset.

To work around this, we ensure there are no pending links before resetting the
Context state.

* Source/ThirdParty/ANGLE/changes.diff:
* Source/ThirdParty/ANGLE/src/libANGLE/Context.cpp:
(gl::Context::onDestroy):
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm:
(TestWebKitAPI::TEST_F):

Canonical link: https://commits.webkit.org/269693@main
  • Loading branch information
djg committed Oct 24, 2023
1 parent 2714943 commit 15b02a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Source/ThirdParty/ANGLE/changes.diff
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ index d5a48edd40f382359db76acf1a1ce75b6a6dc6d5..907c62e0bb659292b391270790498186
/* Bison interface for Yacc-like parsers in C

Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index 8e52937f55bcd77be026e2d99bead9ac4db2c2b9..f956247eaf93806b62d84d15b65f1ab2f59479bc 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -828,6 +828,8 @@ egl::Error Context::onDestroy(const egl::Display *display)
return egl::NoError();
}

+ mState.ensureNoPendingLink(this);
+
// eglDestoryContext() must have been called for this Context and there must not be any Threads
// that still have it current.
ASSERT(mIsDestroyed == true && mRefCount == 0);
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp
index 68e94d1594a4c2b0d11b9ae2a87a38db88c8fde8..dcfdbf60ae37d2b3f461df8e65e8965909c1c679 100644
--- a/src/libANGLE/State.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/ThirdParty/ANGLE/src/libANGLE/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ egl::Error Context::onDestroy(const egl::Display *display)
return egl::NoError();
}

mState.ensureNoPendingLink(this);

// eglDestoryContext() must have been called for this Context and there must not be any Threads
// that still have it current.
ASSERT(mIsDestroyed == true && mRefCount == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,27 @@ static bool hasMultipleGPUs()
}
#endif

TEST_F(GraphicsContextGLCocoaTest, TwoLinks)
{
WebCore::GraphicsContextGLAttributes attributes;
attributes.useMetal = true;
auto gl = TestedGraphicsContextGLCocoa::create(WTFMove(attributes));
auto vs = gl->createShader(WebCore::GraphicsContextGL::VERTEX_SHADER);
gl->shaderSource(vs, "void main() { }"_s);
gl->compileShader(vs);
auto fs = gl->createShader(WebCore::GraphicsContextGL::FRAGMENT_SHADER);
gl->shaderSource(fs, "void main() { }"_s);
gl->compileShader(fs);
auto program = gl->createProgram();
gl->attachShader(program, vs);
gl->attachShader(program, fs);
gl->linkProgram(program);
gl->useProgram(program);
gl->linkProgram(program);
EXPECT_TRUE(gl->getErrors().isEmpty());
gl = nullptr;
}

TEST_P(AnyContextAttributeTest, DisplayBuffersAreRecycled)
{
auto context = createTestContext({ 20, 20 });
Expand Down

0 comments on commit 15b02a1

Please sign in to comment.