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

Commit 2ac9c73

Browse files
authored
Move primitive type to pipeline descriptor (#37315)
This is the correct abstraction for Vulkan as we need this during primitive assembly. We also know this ahead of time so its useful to just wire it in. Fixes flutter/flutter#106379
1 parent 9584880 commit 2ac9c73

23 files changed

+68
-52
lines changed

impeller/entity/contents/clip_contents.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ bool ClipContents::Render(const ContentContext& renderer,
8686
{
8787
cmd.label = "Difference Clip (Increment)";
8888

89-
cmd.primitive_type = PrimitiveType::kTriangleStrip;
9089
auto points = Rect(Size(pass.GetRenderTargetSize())).GetPoints();
9190
auto vertices =
9291
VertexBufferBuilder<VS::PerVertexData>{}
@@ -104,7 +103,6 @@ bool ClipContents::Render(const ContentContext& renderer,
104103
{
105104
cmd.label = "Difference Clip (Punch)";
106105

107-
cmd.primitive_type = PrimitiveType::kTriangle;
108106
cmd.stencil_reference = entity.GetStencilDepth() + 1;
109107
options.stencil_compare = CompareFunction::kEqual;
110108
options.stencil_operation = StencilOperation::kDecrementClamp;
@@ -115,12 +113,13 @@ bool ClipContents::Render(const ContentContext& renderer,
115113
options.stencil_operation = StencilOperation::kIncrementClamp;
116114
}
117115

116+
auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
117+
options.primitive_type = geometry_result.type;
118118
cmd.pipeline = renderer.GetClipPipeline(options);
119119

120120
auto allocator = renderer.GetContext()->GetResourceAllocator();
121-
auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
122121
cmd.BindVertices(geometry_result.vertex_buffer);
123-
cmd.primitive_type = geometry_result.type;
122+
124123
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
125124
entity.GetTransformation();
126125
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));

impeller/entity/contents/content_context.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
127127
stencil.depth_stencil_pass = stencil_operation;
128128
desc.SetStencilAttachmentDescriptors(stencil);
129129
}
130+
131+
desc.SetPrimitiveType(primitive_type);
130132
}
131133

132134
template <typename PipelineT>

impeller/entity/contents/content_context.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ struct ContentContextOptions {
170170
BlendMode blend_mode = BlendMode::kSourceOver;
171171
CompareFunction stencil_compare = CompareFunction::kEqual;
172172
StencilOperation stencil_operation = StencilOperation::kKeep;
173+
PrimitiveType primitive_type = PrimitiveType::kTriangle;
173174

174175
struct Hash {
175176
constexpr std::size_t operator()(const ContentContextOptions& o) const {
176177
return fml::HashCombine(o.sample_count, o.blend_mode, o.stencil_compare,
177-
o.stencil_operation);
178+
o.stencil_operation, o.primitive_type);
178179
}
179180
};
180181

@@ -184,7 +185,8 @@ struct ContentContextOptions {
184185
return lhs.sample_count == rhs.sample_count &&
185186
lhs.blend_mode == rhs.blend_mode &&
186187
lhs.stencil_compare == rhs.stencil_compare &&
187-
lhs.stencil_operation == rhs.stencil_operation;
188+
lhs.stencil_operation == rhs.stencil_operation &&
189+
lhs.primitive_type == rhs.primitive_type;
188190
}
189191
};
190192

impeller/entity/contents/contents.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "fml/logging.h"
99
#include "impeller/entity/contents/content_context.h"
1010
#include "impeller/renderer/command_buffer.h"
11+
#include "impeller/renderer/formats.h"
1112
#include "impeller/renderer/render_pass.h"
1213

