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

Commit 435db1f

Browse files
author
Jonah Williams
authored
[Impeller] Dont synthesize fake index buffer if none was provided to VBB (#41969)
Followup from flutter/flutter#126572
1 parent 3e60827 commit 435db1f

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

impeller/renderer/renderer_unittests.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,18 @@ TEST_P(RendererTest, DefaultIndexSize) {
10071007
// Default to 16bit index buffer size, as this is a reasonable default and
10081008
// supported on all backends without extensions.
10091009
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
1010+
vertex_builder.AppendIndex(0u);
10101011
ASSERT_EQ(vertex_builder.GetIndexType(), IndexType::k16bit);
10111012
}
10121013

1014+
TEST_P(RendererTest, DefaultIndexBehavior) {
1015+
using VS = BoxFadeVertexShader;
1016+
1017+
// Do not create any index buffer if no indices were provided.
1018+
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
1019+
ASSERT_EQ(vertex_builder.GetIndexType(), IndexType::kNone);
1020+
}
1021+
10131022
TEST_P(RendererTest, VertexBufferBuilder) {
10141023
// Does not create index buffer if one is provided.
10151024
using VS = BoxFadeVertexShader;

impeller/renderer/vertex_buffer_builder.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ class VertexBufferBuilder {
3030
~VertexBufferBuilder() = default;
3131

3232
constexpr impeller::IndexType GetIndexType() const {
33+
if (indices_.size() == 0) {
34+
return impeller::IndexType::kNone;
35+
}
3336
if constexpr (sizeof(IndexType) == 2) {
3437
return impeller::IndexType::k16bit;
35-
} else if (sizeof(IndexType) == 4) {
38+
}
39+
if (sizeof(IndexType) == 4) {
3640
return impeller::IndexType::k32bit;
37-
} else {
38-
return impeller::IndexType::kUnknown;
3941
}
42+
return impeller::IndexType::kUnknown;
4043
}
4144

4245
void SetLabel(std::string label) { label_ = std::move(label); }
@@ -121,29 +124,23 @@ class VertexBufferBuilder {
121124
return buffer->AsBufferView();
122125
}
123126

124-
std::vector<IndexType> CreateIndexBuffer() const {
125-
if (indices_.size() > 0) {
126-
return indices_;
127-
}
128-
129-
// So dumb! We don't actually need an index buffer right now. But we will
130-
// once de-duplication is done. So assume this is always done.
131-
std::vector<IndexType> index_buffer;
132-
for (size_t i = 0; i < vertices_.size(); i++) {
133-
index_buffer.push_back(i);
134-
}
135-
return index_buffer;
136-
}
127+
std::vector<IndexType> CreateIndexBuffer() const { return indices_; }
137128

138129
BufferView CreateIndexBufferView(HostBuffer& buffer) const {
139130
const auto index_buffer = CreateIndexBuffer();
131+
if (index_buffer.size() == 0) {
132+
return {};
133+
}
140134
return buffer.Emplace(index_buffer.data(),
141135
index_buffer.size() * sizeof(IndexType),
142136
alignof(IndexType));
143137
}
144138

145139
BufferView CreateIndexBufferView(Allocator& allocator) const {
146140
const auto index_buffer = CreateIndexBuffer();
141+
if (index_buffer.size() == 0) {
142+
return {};
143+
}
147144
auto buffer = allocator.CreateBufferWithCopy(
148145
reinterpret_cast<const uint8_t*>(index_buffer.data()),
149146
index_buffer.size() * sizeof(IndexType));

0 commit comments

Comments
 (0)