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
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
14 changes: 12 additions & 2 deletions impeller/core/vertex_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ namespace impeller {

struct VertexBuffer {
BufferView vertex_buffer;

//----------------------------------------------------------------------------
/// The index buffer binding used by the vertex shader stage.
BufferView index_buffer;
// The total count of vertices, either in the vertex_buffer if the
// index_type is IndexType::kNone or in the index_buffer otherwise.

//----------------------------------------------------------------------------
/// The total count of vertices, either in the vertex_buffer if the
/// index_type is IndexType::kNone or in the index_buffer otherwise.
size_t vertex_count = 0u;

//----------------------------------------------------------------------------
/// The type of indices in the index buffer. The indices must be tightly
/// packed in the index buffer.
///
IndexType index_type = IndexType::kUnknown;

constexpr explicit operator bool() const {
Expand Down
4 changes: 1 addition & 3 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,10 @@ bool AtlasContents::Render(const ContentContext& renderer,
}
}

auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

Command cmd;
DEBUG_COMMAND_INFO(
cmd, SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
cmd.stencil_reference = entity.GetClipDepth();
auto options = OptionsFromPass(pass);
cmd.pipeline = renderer.GetPorterDuffBlendPipeline(options);
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool ClipContents::Render(const ContentContext& renderer,
VertexBufferBuilder<VS::PerVertexData>{}
.AddVertices({{points[0]}, {points[1]}, {points[2]}, {points[3]}})
.CreateVertexBuffer(pass.GetTransientsBuffer());
cmd.BindVertices(vertices);
cmd.BindVertices(std::move(vertices));

info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
Expand Down Expand Up @@ -126,7 +126,7 @@ bool ClipContents::Render(const ContentContext& renderer,
cmd.pipeline = renderer.GetClipPipeline(options);

auto allocator = renderer.GetContext()->GetResourceAllocator();
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));

info.mvp = geometry_result.transform;
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/conical_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetConicalGradientSSBOFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindColorData(cmd, color_buffer);
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
Expand Down Expand Up @@ -173,7 +173,7 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetConicalGradientFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear;
Expand Down
9 changes: 4 additions & 5 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static std::optional<Entity> AdvancedBlend(
Command cmd;
DEBUG_COMMAND_INFO(cmd, SPrintF("Advanced Blend Filter (%s)",
BlendModeToString(blend_mode)));
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(std::move(vtx_buffer));
cmd.pipeline = std::move(pipeline);

typename FS::BlendInfo blend_info;
Expand Down Expand Up @@ -289,7 +289,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
Command cmd;
DEBUG_COMMAND_INFO(cmd, SPrintF("Foreground Advanced Blend Filter (%s)",
BlendModeToString(blend_mode)));
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(std::move(vtx_buffer));
cmd.stencil_reference = entity.GetClipDepth();
auto options = OptionsFromPass(pass);
options.primitive_type = PrimitiveType::kTriangleStrip;
Expand Down Expand Up @@ -460,7 +460,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
Command cmd;
DEBUG_COMMAND_INFO(cmd, SPrintF("Foreground PorterDuff Blend Filter (%s)",
BlendModeToString(blend_mode)));
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(std::move(vtx_buffer));
cmd.stencil_reference = entity.GetClipDepth();
auto options = OptionsFromPass(pass);
options.primitive_type = PrimitiveType::kTriangleStrip;
Expand Down Expand Up @@ -583,8 +583,7 @@ static std::optional<Entity> PipelineBlend(
{Point(0, size.height), Point(0, 1)},
{Point(size.width, size.height), Point(1, 1)},
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
coverage.origin.y + coverage.size.height},
input_uvs[3]},
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

Command cmd;
DEBUG_COMMAND_INFO(cmd, "Border Mask Blur Filter");
auto options = OptionsFromPassAndEntity(pass, entity);
options.primitive_type = PrimitiveType::kTriangleStrip;

cmd.pipeline = renderer.GetBorderMaskBlurPipeline(options);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
cmd.stencil_reference = entity.GetClipDepth();

VS::FrameInfo frame_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
{Point(1, 1)},
});
auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
{Point(0, 1), input_uvs[2]},
{Point(1, 1), input_uvs[3]},
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
Expand All @@ -195,7 +194,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
Command cmd;
DEBUG_COMMAND_INFO(cmd, SPrintF("Gaussian Blur Filter (Radius=%.2f)",
transformed_blur_radius_length));
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

auto options = OptionsFromPass(pass);
options.primitive_type = PrimitiveType::kTriangleStrip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ void BindVertices(Command& cmd,
std::initializer_list<typename T::PerVertexData>&& vertices) {
VertexBufferBuilder<typename T::PerVertexData> vtx_builder;
vtx_builder.AddVertices(vertices);
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
}

Matrix MakeAnchorScale(const Point& anchor, Vector2 scale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ std::optional<Entity> LinearToSrgbFilterContents::RenderFilter(
});

auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
{Point(1, 1), input_uvs[3]},
});

auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
frame_info.texture_sampler_y_coord_scale =
Expand Down Expand Up @@ -120,7 +118,7 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
options.primitive_type = PrimitiveType::kTriangleStrip;
options.blend_mode = BlendMode::kSource;
cmd.pipeline = renderer.GetMorphologyFilterPipeline(options);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

