Skip to content

Commit 7915d9f

Browse files
authored
[Impeller] Allow transfer writes after the Vulkan mipmap layout barrier (flutter#194989)
<!-- 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::OnGenerateMipmapCommand` first moves every mip level to `TransferDst`, then blits into levels 1..N. That first barrier allowed only transfer reads as its destination access, so the blits' writes weren't ordered after the layout transition. This changes the destination access to transfer writes, which is what the blits do in that layout. The destination stage was already the transfer stage. 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 (flutter_pi). 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 645360b commit 7915d9f

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,10 @@ bool BlitPassVK::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
427427
/*image=*/image,
428428
/*src_access_mask=*/vk::AccessFlagBits::eTransferWrite |
429429
vk::AccessFlagBits::eColorAttachmentWrite,
430-
/*dst_access_mask=*/vk::AccessFlagBits::eTransferRead,
430+
// The blits below write mip levels 1..N while they are TransferDst, so
431+
// the next access is a transfer write, not a read
432+
// (SYNC-HAZARD-WRITE-AFTER-WRITE).
433+
/*dst_access_mask=*/vk::AccessFlagBits::eTransferWrite,
431434
/*old_layout=*/src.GetLayout(),
432435
/*new_layout=*/vk::ImageLayout::eTransferDstOptimal,
433436
/*src_stage=*/vk::PipelineStageFlagBits::eTransfer |

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,39 @@ TEST(BlitPassVKTest, MipmapGenerationTransitionsAllLevelsCorrectly) {
5454
EXPECT_EQ(barriers[7].subresourceRange.levelCount, 6u);
5555
}
5656

57+
TEST(BlitPassVKTest, MipmapGenerationInitialBarrierAllowsTransferWrites) {
58+
auto context = testing::MockVulkanContextBuilder().Build();
59+
ASSERT_TRUE(context->IsValid());
60+
61+
auto cmd_buffer = context->CreateCommandBuffer();
62+
ASSERT_TRUE(cmd_buffer);
63+
auto blit_pass = cmd_buffer->CreateBlitPass();
64+
ASSERT_TRUE(blit_pass);
65+
66+
auto vk_cmd_buffer = static_cast<CommandBufferVK*>(cmd_buffer.get());
67+
68+
TextureDescriptor desc;
69+
desc.size = ISize(100, 65);
70+
desc.format = PixelFormat::kR8G8B8A8UNormInt;
71+
desc.mip_count = 6;
72+
auto texture = context->GetResourceAllocator()->CreateTexture(desc);
73+
ASSERT_TRUE(texture);
74+
75+
ASSERT_TRUE(blit_pass->GenerateMipmap(texture, "TestMipmap"));
76+
77+
auto& barriers =
78+
testing::GetImageMemoryBarriers(vk_cmd_buffer->GetCommandBuffer());
79+
ASSERT_FALSE(barriers.empty());
80+
81+
// The first barrier moves every level to TransferDst. The blits that follow
82+
// write levels 1..N in that layout, so the barrier must make them visible to
83+
// transfer writes, not reads.
84+
const auto& initial = barriers[0];
85+
EXPECT_EQ(initial.newLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
86+
EXPECT_EQ(initial.subresourceRange.baseMipLevel, 0u);
87+
EXPECT_EQ(initial.subresourceRange.levelCount, 6u);
88+
EXPECT_EQ(initial.dstAccessMask,
89+
static_cast<VkAccessFlags>(VK_ACCESS_TRANSFER_WRITE_BIT));
90+
}
91+
5792
} // namespace impeller

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ def vulkan_validation_env(build_dir: str) -> typing.Dict[str, str]:
221221
## TODO(https://github.com/flutter/flutter/issues/194987):
222222
## BlitPassVK::OnCopyTextureToBufferCommand barrier.
223223
# 'Play/RendererTest.CanBlitTextureToBuffer/Vulkan',
224-
## TODO(https://github.com/flutter/flutter/issues/194987):
225-
## BlitPassVK::OnGenerateMipmapCommand barrier.
226-
# 'Play/RendererTest.CanGenerateMipmaps/Vulkan',
224+
'Play/RendererTest.CanGenerateMipmaps/Vulkan',
227225
'Play/TypographerTest.GlyphAtlasTextureWillGrowTilMaxTextureSize/Vulkan',
228226
# Render passes, offscreen targets, MSAA, depth/stencil and subpasses.
229227
'Play/RendererTest.CanRenderToTexture/Vulkan',

0 commit comments

Comments
 (0)