Skip to content

Commit 1ac3ce3

Browse files
[Impeller] compute UVs in vertex stage. (flutter#52106)
Split the functionality of texture_fill and tiled_texture_fill vertex stages: * The former will accept uvs as part of the vertex data and pass it to the fragment stage. * The latter will compute the uv geometry in the vertex stage from the position and the normalizing transform. With this functionality, we can delete all of the CPU based uv computation code. Additionally, there is some clean up to remove support for external textures (which use the tiled texture mode) from the texture contents. The external textures are used with an image shader/draw rect by internal engine code and won't go down the drawImageRect path anymore.
1 parent 40110ec commit 1ac3ce3

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

+405
-1107
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40395,7 +40395,6 @@ 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
4039940398
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
4040040399
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
4040140400
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
@@ -40417,6 +40416,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flut
4041740416
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.frag + ../../../flutter/LICENSE
4041840417
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.vert + ../../../flutter/LICENSE
4041940418
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,7 +43275,6 @@ 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
4327943278
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
4328043279
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
4328143280
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag
@@ -43297,6 +43296,7 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert
4329743296
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag
4329843297
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert
4329943298
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,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",
@@ -79,7 +80,6 @@ impeller_shaders("modern_entity_shaders") {
7980
"shaders/gradients/radial_gradient_ssbo_fill.frag",
8081
"shaders/gradients/sweep_gradient_ssbo_fill.frag",
8182
"shaders/geometry/points.comp",
82-
"shaders/geometry/uv.comp",
8383
]
8484
}
8585

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: 2 additions & 9 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);
@@ -456,11 +454,6 @@ ContentContext::ContentContext(
456454
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
457455
point_field_compute_pipelines_ =
458456
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();
464457
}
465458

466459
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

@@ -129,10 +129,8 @@ using TexturePipeline =
129129
using TextureStrictSrcPipeline =
130130
RenderPipelineHandle<TextureFillVertexShader,
131131
TextureFillStrictSrcFragmentShader>;
132-
using PositionUVPipeline = RenderPipelineHandle<TextureFillVertexShader,
133-
TiledTextureFillFragmentShader>;
134132
using TiledTexturePipeline =
135-
RenderPipelineHandle<TextureFillVertexShader,
133+
RenderPipelineHandle<TextureUvFillVertexShader,
136134
TiledTextureFillFragmentShader>;
137135
using KernelDecalPipeline =
138136
RenderPipelineHandle<KernelVertexShader, KernelDecalFragmentShader>;
@@ -253,20 +251,13 @@ using FramebufferBlendSoftLightPipeline =
253251

254252
/// Geometry Pipelines
255253
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
256-
using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;
257254

258255
#ifdef IMPELLER_ENABLE_OPENGLES
259256
using TiledTextureExternalPipeline =
260-
RenderPipelineHandle<TextureFillVertexShader,
257+
RenderPipelineHandle<TextureUvFillVertexShader,
261258
TiledTextureFillExternalFragmentShader>;
262259
#endif // IMPELLER_ENABLE_OPENGLES
263260

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-
270261
/// Pipeline state configuration.
271262
///
272263
/// Each unique combination of these options requires a different pipeline state
@@ -478,11 +469,6 @@ class ContentContext {
478469
}
479470
#endif // IMPELLER_ENABLE_OPENGLES
480471

481-
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPositionUVPipeline(
482-
ContentContextOptions opts) const {
483-
return GetPipeline(position_uv_pipelines_, opts);
484-
}
485-
486472
std::shared_ptr<Pipeline<PipelineDescriptor>> GetTiledTexturePipeline(
487473
ContentContextOptions opts) const {
488474
return GetPipeline(tiled_texture_pipelines_, opts);
@@ -727,12 +713,6 @@ class ContentContext {
727713
return point_field_compute_pipelines_;
728714
}
729715

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

738718
const Capabilities& GetDeviceCapabilities() const;
@@ -932,7 +912,6 @@ class ContentContext {
932912
mutable Variants<TiledTextureExternalPipeline>
933913
tiled_texture_external_pipelines_;
934914
#endif // IMPELLER_ENABLE_OPENGLES
935-
mutable Variants<PositionUVPipeline> position_uv_pipelines_;
936915
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
937916
mutable Variants<KernelDecalPipeline> kernel_decal_pipelines_;
938917
mutable Variants<KernelPipeline> kernel_nodecal_pipelines_;
@@ -997,8 +976,6 @@ class ContentContext {
997976
framebuffer_blend_softlight_pipelines_;
998977
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
999978
point_field_compute_pipelines_;
1000-
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
1001-
uv_compute_pipelines_;
1002979

1003980
template <class TypedPipeline>
1004981
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
@@ -1058,7 +1035,6 @@ class ContentContext {
10581035
#endif // IMPELLER_ENABLE_3D
10591036
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
10601037
std::shared_ptr<HostBuffer> host_buffer_;
1061-
std::unique_ptr<PendingCommandBuffers> pending_command_buffers_;
10621038
bool wireframe_ = false;
10631039

10641040
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.

impeller/entity/contents/tiled_texture_contents.cc

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
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"
119
#include "impeller/entity/tiled_texture_fill.frag.h"
1210
#include "impeller/entity/tiled_texture_fill_external.frag.h"
1311
#include "impeller/renderer/render_pass.h"
@@ -116,7 +114,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
116114
return true;
117115
}
118116

119-
using VS = TextureFillVertexShader;
117+
using VS = TextureUvFillVertexShader;
120118
using FS = TiledTextureFillFragmentShader;
121119
using FSExternal = TiledTextureFillExternalFragmentShader;
122120

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

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

137135
PipelineBuilderMethod pipeline_method;
138136

139137
#ifdef IMPELLER_ENABLE_OPENGLES
140138
if (is_external_texture) {
141139
pipeline_method = &ContentContext::GetTiledTextureExternalPipeline;
142140
} else {
143-
pipeline_method = uses_emulated_tile_mode
144-
? &ContentContext::GetTiledTexturePipeline
145-
: &ContentContext::GetTexturePipeline;
141+
pipeline_method = &ContentContext::GetTiledTexturePipeline;
146142
}
147143
#else
148-
pipeline_method = uses_emulated_tile_mode
149-
? &ContentContext::GetTiledTexturePipeline
150-
: &ContentContext::GetTexturePipeline;
144+
pipeline_method = &ContentContext::GetTiledTexturePipeline;
151145
#endif // IMPELLER_ENABLE_OPENGLES
152146

153147
PipelineBuilderCallback pipeline_callback =
@@ -156,33 +150,23 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
156150
};
157151
return ColorSourceContents::DrawGeometry<VS>(
158152
renderer, entity, pass, pipeline_callback, frame_info,
159-
[this, &renderer, &is_external_texture,
160-
&uses_emulated_tile_mode](RenderPass& pass) {
153+
[this, &renderer, &is_external_texture](RenderPass& pass) {
161154
auto& host_buffer = renderer.GetTransientsBuffer();
162155

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

169158
if (is_external_texture) {
170159
FSExternal::FragInfo frag_info;
171160
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
172161
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
173162
frag_info.alpha = GetOpacityFactor();
174163
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
175-
} else if (uses_emulated_tile_mode) {
164+
} else {
176165
FS::FragInfo frag_info;
177166
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
178167
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
179168
frag_info.alpha = GetOpacityFactor();
180169
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));
186170
}
187171

188172
if (is_external_texture) {
@@ -221,10 +205,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
221205
}
222206

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

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

0 commit comments

Comments
 (0)