Skip to content

Commit

Permalink
[Impeller] organize texture shaders / delete blend.frag + external_te…
Browse files Browse the repository at this point in the history
…xture_fill (#52137)

* Deletes blend.frag/vert . This was identical to the existing texture_fill shader.
* Move alpha to frag info and stop passing as varying.
~~* Deletes strict src rect fragment shader. We should be able to compute the UVs on the CPU, which is trivial since this is only used for rectangular draws.~~
* Deletes external texture fill in favor of tiled texture external fill. The former shader is marginally faster, but we don't use it since we don't correctly check for the right extensions needed for non-emulated sampling modes with external textures on GLES. Easier to just always use emulated tile modes
  • Loading branch information
jonahwilliams authored Apr 19, 2024
1 parent a9a6f59 commit 55670b7
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 945 deletions.
6 changes: 0 additions & 6 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -40372,8 +40372,6 @@ ORIGIN: ../../../flutter/impeller/entity/render_target_cache.cc + ../../../flutt
ORIGIN: ../../../flutter/impeller/entity/render_target_cache.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/advanced_blend.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/advanced_blend.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/blend.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/blend.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/blend_select.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert + ../../../flutter/LICENSE
Expand Down Expand Up @@ -40418,7 +40416,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.frag + ../../../flut
ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flutter/LICENSE
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_external.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag + ../../../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
Expand Down Expand Up @@ -43255,8 +43252,6 @@ FILE: ../../../flutter/impeller/entity/render_target_cache.cc
FILE: ../../../flutter/impeller/entity/render_target_cache.h
FILE: ../../../flutter/impeller/entity/shaders/blending/advanced_blend.frag
FILE: ../../../flutter/impeller/entity/shaders/blending/advanced_blend.vert
FILE: ../../../flutter/impeller/entity/shaders/blending/blend.frag
FILE: ../../../flutter/impeller/entity/shaders/blending/blend.vert
FILE: ../../../flutter/impeller/entity/shaders/blending/blend_select.glsl
FILE: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.frag
FILE: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert
Expand Down Expand Up @@ -43301,7 +43296,6 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.frag
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_external.frag
FILE: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag
Expand Down
5 changes: 1 addition & 4 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ impeller_shaders("entity_shaders") {
shaders = [
"shaders/blending/advanced_blend.vert",
"shaders/blending/advanced_blend.frag",
"shaders/blending/blend.frag",
"shaders/blending/blend.vert",
"shaders/border_mask_blur.frag",
"shaders/border_mask_blur.vert",
"shaders/clip.frag",
Expand All @@ -41,10 +39,9 @@ impeller_shaders("entity_shaders") {
"shaders/gradients/sweep_gradient_fill.frag",
"shaders/texture_fill.frag",
"shaders/texture_fill.vert",
"shaders/texture_fill_external.frag",
"shaders/texture_fill_strict_src.frag",
"shaders/tiled_texture_fill.frag",
"shaders/tiled_texture_fill_external.frag",
"shaders/texture_fill_strict_src.frag",
"shaders/vertices.frag",
"shaders/blending/porter_duff_blend.frag",
"shaders/blending/porter_duff_blend.vert",
Expand Down
6 changes: 5 additions & 1 deletion impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,16 @@ bool AtlasTextureContents::Render(const ContentContext& renderer,
VS::FrameInfo frame_info;
frame_info.mvp = entity.GetShaderTransform(pass);
frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
frame_info.alpha = alpha_;

auto options = OptionsFromPassAndEntity(pass, entity);
pass.SetPipeline(renderer.GetTexturePipeline(options));
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.alpha = alpha_;

FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
FS::BindTextureSampler(pass, texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
parent_.GetSamplerDescriptor()));
Expand Down
4 changes: 0 additions & 4 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ ContentContext::ContentContext(
{static_cast<Scalar>(BlendSelectValues::kSoftLight), supports_decal});

rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
texture_blend_pipelines_.CreateDefault(*context_, options);
texture_strict_src_pipelines_.CreateDefault(*context_, options);
position_uv_pipelines_.CreateDefault(*context_, options);
tiled_texture_pipelines_.CreateDefault(*context_, options);
Expand All @@ -448,9 +447,6 @@ ContentContext::ContentContext(
{supports_decal});
// GLES only shader that is unsupported on macOS.
#if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_MACOSX)
if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) {
texture_external_pipelines_.CreateDefault(*context_, options);
}
if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) {
tiled_texture_external_pipelines_.CreateDefault(*context_, options);
}
Expand Down
23 changes: 0 additions & 23 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include "impeller/entity/checkerboard.vert.h"
#endif // IMPELLER_DEBUG

#include "impeller/entity/blend.frag.h"
#include "impeller/entity/blend.vert.h"
#include "impeller/entity/border_mask_blur.frag.h"
#include "impeller/entity/border_mask_blur.vert.h"
#include "impeller/entity/clip.frag.h"
Expand Down Expand Up @@ -84,7 +82,6 @@
#include "impeller/entity/framebuffer_blend.vert.h"

#ifdef IMPELLER_ENABLE_OPENGLES
#include "impeller/entity/texture_fill_external.frag.h"
#include "impeller/entity/tiled_texture_fill_external.frag.h"
#endif // IMPELLER_ENABLE_OPENGLES

Expand Down Expand Up @@ -127,8 +124,6 @@ using SweepGradientSSBOFillPipeline =
SweepGradientSsboFillFragmentShader>;
using RRectBlurPipeline =
RenderPipelineHandle<RrectBlurVertexShader, RrectBlurFragmentShader>;
using BlendPipeline =
RenderPipelineHandle<BlendVertexShader, BlendFragmentShader>;
using TexturePipeline =
RenderPipelineHandle<TextureFillVertexShader, TextureFillFragmentShader>;
using TextureStrictSrcPipeline =
Expand Down Expand Up @@ -261,10 +256,6 @@ using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;

#ifdef IMPELLER_ENABLE_OPENGLES
using TextureExternalPipeline =
RenderPipelineHandle<TextureFillVertexShader,
TextureFillExternalFragmentShader>;

using TiledTextureExternalPipeline =
RenderPipelineHandle<TextureFillVertexShader,
TiledTextureFillExternalFragmentShader>;
Expand Down Expand Up @@ -468,11 +459,6 @@ class ContentContext {
return GetPipeline(solid_fill_pipelines_, opts);
}

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

std::shared_ptr<Pipeline<PipelineDescriptor>> GetTexturePipeline(
ContentContextOptions opts) const {
return GetPipeline(texture_pipelines_, opts);
Expand All @@ -484,13 +470,6 @@ class ContentContext {
}

#ifdef IMPELLER_ENABLE_OPENGLES
std::shared_ptr<Pipeline<PipelineDescriptor>> GetTextureExternalPipeline(
ContentContextOptions opts) const {
FML_DCHECK(GetContext()->GetBackendType() ==
Context::BackendType::kOpenGLES);
return GetPipeline(texture_external_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetTiledTextureExternalPipeline(
ContentContextOptions opts) const {
FML_DCHECK(GetContext()->GetBackendType() ==
Expand Down Expand Up @@ -947,11 +926,9 @@ class ContentContext {
mutable Variants<SweepGradientSSBOFillPipeline>
sweep_gradient_ssbo_fill_pipelines_;
mutable Variants<RRectBlurPipeline> rrect_blur_pipelines_;
mutable Variants<BlendPipeline> texture_blend_pipelines_;
mutable Variants<TexturePipeline> texture_pipelines_;
mutable Variants<TextureStrictSrcPipeline> texture_strict_src_pipelines_;
#ifdef IMPELLER_ENABLE_OPENGLES
mutable Variants<TextureExternalPipeline> texture_external_pipelines_;
mutable Variants<TiledTextureExternalPipeline>
tiled_texture_external_pipelines_;
#endif // IMPELLER_ENABLE_OPENGLES
Expand Down
12 changes: 6 additions & 6 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ static std::optional<Entity> PipelineBlend(
std::optional<Color> foreground_color,
ColorFilterContents::AbsorbOpacity absorb_opacity,
std::optional<Scalar> alpha) {
using VS = BlendPipeline::VertexShader;
using FS = BlendPipeline::FragmentShader;
using VS = TexturePipeline::VertexShader;
using FS = TexturePipeline::FragmentShader;

auto dst_snapshot =
inputs[0]->GetSnapshot("PipelineBlend(Dst)", renderer, entity);
Expand Down Expand Up @@ -552,7 +552,7 @@ static std::optional<Entity> PipelineBlend(
const std::unique_ptr<const Sampler>& sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
input->sampler_descriptor);
FS::BindTextureSamplerSrc(pass, input->texture, sampler);
FS::BindTextureSampler(pass, input->texture, sampler);

auto size = input->texture->GetSize();
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
Expand All @@ -572,7 +572,7 @@ static std::optional<Entity> PipelineBlend(
input->texture->GetYCoordScale();

FS::FragInfo frag_info;
frag_info.input_alpha =
frag_info.alpha =
absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
? input->opacity
: 1.0;
Expand All @@ -584,7 +584,7 @@ static std::optional<Entity> PipelineBlend(

// Draw the first texture using kSource.
options.blend_mode = BlendMode::kSource;
pass.SetPipeline(renderer.GetBlendPipeline(options));
pass.SetPipeline(renderer.GetTexturePipeline(options));
if (!add_blend_command(dst_snapshot)) {
return true;
}
Expand All @@ -593,7 +593,7 @@ static std::optional<Entity> PipelineBlend(

if (inputs.size() >= 2) {
options.blend_mode = blend_mode;
pass.SetPipeline(renderer.GetBlendPipeline(options));
pass.SetPipeline(renderer.GetTexturePipeline(options));

for (auto texture_i = inputs.begin() + 1; texture_i < inputs.end();
texture_i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass(
TextureFillVertexShader::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
frame_info.texture_sampler_y_coord_scale = 1.0;
frame_info.alpha = 1.0;

TextureFillFragmentShader::FragInfo frag_info;
frag_info.alpha = 1.0;

BindVertices<TextureFillVertexShader>(pass, host_buffer,
{
Expand All @@ -111,6 +113,8 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass(
linear_sampler_descriptor.min_filter = MinMagFilter::kLinear;
TextureFillVertexShader::BindFrameInfo(
pass, host_buffer.EmplaceUniform(frame_info));
TextureFillFragmentShader::BindFragInfo(
pass, host_buffer.EmplaceUniform(frag_info));
TextureFillFragmentShader::BindTextureSampler(
pass, input_texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
Expand Down
39 changes: 29 additions & 10 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "impeller/entity/entity.h"
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/texture_fill_external.frag.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 @@ -113,8 +114,8 @@ bool TextureContents::Render(const ContentContext& renderer,

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

if (destination_rect_.IsEmpty() || source_rect_.IsEmpty() ||
texture_ == nullptr || texture_->GetSize().IsEmpty()) {
Expand All @@ -129,7 +130,6 @@ bool TextureContents::Render(const ContentContext& renderer,
Rect::MakeSize(texture_->GetSize()).Project(source_rect);

VertexBufferBuilder<VS::PerVertexData> vertex_builder;

auto destination_rect =
capture.AddRect("Destination rect", destination_rect_);
vertex_builder.AddVertices({
Expand All @@ -144,7 +144,6 @@ bool TextureContents::Render(const ContentContext& renderer,
VS::FrameInfo frame_info;
frame_info.mvp = entity.GetShaderTransform(pass);
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frame_info.alpha = capture.AddScalar("Alpha", GetOpacity());

#ifdef IMPELLER_DEBUG
if (label_.empty()) {
Expand All @@ -163,7 +162,7 @@ bool TextureContents::Render(const ContentContext& renderer,
std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
#ifdef IMPELLER_ENABLE_OPENGLES
if (is_external_texture) {
pipeline = renderer.GetTextureExternalPipeline(pipeline_options);
pipeline = renderer.GetTiledTextureExternalPipeline(pipeline_options);
}
#endif // IMPELLER_ENABLE_OPENGLES

Expand All @@ -178,26 +177,46 @@ bool TextureContents::Render(const ContentContext& renderer,

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_));
sampler_descriptor));
} else 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.
auto strict_texture_coords =
Rect::MakeSize(texture_->GetSize()).Project(source_rect.Expand(-0.5));

FSStrictSrc::FragInfo frag_info;
FSStrict::FragInfo frag_info;
frag_info.source_rect = Vector4(strict_texture_coords.GetLTRB());
FSStrictSrc::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
FSStrictSrc::BindTextureSampler(
frag_info.alpha = capture.AddScalar("Alpha", GetOpacity());
FSStrict::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
FSStrict::BindTextureSampler(
pass, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
sampler_descriptor_));
} else {
FS::FragInfo frag_info;
frag_info.alpha = capture.AddScalar("Alpha", GetOpacity());
FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
FS::BindTextureSampler(
pass, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
Expand Down
9 changes: 8 additions & 1 deletion impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#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"
Expand Down Expand Up @@ -132,7 +133,6 @@ bool TiledTextureContents::Render(const ContentContext& renderer,

VS::FrameInfo frame_info;
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frame_info.alpha = GetOpacityFactor();

PipelineBuilderMethod pipeline_method;

Expand Down Expand Up @@ -170,12 +170,19 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
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) {
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
4 changes: 3 additions & 1 deletion impeller/entity/contents/vertices_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
frame_info.mvp = geometry_result.transform;
frame_info.texture_sampler_y_coord_scale =
snapshot->texture->GetYCoordScale();
frame_info.alpha = alpha_ * snapshot->opacity;
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.alpha = alpha_ * snapshot->opacity;
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
FS::BindTextureSampler(pass, snapshot->texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
snapshot->sampler_descriptor));
Expand Down
Loading

0 comments on commit 55670b7

Please sign in to comment.