forked from firka/flutter
Make hot reload work (flutter/engine#37304)
This commit is contained in:
@@ -52,6 +52,13 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
|
||||
std::shared_ptr<const ShaderFunction> function = library->GetFunction(
|
||||
runtime_stage_->GetEntrypoint(), ShaderStage::kFragment);
|
||||
|
||||
if (function && runtime_stage_->IsDirty()) {
|
||||
library->UnregisterFunction(runtime_stage_->GetEntrypoint(),
|
||||
ShaderStage::kFragment);
|
||||
|
||||
function = nullptr;
|
||||
}
|
||||
|
||||
if (!function) {
|
||||
std::promise<bool> promise;
|
||||
auto future = promise.get_future();
|
||||
@@ -79,6 +86,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
|
||||
<< runtime_stage_->GetEntrypoint() << ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
runtime_stage_->SetClean();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -2142,12 +2142,21 @@ TEST_P(EntityTest, RuntimeEffect) {
|
||||
GTEST_SKIP_("This test only has a Metal fixture at the moment.");
|
||||
}
|
||||
|
||||
auto runtime_stage =
|
||||
OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
|
||||
ASSERT_TRUE(runtime_stage->IsDirty());
|
||||
|
||||
bool first_frame = true;
|
||||
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
|
||||
if (first_frame) {
|
||||
first_frame = false;
|
||||
} else {
|
||||
assert(runtime_stage->IsDirty() == false);
|
||||
}
|
||||
|
||||
auto contents = std::make_shared<RuntimeEffectContents>();
|
||||
contents->SetGeometry(Geometry::MakeCover());
|
||||
|
||||
auto runtime_stage =
|
||||
OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
|
||||
contents->SetRuntimeStage(runtime_stage);
|
||||
|
||||
struct FragUniforms {
|
||||
|
||||
@@ -144,4 +144,12 @@ RuntimeShaderStage RuntimeStage::GetShaderStage() const {
|
||||
return stage_;
|
||||
}
|
||||
|
||||
bool RuntimeStage::IsDirty() const {
|
||||
return is_dirty_;
|
||||
}
|
||||
|
||||
void RuntimeStage::SetClean() {
|
||||
is_dirty_ = false;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -36,6 +36,10 @@ class RuntimeStage {
|
||||
|
||||
const std::shared_ptr<fml::Mapping>& GetSkSLMapping() const;
|
||||
|
||||
bool IsDirty() const;
|
||||
|
||||
void SetClean();
|
||||
|
||||
private:
|
||||
RuntimeShaderStage stage_ = RuntimeShaderStage::kVertex;
|
||||
std::shared_ptr<fml::Mapping> payload_;
|
||||
@@ -44,6 +48,7 @@ class RuntimeStage {
|
||||
std::shared_ptr<fml::Mapping> sksl_mapping_;
|
||||
std::vector<RuntimeUniformDescription> uniforms_;
|
||||
bool is_valid_ = false;
|
||||
bool is_dirty_ = true;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(RuntimeStage);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user