Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] compute UVs in vertex stage. #52106

Merged
merged 12 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -40395,7 +40395,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert + ../
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/uv.comp + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
Expand All @@ -40417,6 +40416,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flut
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/vertices.frag + ../../../flutter/LICENSE
Expand Down Expand Up @@ -43275,7 +43275,6 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
FILE: ../../../flutter/impeller/entity/shaders/geometry/uv.comp
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag
Expand All @@ -43297,6 +43296,7 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert
FILE: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag
FILE: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag
FILE: ../../../flutter/impeller/entity/shaders/vertices.frag
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impeller_shaders("entity_shaders") {
"shaders/gradients/sweep_gradient_fill.frag",
"shaders/texture_fill.frag",
"shaders/texture_fill.vert",
"shaders/texture_uv_fill.vert",
"shaders/tiled_texture_fill.frag",
"shaders/tiled_texture_fill_external.frag",
"shaders/texture_fill_strict_src.frag",
Expand Down Expand Up @@ -79,7 +80,6 @@ impeller_shaders("modern_entity_shaders") {
"shaders/gradients/radial_gradient_ssbo_fill.frag",
"shaders/gradients/sweep_gradient_ssbo_fill.frag",
"shaders/geometry/points.comp",
"shaders/geometry/uv.comp",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 for 1!

]
}

Expand Down
1 change: 0 additions & 1 deletion impeller/entity/contents/clip_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <memory>
#include <vector>

#include "flutter/fml/macros.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry/geometry.h"
Expand Down
10 changes: 2 additions & 8 deletions impeller/entity/contents/color_source_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ class ColorSourceContents : public Contents {
RenderPass& pass,
const PipelineBuilderCallback& pipeline_callback,
typename VertexShaderT::FrameInfo frame_info,
const BindFragmentCallback& bind_fragment_callback,
bool enable_uvs = false,
Rect texture_coverage = {},
const Matrix& effect_transform = {}) const {
const BindFragmentCallback& bind_fragment_callback) const {
auto options = OptionsFromPassAndEntity(pass, entity);

GeometryResult::Mode geometry_mode = GetGeometry()->GetResultMode();
Expand Down Expand Up @@ -181,10 +178,7 @@ class ColorSourceContents : public Contents {
}

GeometryResult geometry_result =
enable_uvs
? geometry.GetPositionUVBuffer(texture_coverage, effect_transform,
renderer, entity, pass)
: geometry.GetPositionBuffer(renderer, entity, pass);
geometry.GetPositionBuffer(renderer, entity, pass);
if (geometry_result.vertex_buffer.vertex_count == 0u) {
return true;
}
Expand Down
11 changes: 2 additions & 9 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ ContentContext::ContentContext(
? std::make_shared<RenderTargetCache>(
context_->GetResourceAllocator())
: std::move(render_target_allocator)),
host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())),
pending_command_buffers_(std::make_unique<PendingCommandBuffers>()) {
host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())) {
if (!context_ || !context_->IsValid()) {
return;
}
Expand Down Expand Up @@ -422,8 +421,7 @@ ContentContext::ContentContext(

rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
texture_strict_src_pipelines_.CreateDefault(*context_, options);
position_uv_pipelines_.CreateDefault(*context_, options);
tiled_texture_pipelines_.CreateDefault(*context_, options);
tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal});
kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip);
kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip);
border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
Expand Down Expand Up @@ -456,11 +454,6 @@ ContentContext::ContentContext(
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
point_field_compute_pipelines_ =
context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();

auto uv_pipeline_desc =
UvComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
uv_compute_pipelines_ =
context_->GetPipelineLibrary()->GetPipeline(uv_pipeline_desc).Get();
}

is_valid_ = true;
Expand Down
30 changes: 3 additions & 27 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/texture_fill_strict_src.frag.h"
#include "impeller/entity/texture_uv_fill.vert.h"
#include "impeller/entity/tiled_texture_fill.frag.h"
#include "impeller/entity/uv.comp.h"
#include "impeller/entity/vertices.frag.h"
#include "impeller/entity/yuv_to_rgb_filter.frag.h"

Expand Down Expand Up @@ -129,10 +129,8 @@ using TexturePipeline =
using TextureStrictSrcPipeline =
RenderPipelineHandle<TextureFillVertexShader,
TextureFillStrictSrcFragmentShader>;
using PositionUVPipeline = RenderPipelineHandle<TextureFillVertexShader,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

