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

Commit 0591bf1

Browse files
author
jonahwilliams
committed
non working index buffer removal
1 parent b23b616 commit 0591bf1

6 files changed

Lines changed: 53 additions & 44 deletions

File tree

impeller/core/formats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ enum class IndexType {
308308
kUnknown,
309309
k16bit,
310310
k32bit,
311+
// Do not use the index buffer.
312+
kNone,
311313
};
312314

313315
enum class PrimitiveType {

impeller/core/vertex_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct VertexBuffer {
1616
IndexType index_type = IndexType::kUnknown;
1717

1818
constexpr operator bool() const {
19-
return static_cast<bool>(vertex_buffer) && static_cast<bool>(index_buffer);
19+
return static_cast<bool>(vertex_buffer); // && static_cast<bool>(index_buffer);
2020
}
2121
};
2222

impeller/display_list/dl_dispatcher.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ void DlDispatcher::drawPoints(PointMode mode,
935935
auto point_style = paint.stroke_cap == Cap::kRound ? PointStyle::kRound
936936
: PointStyle::kSquare;
937937
canvas_.DrawPoints(skia_conversions::ToPoints(points, count),
938-
paint.stroke_width, paint, point_style);
938+
paint.stroke_width / 2.0, paint, point_style);
939939
} break;
940940
case flutter::DlCanvas::PointMode::kLines:
941941
for (uint32_t i = 1; i < count; i += 2) {

impeller/entity/geometry.cc

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "impeller/entity/geometry.h"
6+
#include <iostream>
67

78
#include "impeller/core/device_buffer.h"
89
#include "impeller/entity/contents/content_context.h"
@@ -825,6 +826,10 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
825826
const ContentContext& renderer,
826827
const Entity& entity,
827828
RenderPass& pass) {
829+
if (radius_ <= 0) {
830+
return {};
831+
}
832+
828833
if (!renderer.GetDeviceCapabilities().SupportsDisabledRasterization()) {
829834
return GetPositionBufferCPU(renderer, entity, pass);
830835
}
@@ -836,21 +841,11 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
836841

837842
using VS = PointFieldGeometryPipeline::VertexShader;
838843

839-
// Create Dummy index buffer.
840-
auto index_count = divisions_per_circle * points_.size() * 3;
841-
std::vector<uint16_t> dummy_index(index_count);
842-
for (auto i = 0u; i < index_count; i++) {
843-
dummy_index[i] = i;
844-
}
845-
846844
auto vtx_buffer = VertexBuffer{
847845
.vertex_buffer = host_buffer.Emplace(
848846
points_.data(), points_.size() * sizeof(Point), alignof(Point)),
849-
.index_buffer = host_buffer.Emplace(dummy_index.data(),
850-
points_.size() * sizeof(uint16_t),
851-
alignof(uint16_t)),
852847
.index_count = points_.size(),
853-
.index_type = IndexType::k16bit,
848+
.index_type = IndexType::kNone,
854849
};
855850

856851
DeviceBufferDescriptor buffer_desc;
@@ -860,9 +855,6 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
860855
auto buffer =
861856
renderer.GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
862857

863-
auto index_buffer = host_buffer.Emplace(
864-
dummy_index.data(), index_count * sizeof(uint16_t), alignof(uint16_t));
865-
866858
Command cmd;
867859
cmd.label = "Points Geometry";
868860

@@ -905,9 +897,8 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
905897
.vertex_buffer = {.vertex_buffer = {.buffer = buffer,
906898
.range =
907899
Range{0, total * sizeof(Point)}},
908-
.index_buffer = index_buffer,
909-
.index_count = index_count,
910-
.index_type = IndexType::k16bit},
900+
.index_count = divisions_per_circle * points_.size() * 3,
901+
.index_type = IndexType::kNone},
911902
.transform = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
912903
entity.GetTransformation(),
913904
.prevent_overdraw = false,
@@ -925,7 +916,8 @@ GeometryResult PointFieldGeometry::GetPositionBufferCPU(
925916
auto radian_start = round_ ? 0.0f : 0.785398f;
926917
auto radian_step = k2Pi / divisions_per_circle;
927918

928-
VertexBufferBuilder<SolidFillVertexShader::PerVertexData> vtx_builder;
919+
VertexBufferBuilder<SolidFillVertexShader::PerVertexData, uint32_t>
920+
vtx_builder;
929921
vtx_builder.Reserve(total);
930922

931923
for (auto i = 0u; i < points_.size(); i++) {
@@ -940,7 +932,7 @@ GeometryResult PointFieldGeometry::GetPositionBufferCPU(
940932
auto pt2 = center + Point(cos(elapsed_angle), sin(elapsed_angle)) * radius_;
941933
vtx_builder.AppendVertex({pt2});
942934

943-
for (auto j = 1u; j < divisions_per_circle; j++) {
935+
for (auto j = 0u; j < divisions_per_circle - 1; j++) {
944936
vtx_builder.AppendVertex({center});
945937

946938
pt1 = pt2;
@@ -978,18 +970,22 @@ size_t PointFieldGeometry::ComputeCircleDivisions(Scalar scaled_radius,
978970
if (!round) {
979971
return 4;
980972
}
981-
// note: this formula is completely arbitrary, we should find a reasonable
982-
// curve based on experimental data.
983-
if (scaled_radius < 4.0) {
973+
974+
// Note: these values are approximated based on the values returned from
975+
// the decomposition of 4 cubics performed by Path::CreatePolyline.
976+
if (scaled_radius < 1.0) {
977+
return 4;
978+
}
979+
if (scaled_radius < 2.0) {
984980
return 8;
985981
}
986-
if (scaled_radius < 16) {
987-
return 16;
982+
if (scaled_radius < 12.0) {
983+
return 24;
988984
}
989-
if (scaled_radius < 32) {
990-
return 32;
985+
if (scaled_radius < 22.0) {
986+
return 34;
991987
}
992-
return 64;
988+
return std::min(scaled_radius, 140.0f);
993989
}
994990

995991
// |Geometry|
@@ -1000,7 +996,11 @@ GeometryVertexType PointFieldGeometry::GetVertexType() const {
1000996
// |Geometry|
1001997
std::optional<Rect> PointFieldGeometry::GetCoverage(
1002998
const Matrix& transform) const {
1003-
return Rect::MakeMaximum();
999+
auto pt_bounds = Rect::MakePointBounds(points_.begin(), points_.end());
1000+
if (pt_bounds.has_value()) {
1001+
return pt_bounds->TransformBounds(transform);
1002+
}
1003+
return std::nullopt;
10041004
}
10051005

10061006
} // namespace impeller

impeller/renderer/backend/metal/render_pass_mtl.mm

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "impeller/renderer/backend/metal/render_pass_mtl.h"
6-
6+
#include <iostream>
77
#include "flutter/fml/closure.h"
88
#include "flutter/fml/logging.h"
99
#include "flutter/fml/trace_event.h"
@@ -486,6 +486,15 @@ static bool Bind(PassBindingsCache& pass,
486486
ShaderStage::kFragment)) {
487487
return false;
488488
}
489+
const PrimitiveType primitive_type = pipeline_desc.GetPrimitiveType();
490+
491+
if (command.index_type == IndexType::kNone) {
492+
[encoder drawPrimitives:ToMTLPrimitiveType(primitive_type)
493+
vertexStart:command.base_vertex
494+
vertexCount:command.index_count];
495+
return true;
496+
}
497+
489498
if (command.index_type == IndexType::kUnknown) {
490499
return false;
491500
}
@@ -503,8 +512,6 @@ static bool Bind(PassBindingsCache& pass,
503512
return false;
504513
}
505514

506-
const PrimitiveType primitive_type = pipeline_desc.GetPrimitiveType();
507-
508515
FML_DCHECK(command.index_count *
509516
(command.index_type == IndexType::k16bit ? 2 : 4) ==
510517
command.index_buffer.range.length);

impeller/renderer/render_pass.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ bool RenderPass::AddCommand(Command command) {
4949
}
5050
}
5151

52-
if (command.index_count == 0u) {
53-
// Essentially a no-op. Don't record the command but this is not necessary
54-
// an error either.
55-
return true;
56-
}
57-
58-
if (command.instance_count == 0u) {
59-
// Essentially a no-op. Don't record the command but this is not necessary
60-
// an error either.
61-
return true;
62-
}
52+
// if (command.index_count == 0u) {
53+
// // Essentially a no-op. Don't record the command but this is not necessary
54+
// // an error either.
55+
// return true;
56+
// }
57+
58+
// if (command.instance_count == 0u) {
59+
// // Essentially a no-op. Don't record the command but this is not necessary
60+
// // an error either.
61+
// return true;
62+
// }
6363

6464
commands_.emplace_back(std::move(command));
6565
return true;

0 commit comments

Comments
 (0)