Skip to content

Commit d1ecf22

Browse files
committed
Revert "[Impeller] compute UVs in vertex stage. (flutter#52106)"
This reverts commit 1ac3ce3.
1 parent 8affe44 commit d1ecf22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1107
-405
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40395,6 +40395,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert + ../
4039540395
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag + ../../../flutter/LICENSE
4039640396
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag + ../../../flutter/LICENSE
4039740397
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
40398+
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/uv.comp + ../../../flutter/LICENSE
4039840399
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
4039940400
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
4040040401
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
@@ -40416,7 +40417,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flut
4041640417
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.frag + ../../../flutter/LICENSE
4041740418
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.vert + ../../../flutter/LICENSE
4041840419
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag + ../../../flutter/LICENSE
40419-
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert + ../../../flutter/LICENSE
4042040420
ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag + ../../../flutter/LICENSE
4042140421
ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag + ../../../flutter/LICENSE
4042240422
ORIGIN: ../../../flutter/impeller/entity/shaders/vertices.frag + ../../../flutter/LICENSE
@@ -43275,6 +43275,7 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert
4327543275
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag
4327643276
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag
4327743277
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
43278+
FILE: ../../../flutter/impeller/entity/shaders/geometry/uv.comp
4327843279
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
4327943280
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
4328043281
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag
@@ -43296,7 +43297,6 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert
4329643297
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag
4329743298
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert
4329843299
FILE: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag
43299-
FILE: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert
4330043300
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag
4330143301
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag
4330243302
FILE: ../../../flutter/impeller/entity/shaders/vertices.frag

impeller/entity/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ impeller_shaders("entity_shaders") {
3939
"shaders/gradients/sweep_gradient_fill.frag",
4040
"shaders/texture_fill.frag",
4141
"shaders/texture_fill.vert",
42-
"shaders/texture_uv_fill.vert",
4342
"shaders/tiled_texture_fill.frag",
4443
"shaders/tiled_texture_fill_external.frag",
4544
"shaders/texture_fill_strict_src.frag",
@@ -80,6 +79,7 @@ impeller_shaders("modern_entity_shaders") {
8079
"shaders/gradients/radial_gradient_ssbo_fill.frag",
8180
"shaders/gradients/sweep_gradient_ssbo_fill.frag",
8281
"shaders/geometry/points.comp",
82+
"shaders/geometry/uv.comp",
8383
]
8484
}
8585

impeller/entity/contents/clip_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <memory>
1010
#include <vector>
1111

12+
#include "flutter/fml/macros.h"
1213
#include "impeller/entity/contents/contents.h"
1314
#include "impeller/entity/entity.h"
1415
#include "impeller/entity/geometry/geometry.h"

impeller/entity/contents/color_source_contents.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ class ColorSourceContents : public Contents {
118118
RenderPass& pass,
119119
const PipelineBuilderCallback& pipeline_callback,
120120
typename VertexShaderT::FrameInfo frame_info,
121-
const BindFragmentCallback& bind_fragment_callback) const {
121+
const BindFragmentCallback& bind_fragment_callback,
122+
bool enable_uvs = false,
123+
Rect texture_coverage = {},
124+
const Matrix& effect_transform = {}) const {
122125
auto options = OptionsFromPassAndEntity(pass, entity);
123126

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

180183
GeometryResult geometry_result =
181-
geometry.GetPositionBuffer(renderer, entity, pass);
184+
enable_uvs
185+
? geometry.GetPositionUVBuffer(texture_coverage, effect_transform,
186+
renderer, entity, pass)
187+
: geometry.GetPositionBuffer(renderer, entity, pass);
182188
if (geometry_result.vertex_buffer.vertex_count == 0u) {
183189
return true;
184190
}

impeller/entity/contents/content_context.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ ContentContext::ContentContext(
260260
? std::make_shared<RenderTargetCache>(
261261
context_->GetResourceAllocator())
262262
: std::move(render_target_allocator)),
263-
host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())) {
263+
host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())),
264+
pending_command_buffers_(std::make_unique<PendingCommandBuffers>()) {
264265
if (!context_ || !context_->IsValid()) {
265266
return;
266267
}
@@ -421,7 +422,8 @@ ContentContext::ContentContext(
421422

422423
rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
423424
texture_strict_src_pipelines_.CreateDefault(*context_, options);
424-
tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal});
425+
position_uv_pipelines_.CreateDefault(*context_, options);
426+
tiled_texture_pipelines_.CreateDefault(*context_, options);
425427
kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip);
426428
kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip);
427429
border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
@@ -454,6 +456,11 @@ ContentContext::ContentContext(
454456
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
455457
point_field_compute_pipelines_ =
456458
context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
459+
460+
auto uv_pipeline_desc =
461+
UvComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
462+
uv_compute_pipelines_ =
463+
context_->GetPipelineLibrary()->GetPipeline(uv_pipeline_desc).Get();
457464
}
458465

