Skip to content

Commit cd0b145

Browse files
committed
Scope GLES texture upload rebinding to affected Arm drivers
Arm identified the reproduced texture-name reuse failure as EN_ID 1,792,661, affecting Bifrost and Valhall r17p0 through r23p0 and fixed in r24p0. Cache the workaround decision from native GLES renderer and driver strings, retaining a conservative fallback for unidentifiable Arm G-series drivers. Cover driver boundaries, exclusions, malformed versions, and bind-before-upload ordering.
1 parent d00e967 commit cd0b145

7 files changed

Lines changed: 132 additions & 12 deletions

File tree

‎engine/src/flutter/impeller/renderer/backend/gles/blit_command_gles.cc‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,12 @@ bool BlitCopyBufferToTextureCommandGLES::Encode(
210210
return false;
211211
}
212212
const auto& gl = reactor.GetProcTable();
213-
// Force a rebind after deleted shared texture names can be reused on Mali.
214-
// See https://github.com/flutter/flutter/issues/190640.
215-
gl.BindTexture(texture_type, 0u);
213+
// Arm erratum EN_ID 1,792,661: force a binding change before uploading to
214+
// a reused shared texture name. See
215+
// https://github.com/flutter/flutter/issues/190640.
216+
if (gl.GetDescription()->NeedsTextureUploadRebind()) {
217+
gl.BindTexture(texture_type, 0u);
218+
}
216219
gl.BindTexture(texture_type, gl_handle.value());
217220
const GLvoid* tex_data =
218221
source.GetBuffer()->OnGetContents() + source.GetRange().offset;

‎engine/src/flutter/impeller/renderer/backend/gles/blit_command_gles_unittests.cc‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,24 @@ BlitCopyTextureToBufferCommandGLES CreateCopyTextureToBufferCommand(
9090

9191
} // namespace
9292

93-
TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESRGBA) {
93+
struct TextureUploadPrebindCase {
94+
const char* name;
95+
const char* renderer;
96+
const char* version;
97+
bool needs_prebind;
98+
};
99+
100+
class TextureUploadPrebindTest
101+
: public ::testing::TestWithParam<TextureUploadPrebindCase> {};
102+
103+
TEST_P(TextureUploadPrebindTest, RebindsOnlyAffectedDriversBeforeUpload) {
94104
auto mock_gles_impl = std::make_unique<MockGLESImpl>();
95105
auto& mock_gles_impl_ref = *mock_gles_impl;
96106

97-
std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
107+
const auto& test_case = GetParam();
108+
std::shared_ptr<MockGLES> mock_gl =
109+
MockGLES::Init(std::move(mock_gles_impl), std::nullopt, test_case.version,
110+
test_case.renderer);
98111
auto reactor = std::make_shared<TestReactorGLES>();
99112
auto worker = std::make_shared<MockWorker>();
100113
reactor->AddWorker(worker);
@@ -108,9 +121,14 @@ TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESRGBA) {
108121
BlitCopyBufferToTextureCommandGLES command =
109122
CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
110123

124+
if (!test_case.needs_prebind) {
125+
EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_2D, 0u)).Times(0);
126+
}
111127
{
112128
::testing::InSequence sequence;
113-
EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_2D, 0u));
129+
if (test_case.needs_prebind) {
130+
EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_2D, 0u));
131+
}
114132
EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_2D, 7u));
115133
// Upload only after the texture has been rebound.
116134
EXPECT_CALL(mock_gles_impl_ref,
@@ -121,6 +139,53 @@ TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESRGBA) {
121139
EXPECT_TRUE(command.Encode(*reactor));
122140
}
123141

