Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
961008c
[Impeller] compute circles in vertex shader
May 7, 2023
56638b0
++
May 8, 2023
be1332a
capabilities and license
May 8, 2023
7a83b0d
add support for square caps
May 8, 2023
d36a452
++
May 8, 2023
69ea8a9
++
May 8, 2023
6a830a7
++
May 8, 2023
5cec1a4
switch to enum class and add docs
May 8, 2023
de05b5c
fix offsets
May 9, 2023
94b0808
Merge branch 'master' of github.com:flutter/engine into draw_circles
May 10, 2023
f0a8297
use different render pass
May 10, 2023
96fea2f
Merge branch 'master' of github.com:flutter/engine into draw_circles
May 10, 2023
faba06f
fix merge
May 10, 2023
a8e4106
add CPU fallback
May 10, 2023
8b8f4f8
++
May 10, 2023
b23b616
fix off by one
May 10, 2023
0591bf1
non working index buffer removal
May 11, 2023
0fc1ee2
fix no index
May 12, 2023
6d979a2
++
May 12, 2023
75ce9fb
Merge branch 'master' of github.com:flutter/engine into draw_circles
May 12, 2023
a2f218d
++
May 12, 2023
cbb0aa6
Rename field
May 12, 2023
542b465
Merge branch 'master' of github.com:flutter/engine into draw_circles
May 12, 2023
8799795
improve efficiency
May 12, 2023
b715d40
++
May 12, 2023
7693925
disable on desktop
May 12, 2023
8cc4e81
Merge branch 'master' of github.com:flutter/engine into draw_circles
May 12, 2023
6f46186
fix geometry computation bug
May 13, 2023
cca59fe
malioc update
May 13, 2023
f08fff2
++
May 13, 2023
36b9ee3
[Impeller] draw cirlces with compute
May 13, 2023
08296cd
remove disabled rasterization support
May 15, 2023
9603338
++
May 15, 2023
728a734
++
May 15, 2023
92534b8
++
May 15, 2023
e306942
++
May 15, 2023
408642f
++
May 15, 2023
4a44b46
add golden for drawPoints
May 15, 2023
78f5a57
Merge branch 'master' of github.com:flutter/engine into draw_with_com…
May 16, 2023
c907260
dnfield review
May 18, 2023
1f0a9b6
Merge branch 'main' into draw_with_compute
May 18, 2023
40ef2b4
++
May 18, 2023
e788b29
Merge branch 'master' of github.com:flutter/engine into draw_with_com…
May 18, 2023
ca70a31
Merge branch 'draw_with_compute' of github.com:jonahwilliams/engine i…
May 18, 2023
14e76fc
fix threadgroup size for 1d dispatch
May 19, 2023
6e82927
Remove commented out code
May 19, 2023
96921e2
dont use std numeric limits
May 19, 2023
0275a10
++
May 19, 2023
e4fae27
++
May 19, 2023
f9e57a2
Merge branch 'main' into draw_with_compute
May 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alp
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
Expand Down Expand Up @@ -3916,6 +3917,7 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag
Expand Down
30 changes: 30 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2320,5 +2320,35 @@ TEST_P(AiksTest, CanRenderClippedRuntimeEffects) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanDrawPoints) {
std::vector<Point> points = {
{0, 0}, //
{100, 100}, //
{100, 0}, //
{0, 100}, //
{0, 0}, //
{48, 48}, //
{52, 52}, //
};
std::vector<PointStyle> caps = {
PointStyle::kRound,
PointStyle::kSquare,
};
Paint paint;
paint.color = Color::Yellow().WithAlpha(0.5);

Paint background;
background.color = Color::Black();

Canvas canvas;
canvas.DrawPaint(background);
canvas.Translate({200, 200});
canvas.DrawPoints(points, 10, paint, PointStyle::kRound);
canvas.Translate({150, 0});
canvas.DrawPoints(points, 10, paint, PointStyle::kSquare);

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

} // namespace testing
} // namespace impeller
19 changes: 19 additions & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ void Canvas::RestoreClip() {
GetCurrentPass().AddEntity(entity);
}

void Canvas::DrawPoints(std::vector<Point> points,
Scalar radius,
const Paint& paint,
PointStyle point_style) {
if (radius <= 0) {
return;
}

Entity entity;
entity.SetTransformation(GetCurrentTransformation());
entity.SetStencilDepth(GetStencilDepth());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(paint.WithFilters(paint.CreateContentsForGeometry(
Geometry::MakePointField(std::move(points), radius,
/*round=*/point_style == PointStyle::kRound))));

GetCurrentPass().AddEntity(entity);
}

