5 #include "flutter/fml/synchronization/waitable_event.h"
6 #include "flutter/testing/testing.h"
9 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
14 TEST(ContextVKTest, DeletesCommandPools) {
15 std::weak_ptr<ContextVK> weak_context;
16 std::weak_ptr<CommandPoolVK> weak_pool;
18 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
19 auto const pool = context->GetCommandPoolRecycler()->Get();
21 weak_context = context;
22 ASSERT_TRUE(weak_pool.lock());
23 ASSERT_TRUE(weak_context.lock());
25 ASSERT_FALSE(weak_pool.lock());
26 ASSERT_FALSE(weak_context.lock());
29 TEST(ContextVKTest, DeletesCommandPoolsOnAllThreads) {
30 std::weak_ptr<ContextVK> weak_context;
31 std::weak_ptr<CommandPoolVK> weak_pool_main;
33 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
34 weak_pool_main = context->GetCommandPoolRecycler()->Get();
35 weak_context = context;
36 ASSERT_TRUE(weak_pool_main.lock());
37 ASSERT_TRUE(weak_context.lock());
40 fml::AutoResetWaitableEvent latch1, latch2;
41 std::weak_ptr<CommandPoolVK> weak_pool_thread;
42 std::thread thread([&]() {
43 weak_pool_thread = context->GetCommandPoolRecycler()->Get();
51 ASSERT_FALSE(weak_pool_main.lock());
52 ASSERT_FALSE(weak_context.lock());
57 ASSERT_FALSE(weak_pool_thread.lock());
60 TEST(ContextVKTest, DeletePipelineAfterContext) {
61 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
62 std::shared_ptr<std::vector<std::string>> functions;
64 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
68 context->GetPipelineLibrary()->GetPipeline(pipeline_desc);
69 pipeline = pipeline_future.
Get();
70 ASSERT_TRUE(pipeline);
71 functions = GetMockVulkanFunctions(context->GetDevice());
72 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
73 "vkCreateGraphicsPipelines") != functions->end());
75 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
76 "vkDestroyDevice") != functions->end());
79 TEST(ContextVKTest, DeleteShaderFunctionAfterContext) {
80 std::shared_ptr<const ShaderFunction> shader_function;
81 std::shared_ptr<std::vector<std::string>> functions;
83 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
86 std::vector<uint8_t> data = {0x03, 0x02, 0x23, 0x07};
87 context->GetShaderLibrary()->RegisterFunction(
89 std::make_shared<fml::DataMapping>(data), [](
bool) {});
90 shader_function = context->GetShaderLibrary()->GetFunction(
92 ASSERT_TRUE(shader_function);
93 functions = GetMockVulkanFunctions(context->GetDevice());
94 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
95 "vkCreateShaderModule") != functions->end());
97 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
98 "vkDestroyDevice") != functions->end());
101 TEST(ContextVKTest, DeletePipelineLibraryAfterContext) {
102 std::shared_ptr<PipelineLibrary> pipeline_library;
103 std::shared_ptr<std::vector<std::string>> functions;
105 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
108 pipeline_library = context->GetPipelineLibrary();
109 functions = GetMockVulkanFunctions(context->GetDevice());
110 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
111 "vkCreatePipelineCache") != functions->end());
113 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
114 "vkDestroyDevice") != functions->end());
117 TEST(ContextVKTest, CanCreateContextInAbsenceOfValidationLayers) {
120 auto context = MockVulkanContextBuilder()
121 .SetSettingsCallback([](
auto& settings) {
122 settings.enable_validation =
true;
125 ASSERT_NE(context,
nullptr);
127 reinterpret_cast<const CapabilitiesVK*
>(context->GetCapabilities().get());
131 TEST(ContextVKTest, CanCreateContextWithValidationLayers) {
133 MockVulkanContextBuilder()
134 .SetSettingsCallback(
135 [](
auto& settings) { settings.enable_validation =
true; })
136 .SetInstanceExtensions(
137 {
"VK_KHR_surface",
"VK_MVK_macos_surface",
"VK_EXT_debug_utils"})
138 .SetInstanceLayers({
"VK_LAYER_KHRONOS_validation"})
140 ASSERT_NE(context,
nullptr);
142 reinterpret_cast<const CapabilitiesVK*
>(context->GetCapabilities().get());