From 264e3aa567b627dd6198412d6ab66c2d929a6b28 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Mon, 12 Jun 2023 14:13:19 -0700 Subject: [PATCH 1/6] [Impeller] Added cache for command buffers in vulkan --- impeller/renderer/backend/vulkan/BUILD.gn | 2 + .../backend/vulkan/command_buffer_cache.h | 93 ++++++++++++++++++ .../vulkan/command_buffer_cache_unittests.cc | 95 +++++++++++++++++++ .../renderer/backend/vulkan/render_pass_vk.cc | 35 ++++--- .../renderer/backend/vulkan/render_pass_vk.h | 2 + 5 files changed, 212 insertions(+), 15 deletions(-) create mode 100644 impeller/renderer/backend/vulkan/command_buffer_cache.h create mode 100644 impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 96fe23a6c310d..fabd88a91267e 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -9,6 +9,7 @@ impeller_component("vulkan_unittests") { testonly = true sources = [ "blit_command_vk_unittests.cc", + "command_buffer_cache_unittests.cc", "context_vk_unittests.cc", "test/mock_vulkan.cc", "test/mock_vulkan.h", @@ -29,6 +30,7 @@ impeller_component("vulkan") { "blit_pass_vk.h", "capabilities_vk.cc", "capabilities_vk.h", + "command_buffer_cache.h", "command_buffer_vk.cc", "command_buffer_vk.h", "command_encoder_vk.cc", diff --git a/impeller/renderer/backend/vulkan/command_buffer_cache.h b/impeller/renderer/backend/vulkan/command_buffer_cache.h new file mode 100644 index 0000000000000..acda305347a03 --- /dev/null +++ b/impeller/renderer/backend/vulkan/command_buffer_cache.h @@ -0,0 +1,93 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include + +#include "flutter/impeller/renderer/backend/vulkan/vk.h" + +namespace impeller { + +template +class CommandBufferCache { + public: + void bindPipeline(CommandBuffer command_buffer, + vk::PipelineBindPoint pipeline_bind_point, + vk::Pipeline pipeline) { + switch (pipeline_bind_point) { + case vk::PipelineBindPoint::eGraphics: + if (graphics_pipeline_.has_value() && + graphics_pipeline_.value() == pipeline) { + return; + } + graphics_pipeline_ = pipeline; + break; + case vk::PipelineBindPoint::eCompute: + if (compute_pipeline_.has_value() && + compute_pipeline_.value() == pipeline) { + return; + } + compute_pipeline_ = pipeline; + break; + default: + break; + } + command_buffer.bindPipeline(pipeline_bind_point, pipeline); + } + + void setStencilReference(CommandBuffer command_buffer, + vk::StencilFaceFlags face_mask, + uint32_t reference) { + if (stencil_face_flags_.has_value() && + face_mask == stencil_face_flags_.value() && + reference == stencil_reference_) { + return; + } + stencil_face_flags_ = face_mask; + stencil_reference_ = reference; + command_buffer.setStencilReference(face_mask, reference); + } + + void setScissor(CommandBuffer command_buffer, + uint32_t first_scissor, + uint32_t scissor_count, + const vk::Rect2D* scissors) { + if (first_scissor == 0 && scissor_count == 1) { + if (scissors_.has_value() && scissors_.value() == scissors[0]) { + return; + } + scissors_ = scissors[0]; + } + command_buffer.setScissor(first_scissor, scissor_count, scissors); + } + + void setViewport(CommandBuffer command_buffer, + uint32_t first_viewport, + uint32_t viewport_count, + const vk::Viewport* viewports) { + if (first_viewport == 0 && viewport_count == 1) { + // Note that this is doing equality checks on floating point numbers. + if (viewport_.has_value() && viewport_.value() == viewports[0]) { + return; + } + viewport_ = viewports[0]; + } + command_buffer.setViewport(first_viewport, viewport_count, viewports); + } + + private: + // bindPipeline + std::optional graphics_pipeline_; + std::optional compute_pipeline_; + // setStencilReference + std::optional stencil_face_flags_; + uint32_t stencil_reference_ = 0; + // setScissor + std::optional scissors_; + // setViewport + std::optional viewport_; +}; + +} // namespace impeller diff --git a/impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc b/impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc new file mode 100644 index 0000000000000..c30d1bd495a7a --- /dev/null +++ b/impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc @@ -0,0 +1,95 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/testing/testing.h" +#include "impeller/renderer/backend/vulkan/command_buffer_cache.h" + +namespace impeller { +namespace testing { + +namespace { +struct Tallies { + int32_t bindPipeline_count = 0; + int32_t setStencilReference_count = 0; + int32_t setScissor_count = 0; + int32_t setViewport_count = 0; +}; + +class MockCommandBuffer { + public: + MockCommandBuffer() : tallies_(new Tallies()) {} + + void bindPipeline(vk::PipelineBindPoint pipeline_bind_point, + vk::Pipeline pipeline) { + tallies_->bindPipeline_count += 1; + } + + void setStencilReference(vk::StencilFaceFlags face_mask, uint32_t reference) { + tallies_->setStencilReference_count += 1; + } + + void setScissor(uint32_t first_scissor, + uint32_t scissor_count, + const vk::Rect2D* scissors) { + tallies_->setScissor_count += 1; + } + + void setViewport(uint32_t first_viewport, + uint32_t viewport_count, + const vk::Viewport* viewports) { + tallies_->setViewport_count += 1; + } + + std::shared_ptr tallies_; +}; +} // namespace + +TEST(CommandBufferCacheTest, bindPipeline) { + CommandBufferCache cache; + MockCommandBuffer buffer; + VkPipeline vk_pipeline = reinterpret_cast(0xfeedface); + vk::Pipeline pipeline(vk_pipeline); + ASSERT_EQ(buffer.tallies_->bindPipeline_count, 0); + cache.bindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); + ASSERT_EQ(buffer.tallies_->bindPipeline_count, 1); + cache.bindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); + ASSERT_EQ(buffer.tallies_->bindPipeline_count, 1); +} + +TEST(CommandBufferCacheTest, setStencilReference) { + CommandBufferCache cache; + MockCommandBuffer buffer; + ASSERT_EQ(buffer.tallies_->setStencilReference_count, 0); + cache.setStencilReference( + buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123); + ASSERT_EQ(buffer.tallies_->setStencilReference_count, 1); + cache.setStencilReference( + buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123); + ASSERT_EQ(buffer.tallies_->setStencilReference_count, 1); +} + +TEST(CommandBufferCacheTest, setScissor) { + CommandBufferCache cache; + MockCommandBuffer buffer; + vk::Rect2D scissors; + ASSERT_EQ(buffer.tallies_->setScissor_count, 0); + cache.setScissor(buffer, 0, 1, &scissors); + ASSERT_EQ(buffer.tallies_->setScissor_count, 1); + cache.setScissor(buffer, 0, 1, &scissors); + ASSERT_EQ(buffer.tallies_->setScissor_count, 1); +} + +TEST(CommandBufferCacheTest, setViewport) { + CommandBufferCache cache; + MockCommandBuffer buffer; + vk::Viewport viewports; + ASSERT_EQ(buffer.tallies_->setViewport_count, 0); + cache.setViewport(buffer, 0, 1, &viewports); + ASSERT_EQ(buffer.tallies_->setViewport_count, 1); + cache.setViewport(buffer, 0, 1, &viewports); + ASSERT_EQ(buffer.tallies_->setViewport_count, 1); +} + +} // namespace testing +} // namespace impeller diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 9806fb675a460..24b62092c7729 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -415,9 +415,11 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context, return true; } -static void SetViewportAndScissor(const Command& command, - const vk::CommandBuffer& cmd_buffer, - const ISize& target_size) { +static void SetViewportAndScissor( + const Command& command, + const vk::CommandBuffer& cmd_buffer, + CommandBufferCache& cmd_buffer_cache, + const ISize& target_size) { // Set the viewport. const auto& vp = command.viewport.value_or( {.rect = Rect::MakeSize(target_size)}); @@ -427,7 +429,7 @@ static void SetViewportAndScissor(const Command& command, .setY(vp.rect.size.height) .setMinDepth(0.0f) .setMaxDepth(1.0f); - cmd_buffer.setViewport(0, 1, &viewport); + cmd_buffer_cache.setViewport(cmd_buffer, 0, 1, &viewport); // Set the scissor rect. const auto& sc = command.scissor.value_or(IRect::MakeSize(target_size)); @@ -435,13 +437,15 @@ static void SetViewportAndScissor(const Command& command, vk::Rect2D() .setOffset(vk::Offset2D(sc.origin.x, sc.origin.y)) .setExtent(vk::Extent2D(sc.size.width, sc.size.height)); - cmd_buffer.setScissor(0, 1, &scissor); + cmd_buffer_cache.setScissor(cmd_buffer, 0, 1, &scissor); } -static bool EncodeCommand(const Context& context, - const Command& command, - CommandEncoderVK& encoder, - const ISize& target_size) { +static bool EncodeCommand( + const Context& context, + const Command& command, + CommandEncoderVK& encoder, + CommandBufferCache& command_buffer_cache, + const ISize& target_size) { if (command.vertex_count == 0u || command.instance_count == 0u) { return true; } @@ -466,15 +470,15 @@ static bool EncodeCommand(const Context& context, return false; } - cmd_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, - pipeline_vk.GetPipeline()); + command_buffer_cache.bindPipeline( + cmd_buffer, vk::PipelineBindPoint::eGraphics, pipeline_vk.GetPipeline()); // Set the viewport and scissors. - SetViewportAndScissor(command, cmd_buffer, target_size); + SetViewportAndScissor(command, cmd_buffer, command_buffer_cache, target_size); // Set the stencil reference. - cmd_buffer.setStencilReference( - vk::StencilFaceFlagBits::eVkStencilFrontAndBack, + command_buffer_cache.setStencilReference( + cmd_buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, command.stencil_reference); // Configure vertex and index and buffers for binding. @@ -619,7 +623,8 @@ bool RenderPassVK::OnEncodeCommands(const Context& context) const { continue; } - if (!EncodeCommand(context, command, *encoder, target_size)) { + if (!EncodeCommand(context, command, *encoder, command_buffer_cache_, + target_size)) { return false; } } diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.h b/impeller/renderer/backend/vulkan/render_pass_vk.h index 1f267cea5211b..c8ac6eb0ac8bf 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.h +++ b/impeller/renderer/backend/vulkan/render_pass_vk.h @@ -5,6 +5,7 @@ #pragma once #include "flutter/fml/macros.h" +#include "impeller/renderer/backend/vulkan/command_buffer_cache.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/shared_object_vk.h" #include "impeller/renderer/backend/vulkan/texture_vk.h" @@ -26,6 +27,7 @@ class RenderPassVK final : public RenderPass { std::weak_ptr encoder_; std::string debug_label_; bool is_valid_ = false; + mutable CommandBufferCache command_buffer_cache_; RenderPassVK(const std::shared_ptr& context, const RenderTarget& target, From 46b1453168a90c492d26efc823aab8c3e54df451 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 13 Jun 2023 09:53:02 -0700 Subject: [PATCH 2/6] chinmay feedback1 --- impeller/renderer/backend/vulkan/BUILD.gn | 4 ++-- ...nd_buffer_cache.h => pass_bindings_cache.h} | 2 +- ...sts.cc => pass_bindings_cache_unittests.cc} | 18 +++++++++--------- .../renderer/backend/vulkan/render_pass_vk.cc | 6 +++--- .../renderer/backend/vulkan/render_pass_vk.h | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) rename impeller/renderer/backend/vulkan/{command_buffer_cache.h => pass_bindings_cache.h} (99%) rename impeller/renderer/backend/vulkan/{command_buffer_cache_unittests.cc => pass_bindings_cache_unittests.cc} (86%) diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index fabd88a91267e..b3eaa42d24685 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -9,8 +9,8 @@ impeller_component("vulkan_unittests") { testonly = true sources = [ "blit_command_vk_unittests.cc", - "command_buffer_cache_unittests.cc", "context_vk_unittests.cc", + "pass_bindings_cache_unittests.cc", "test/mock_vulkan.cc", "test/mock_vulkan.h", ] @@ -30,7 +30,6 @@ impeller_component("vulkan") { "blit_pass_vk.h", "capabilities_vk.cc", "capabilities_vk.h", - "command_buffer_cache.h", "command_buffer_vk.cc", "command_buffer_vk.h", "command_encoder_vk.cc", @@ -53,6 +52,7 @@ impeller_component("vulkan") { "fence_waiter_vk.h", "formats_vk.cc", "formats_vk.h", + "pass_bindings_cache.h", "pipeline_cache_vk.cc", "pipeline_cache_vk.h", "pipeline_library_vk.cc", diff --git a/impeller/renderer/backend/vulkan/command_buffer_cache.h b/impeller/renderer/backend/vulkan/pass_bindings_cache.h similarity index 99% rename from impeller/renderer/backend/vulkan/command_buffer_cache.h rename to impeller/renderer/backend/vulkan/pass_bindings_cache.h index acda305347a03..60655379ff564 100644 --- a/impeller/renderer/backend/vulkan/command_buffer_cache.h +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache.h @@ -11,7 +11,7 @@ namespace impeller { template -class CommandBufferCache { +class PassBindingsCache { public: void bindPipeline(CommandBuffer command_buffer, vk::PipelineBindPoint pipeline_bind_point, diff --git a/impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc b/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc similarity index 86% rename from impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc rename to impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc index c30d1bd495a7a..ef5d8669e20aa 100644 --- a/impeller/renderer/backend/vulkan/command_buffer_cache_unittests.cc +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "flutter/testing/testing.h" -#include "impeller/renderer/backend/vulkan/command_buffer_cache.h" +#include "impeller/renderer/backend/vulkan/pass_bindings_cache.h" namespace impeller { namespace testing { @@ -45,8 +45,8 @@ class MockCommandBuffer { }; } // namespace -TEST(CommandBufferCacheTest, bindPipeline) { - CommandBufferCache cache; +TEST(PassBindingsCacheTest, bindPipeline) { + PassBindingsCache cache; MockCommandBuffer buffer; VkPipeline vk_pipeline = reinterpret_cast(0xfeedface); vk::Pipeline pipeline(vk_pipeline); @@ -57,8 +57,8 @@ TEST(CommandBufferCacheTest, bindPipeline) { ASSERT_EQ(buffer.tallies_->bindPipeline_count, 1); } -TEST(CommandBufferCacheTest, setStencilReference) { - CommandBufferCache cache; +TEST(PassBindingsCacheTest, setStencilReference) { + PassBindingsCache cache; MockCommandBuffer buffer; ASSERT_EQ(buffer.tallies_->setStencilReference_count, 0); cache.setStencilReference( @@ -69,8 +69,8 @@ TEST(CommandBufferCacheTest, setStencilReference) { ASSERT_EQ(buffer.tallies_->setStencilReference_count, 1); } -TEST(CommandBufferCacheTest, setScissor) { - CommandBufferCache cache; +TEST(PassBindingsCacheTest, setScissor) { + PassBindingsCache cache; MockCommandBuffer buffer; vk::Rect2D scissors; ASSERT_EQ(buffer.tallies_->setScissor_count, 0); @@ -80,8 +80,8 @@ TEST(CommandBufferCacheTest, setScissor) { ASSERT_EQ(buffer.tallies_->setScissor_count, 1); } -TEST(CommandBufferCacheTest, setViewport) { - CommandBufferCache cache; +TEST(PassBindingsCacheTest, setViewport) { + PassBindingsCache cache; MockCommandBuffer buffer; vk::Viewport viewports; ASSERT_EQ(buffer.tallies_->setViewport_count, 0); diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 24b62092c7729..700ddbb62032f 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -418,7 +418,7 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context, static void SetViewportAndScissor( const Command& command, const vk::CommandBuffer& cmd_buffer, - CommandBufferCache& cmd_buffer_cache, + PassBindingsCache& cmd_buffer_cache, const ISize& target_size) { // Set the viewport. const auto& vp = command.viewport.value_or( @@ -444,7 +444,7 @@ static bool EncodeCommand( const Context& context, const Command& command, CommandEncoderVK& encoder, - CommandBufferCache& command_buffer_cache, + PassBindingsCache& command_buffer_cache, const ISize& target_size) { if (command.vertex_count == 0u || command.instance_count == 0u) { return true; @@ -623,7 +623,7 @@ bool RenderPassVK::OnEncodeCommands(const Context& context) const { continue; } - if (!EncodeCommand(context, command, *encoder, command_buffer_cache_, + if (!EncodeCommand(context, command, *encoder, pass_bindings_cache_, target_size)) { return false; } diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.h b/impeller/renderer/backend/vulkan/render_pass_vk.h index c8ac6eb0ac8bf..3a6cd0db2b405 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.h +++ b/impeller/renderer/backend/vulkan/render_pass_vk.h @@ -5,8 +5,8 @@ #pragma once #include "flutter/fml/macros.h" -#include "impeller/renderer/backend/vulkan/command_buffer_cache.h" #include "impeller/renderer/backend/vulkan/context_vk.h" +#include "impeller/renderer/backend/vulkan/pass_bindings_cache.h" #include "impeller/renderer/backend/vulkan/shared_object_vk.h" #include "impeller/renderer/backend/vulkan/texture_vk.h" #include "impeller/renderer/backend/vulkan/vk.h" @@ -27,7 +27,7 @@ class RenderPassVK final : public RenderPass { std::weak_ptr encoder_; std::string debug_label_; bool is_valid_ = false; - mutable CommandBufferCache command_buffer_cache_; + mutable PassBindingsCache pass_bindings_cache_; RenderPassVK(const std::shared_ptr& context, const RenderTarget& target, From 51c862571290bae2fbfec009bf2430fc59c36b65 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 13 Jun 2023 10:33:17 -0700 Subject: [PATCH 3/6] redid the tests --- impeller/renderer/backend/vulkan/BUILD.gn | 1 + .../backend/vulkan/command_encoder_vk.h | 26 +---- .../backend/vulkan/pass_bindings_cache.cc | 72 ++++++++++++ .../backend/vulkan/pass_bindings_cache.h | 63 ++--------- .../vulkan/pass_bindings_cache_unittests.cc | 105 +++++++++--------- .../renderer/backend/vulkan/render_pass_vk.cc | 20 ++-- .../renderer/backend/vulkan/render_pass_vk.h | 2 +- .../backend/vulkan/test/mock_vulkan.cc | 60 +++++++++- 8 files changed, 208 insertions(+), 141 deletions(-) create mode 100644 impeller/renderer/backend/vulkan/pass_bindings_cache.cc diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index b3eaa42d24685..4e451c4a233a7 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -52,6 +52,7 @@ impeller_component("vulkan") { "fence_waiter_vk.h", "formats_vk.cc", "formats_vk.h", + "pass_bindings_cache.cc", "pass_bindings_cache.h", "pipeline_cache_vk.cc", "pipeline_cache_vk.h", diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk.h b/impeller/renderer/backend/vulkan/command_encoder_vk.h index 32e176023d049..985e955fe0142 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk.h +++ b/impeller/renderer/backend/vulkan/command_encoder_vk.h @@ -18,13 +18,6 @@ namespace impeller { -namespace testing { -class BlitCommandVkTest_BlitCopyTextureToTextureCommandVK_Test; -class BlitCommandVkTest_BlitCopyTextureToBufferCommandVK_Test; -class BlitCommandVkTest_BlitCopyBufferToTextureCommandVK_Test; -class BlitCommandVkTest_BlitGenerateMipmapCommandVK_Test; -} // namespace testing - class ContextVK; class DeviceBuffer; class Buffer; @@ -37,6 +30,12 @@ class CommandEncoderVK { public: using SubmitCallback = std::function; + // Visible for testing. + CommandEncoderVK(const std::weak_ptr& device_holder, + const std::shared_ptr& queue, + const std::shared_ptr& pool, + std::shared_ptr fence_waiter); + ~CommandEncoderVK(); bool IsValid() const; @@ -68,14 +67,6 @@ class CommandEncoderVK { private: friend class ContextVK; - friend class ::impeller::testing:: - BlitCommandVkTest_BlitCopyTextureToTextureCommandVK_Test; - friend class ::impeller::testing:: - BlitCommandVkTest_BlitCopyTextureToBufferCommandVK_Test; - friend class ::impeller::testing:: - BlitCommandVkTest_BlitGenerateMipmapCommandVK_Test; - friend class ::impeller::testing:: - BlitCommandVkTest_BlitCopyBufferToTextureCommandVK_Test; std::weak_ptr device_holder_; std::shared_ptr queue_; @@ -83,11 +74,6 @@ class CommandEncoderVK { std::shared_ptr tracked_objects_; bool is_valid_ = false; - CommandEncoderVK(const std::weak_ptr& device_holder, - const std::shared_ptr& queue, - const std::shared_ptr& pool, - std::shared_ptr fence_waiter); - void Reset(); FML_DISALLOW_COPY_AND_ASSIGN(CommandEncoderVK); diff --git a/impeller/renderer/backend/vulkan/pass_bindings_cache.cc b/impeller/renderer/backend/vulkan/pass_bindings_cache.cc new file mode 100644 index 0000000000000..925f1d38d15b1 --- /dev/null +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache.cc @@ -0,0 +1,72 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/backend/vulkan/pass_bindings_cache.h" + +namespace impeller { +void PassBindingsCache::bindPipeline(vk::CommandBuffer command_buffer, + vk::PipelineBindPoint pipeline_bind_point, + vk::Pipeline pipeline) { + switch (pipeline_bind_point) { + case vk::PipelineBindPoint::eGraphics: + if (graphics_pipeline_.has_value() && + graphics_pipeline_.value() == pipeline) { + return; + } + graphics_pipeline_ = pipeline; + break; + case vk::PipelineBindPoint::eCompute: + if (compute_pipeline_.has_value() && + compute_pipeline_.value() == pipeline) { + return; + } + compute_pipeline_ = pipeline; + break; + default: + break; + } + command_buffer.bindPipeline(pipeline_bind_point, pipeline); +} + +void PassBindingsCache::setStencilReference(vk::CommandBuffer command_buffer, + vk::StencilFaceFlags face_mask, + uint32_t reference) { + if (stencil_face_flags_.has_value() && + face_mask == stencil_face_flags_.value() && + reference == stencil_reference_) { + return; + } + stencil_face_flags_ = face_mask; + stencil_reference_ = reference; + command_buffer.setStencilReference(face_mask, reference); +} + +void PassBindingsCache::setScissor(vk::CommandBuffer command_buffer, + uint32_t first_scissor, + uint32_t scissor_count, + const vk::Rect2D* scissors) { + if (first_scissor == 0 && scissor_count == 1) { + if (scissors_.has_value() && scissors_.value() == scissors[0]) { + return; + } + scissors_ = scissors[0]; + } + command_buffer.setScissor(first_scissor, scissor_count, scissors); +} + +void PassBindingsCache::setViewport(vk::CommandBuffer command_buffer, + uint32_t first_viewport, + uint32_t viewport_count, + const vk::Viewport* viewports) { + if (first_viewport == 0 && viewport_count == 1) { + // Note that this is doing equality checks on floating point numbers. + if (viewport_.has_value() && viewport_.value() == viewports[0]) { + return; + } + viewport_ = viewports[0]; + } + command_buffer.setViewport(first_viewport, viewport_count, viewports); +} + +} // namespace impeller diff --git a/impeller/renderer/backend/vulkan/pass_bindings_cache.h b/impeller/renderer/backend/vulkan/pass_bindings_cache.h index 60655379ff564..252bb276e49e6 100644 --- a/impeller/renderer/backend/vulkan/pass_bindings_cache.h +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache.h @@ -10,72 +10,25 @@ namespace impeller { -template class PassBindingsCache { public: - void bindPipeline(CommandBuffer command_buffer, + void bindPipeline(vk::CommandBuffer command_buffer, vk::PipelineBindPoint pipeline_bind_point, - vk::Pipeline pipeline) { - switch (pipeline_bind_point) { - case vk::PipelineBindPoint::eGraphics: - if (graphics_pipeline_.has_value() && - graphics_pipeline_.value() == pipeline) { - return; - } - graphics_pipeline_ = pipeline; - break; - case vk::PipelineBindPoint::eCompute: - if (compute_pipeline_.has_value() && - compute_pipeline_.value() == pipeline) { - return; - } - compute_pipeline_ = pipeline; - break; - default: - break; - } - command_buffer.bindPipeline(pipeline_bind_point, pipeline); - } + vk::Pipeline pipeline); - void setStencilReference(CommandBuffer command_buffer, + void setStencilReference(vk::CommandBuffer command_buffer, vk::StencilFaceFlags face_mask, - uint32_t reference) { - if (stencil_face_flags_.has_value() && - face_mask == stencil_face_flags_.value() && - reference == stencil_reference_) { - return; - } - stencil_face_flags_ = face_mask; - stencil_reference_ = reference; - command_buffer.setStencilReference(face_mask, reference); - } + uint32_t reference); - void setScissor(CommandBuffer command_buffer, + void setScissor(vk::CommandBuffer command_buffer, uint32_t first_scissor, uint32_t scissor_count, - const vk::Rect2D* scissors) { - if (first_scissor == 0 && scissor_count == 1) { - if (scissors_.has_value() && scissors_.value() == scissors[0]) { - return; - } - scissors_ = scissors[0]; - } - command_buffer.setScissor(first_scissor, scissor_count, scissors); - } + const vk::Rect2D* scissors); - void setViewport(CommandBuffer command_buffer, + void setViewport(vk::CommandBuffer command_buffer, uint32_t first_viewport, uint32_t viewport_count, - const vk::Viewport* viewports) { - if (first_viewport == 0 && viewport_count == 1) { - // Note that this is doing equality checks on floating point numbers. - if (viewport_.has_value() && viewport_.value() == viewports[0]) { - return; - } - viewport_ = viewports[0]; - } - command_buffer.setViewport(first_viewport, viewport_count, viewports); - } + const vk::Viewport* viewports); private: // bindPipeline diff --git a/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc b/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc index ef5d8669e20aa..4fc0862ffce4a 100644 --- a/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc @@ -3,92 +3,91 @@ // found in the LICENSE file. #include "flutter/testing/testing.h" +#include "impeller/renderer/backend/vulkan/command_encoder_vk.h" #include "impeller/renderer/backend/vulkan/pass_bindings_cache.h" +#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h" namespace impeller { namespace testing { namespace { -struct Tallies { - int32_t bindPipeline_count = 0; - int32_t setStencilReference_count = 0; - int32_t setScissor_count = 0; - int32_t setViewport_count = 0; -}; - -class MockCommandBuffer { - public: - MockCommandBuffer() : tallies_(new Tallies()) {} - - void bindPipeline(vk::PipelineBindPoint pipeline_bind_point, - vk::Pipeline pipeline) { - tallies_->bindPipeline_count += 1; - } - - void setStencilReference(vk::StencilFaceFlags face_mask, uint32_t reference) { - tallies_->setStencilReference_count += 1; - } - - void setScissor(uint32_t first_scissor, - uint32_t scissor_count, - const vk::Rect2D* scissors) { - tallies_->setScissor_count += 1; - } - - void setViewport(uint32_t first_viewport, - uint32_t viewport_count, - const vk::Viewport* viewports) { - tallies_->setViewport_count += 1; +int32_t CountStringViewInstances(const std::vector& strings, + std::string_view target) { + int32_t count = 0; + for (const std::string& str : strings) { + if (str == target) { + count++; + } } - - std::shared_ptr tallies_; -}; + return count; +} } // namespace TEST(PassBindingsCacheTest, bindPipeline) { - PassBindingsCache cache; - MockCommandBuffer buffer; + auto context = CreateMockVulkanContext(); + PassBindingsCache cache; + auto pool = CommandPoolVK::GetThreadLocal(context.get()); + CommandEncoderVK encoder(context->GetDeviceHolder(), + context->GetGraphicsQueue(), pool, + context->GetFenceWaiter()); + auto buffer = encoder.GetCommandBuffer(); VkPipeline vk_pipeline = reinterpret_cast(0xfeedface); vk::Pipeline pipeline(vk_pipeline); - ASSERT_EQ(buffer.tallies_->bindPipeline_count, 0); cache.bindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); - ASSERT_EQ(buffer.tallies_->bindPipeline_count, 1); cache.bindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); - ASSERT_EQ(buffer.tallies_->bindPipeline_count, 1); + std::shared_ptr> functions = + GetMockVulkanFunctions(context->GetDevice()); + EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdBindPipeline"), 1); } TEST(PassBindingsCacheTest, setStencilReference) { - PassBindingsCache cache; - MockCommandBuffer buffer; - ASSERT_EQ(buffer.tallies_->setStencilReference_count, 0); + auto context = CreateMockVulkanContext(); + PassBindingsCache cache; + auto pool = CommandPoolVK::GetThreadLocal(context.get()); + CommandEncoderVK encoder(context->GetDeviceHolder(), + context->GetGraphicsQueue(), pool, + context->GetFenceWaiter()); + auto buffer = encoder.GetCommandBuffer(); cache.setStencilReference( buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123); - ASSERT_EQ(buffer.tallies_->setStencilReference_count, 1); cache.setStencilReference( buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123); - ASSERT_EQ(buffer.tallies_->setStencilReference_count, 1); + std::shared_ptr> functions = + GetMockVulkanFunctions(context->GetDevice()); + EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetStencilReference"), + 1); } TEST(PassBindingsCacheTest, setScissor) { - PassBindingsCache cache; - MockCommandBuffer buffer; + auto context = CreateMockVulkanContext(); + PassBindingsCache cache; + auto pool = CommandPoolVK::GetThreadLocal(context.get()); + CommandEncoderVK encoder(context->GetDeviceHolder(), + context->GetGraphicsQueue(), pool, + context->GetFenceWaiter()); + auto buffer = encoder.GetCommandBuffer(); vk::Rect2D scissors; - ASSERT_EQ(buffer.tallies_->setScissor_count, 0); cache.setScissor(buffer, 0, 1, &scissors); - ASSERT_EQ(buffer.tallies_->setScissor_count, 1); cache.setScissor(buffer, 0, 1, &scissors); - ASSERT_EQ(buffer.tallies_->setScissor_count, 1); + std::shared_ptr> functions = + GetMockVulkanFunctions(context->GetDevice()); + EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetScissor"), 1); } TEST(PassBindingsCacheTest, setViewport) { - PassBindingsCache cache; - MockCommandBuffer buffer; + auto context = CreateMockVulkanContext(); + PassBindingsCache cache; + auto pool = CommandPoolVK::GetThreadLocal(context.get()); + CommandEncoderVK encoder(context->GetDeviceHolder(), + context->GetGraphicsQueue(), pool, + context->GetFenceWaiter()); + auto buffer = encoder.GetCommandBuffer(); vk::Viewport viewports; - ASSERT_EQ(buffer.tallies_->setViewport_count, 0); cache.setViewport(buffer, 0, 1, &viewports); - ASSERT_EQ(buffer.tallies_->setViewport_count, 1); cache.setViewport(buffer, 0, 1, &viewports); - ASSERT_EQ(buffer.tallies_->setViewport_count, 1); + std::shared_ptr> functions = + GetMockVulkanFunctions(context->GetDevice()); + EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetViewport"), 1); } } // namespace testing diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 700ddbb62032f..4ffbbce52fe51 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -415,11 +415,10 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context, return true; } -static void SetViewportAndScissor( - const Command& command, - const vk::CommandBuffer& cmd_buffer, - PassBindingsCache& cmd_buffer_cache, - const ISize& target_size) { +static void SetViewportAndScissor(const Command& command, + const vk::CommandBuffer& cmd_buffer, + PassBindingsCache& cmd_buffer_cache, + const ISize& target_size) { // Set the viewport. const auto& vp = command.viewport.value_or( {.rect = Rect::MakeSize(target_size)}); @@ -440,12 +439,11 @@ static void SetViewportAndScissor( cmd_buffer_cache.setScissor(cmd_buffer, 0, 1, &scissor); } -static bool EncodeCommand( - const Context& context, - const Command& command, - CommandEncoderVK& encoder, - PassBindingsCache& command_buffer_cache, - const ISize& target_size) { +static bool EncodeCommand(const Context& context, + const Command& command, + CommandEncoderVK& encoder, + PassBindingsCache& command_buffer_cache, + const ISize& target_size) { if (command.vertex_count == 0u || command.instance_count == 0u) { return true; } diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.h b/impeller/renderer/backend/vulkan/render_pass_vk.h index 3a6cd0db2b405..b952b7db146ea 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.h +++ b/impeller/renderer/backend/vulkan/render_pass_vk.h @@ -27,7 +27,7 @@ class RenderPassVK final : public RenderPass { std::weak_ptr encoder_; std::string debug_label_; bool is_valid_ = false; - mutable PassBindingsCache pass_bindings_cache_; + mutable PassBindingsCache pass_bindings_cache_; RenderPassVK(const std::shared_ptr& context, const RenderTarget& target, diff --git a/impeller/renderer/backend/vulkan/test/mock_vulkan.cc b/impeller/renderer/backend/vulkan/test/mock_vulkan.cc index aac80e1abac72..eae0cf18ccb68 100644 --- a/impeller/renderer/backend/vulkan/test/mock_vulkan.cc +++ b/impeller/renderer/backend/vulkan/test/mock_vulkan.cc @@ -9,9 +9,23 @@ namespace testing { namespace { +struct MockCommandBuffer { + MockCommandBuffer(std::shared_ptr> called_functions) + : called_functions_(called_functions) {} + std::shared_ptr> called_functions_; +}; + struct MockDevice { MockDevice() : called_functions_(new std::vector()) {} + MockCommandBuffer* NewCommandBuffer() { + std::unique_ptr buffer = + std::make_unique(called_functions_); + MockCommandBuffer* result = buffer.get(); + command_buffers_.emplace_back(std::move(buffer)); + return result; + } std::shared_ptr> called_functions_; + std::vector> command_buffers_; }; void noop() {} @@ -149,7 +163,9 @@ VkResult vkAllocateCommandBuffers( VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers) { - *pCommandBuffers = reinterpret_cast(0x0b0ffe12); + MockDevice* mock_device = reinterpret_cast(device); + *pCommandBuffers = + reinterpret_cast(mock_device->NewCommandBuffer()); return VK_SUCCESS; } @@ -295,6 +311,40 @@ void vkDestroyPipelineCache(VkDevice device, mock_device->called_functions_->push_back("vkDestroyPipelineCache"); } +void vkCmdBindPipeline(VkCommandBuffer commandBuffer, + VkPipelineBindPoint pipelineBindPoint, + VkPipeline pipeline) { + MockCommandBuffer* mock_command_buffer = + reinterpret_cast(commandBuffer); + mock_command_buffer->called_functions_->push_back("vkCmdBindPipeline"); +} + +void vkCmdSetStencilReference(VkCommandBuffer commandBuffer, + VkStencilFaceFlags faceMask, + uint32_t reference) { + MockCommandBuffer* mock_command_buffer = + reinterpret_cast(commandBuffer); + mock_command_buffer->called_functions_->push_back("vkCmdSetStencilReference"); +} + +void vkCmdSetScissor(VkCommandBuffer commandBuffer, + uint32_t firstScissor, + uint32_t scissorCount, + const VkRect2D* pScissors) { + MockCommandBuffer* mock_command_buffer = + reinterpret_cast(commandBuffer); + mock_command_buffer->called_functions_->push_back("vkCmdSetScissor"); +} + +void vkCmdSetViewport(VkCommandBuffer commandBuffer, + uint32_t firstViewport, + uint32_t viewportCount, + const VkViewport* pViewports) { + MockCommandBuffer* mock_command_buffer = + reinterpret_cast(commandBuffer); + mock_command_buffer->called_functions_->push_back("vkCmdSetViewport"); +} + PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance, const char* pName) { if (strcmp("vkEnumerateInstanceExtensionProperties", pName) == 0) { @@ -365,6 +415,14 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance, return (PFN_vkVoidFunction)vkDestroyShaderModule; } else if (strcmp("vkDestroyPipelineCache", pName) == 0) { return (PFN_vkVoidFunction)vkDestroyPipelineCache; + } else if (strcmp("vkCmdBindPipeline", pName) == 0) { + return (PFN_vkVoidFunction)vkCmdBindPipeline; + } else if (strcmp("vkCmdSetStencilReference", pName) == 0) { + return (PFN_vkVoidFunction)vkCmdSetStencilReference; + } else if (strcmp("vkCmdSetScissor", pName) == 0) { + return (PFN_vkVoidFunction)vkCmdSetScissor; + } else if (strcmp("vkCmdSetViewport", pName) == 0) { + return (PFN_vkVoidFunction)vkCmdSetViewport; } return noop; } From 2041de3456fd3a5b7069a9d817b2a82d80114469 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 13 Jun 2023 12:35:49 -0700 Subject: [PATCH 4/6] lint and license --- ci/licenses_golden/licenses_flutter | 4 ++++ impeller/renderer/backend/vulkan/test/mock_vulkan.cc | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 5000803f207e8..09c825e26c410 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1520,6 +1520,8 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.cc + . ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_library_vk.cc + ../../../flutter/LICENSE @@ -4195,6 +4197,8 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h +FILE: ../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache.cc +FILE: ../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_library_vk.cc diff --git a/impeller/renderer/backend/vulkan/test/mock_vulkan.cc b/impeller/renderer/backend/vulkan/test/mock_vulkan.cc index eae0cf18ccb68..d4faece695e4d 100644 --- a/impeller/renderer/backend/vulkan/test/mock_vulkan.cc +++ b/impeller/renderer/backend/vulkan/test/mock_vulkan.cc @@ -10,8 +10,9 @@ namespace testing { namespace { struct MockCommandBuffer { - MockCommandBuffer(std::shared_ptr> called_functions) - : called_functions_(called_functions) {} + explicit MockCommandBuffer( + std::shared_ptr> called_functions) + : called_functions_(std::move(called_functions)) {} std::shared_ptr> called_functions_; }; From 3acfc044eb39754fb5e8d78d39761e13f827c966 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 13 Jun 2023 12:52:41 -0700 Subject: [PATCH 5/6] license --- ci/licenses_golden/excluded_files | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index cbb190fb11605..b9b1d51ac7282 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -147,6 +147,7 @@ ../../../flutter/impeller/playground ../../../flutter/impeller/renderer/backend/vulkan/blit_command_vk_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/context_vk_unittests.cc +../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/test ../../../flutter/impeller/renderer/capabilities_unittests.cc ../../../flutter/impeller/renderer/compute_subgroup_unittests.cc From 6addb4e800bb88d31f55a97c787f5da09287a8ec Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 13 Jun 2023 14:03:11 -0700 Subject: [PATCH 6/6] case fix --- .../backend/vulkan/pass_bindings_cache.cc | 8 ++++---- .../backend/vulkan/pass_bindings_cache.h | 8 ++++---- .../vulkan/pass_bindings_cache_unittests.cc | 16 ++++++++-------- .../renderer/backend/vulkan/render_pass_vk.cc | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/impeller/renderer/backend/vulkan/pass_bindings_cache.cc b/impeller/renderer/backend/vulkan/pass_bindings_cache.cc index 925f1d38d15b1..00d8774443824 100644 --- a/impeller/renderer/backend/vulkan/pass_bindings_cache.cc +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache.cc @@ -5,7 +5,7 @@ #include "impeller/renderer/backend/vulkan/pass_bindings_cache.h" namespace impeller { -void PassBindingsCache::bindPipeline(vk::CommandBuffer command_buffer, +void PassBindingsCache::BindPipeline(vk::CommandBuffer command_buffer, vk::PipelineBindPoint pipeline_bind_point, vk::Pipeline pipeline) { switch (pipeline_bind_point) { @@ -29,7 +29,7 @@ void PassBindingsCache::bindPipeline(vk::CommandBuffer command_buffer, command_buffer.bindPipeline(pipeline_bind_point, pipeline); } -void PassBindingsCache::setStencilReference(vk::CommandBuffer command_buffer, +void PassBindingsCache::SetStencilReference(vk::CommandBuffer command_buffer, vk::StencilFaceFlags face_mask, uint32_t reference) { if (stencil_face_flags_.has_value() && @@ -42,7 +42,7 @@ void PassBindingsCache::setStencilReference(vk::CommandBuffer command_buffer, command_buffer.setStencilReference(face_mask, reference); } -void PassBindingsCache::setScissor(vk::CommandBuffer command_buffer, +void PassBindingsCache::SetScissor(vk::CommandBuffer command_buffer, uint32_t first_scissor, uint32_t scissor_count, const vk::Rect2D* scissors) { @@ -55,7 +55,7 @@ void PassBindingsCache::setScissor(vk::CommandBuffer command_buffer, command_buffer.setScissor(first_scissor, scissor_count, scissors); } -void PassBindingsCache::setViewport(vk::CommandBuffer command_buffer, +void PassBindingsCache::SetViewport(vk::CommandBuffer command_buffer, uint32_t first_viewport, uint32_t viewport_count, const vk::Viewport* viewports) { diff --git a/impeller/renderer/backend/vulkan/pass_bindings_cache.h b/impeller/renderer/backend/vulkan/pass_bindings_cache.h index 252bb276e49e6..2c7ed85445402 100644 --- a/impeller/renderer/backend/vulkan/pass_bindings_cache.h +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache.h @@ -12,20 +12,20 @@ namespace impeller { class PassBindingsCache { public: - void bindPipeline(vk::CommandBuffer command_buffer, + void BindPipeline(vk::CommandBuffer command_buffer, vk::PipelineBindPoint pipeline_bind_point, vk::Pipeline pipeline); - void setStencilReference(vk::CommandBuffer command_buffer, + void SetStencilReference(vk::CommandBuffer command_buffer, vk::StencilFaceFlags face_mask, uint32_t reference); - void setScissor(vk::CommandBuffer command_buffer, + void SetScissor(vk::CommandBuffer command_buffer, uint32_t first_scissor, uint32_t scissor_count, const vk::Rect2D* scissors); - void setViewport(vk::CommandBuffer command_buffer, + void SetViewport(vk::CommandBuffer command_buffer, uint32_t first_viewport, uint32_t viewport_count, const vk::Viewport* viewports); diff --git a/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc b/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc index 4fc0862ffce4a..feb788fe3afbe 100644 --- a/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc +++ b/impeller/renderer/backend/vulkan/pass_bindings_cache_unittests.cc @@ -33,8 +33,8 @@ TEST(PassBindingsCacheTest, bindPipeline) { auto buffer = encoder.GetCommandBuffer(); VkPipeline vk_pipeline = reinterpret_cast(0xfeedface); vk::Pipeline pipeline(vk_pipeline); - cache.bindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); - cache.bindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); + cache.BindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); + cache.BindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline); std::shared_ptr> functions = GetMockVulkanFunctions(context->GetDevice()); EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdBindPipeline"), 1); @@ -48,9 +48,9 @@ TEST(PassBindingsCacheTest, setStencilReference) { context->GetGraphicsQueue(), pool, context->GetFenceWaiter()); auto buffer = encoder.GetCommandBuffer(); - cache.setStencilReference( + cache.SetStencilReference( buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123); - cache.setStencilReference( + cache.SetStencilReference( buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123); std::shared_ptr> functions = GetMockVulkanFunctions(context->GetDevice()); @@ -67,8 +67,8 @@ TEST(PassBindingsCacheTest, setScissor) { context->GetFenceWaiter()); auto buffer = encoder.GetCommandBuffer(); vk::Rect2D scissors; - cache.setScissor(buffer, 0, 1, &scissors); - cache.setScissor(buffer, 0, 1, &scissors); + cache.SetScissor(buffer, 0, 1, &scissors); + cache.SetScissor(buffer, 0, 1, &scissors); std::shared_ptr> functions = GetMockVulkanFunctions(context->GetDevice()); EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetScissor"), 1); @@ -83,8 +83,8 @@ TEST(PassBindingsCacheTest, setViewport) { context->GetFenceWaiter()); auto buffer = encoder.GetCommandBuffer(); vk::Viewport viewports; - cache.setViewport(buffer, 0, 1, &viewports); - cache.setViewport(buffer, 0, 1, &viewports); + cache.SetViewport(buffer, 0, 1, &viewports); + cache.SetViewport(buffer, 0, 1, &viewports); std::shared_ptr> functions = GetMockVulkanFunctions(context->GetDevice()); EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetViewport"), 1); diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 4ffbbce52fe51..2a782757f8cc0 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -428,7 +428,7 @@ static void SetViewportAndScissor(const Command& command, .setY(vp.rect.size.height) .setMinDepth(0.0f) .setMaxDepth(1.0f); - cmd_buffer_cache.setViewport(cmd_buffer, 0, 1, &viewport); + cmd_buffer_cache.SetViewport(cmd_buffer, 0, 1, &viewport); // Set the scissor rect. const auto& sc = command.scissor.value_or(IRect::MakeSize(target_size)); @@ -436,7 +436,7 @@ static void SetViewportAndScissor(const Command& command, vk::Rect2D() .setOffset(vk::Offset2D(sc.origin.x, sc.origin.y)) .setExtent(vk::Extent2D(sc.size.width, sc.size.height)); - cmd_buffer_cache.setScissor(cmd_buffer, 0, 1, &scissor); + cmd_buffer_cache.SetScissor(cmd_buffer, 0, 1, &scissor); } static bool EncodeCommand(const Context& context, @@ -468,14 +468,14 @@ static bool EncodeCommand(const Context& context, return false; } - command_buffer_cache.bindPipeline( + command_buffer_cache.BindPipeline( cmd_buffer, vk::PipelineBindPoint::eGraphics, pipeline_vk.GetPipeline()); // Set the viewport and scissors. SetViewportAndScissor(command, cmd_buffer, command_buffer_cache, target_size); // Set the stencil reference. - command_buffer_cache.setStencilReference( + command_buffer_cache.SetStencilReference( cmd_buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, command.stencil_reference);