[Impeller] Optionally support SamplerAddressMode::kDecal on the OpenGLES backend (flutter/engine#46650)
fix https://github.com/flutter/flutter/issues/129358
This commit is contained in:
@@ -262,6 +262,8 @@ bool AtlasContents::Render(const ContentContext& renderer,
|
||||
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
|
||||
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
frag_info.supports_decal_sampler_address_mode =
|
||||
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode();
|
||||
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
FS::BindTextureSamplerDst(cmd, texture_, dst_sampler);
|
||||
|
||||
@@ -181,6 +181,8 @@ static std::optional<Entity> AdvancedBlend(
|
||||
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
|
||||
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
blend_info.supports_decal_sampler_address_mode =
|
||||
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode();
|
||||
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
|
||||
@@ -355,6 +357,8 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
|
||||
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
|
||||
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
blend_info.supports_decal_sampler_address_mode =
|
||||
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode();
|
||||
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
|
||||
@@ -479,6 +483,8 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
|
||||
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
|
||||
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
frag_info.supports_decal_sampler_address_mode =
|
||||
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode();
|
||||
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
|
||||
|
||||
@@ -127,6 +127,8 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
|
||||
sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
|
||||
sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
frag_info.supports_decal_sampler_address_mode =
|
||||
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode();
|
||||
|
||||
FS::BindTextureSampler(
|
||||
cmd, input_snapshot->texture,
|
||||
|
||||
@@ -12,6 +12,7 @@ uniform BlendInfo {
|
||||
float16_t src_input_alpha;
|
||||
float16_t color_factor;
|
||||
f16vec4 color; // This color input is expected to be unpremultiplied.
|
||||
float supports_decal_sampler_address_mode;
|
||||
}
|
||||
blend_info;
|
||||
|
||||
@@ -24,9 +25,12 @@ in vec2 v_src_texture_coords;
|
||||
out f16vec4 frag_color;
|
||||
|
||||
f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
|
||||
// gles 2.0 is the only backend without native decal support.
|
||||
#ifdef IMPELLER_TARGET_OPENGLES
|
||||
return IPSampleDecal(texture_sampler, texture_coords);
|
||||
if (blend_info.supports_decal_sampler_address_mode > 0.0) {
|
||||
return texture(texture_sampler, texture_coords);
|
||||
} else {
|
||||
return IPHalfSampleDecal(texture_sampler, texture_coords);
|
||||
}
|
||||
#else
|
||||
return texture(texture_sampler, texture_coords);
|
||||
#endif
|
||||
|
||||
@@ -19,6 +19,7 @@ uniform FragInfo {
|
||||
float16_t dst_coeff_src_color;
|
||||
float16_t input_alpha;
|
||||
float16_t output_alpha;
|
||||
float supports_decal_sampler_address_mode;
|
||||
}
|
||||
frag_info;
|
||||
|
||||
@@ -28,9 +29,12 @@ in f16vec4 v_color;
|
||||
out f16vec4 frag_color;
|
||||
|
||||
f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
|
||||
// gles 2.0 is the only backend without native decal support.
|
||||
#ifdef IMPELLER_TARGET_OPENGLES
|
||||
return IPSampleDecal(texture_sampler, texture_coords);
|
||||
if (frag_info.supports_decal_sampler_address_mode > 0.0) {
|
||||
return texture(texture_sampler, texture_coords);
|
||||
} else {
|
||||
return IPHalfSampleDecal(texture_sampler, texture_coords);
|
||||
}
|
||||
#else
|
||||
return texture(texture_sampler, texture_coords);
|
||||
#endif
|
||||
|
||||
@@ -19,6 +19,7 @@ uniform FragInfo {
|
||||
f16vec2 uv_offset;
|
||||
float16_t radius;
|
||||
float16_t morph_type;
|
||||
float supports_decal_sampler_address_mode;
|
||||
}
|
||||
frag_info;
|
||||
|
||||
@@ -32,11 +33,15 @@ void main() {
|
||||
for (float16_t i = -frag_info.radius; i <= frag_info.radius; i++) {
|
||||
vec2 texture_coords = v_texture_coords + frag_info.uv_offset * i;
|
||||
|
||||
// gles 2.0 is the only backend without native decal support.
|
||||
f16vec4 color;
|
||||
#ifdef IMPELLER_TARGET_OPENGLES
|
||||
f16vec4 color = IPHalfSampleDecal(texture_sampler, texture_coords);
|
||||
if (frag_info.supports_decal_sampler_address_mode > 0.0) {
|
||||
color = texture(texture_sampler, texture_coords);
|
||||
} else {
|
||||
color = IPHalfSampleDecal(texture_sampler, texture_coords);
|
||||
}
|
||||
#else
|
||||
f16vec4 color = texture(texture_sampler, texture_coords);
|
||||
color = texture(texture_sampler, texture_coords);
|
||||
#endif
|
||||
|
||||
if (frag_info.morph_type == kMorphTypeDilate) {
|
||||
|
||||
@@ -86,6 +86,12 @@ CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
|
||||
gl.GetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &value);
|
||||
num_shader_binary_formats = value;
|
||||
}
|
||||
|
||||
if (gl.GetDescription()->HasExtension("GL_EXT_texture_border_clamp") ||
|
||||
gl.GetDescription()->HasExtension("GL_NV_texture_border_clamp") ||
|
||||
gl.GetDescription()->HasExtension("GL_OES_texture_border_clamp")) {
|
||||
supports_decal_sampler_address_mode_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
size_t CapabilitiesGLES::GetMaxTextureUnits(ShaderStage stage) const {
|
||||
@@ -140,7 +146,7 @@ bool CapabilitiesGLES::SupportsReadFromResolve() const {
|
||||
}
|
||||
|
||||
bool CapabilitiesGLES::SupportsDecalSamplerAddressMode() const {
|
||||
return false;
|
||||
return supports_decal_sampler_address_mode_;
|
||||
}
|
||||
|
||||
bool CapabilitiesGLES::SupportsDeviceTransientTextures() const {
|
||||
|
||||
@@ -114,6 +114,9 @@ class CapabilitiesGLES final
|
||||
|
||||
// |Capabilities|
|
||||
PixelFormat GetDefaultDepthStencilFormat() const override;
|
||||
|
||||
private:
|
||||
bool supports_decal_sampler_address_mode_ = false;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -53,13 +53,15 @@ ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
|
||||
}
|
||||
}
|
||||
|
||||
device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
|
||||
|
||||
// Create the sampler library.
|
||||
{
|
||||
sampler_library_ =
|
||||
std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES());
|
||||
std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES(
|
||||
device_capabilities_->SupportsDecalSamplerAddressMode()));
|
||||
}
|
||||
|
||||
device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
// IWYU pragma: begin_exports
|
||||
#include "GLES3/gl3.h"
|
||||
#define GL_CLAMP_TO_BORDER 0x812D
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include "GLES2/gl2ext.h"
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
@@ -53,7 +53,8 @@ static GLint ToParam(MinMagFilter minmag_filter,
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
static GLint ToAddressMode(SamplerAddressMode mode) {
|
||||
static GLint ToAddressMode(SamplerAddressMode mode,
|
||||
bool supports_decal_sampler_address_mode) {
|
||||
switch (mode) {
|
||||
case SamplerAddressMode::kClampToEdge:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
@@ -62,7 +63,10 @@ static GLint ToAddressMode(SamplerAddressMode mode) {
|
||||
case SamplerAddressMode::kMirror:
|
||||
return GL_MIRRORED_REPEAT;
|
||||
case SamplerAddressMode::kDecal:
|
||||
break; // Unsupported.
|
||||
if (supports_decal_sampler_address_mode) {
|
||||
return GL_CLAMP_TO_BORDER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
@@ -96,10 +100,14 @@ bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
|
||||
ToParam(desc.min_filter, mip_filter));
|
||||
gl.TexParameteri(target.value(), GL_TEXTURE_MAG_FILTER,
|
||||
ToParam(desc.mag_filter));
|
||||
gl.TexParameteri(target.value(), GL_TEXTURE_WRAP_S,
|
||||
ToAddressMode(desc.width_address_mode));
|
||||
gl.TexParameteri(target.value(), GL_TEXTURE_WRAP_T,
|
||||
ToAddressMode(desc.height_address_mode));
|
||||
gl.TexParameteri(
|
||||
target.value(), GL_TEXTURE_WRAP_S,
|
||||
ToAddressMode(desc.width_address_mode,
|
||||
gl.GetCapabilities()->SupportsDecalSamplerAddressMode()));
|
||||
gl.TexParameteri(
|
||||
target.value(), GL_TEXTURE_WRAP_T,
|
||||
ToAddressMode(desc.height_address_mode,
|
||||
gl.GetCapabilities()->SupportsDecalSamplerAddressMode()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
SamplerLibraryGLES::SamplerLibraryGLES() = default;
|
||||
SamplerLibraryGLES::SamplerLibraryGLES(bool supports_decal_sampler_address_mode)
|
||||
: supports_decal_sampler_address_mode_(
|
||||
supports_decal_sampler_address_mode) {}
|
||||
|
||||
// |SamplerLibrary|
|
||||
SamplerLibraryGLES::~SamplerLibraryGLES() = default;
|
||||
@@ -19,14 +21,12 @@ SamplerLibraryGLES::~SamplerLibraryGLES() = default;
|
||||
// |SamplerLibrary|
|
||||
std::shared_ptr<const Sampler> SamplerLibraryGLES::GetSampler(
|
||||
SamplerDescriptor descriptor) {
|
||||
// TODO(bdero): Change this validation once optional support for kDecal is
|
||||
// added to the OpenGLES backend:
|
||||
// https://github.com/flutter/flutter/issues/129358
|
||||
if (descriptor.width_address_mode == SamplerAddressMode::kDecal ||
|
||||
descriptor.height_address_mode == SamplerAddressMode::kDecal ||
|
||||
descriptor.depth_address_mode == SamplerAddressMode::kDecal) {
|
||||
if (!supports_decal_sampler_address_mode_ &&
|
||||
(descriptor.width_address_mode == SamplerAddressMode::kDecal ||
|
||||
descriptor.height_address_mode == SamplerAddressMode::kDecal ||
|
||||
descriptor.depth_address_mode == SamplerAddressMode::kDecal)) {
|
||||
VALIDATION_LOG << "SamplerAddressMode::kDecal is not supported by the "
|
||||
"OpenGLES backend.";
|
||||
"current OpenGLES backend.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace impeller {
|
||||
|
||||
class SamplerLibraryGLES final : public SamplerLibrary {
|
||||
public:
|
||||
explicit SamplerLibraryGLES(bool supports_decal_sampler_address_mode);
|
||||
// |SamplerLibrary|
|
||||
~SamplerLibraryGLES() override;
|
||||
|
||||
@@ -26,6 +27,8 @@ class SamplerLibraryGLES final : public SamplerLibrary {
|
||||
std::shared_ptr<const Sampler> GetSampler(
|
||||
SamplerDescriptor descriptor) override;
|
||||
|
||||
bool supports_decal_sampler_address_mode_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(SamplerLibraryGLES);
|
||||
};
|
||||
|
||||
|
||||
@@ -34,5 +34,15 @@ TEST(CapabilitiesGLES, CanInitializeWithDefaults) {
|
||||
PixelFormat::kD24UnormS8Uint);
|
||||
}
|
||||
|
||||
TEST(CapabilitiesGLES, SupportsDecalSamplerAddressMode) {
|
||||
auto const extensions = std::vector<const unsigned char*>{
|
||||
reinterpret_cast<const unsigned char*>("GL_KHR_debug"), //
|
||||
reinterpret_cast<const unsigned char*>("GL_EXT_texture_border_clamp"), //
|
||||
};
|
||||
auto mock_gles = MockGLES::Init(extensions);
|
||||
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
|
||||
EXPECT_TRUE(capabilities->SupportsDecalSamplerAddressMode());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -19,6 +19,8 @@ static std::mutex g_test_lock;
|
||||
|
||||
static std::weak_ptr<MockGLES> g_mock_gles;
|
||||
|
||||
static std::vector<const unsigned char*> g_extensions;
|
||||
|
||||
// Has friend visibility into MockGLES to record calls.
|
||||
void RecordGLCall(const char* name) {
|
||||
if (auto mock_gles = g_mock_gles.lock()) {
|
||||
@@ -37,7 +39,7 @@ void doNothing() {}
|
||||
|
||||
auto const kMockVendor = (unsigned char*)"MockGLES";
|
||||
auto const kMockVersion = (unsigned char*)"3.0";
|
||||
auto const kExtensions = std::vector<unsigned char*>{
|
||||
auto const kExtensions = std::vector<const unsigned char*>{
|
||||
(unsigned char*)"GL_KHR_debug" //
|
||||
};
|
||||
|
||||
@@ -60,7 +62,7 @@ static_assert(CheckSameSignature<decltype(mockGetString), //
|
||||
const unsigned char* mockGetStringi(GLenum name, GLuint index) {
|
||||
switch (name) {
|
||||
case GL_EXTENSIONS:
|
||||
return kExtensions[index];
|
||||
return g_extensions[index];
|
||||
default:
|
||||
return (unsigned char*)"";
|
||||
}
|
||||
@@ -72,7 +74,7 @@ static_assert(CheckSameSignature<decltype(mockGetStringi), //
|
||||
void mockGetIntegerv(GLenum name, int* value) {
|
||||
switch (name) {
|
||||
case GL_NUM_EXTENSIONS: {
|
||||
*value = kExtensions.size();
|
||||
*value = g_extensions.size();
|
||||
} break;
|
||||
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
|
||||
*value = 8;
|
||||
@@ -110,10 +112,12 @@ void mockPushDebugGroupKHR(GLenum source,
|
||||
static_assert(CheckSameSignature<decltype(mockPushDebugGroupKHR), //
|
||||
decltype(glPushDebugGroupKHR)>::value);
|
||||
|
||||
std::shared_ptr<MockGLES> MockGLES::Init() {
|
||||
std::shared_ptr<MockGLES> MockGLES::Init(
|
||||
const std::optional<std::vector<const unsigned char*>>& extensions) {
|
||||
// If we cannot obtain a lock, MockGLES is already being used elsewhere.
|
||||
FML_CHECK(g_test_lock.try_lock())
|
||||
<< "MockGLES is already being used by another test.";
|
||||
g_extensions = extensions.value_or(kExtensions);
|
||||
auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES());
|
||||
g_mock_gles = mock_gles;
|
||||
return mock_gles;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include "fml/macros.h"
|
||||
#include "impeller/renderer/backend/gles/proc_table_gles.h"
|
||||
|
||||
@@ -24,7 +25,9 @@ class MockGLES final {
|
||||
/// This method overwrites mocked global GLES function pointers to record
|
||||
/// invocations on this instance of |MockGLES|. As such, it should only be
|
||||
/// called once per test.
|
||||
static std::shared_ptr<MockGLES> Init();
|
||||
static std::shared_ptr<MockGLES> Init(
|
||||
const std::optional<std::vector<const unsigned char*>>& extensions =
|
||||
std::nullopt);
|
||||
|
||||
/// @brief Returns a configured |ProcTableGLES| instance.
|
||||
const ProcTableGLES& GetProcTable() const { return proc_table_; }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user