auto sampler_descriptor = input_snapshot->sampler_descriptor;
if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
});

auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
});

auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
3 changes: 1 addition & 2 deletions impeller/entity/contents/framebuffer_blend_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
{Point(0, size.height), Point(0, 1)},
{Point(size.width, size.height), Point(1, 1)},
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

auto options = OptionsFromPass(pass);
options.blend_mode = BlendMode::kSource;
options.primitive_type = PrimitiveType::kTriangleStrip;

Command cmd;
DEBUG_COMMAND_INFO(cmd, "Framebuffer Advanced Blend Filter");
cmd.BindVertices(vtx_buffer);
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
cmd.stencil_reference = entity.GetClipDepth();

switch (blend_mode_) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetLinearGradientFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear;
Expand Down Expand Up @@ -169,7 +169,7 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetLinearGradientSSBOFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindColorData(cmd, color_buffer);
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/radial_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetRadialGradientSSBOFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindColorData(cmd, color_buffer);
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
Expand Down Expand Up @@ -165,7 +165,7 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetRadialGradientFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear;
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
DEBUG_COMMAND_INFO(cmd, "RuntimeEffectContents");
cmd.pipeline = pipeline;
cmd.stencil_reference = entity.GetClipDepth();
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));

//--------------------------------------------------------------------------
/// Vertex stage uniforms.
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool SolidColorContents::Render(const ContentContext& renderer,

options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetSolidFillPipeline(options);
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = capture.AddMatrix("Transform", geometry_result.transform);
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/sweep_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetSweepGradientSSBOFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindColorData(cmd, color_buffer);
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
Expand Down Expand Up @@ -172,7 +172,7 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer,
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetSweepGradientFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
SamplerDescriptor sampler_desc;
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
: renderer.GetTexturePipeline(options);
#endif // IMPELLER_ENABLE_OPENGLES

cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

if (is_external_texture) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/vertices_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
opts.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetTexturePipeline(opts);
cmd.stencil_reference = entity.GetClipDepth();
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = geometry_result.transform;
Expand Down Expand Up @@ -185,7 +185,7 @@ bool VerticesColorContents::Render(const ContentContext& renderer,
opts.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetGeometryColorPipeline(opts);
cmd.stencil_reference = entity.GetClipDepth();
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.BindVertices(std::move(geometry_result.vertex_buffer));

VS::FrameInfo frame_info;
frame_info.mvp = geometry_result.transform;
Expand Down
2 changes: 1 addition & 1 deletion impeller/playground/imgui/imgui_impl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data,
pcmd->ElemCount * sizeof(ImDrawIdx))};
vertex_buffer.vertex_count = pcmd->ElemCount;
vertex_buffer.index_type = impeller::IndexType::k16bit;
cmd.BindVertices(vertex_buffer);
cmd.BindVertices(std::move(vertex_buffer));
cmd.base_vertex = pcmd->VtxOffset;

render_pass.AddCommand(std::move(cmd));
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ std::optional<size_t> BufferBindingsGLES::BindTextures(
/// If there is a sampler for the texture at the same index, configure the
/// bound texture using that sampler.
///
const auto& sampler_gles = SamplerGLES::Cast(*data.second.sampler.resource);
const auto& sampler_gles = SamplerGLES::Cast(*data.second.sampler);
if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
return std::nullopt;
}
Expand Down
17 changes: 9 additions & 8 deletions impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ struct RenderPassData {
break;
}

if (command.index_type == IndexType::kUnknown) {
if (command.vertex_buffer.index_type == IndexType::kUnknown) {
return false;
}

Expand All @@ -381,7 +381,7 @@ struct RenderPassData {
//--------------------------------------------------------------------------
/// Bind vertex and index buffers.
///
auto vertex_buffer_view = command.GetVertexBuffer();
auto& vertex_buffer_view = command.vertex_buffer.vertex_buffer;

if (!vertex_buffer_view) {
return false;
Expand Down Expand Up @@ -441,21 +441,22 @@ struct RenderPassData {
//--------------------------------------------------------------------------
/// Finally! Invoke the draw call.
///
if (command.index_type == IndexType::kNone) {
gl.DrawArrays(mode, command.base_vertex, command.vertex_count);
if (command.vertex_buffer.index_type == IndexType::kNone) {
gl.DrawArrays(mode, command.base_vertex,
command.vertex_buffer.vertex_count);
} else {
// Bind the index buffer if necessary.
auto index_buffer_view = command.index_buffer;
auto index_buffer_view = command.vertex_buffer.index_buffer;
auto index_buffer =
index_buffer_view.buffer->GetDeviceBuffer(*transients_allocator);
const auto& index_buffer_gles = DeviceBufferGLES::Cast(*index_buffer);
if (!index_buffer_gles.BindAndUploadDataIfNecessary(
DeviceBufferGLES::BindingType::kElementArrayBuffer)) {
return false;
}
gl.DrawElements(mode, // mode
command.vertex_count, // count
ToIndexType(command.index_type), // type
gl.DrawElements(mode, // mode
command.vertex_buffer.vertex_count, // count
ToIndexType(command.vertex_buffer.index_type), // type
reinterpret_cast<const GLvoid*>(static_cast<GLsizei>(
index_buffer_view.range.offset)) // indices
);
Expand Down
Loading