-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Started tracking the pool with the command buffer. #45298
Changes from all commits
4f4240d
0f47509
1199826
c709f39
30b3b3d
2313fd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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 <thread> | ||
|
||
#include "flutter/fml/synchronization/count_down_latch.h" | ||
#include "flutter/testing/testing.h" | ||
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h" | ||
#include "impeller/renderer/backend/vulkan/fence_waiter_vk.h" | ||
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h" | ||
|
||
namespace impeller { | ||
namespace testing { | ||
|
||
TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have sort of mixed feelings about these tests, because its sort disjointed from how these classes are used. I would feel better if there was substantially more commentary on specifically what these tests are covering. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or at least for one of them, and then subsequent tests could have less commentary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unit tests are supposed to be testing how a class can be used, not how they are supposed to be used. Maybe it will help to understand why I implemented this fix. The pool change is a fix for a real bug that I was running into when using the playgrounds test harness which Chinmay was trying to get working. So, it may be true that this bug shouldn't present itself in production, it has demonstrably happened in our test harness and may present itself accidentally in production. The second fix with the resourcemanager is definitely something that can manifest in production code, but was showing up regularly in these tests. We typically don't annotate unit tests that are using the public api of a method. I'm happy to add any comments you think will help. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that, what I'm saying is that I'm having a hard time following the test and so I'd appreciate more commentary on how/why the particular test successfully exercises the assertions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment to the first test, expanded the second comment and removed one piece of vestigial code. |
||
// Tests that when a CommandEncoderVK is deleted that it will clean up its | ||
// command buffers before it cleans up its command pool. | ||
std::shared_ptr<std::vector<std::string>> called_functions; | ||
{ | ||
auto context = CreateMockVulkanContext(); | ||
called_functions = GetMockVulkanFunctions(context->GetDevice()); | ||
std::shared_ptr<CommandEncoderVK> encoder; | ||
std::thread thread([&] { | ||
CommandEncoderFactoryVK factory(context); | ||
encoder = factory.Create(); | ||
}); | ||
thread.join(); | ||
} | ||
auto destroy_pool = | ||
std::find(called_functions->begin(), called_functions->end(), | ||
"vkDestroyCommandPool"); | ||
auto free_buffers = | ||
std::find(called_functions->begin(), called_functions->end(), | ||
"vkFreeCommandBuffers"); | ||
EXPECT_TRUE(destroy_pool != called_functions->end()); | ||
EXPECT_TRUE(free_buffers != called_functions->end()); | ||
EXPECT_TRUE(free_buffers < destroy_pool); | ||
} | ||
|
||
TEST(CommandEncoderVKTest, CleanupAfterSubmit) { | ||
// This tests deleting the TrackedObjects where the thread is killed before | ||
// the fence waiter has disposed of them, making sure the command buffer and | ||
// its pools are deleted in that order. | ||
std::shared_ptr<std::vector<std::string>> called_functions; | ||
{ | ||
fml::AutoResetWaitableEvent wait_for_submit; | ||
fml::AutoResetWaitableEvent wait_for_thread_join; | ||
auto context = CreateMockVulkanContext(); | ||
std::thread thread([&] { | ||
CommandEncoderFactoryVK factory(context); | ||
std::shared_ptr<CommandEncoderVK> encoder = factory.Create(); | ||
encoder->Submit([&](bool success) { | ||
ASSERT_TRUE(success); | ||
wait_for_thread_join.Wait(); | ||
wait_for_submit.Signal(); | ||
}); | ||
}); | ||
thread.join(); | ||
wait_for_thread_join.Signal(); | ||
wait_for_submit.Wait(); | ||
called_functions = GetMockVulkanFunctions(context->GetDevice()); | ||
} | ||
auto destroy_pool = | ||
std::find(called_functions->begin(), called_functions->end(), | ||
"vkDestroyCommandPool"); | ||
auto free_buffers = | ||
std::find(called_functions->begin(), called_functions->end(), | ||
"vkFreeCommandBuffers"); | ||
EXPECT_TRUE(destroy_pool != called_functions->end()); | ||
EXPECT_TRUE(free_buffers != called_functions->end()); | ||
EXPECT_TRUE(free_buffers < destroy_pool); | ||
} | ||
|
||
} // namespace testing | ||
} // namespace impeller |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,12 +75,13 @@ class ResourceManagerVK final | |
using Reclaimables = std::vector<std::unique_ptr<ResourceVK>>; | ||
|
||
ResourceManagerVK(); | ||
|
||
std::thread waiter_; | ||
std::mutex reclaimables_mutex_; | ||
std::condition_variable reclaimables_cv_; | ||
Reclaimables reclaimables_; | ||
bool should_exit_ = false; | ||
// This should be initialized last since it references the other instance | ||
// variables. | ||
std::thread waiter_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a nasty race condition I was running into. |
||
|
||
//---------------------------------------------------------------------------- | ||
/// @brief Starts the resource manager thread. | ||
|
Uh oh!
There was an error while loading. Please reload this page.