459466
is_valid_ = true;

impeller/entity/contents/content_context.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
#include "impeller/entity/texture_fill.frag.h"
5858
#include "impeller/entity/texture_fill.vert.h"
5959
#include "impeller/entity/texture_fill_strict_src.frag.h"
60-
#include "impeller/entity/texture_uv_fill.vert.h"
6160
#include "impeller/entity/tiled_texture_fill.frag.h"
61+
#include "impeller/entity/uv.comp.h"
6262
#include "impeller/entity/vertices.frag.h"
6363
#include "impeller/entity/yuv_to_rgb_filter.frag.h"
6464

@@ -129,8 +129,10 @@ using TexturePipeline =
129129
using TextureStrictSrcPipeline =
130130
RenderPipelineHandle<TextureFillVertexShader,
131131
TextureFillStrictSrcFragmentShader>;
132+
using PositionUVPipeline = RenderPipelineHandle<TextureFillVertexShader,
133+
TiledTextureFillFragmentShader>;
132134
using TiledTexturePipeline =
133-
RenderPipelineHandle<TextureUvFillVertexShader,
135+
RenderPipelineHandle<TextureFillVertexShader,
134136
TiledTextureFillFragmentShader>;
135137
using KernelDecalPipeline =
136138
RenderPipelineHandle<KernelVertexShader, KernelDecalFragmentShader>;
@@ -251,13 +253,20 @@ using FramebufferBlendSoftLightPipeline =
251253

252254
/// Geometry Pipelines
253255
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
256+
using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;
254257

255258
#ifdef IMPELLER_ENABLE_OPENGLES
256259
using TiledTextureExternalPipeline =
257-
RenderPipelineHandle<TextureUvFillVertexShader,
260+
RenderPipelineHandle<TextureFillVertexShader,
258261
TiledTextureFillExternalFragmentShader>;
259262
#endif // IMPELLER_ENABLE_OPENGLES
260263

264+
// A struct used to isolate command buffer storage from the content
265+
// context options to preserve const-ness.
266+
struct PendingCommandBuffers {
267+
std::vector<std::shared_ptr<CommandBuffer>> command_buffers;
268+
};
269+
261270
/// Pipeline state configuration.
262271
///
263272
/// Each unique combination of these options requires a different pipeline state
@@ -469,6 +478,11 @@ class ContentContext {
469478
}
470479
#endif // IMPELLER_ENABLE_OPENGLES
471480

