Sitelet https://github.com/flutter/flutter/pull/186767
Skip to content

[Impeller] Fix hardcoded Vulkan validation state in C API - #186767

Merged
auto-submit[bot] merged 17 commits into
flutter:masterfrom
KercyDing:master
Aug 7, 2026
Merged

auto-submit[bot] merged 17 commits into
flutter:masterfrom
KercyDing:master

Conversation

@KercyDing

@KercyDing KercyDing commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Make the standalone Impeller Vulkan interop layer respect ImpellerContextVulkanSettings.enable_vulkan_validation.

The C API already exposes this setting and ContextVK::Settings reads it, but ContextVK::Create currently forces impeller_settings.enable_validation = true. This means callers cannot disable Vulkan validation through the public standalone SDK API.

This PR changes the interop layer to pass through settings.enable_validation.

Fixes #186764

Tested

See PR comment for the full local test output.

Locally verified from engine/src/flutter:

  • ./bin/et build -c host_debug_unopt //flutter/impeller:impeller_unittests
  • ../out/host_debug_unopt/impeller_unittests --gtest_filter="InteropObjectTest.*" passed, 3 tests.
  • ../out/host_debug_unopt/impeller_unittests --gtest_filter="Play/InteropPlaygroundTest.*OpenGLES*" passed, 18 tests.

Vulkan coverage is left to CI because the local Vulkan playground run aborts in my Vulkan environment while initializing debug utils.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels May 19, 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 context creation in Impeller to propagate the enable_validation flag from the C API settings to the internal renderer. Feedback indicates that this logic change requires a corresponding regression test to comply with the repository style guide's requirement that all code changes be tested.

impeller_settings.shader_libraries_data = CreateShaderLibraryMappings();
impeller_settings.cache_directory = fml::paths::GetCachesDirectory();
impeller_settings.enable_validation = true;
impeller_settings.enable_validation = settings.enable_validation;

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.

medium

This bug fix lacks a corresponding regression test. Although the pull request description mentions a test exemption, forwarding a setting from the C API to the internal renderer is a logic change that should be tested to ensure the flag is correctly propagated and functional. Per the Repository Style Guide (line 11), all code changes should be tested.

References
  1. Code should be tested and follow the guidance described in the writing effective tests guide. (link)

@KercyDing

Copy link
Copy Markdown
Contributor Author

Tested on Linux with host_debug_unopt.

Built the Impeller unit test binary:

./bin/et build -c host_debug_unopt //flutter/impeller:impeller_unittests

Output:

[2026-05-20T08:47:31.858][linux/host_debug_unopt: GN]: STARTING
[2026-05-20T08:47:32.972][linux/host_debug_unopt: GN]: OK
[2026-05-20T08:47:33.598][linux/host_debug_unopt: ninja]: STARTING
[2026-05-20T08:47:33.787][linux/host_debug_unopt: ninja]: OK

Ran the interop object tests:

../out/host_debug_unopt/impeller_unittests --gtest_filter="InteropObjectTest.*"

Output:

[==========] Running 3 tests from 1 test suite.
[----------] 3 tests from InteropObjectTest
[ RUN      ] InteropObjectTest.CanCreateScoped
[       OK ] InteropObjectTest.CanCreateScoped (0 ms)
[ RUN      ] InteropObjectTest.CanCreate
[       OK ] InteropObjectTest.CanCreate (0 ms)
[ RUN      ] InteropObjectTest.CanCopyAssignMove
[       OK ] InteropObjectTest.CanCopyAssignMove (0 ms)
[----------] 3 tests from InteropObjectTest (0 ms total)
[==========] 3 tests from 1 test suite ran. (0 ms total)
[  PASSED  ] 3 tests.

Ran the OpenGLES interop playground tests:

../out/host_debug_unopt/impeller_unittests --gtest_filter="Play/InteropPlaygroundTest.*OpenGLES*"

Output:

