Skip to content

Commit 9ac9b06

Browse files
authored
Fix Vulkan MSAA diagonal seam in FramebufferBlend (flutter#196197)
On Metal and OpenGL ES, SPIRV-Cross lowers `subpassInputMS` to native framebuffer fetch, which the hardware/driver scopes to the current primitive's covered samples. On Vulkan, `subpassLoad(uSub, i)` remains an explicit pixel-rate MSAA input-attachment read of sample `i`. Unconditionally averaging samples reads samples outside this primitive's coverage, including samples along a triangle strip's shared edge already written by the adjacent triangle. To address the issue, This PR averages only the samples indicated by the mask. Fixes flutter#179547 ## 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. - [x] 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 031636e commit 9ac9b06

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎engine/src/flutter/impeller/entity/shaders/blending/framebuffer_blend.frag‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,26 @@ layout(constant_id = 1) const float supports_decal = 1;
1919
layout(input_attachment_index = 0) uniform subpassInputMS uSub;
2020

2121
vec4 ReadDestination() {
22-
return (subpassLoad(uSub, 0) + subpassLoad(uSub, 1) + subpassLoad(uSub, 2) +
23-
subpassLoad(uSub, 3)) /
24-
vec4(4.0);
22+
#ifdef IMPELLER_TARGET_VULKAN
23+
// Vulkan reads MSAA input attachments one sample at a time, and this shader
24+
// runs once per pixel. Average only the samples covered by this primitive.
25+
// Samples outside its coverage may already have been written earlier in
26+
// this draw, e.g. along the shared edge of the quad's two triangles.
27+
// https://github.com/flutter/flutter/issues/179547
28+
int mask = gl_SampleMaskIn[0] & 0xf;
29+
vec4 result = vec4(0.0);
30+
for (int i = 0; i < 4; i++) {
31+
if ((mask & (1 << i)) != 0) {
32+
result += subpassLoad(uSub, i);
33+
}
34+
}
35+
return result / float(max(bitCount(mask), 1));
36+
#else
37+
// On Metal and GLES, SPIRV-Cross turns this into framebuffer fetch and
38+
// ignores the sample index. Sample variables such as gl_SampleMaskIn also
39+
// aren't available in GLSL ES 1.00.
40+
return subpassLoad(uSub, 0);
41+
#endif
2542
}
2643

2744
uniform sampler2D texture_sampler_src;

0 commit comments

Comments
 (0)