Skip to content

Commit f95e1c9

Browse files
authored
[Impeller] Use the transfer stage for the Vulkan readback barrier (flutter#194991)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> `BlitPassVK::OnCopyTextureToBufferCommand` transitions the source image to `TransferSrc` and then copies it with `vkCmdCopyImageToBuffer`. The barrier for that transition named shader reads in the vertex and fragment stages as its destination, so nothing ordered the copy after the layout transition. This changes the destination to transfer reads in the transfer stage, which is what the copy does. The barrier after the copy (transfer to host read) was already correct. Found with `VK_LAYER_KHRONOS_validation` 1.4.309 and synchronization validation on, on a Raspberry Pi 5 / CM5 (V3D 7.1, Mesa 26.2.1) running Impeller Vulkan through a custom embedder. The message appeared at every app launch and no longer appears with this change. The code changed here is identical on `master`. ``` Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] vkCmdCopyImageToBuffer(): READ_AFTER_WRITE hazard detected. vkCmdCopyImageToBuffer reads VkImage 0x…, which was previously written during an image layout transition initiated by vkCmdPipelineBarrier. The current synchronization allows VK_ACCESS_2_SHADER_READ_BIT accesses at VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT|VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT, but to prevent this hazard, it must allow VK_ACCESS_2_TRANSFER_READ_BIT accesses at VK_PIPELINE_STAGE_2_COPY_BIT. ``` Test: `BlitPassVKTest.CopyTextureToBufferBarrierTargetsTheCopy` checks the barrier's destination access and stage. To check the stage, the Vulkan mock now also records each image barrier's `dstStageMask` (`GetImageMemoryBarrierDstStages`). The test fails without the fix. Fixes: [flutter#194987](flutter#194987) *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [~ (within test files changed)] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent de37392 commit f95e1c9

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎engine/src/flutter/impeller/renderer/backend/vulkan/blit_pass_vk.cc‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ bool BlitPassVK::OnCopyTextureToBufferCommand(
172172
barrier.src_stage = vk::PipelineStageFlagBits::eFragmentShader |
173173
vk::PipelineStageFlagBits::eTransfer |
174174
vk::PipelineStageFlagBits::eColorAttachmentOutput;
175-
barrier.dst_access = vk::AccessFlagBits::eShaderRead;
176-
barrier.dst_stage = vk::PipelineStageFlagBits::eVertexShader |
177-
vk::PipelineStageFlagBits::eFragmentShader;
175+
// The next access is the copy below, a transfer read. Shader stages don't
176+
// order the copy after the layout transition (SYNC-HAZARD-READ-AFTER-WRITE).
177+
barrier.dst_access = vk::AccessFlagBits::eTransferRead;
178+
barrier.dst_stage = vk::PipelineStageFlagBits::eTransfer;
178179

179180
const auto& dst = DeviceBufferVK::Cast(*destination);
180181

‎engine/src/flutter/testing/run_tests.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ def vulkan_validation_env(build_dir: str) -> typing.Dict[str, str]:
218218
# Blits, readbacks and mipmap generation.
219219
'Play/BlitPassTest.CanBlitSmallRegionToUninitializedTexture/Vulkan',
220220
'Play/BlitPassTest.CanResizeTextures/Vulkan',
221-
## TODO(https://github.com/flutter/flutter/issues/194987):
222-
## BlitPassVK::OnCopyTextureToBufferCommand barrier.
223-
# 'Play/RendererTest.CanBlitTextureToBuffer/Vulkan',
221+
'Play/RendererTest.CanBlitTextureToBuffer/Vulkan',
224222
'Play/RendererTest.CanGenerateMipmaps/Vulkan',
225223
'Play/TypographerTest.GlyphAtlasTextureWillGrowTilMaxTextureSize/Vulkan',
226224
# Render passes, offscreen targets, MSAA, depth/stencil and subpasses.

0 commit comments

Comments
 (0)