Skip to content

Commit

Permalink
Add initial support for 4x MSAA in OpenGLES backend. (flutter#46381)
Browse files Browse the repository at this point in the history
Initial support _towards_ flutter/flutter#130045.

This updates the `PROC_TABLE`, and adds (and supports) `Type::kRenderBufferMultisampled`.

The type remains unused in the actual engine, and will be in a follow-up PR once we like this one!

/cc @chinmaygarde
  • Loading branch information
matanlurey authored Sep 28, 2023
1 parent 7a895f8 commit d85c839
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
2 changes: 2 additions & 0 deletions impeller/renderer/backend/gles/gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

// IWYU pragma: begin_exports
#include "GLES3/gl3.h"
#define GL_GLEXT_PROTOTYPES
#include "GLES2/gl2ext.h"
// IWYU pragma: end_exports
16 changes: 8 additions & 8 deletions impeller/renderer/backend/gles/proc_table_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

#include <functional>
#include <string>
#include <vector>

#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/trace_event.h"
#include "impeller/renderer/backend/gles/capabilities_gles.h"
#include "impeller/renderer/backend/gles/description_gles.h"
#include "impeller/renderer/backend/gles/gles.h"
Expand Down Expand Up @@ -170,11 +168,13 @@ struct GLProc {

#define FOR_EACH_IMPELLER_GLES3_PROC(PROC) PROC(BlitFramebuffer);

#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
PROC(DiscardFramebufferEXT); \
PROC(PushDebugGroupKHR); \
PROC(PopDebugGroupKHR); \
PROC(ObjectLabelKHR);
#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
PROC(DiscardFramebufferEXT); \
PROC(FramebufferTexture2DMultisampleEXT) \
PROC(PushDebugGroupKHR); \
PROC(PopDebugGroupKHR); \
PROC(ObjectLabelKHR); \
PROC(RenderbufferStorageMultisampleEXT);

enum class DebugResourceType {
kTexture,
Expand All @@ -188,7 +188,7 @@ enum class DebugResourceType {
class ProcTableGLES {
public:
using Resolver = std::function<void*(const char* function_name)>;
ProcTableGLES(Resolver resolver);
explicit ProcTableGLES(Resolver resolver);

~ProcTableGLES();

Expand Down
3 changes: 0 additions & 3 deletions impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

#include "impeller/renderer/backend/gles/render_pass_gles.h"

#include <algorithm>

#include "flutter/fml/trace_event.h"
#include "impeller/base/config.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/device_buffer_gles.h"
#include "impeller/renderer/backend/gles/formats_gles.h"
Expand Down
39 changes: 37 additions & 2 deletions impeller/renderer/backend/gles/texture_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "flutter/fml/mapping.h"
#include "flutter/fml/trace_event.h"
#include "impeller/base/allocation.h"
#include "impeller/base/config.h"
#include "impeller/base/validation.h"
#include "impeller/core/formats.h"
#include "impeller/renderer/backend/gles/formats_gles.h"
Expand All @@ -33,6 +32,8 @@ HandleType ToHandleType(TextureGLES::Type type) {
case TextureGLES::Type::kTexture:
return HandleType::kTexture;
case TextureGLES::Type::kRenderBuffer:
// MSAA textures are treated as render buffers.
case TextureGLES::Type::kRenderBufferMultisampled:
return HandleType::kRenderBuffer;
}
FML_UNREACHABLE();
Expand Down Expand Up @@ -383,7 +384,7 @@ void TextureGLES::InitializeContentsIfNecessary() const {
}

} break;
case Type::kRenderBuffer:
case Type::kRenderBuffer: {
auto render_buffer_format =
ToRenderBufferFormat(GetTextureDescriptor().format);
if (!render_buffer_format.has_value()) {
Expand All @@ -399,7 +400,27 @@ void TextureGLES::InitializeContentsIfNecessary() const {
size.height // height
);
}
} break;
case Type::kRenderBufferMultisampled: {
auto render_buffer_msaa =
ToRenderBufferFormat(GetTextureDescriptor().format);
if (!render_buffer_msaa.has_value()) {
VALIDATION_LOG << "Invalid format for render-buffer MSAA image.";
return;
}
gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
{
TRACE_EVENT0("impeller", "RenderBufferStorageInitialization");
gl.RenderbufferStorageMultisampleEXT(
GL_RENDERBUFFER, // target
4, // samples
render_buffer_msaa.value(), // internal format
size.width, // width
size.height // height
);
}
break;
}
}
}

Expand All @@ -426,6 +447,8 @@ bool TextureGLES::Bind() const {
gl.BindTexture(target.value(), handle.value());
} break;
case Type::kRenderBuffer:
// MSAA textures are treated as render buffers.
case Type::kRenderBufferMultisampled:
gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
break;
}
Expand Down Expand Up @@ -510,6 +533,18 @@ bool TextureGLES::SetAsFramebufferAttachment(GLenum target,
handle.value() // render-buffer
);
break;
case Type::kRenderBufferMultisampled:
// Assume that when MSAA is enabled, we're using 4x MSAA.
FML_DCHECK(GetTextureDescriptor().sample_count == SampleCount::kCount4);
gl.FramebufferTexture2DMultisampleEXT(
target, // target
ToAttachmentPoint(point), // attachment
GL_TEXTURE_2D, // textarget
handle.value(), // texture
0, // level
4 // samples
);
break;
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/gles/texture_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TextureGLES final : public Texture,
enum class Type {
kTexture,
kRenderBuffer,
kRenderBufferMultisampled,
};

enum class IsWrapped {
Expand Down

0 comments on commit d85c839

Please sign in to comment.