Skip to content

[frame looping] Update and optimize buffer state restoration - #36

Open
olehkuznetsov wants to merge 1 commit into
android-graphics:devfrom
olehkuznetsov:frame-loop-fix
Open

[frame looping] Update and optimize buffer state restoration#36
olehkuznetsov wants to merge 1 commit into
android-graphics:devfrom
olehkuznetsov:frame-loop-fix

Conversation

@olehkuznetsov

@olehkuznetsov olehkuznetsov commented Aug 13, 2026

Copy link
Copy Markdown

Summary

This PR improves and optimizes GPU buffer state restoration for Vulkan frame looping, and fixes crashes caused by attempting to copy unbound buffers:

  1. Lazy Mutation-Focused Buffer Tracking:

    • Intercepts mutating buffer commands (vkCmdCopyBuffer destination, vkCmdCopyImageToBuffer, vkCmdUpdateBuffer, vkCmdFillBuffer, vkCmdPipelineBarrier) to populate touched buffers.
    • Filters descriptor set inspection to only collect Storage Buffers (SSBOs) and Storage Texel Buffers, skipping static read-only buffers (vertex, index, UBOs, copy sources) to save significant VRAM and avoid unnecessary copy bandwidth during loop resets.
    • Recursively traverses executed secondary command buffers with a cycle/duplicate guard (visited_cbs).
  2. Vulkan Safety & Lifecycle Fixes:

    • Fix Unbound Buffers Crash: Previously, RecordInitialBufferStates greedily snapshotted all buffers in GetObjectInfoTable() upfront at loop start, attempting to copy state via vkCmdCopyBuffer for buffers that were created with vkCreateBuffer but never bound to memory with vkBindBufferMemory (e.g. secondary devices in multi-device Android HWUI traces). Copying unbound buffers violates VUID-vkCmdCopyBuffer-srcBuffer-00119 and causes GPU MMU page faults at virtual address 0x0 (TRANSLATION_FAULT), resulting in VK_ERROR_DEVICE_LOST. Switching to on-demand tracking ensures only buffers actively bound and referenced by submitted workloads are snapshotted.
    • Queue Family Mismatch: Tracks restoration_queue_family_index_ in InitializeRestorationResources so that the restoration command pool is properly recreated if submits switch queue families on the same logical device (conforming to VUID-vkQueueSubmit-pCommandBuffers-00064).
    • Null Device Info Guard: Added null checks on GetObjectInfoTable().GetVkDeviceInfo(queue_info->parent_id) before dereferencing device handles.
    • Transactional Shadow Registration: Staged new shadow buffers locally and committed them to shadow_buffers_ only after snapshot QueueSubmit succeeds, rolling back on failure.
    • Command Buffer Reset Cleanup: Cleared bound_buffers in Process_vkBeginCommandBuffer and ClearCommandBufferInfo to prevent memory growth across loop iterations.
    • Host Synchronization: Included VK_PIPELINE_STAGE_HOST_BIT and VK_ACCESS_HOST_WRITE_BIT in the pre-copy snapshot barrier to guarantee visibility of host-visible buffer writes.
    • Shadow Buffer Creation Helper: Encapsulated shadow buffer allocation and binding into CreateShadowBuffer.
  3. Documentation:

    • Updated frame_loop_buffers_content.md describing the buffer tracking architecture and restoration lifecycle.

Testing

  • Tested and verified buffer state backup and restoration on Vulkan replay traces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant