From 18afdaa16870e6e8a5ea582609b34f2741a73dee Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 27 Jan 2025 12:14:02 -0800 Subject: [PATCH] gfxstream: Move snapshot decoder replay into VkDecoderGlobalState ... to break the recursive behavior of the replay calling into VkDecoderSnapshot so that locking and thread safety annotations can be preserved in VkDecoderSnapshot. Follow up to aosp/3412302. Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader Test: cvd snapshot_take --snapshot_path=<> Test: cvd create --snapshot_path=<> Reviewed-by: Aaron Ruby Part-of: --- .../codegen/scripts/cereal/decodersnapshot.py | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py b/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py index 3c5c62d1028..ef2273b2874 100644 --- a/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py +++ b/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py @@ -27,20 +27,21 @@ namespace gfxstream { namespace vk { class VkDecoderSnapshot { -public: + public: VkDecoderSnapshot(); ~VkDecoderSnapshot(); - void save(android::base::Stream* stream); - void load(android::base::Stream* stream, emugl::GfxApiLogger& gfx_logger, - emugl::HealthMonitor<>* healthMonitor); + void clear(); + + void saveDecoderReplayBuffer(android::base::Stream* stream); + static void loadDecoderReplayBuffer(android::base::Stream* stream, std::vector* outBuffer); VkSnapshotApiCallInfo* createApiCallInfo(); void destroyApiCallInfoIfUnused(VkSnapshotApiCallInfo* info); """ decoder_snapshot_decl_postamble = """ -private: + private: class Impl; std::unique_ptr mImpl; @@ -59,16 +60,21 @@ namespace gfxstream { namespace vk { class VkDecoderSnapshot::Impl { -public: + public: Impl() { } - void save(android::base::Stream* stream) { + void clear() { std::lock_guard lock(mReconstructionMutex); - mReconstruction.save(stream); + mReconstruction.clear(); } - void load(android::base::Stream* stream, GfxApiLogger& gfx_logger, HealthMonitor<>* healthMonitor) { - mReconstruction.load(stream, gfx_logger, healthMonitor); + void saveDecoderReplayBuffer(android::base::Stream* stream) { + std::lock_guard lock(mReconstructionMutex); + mReconstruction.saveDecoderReplayBuffer(stream); + } + + static void loadDecoderReplayBuffer(android::base::Stream* stream, std::vector* outBuffer) { + VkReconstruction::loadDecoderReplayBuffer(stream, outBuffer); } VkSnapshotApiCallInfo* createApiCallInfo() { @@ -83,7 +89,7 @@ public: """ decoder_snapshot_impl_postamble = """ -private: + private: std::mutex mReconstructionMutex; VkReconstruction mReconstruction GUARDED_BY(mReconstructionMutex); }; @@ -91,12 +97,17 @@ private: VkDecoderSnapshot::VkDecoderSnapshot() : mImpl(new VkDecoderSnapshot::Impl()) { } -void VkDecoderSnapshot::save(android::base::Stream* stream) { - mImpl->save(stream); +void VkDecoderSnapshot::clear() { + mImpl->clear(); } -void VkDecoderSnapshot::load(android::base::Stream* stream, GfxApiLogger& gfx_logger, HealthMonitor<>* healthMonitor) { - mImpl->load(stream, gfx_logger, healthMonitor); +void VkDecoderSnapshot::saveDecoderReplayBuffer(android::base::Stream* stream) { + mImpl->saveDecoderReplayBuffer(stream); +} + +/*static*/ +void VkDecoderSnapshot::loadDecoderReplayBuffer(android::base::Stream* stream, std::vector* outBuffer) { + VkDecoderSnapshot::Impl::loadDecoderReplayBuffer(stream, outBuffer); } VkSnapshotApiCallInfo* VkDecoderSnapshot::createApiCallInfo() {