Flutter Impeller
pass_bindings_cache_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/testing/testing.h"
8 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
9 
10 namespace impeller {
11 namespace testing {
12 
13 namespace {
14 int32_t CountStringViewInstances(const std::vector<std::string>& strings,
15  std::string_view target) {
16  int32_t count = 0;
17  for (const std::string& str : strings) {
18  if (str == target) {
19  count++;
20  }
21  }
22  return count;
23 }
24 } // namespace
25 
26 TEST(PassBindingsCacheTest, bindPipeline) {
27  auto context = MockVulkanContextBuilder().Build();
28  PassBindingsCache cache;
29  auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
30  auto buffer = encoder->GetCommandBuffer();
31  VkPipeline vk_pipeline = reinterpret_cast<VkPipeline>(0xfeedface);
32  vk::Pipeline pipeline(vk_pipeline);
33  cache.BindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline);
34  cache.BindPipeline(buffer, vk::PipelineBindPoint::eGraphics, pipeline);
35  std::shared_ptr<std::vector<std::string>> functions =
36  GetMockVulkanFunctions(context->GetDevice());
37  EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdBindPipeline"), 1);
38 }
39 
40 TEST(PassBindingsCacheTest, setStencilReference) {
41  auto context = MockVulkanContextBuilder().Build();
42  PassBindingsCache cache;
43  auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
44  auto buffer = encoder->GetCommandBuffer();
45  cache.SetStencilReference(
46  buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123);
47  cache.SetStencilReference(
48  buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123);
49  std::shared_ptr<std::vector<std::string>> functions =
50  GetMockVulkanFunctions(context->GetDevice());
51  EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetStencilReference"),
52  1);
53 }
54 
55 TEST(PassBindingsCacheTest, setScissor) {
56  auto context = MockVulkanContextBuilder().Build();
57  PassBindingsCache cache;
58  auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
59  auto buffer = encoder->GetCommandBuffer();
60  vk::Rect2D scissors;
61  cache.SetScissor(buffer, 0, 1, &scissors);
62  cache.SetScissor(buffer, 0, 1, &scissors);
63  std::shared_ptr<std::vector<std::string>> functions =
64  GetMockVulkanFunctions(context->GetDevice());
65  EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetScissor"), 1);
66 }
67 
68 TEST(PassBindingsCacheTest, setViewport) {
69  auto context = MockVulkanContextBuilder().Build();
70  PassBindingsCache cache;
71  auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
72  auto buffer = encoder->GetCommandBuffer();
73  vk::Viewport viewports;
74  cache.SetViewport(buffer, 0, 1, &viewports);
75  cache.SetViewport(buffer, 0, 1, &viewports);
76  std::shared_ptr<std::vector<std::string>> functions =
77  GetMockVulkanFunctions(context->GetDevice());
78  EXPECT_EQ(CountStringViewInstances(*functions, "vkCmdSetViewport"), 1);
79 }
80 
81 } // namespace testing
82 } // namespace impeller
impeller::PassBindingsCache::SetStencilReference
void SetStencilReference(vk::CommandBuffer command_buffer, vk::StencilFaceFlags face_mask, uint32_t reference)
Definition: pass_bindings_cache.cc:32
command_encoder_vk.h
impeller::testing::TEST
TEST(AiksCanvasTest, EmptyCullRect)
Definition: canvas_unittests.cc:17
impeller::PassBindingsCache::SetScissor
void SetScissor(const IRect &scissor)
Definition: render_pass_mtl.mm:323
pass_bindings_cache.h
impeller::PassBindingsCache
Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do add...
Definition: render_pass_mtl.mm:194
impeller::PassBindingsCache::SetViewport
void SetViewport(const Viewport &viewport)
Definition: render_pass_mtl.mm:308
impeller
Definition: aiks_context.cc:10
impeller::PassBindingsCache::BindPipeline
void BindPipeline(vk::CommandBuffer command_buffer, vk::PipelineBindPoint pipeline_bind_point, vk::Pipeline pipeline)
Definition: pass_bindings_cache.cc:8