481+
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPositionUVPipeline(
482+
ContentContextOptions opts) const {
483+
return GetPipeline(position_uv_pipelines_, opts);
484+
}
485+
472486
std::shared_ptr<Pipeline<PipelineDescriptor>> GetTiledTexturePipeline(
473487
ContentContextOptions opts) const {
474488
return GetPipeline(tiled_texture_pipelines_, opts);
@@ -713,6 +727,12 @@ class ContentContext {
713727
return point_field_compute_pipelines_;
714728
}
715729

730+
std::shared_ptr<Pipeline<ComputePipelineDescriptor>> GetUvComputePipeline()
731+
const {
732+
FML_DCHECK(GetDeviceCapabilities().SupportsCompute());
733+
return uv_compute_pipelines_;
734+
}
735+
716736
std::shared_ptr<Context> GetContext() const;
717737

718738
const Capabilities& GetDeviceCapabilities() const;
@@ -912,6 +932,7 @@ class ContentContext {
912932
mutable Variants<TiledTextureExternalPipeline>
913933
tiled_texture_external_pipelines_;
914934
#endif // IMPELLER_ENABLE_OPENGLES
935+
mutable Variants<PositionUVPipeline> position_uv_pipelines_;
915936
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
916937
mutable Variants<KernelDecalPipeline> kernel_decal_pipelines_;
917938
mutable Variants<KernelPipeline> kernel_nodecal_pipelines_;
@@ -976,6 +997,8 @@ class ContentContext {
976997
framebuffer_blend_softlight_pipelines_;
977998
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
978999
point_field_compute_pipelines_;
1000+
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
1001+
uv_compute_pipelines_;
9791002

9801003
template <class TypedPipeline>
9811004
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
@@ -1035,6 +1058,7 @@ class ContentContext {
10351058
#endif // IMPELLER_ENABLE_3D
10361059
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
10371060
std::shared_ptr<HostBuffer> host_buffer_;
1061+
std::unique_ptr<PendingCommandBuffers> pending_command_buffers_;
10381062
bool wireframe_ = false;
10391063

10401064
ContentContext(const ContentContext&) = delete;

impeller/entity/contents/texture_contents.cc

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "impeller/entity/texture_fill.frag.h"
1515
#include "impeller/entity/texture_fill.vert.h"
1616
#include "impeller/entity/texture_fill_strict_src.frag.h"
17+
#include "impeller/entity/tiled_texture_fill_external.frag.h"
1718
#include "impeller/geometry/constants.h"
1819
#include "impeller/renderer/render_pass.h"
1920
#include "impeller/renderer/vertex_buffer_builder.h"
@@ -113,16 +114,16 @@ bool TextureContents::Render(const ContentContext& renderer,
113114

114115
using VS = TextureFillVertexShader;
115116
using FS = TextureFillFragmentShader;
117+
using FSExternal = TiledTextureFillExternalFragmentShader;
116118
using FSStrict = TextureFillStrictSrcFragmentShader;
117119

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

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

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

161-
pass.SetPipeline(strict_source_rect_enabled_
162-
? renderer.GetTextureStrictSrcPipeline(pipeline_options)
163-
: renderer.GetTexturePipeline(pipeline_options));
162+
std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
163+
#ifdef IMPELLER_ENABLE_OPENGLES
164+
if (is_external_texture) {
165+
pipeline = renderer.GetTiledTextureExternalPipeline(pipeline_options);
166+
}
167+
#endif // IMPELLER_ENABLE_OPENGLES
168+
169+
if (!pipeline) {
170+
if (strict_source_rect_enabled_) {
171+
pipeline = renderer.GetTextureStrictSrcPipeline(pipeline_options);
172+
} else {
173+
pipeline = renderer.GetTexturePipeline(pipeline_options);
174+
}
175+
}
176+
pass.SetPipeline(pipeline);
164177

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

168-
if (strict_source_rect_enabled_) {
181+
if (is_external_texture) {
182+
FSExternal::FragInfo frag_info;
183+
frag_info.x_tile_mode =
184+
static_cast<int>(sampler_descriptor_.width_address_mode);
185+
frag_info.y_tile_mode =
186+
static_cast<int>(sampler_descriptor_.height_address_mode);
187+
frag_info.alpha = capture.AddScalar("Alpha", GetOpacity());
188+
189+
auto sampler_descriptor = sampler_descriptor_;
190+
// OES_EGL_image_external states that only CLAMP_TO_EDGE is valid, so
191+
// we emulate all other tile modes here by remapping the texture
192+
// coordinates.
193+
sampler_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge;
194+
sampler_descriptor.height_address_mode = SamplerAddressMode::kClampToEdge;
195+
196+
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
197+
FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
198+
pass, texture_,
199+
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
200+
sampler_descriptor));
201+
} else if (strict_source_rect_enabled_) {
169202
// For a strict source rect, shrink the texture coordinate range by half a
170203
// texel to ensure that linear filtering does not sample anything outside
171204
// the source rect bounds.

impeller/entity/contents/tiled_texture_contents.cc

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "fml/logging.h"
88
#include "impeller/entity/contents/content_context.h"
9+
#include "impeller/entity/texture_fill.frag.h"
10+
#include "impeller/entity/texture_fill.vert.h"
911
#include "impeller/entity/tiled_texture_fill.frag.h"
1012
#include "impeller/entity/tiled_texture_fill_external.frag.h"
1113
#include "impeller/renderer/render_pass.h"
@@ -114,7 +116,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
114116
return true;
115117
}
116118

117-
using VS = TextureUvFillVertexShader;
119+
using VS = TextureFillVertexShader;
118120
using FS = TiledTextureFillFragmentShader;
119121
using FSExternal = TiledTextureFillExternalFragmentShader;
120122

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

131+
bool uses_emulated_tile_mode =
132+
UsesEmulatedTileMode(renderer.GetDeviceCapabilities());
133+
129134
VS::FrameInfo frame_info;
130135
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
131-
frame_info.uv_transform =
132-
Rect::MakeSize(texture_size).GetNormalizingTransform() *
133-
GetInverseEffectTransform();
134136

135137
PipelineBuilderMethod pipeline_method;
136138

137139
#ifdef IMPELLER_ENABLE_OPENGLES
138140
if (is_external_texture) {
139141
pipeline_method = &ContentContext::GetTiledTextureExternalPipeline;
140142
} else {
141-
pipeline_method = &ContentContext::GetTiledTexturePipeline;
143+
pipeline_method = uses_emulated_tile_mode
144+
? &ContentContext::GetTiledTexturePipeline
145+
: &ContentContext::GetTexturePipeline;
142146
}
143147
#else
144-
pipeline_method = &ContentContext::GetTiledTexturePipeline;
148+
pipeline_method = uses_emulated_tile_mode
149+
? &ContentContext::GetTiledTexturePipeline
150+
: &ContentContext::GetTexturePipeline;
145151
#endif // IMPELLER_ENABLE_OPENGLES
146152

147153
PipelineBuilderCallback pipeline_callback =
@@ -150,23 +156,33 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
150156
};
151157
return ColorSourceContents::DrawGeometry<VS>(
152158
renderer, entity, pass, pipeline_callback, frame_info,
153-
[this, &renderer, &is_external_texture](RenderPass& pass) {
159+
[this, &renderer, &is_external_texture,
160+
&uses_emulated_tile_mode](RenderPass& pass) {
154161
auto& host_buffer = renderer.GetTransientsBuffer();
155162

156-
pass.SetCommandLabel("TextureFill");
163+
if (uses_emulated_tile_mode) {
164+
pass.SetCommandLabel("TiledTextureFill");
165+
} else {
166+
pass.SetCommandLabel("TextureFill");
167+
}
157168

158169
if (is_external_texture) {
159170
FSExternal::FragInfo frag_info;
160171
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
161172
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
162173
frag_info.alpha = GetOpacityFactor();
163174
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
164-
} else {
175+
} else if (uses_emulated_tile_mode) {
165176
FS::FragInfo frag_info;
166177
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
167178
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
168179
frag_info.alpha = GetOpacityFactor();
169180
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
181+
} else {
182+
TextureFillFragmentShader::FragInfo frag_info;
183+
frag_info.alpha = GetOpacityFactor();
184+
TextureFillFragmentShader::BindFragInfo(
185+
pass, host_buffer.EmplaceUniform(frag_info));
170186
}
171187

172188
if (is_external_texture) {
@@ -205,7 +221,10 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
205221
}
206222

207223
return true;
208-
});
224+
},
225+
/*enable_uvs=*/true,
226+
/*texture_coverage=*/Rect::MakeSize(texture_size),
227+
/*effect_transform=*/GetInverseEffectTransform());
209228
}
210229

211230
std::optional<Snapshot> TiledTextureContents::RenderToSnapshot(

0 commit comments

Comments
 (0)