5 #include "flutter/testing/testing.h"
8 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
14 int32_t CountStringViewInstances(
const std::vector<std::string>& strings,
15 std::string_view target) {
17 for (
const std::string& str : strings) {
26 TEST(PassBindingsCacheTest, bindPipeline) {
27 auto context = MockVulkanContextBuilder().Build();
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);
40 TEST(PassBindingsCacheTest, setStencilReference) {
41 auto context = MockVulkanContextBuilder().Build();
43 auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
44 auto buffer = encoder->GetCommandBuffer();
46 buffer, vk::StencilFaceFlagBits::eVkStencilFrontAndBack, 123);
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"),
55 TEST(PassBindingsCacheTest, setScissor) {
56 auto context = MockVulkanContextBuilder().Build();
58 auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
59 auto buffer = encoder->GetCommandBuffer();
63 std::shared_ptr<std::vector<std::string>> functions =
64 GetMockVulkanFunctions(context->GetDevice());
65 EXPECT_EQ(CountStringViewInstances(*functions,
"vkCmdSetScissor"), 1);
68 TEST(PassBindingsCacheTest, setViewport) {
69 auto context = MockVulkanContextBuilder().Build();
71 auto encoder = std::make_unique<CommandEncoderFactoryVK>(context)->Create();
72 auto buffer = encoder->GetCommandBuffer();
73 vk::Viewport viewports;
76 std::shared_ptr<std::vector<std::string>> functions =
77 GetMockVulkanFunctions(context->GetDevice());
78 EXPECT_EQ(CountStringViewInstances(*functions,
"vkCmdSetViewport"), 1);