Skip to content

[Impeller] Order the Vulkan depth/stencil clear after earlier depth writes - #194990

Closed
jpohhhh wants to merge 6 commits into
flutter:masterfrom
Telosnex:impeller-vk-depth-dependency
Closed

jpohhhh wants to merge 6 commits into
flutter:masterfrom
Telosnex:impeller-vk-depth-dependency

Conversation

@jpohhhh

@jpohhhh jpohhhh commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

RenderPassBuilderVK's incoming subpass dependency (VK_SUBPASS_EXTERNAL to subpass 0) only covers the color attachment output and fragment shader stages. A depth/stencil attachment's load op (clear) runs in the fragment test stages, so it wasn't ordered after the attachment's layout transition or earlier depth/stencil writes.

When the render pass has a depth/stencil attachment, this adds the early and late fragment test stages and depth/stencil access to that dependency. Passes without one keep the existing masks, so color-only passes don't wait on more than before.

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-WRITE-AFTER-WRITE ] vkCmdBeginRenderPass(): WRITE_AFTER_WRITE hazard detected: attachment loadOp access is not synchronized with the attachment layout transition. vkCmdBeginRenderPass clears the depth aspect of attachment 2 in subpass 0 (VkImageView 0x…, loadOp VK_ATTACHMENT_LOAD_OP_CLEAR), which was previously written during an image layout transition initiated by the same command. The current synchronization allows VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT accesses at VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, but to prevent this hazard, it must allow VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT accesses at VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT.

Tests:

  • RenderPassBuilder.ExternalDependencyCoversDepthStencilClear checks the exact masks for a pass with depth/stencil. It fails without the fix.
  • RenderPassBuilder.ExternalDependencyOmitsDepthStagesWithoutDepthStencil checks a color-only pass keeps the existing masks.

To read the dependencies, the Vulkan mock now records the ones passed to vkCreateRenderPass (GetLastRenderPassDependencies).

Fixes: #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

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. 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.

…rites

The render pass's incoming dependency covered only color stages, so a
depth/stencil clear wasn't ordered after the attachment's layout transition
or earlier depth/stencil writes (SYNC-HAZARD-WRITE-AFTER-WRITE). Add the
fragment test stages and depth/stencil access, only when the pass has a
depth/stencil attachment.
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Oct 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Vulkan render pass builder to include depth/stencil stages and access flags in subpass dependencies when a depth/stencil attachment is present, and adds corresponding unit tests. It also updates the Vulkan mock device to track and retrieve render pass dependencies. Feedback on the mock implementation notes that constructing a vector from a potentially null pointer when the dependency count is zero can lead to undefined behavior, and suggests adding a null check.

@gaaclarke
gaaclarke requested a review from andywolff October 26, 2026 18:27
@andywolff andywolff added the CICD Run CI/CD label Oct 27, 2026

@andywolff andywolff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix

@andywolff

Copy link
Copy Markdown
Contributor

the ci.yaml validation failure check means you need to sync

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 28, 2026
@andywolff andywolff added the CICD Run CI/CD label Oct 28, 2026
andywolff
andywolff previously approved these changes Oct 28, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rebase this one too and add a validation test to run_tests.py

…y tests

flutter#195714 added eColorAttachmentRead to the incoming dependency's destination
access, and flutter#195689 landed the depth/stencil masks this PR originally added.
Update the expected masks to match.
@jpohhhh

jpohhhh commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for landing #195689 (and #195714), and for getting the depth validation tests back on - that covers both the fix and the validation test. I merged main and this PR is now just the RenderPassBuilder unit tests (the mock records the render pass dependencies, and the two tests check the masks, updated for the color attachment read).

Totally understand if that's not worth keeping now that the validation shard covers it. Happy to close it if so.

@jpohhhh
jpohhhh requested a review from gaaclarke November 4, 2026 17:52
@gaaclarke gaaclarke added the CICD Run CI/CD label Nov 4, 2026
@gaaclarke

Copy link
Copy Markdown
Member

Okay, sounds good, thanks for your help.

@gaaclarke gaaclarke closed this Nov 5, 2026
@jpohhhh
jpohhhh deleted the impeller-vk-depth-dependency branch November 5, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] Vulkan synchronization validation reports three hazards in BlitPassVK and RenderPassBuilderVK

3 participants