142+
INSTANTIATE_TEST_SUITE_P(
143+
ArmErratum1792661,
144+
TextureUploadPrebindTest,
145+
::testing::Values(
146+
TextureUploadPrebindCase{"BeforeAffectedRange", "Mali-G71",
147+
"OpenGL ES 3.2 v1.r16p0-01rel0", false},
148+
TextureUploadPrebindCase{"FirstAffectedRelease", "Mali-G71",
149+
"OpenGL ES 3.2 v1.r17p0-01rel0", true},
150+
TextureUploadPrebindCase{"AffectedG72", "Mali-G72 MP18",
151+
"OpenGL ES 3.2 v1.r18p0-01rel0", true},
152+
TextureUploadPrebindCase{"LastAffectedRelease", "Mali-G76",
153+
"OpenGL ES 3.2 v1.r23p0-01rel0", true},
154+
TextureUploadPrebindCase{"AffectedValhall", "Mali-G77",
155+
"OpenGL ES 3.2 v1.r19p0-01rel0", true},
156+
TextureUploadPrebindCase{"FixedRelease", "Mali-G72",
157+
"OpenGL ES 3.2 v1.r24p0-01rel0", false},
158+
TextureUploadPrebindCase{"NewerRelease", "Mali-G78",
159+
"OpenGL ES 3.2 v1.r36p0-01rel0", false},
160+
TextureUploadPrebindCase{"Midgard", "Mali-T880",
161+
"OpenGL ES 3.2 v1.r18p0-01rel0", false},
162+
TextureUploadPrebindCase{"OtherVendor", "Adreno (TM) 530",
163+
"OpenGL ES 3.2 [email protected]", false},
164+
TextureUploadPrebindCase{"UnknownArmDriver", "Mali-G72",
165+
"OpenGL ES 3.2", true},
166+
TextureUploadPrebindCase{"MalformedArmDriver", "Mali-G72",
167+
"OpenGL ES 3.2 v1.r24p-01rel0", true},
168+
TextureUploadPrebindCase{"Angle", "Mali-G72",
169+
"OpenGL ES 3.2 (ANGLE 2.1) v1.r18p0", false},
170+
TextureUploadPrebindCase{"DesktopGL", "Mali-G72", "4.6 v1.r18p0",
171+
false},
172+
TextureUploadPrebindCase{"LaterPatchBeforeFix", "Mali-G76",
173+
"OpenGL ES 3.2 v1.r23p1-01rel0", true},
174+
TextureUploadPrebindCase{"NoBuildSuffix", "Mali-G72",
175+
"OpenGL ES 3.2 v1.r18p0", true},
176+
TextureUploadPrebindCase{"CompleteReleaseNumber", "Mali-G720",
177+
"OpenGL ES 3.2 v1.r170p0-01rel0", false},
178+
TextureUploadPrebindCase{"ImmortalisFixedDriver", "Immortalis-G715",
179+
"OpenGL ES 3.2 v1.r42p0-01rel0", false},
180+
TextureUploadPrebindCase{"OverflowRelease", "Mali-G72",
181+
"OpenGL ES 3.2 v1.r99999999999999999999p0",
182+
true},
183+
TextureUploadPrebindCase{"MalformedPatchSuffix", "Mali-G72",
184+
"OpenGL ES 3.2 v1.r24p0invalid", true}),
185+
[](const ::testing::TestParamInfo<TextureUploadPrebindCase>& info) {
186+
return info.param.name;
187+
});
188+
124189
TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESBGRA) {
125190
auto mock_gles_impl = std::make_unique<MockGLESImpl>();
126191
auto& mock_gles_impl_ref = *mock_gles_impl;
@@ -511,7 +576,7 @@ TEST(BlitCommandGLESTest,
511576

512577
// The bind target is the cubemap parent, even though allocation/upload
513578
// calls use the per-face target.
514-
EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_CUBE_MAP, _)).Times(2);
579+
EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_CUBE_MAP, _)).Times(1);
515580
EXPECT_CALL(mock_gles_impl_ref,
516581
TexImage2D(face_target, 0, _, 4, 4, _, _, _, nullptr))
517582
.Times(1);

