This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Add blit pass #34901
Merged
Merged
[Impeller] Add blit pass #34901
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
40d5510
Add blit pass
bdero 370d68b
Use GLES3 blit if available
bdero 88746ef
Add tests
bdero 9583329
Licenses
bdero 67c4041
Format
bdero d8ae678
Remainter of mipmap test
bdero d67ae15
Mip count convenience
bdero 552d912
Add mip filter setting to sampler
bdero c532288
Flip mip filter enums to correct direction, add min filter to mipmap …
bdero ffca873
Clip to source/destination image
bdero 9742381
Get GLES3 blits working
bdero d5fad8e
Mipmap flag for playground tests
bdero 2b892cf
Refactor blit commands into subclasses
bdero 4dbd85c
Address comments
bdero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| uniform FragInfo { | ||
| float lod; | ||
| } | ||
| frag_info; | ||
|
|
||
| uniform sampler2D tex; | ||
|
|
||
| in vec2 v_uv; | ||
|
|
||
| out vec4 frag_color; | ||
|
|
||
| void main() { | ||
| frag_color = textureLod(tex, v_uv, frag_info.lod); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| uniform VertInfo { | ||
| mat4 mvp; | ||
| } | ||
| vert_info; | ||
|
|
||
| in vec2 vertex_position; | ||
| in vec2 uv; | ||
|
|
||
| out vec2 v_uv; | ||
|
|
||
| void main() { | ||
| gl_Position = vert_info.mvp * vec4(vertex_position, 0.0, 1.0); | ||
| v_uv = uv; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "impeller/renderer/backend/gles/blit_command_gles.h" | ||
|
|
||
| #include "flutter/fml/closure.h" | ||
| #include "impeller/base/validation.h" | ||
| #include "impeller/renderer/backend/gles/texture_gles.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| BlitEncodeGLES::~BlitEncodeGLES() = default; | ||
|
|
||
| static void DeleteFBO(const ProcTableGLES& gl, GLuint fbo, GLenum type) { | ||
| if (fbo != GL_NONE) { | ||
| gl.BindFramebuffer(type, GL_NONE); | ||
| gl.DeleteFramebuffers(1u, &fbo); | ||
| } | ||
| }; | ||
|
|
||
| static std::optional<GLuint> ConfigureFBO( | ||
| const ProcTableGLES& gl, | ||
| const std::shared_ptr<Texture>& texture, | ||
| GLenum fbo_type) { | ||
| auto handle = TextureGLES::Cast(texture.get())->GetGLHandle(); | ||
| if (!handle.has_value()) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| if (TextureGLES::Cast(*texture).IsWrapped()) { | ||
| // The texture is attached to the default FBO, so there's no need to | ||
| // create/configure one. | ||
| gl.BindFramebuffer(fbo_type, 0); | ||
| return 0; | ||
| } | ||
|
|
||
| GLuint fbo; | ||
| gl.GenFramebuffers(1u, &fbo); | ||
| gl.BindFramebuffer(fbo_type, fbo); | ||
|
|
||
| if (!TextureGLES::Cast(*texture).SetAsFramebufferAttachment( | ||
| fbo_type, fbo, TextureGLES::AttachmentPoint::kColor0)) { | ||
| VALIDATION_LOG << "Could not attach texture to framebuffer."; | ||
| DeleteFBO(gl, fbo, fbo_type); | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| if (gl.CheckFramebufferStatus(fbo_type) != GL_FRAMEBUFFER_COMPLETE) { | ||
| VALIDATION_LOG << "Could not create a complete frambuffer."; | ||
| DeleteFBO(gl, fbo, fbo_type); | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| return fbo; | ||
| }; | ||
|
|
||
| BlitCopyTextureToTextureCommandGLES::~BlitCopyTextureToTextureCommandGLES() = | ||
| default; | ||
|
|
||
| std::string BlitCopyTextureToTextureCommandGLES::GetLabel() const { | ||
| return label; | ||
| } | ||
|
|
||
| bool BlitCopyTextureToTextureCommandGLES::Encode( | ||
| const ReactorGLES& reactor) const { | ||
| const auto& gl = reactor.GetProcTable(); | ||
|
|
||
| // glBlitFramebuffer is a GLES3 proc. Since we target GLES2, we need to | ||
| // emulate the blit when it's not available in the driver. | ||
| if (!gl.BlitFramebuffer.IsAvailable()) { | ||
| // TODO(bdero): Emulate the blit using a raster draw call here. | ||
| FML_LOG(ERROR) << "Texture blit fallback not implemented yet for GLES2."; | ||
| return true; | ||
| } | ||
|
|
||
| GLuint read_fbo = GL_NONE; | ||
| GLuint draw_fbo = GL_NONE; | ||
| fml::ScopedCleanupClosure delete_fbos([&gl, &read_fbo, &draw_fbo]() { | ||
| DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER); | ||
| DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER); | ||
| }); | ||
|
|
||
| { | ||
| auto read = ConfigureFBO(gl, source, GL_READ_FRAMEBUFFER); | ||
| if (!read.has_value()) { | ||
| return false; | ||
| } | ||
| read_fbo = read.value(); | ||
| } | ||
|
|
||
| { | ||
| auto draw = ConfigureFBO(gl, destination, GL_DRAW_FRAMEBUFFER); | ||
| if (!draw.has_value()) { | ||
| return false; | ||
| } | ||
| draw_fbo = draw.value(); | ||
| } | ||
|
|
||
| gl.Disable(GL_SCISSOR_TEST); | ||
| gl.Disable(GL_DEPTH_TEST); | ||
| gl.Disable(GL_STENCIL_TEST); | ||
|
|
||
| gl.BlitFramebuffer(source_region.origin.x, // srcX0 | ||
| source_region.origin.y, // srcY0 | ||
| source_region.size.width, // srcX1 | ||
| source_region.size.height, // srcY1 | ||
| destination_origin.x, // dstX0 | ||
| destination_origin.y, // dstY0 | ||
| source_region.size.width, // dstX1 | ||
| source_region.size.height, // dstY1 | ||
| GL_COLOR_BUFFER_BIT, // mask | ||
| GL_NEAREST // filter | ||
| ); | ||
|
|
||
| return true; | ||
| }; | ||
|
|
||
| BlitGenerateMipmapCommandGLES::~BlitGenerateMipmapCommandGLES() = default; | ||
|
|
||
| std::string BlitGenerateMipmapCommandGLES::GetLabel() const { | ||
| return label; | ||
| } | ||
|
|
||
| bool BlitGenerateMipmapCommandGLES::Encode(const ReactorGLES& reactor) const { | ||
| auto texture_gles = TextureGLES::Cast(texture.get()); | ||
| if (!texture_gles->GenerateMipmaps()) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
|
|
||
| } // namespace impeller | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "impeller/base/backend_cast.h" | ||
| #include "impeller/renderer/backend/gles/reactor_gles.h" | ||
| #include "impeller/renderer/blit_command.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| /// Mixin for dispatching metal commands. | ||
|
||
| struct BlitEncodeGLES : BackendCast<BlitEncodeGLES, BlitCommand> { | ||
| virtual ~BlitEncodeGLES(); | ||
|
|
||
| virtual std::string GetLabel() const = 0; | ||
|
|
||
| [[nodiscard]] virtual bool Encode(const ReactorGLES& reactor) const = 0; | ||
| }; | ||
|
|
||
| struct BlitCopyTextureToTextureCommandGLES | ||
| : public BlitEncodeGLES, | ||
| public BlitCopyTextureToTextureCommand { | ||
| ~BlitCopyTextureToTextureCommandGLES() override; | ||
|
|
||
| std::string GetLabel() const override; | ||
|
|
||
| [[nodiscard]] bool Encode(const ReactorGLES& reactor) const override; | ||
| }; | ||
|
|
||
| struct BlitGenerateMipmapCommandGLES : public BlitEncodeGLES, | ||
| public BlitGenerateMipmapCommand { | ||
| ~BlitGenerateMipmapCommandGLES() override; | ||
|
|
||
| std::string GetLabel() const override; | ||
|
|
||
| [[nodiscard]] bool Encode(const ReactorGLES& reactor) const override; | ||
| }; | ||
|
|
||
| } // namespace impeller | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return
false?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, I suppose we can't really use CopyTextureToTexture for real until we have this fallback in place anyhow, so might as well fail loudly by failing the whole frame. Done.