Repository navigation
Description
While working on #192937 to fix the snapshot memory leak in #192097 by resetting the transient HostBuffer after each snapshot, I hit flaky pixel comparison failures in transform_test.dart and canvas_test.dart. I initially landed test workarounds in #193030, #193936, and #193937 (under #193029 and #193689), but closer inspection showed those failures were caused by two Impeller HostBuffer bugs rather than rendering nondeterminism.
The core problem is that DisplayListToTexture resets the shared HostBuffer twice per snapshot, and SurfaceContextVK fails to forward its parent ContextVK's GpuSubmissionTracker. Together, these cause Vulkan snapshots to wrap the 4-slot HostBuffer ring buffer after just 2 snapshots and overwrite in-flight GPU vertex and uniform data.
In transform_test.dart and canvas_test.dart, tests capture multiple toImage snapshots back-to-back before waiting on readback. With reset_host_buffer = true, entire drawn quads were disappearing from earlier snapshots because later snapshots overwrote their buffer slots before the GPU finished rendering them.
Tracing toImage into DisplayListToTexture (dl_dispatcher.cc) shows two issues:
- Double reset in
DisplayListToTexture: At the end of a snapshot,DisplayListToTexturecallsReset()on bothGetTransientsDataBuffer()andGetTransientsIndexesBuffer(). On all non-WebGL backends, both getters return the sameHostBufferinstance, so each snapshot advances the 4-slot ring buffer twice instead of once (unlikeRenderToTarget, which callscontext.ResetTransientsBuffers()). - Missing tracker in
SurfaceContextVK: Before reusing a ring-buffer slot,HostBuffer::Reset()checkscontext->GetSubmissionTracker()(added in [Impeller] Recycle HostBuffer arena entries only after GPU completion #188965) to see if the GPU has finished with that slot. Bothflutter_testerVulkan (TesterContextVK) and Android Vulkan (AndroidSurfaceVKImpeller) pass aSurfaceContextVKwrapper toContentContext, andSurfaceContextVKdid not overrideGetSubmissionTracker()to forwardparent_->GetSubmissionTracker(). Receivingnullptr,HostBuffer::Reset()skips the GPU completion check and reuses in-flight slots immediately.
Activity
Revert: Mitigate snapshot race in 3D transform test by reducing loop …
Revert: Allow color delta tolerance in in-memory fuzzy image comparat…
[Impeller] Fix SurfaceContextVK submission tracking and double HostBu…