‎engine/src/flutter/impeller/renderer/backend/gles/command_buffer_gles_unittests.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ TEST(CommandBufferGLES, LaterCurrentSubmitDrainsPreviouslyDeferredWork) {
176176
TEST(CommandBufferGLES, BufferToTextureBlitCanBeSubmittedBeforeContextCurrent) {
177177
auto mock_gles_impl = std::make_unique<NiceMock<MockGLESImpl>>();
178178
auto& mock_gles_impl_ref = *mock_gles_impl;
179-
auto mock_gles = MockGLES::Init(std::move(mock_gles_impl));
179+
auto mock_gles = MockGLES::Init(std::move(mock_gles_impl), std::nullopt,
180+
"OpenGL ES 3.2 v1.r18p0-01rel0", "Mali-G72");
180181
auto context = CreateFakeGLESContext();
181182
auto context_base = std::static_pointer_cast<Context>(context);
182183
auto worker = std::make_shared<ToggleWorker>(false);

‎engine/src/flutter/impeller/renderer/backend/gles/description_gles.cc‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <algorithm>
88
#include <cctype>
9+
#include <charconv>
910
#include <iomanip>
1011
#include <sstream>
1112
#include <string>
@@ -79,6 +80,33 @@ static std::optional<Version> DetermineVersion(std::string version) {
7980
return Version::FromVector(version_components);
8081
}
8182

83+
static bool MaliDriverNeedsTextureUploadRebind(const std::string& version) {
84+
// Arm's version string includes a driver release, for example:
85+
// "OpenGL ES 3.2 v1.r18p0-01rel0...". If it is unavailable, retain the
86+
// workaround rather than assuming that the driver has been fixed.
87+
const auto marker = version.find(" v1.r");
88+
if (marker == std::string::npos) {
89+
return true;
90+
}
91+
const char* end = version.data() + version.size();
92+
unsigned int release = 0;
93+
const auto release_result =
94+
std::from_chars(version.data() + marker + 5, end, release);
95+
if (release_result.ec != std::errc{} || release_result.ptr == end ||
96+
*release_result.ptr != 'p') {
97+
return true;
98+
}
99+
unsigned int patch = 0;
100+
const auto patch_result = std::from_chars(release_result.ptr + 1, end, patch);
101+
if (patch_result.ec != std::errc{} ||
102+
(patch_result.ptr != end && *patch_result.ptr != '-')) {
103+
return true;
104+
}
105+
// Arm erratum EN_ID 1,792,661 affects Bifrost/Valhall r17p0-r23p0 and was
106+
// fixed in r24p0. OEM backports within that range cannot be detected.
107+
return release >= 17 && release < 24;
108+
}
109+
82110
DescriptionGLES::DescriptionGLES(const ProcTableGLES& gl)
83111
: vendor_(GetGLString(gl, GL_VENDOR)),
84112
renderer_(GetGLString(gl, GL_RENDERER)),
@@ -117,6 +145,12 @@ DescriptionGLES::DescriptionGLES(const ProcTableGLES& gl)
117145
}
118146
sl_version_ = sl_version.value();
119147

148+
needs_texture_upload_rebind_ =
149+
is_es_ && !is_angle_ &&
150+
(HasPrefix(renderer_, "Mali-G") ||
151+
HasPrefix(renderer_, "Immortalis-G")) &&
152+
MaliDriverNeedsTextureUploadRebind(gl_version_string_);
153+
120154
is_valid_ = true;
121155
}
122156

@@ -173,6 +207,10 @@ bool DescriptionGLES::IsANGLE() const {
173207
return is_angle_;
174208
}
175209

210+
bool DescriptionGLES::NeedsTextureUploadRebind() const {
211+
return needs_texture_upload_rebind_;
212+
}
213+
176214
bool DescriptionGLES::HasExtension(const std::string& ext) const {
177215
return extensions_.find(ext) != extensions_.end();
178216
}

