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

Commit 88fc864

Browse files
author
Jonah Williams
authored
[Impeller] delete points compute shader. (#52346)
We only use this for drawPoints, a rarely used API. On local tests, this is just as fast with the CPU backend implementations. While this was intended to be the first in a series of compute based rendering experiments, it hasn't really been worth the carrying cost. So lets shrink the complexity and and remove another shader to boot. Fixes flutter/flutter#147184
1 parent c330ca8 commit 88fc864

File tree

11 files changed

+12
-317
lines changed

11 files changed

+12
-317
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40396,7 +40396,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.glsl + ../
4039640396
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert + ../../../flutter/LICENSE
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
40399-
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
4040040399
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
4040140400
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
4040240401
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
@@ -43278,7 +43277,6 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.glsl
4327843277
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert
4327943278
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag
4328043279
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag
43281-
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
4328243280
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
4328343281
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
4328443282
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag

impeller/aiks/aiks_unittests.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,10 +2349,6 @@ TEST_P(AiksTest, DrawPaintTransformsBounds) {
23492349
}
23502350

23512351
TEST_P(AiksTest, CanDrawPoints) {
2352-
if (GetBackend() == PlaygroundBackend::kMetal) {
2353-
// https://github.com/flutter/flutter/issues/147184
2354-
GTEST_SKIP() << "Draw Points is currently broken on the metal m1 backend.";
2355-
}
23562352
std::vector<Point> points = {
23572353
{0, 0}, //
23582354
{100, 100}, //
@@ -2447,10 +2443,6 @@ TEST_P(AiksTest, DrawAtlasAdvancedAndTransform) {
24472443
}
24482444

24492445
TEST_P(AiksTest, CanDrawPointsWithTextureMap) {
2450-
if (GetBackend() == PlaygroundBackend::kMetal) {
2451-
// https://github.com/flutter/flutter/issues/147184
2452-
GTEST_SKIP() << "Draw Points is currently broken on the metal m1 backend.";
2453-
}
24542446
auto texture = CreateTextureForFixture("table_mountain_nx.png",
24552447
/*enable_mipmapping=*/true);
24562448

impeller/entity/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impeller_shaders("modern_entity_shaders") {
8181
"shaders/gradients/linear_gradient_ssbo_fill.frag",
8282
"shaders/gradients/radial_gradient_ssbo_fill.frag",
8383
"shaders/gradients/sweep_gradient_ssbo_fill.frag",
84-
"shaders/geometry/points.comp",
8584
]
8685
}
8786

impeller/entity/contents/content_context.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,6 @@ ContentContext::ContentContext(
450450
tiled_texture_external_pipelines_.CreateDefault(*context_, options);
451451
}
452452
#endif // IMPELLER_ENABLE_OPENGLES
453-
if (context_->GetCapabilities()->SupportsCompute()) {
454-
auto pipeline_desc =
455-
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
456-
point_field_compute_pipelines_ =
457-
context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
458-
}
459453

460454
is_valid_ = true;
461455
InitializeCommonlyUsedShadersIfNeeded();

impeller/entity/contents/content_context.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "impeller/entity/linear_to_srgb_filter.frag.h"
4545
#include "impeller/entity/morphology_filter.frag.h"
4646
#include "impeller/entity/morphology_filter.vert.h"
47-
#include "impeller/entity/points.comp.h"
4847
#include "impeller/entity/porter_duff_blend.frag.h"
4948
#include "impeller/entity/porter_duff_blend.vert.h"
5049
#include "impeller/entity/radial_gradient_fill.frag.h"
@@ -256,9 +255,6 @@ using FramebufferBlendSoftLightPipeline =
256255
using VerticesUberShader =
257256
RenderPipelineHandle<VerticesUberVertexShader, VerticesUberFragmentShader>;
258257

259-
/// Geometry Pipelines
260-
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
261-
262258
#ifdef IMPELLER_ENABLE_OPENGLES
263259
using TiledTextureExternalPipeline =
264260
RenderPipelineHandle<TextureUvFillVertexShader,
@@ -719,12 +715,6 @@ class ContentContext {
719715
return GetPipeline(vertices_uber_shader_, opts);
720716
}
721717

722-
std::shared_ptr<Pipeline<ComputePipelineDescriptor>> GetPointComputePipeline()
723-
const {
724-
FML_DCHECK(GetDeviceCapabilities().SupportsCompute());
725-
return point_field_compute_pipelines_;
726-
}
727-
728718
std::shared_ptr<Context> GetContext() const;
729719

730720
const Capabilities& GetDeviceCapabilities() const;
@@ -987,8 +977,6 @@ class ContentContext {
987977
mutable Variants<FramebufferBlendSoftLightPipeline>
988978
framebuffer_blend_softlight_pipelines_;
989979
mutable Variants<VerticesUberShader> vertices_uber_shader_;
990-
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
991-
point_field_compute_pipelines_;
992980

993981
template <class TypedPipeline>
994982
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(

impeller/entity/entity_unittests.cc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,24 +2519,6 @@ TEST_P(EntityTest, TiledTextureContentsIsOpaque) {
25192519
ASSERT_FALSE(contents.IsOpaque());
25202520
}
25212521

2522-
TEST_P(EntityTest, PointFieldGeometryDivisions) {
2523-
// Square always gives 4 divisions.
2524-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(24.0, false), 4u);
2525-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(2.0, false), 4u);
2526-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(200.0, false), 4u);
2527-
2528-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(0.5, true), 4u);
2529-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(1.5, true), 8u);
2530-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(5.5, true), 24u);
2531-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(12.5, true), 34u);
2532-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(22.3, true), 22u);
2533-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(40.5, true), 40u);
2534-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(100.0, true), 100u);
2535-
// Caps at 140.
2536-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(1000.0, true), 140u);
2537-
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(20000.0, true), 140u);
2538-
}
2539-
25402522
TEST_P(EntityTest, PointFieldGeometryCoverage) {
25412523
std::vector<Point> points = {{10, 20}, {100, 200}};
25422524
auto geometry = Geometry::MakePointField(points, 5.0, false);

impeller/entity/geometry/point_field_geometry.cc

Lines changed: 10 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
#include "impeller/entity/geometry/point_field_geometry.h"
66

7-
#include "impeller/geometry/color.h"
7+
#include "impeller/core/vertex_buffer.h"
8+
#include "impeller/entity/geometry/geometry.h"
89
#include "impeller/renderer/command_buffer.h"
910

1011
namespace impeller {
@@ -18,38 +19,19 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
1819
const ContentContext& renderer,
1920
const Entity& entity,
2021
RenderPass& pass) const {
21-
if (renderer.GetDeviceCapabilities().SupportsCompute()) {
22-
return GetPositionBufferGPU(renderer, entity, pass);
23-
}
24-
auto vtx_builder = GetPositionBufferCPU(renderer, entity, pass);
25-
if (!vtx_builder.has_value()) {
26-
return {};
27-
}
28-
29-
auto& host_buffer = renderer.GetTransientsBuffer();
30-
return {
31-
.type = PrimitiveType::kTriangleStrip,
32-
.vertex_buffer = vtx_builder->CreateVertexBuffer(host_buffer),
33-
.transform = entity.GetShaderTransform(pass),
34-
};
35-
}
36-
37-
std::optional<VertexBufferBuilder<SolidFillVertexShader::PerVertexData>>
38-
PointFieldGeometry::GetPositionBufferCPU(const ContentContext& renderer,
39-
const Entity& entity,
40-
RenderPass& pass) const {
4122
if (radius_ < 0.0) {
42-
return std::nullopt;
23+
return {};
4324
}
44-
auto transform = entity.GetTransform();
45-
auto determinant = transform.GetDeterminant();
25+
Matrix transform = entity.GetTransform();
26+
Scalar determinant = transform.GetDeterminant();
4627
if (determinant == 0) {
47-
return std::nullopt;
28+
return {};
4829
}
4930

5031
Scalar min_size = 1.0f / sqrt(std::abs(determinant));
5132
Scalar radius = std::max(radius_, min_size);
5233

34+
HostBuffer& host_buffer = renderer.GetTransientsBuffer();
5335
VertexBufferBuilder<SolidFillVertexShader::PerVertexData> vtx_builder;
5436

5537
if (round_) {
@@ -94,114 +76,13 @@ PointFieldGeometry::GetPositionBufferCPU(const ContentContext& renderer,
9476
}
9577
}
9678

97-
return vtx_builder;
98-
}
99-
100-
GeometryResult PointFieldGeometry::GetPositionBufferGPU(
101-
const ContentContext& renderer,
102-
const Entity& entity,
103-
RenderPass& pass) const {
104-
FML_DCHECK(renderer.GetDeviceCapabilities().SupportsCompute());
105-
if (radius_ < 0.0) {
106-
return {};
107-
}
108-
Scalar determinant = entity.GetTransform().GetDeterminant();
109-
if (determinant == 0) {
110-
return {};
111-
}
112-
113-
Scalar min_size = 1.0f / sqrt(std::abs(determinant));
114-
Scalar radius = std::max(radius_, min_size);
115-
116-
size_t vertices_per_geom = ComputeCircleDivisions(
117-
entity.GetTransform().GetMaxBasisLength() * radius, round_);
118-
119-
size_t points_per_circle = 3 + (vertices_per_geom - 3) * 3;
120-
size_t total = points_per_circle * points_.size();
121-
122-
std::shared_ptr<CommandBuffer> cmd_buffer =
123-
renderer.GetContext()->CreateCommandBuffer();
124-
std::shared_ptr<ComputePass> compute_pass = cmd_buffer->CreateComputePass();
125-
HostBuffer& host_buffer = renderer.GetTransientsBuffer();
126-
127-
BufferView points_data =
128-
host_buffer.Emplace(points_.data(), points_.size() * sizeof(Point),
129-
DefaultUniformAlignment());
130-
131-
BufferView geometry_buffer =
132-
host_buffer.Emplace(nullptr, total * sizeof(Point),
133-
std::max(DefaultUniformAlignment(), alignof(Point)));
134-
135-
BufferView output;
136-
{
137-
using PS = PointsComputeShader;
138-
139-
compute_pass->SetPipeline(renderer.GetPointComputePipeline());
140-
compute_pass->SetCommandLabel("Points Geometry");
141-
142-
PS::FrameInfo frame_info;
143-
frame_info.count = points_.size();
144-
frame_info.radius = round_ ? radius : radius * kSqrt2;
145-
frame_info.radian_start = round_ ? 0.0f : kPiOver4;
146-
frame_info.radian_step = k2Pi / vertices_per_geom;
147-
frame_info.points_per_circle = points_per_circle;
148-
frame_info.divisions_per_circle = vertices_per_geom;
149-
150-
PS::BindFrameInfo(*compute_pass, host_buffer.EmplaceUniform(frame_info));
151-
PS::BindGeometryData(*compute_pass, geometry_buffer);
152-
PS::BindPointData(*compute_pass, points_data);
153-
154-
if (!compute_pass->Compute(ISize(total, 1)).ok()) {
155-
return {};
156-
}
157-
output = geometry_buffer;
158-
}
159-
160-
if (!compute_pass->EncodeCommands()) {
161-
return {};
162-
}
163-
if (!renderer.GetContext()
164-
->GetCommandQueue()
165-
->Submit({std::move(cmd_buffer)})
166-
.ok()) {
167-
return {};
168-
}
169-
170-
return {
171-
.type = PrimitiveType::kTriangle,
172-
.vertex_buffer = {.vertex_buffer = std::move(output),
173-
.vertex_count = total,
174-
.index_type = IndexType::kNone},
79+
return GeometryResult{
80+
.type = PrimitiveType::kTriangleStrip,
81+
.vertex_buffer = vtx_builder.CreateVertexBuffer(host_buffer),
17582
.transform = entity.GetShaderTransform(pass),
17683
};
17784
}
17885

179-
/// @brief Compute the number of vertices to divide each circle into.
180-
///
181-
/// @return the number of vertices.
182-
size_t PointFieldGeometry::ComputeCircleDivisions(Scalar scaled_radius,
183-
bool round) {
184-
if (!round) {
185-
return 4;
186-
}
187-
188-
// Note: these values are approximated based on the values returned from
189-
// the decomposition of 4 cubics performed by Path::CreatePolyline.
190-
if (scaled_radius < 1.0) {
191-
return 4;
192-
}
193-
if (scaled_radius < 2.0) {
194-
return 8;
195-
}
196-
if (scaled_radius < 12.0) {
197-
return 24;
198-
}
199-
if (scaled_radius < 22.0) {
200-
return 34;
201-
}
202-
return std::min(scaled_radius, 140.0f);
203-
}
204-
20586
// |Geometry|
20687
std::optional<Rect> PointFieldGeometry::GetCoverage(
20788
const Matrix& transform) const {

impeller/entity/geometry/point_field_geometry.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class PointFieldGeometry final : public Geometry {
1515

1616
~PointFieldGeometry() = default;
1717

18-
static size_t ComputeCircleDivisions(Scalar scaled_radius, bool round);
19-
2018
private:
2119
// |Geometry|
2220
GeometryResult GetPositionBuffer(const ContentContext& renderer,
@@ -26,15 +24,6 @@ class PointFieldGeometry final : public Geometry {
2624
// |Geometry|
2725
std::optional<Rect> GetCoverage(const Matrix& transform) const override;
2826

29-
GeometryResult GetPositionBufferGPU(const ContentContext& renderer,
30-
const Entity& entity,
31-
RenderPass& pass) const;
32-
33-
std::optional<VertexBufferBuilder<SolidFillVertexShader::PerVertexData>>
34-
GetPositionBufferCPU(const ContentContext& renderer,
35-
const Entity& entity,
36-
RenderPass& pass) const;
37-
3827
std::vector<Point> points_;
3928
Scalar radius_;
4029
bool round_;

impeller/entity/shaders/geometry/points.comp

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)