void Canvas::DrawPicture(Picture picture) {
if (!picture.pass) {
return;
Expand Down
13 changes: 13 additions & 0 deletions impeller/aiks/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ struct CanvasStackEntry {
bool contains_clips = false;
};

enum class PointStyle {
/// @brief Points are drawn as squares.
kRound,

/// @brief Points are drawn as circles.
kSquare,
};

class Canvas {
public:
struct DebugOptions {
Expand Down Expand Up @@ -100,6 +108,11 @@ class Canvas {

void DrawCircle(Point center, Scalar radius, const Paint& paint);

void DrawPoints(std::vector<Point>,
Scalar radius,
const Paint& paint,
PointStyle point_style);

void DrawImage(const std::shared_ptr<Image>& image,
Point offset,
const Paint& paint,
Expand Down
19 changes: 10 additions & 9 deletions impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,17 @@ void DlDispatcher::drawPoints(PointMode mode,
Paint paint = paint_;
paint.style = Paint::Style::kStroke;
switch (mode) {
case flutter::DlCanvas::PointMode::kPoints:
if (paint.stroke_cap == Cap::kButt) {
paint.stroke_cap = Cap::kSquare;
case flutter::DlCanvas::PointMode::kPoints: {
// Cap::kButt is also treated as a square.
auto point_style = paint.stroke_cap == Cap::kRound ? PointStyle::kRound
: PointStyle::kSquare;
auto radius = paint.stroke_width;
if (radius > 0) {
radius /= 2.0;
}
for (uint32_t i = 0; i < count; i++) {
Point p0 = skia_conversions::ToPoint(points[i]);
auto path = PathBuilder{}.AddLine(p0, p0).TakePath();
canvas_.DrawPath(path, paint);
}
break;
canvas_.DrawPoints(skia_conversions::ToPoints(points, count), radius,
paint, point_style);
} break;
case flutter::DlCanvas::PointMode::kLines:
for (uint32_t i = 1; i < count; i += 2) {
Point p0 = skia_conversions::ToPoint(points[i - 1]);
Expand Down
8 changes: 8 additions & 0 deletions impeller/display_list/skia_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ std::vector<Rect> ToRects(const SkRect tex[], int count) {
return result;
}

std::vector<Point> ToPoints(const SkPoint points[], int count) {
std::vector<Point> result(count);
for (auto i = 0; i < count; i++) {
result[i] = ToPoint(points[i]);
}
return result;
}

PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect& rrect) {
using Corner = SkRRect::Corner;
PathBuilder::RoundingRadii radii;
Expand Down
2 changes: 2 additions & 0 deletions impeller/display_list/skia_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ std::optional<Rect> ToRect(const SkRect* rect);

std::vector<Rect> ToRects(const SkRect tex[], int count);

std::vector<Point> ToPoints(const SkPoint points[], int count);

Point ToPoint(const SkPoint& point);

Color ToColor(const SkColor& color);
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impeller_shaders("modern_entity_shaders") {
"shaders/linear_gradient_ssbo_fill.frag",
"shaders/radial_gradient_ssbo_fill.frag",
"shaders/sweep_gradient_ssbo_fill.frag",
"shaders/geometry/points.comp",
]
}

Expand Down
8 changes: 8 additions & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/core/formats.h"
#include "impeller/entity/entity.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/pipeline_library.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "impeller/tessellator/tessellator.h"
Expand Down Expand Up @@ -296,6 +297,13 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
porter_duff_blend_pipelines_[{}] =
CreateDefaultPipeline<PorterDuffBlendPipeline>(*context_);

if (context_->GetCapabilities()->SupportsCompute()) {
auto pipeline_desc =
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
point_field_compute_pipelines_ =
context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
}

if (solid_fill_pipelines_[{}]->GetDescriptor().has_value()) {
auto clip_pipeline_descriptor =
solid_fill_pipelines_[{}]->GetDescriptor().value();
Expand Down
12 changes: 12 additions & 0 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "impeller/entity/linear_to_srgb_filter.vert.h"
#include "impeller/entity/morphology_filter.frag.h"
#include "impeller/entity/morphology_filter.vert.h"
#include "impeller/entity/points.comp.h"
#include "impeller/entity/porter_duff_blend.frag.h"
#include "impeller/entity/radial_gradient_fill.frag.h"
#include "impeller/entity/rrect_blur.frag.h"
Expand Down Expand Up @@ -275,6 +276,9 @@ using FramebufferBlendSoftLightPipeline =
RenderPipelineT<FramebufferBlendVertexShader,
FramebufferBlendSoftlightFragmentShader>;

/// Geometry Pipelines
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;

/// Pipeline state configuration.
///
/// Each unique combination of these options requires a different pipeline state
Expand Down Expand Up @@ -660,6 +664,12 @@ class ContentContext {
return GetPipeline(framebuffer_blend_softlight_pipelines_, opts);
}

std::shared_ptr<Pipeline<ComputePipelineDescriptor>> GetPointComputePipeline()
const {
FML_DCHECK(GetDeviceCapabilities().SupportsCompute());
return point_field_compute_pipelines_;
}

std::shared_ptr<Context> GetContext() const;

std::shared_ptr<GlyphAtlasContext> GetGlyphAtlasContext(
Expand Down Expand Up @@ -782,6 +792,8 @@ class ContentContext {
framebuffer_blend_screen_pipelines_;
mutable Variants<FramebufferBlendSoftLightPipeline>
framebuffer_blend_softlight_pipelines_;
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
point_field_compute_pipelines_;

template <class TypedPipeline>
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
Expand Down
18 changes: 18 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2616,5 +2616,23 @@ TEST_P(EntityTest, TessellateConvex) {
}
}

TEST_P(EntityTest, PointFieldGeometryDivisions) {
// Square always gives 4 divisions.
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(24.0, false), 4u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(2.0, false), 4u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(200.0, false), 4u);

ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(0.5, true), 4u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(1.5, true), 8u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(5.5, true), 24u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(12.5, true), 34u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(22.3, true), 22u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(40.5, true), 40u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(100.0, true), 100u);
// Caps at 140.
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(1000.0, true), 140u);
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(20000.0, true), 140u);
}

} // namespace testing
} // namespace impeller
Loading