Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1d680e4

Browse files
committed
added second test
1 parent 284189b commit 1d680e4

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
#include <thread>
66

7+
#include "flutter/fml/synchronization/count_down_latch.h"
78
#include "flutter/testing/testing.h"
89
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h"
10+
#include "impeller/renderer/backend/vulkan/fence_waiter_vk.h"
911
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
1012

1113
namespace impeller {
@@ -34,5 +36,41 @@ TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) {
3436
EXPECT_TRUE(free_buffers < destroy_pool);
3537
}
3638

39+
TEST(CommandEncoderVKTest, CleanupAfterSubmit) {
40+
// This tests deleting the TrackedObjects where the thread is killed before
41+
// the fence waiter has disposed of them.
42+
std::shared_ptr<std::vector<std::string>> called_functions;
43+
{
44+
fml::AutoResetWaitableEvent wait_for_submit;
45+
fml::AutoResetWaitableEvent wait_for_thread_join;
46+
auto context = CreateMockVulkanContext();
47+
std::thread thread([&] {
48+
CommandEncoderFactoryVK factory(context);
49+
std::shared_ptr<CommandEncoderVK> encoder = factory.Create();
50+
encoder->Submit([&](bool success) {
51+
ASSERT_TRUE(success);
52+
wait_for_thread_join.Wait();
53+
wait_for_submit.Signal();
54+
});
55+
});
56+
thread.join();
57+
wait_for_thread_join.Signal();
58+
auto [fence_result, fence] = context->GetDevice().createFenceUnique({});
59+
ASSERT_EQ(fence_result, vk::Result::eSuccess);
60+
context->GetFenceWaiter()->AddFence(std::move(fence), [] {});
61+
wait_for_submit.Wait();
62+
called_functions = GetMockVulkanFunctions(context->GetDevice());
63+
}
64+
auto destroy_pool =
65+
std::find(called_functions->begin(), called_functions->end(),
66+
"vkDestroyCommandPool");
67+
auto free_buffers =
68+
std::find(called_functions->begin(), called_functions->end(),
69+
"vkFreeCommandBuffers");
70+
EXPECT_TRUE(destroy_pool != called_functions->end());
71+
EXPECT_TRUE(free_buffers != called_functions->end());
72+
EXPECT_TRUE(free_buffers < destroy_pool);
73+
}
74+
3775
} // namespace testing
38-
} // namespace impeller
76+
} // namespace impeller

impeller/renderer/backend/vulkan/resource_manager_vk.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ class ResourceManagerVK
7171

7272
using Reclaimables = std::vector<std::unique_ptr<ResourceVK>>;
7373

74-
std::thread waiter_;
7574
std::mutex reclaimables_mutex_;
7675
std::condition_variable reclaimables_cv_;
7776
Reclaimables reclaimables_;
7877
bool should_exit_ = false;
78+
// This should be initialized last since it references the other instance
79+
// variables.
80+
std::thread waiter_;
7981

8082
void Main();
8183

impeller/renderer/backend/vulkan/test/mock_vulkan.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,37 @@ void vkDestroyCommandPool(VkDevice device,
361361
mock_device->called_functions_->push_back("vkDestroyCommandPool");
362362
}
363363

364+
VkResult vkEndCommandBuffer(VkCommandBuffer commandBuffer) {
365+
return VK_SUCCESS;
366+
}
367+
368+
VkResult vkCreateFence(VkDevice device,
369+
const VkFenceCreateInfo* pCreateInfo,
370+
const VkAllocationCallbacks* pAllocator,
371+
VkFence* pFence) {
372+
*pFence = reinterpret_cast<VkFence>(0xfe0ce);
373+
return VK_SUCCESS;
374+
}
375+
376+
VkResult vkQueueSubmit(VkQueue queue,
377+
uint32_t submitCount,
378+
const VkSubmitInfo* pSubmits,
379+
VkFence fence) {
380+
return VK_SUCCESS;
381+
}
382+
383+
VkResult vkWaitForFences(VkDevice device,
384+
uint32_t fenceCount,
385+
const VkFence* pFences,
386+
VkBool32 waitAll,
387+
uint64_t timeout) {
388+
return VK_SUCCESS;
389+
}
390+
391+
VkResult vkGetFenceStatus(VkDevice device, VkFence fence) {
392+
return VK_SUCCESS;
393+
}
394+
364395
PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
365396
const char* pName) {
366397
if (strcmp("vkEnumerateInstanceExtensionProperties", pName) == 0) {
@@ -443,6 +474,16 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
443474
return (PFN_vkVoidFunction)vkDestroyCommandPool;
444475
} else if (strcmp("vkFreeCommandBuffers", pName) == 0) {
445476
return (PFN_vkVoidFunction)vkFreeCommandBuffers;
477+
} else if (strcmp("vkEndCommandBuffer", pName) == 0) {
478+
return (PFN_vkVoidFunction)vkEndCommandBuffer;
479+
} else if (strcmp("vkCreateFence", pName) == 0) {
480+
return (PFN_vkVoidFunction)vkCreateFence;
481+
} else if (strcmp("vkQueueSubmit", pName) == 0) {
482+
return (PFN_vkVoidFunction)vkQueueSubmit;
483+
} else if (strcmp("vkWaitForFences", pName) == 0) {
484+
return (PFN_vkVoidFunction)vkWaitForFences;
485+
} else if (strcmp("vkGetFenceStatus", pName) == 0) {
486+
return (PFN_vkVoidFunction)vkGetFenceStatus;
446487
}
447488
return noop;
448489
}

0 commit comments

Comments
 (0)