Skip to content

Commit d0bb78c

Browse files
author
Jonah Williams
authored
[Impeller] keep imgui hostbuffer alive. (flutter/engine#56409)
Fixes flutter#158275 We are now counting on the content context to keep the host buffer alive. the imgui overlay does not use a content context, so it has to manage the lifetime of the host buffer correctly, keeping it alive for as many frames as needed and destroying it in the correct order (before context destruction).
1 parent fef9795 commit d0bb78c

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

engine/src/flutter/impeller/playground/imgui/imgui_impl_impeller.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ void ImGui_ImplImpeller_Shutdown() {
138138
}
139139

140140
void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data,
141-
impeller::RenderPass& render_pass) {
141+
impeller::RenderPass& render_pass,
142+
impeller::HostBuffer& host_buffer) {
142143
if (draw_data->CmdListsCount == 0) {
143144
return; // Nothing to render.
144145
}
145-
auto host_buffer = impeller::HostBuffer::Create(
146-
render_pass.GetContext()->GetResourceAllocator(),
147-
render_pass.GetContext()->GetIdleWaiter());
148146

149147
using VS = impeller::ImguiRasterVertexShader;
150148
using FS = impeller::ImguiRasterFragmentShader;
@@ -178,7 +176,7 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data,
178176
VS::UniformBuffer uniforms;
179177
uniforms.mvp = impeller::Matrix::MakeOrthographic(display_rect.GetSize())
180178
.Translate(-display_rect.GetOrigin());
181-
auto vtx_uniforms = host_buffer->EmplaceUniform(uniforms);
179+
auto vtx_uniforms = host_buffer.EmplaceUniform(uniforms);
182180

183181
size_t vertex_buffer_offset = 0;
184182
size_t index_buffer_offset = total_vtx_bytes;
@@ -284,5 +282,5 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data,
284282
vertex_buffer_offset += draw_list_vtx_bytes;
285283
index_buffer_offset += draw_list_idx_bytes;
286284
}
287-
host_buffer->Reset();
285+
host_buffer.Reset();
288286
}

engine/src/flutter/impeller/playground/imgui/imgui_impl_impeller.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <memory>
99

10+
#include "impeller/core/host_buffer.h"
1011
#include "third_party/imgui/imgui.h"
1112

1213
namespace impeller {
@@ -23,6 +24,7 @@ IMGUI_IMPL_API void ImGui_ImplImpeller_Shutdown();
2324

2425
IMGUI_IMPL_API void ImGui_ImplImpeller_RenderDrawData(
2526
ImDrawData* draw_data,
26-
impeller::RenderPass& renderpass);
27+
impeller::RenderPass& renderpass,
28+
impeller::HostBuffer& host_buffer);
2729

2830
#endif // FLUTTER_IMPELLER_PLAYGROUND_IMGUI_IMGUI_IMPL_IMPELLER_H_

engine/src/flutter/impeller/playground/playground.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "fml/closure.h"
1111
#include "fml/time/time_point.h"
12+
#include "impeller/core/host_buffer.h"
1213
#include "impeller/playground/image/backends/skia/compressed_image_skia.h"
1314
#include "impeller/playground/image/decompressed_image.h"
1415
#include "impeller/renderer/command_buffer.h"
@@ -148,6 +149,9 @@ bool Playground::IsPlaygroundEnabled() const {
148149
}
149150

150151
void Playground::TeardownWindow() {
152+
if (host_buffer_) {
153+
host_buffer_.reset();
154+
}
151155
if (context_) {
152156
context_->Shutdown();
153157
}
@@ -303,8 +307,13 @@ bool Playground::OpenPlaygroundHere(
303307
return false;
304308
}
305309
pass->SetLabel("ImGui Render Pass");
310+
if (!host_buffer_) {
311+
host_buffer_ = HostBuffer::Create(context_->GetResourceAllocator(),
312+
context_->GetIdleWaiter());
313+
}
306314

307-
ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass);
315+
ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass,
316+
*host_buffer_);
308317

309318
pass->EncodeCommands();
310319

engine/src/flutter/impeller/playground/playground.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "flutter/fml/status.h"
1212
#include "flutter/fml/time/time_delta.h"
13+
#include "impeller/core/host_buffer.h"
1314
#include "impeller/core/runtime_types.h"
1415
#include "impeller/core/texture.h"
1516
#include "impeller/geometry/point.h"
@@ -130,6 +131,7 @@ class Playground {
130131
std::shared_ptr<Context> context_;
131132
Point cursor_position_;
132133
ISize window_size_ = ISize{1024, 768};
134+
std::shared_ptr<HostBuffer> host_buffer_;
133135

134136
void SetCursorPosition(Point pos);
135137

engine/src/flutter/testing/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def make_test(name, flags=None, extra_env=None):
553553
'--enable_vulkan_validation',
554554
'--enable_playground',
555555
'--playground_timeout_ms=4000',
556-
'--gtest_filter="*ColorWheel/Vulkan"',
556+
'--gtest_filter="*ColorWheel*"',
557557
],
558558
coverage=coverage,
559559
extra_env=extra_env,

0 commit comments

Comments
 (0)