From 8aeac570add820472979ce16129de05b8e91a042 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 5 Dec 2023 13:02:52 -0800 Subject: [PATCH] [Impeller] Prefer moving vertex buffer, place on command instead of binding object. (flutter/engine#48630) Placing the vertex buffer on the binding object meant that we were actually paying 2x the size cost for it (one for vertex bindings, one for fragment bindings). By moving this object onto command itself, we reduce the size and avoid spliting up the command state in a weird way. Also updates most of the contents to prefer moving the VertexBuffer. --- .../src/flutter/impeller/core/vertex_buffer.h | 14 +++- .../entity/contents/atlas_contents.cc | 4 +- .../impeller/entity/contents/clip_contents.cc | 4 +- .../contents/conical_gradient_contents.cc | 4 +- .../contents/filters/blend_filter_contents.cc | 9 ++- .../border_mask_blur_filter_contents.cc | 3 +- .../filters/color_matrix_filter_contents.cc | 3 +- ...rectional_gaussian_blur_filter_contents.cc | 3 +- .../filters/gaussian_blur_filter_contents.cc | 3 +- .../filters/linear_to_srgb_filter_contents.cc | 3 +- .../filters/morphology_filter_contents.cc | 4 +- .../filters/srgb_to_linear_filter_contents.cc | 3 +- .../filters/yuv_to_rgb_filter_contents.cc | 3 +- .../contents/framebuffer_blend_contents.cc | 3 +- .../contents/linear_gradient_contents.cc | 4 +- .../contents/radial_gradient_contents.cc | 4 +- .../contents/runtime_effect_contents.cc | 2 +- .../entity/contents/solid_color_contents.cc | 2 +- .../contents/sweep_gradient_contents.cc | 4 +- .../entity/contents/tiled_texture_contents.cc | 2 +- .../entity/contents/vertices_contents.cc | 4 +- .../playground/imgui/imgui_impl_impeller.cc | 2 +- .../backend/gles/buffer_bindings_gles.cc | 2 +- .../renderer/backend/gles/render_pass_gles.cc | 17 ++--- .../backend/metal/compute_pass_mtl.mm | 2 +- .../renderer/backend/metal/render_pass_mtl.mm | 68 +++++++++---------- .../backend/vulkan/binding_helpers_vk.cc | 2 +- .../renderer/backend/vulkan/render_pass_vk.cc | 23 +++---- .../src/flutter/impeller/renderer/command.cc | 16 ++--- .../src/flutter/impeller/renderer/command.h | 39 +++-------- .../impeller/renderer/compute_command.cc | 2 +- .../renderer/compute_subgroup_unittests.cc | 27 ++++---- .../flutter/impeller/renderer/render_pass.cc | 9 +-- .../impeller/renderer/renderer_unittests.cc | 7 +- engine/src/flutter/lib/gpu/render_pass.cc | 3 +- 35 files changed, 125 insertions(+), 179 deletions(-) diff --git a/engine/src/flutter/impeller/core/vertex_buffer.h b/engine/src/flutter/impeller/core/vertex_buffer.h index 5ef934f4b8..7beac43d3c 100644 --- a/engine/src/flutter/impeller/core/vertex_buffer.h +++ b/engine/src/flutter/impeller/core/vertex_buffer.h @@ -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 { diff --git a/engine/src/flutter/impeller/entity/contents/atlas_contents.cc b/engine/src/flutter/impeller/entity/contents/atlas_contents.cc index 412441b03b..c72f0c9434 100644 --- a/engine/src/flutter/impeller/entity/contents/atlas_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/atlas_contents.cc @@ -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); diff --git a/engine/src/flutter/impeller/entity/contents/clip_contents.cc b/engine/src/flutter/impeller/entity/contents/clip_contents.cc index 7beee247cc..8779ab9b44 100644 --- a/engine/src/flutter/impeller/entity/contents/clip_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/clip_contents.cc @@ -98,7 +98,7 @@ bool ClipContents::Render(const ContentContext& renderer, VertexBufferBuilder{} .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)); @@ -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)); diff --git a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc index 7b7d911976..fbfe31a9c1 100644 --- a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc @@ -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)); @@ -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; diff --git a/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc index dc480f5e6c..5fe7017df5 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc @@ -169,7 +169,7 @@ static std::optional 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; @@ -289,7 +289,7 @@ std::optional 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; @@ -460,7 +460,7 @@ std::optional 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; @@ -583,8 +583,7 @@ static std::optional 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()) * diff --git a/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc index c653f54a23..da21b91349 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc @@ -102,7 +102,6 @@ std::optional 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"); @@ -110,7 +109,7 @@ std::optional BorderMaskBlurFilterContents::RenderFilter( 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; diff --git a/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc index f0d9cfe5f2..2c159c803a 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc @@ -73,8 +73,7 @@ std::optional 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()) * diff --git a/engine/src/flutter/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc index 4df745e1e4..cbda251816 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc @@ -174,7 +174,6 @@ std::optional 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)); @@ -195,7 +194,7 @@ std::optional 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; diff --git a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 940e93d50d..dd1d0256a9 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -44,8 +44,7 @@ void BindVertices(Command& cmd, std::initializer_list&& vertices) { VertexBufferBuilder 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) { diff --git a/engine/src/flutter/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc index b476a67396..64f13cdddf 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc @@ -64,8 +64,7 @@ std::optional 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()) * diff --git a/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc index 0fb2760e6a..2aa8290830 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc @@ -85,8 +85,6 @@ std::optional 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 = @@ -120,7 +118,7 @@ std::optional 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()) { diff --git a/engine/src/flutter/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc index 2da4cb00be..38c6a2fe28 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc @@ -64,8 +64,7 @@ std::optional 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()) * diff --git a/engine/src/flutter/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc index 53962ed947..21ddf7ee82 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc @@ -92,8 +92,7 @@ std::optional 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()) * diff --git a/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc b/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc index 7edc478076..867bc150c9 100644 --- a/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc @@ -66,7 +66,6 @@ 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; @@ -74,7 +73,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer, 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_) { diff --git a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc index f1fc10d437..d96525e7a0 100644 --- a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc @@ -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; @@ -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)); diff --git a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc index a7020706f2..0eee4d448e 100644 --- a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc @@ -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)); @@ -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; diff --git a/engine/src/flutter/impeller/entity/contents/runtime_effect_contents.cc b/engine/src/flutter/impeller/entity/contents/runtime_effect_contents.cc index 502d6d044d..91c18a3b7e 100644 --- a/engine/src/flutter/impeller/entity/contents/runtime_effect_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/runtime_effect_contents.cc @@ -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. diff --git a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc index 99a7574f4a..323da22797 100644 --- a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc @@ -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); diff --git a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc index caa29efd4b..f9b22e3c12 100644 --- a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc @@ -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)); @@ -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; diff --git a/engine/src/flutter/impeller/entity/contents/tiled_texture_contents.cc b/engine/src/flutter/impeller/entity/contents/tiled_texture_contents.cc index a9985d8eba..ef756577d2 100644 --- a/engine/src/flutter/impeller/entity/contents/tiled_texture_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/tiled_texture_contents.cc @@ -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) { diff --git a/engine/src/flutter/impeller/entity/contents/vertices_contents.cc b/engine/src/flutter/impeller/entity/contents/vertices_contents.cc index fae8ed89b6..47fdc1e9d1 100644 --- a/engine/src/flutter/impeller/entity/contents/vertices_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/vertices_contents.cc @@ -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; @@ -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; diff --git a/engine/src/flutter/impeller/playground/imgui/imgui_impl_impeller.cc b/engine/src/flutter/impeller/playground/imgui/imgui_impl_impeller.cc index 449c9c7cf7..417e0c0067 100644 --- a/engine/src/flutter/impeller/playground/imgui/imgui_impl_impeller.cc +++ b/engine/src/flutter/impeller/playground/imgui/imgui_impl_impeller.cc @@ -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)); diff --git a/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc b/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc index 69467f6800..c96c4a5a04 100644 --- a/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc +++ b/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc @@ -377,7 +377,7 @@ std::optional 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; } diff --git a/engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc b/engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc index 427225eb49..efee4d68f6 100644 --- a/engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc +++ b/engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc @@ -372,7 +372,7 @@ struct RenderPassData { break; } - if (command.index_type == IndexType::kUnknown) { + if (command.vertex_buffer.index_type == IndexType::kUnknown) { return false; } @@ -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; @@ -441,11 +441,12 @@ 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); @@ -453,9 +454,9 @@ struct RenderPassData { 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(static_cast( index_buffer_view.range.offset)) // indices ); diff --git a/engine/src/flutter/impeller/renderer/backend/metal/compute_pass_mtl.mm b/engine/src/flutter/impeller/renderer/backend/metal/compute_pass_mtl.mm index e22821485d..a55ec4fe07 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/compute_pass_mtl.mm +++ b/engine/src/flutter/impeller/renderer/backend/metal/compute_pass_mtl.mm @@ -231,7 +231,7 @@ bool ComputePassMTL::EncodeCommands(const std::shared_ptr& allocator, } for (const auto& data : command.bindings.sampled_images) { - if (!Bind(pass_bindings, data.first, *data.second.sampler.resource, + if (!Bind(pass_bindings, data.first, *data.second.sampler, *data.second.texture.resource)) { return false; } diff --git a/engine/src/flutter/impeller/renderer/backend/metal/render_pass_mtl.mm b/engine/src/flutter/impeller/renderer/backend/metal/render_pass_mtl.mm index a63edda8f8..f4fc37f0df 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/render_pass_mtl.mm +++ b/engine/src/flutter/impeller/renderer/backend/metal/render_pass_mtl.mm @@ -408,13 +408,6 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, auto bind_stage_resources = [&allocator, &pass_bindings]( const Bindings& bindings, ShaderStage stage) -> bool { - if (stage == ShaderStage::kVertex) { - if (!Bind(pass_bindings, *allocator, stage, - VertexDescriptor::kReservedVertexBufferIndex, - bindings.vertex_buffer.view.resource)) { - return false; - } - } for (const auto& buffer : bindings.buffers) { if (!Bind(pass_bindings, *allocator, stage, buffer.first, buffer.second.view.resource)) { @@ -422,7 +415,7 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, } } for (const auto& data : bindings.sampled_images) { - if (!Bind(pass_bindings, stage, data.first, *data.second.sampler.resource, + if (!Bind(pass_bindings, stage, data.first, *data.second.sampler, *data.second.texture.resource)) { return false; } @@ -434,13 +427,6 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, fml::closure pop_debug_marker = [encoder]() { [encoder popDebugGroup]; }; for (const auto& command : commands_) { - if (command.vertex_count == 0u) { - continue; - } - if (command.instance_count == 0u) { - continue; - } - #ifdef IMPELLER_DEBUG fml::ScopedCleanupClosure auto_pop_debug_marker(pop_debug_marker); if (!command.label.empty()) { @@ -479,6 +465,12 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, pipeline_desc.GetPolygonMode())]; [encoder setStencilReferenceValue:command.stencil_reference]; + if (!Bind(pass_bindings, *allocator, ShaderStage::kVertex, + VertexDescriptor::kReservedVertexBufferIndex, + command.vertex_buffer.vertex_buffer)) { + return false; + } + if (!bind_stage_resources(command.vertex_bindings, ShaderStage::kVertex)) { return false; } @@ -488,7 +480,7 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, } const PrimitiveType primitive_type = pipeline_desc.GetPrimitiveType(); - if (command.index_type == IndexType::kNone) { + if (command.vertex_buffer.index_type == IndexType::kNone) { if (command.instance_count != 1u) { #if TARGET_OS_SIMULATOR VALIDATION_LOG << "iOS Simulator does not support instanced rendering."; @@ -496,22 +488,22 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, #else // TARGET_OS_SIMULATOR [encoder drawPrimitives:ToMTLPrimitiveType(primitive_type) vertexStart:command.base_vertex - vertexCount:command.vertex_count + vertexCount:command.vertex_buffer.vertex_count instanceCount:command.instance_count baseInstance:0u]; #endif // TARGET_OS_SIMULATOR } else { [encoder drawPrimitives:ToMTLPrimitiveType(primitive_type) vertexStart:command.base_vertex - vertexCount:command.vertex_count]; + vertexCount:command.vertex_buffer.vertex_count]; } continue; } - if (command.index_type == IndexType::kUnknown) { + if (command.vertex_buffer.index_type == IndexType::kUnknown) { return false; } - auto index_buffer = command.index_buffer.buffer; + auto index_buffer = command.vertex_buffer.index_buffer.buffer; if (!index_buffer) { return false; } @@ -525,30 +517,34 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr& allocator, return false; } - FML_DCHECK(command.vertex_count * - (command.index_type == IndexType::k16bit ? 2 : 4) == - command.index_buffer.range.length); + FML_DCHECK( + command.vertex_buffer.vertex_count * + (command.vertex_buffer.index_type == IndexType::k16bit ? 2 : 4) == + command.vertex_buffer.index_buffer.range.length); if (command.instance_count != 1u) { #if TARGET_OS_SIMULATOR VALIDATION_LOG << "iOS Simulator does not support instanced rendering."; return false; #else // TARGET_OS_SIMULATOR - [encoder drawIndexedPrimitives:ToMTLPrimitiveType(primitive_type) - indexCount:command.vertex_count - indexType:ToMTLIndexType(command.index_type) - indexBuffer:mtl_index_buffer - indexBufferOffset:command.index_buffer.range.offset - instanceCount:command.instance_count - baseVertex:command.base_vertex - baseInstance:0u]; + [encoder + drawIndexedPrimitives:ToMTLPrimitiveType(primitive_type) + indexCount:command.vertex_buffer.vertex_count + indexType:ToMTLIndexType(command.vertex_buffer.index_type) + indexBuffer:mtl_index_buffer + indexBufferOffset:command.vertex_buffer.index_buffer.range.offset + instanceCount:command.instance_count + baseVertex:command.base_vertex + baseInstance:0u]; #endif // TARGET_OS_SIMULATOR } else { - [encoder drawIndexedPrimitives:ToMTLPrimitiveType(primitive_type) - indexCount:command.vertex_count - indexType:ToMTLIndexType(command.index_type) - indexBuffer:mtl_index_buffer - indexBufferOffset:command.index_buffer.range.offset]; + [encoder + drawIndexedPrimitives:ToMTLPrimitiveType(primitive_type) + indexCount:command.vertex_buffer.vertex_count + indexType:ToMTLIndexType(command.vertex_buffer.index_type) + indexBuffer:mtl_index_buffer + indexBufferOffset:command.vertex_buffer.index_buffer.range + .offset]; } } return true; diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/binding_helpers_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/binding_helpers_vk.cc index 9acc128ee3..e331ee7e8e 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/binding_helpers_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/binding_helpers_vk.cc @@ -26,7 +26,7 @@ static bool BindImages(const Bindings& bindings, for (const auto& [index, data] : bindings.sampled_images) { auto texture = data.texture.resource; const auto& texture_vk = TextureVK::Cast(*texture); - const SamplerVK& sampler = SamplerVK::Cast(*data.sampler.resource); + const SamplerVK& sampler = SamplerVK::Cast(*data.sampler); if (!encoder->Track(texture) || !encoder->Track(sampler.GetSharedSampler())) { diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/render_pass_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/render_pass_vk.cc index 32ecf0534e..d720b8abf2 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -351,10 +351,6 @@ static bool EncodeCommand(const Context& context, PassBindingsCache& command_buffer_cache, const ISize& target_size, const vk::DescriptorSet vk_desc_set) { - if (command.vertex_count == 0u || command.instance_count == 0u) { - return true; - } - #ifdef IMPELLER_DEBUG fml::ScopedCleanupClosure pop_marker( [&encoder]() { encoder.PopDebugGroup(); }); @@ -388,14 +384,13 @@ static bool EncodeCommand(const Context& context, command.stencil_reference); // Configure vertex and index and buffers for binding. - auto vertex_buffer_view = command.GetVertexBuffer(); + auto& vertex_buffer_view = command.vertex_buffer.vertex_buffer; if (!vertex_buffer_view) { return false; } auto& allocator = *context.GetResourceAllocator(); - auto vertex_buffer = vertex_buffer_view.buffer->GetDeviceBuffer(allocator); if (!vertex_buffer) { @@ -414,9 +409,9 @@ static bool EncodeCommand(const Context& context, vk::DeviceSize vertex_buffer_offsets[] = {vertex_buffer_view.range.offset}; cmd_buffer.bindVertexBuffers(0u, 1u, vertex_buffers, vertex_buffer_offsets); - if (command.index_type != IndexType::kNone) { + if (command.vertex_buffer.index_type != IndexType::kNone) { // Bind the index buffer. - auto index_buffer_view = command.index_buffer; + auto index_buffer_view = command.vertex_buffer.index_buffer; if (!index_buffer_view) { return false; } @@ -435,20 +430,20 @@ static bool EncodeCommand(const Context& context, auto index_buffer_handle = DeviceBufferVK::Cast(*index_buffer).GetBuffer(); cmd_buffer.bindIndexBuffer(index_buffer_handle, index_buffer_view.range.offset, - ToVKIndexType(command.index_type)); + ToVKIndexType(command.vertex_buffer.index_type)); // Engage! - cmd_buffer.drawIndexed(command.vertex_count, // index count + cmd_buffer.drawIndexed(command.vertex_buffer.vertex_count, // index count command.instance_count, // instance count 0u, // first index command.base_vertex, // vertex offset 0u // first instance ); } else { - cmd_buffer.draw(command.vertex_count, // vertex count - command.instance_count, // instance count - command.base_vertex, // vertex offset - 0u // first instance + cmd_buffer.draw(command.vertex_buffer.vertex_count, // vertex count + command.instance_count, // instance count + command.base_vertex, // vertex offset + 0u // first instance ); } return true; diff --git a/engine/src/flutter/impeller/renderer/command.cc b/engine/src/flutter/impeller/renderer/command.cc index a373a31742..ed7fc0bc49 100644 --- a/engine/src/flutter/impeller/renderer/command.cc +++ b/engine/src/flutter/impeller/renderer/command.cc @@ -12,24 +12,16 @@ namespace impeller { -bool Command::BindVertices(const VertexBuffer& buffer) { +bool Command::BindVertices(VertexBuffer buffer) { if (buffer.index_type == IndexType::kUnknown) { VALIDATION_LOG << "Cannot bind vertex buffer with an unknown index type."; return false; } - vertex_bindings.vertex_buffer = - BufferAndUniformSlot{.slot = {}, .view = {nullptr, buffer.vertex_buffer}}; - index_buffer = buffer.index_buffer; - vertex_count = buffer.vertex_count; - index_type = buffer.index_type; + vertex_buffer = std::move(buffer); return true; } -BufferView Command::GetVertexBuffer() const { - return vertex_bindings.vertex_buffer.view.resource; -} - bool Command::BindResource(ShaderStage stage, const ShaderUniformSlot& slot, const ShaderMetadata& metadata, @@ -93,14 +85,14 @@ bool Command::BindResource(ShaderStage stage, vertex_bindings.sampled_images[slot.sampler_index] = TextureAndSampler{ .slot = slot, .texture = {&metadata, std::move(texture)}, - .sampler = {&metadata, std::move(sampler)}, + .sampler = std::move(sampler), }; return true; case ShaderStage::kFragment: fragment_bindings.sampled_images[slot.sampler_index] = TextureAndSampler{ .slot = slot, .texture = {&metadata, std::move(texture)}, - .sampler = {&metadata, std::move(sampler)}, + .sampler = std::move(sampler), }; return true; case ShaderStage::kCompute: diff --git a/engine/src/flutter/impeller/renderer/command.h b/engine/src/flutter/impeller/renderer/command.h index 0c2d08ebe8..d64215d134 100644 --- a/engine/src/flutter/impeller/renderer/command.h +++ b/engine/src/flutter/impeller/renderer/command.h @@ -60,13 +60,12 @@ struct Resource { using BufferResource = Resource; using TextureResource = Resource>; -using SamplerResource = Resource>; /// @brief combines the texture, sampler and sampler slot information. struct TextureAndSampler { SampledImageSlot slot; TextureResource texture; - SamplerResource sampler; + std::shared_ptr sampler; }; /// @brief combines the buffer resource and its uniform slot information. @@ -78,8 +77,6 @@ struct BufferAndUniformSlot { struct Bindings { std::map sampled_images; std::map buffers; - // This is only valid for vertex bindings. - BufferAndUniformSlot vertex_buffer; }; //------------------------------------------------------------------------------ @@ -111,29 +108,6 @@ struct Command : public ResourceBinder { /// stage. /// Bindings fragment_bindings; - //---------------------------------------------------------------------------- - /// The index buffer binding used by the vertex shader stage. Instead of - /// setting this directly, it usually easier to specify the vertex and index - /// buffer bindings directly via a single call to `BindVertices`. - /// - /// @see `BindVertices` - /// - BufferView index_buffer; - //---------------------------------------------------------------------------- - /// The number of vertices to draw. - /// - /// If the index_type is `IndexType::kNone`, this is a count into the vertex - /// buffer. Otherwise, it is a count into the index buffer. Set the vertex and - /// index buffers as well as the index count using a call to `BindVertices`. - /// - /// @see `BindVertices` - /// - 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; #ifdef IMPELLER_DEBUG //---------------------------------------------------------------------------- @@ -176,14 +150,19 @@ struct Command : public ResourceBinder { /// size_t instance_count = 1u; + //---------------------------------------------------------------------------- + /// The bound per-vertex data and optional index buffer. + VertexBuffer vertex_buffer; + //---------------------------------------------------------------------------- /// @brief Specify the vertex and index buffer to use for this command. /// - /// @param[in] buffer The vertex and index buffer definition. + /// @param[in] buffer The vertex and index buffer definition. If possible, + /// this value should be moved and not copied. /// /// @return returns if the binding was updated. /// - bool BindVertices(const VertexBuffer& buffer); + bool BindVertices(VertexBuffer buffer); // |ResourceBinder| bool BindResource(ShaderStage stage, @@ -203,8 +182,6 @@ struct Command : public ResourceBinder { std::shared_ptr texture, std::shared_ptr sampler) override; - BufferView GetVertexBuffer() const; - bool IsValid() const { return pipeline && pipeline->IsValid(); } private: diff --git a/engine/src/flutter/impeller/renderer/compute_command.cc b/engine/src/flutter/impeller/renderer/compute_command.cc index 902edcf470..78b9fb99ec 100644 --- a/engine/src/flutter/impeller/renderer/compute_command.cc +++ b/engine/src/flutter/impeller/renderer/compute_command.cc @@ -50,7 +50,7 @@ bool ComputeCommand::BindResource(ShaderStage stage, bindings.sampled_images[slot.sampler_index] = TextureAndSampler{ .slot = slot, .texture = {&metadata, std::move(texture)}, - .sampler = {&metadata, std::move(sampler)}, + .sampler = std::move(sampler), }; return false; diff --git a/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc b/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc index bec4030735..b49968fcdb 100644 --- a/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc +++ b/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc @@ -153,11 +153,10 @@ TEST_P(ComputeSubgroupTest, PathPlayground) { vertex_buffer_count->AsBufferView().contents) ->count; - VertexBuffer render_vertex_buffer{ - .vertex_buffer = vertex_buffer->AsBufferView(), - .vertex_count = count, - .index_type = IndexType::kNone}; - cmd.BindVertices(render_vertex_buffer); + cmd.BindVertices( + VertexBuffer{.vertex_buffer = vertex_buffer->AsBufferView(), + .vertex_count = count, + .index_type = IndexType::kNone}); VS::FrameInfo frame_info; auto world_matrix = Matrix::MakeScale(GetContentScale()); @@ -357,11 +356,10 @@ TEST_P(ComputeSubgroupTest, LargePath) { vertex_buffer_count->AsBufferView().contents) ->count; - VertexBuffer render_vertex_buffer{ - .vertex_buffer = vertex_buffer->AsBufferView(), - .vertex_count = count, - .index_type = IndexType::kNone}; - cmd.BindVertices(render_vertex_buffer); + cmd.BindVertices( + VertexBuffer{.vertex_buffer = vertex_buffer->AsBufferView(), + .vertex_count = count, + .index_type = IndexType::kNone}); VS::FrameInfo frame_info; auto world_matrix = Matrix::MakeScale(GetContentScale()); @@ -441,11 +439,10 @@ TEST_P(ComputeSubgroupTest, QuadAndCubicInOnePath) { vertex_buffer_count->AsBufferView().contents) ->count; - VertexBuffer render_vertex_buffer{ - .vertex_buffer = vertex_buffer->AsBufferView(), - .vertex_count = count, - .index_type = IndexType::kNone}; - cmd.BindVertices(render_vertex_buffer); + cmd.BindVertices( + VertexBuffer{.vertex_buffer = vertex_buffer->AsBufferView(), + .vertex_count = count, + .index_type = IndexType::kNone}); VS::FrameInfo frame_info; auto world_matrix = Matrix::MakeScale(GetContentScale()); diff --git a/engine/src/flutter/impeller/renderer/render_pass.cc b/engine/src/flutter/impeller/renderer/render_pass.cc index 8cc60b93ea..66b9551588 100644 --- a/engine/src/flutter/impeller/renderer/render_pass.cc +++ b/engine/src/flutter/impeller/renderer/render_pass.cc @@ -74,13 +74,8 @@ bool RenderPass::AddCommand(Command&& command) { } } - if (command.vertex_count == 0u) { - // Essentially a no-op. Don't record the command but this is not necessary - // an error either. - return true; - } - - if (command.instance_count == 0u) { + if (command.vertex_buffer.vertex_count == 0u || + command.instance_count == 0u) { // Essentially a no-op. Don't record the command but this is not necessary // an error either. return true; diff --git a/engine/src/flutter/impeller/renderer/renderer_unittests.cc b/engine/src/flutter/impeller/renderer/renderer_unittests.cc index 9ca1ed2cae..a407350402 100644 --- a/engine/src/flutter/impeller/renderer/renderer_unittests.cc +++ b/engine/src/flutter/impeller/renderer/renderer_unittests.cc @@ -72,10 +72,6 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { {{800, 800, 0.0}, {1.0, 1.0}}, // 3 {{100, 800, 0.0}, {0.0, 1.0}}, // 4 }); - auto vertex_buffer = - vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator()); - ASSERT_TRUE(vertex_buffer); - auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto boston = CreateTextureForFixture("boston.jpg"); ASSERT_TRUE(bridge && boston); @@ -96,7 +92,8 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { DEBUG_COMMAND_INFO(cmd, "Box"); cmd.pipeline = pipeline; - cmd.BindVertices(vertex_buffer); + cmd.BindVertices( + vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator())); VS::UniformBuffer uniforms; uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * diff --git a/engine/src/flutter/lib/gpu/render_pass.cc b/engine/src/flutter/lib/gpu/render_pass.cc index 8dd9403d29..24e01f2ad2 100644 --- a/engine/src/flutter/lib/gpu/render_pass.cc +++ b/engine/src/flutter/lib/gpu/render_pass.cc @@ -395,10 +395,9 @@ bool InternalFlutterGpu_RenderPass_BindTexture( void InternalFlutterGpu_RenderPass_ClearBindings( flutter::gpu::RenderPass* wrapper) { auto& command = wrapper->GetCommand(); - command.vertex_count = 0; + command.vertex_buffer = {}; command.vertex_bindings = {}; command.fragment_bindings = {}; - command.index_buffer = {}; } void InternalFlutterGpu_RenderPass_SetColorBlendEnable(