-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] flutter_tester --enable-impeller #46389
Changes from 6 commits
3fb8de3
af399e7
28f759b
c91fb44
0e49330
bf08e66
d4aef8a
ee377fc
1c35a29
4f06076
de4abfa
5975e14
11d53f2
79f99c9
7cd05f6
effb21b
28eea9a
5f78735
f801e47
58b1cb6
0b137b9
fb4c806
48a6d52
46a393a
91804dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,45 @@ | |||||
| #include "third_party/dart/runtime/include/dart_api.h" | ||||||
| #include "third_party/skia/include/core/SkSurface.h" | ||||||
|
|
||||||
| #if IMPELLER_SUPPORTS_RENDERING | ||||||
| #include <vulkan/vulkan.h> // nogncheck | ||||||
| #include "impeller/core/formats.h" // nogncheck | ||||||
| #include "impeller/entity/vk/entity_shaders_vk.h" // nogncheck | ||||||
| #include "impeller/entity/vk/modern_shaders_vk.h" // nogncheck | ||||||
| #include "impeller/renderer/backend/vulkan/context_vk.h" // nogncheck | ||||||
| #include "impeller/renderer/backend/vulkan/surface_context_vk.h" // nogncheck | ||||||
| #include "impeller/renderer/context.h" // nogncheck | ||||||
| #include "impeller/renderer/surface.h" // nogncheck | ||||||
| #include "impeller/renderer/vk/compute_shaders_vk.h" // nogncheck | ||||||
| #include "shell/gpu/gpu_surface_vulkan_impeller.h" // nogncheck | ||||||
| #if IMPELLER_ENABLE_3D | ||||||
| #include "impeller/scene/shaders/vk/scene_shaders_vk.h" // nogncheck | ||||||
| #endif // IMPELLER_ENABLE_3D | ||||||
|
|
||||||
| static std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() { | ||||||
| return { | ||||||
| std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data, | ||||||
| impeller_entity_shaders_vk_length), | ||||||
| std::make_shared<fml::NonOwnedMapping>( | ||||||
| impeller_modern_shaders_vk_data, impeller_modern_shaders_vk_length), | ||||||
| #if IMPELLER_ENABLE_3D | ||||||
| std::make_shared<fml::NonOwnedMapping>( | ||||||
| impeller_scene_shaders_vk_data, impeller_scene_shaders_vk_length), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for taking care of Scene. 🙏 |
||||||
| #endif // IMPELLER_ENABLE_3D | ||||||
| std::make_shared<fml::NonOwnedMapping>( | ||||||
| impeller_compute_shaders_vk_data, | ||||||
| impeller_compute_shaders_vk_length), | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| #else | ||||||
| namespace impeller { | ||||||
| class Context; | ||||||
| class ContextVK; | ||||||
| class SurfaceContextVK; | ||||||
| } // namespace impeller | ||||||
| #endif // IMPELLER_SUPPORTS_RENDERING | ||||||
|
|
||||||
| #if defined(FML_OS_WIN) | ||||||
| #include <combaseapi.h> | ||||||
| #endif // defined(FML_OS_WIN) | ||||||
|
|
@@ -81,11 +120,32 @@ class TesterGPUSurfaceSoftware : public GPUSurfaceSoftware { | |||||
| class TesterPlatformView : public PlatformView, | ||||||
| public GPUSurfaceSoftwareDelegate { | ||||||
| public: | ||||||
| TesterPlatformView(Delegate& delegate, const TaskRunners& task_runners) | ||||||
| : PlatformView(delegate, task_runners) {} | ||||||
| TesterPlatformView(Delegate& delegate, | ||||||
| const TaskRunners& task_runners, | ||||||
| const std::shared_ptr<impeller::Context>& impeller_context, | ||||||
| const std::shared_ptr<impeller::SurfaceContextVK>& | ||||||
| impeller_surface_context) | ||||||
| : PlatformView(delegate, task_runners), | ||||||
| impeller_context_(impeller_context), | ||||||
| impeller_surface_context_(impeller_surface_context) {} | ||||||
|
|
||||||
| // |PlatformView| | ||||||
| std::shared_ptr<impeller::Context> GetImpellerContext() const override { | ||||||
| return impeller_context_; | ||||||
| } | ||||||
|
|
||||||
| // |PlatformView| | ||||||
| std::unique_ptr<Surface> CreateRenderingSurface() override { | ||||||
| #if IMPELLER_SUPPORTS_RENDERING | ||||||
| if (delegate_.OnPlatformViewGetSettings().enable_impeller) { | ||||||
| FML_DCHECK(impeller_context_); | ||||||
| auto surface = | ||||||
| std::make_unique<GPUSurfaceVulkanImpeller>(impeller_surface_context_); | ||||||
| FML_DCHECK(surface->IsValid()); | ||||||
| return surface; | ||||||
| } | ||||||
| #endif // IMPELLER_SUPPORTS_RENDERING | ||||||
| FML_DCHECK(!impeller_context_); | ||||||
| auto surface = std::make_unique<TesterGPUSurfaceSoftware>( | ||||||
| this, true /* render to surface */); | ||||||
| FML_DCHECK(surface->IsValid()); | ||||||
|
|
@@ -126,6 +186,8 @@ class TesterPlatformView : public PlatformView, | |||||
|
|
||||||
| private: | ||||||
| sk_sp<SkSurface> sk_surface_ = nullptr; | ||||||
| std::shared_ptr<impeller::Context> impeller_context_; | ||||||
| std::shared_ptr<impeller::SurfaceContextVK> impeller_surface_context_; | ||||||
| std::shared_ptr<TesterExternalViewEmbedder> external_view_embedder_ = | ||||||
| std::make_shared<TesterExternalViewEmbedder>(); | ||||||
| }; | ||||||
|
|
@@ -235,10 +297,52 @@ int RunTester(const flutter::Settings& settings, | |||||
| io_task_runner // io | ||||||
| ); | ||||||
|
|
||||||
| std::shared_ptr<impeller::ContextVK> impeller_context; | ||||||
| std::shared_ptr<impeller::SurfaceContextVK> impeller_surface_context; | ||||||
|
|
||||||
| #if IMPELLER_SUPPORTS_RENDERING | ||||||
| if (settings.enable_impeller) { | ||||||
| impeller::ContextVK::Settings context_settings; | ||||||
| context_settings.proc_address_callback = | ||||||
| reinterpret_cast<PFN_vkGetInstanceProcAddr>(&::vkGetInstanceProcAddr); | ||||||
| context_settings.shader_libraries_data = ShaderLibraryMappings(); | ||||||
| context_settings.cache_directory = fml::paths::GetCachesDirectory(); | ||||||
| context_settings.enable_validation = settings.enable_vulkan_validation; | ||||||
|
|
||||||
| impeller_context = impeller::ContextVK::Create(std::move(context_settings)); | ||||||
| if (!impeller_context || !impeller_context->IsValid()) { | ||||||
| VALIDATION_LOG << "Could not create Vulkan context."; | ||||||
| return -1; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| impeller::vk::SurfaceKHR vk_surface; | ||||||
| impeller::vk::HeadlessSurfaceCreateInfoEXT surface_create_info; | ||||||
| auto res = impeller_context->GetInstance().createHeadlessSurfaceEXT( | ||||||
| &surface_create_info, // surface create info | ||||||
| nullptr, // allocator | ||||||
| &vk_surface // surface | ||||||
| ); | ||||||
| if (res != impeller::vk::Result::eSuccess) { | ||||||
| VALIDATION_LOG << "Could not create surface for tester " | ||||||
| << impeller::vk::to_string(res); | ||||||
| return -1; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done here and elsewhere |
||||||
| } | ||||||
|
|
||||||
| impeller::vk::UniqueSurfaceKHR surface{vk_surface, | ||||||
| impeller_context->GetInstance()}; | ||||||
| impeller_surface_context = impeller_context->CreateSurfaceContext(); | ||||||
| if (!impeller_surface_context->SetWindowSurface(std::move(surface))) { | ||||||
| VALIDATION_LOG << "Could not set up surface for context."; | ||||||
| return -1; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| } | ||||||
| #endif // IMPELLER_SUPPORTS_RENDERING | ||||||
|
|
||||||
| Shell::CreateCallback<PlatformView> on_create_platform_view = | ||||||
| [](Shell& shell) { | ||||||
| return std::make_unique<TesterPlatformView>(shell, | ||||||
| shell.GetTaskRunners()); | ||||||
| [impeller_context, impeller_surface_context](Shell& shell) { | ||||||
| return std::make_unique<TesterPlatformView>( | ||||||
| shell, shell.GetTaskRunners(), impeller_context, | ||||||
| impeller_surface_context); | ||||||
| }; | ||||||
|
|
||||||
| Shell::CreateCallback<Rasterizer> on_create_rasterizer = [](Shell& shell) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ import 'package:vector_math/vector_math_64.dart'; | |
|
|
||
| typedef CanvasCallback = void Function(Canvas canvas); | ||
|
|
||
| bool get impellerEnabled => Platform.executableArguments.contains('--enable-impeller'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider factoring this definition out into a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| Future<Image> createImage(int width, int height) { | ||
| final Completer<Image> completer = Completer<Image>(); | ||
| decodeImageFromPixels( | ||
|
|
@@ -190,7 +192,7 @@ void main() { | |
| expect(image.height, equals(100)); | ||
|
|
||
| final bool areEqual = | ||
| await fuzzyGoldenImageCompare(image, 'canvas_test_toImage.png'); | ||
| await fuzzyGoldenImageCompare(image, '${impellerEnabled ? 'impeller_' : ''}canvas_test_toImage.png'); | ||
| expect(areEqual, true); | ||
| }); | ||
|
|
||
|
|
@@ -438,6 +440,12 @@ void main() { | |
| recorder = PictureRecorder(); | ||
| canvas = Canvas(recorder); | ||
|
|
||
| if (impellerEnabled) { | ||
| // Impeller tries to automagically scale this. See | ||
| // https://github.com/flutter/flutter/issues/128885 | ||
| canvas.drawImage(image, Offset.zero, Paint()); | ||
| return; | ||
| } | ||
| // On a slower CI machine, the raster thread may get behind the UI thread | ||
| // here. However, once the image is in an error state it will immediately | ||
| // throw on subsequent attempts. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we have these swiftshader lib names copied around in 3 or 4 places at this point (including in some source files). Not sure if there's one good place we could consolidate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up moving this to
//flutter/vulkan/swiftshader_path.h