This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
impeller/renderer/backend/vulkan/swapchain/ahb Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ bool AHBSwapchainImplVK::Present(
123123 if (!thiz) {
124124 return ;
125125 }
126- thiz->pool_ -> Push (texture);
126+ thiz->OnTextureSetOnSurfaceControl (texture);
127127 });
128128}
129129
@@ -145,4 +145,15 @@ std::shared_ptr<ExternalFenceVK> AHBSwapchainImplVK::SubmitCompletionSignal()
145145 return fence;
146146}
147147
148+ void AHBSwapchainImplVK::OnTextureSetOnSurfaceControl (
149+ std::shared_ptr<AHBTextureSourceVK> texture) {
150+ // The transaction completion indicates that the surface control now
151+ // references the hardware buffer. We can recycle the previous set buffer
152+ // safely.
153+ Lock lock (currently_displayed_texture_mutex_);
154+ auto old_texture = currently_displayed_texture_;
155+ currently_displayed_texture_ = std::move (texture);
156+ pool_->Push (std::move (old_texture));
157+ }
158+
148159} // namespace impeller
Original file line number Diff line number Diff line change 77
88#include < memory>
99
10+ #include " impeller/base/thread.h"
1011#include " impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.h"
1112#include " impeller/renderer/backend/vulkan/swapchain/ahb/ahb_texture_pool_vk.h"
1213#include " impeller/renderer/backend/vulkan/swapchain/ahb/external_fence_vk.h"
@@ -90,6 +91,11 @@ class AHBSwapchainImplVK final
9091 android::HardwareBufferDescriptor desc_;
9192 std::shared_ptr<AHBTexturePoolVK> pool_;
9293 std::shared_ptr<SwapchainTransientsVK> transients_;
94+ // In C++20, this mutex can be replaced by the shared pointer specialization
95+ // of std::atomic.
96+ Mutex currently_displayed_texture_mutex_;
97+ std::shared_ptr<AHBTextureSourceVK> currently_displayed_texture_
98+ IPLR_GUARDED_BY (currently_displayed_texture_mutex_);
9399 bool is_valid_ = false ;
94100
95101 explicit AHBSwapchainImplVK (
@@ -101,6 +107,9 @@ class AHBSwapchainImplVK final
101107 bool Present (const std::shared_ptr<AHBTextureSourceVK>& texture);
102108
103109 std::shared_ptr<ExternalFenceVK> SubmitCompletionSignal () const ;
110+
111+ void OnTextureSetOnSurfaceControl (
112+ std::shared_ptr<AHBTextureSourceVK> texture);
104113};
105114
106115} // namespace impeller
Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ std::shared_ptr<AHBTextureSourceVK> AHBTexturePoolVK::Pop() {
3838}
3939
4040void AHBTexturePoolVK::Push (std::shared_ptr<AHBTextureSourceVK> texture) {
41+ if (!texture) {
42+ return ;
43+ }
4144 Lock lock (pool_mutex_);
4245 pool_.push_back (PoolEntry{std::move (texture)});
4346 PerformGCLocked ();
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ namespace impeller {
2525// / new entry is created. The only case where a valid texture source
2626// / cannot be obtained is due to resource exhaustion.
2727// /
28+ // / Pools are thread-safe.
29+ // /
2830class AHBTexturePoolVK {
2931 public:
3032 // ----------------------------------------------------------------------------
@@ -65,6 +67,8 @@ class AHBTexturePoolVK {
6567 // / @brief Pops an texture source from the pool. If the pool is empty, a
6668 // / new texture source is created and returned.
6769 // /
70+ // / This operation is thread-safe.
71+ // /
6872 // / @return A texture source that can be used as a swapchain image. This
6973 // / can be nullptr in case of resource exhaustion.
7074 // /
@@ -74,6 +78,8 @@ class AHBTexturePoolVK {
7478 // / @brief Push a popped texture back into the pool. This also performs a
7579 // / GC.
7680 // /
81+ // / This operation is thread-safe.
82+ // /
7783 // / @warning Only a texture source obtained from the same pool can be
7884 // / returned to it. It is user error to mix and match texture
7985 // / sources from different pools.
You can’t perform that action at this time.
0 commit comments