[Impeller] OpenGLES MSAA Render Buffers (i.e. for stencils) (flutter/engine#47495)
Closes https://github.com/flutter/flutter/issues/137569. Closes https://github.com/flutter/flutter/issues/137095. As of the latest commit, it works on both the Moto G4 and Pixel 5.
This commit is contained in:
@@ -21,7 +21,7 @@ static const constexpr char* kOESTextureBorderClampExt =
|
||||
|
||||
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture.txt
|
||||
static const constexpr char* kMultisampledRenderToTextureExt =
|
||||
"GL_EXT_multisampled_render_to_texture2";
|
||||
"GL_EXT_multisampled_render_to_texture";
|
||||
|
||||
CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "impeller/renderer/backend/gles/capabilities_gles.h"
|
||||
#include "impeller/renderer/backend/gles/description_gles.h"
|
||||
@@ -189,19 +188,19 @@ struct GLProc {
|
||||
|
||||
#define FOR_EACH_IMPELLER_GLES3_PROC(PROC) PROC(BlitFramebuffer);
|
||||
|
||||
#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
|
||||
PROC(DebugMessageControlKHR); \
|
||||
PROC(DiscardFramebufferEXT); \
|
||||
PROC(FramebufferTexture2DMultisampleEXT) \
|
||||
PROC(PushDebugGroupKHR); \
|
||||
PROC(PopDebugGroupKHR); \
|
||||
PROC(ObjectLabelKHR); \
|
||||
PROC(RenderbufferStorageMultisampleEXT); \
|
||||
PROC(GenQueriesEXT); \
|
||||
PROC(DeleteQueriesEXT); \
|
||||
PROC(GetQueryObjectui64vEXT); \
|
||||
PROC(BeginQueryEXT); \
|
||||
PROC(EndQueryEXT); \
|
||||
#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
|
||||
PROC(DebugMessageControlKHR); \
|
||||
PROC(DiscardFramebufferEXT); \
|
||||
PROC(FramebufferTexture2DMultisampleEXT); \
|
||||
PROC(PushDebugGroupKHR); \
|
||||
PROC(PopDebugGroupKHR); \
|
||||
PROC(ObjectLabelKHR); \
|
||||
PROC(RenderbufferStorageMultisampleEXT); \
|
||||
PROC(GenQueriesEXT); \
|
||||
PROC(DeleteQueriesEXT); \
|
||||
PROC(GetQueryObjectui64vEXT); \
|
||||
PROC(BeginQueryEXT); \
|
||||
PROC(EndQueryEXT); \
|
||||
PROC(GetQueryObjectuivEXT);
|
||||
|
||||
enum class DebugResourceType {
|
||||
|
||||
@@ -23,10 +23,9 @@ static TextureGLES::Type GetTextureTypeFromDescriptor(
|
||||
const auto render_target =
|
||||
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
|
||||
const auto is_msaa = desc.sample_count == SampleCount::kCount4;
|
||||
if (usage == render_target && !is_msaa) {
|
||||
// TODO(matanlurey): MSAA render buffers?
|
||||
// See https://github.com/flutter/flutter/issues/137095.
|
||||
return TextureGLES::Type::kRenderBuffer;
|
||||
if (usage == render_target && desc.format == PixelFormat::kS8UInt) {
|
||||
return is_msaa ? TextureGLES::Type::kRenderBufferMultisampled
|
||||
: TextureGLES::Type::kRenderBuffer;
|
||||
}
|
||||
return is_msaa ? TextureGLES::Type::kTextureMultisampled
|
||||
: TextureGLES::Type::kTexture;
|
||||
@@ -38,6 +37,7 @@ HandleType ToHandleType(TextureGLES::Type type) {
|
||||
case TextureGLES::Type::kTextureMultisampled:
|
||||
return HandleType::kTexture;
|
||||
case TextureGLES::Type::kRenderBuffer:
|
||||
case TextureGLES::Type::kRenderBufferMultisampled:
|
||||
return HandleType::kRenderBuffer;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
@@ -354,7 +354,8 @@ void TextureGLES::InitializeContentsIfNecessary() const {
|
||||
);
|
||||
}
|
||||
} break;
|
||||
case Type::kRenderBuffer: {
|
||||
case Type::kRenderBuffer:
|
||||
case Type::kRenderBufferMultisampled: {
|
||||
auto render_buffer_format =
|
||||
ToRenderBufferFormat(GetTextureDescriptor().format);
|
||||
if (!render_buffer_format.has_value()) {
|
||||
@@ -364,11 +365,22 @@ void TextureGLES::InitializeContentsIfNecessary() const {
|
||||
gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
|
||||
{
|
||||
TRACE_EVENT0("impeller", "RenderBufferStorageInitialization");
|
||||
gl.RenderbufferStorage(GL_RENDERBUFFER, // target
|
||||
render_buffer_format.value(), // internal format
|
||||
size.width, // width
|
||||
size.height // height
|
||||
);
|
||||
if (type_ == Type::kRenderBufferMultisampled) {
|
||||
gl.RenderbufferStorageMultisampleEXT(
|
||||
GL_RENDERBUFFER, // target
|
||||
4, // samples
|
||||
render_buffer_format.value(), // internal format
|
||||
size.width, // width
|
||||
size.height // height
|
||||
);
|
||||
} else {
|
||||
gl.RenderbufferStorage(
|
||||
GL_RENDERBUFFER, // target
|
||||
render_buffer_format.value(), // internal format
|
||||
size.width, // width
|
||||
size.height // height
|
||||
);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -398,6 +410,7 @@ bool TextureGLES::Bind() const {
|
||||
gl.BindTexture(target.value(), handle.value());
|
||||
} break;
|
||||
case Type::kRenderBuffer:
|
||||
case Type::kRenderBufferMultisampled:
|
||||
gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
|
||||
break;
|
||||
}
|
||||
@@ -486,12 +499,12 @@ bool TextureGLES::SetAsFramebufferAttachment(GLenum target,
|
||||
);
|
||||
break;
|
||||
case Type::kRenderBuffer:
|
||||
case Type::kRenderBufferMultisampled:
|
||||
gl.FramebufferRenderbuffer(target, // target
|
||||
ToAttachmentPoint(point), // attachment
|
||||
GL_RENDERBUFFER, // render-buffer target
|
||||
handle.value() // render-buffer
|
||||
);
|
||||
gl.BindRenderbuffer(GL_RENDERBUFFER, GL_NONE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/core/texture.h"
|
||||
#include "impeller/renderer/backend/gles/handle_gles.h"
|
||||
@@ -19,6 +18,7 @@ class TextureGLES final : public Texture,
|
||||
kTexture,
|
||||
kTextureMultisampled,
|
||||
kRenderBuffer,
|
||||
kRenderBufferMultisampled,
|
||||
};
|
||||
|
||||
enum class IsWrapped {
|
||||
|
||||
Reference in New Issue
Block a user