Skip to content

Commit 5b2763f

Browse files
committed
Move GLES texture upload workaround detection to capabilities
1 parent 89a68b7 commit 5b2763f

5 files changed

Lines changed: 53 additions & 40 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ bool BlitCopyBufferToTextureCommandGLES::Encode(
213213
// Arm erratum EN_ID 1,792,661: force a binding change before uploading to
214214
// a reused shared texture name. See
215215
// https://github.com/flutter/flutter/issues/190640.
216-
if (gl.GetDescription()->NeedsTextureUploadRebind()) {
216+
if (gl.GetCapabilities()->NeedsTextureUploadRebind()) {
217217
gl.BindTexture(texture_type, 0u);
218218
}
219219
gl.BindTexture(texture_type, gl_handle.value());

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include "impeller/renderer/backend/gles/capabilities_gles.h"
66

77
#include <algorithm>
8+
#include <charconv>
9+
#include <string>
810

11+
#include "impeller/base/strings.h"
912
#include "impeller/core/formats.h"
1013
#include "impeller/renderer/backend/gles/proc_table_gles.h"
1114

@@ -61,6 +64,33 @@ static const constexpr char* kAppleTextureMaxLevelExt =
6164
static const constexpr char* kTextureFilterAnisotropicExt =
6265
"GL_EXT_texture_filter_anisotropic";
6366

67+
static bool MaliDriverNeedsTextureUploadRebind(const std::string& version) {
68+
// Arm's version string includes a driver release, for example:
69+
// "OpenGL ES 3.2 v1.r18p0-01rel0...". If it is unavailable, retain the
70+
// workaround rather than assuming that the driver has been fixed.
71+
const auto marker = version.find(" v1.r");
72+
if (marker == std::string::npos) {
73+
return true;
74+
}
75+
const char* end = version.data() + version.size();
76+
unsigned int release = 0;
77+
const auto release_result =
78+
std::from_chars(version.data() + marker + 5, end, release);
79+
if (release_result.ec != std::errc{} || release_result.ptr == end ||
80+
*release_result.ptr != 'p') {
81+
return true;
82+
}
83+
unsigned int patch = 0;
84+
const auto patch_result = std::from_chars(release_result.ptr + 1, end, patch);
85+
if (patch_result.ec != std::errc{} ||
86+
(patch_result.ptr != end && *patch_result.ptr != '-')) {
87+
return true;
88+
}
89+
// Arm erratum EN_ID 1,792,661 affects Bifrost/Valhall r17p0-r23p0 and was
90+
// fixed in r24p0. OEM backports within that range cannot be detected.
91+
return release >= 17 && release < 24;
92+
}
93+
6494
CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
6595
{
6696
GLint value = 0;
@@ -179,6 +209,11 @@ CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
179209
}
180210
is_es_ = desc->IsES();
181211
is_angle_ = desc->IsANGLE();
212+
needs_texture_upload_rebind_ =
213+
is_es_ && !is_angle_ &&
214+
(HasPrefix(desc->GetRenderer(), "Mali-G") ||
215+
HasPrefix(desc->GetRenderer(), "Immortalis-G")) &&
216+
MaliDriverNeedsTextureUploadRebind(desc->GetGlVersionString());
182217

183218
// ETC2 and EAC are mandatory in OpenGL ES 3.0. BC and ASTC are gated behind
184219
// extensions and are not present on most mobile or desktop GLES. The whole BC
@@ -231,6 +266,10 @@ CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
231266
}
232267
}
233268

269+
bool CapabilitiesGLES::NeedsTextureUploadRebind() const {
270+
return needs_texture_upload_rebind_;
271+
}
272+
234273
bool CapabilitiesGLES::IsES() const {
235274
return is_es_;
236275
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class CapabilitiesGLES final
7777

7878
bool IsANGLE() const;
7979

80+
/// Whether uploads must reset a stale shared-context texture binding.
81+
bool NeedsTextureUploadRebind() const;
82+
8083
/// @brief Whether this is an ES GL variant or (if false) desktop GL.
8184
bool IsES() const;
8285

@@ -181,6 +184,7 @@ class CapabilitiesGLES final
181184
bool supports_32bit_primitive_indices_ = false;
182185
bool supports_texture_max_level_ = false;
183186
bool supports_texture_array_ = false;
187+
bool needs_texture_upload_rebind_ = false;
184188
bool is_angle_ = false;
185189
bool is_es_ = false;
186190
bool supports_texture_compression_bc_ = false;

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

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

77
#include <algorithm>
88
#include <cctype>
9-
#include <charconv>
109
#include <iomanip>
1110
#include <sstream>
1211
#include <string>
@@ -80,33 +79,6 @@ static std::optional<Version> DetermineVersion(std::string version) {
8079
return Version::FromVector(version_components);
8180
}
8281

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-
11082
DescriptionGLES::DescriptionGLES(const ProcTableGLES& gl)
11183
: vendor_(GetGLString(gl, GL_VENDOR)),
11284
renderer_(GetGLString(gl, GL_RENDERER)),
@@ -145,12 +117,6 @@ DescriptionGLES::DescriptionGLES(const ProcTableGLES& gl)
145117
}
146118
sl_version_ = sl_version.value();
147119

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-
154120
is_valid_ = true;
155121
}
156122

@@ -207,8 +173,12 @@ bool DescriptionGLES::IsANGLE() const {
207173
return is_angle_;
208174
}
209175

210-
bool DescriptionGLES::NeedsTextureUploadRebind() const {
211-
return needs_texture_upload_rebind_;
176+
const std::string& DescriptionGLES::GetRenderer() const {
177+
return renderer_;
178+
}
179+
180+
const std::string& DescriptionGLES::GetGlVersionString() const {
181+
return gl_version_string_;
212182
}
213183

214184
bool DescriptionGLES::HasExtension(const std::string& ext) const {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +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;
38+
const std::string& GetRenderer() const;
39+
40+
const std::string& GetGlVersionString() const;
4041

4142
private:
4243
Version gl_version_;
@@ -48,7 +49,6 @@ class DescriptionGLES {
4849
std::string sl_version_string_;
4950
std::set<std::string> extensions_;
5051
bool is_angle_ = false;
51-
bool needs_texture_upload_rebind_ = false;
5252
bool is_valid_ = false;
5353

5454
DescriptionGLES(const DescriptionGLES&) = delete;

0 commit comments

Comments
 (0)