TiledTextureFillFragmentShader>;
using TiledTexturePipeline =
RenderPipelineHandle<TextureFillVertexShader,
RenderPipelineHandle<TextureUvFillVertexShader,
TiledTextureFillFragmentShader>;
using KernelDecalPipeline =
RenderPipelineHandle<KernelVertexShader, KernelDecalFragmentShader>;
Expand Down Expand Up @@ -253,20 +251,13 @@ using FramebufferBlendSoftLightPipeline =

/// Geometry Pipelines
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;

#ifdef IMPELLER_ENABLE_OPENGLES
using TiledTextureExternalPipeline =
RenderPipelineHandle<TextureFillVertexShader,
RenderPipelineHandle<TextureUvFillVertexShader,
TiledTextureFillExternalFragmentShader>;
#endif // IMPELLER_ENABLE_OPENGLES

// A struct used to isolate command buffer storage from the content
// context options to preserve const-ness.
struct PendingCommandBuffers {
std::vector<std::shared_ptr<CommandBuffer>> command_buffers;
};

/// Pipeline state configuration.
///
/// Each unique combination of these options requires a different pipeline state
Expand Down Expand Up @@ -478,11 +469,6 @@ class ContentContext {
}
#endif // IMPELLER_ENABLE_OPENGLES

std::shared_ptr<Pipeline<PipelineDescriptor>> GetPositionUVPipeline(
ContentContextOptions opts) const {
return GetPipeline(position_uv_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetTiledTexturePipeline(
ContentContextOptions opts) const {
return GetPipeline(tiled_texture_pipelines_, opts);
Expand Down Expand Up @@ -727,12 +713,6 @@ class ContentContext {
return point_field_compute_pipelines_;
}

std::shared_ptr<Pipeline<ComputePipelineDescriptor>> GetUvComputePipeline()
const {
FML_DCHECK(GetDeviceCapabilities().SupportsCompute());
return uv_compute_pipelines_;
}

std::shared_ptr<Context> GetContext() const;

const Capabilities& GetDeviceCapabilities() const;
Expand Down Expand Up @@ -932,7 +912,6 @@ class ContentContext {
mutable Variants<TiledTextureExternalPipeline>
tiled_texture_external_pipelines_;
#endif // IMPELLER_ENABLE_OPENGLES
mutable Variants<PositionUVPipeline> position_uv_pipelines_;
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
mutable Variants<KernelDecalPipeline> kernel_decal_pipelines_;
mutable Variants<KernelPipeline> kernel_nodecal_pipelines_;
Expand Down Expand Up @@ -997,8 +976,6 @@ class ContentContext {
framebuffer_blend_softlight_pipelines_;
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
point_field_compute_pipelines_;
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
uv_compute_pipelines_;

template <class TypedPipeline>
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
Expand Down Expand Up @@ -1058,7 +1035,6 @@ class ContentContext {
#endif // IMPELLER_ENABLE_3D
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
std::shared_ptr<HostBuffer> host_buffer_;
std::unique_ptr<PendingCommandBuffers> pending_command_buffers_;
bool wireframe_ = false;

ContentContext(const ContentContext&) = delete;
Expand Down
45 changes: 6 additions & 39 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/texture_fill_strict_src.frag.h"
#include "impeller/entity/tiled_texture_fill_external.frag.h"
#include "impeller/geometry/constants.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/vertex_buffer_builder.h"
Expand Down Expand Up @@ -114,16 +113,16 @@ bool TextureContents::Render(const ContentContext& renderer,

using VS = TextureFillVertexShader;
using FS = TextureFillFragmentShader;
using FSExternal = TiledTextureFillExternalFragmentShader;
using FSStrict = TextureFillStrictSrcFragmentShader;

if (destination_rect_.IsEmpty() || source_rect_.IsEmpty() ||
texture_ == nullptr || texture_->GetSize().IsEmpty()) {
return true; // Nothing to render.
}

bool is_external_texture =
[[maybe_unused]] bool is_external_texture =
texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES;
FML_DCHECK(!is_external_texture);

auto source_rect = capture.AddRect("Source rect", source_rect_);
auto texture_coords =
Expand Down Expand Up @@ -159,46 +158,14 @@ bool TextureContents::Render(const ContentContext& renderer,
}
pipeline_options.primitive_type = PrimitiveType::kTriangleStrip;

std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
#ifdef IMPELLER_ENABLE_OPENGLES
if (is_external_texture) {
pipeline = renderer.GetTiledTextureExternalPipeline(pipeline_options);
}
#endif // IMPELLER_ENABLE_OPENGLES

if (!pipeline) {
if (strict_source_rect_enabled_) {
pipeline = renderer.GetTextureStrictSrcPipeline(pipeline_options);
} else {
pipeline = renderer.GetTexturePipeline(pipeline_options);
}
}
pass.SetPipeline(pipeline);
pass.SetPipeline(strict_source_rect_enabled_
? renderer.GetTextureStrictSrcPipeline(pipeline_options)
: renderer.GetTexturePipeline(pipeline_options));

pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));

if (is_external_texture) {
FSExternal::FragInfo frag_info;
frag_info.x_tile_mode =
static_cast<int>(sampler_descriptor_.width_address_mode);
frag_info.y_tile_mode =
static_cast<int>(sampler_descriptor_.height_address_mode);
frag_info.alpha = capture.AddScalar("Alpha", GetOpacity());

auto sampler_descriptor = sampler_descriptor_;
// OES_EGL_image_external states that only CLAMP_TO_EDGE is valid, so
// we emulate all other tile modes here by remapping the texture
// coordinates.
sampler_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge;
sampler_descriptor.height_address_mode = SamplerAddressMode::kClampToEdge;

FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
pass, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
sampler_descriptor));
} else if (strict_source_rect_enabled_) {
if (strict_source_rect_enabled_) {
// For a strict source rect, shrink the texture coordinate range by half a
// texel to ensure that linear filtering does not sample anything outside
// the source rect bounds.
Expand Down
39 changes: 10 additions & 29 deletions impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include "fml/logging.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/tiled_texture_fill.frag.h"
#include "impeller/entity/tiled_texture_fill_external.frag.h"
#include "impeller/renderer/render_pass.h"
Expand Down Expand Up @@ -116,7 +114,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
return true;
}

using VS = TextureFillVertexShader;
using VS = TextureUvFillVertexShader;
using FS = TiledTextureFillFragmentShader;
using FSExternal = TiledTextureFillExternalFragmentShader;

Expand All @@ -128,26 +126,22 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
bool is_external_texture =
texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES;

bool uses_emulated_tile_mode =
UsesEmulatedTileMode(renderer.GetDeviceCapabilities());

VS::FrameInfo frame_info;
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frame_info.uv_transform =
Rect::MakeSize(texture_size).GetNormalizingTransform() *
GetInverseEffectTransform();

PipelineBuilderMethod pipeline_method;

#ifdef IMPELLER_ENABLE_OPENGLES
if (is_external_texture) {
pipeline_method = &ContentContext::GetTiledTextureExternalPipeline;
} else {
pipeline_method = uses_emulated_tile_mode
? &ContentContext::GetTiledTexturePipeline
: &ContentContext::GetTexturePipeline;
pipeline_method = &ContentContext::GetTiledTexturePipeline;
}
#else
pipeline_method = uses_emulated_tile_mode
? &ContentContext::GetTiledTexturePipeline
: &ContentContext::GetTexturePipeline;
pipeline_method = &ContentContext::GetTiledTexturePipeline;
#endif // IMPELLER_ENABLE_OPENGLES

PipelineBuilderCallback pipeline_callback =
Expand All @@ -156,33 +150,23 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
};
return ColorSourceContents::DrawGeometry<VS>(
renderer, entity, pass, pipeline_callback, frame_info,
[this, &renderer, &is_external_texture,
&uses_emulated_tile_mode](RenderPass& pass) {
[this, &renderer, &is_external_texture](RenderPass& pass) {
auto& host_buffer = renderer.GetTransientsBuffer();

if (uses_emulated_tile_mode) {
pass.SetCommandLabel("TiledTextureFill");
} else {
pass.SetCommandLabel("TextureFill");
}
pass.SetCommandLabel("TextureFill");

if (is_external_texture) {
FSExternal::FragInfo frag_info;
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
frag_info.alpha = GetOpacityFactor();
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
} else if (uses_emulated_tile_mode) {
} else {
FS::FragInfo frag_info;
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
frag_info.alpha = GetOpacityFactor();
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
} else {
TextureFillFragmentShader::FragInfo frag_info;
frag_info.alpha = GetOpacityFactor();
TextureFillFragmentShader::BindFragInfo(
pass, host_buffer.EmplaceUniform(frag_info));
}

if (is_external_texture) {
Expand Down Expand Up @@ -221,10 +205,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
}

return true;
},
/*enable_uvs=*/true,
/*texture_coverage=*/Rect::MakeSize(texture_size),
/*effect_transform=*/GetInverseEffectTransform());
});
}

std::optional<Snapshot> TiledTextureContents::RenderToSnapshot(
Expand Down
Loading