‎engine/src/flutter/impeller/renderer/backend/gles/description_gles.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class DescriptionGLES {
3535

3636
bool IsANGLE() const;
3737

38+
/// Whether uploads must reset a stale shared-context texture binding.
39+
bool NeedsTextureUploadRebind() const;
40+
3841
private:
3942
Version gl_version_;
4043
Version sl_version_;
@@ -45,6 +48,7 @@ class DescriptionGLES {
4548
std::string sl_version_string_;
4649
std::set<std::string> extensions_;
4750
bool is_angle_ = false;
51+
bool needs_texture_upload_rebind_ = false;
4852
bool is_valid_ = false;
4953

5054
DescriptionGLES(const DescriptionGLES&) = delete;

‎engine/src/flutter/impeller/renderer/backend/gles/test/mock_gles.cc‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static std::weak_ptr<MockGLES> g_mock_gles;
2222
static std::vector<const char*> g_extensions;
2323

2424
static const char* g_version;
25+
static const char* g_renderer;
2526
static std::string g_extensions_string;
2627

2728
template <typename T, typename U>
@@ -64,6 +65,8 @@ const unsigned char* mockGetString(GLenum name) {
6465
switch (name) {
6566
case GL_VENDOR:
6667
return reinterpret_cast<const unsigned char*>(kMockVendor);
68+
case GL_RENDERER:
69+
return reinterpret_cast<const unsigned char*>(g_renderer);
6770
case GL_VERSION:
6871
return reinterpret_cast<const unsigned char*>(g_version);
6972
case GL_EXTENSIONS:
@@ -472,7 +475,8 @@ static_assert(CheckSameSignature<decltype(mockVertexAttribDivisor), //
472475
std::shared_ptr<MockGLES> MockGLES::Init(
473476
std::unique_ptr<MockGLESImpl> impl,
474477
const std::optional<std::vector<const char*>>& extensions,
475-
const char* version_string) {
478+
const char* version_string,
479+
const char* renderer_string) {
476480
FML_CHECK(g_test_lock.try_lock())
477481
<< "MockGLES is already being used by another test.";
478482
g_extensions = extensions.value_or(kExtensions);
@@ -484,6 +488,7 @@ std::shared_ptr<MockGLES> MockGLES::Init(
484488
g_extensions_string += ext;
485489
}
486490
g_version = version_string;
491+
g_renderer = renderer_string;
487492
auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES());
488493
mock_gles->impl_ = std::move(impl);
489494
g_mock_gles = mock_gles;
@@ -493,7 +498,8 @@ std::shared_ptr<MockGLES> MockGLES::Init(
493498
std::shared_ptr<MockGLES> MockGLES::Init(
494499
const std::optional<std::vector<const char*>>& extensions,
495500
const char* version_string,
496-
ProcTableGLES::Resolver resolver) {
501+
ProcTableGLES::Resolver resolver,
502+
const char* renderer_string) {
497503
// If we cannot obtain a lock, MockGLES is already being used elsewhere.
498504
FML_CHECK(g_test_lock.try_lock())
499505
<< "MockGLES is already being used by another test.";
@@ -506,6 +512,7 @@ std::shared_ptr<MockGLES> MockGLES::Init(
506512
g_extensions_string += ext;
507513
}
508514
g_version = version_string;
515+
g_renderer = renderer_string;
509516
auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES(std::move(resolver)));
510517
g_mock_gles = mock_gles;
511518
return mock_gles;

‎engine/src/flutter/impeller/renderer/backend/gles/test/mock_gles.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ class MockGLES final {
364364
static std::shared_ptr<MockGLES> Init(
365365
std::unique_ptr<MockGLESImpl> impl,
366366
const std::optional<std::vector<const char*>>& extensions = std::nullopt,
367-
const char* version_string = "OpenGL ES 3.0");
367+
const char* version_string = "OpenGL ES 3.0",
368+
const char* renderer_string = "");
368369

369370
/// @brief Returns an initialized |MockGLES| instance.
370371
///
@@ -374,7 +375,8 @@ class MockGLES final {
374375
static std::shared_ptr<MockGLES> Init(
375376
const std::optional<std::vector<const char*>>& extensions = std::nullopt,
376377
const char* version_string = "OpenGL ES 3.0",
377-
ProcTableGLES::Resolver resolver = kMockResolverGLES);
378+
ProcTableGLES::Resolver resolver = kMockResolverGLES,
379+
const char* renderer_string = "");
378380

379381
/// @brief Returns a configured |ProcTableGLES| instance.
380382
const ProcTableGLES& GetProcTable() const { return proc_table_; }

0 commit comments

Comments
 (0)