[==========] Running 18 tests from 1 test suite.
[----------] 18 tests from Play/InteropPlaygroundTest
[ RUN      ] Play/InteropPlaygroundTest.CanCreateContext/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateContext/OpenGLES (77 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateDisplayListBuilder/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateDisplayListBuilder/OpenGLES (6 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateSurface/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateSurface/OpenGLES (24 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanDrawRect/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanDrawRect/OpenGLES (19 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanDrawImage/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanDrawImage/OpenGLES (40 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateOpenGLImage/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateOpenGLImage/OpenGLES (21 ms)
[ RUN      ] Play/InteropPlaygroundTest.ClearsOpenGLStancilStateAfterTransition/OpenGLES
[       OK ] Play/InteropPlaygroundTest.ClearsOpenGLStancilStateAfterTransition/OpenGLES (21 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateParagraphs/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateParagraphs/OpenGLES (217 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateDecorations/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateDecorations/OpenGLES (22 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateShapes/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateShapes/OpenGLES (20 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateParagraphsWithCustomFont/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateParagraphsWithCustomFont/OpenGLES (22 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanRenderTextAlignments/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanRenderTextAlignments/OpenGLES (24 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanRenderShadows/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanRenderShadows/OpenGLES (21 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanMeasureText/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanMeasureText/OpenGLES (25 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanGetPathBounds/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanGetPathBounds/OpenGLES (5 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanControlEllipses/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanControlEllipses/OpenGLES (23 ms)
[ RUN      ] Play/InteropPlaygroundTest.CanCreateFragmentProgramColorFilters/OpenGLES
[       OK ] Play/InteropPlaygroundTest.CanCreateFragmentProgramColorFilters/OpenGLES (46 ms)
[ RUN      ] Play/InteropPlaygroundTest.MappingsReleaseTheirDataOnDestruction/OpenGLES
[       OK ] Play/InteropPlaygroundTest.MappingsReleaseTheirDataOnDestruction/OpenGLES (6 ms)
[----------] 18 tests from Play/InteropPlaygroundTest (648 ms total)
[==========] 18 tests from 1 test suite ran. (649 ms total)
[  PASSED  ] 18 tests.

Note: I did not include the local Vulkan playground run here because it aborts in my local Vulkan environment while initializing debug utils. Relying on CI for Vulkan coverage.

gaaclarke
gaaclarke previously approved these changes Jun 2, 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.

lgtm

@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

@gaaclarke gaaclarke added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jul 27, 2026
@auto-submit

auto-submit Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/186767, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 27, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 27, 2026
@andywolff andywolff added the CICD Run CI/CD label Jul 28, 2026
@andywolff

Copy link
Copy Markdown
Contributor

Play/InteropPlaygroundTest.CanCreateContext/Vulkan is failing in CI

Previously we were hardcoding impeller_settings.enable_validation = true. But now we're passing settings.enable_validation. In CI, this is resolving to false because CI runs don't pass the --enable_vulkan_validation flag. ContextVK::Create unconditionally instantiates DebugReportVK. But because validation is not enabled in this run, DebugReportVK's vk::UniqueDebugUtilsMessengerEXT messenger_ is never initialized. During teardown, it attempts to invoke vkDestroyDebugUtilsMessengerEXT which is nullptr, causing a crash. To fix this, we can just wrap it in a std::unique_ptr. That way, the DebugReportVK's no-op implementation when validations are disabled will still be safe to use. See ebe6697

This only affects the PlaygroundTest because PlaygroundTest::CreateContext() sets settings.enable_vulkan_validation = GetSwitches().enable_vulkan_validation. Other tests just hardcode it to true. I think we need to set this to true here like the other tests. If we don't do that, this PR will cause the playground tests to run without validation, which we don't want. When I tried setting it to true, however, I ran into a problem where UserData created a dangling pointer, so I moved it to the heap. See 188da4f

If you agree please update your PR with these changes

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

See my comment above

@KercyDing

Copy link
Copy Markdown
Contributor Author

See my comment above请看我上面的评论。

Thanks for catching this! I’ll take a look and update the PR accordingly.

@KercyDing

Copy link
Copy Markdown
Contributor Author

Done, I’ve cherry-picked both commits. Please take another look.

@andywolff andywolff added the CICD Run CI/CD label Jul 30, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 6, 2026
@KercyDing

Copy link
Copy Markdown
Contributor Author

I've synced the branch with the latest master.

@andywolff, could you approve them and re-add the label when you get a chance? Thanks!

@andywolff andywolff added the CICD Run CI/CD label Aug 6, 2026
@andywolff

Copy link
Copy Markdown
Contributor

Thanks. It seems all impacted tests are passing, but there's a github outage right now which is affecting some of the other checks. I'll try it again when that outage is resolved

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 7, 2026
@andywolff andywolff added the CICD Run CI/CD label Aug 7, 2026

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

The LGTM exchange rates are currently trading at:

  • 1 LGTM = golden images match closely enough if I squint.
  • 2 LGTMs = I checked that this won't break the devicelab benchmarks
  • 3 LGTMs = I trust that this C++ pointer won't leak memory every frame.
  • 4 LGTMs = CI is green on the first try without a single retry or shard failure
image_1786120554622963

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] C API ignores enable_vulkan_validation setting in ContextVK

4 participants