Faster vulkan buffer tracking (flutter/engine#56099)
issue: https://github.com/flutter/flutter/issues/157538 This removes multiple instances of copying std::shared_ptr and hashing. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
@@ -132,14 +132,6 @@ bool CommandBufferVK::Track(const std::shared_ptr<const DeviceBuffer>& buffer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferVK::IsTracking(
|
||||
const std::shared_ptr<const DeviceBuffer>& buffer) const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
return tracked_objects_->IsTracking(buffer);
|
||||
}
|
||||
|
||||
bool CommandBufferVK::Track(std::shared_ptr<const TextureSourceVK> texture) {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
@@ -158,16 +150,6 @@ bool CommandBufferVK::Track(const std::shared_ptr<const Texture>& texture) {
|
||||
return Track(TextureVK::Cast(*texture).GetTextureSource());
|
||||
}
|
||||
|
||||
bool CommandBufferVK::IsTracking(
|
||||
const std::shared_ptr<const Texture>& texture) const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<const TextureSourceVK> source =
|
||||
TextureVK::Cast(*texture).GetTextureSource();
|
||||
return tracked_objects_->IsTracking(source);
|
||||
}
|
||||
|
||||
fml::StatusOr<vk::DescriptorSet> CommandBufferVK::AllocateDescriptorSets(
|
||||
const vk::DescriptorSetLayout& layout,
|
||||
const ContextVK& context) {
|
||||
|
||||
@@ -76,12 +76,6 @@ class CommandBufferVK final
|
||||
const vk::DescriptorSetLayout& layout,
|
||||
const ContextVK& context);
|
||||
|
||||
// Visible for testing.
|
||||
bool IsTracking(const std::shared_ptr<const DeviceBuffer>& texture) const;
|
||||
|
||||
// Visible for testing.
|
||||
bool IsTracking(const std::shared_ptr<const Texture>& texture) const;
|
||||
|
||||
// Visible for testing.
|
||||
DescriptorPoolVK& GetDescriptorPool() const;
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@ TrackedObjectsVK::TrackedObjectsVK(
|
||||
pool_ = pool;
|
||||
buffer_ = std::move(buffer);
|
||||
is_valid_ = true;
|
||||
// Starting values were selected by looking at values from
|
||||
// AiksTest.CanRenderMultipleBackdropBlurWithSingleBackdropId.
|
||||
tracked_objects_.reserve(5);
|
||||
tracked_buffers_.reserve(5);
|
||||
tracked_textures_.reserve(5);
|
||||
}
|
||||
|
||||
TrackedObjectsVK::~TrackedObjectsVK() {
|
||||
@@ -39,40 +44,27 @@ bool TrackedObjectsVK::IsValid() const {
|
||||
}
|
||||
|
||||
void TrackedObjectsVK::Track(std::shared_ptr<SharedObjectVK> object) {
|
||||
if (!object) {
|
||||
if (!object || (!tracked_objects_.empty() &&
|
||||
object.get() == tracked_objects_.back().get())) {
|
||||
return;
|
||||
}
|
||||
tracked_objects_.insert(std::move(object));
|
||||
tracked_objects_.emplace_back(std::move(object));
|
||||
}
|
||||
|
||||
void TrackedObjectsVK::Track(std::shared_ptr<const DeviceBuffer> buffer) {
|
||||
if (!buffer) {
|
||||
if (!buffer || (!tracked_buffers_.empty() &&
|
||||
buffer.get() == tracked_buffers_.back().get())) {
|
||||
return;
|
||||
}
|
||||
tracked_buffers_.insert(std::move(buffer));
|
||||
}
|
||||
|
||||
bool TrackedObjectsVK::IsTracking(
|
||||
const std::shared_ptr<const DeviceBuffer>& buffer) const {
|
||||
if (!buffer) {
|
||||
return false;
|
||||
}
|
||||
return tracked_buffers_.find(buffer) != tracked_buffers_.end();
|
||||
tracked_buffers_.emplace_back(std::move(buffer));
|
||||
}
|
||||
|
||||
void TrackedObjectsVK::Track(std::shared_ptr<const TextureSourceVK> texture) {
|
||||
if (!texture) {
|
||||
if (!texture || (!tracked_textures_.empty() &&
|
||||
texture.get() == tracked_textures_.back().get())) {
|
||||
return;
|
||||
}
|
||||
tracked_textures_.insert(std::move(texture));
|
||||
}
|
||||
|
||||
bool TrackedObjectsVK::IsTracking(
|
||||
const std::shared_ptr<const TextureSourceVK>& texture) const {
|
||||
if (!texture) {
|
||||
return false;
|
||||
}
|
||||
return tracked_textures_.find(texture) != tracked_textures_.end();
|
||||
tracked_textures_.emplace_back(std::move(texture));
|
||||
}
|
||||
|
||||
vk::CommandBuffer TrackedObjectsVK::GetCommandBuffer() const {
|
||||
|
||||
@@ -31,12 +31,8 @@ class TrackedObjectsVK {
|
||||
|
||||
void Track(std::shared_ptr<const DeviceBuffer> buffer);
|
||||
|
||||
bool IsTracking(const std::shared_ptr<const DeviceBuffer>& buffer) const;
|
||||
|
||||
void Track(std::shared_ptr<const TextureSourceVK> texture);
|
||||
|
||||
bool IsTracking(const std::shared_ptr<const TextureSourceVK>& texture) const;
|
||||
|
||||
vk::CommandBuffer GetCommandBuffer() const;
|
||||
|
||||
DescriptorPoolVK& GetDescriptorPool();
|
||||
@@ -48,9 +44,9 @@ class TrackedObjectsVK {
|
||||
// `shared_ptr` since command buffers have a link to the command pool.
|
||||
std::shared_ptr<CommandPoolVK> pool_;
|
||||
vk::UniqueCommandBuffer buffer_;
|
||||
std::set<std::shared_ptr<SharedObjectVK>> tracked_objects_;
|
||||
std::set<std::shared_ptr<const DeviceBuffer>> tracked_buffers_;
|
||||
std::set<std::shared_ptr<const TextureSourceVK>> tracked_textures_;
|
||||
std::vector<std::shared_ptr<SharedObjectVK>> tracked_objects_;
|
||||
std::vector<std::shared_ptr<const DeviceBuffer>> tracked_buffers_;
|
||||
std::vector<std::shared_ptr<const TextureSourceVK>> tracked_textures_;
|
||||
std::unique_ptr<GPUProbe> probe_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user