Skip to content

gfxstream: Fix crash and synchronization in GPU scaled readback - #181

Closed
GOOG-sergiu wants to merge 1 commit into
google:mainfrom
GOOG-sergiu:fix_scaled_readback
Closed

gfxstream: Fix crash and synchronization in GPU scaled readback#181
GOOG-sergiu wants to merge 1 commit into
google:mainfrom
GOOG-sergiu:fix_scaled_readback

Conversation

@GOOG-sergiu

Copy link
Copy Markdown
Collaborator

When Android Studio or a client requests a scaled display frame (via gRPC streamScreenshot), readColorBufferPixelsScaled delegates to readColorBufferPixelsScaledGpu. This previously caused an immediate crash (SIGSEGV / exit code 139) on the host due to several Vulkan synchronization and memory violations:

  • Missing layout transition and memory barrier: sourceCbInfo->image was sampled in CompositorVk::drawImage() as VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL without transitioning from its current layout (e.g. COLOR_ATTACHMENT_OPTIMAL or GENERAL). On host drivers, sampling an attachment layout without a barrier triggers GPU MMU faults. Added a pre-draw pipeline barrier transitioning to SHADER_READ_ONLY_OPTIMAL and a post-draw barrier restoring the original layout.
  • Missing outbound subpass dependency: tempRenderPass only specified an inbound dependency (EXTERNAL -> 0), causing vkCmdCopyImageToBuffer to execute concurrently with active color attachment writes. Added an outbound dependency (0 -> EXTERNAL) to flush color attachment writes before the transfer read.
  • Missing staging buffer size check: validated requiredStagingSize against mStaging.mAllocationSize.
  • Hard aborts on transient errors: replaced VK_CHECK with graceful error logging, resource cleanup, and queue idling on fence failure.
  • Added graceful fallback to readColorBufferPixelsScaledCpu if readColorBufferPixelsScaledGpu fails.

Bug: 553490628
Test: bazel test //host/vulkan:vk_common_operations_tests //host/vulkan:gfxstream_compositorvk_tests
Change-Id: Icb7889bb7bbdc8dbe3d3ffdae0ba2899dfd85a2f

When Android Studio or a client requests a scaled display frame
(via gRPC streamScreenshot), readColorBufferPixelsScaled delegates
to readColorBufferPixelsScaledGpu. This previously caused an immediate
crash (SIGSEGV / exit code 139) on the host due to several Vulkan
synchronization and memory violations:

- Missing layout transition and memory barrier: sourceCbInfo->image
  was sampled in CompositorVk::drawImage() as VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
  without transitioning from its current layout (e.g. COLOR_ATTACHMENT_OPTIMAL
  or GENERAL). On host drivers, sampling an attachment layout without a
  barrier triggers GPU MMU faults. Added a pre-draw pipeline barrier
  transitioning to SHADER_READ_ONLY_OPTIMAL and a post-draw barrier
  restoring the original layout.
- Missing outbound subpass dependency: tempRenderPass only specified
  an inbound dependency (EXTERNAL -> 0), causing vkCmdCopyImageToBuffer
  to execute concurrently with active color attachment writes. Added an
  outbound dependency (0 -> EXTERNAL) to flush color attachment writes
  before the transfer read.
- Missing staging buffer size check: validated requiredStagingSize
  against mStaging.mAllocationSize.
- Hard aborts on transient errors: replaced VK_CHECK with graceful
  error logging, resource cleanup, and queue idling on fence failure.
- Added graceful fallback to readColorBufferPixelsScaledCpu if
  readColorBufferPixelsScaledGpu fails.

Bug: 553490628
Test: bazel test //host/vulkan:vk_common_operations_tests //host/vulkan:gfxstream_compositorvk_tests
Change-Id: Icb7889bb7bbdc8dbe3d3ffdae0ba2899dfd85a2f
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