1314
namespace impeller {

impeller/entity/contents/linear_gradient_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ bool LinearGradientContents::Render(const ContentContext& renderer,
8282
options.stencil_compare = CompareFunction::kEqual;
8383
options.stencil_operation = StencilOperation::kIncrementClamp;
8484
}
85+
options.primitive_type = geometry_result.type;
8586
cmd.pipeline = renderer.GetLinearGradientFillPipeline(options);
8687

8788
cmd.BindVertices(geometry_result.vertex_buffer);
88-
cmd.primitive_type = geometry_result.type;
8989
FS::BindGradientInfo(
9090
cmd, pass.GetTransientsBuffer().EmplaceUniform(gradient_info));
9191
SamplerDescriptor sampler_desc;

impeller/entity/contents/radial_gradient_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ bool RadialGradientContents::Render(const ContentContext& renderer,
8282
options.stencil_compare = CompareFunction::kEqual;
8383
options.stencil_operation = StencilOperation::kIncrementClamp;
8484
}
85+
options.primitive_type = geometry_result.type;
8586
cmd.pipeline = renderer.GetRadialGradientFillPipeline(options);
8687

8788
cmd.BindVertices(geometry_result.vertex_buffer);
88-
cmd.primitive_type = geometry_result.type;
8989
FS::BindGradientInfo(
9090
cmd, pass.GetTransientsBuffer().EmplaceUniform(gradient_info));
9191
SamplerDescriptor sampler_desc;

impeller/entity/contents/rrect_shadow_contents.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ bool RRectShadowContents::Render(const ContentContext& renderer,
7979

8080
Command cmd;
8181
cmd.label = "RRect Shadow";
82-
cmd.pipeline =
83-
renderer.GetRRectBlurPipeline(OptionsFromPassAndEntity(pass, entity));
82+
auto opts = OptionsFromPassAndEntity(pass, entity);
83+
opts.primitive_type = PrimitiveType::kTriangle;
84+
cmd.pipeline = renderer.GetRRectBlurPipeline(opts);
8485
cmd.stencil_reference = entity.GetStencilDepth();
8586

86-
cmd.primitive_type = PrimitiveType::kTriangle;
8787
cmd.BindVertices(vtx_builder.CreateVertexBuffer(pass.GetTransientsBuffer()));
8888

8989
VS::VertInfo vert_info;

impeller/entity/contents/runtime_effect_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
122122
options.stencil_compare = CompareFunction::kEqual;
123123
options.stencil_operation = StencilOperation::kIncrementClamp;
124124
}
125+
options.primitive_type = geometry_result.type;
125126
options.ApplyToPipelineDescriptor(desc);
126127

127128
auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).get();
@@ -135,7 +136,6 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
135136
cmd.pipeline = pipeline;
136137
cmd.stencil_reference = entity.GetStencilDepth();
137138
cmd.BindVertices(geometry_result.vertex_buffer);
138-
cmd.primitive_type = geometry_result.type;
139139

140140
//--------------------------------------------------------------------------
141141
/// Vertex stage uniforms.

impeller/entity/contents/solid_color_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ bool SolidColorContents::Render(const ContentContext& renderer,
6666
options.stencil_operation = StencilOperation::kIncrementClamp;
6767
}
6868

69+
options.primitive_type = geometry_result.type;
6970
cmd.pipeline = renderer.GetSolidFillPipeline(options);
7071
cmd.BindVertices(geometry_result.vertex_buffer);
71-
cmd.primitive_type = geometry_result.type;
7272

7373
VS::VertInfo vert_info;
7474
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *

impeller/entity/contents/sweep_gradient_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ bool SweepGradientContents::Render(const ContentContext& renderer,
8888
options.stencil_compare = CompareFunction::kEqual;
8989
options.stencil_operation = StencilOperation::kIncrementClamp;
9090
}
91+
options.primitive_type = geometry_result.type;
9192
cmd.pipeline = renderer.GetSweepGradientFillPipeline(options);
9293

9394
cmd.BindVertices(geometry_result.vertex_buffer);
94-
cmd.primitive_type = geometry_result.type;
9595
FS::BindGradientInfo(
9696
cmd, pass.GetTransientsBuffer().EmplaceUniform(gradient_info));
9797
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));

0 commit comments

Comments
 (0)