[Impeller] Remove cached pipelines when RuntimeStage is hot reloaded (flutter/engine#37307)
This commit is contained in:
@@ -850,6 +850,8 @@ FILE: ../../../flutter/fml/command_line_unittest.cc
|
||||
FILE: ../../../flutter/fml/compiler_specific.h
|
||||
FILE: ../../../flutter/fml/concurrent_message_loop.cc
|
||||
FILE: ../../../flutter/fml/concurrent_message_loop.h
|
||||
FILE: ../../../flutter/fml/container.h
|
||||
FILE: ../../../flutter/fml/container_unittests.cc
|
||||
FILE: ../../../flutter/fml/dart/dart_converter.cc
|
||||
FILE: ../../../flutter/fml/dart/dart_converter.h
|
||||
FILE: ../../../flutter/fml/delayed_task.cc
|
||||
|
||||
@@ -18,6 +18,7 @@ source_set("fml") {
|
||||
"compiler_specific.h",
|
||||
"concurrent_message_loop.cc",
|
||||
"concurrent_message_loop.h",
|
||||
"container.h",
|
||||
"delayed_task.cc",
|
||||
"delayed_task.h",
|
||||
"eintr_wrapper.h",
|
||||
@@ -310,6 +311,7 @@ if (enable_unittests) {
|
||||
"backtrace_unittests.cc",
|
||||
"base32_unittest.cc",
|
||||
"command_line_unittest.cc",
|
||||
"container_unittests.cc",
|
||||
"endianness_unittests.cc",
|
||||
"file_unittest.cc",
|
||||
"hash_combine_unittests.cc",
|
||||
|
||||
30
engine/src/flutter/fml/container.h
Normal file
30
engine/src/flutter/fml/container.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
#ifndef FLUTTER_FML_CONTAINER_H_
|
||||
#define FLUTTER_FML_CONTAINER_H_
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
namespace fml {
|
||||
|
||||
template <
|
||||
class Collection =
|
||||
std::unordered_map<class Key, class Value, class Hash, class Equal>>
|
||||
void erase_if(Collection& container,
|
||||
std::function<bool(typename Collection::iterator)> predicate) {
|
||||
auto it = container.begin();
|
||||
while (it != container.end()) {
|
||||
if (predicate(it)) {
|
||||
it = container.erase(it);
|
||||
continue;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_CONTAINER_H_
|
||||
26
engine/src/flutter/fml/container_unittests.cc
Normal file
26
engine/src/flutter/fml/container_unittests.cc
Normal file
@@ -0,0 +1,26 @@
|
||||
// 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 <unordered_map>
|
||||
|
||||
#include "flutter/fml/container.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace fml {
|
||||
namespace {
|
||||
|
||||
TEST(ContainerTest, MapEraseIf) {
|
||||
std::unordered_map<int, int> map = {{0, 1}, {2, 3}, {4, 5}};
|
||||
|
||||
fml::erase_if(map, [](std::unordered_map<int, int>::iterator it) {
|
||||
return it->first == 0 || it->second == 5;
|
||||
});
|
||||
|
||||
EXPECT_EQ(map.size(), 1u);
|
||||
EXPECT_TRUE(map.find(2) != map.end());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace fml
|
||||
@@ -53,6 +53,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
|
||||
runtime_stage_->GetEntrypoint(), ShaderStage::kFragment);
|
||||
|
||||
if (function && runtime_stage_->IsDirty()) {
|
||||
context->GetPipelineLibrary()->RemovePipelinesWithEntryPoint(function);
|
||||
library->UnregisterFunction(runtime_stage_->GetEntrypoint(),
|
||||
ShaderStage::kFragment);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "flutter/fml/container.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "impeller/base/promise.h"
|
||||
#include "impeller/renderer/backend/gles/pipeline_gles.h"
|
||||
@@ -257,6 +258,15 @@ PipelineFuture<ComputePipelineDescriptor> PipelineLibraryGLES::GetPipeline(
|
||||
return future;
|
||||
}
|
||||
|
||||
// |PipelineLibrary|
|
||||
void PipelineLibraryGLES::RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) {
|
||||
fml::erase_if(pipelines_, [&](auto item) {
|
||||
return item->first.GetEntrypointForStage(function->GetStage())
|
||||
->IsEqual(*function);
|
||||
});
|
||||
}
|
||||
|
||||
// |PipelineLibrary|
|
||||
PipelineLibraryGLES::~PipelineLibraryGLES() = default;
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ class PipelineLibraryGLES final : public PipelineLibrary {
|
||||
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
|
||||
ComputePipelineDescriptor descriptor) override;
|
||||
|
||||
// |PipelineLibrary|
|
||||
void RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PipelineLibraryGLES);
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ class PipelineLibraryMTL final : public PipelineLibrary {
|
||||
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
|
||||
ComputePipelineDescriptor descriptor) override;
|
||||
|
||||
// |PipelineLibrary|
|
||||
void RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PipelineLibraryMTL);
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "impeller/renderer/backend/metal/pipeline_library_mtl.h"
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
#include "flutter/fml/container.h"
|
||||
#include "impeller/base/promise.h"
|
||||
#include "impeller/renderer/backend/metal/compute_pipeline_mtl.h"
|
||||
#include "impeller/renderer/backend/metal/formats_mtl.h"
|
||||
@@ -187,4 +188,13 @@ PipelineFuture<ComputePipelineDescriptor> PipelineLibraryMTL::GetPipeline(
|
||||
return future;
|
||||
}
|
||||
|
||||
// |PipelineLibrary|
|
||||
void PipelineLibraryMTL::RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) {
|
||||
fml::erase_if(pipelines_, [&](auto item) {
|
||||
return item->first.GetEntrypointForStage(function->GetStage())
|
||||
->IsEqual(*function);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "flutter/fml/container.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "impeller/base/promise.h"
|
||||
#include "impeller/base/validation.h"
|
||||
@@ -131,6 +132,17 @@ static vk::AttachmentDescription CreatePlaceholderAttachmentDescription(
|
||||
return desc;
|
||||
}
|
||||
|
||||
// |PipelineLibrary|
|
||||
void PipelineLibraryVK::RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) {
|
||||
Lock lock(pipelines_mutex_);
|
||||
|
||||
fml::erase_if(pipelines_, [&](auto item) {
|
||||
return item->first.GetEntrypointForStage(function->GetStage())
|
||||
->IsEqual(*function);
|
||||
});
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Render Pass
|
||||
/// We are NOT going to use the same render pass with the framebuffer (later)
|
||||
|
||||
@@ -58,6 +58,10 @@ class PipelineLibraryVK final
|
||||
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
|
||||
ComputePipelineDescriptor descriptor) override;
|
||||
|
||||
// |PipelineLibrary|
|
||||
void RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) override;
|
||||
|
||||
std::unique_ptr<PipelineCreateInfoVK> CreatePipeline(
|
||||
const PipelineDescriptor& desc);
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ class PipelineLibrary : public std::enable_shared_from_this<PipelineLibrary> {
|
||||
virtual PipelineFuture<ComputePipelineDescriptor> GetPipeline(
|
||||
ComputePipelineDescriptor descriptor) = 0;
|
||||
|
||||
virtual void RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) = 0;
|
||||
|
||||
protected:
|
||||
PipelineLibrary();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user