Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ea438cd

Browse files
author
Jonah Williams
authored
[Impeller] Reland: Compute UVs in vertex stage. (#52303)
Compute texture UVs in the vertex stage. Reland of #52106 which was reverted to investigate golden failures during the x64 to arm64 mac switch.
1 parent 0aeddbb commit ea438cd

40 files changed

+419
-1046
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40397,7 +40397,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert + ../
4039740397
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag + ../../../flutter/LICENSE
4039840398
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag + ../../../flutter/LICENSE
4039940399
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
40400-
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/uv.comp + ../../../flutter/LICENSE
4040140400
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
4040240401
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
4040340402
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
@@ -40419,6 +40418,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flut
4041940418
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.frag + ../../../flutter/LICENSE
4042040419
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.vert + ../../../flutter/LICENSE
4042140420
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag + ../../../flutter/LICENSE
40421+
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert + ../../../flutter/LICENSE
4042240422
ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag + ../../../flutter/LICENSE
4042340423
ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag + ../../../flutter/LICENSE
4042440424
ORIGIN: ../../../flutter/impeller/entity/shaders/vertices.frag + ../../../flutter/LICENSE
@@ -43279,7 +43279,6 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert
4327943279
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag
4328043280
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag
4328143281
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
43282-
FILE: ../../../flutter/impeller/entity/shaders/geometry/uv.comp
4328343282
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
4328443283
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
4328543284
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag
@@ -43301,6 +43300,7 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert
4330143300
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag
4330243301
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert
4330343302
FILE: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag
43303+
FILE: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert
4330443304
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag
4330543305
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag
4330643306
FILE: ../../../flutter/impeller/entity/shaders/vertices.frag

impeller/aiks/canvas.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,14 +901,12 @@ static bool UseColorSourceContents(
901901
const std::shared_ptr<VerticesGeometry>& vertices,
902902
const Paint& paint) {
903903
// If there are no vertex color or texture coordinates. Or if there
904-
// are vertex coordinates then only if the contents are an image or
905-
// a solid color.
904+
// are vertex coordinates but its just a color.
906905
if (vertices->HasVertexColors()) {
907906
return false;
908907
}
909908
if (vertices->HasTextureCoordinates() &&
910-
(paint.color_source.GetType() == ColorSource::Type::kImage ||
911-
paint.color_source.GetType() == ColorSource::Type::kColor)) {
909+
(paint.color_source.GetType() == ColorSource::Type::kColor)) {
912910
return true;
913911
}
914912
return !vertices->HasTextureCoordinates();
@@ -928,8 +926,7 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
928926
entity.SetTransform(GetCurrentTransform());
929927
entity.SetBlendMode(paint.blend_mode);
930928

931-
// If there are no vertex color or texture coordinates. Or if there
932-
// are vertex coordinates then only if the contents are an image.
929+
// If there are no vertex colors.
933930
if (UseColorSourceContents(vertices, paint)) {
934931
entity.SetContents(CreateContentsForGeometryWithFilters(paint, vertices));
935932
AddRenderEntityToCurrentPass(std::move(entity));
@@ -945,7 +942,6 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
945942
contents->SetBlendMode(blend_mode);
946943
contents->SetAlpha(paint.color.alpha);
947944
contents->SetGeometry(vertices);
948-
949945
contents->SetEffectTransform(image_data.effect_transform);
950946
contents->SetTexture(image_data.texture);
951947
contents->SetTileMode(image_data.x_tile_mode, image_data.y_tile_mode);

impeller/entity/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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",
4243
"shaders/tiled_texture_fill.frag",
4344
"shaders/tiled_texture_fill_external.frag",
4445
"shaders/texture_fill_strict_src.frag",
@@ -81,7 +82,6 @@ impeller_shaders("modern_entity_shaders") {
8182
"shaders/gradients/radial_gradient_ssbo_fill.frag",
8283
"shaders/gradients/sweep_gradient_ssbo_fill.frag",
8384
"shaders/geometry/points.comp",
84-
"shaders/geometry/uv.comp",
8585
]
8686
}
8787

impeller/entity/contents/clip_contents.h

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

12-
#include "flutter/fml/macros.h"
1312
#include "impeller/entity/contents/contents.h"
1413
#include "impeller/entity/entity.h"
1514
#include "impeller/entity/geometry/geometry.h"

impeller/entity/contents/color_source_contents.h

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

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

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

impeller/entity/contents/content_context.cc

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

423422
rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
424423
texture_strict_src_pipelines_.CreateDefault(*context_, options);
425-
position_uv_pipelines_.CreateDefault(*context_, options);
426-
tiled_texture_pipelines_.CreateDefault(*context_, options);
424+
tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal});
427425
kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip);
428426
kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip);
429427
border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
@@ -445,7 +443,7 @@ ContentContext::ContentContext(
445443
yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip);
446444
porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
447445
{supports_decal});
448-
vertices_uber_shader_.CreateDefault(*context_, options);
446+
vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal});
449447
// GLES only shader that is unsupported on macOS.
450448
#if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_MACOSX)
451449
if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) {
@@ -457,11 +455,6 @@ ContentContext::ContentContext(
457455
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
458456
point_field_compute_pipelines_ =
459457
context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
460-
461-
auto uv_pipeline_desc =
462-
UvComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
463-
uv_compute_pipelines_ =
464-
context_->GetPipelineLibrary()->GetPipeline(uv_pipeline_desc).Get();
465458
}
466459

467460
is_valid_ = true;

impeller/entity/contents/content_context.h

Lines changed: 3 additions & 27 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"
6061
#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

@@ -132,10 +132,8 @@ using TexturePipeline =
132132
using TextureStrictSrcPipeline =
133133
RenderPipelineHandle<TextureFillVertexShader,
134134
TextureFillStrictSrcFragmentShader>;
135-
using PositionUVPipeline = RenderPipelineHandle<TextureFillVertexShader,
136-
TiledTextureFillFragmentShader>;
137135
using TiledTexturePipeline =
138-
RenderPipelineHandle<TextureFillVertexShader,
136+
RenderPipelineHandle<TextureUvFillVertexShader,
139137
TiledTextureFillFragmentShader>;
140138
using KernelDecalPipeline =
141139
RenderPipelineHandle<KernelVertexShader, KernelDecalFragmentShader>;
@@ -260,20 +258,13 @@ using VerticesUberShader =
260258

261259
/// Geometry Pipelines
262260
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
263-
using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;
264261

265262
#ifdef IMPELLER_ENABLE_OPENGLES
266263
using TiledTextureExternalPipeline =
267-
RenderPipelineHandle<TextureFillVertexShader,
264+
RenderPipelineHandle<TextureUvFillVertexShader,
268265
TiledTextureFillExternalFragmentShader>;
269266
#endif // IMPELLER_ENABLE_OPENGLES
270267

271-
// A struct used to isolate command buffer storage from the content
272-
// context options to preserve const-ness.
273-
struct PendingCommandBuffers {
274-
std::vector<std::shared_ptr<CommandBuffer>> command_buffers;
275-
};
276-
277268
/// Pipeline state configuration.
278269
///
279270
/// Each unique combination of these options requires a different pipeline state
@@ -485,11 +476,6 @@ class ContentContext {
485476
}
486477
#endif // IMPELLER_ENABLE_OPENGLES
487478

488-
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPositionUVPipeline(
489-
ContentContextOptions opts) const {
490-
return GetPipeline(position_uv_pipelines_, opts);
491-
}
492-
493479
std::shared_ptr<Pipeline<PipelineDescriptor>> GetTiledTexturePipeline(
494480
ContentContextOptions opts) const {
495481
return GetPipeline(tiled_texture_pipelines_, opts);
@@ -739,12 +725,6 @@ class ContentContext {
739725
return point_field_compute_pipelines_;
740726
}
741727

742-
std::shared_ptr<Pipeline<ComputePipelineDescriptor>> GetUvComputePipeline()
743-
const {
744-
FML_DCHECK(GetDeviceCapabilities().SupportsCompute());
745-
return uv_compute_pipelines_;
746-
}
747-
748728
std::shared_ptr<Context> GetContext() const;
749729

750730
const Capabilities& GetDeviceCapabilities() const;
@@ -944,7 +924,6 @@ class ContentContext {
944924
mutable Variants<TiledTextureExternalPipeline>
945925
tiled_texture_external_pipelines_;
946926
#endif // IMPELLER_ENABLE_OPENGLES
947-
mutable Variants<PositionUVPipeline> position_uv_pipelines_;
948927
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
949928
mutable Variants<KernelDecalPipeline> kernel_decal_pipelines_;
950929
mutable Variants<KernelPipeline> kernel_nodecal_pipelines_;
@@ -1010,8 +989,6 @@ class ContentContext {
1010989
mutable Variants<VerticesUberShader> vertices_uber_shader_;
1011990
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
1012991
point_field_compute_pipelines_;
1013-
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
1014-
uv_compute_pipelines_;
1015992

1016993
template <class TypedPipeline>
1017994
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
@@ -1071,7 +1048,6 @@ class ContentContext {
10711048
#endif // IMPELLER_ENABLE_3D
10721049
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
10731050
std::shared_ptr<HostBuffer> host_buffer_;
1074-
std::unique_ptr<PendingCommandBuffers> pending_command_buffers_;
10751051
bool wireframe_ = false;
10761052

10771053
ContentContext(const ContentContext&) = delete;

impeller/entity/contents/texture_contents.cc

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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"
1817
#include "impeller/geometry/constants.h"
1918
#include "impeller/renderer/render_pass.h"
2019
#include "impeller/renderer/vertex_buffer_builder.h"
@@ -114,16 +113,16 @@ bool TextureContents::Render(const ContentContext& renderer,
114113

115114
using VS = TextureFillVertexShader;
116115
using FS = TextureFillFragmentShader;
117-
using FSExternal = TiledTextureFillExternalFragmentShader;
118116
using FSStrict = TextureFillStrictSrcFragmentShader;
119117

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

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

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

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);
161+
pass.SetPipeline(strict_source_rect_enabled_
162+
? renderer.GetTextureStrictSrcPipeline(pipeline_options)
163+
: renderer.GetTexturePipeline(pipeline_options));
177164

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

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_) {
168+
if (strict_source_rect_enabled_) {
202169
// For a strict source rect, shrink the texture coordinate range by half a
203170
// texel to ensure that linear filtering does not sample anything outside
204171
// the source rect bounds.

0 commit comments

Comments
 (0)