Skip to content

Commit 8c843aa

Browse files
authored
[Impeller] libImpeller: Add support for Metal and Vulkan rendering. (flutter#161547)
* Adds context creation and WSI routines for Metal and Vulkan. * Enables all tests for the Metal, Vulkan, and OpenGLES backends. * Separate standalone examples for Metal, Vulkan, and OpenGLES have been created. These will be packaged with the SDK. * Disallows the use of OpenGL ES on macOS. * All new public methods are documented. * The SDK version number has been bumped. * Some incorrect nullability annotations were patched. * Tests harness is overhauled to reuse the same underlying context as the playgrounds. * The C++ public header has been updated. Fixes flutter#159512 Ports flutter/engine#56906
1 parent c5a1444 commit 8c843aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1764
-178
lines changed

engine/src/flutter/ci/licenses_golden/licenses_flutter

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42277,6 +42277,22 @@ ORIGIN: ../../../flutter/impeller/toolkit/glvk/proc_table.cc + ../../../flutter/
4227742277
ORIGIN: ../../../flutter/impeller/toolkit/glvk/proc_table.h + ../../../flutter/LICENSE
4227842278
ORIGIN: ../../../flutter/impeller/toolkit/glvk/trampoline.cc + ../../../flutter/LICENSE
4227942279
ORIGIN: ../../../flutter/impeller/toolkit/glvk/trampoline.h + ../../../flutter/LICENSE
42280+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/gles/context_gles.cc + ../../../flutter/LICENSE
42281+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/gles/context_gles.h + ../../../flutter/LICENSE
42282+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/gles/reactor_worker_gles.cc + ../../../flutter/LICENSE
42283+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/gles/reactor_worker_gles.h + ../../../flutter/LICENSE
42284+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/gles/surface_gles.cc + ../../../flutter/LICENSE
42285+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/gles/surface_gles.h + ../../../flutter/LICENSE
42286+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/metal/context_mtl.h + ../../../flutter/LICENSE
42287+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/metal/context_mtl.mm + ../../../flutter/LICENSE
42288+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/metal/surface_mtl.h + ../../../flutter/LICENSE
42289+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/metal/surface_mtl.mm + ../../../flutter/LICENSE
42290+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/vulkan/context_vk.cc + ../../../flutter/LICENSE
42291+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/vulkan/context_vk.h + ../../../flutter/LICENSE
42292+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/vulkan/surface_vk.cc + ../../../flutter/LICENSE
42293+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/vulkan/surface_vk.h + ../../../flutter/LICENSE
42294+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/vulkan/swapchain_vk.cc + ../../../flutter/LICENSE
42295+
ORIGIN: ../../../flutter/impeller/toolkit/interop/backend/vulkan/swapchain_vk.h + ../../../flutter/LICENSE
4228042296
ORIGIN: ../../../flutter/impeller/toolkit/interop/color_filter.cc + ../../../flutter/LICENSE
4228142297
ORIGIN: ../../../flutter/impeller/toolkit/interop/color_filter.h + ../../../flutter/LICENSE
4228242298
ORIGIN: ../../../flutter/impeller/toolkit/interop/color_source.cc + ../../../flutter/LICENSE
@@ -42287,7 +42303,9 @@ ORIGIN: ../../../flutter/impeller/toolkit/interop/dl.cc + ../../../flutter/LICEN
4228742303
ORIGIN: ../../../flutter/impeller/toolkit/interop/dl.h + ../../../flutter/LICENSE
4228842304
ORIGIN: ../../../flutter/impeller/toolkit/interop/dl_builder.cc + ../../../flutter/LICENSE
4228942305
ORIGIN: ../../../flutter/impeller/toolkit/interop/dl_builder.h + ../../../flutter/LICENSE
42290-
ORIGIN: ../../../flutter/impeller/toolkit/interop/example.c + ../../../flutter/LICENSE
42306+
ORIGIN: ../../../flutter/impeller/toolkit/interop/example_gl.c + ../../../flutter/LICENSE
42307+
ORIGIN: ../../../flutter/impeller/toolkit/interop/example_mtl.m + ../../../flutter/LICENSE
42308+
ORIGIN: ../../../flutter/impeller/toolkit/interop/example_vk.c + ../../../flutter/LICENSE
4229142309
ORIGIN: ../../../flutter/impeller/toolkit/interop/formats.cc + ../../../flutter/LICENSE
4229242310
ORIGIN: ../../../flutter/impeller/toolkit/interop/formats.h + ../../../flutter/LICENSE
4229342311
ORIGIN: ../../../flutter/impeller/toolkit/interop/image_filter.cc + ../../../flutter/LICENSE
@@ -45229,6 +45247,22 @@ FILE: ../../../flutter/impeller/toolkit/glvk/proc_table.cc
4522945247
FILE: ../../../flutter/impeller/toolkit/glvk/proc_table.h
4523045248
FILE: ../../../flutter/impeller/toolkit/glvk/trampoline.cc
4523145249
FILE: ../../../flutter/impeller/toolkit/glvk/trampoline.h
45250+
FILE: ../../../flutter/impeller/toolkit/interop/backend/gles/context_gles.cc
45251+
FILE: ../../../flutter/impeller/toolkit/interop/backend/gles/context_gles.h
45252+
FILE: ../../../flutter/impeller/toolkit/interop/backend/gles/reactor_worker_gles.cc
45253+
FILE: ../../../flutter/impeller/toolkit/interop/backend/gles/reactor_worker_gles.h
45254+
FILE: ../../../flutter/impeller/toolkit/interop/backend/gles/surface_gles.cc
45255+
FILE: ../../../flutter/impeller/toolkit/interop/backend/gles/surface_gles.h
45256+
FILE: ../../../flutter/impeller/toolkit/interop/backend/metal/context_mtl.h
45257+
FILE: ../../../flutter/impeller/toolkit/interop/backend/metal/context_mtl.mm
45258+
FILE: ../../../flutter/impeller/toolkit/interop/backend/metal/surface_mtl.h
45259+
FILE: ../../../flutter/impeller/toolkit/interop/backend/metal/surface_mtl.mm
45260+
FILE: ../../../flutter/impeller/toolkit/interop/backend/vulkan/context_vk.cc
45261+
FILE: ../../../flutter/impeller/toolkit/interop/backend/vulkan/context_vk.h
45262+
FILE: ../../../flutter/impeller/toolkit/interop/backend/vulkan/surface_vk.cc
45263+
FILE: ../../../flutter/impeller/toolkit/interop/backend/vulkan/surface_vk.h
45264+
FILE: ../../../flutter/impeller/toolkit/interop/backend/vulkan/swapchain_vk.cc
45265+
FILE: ../../../flutter/impeller/toolkit/interop/backend/vulkan/swapchain_vk.h
4523245266
FILE: ../../../flutter/impeller/toolkit/interop/color_filter.cc
4523345267
FILE: ../../../flutter/impeller/toolkit/interop/color_filter.h
4523445268
FILE: ../../../flutter/impeller/toolkit/interop/color_source.cc
@@ -45239,7 +45273,9 @@ FILE: ../../../flutter/impeller/toolkit/interop/dl.cc
4523945273
FILE: ../../../flutter/impeller/toolkit/interop/dl.h
4524045274
FILE: ../../../flutter/impeller/toolkit/interop/dl_builder.cc
4524145275
FILE: ../../../flutter/impeller/toolkit/interop/dl_builder.h
45242-
FILE: ../../../flutter/impeller/toolkit/interop/example.c
45276+
FILE: ../../../flutter/impeller/toolkit/interop/example_gl.c
45277+
FILE: ../../../flutter/impeller/toolkit/interop/example_mtl.m
45278+
FILE: ../../../flutter/impeller/toolkit/interop/example_vk.c
4524345279
FILE: ../../../flutter/impeller/toolkit/interop/formats.cc
4524445280
FILE: ../../../flutter/impeller/toolkit/interop/formats.h
4524545281
FILE: ../../../flutter/impeller/toolkit/interop/image_filter.cc

engine/src/flutter/impeller/playground/backend/vulkan/playground_impl_vk.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ PlaygroundImplVK::PlaygroundImplVK(PlaygroundSwitches switches)
9595
context_settings.enable_validation = switches_.enable_vulkan_validation;
9696
context_settings.fatal_missing_validations =
9797
switches_.enable_vulkan_validation;
98-
;
9998

10099
auto context_vk = ContextVK::Create(std::move(context_settings));
101100
if (!context_vk || !context_vk->IsValid()) {
@@ -237,4 +236,13 @@ bool PlaygroundImplVK::IsVulkanDriverPresent() {
237236
return false;
238237
}
239238

239+
// |PlaygroundImpl|
240+
Playground::VKProcAddressResolver
241+
PlaygroundImplVK::CreateVKProcAddressResolver() const {
242+
return [](void* instance, const char* proc_name) -> void* {
243+
return reinterpret_cast<void*>(::glfwGetInstanceProcAddress(
244+
reinterpret_cast<VkInstance>(instance), proc_name));
245+
};
246+
}
247+
240248
} // namespace impeller

engine/src/flutter/impeller/playground/backend/vulkan/playground_impl_vk.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class PlaygroundImplVK final : public PlaygroundImpl {
4444
std::unique_ptr<Surface> AcquireSurfaceFrame(
4545
std::shared_ptr<Context> context) override;
4646

47+
// |PlaygroundImpl|
48+
Playground::VKProcAddressResolver CreateVKProcAddressResolver()
49+
const override;
50+
4751
PlaygroundImplVK(const PlaygroundImplVK&) = delete;
4852

4953
PlaygroundImplVK& operator=(const PlaygroundImplVK&) = delete;

engine/src/flutter/impeller/playground/playground.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,9 @@ Playground::GLProcAddressResolver Playground::CreateGLProcAddressResolver()
521521
return impl_->CreateGLProcAddressResolver();
522522
}
523523

524+
Playground::VKProcAddressResolver Playground::CreateVKProcAddressResolver()
525+
const {
526+
return impl_->CreateVKProcAddressResolver();
527+
}
528+
524529
} // namespace impeller

engine/src/flutter/impeller/playground/playground.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class Playground {
118118
using GLProcAddressResolver = std::function<void*(const char* proc_name)>;
119119
GLProcAddressResolver CreateGLProcAddressResolver() const;
120120

121+
using VKProcAddressResolver =
122+
std::function<void*(void* instance, const char* proc_name)>;
123+
VKProcAddressResolver CreateVKProcAddressResolver() const;
124+
121125
protected:
122126
const PlaygroundSwitches switches_;
123127

engine/src/flutter/impeller/playground/playground_impl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ Playground::GLProcAddressResolver PlaygroundImpl::CreateGLProcAddressResolver()
7171
return nullptr;
7272
}
7373

74+
Playground::VKProcAddressResolver PlaygroundImpl::CreateVKProcAddressResolver()
75+
const {
76+
return nullptr;
77+
}
78+
7479
} // namespace impeller

engine/src/flutter/impeller/playground/playground_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class PlaygroundImpl {
3838

3939
virtual Playground::GLProcAddressResolver CreateGLProcAddressResolver() const;
4040

41+
virtual Playground::VKProcAddressResolver CreateVKProcAddressResolver() const;
42+
4143
protected:
4244
const PlaygroundSwitches switches_;
4345

engine/src/flutter/impeller/renderer/backend/vulkan/context_vk.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void ContextVK::Setup(Settings settings) {
144144
TRACE_EVENT0("impeller", "ContextVK::Setup");
145145

146146
if (!settings.proc_address_callback) {
147+
VALIDATION_LOG << "Missing proc address callback.";
147148
return;
148149
}
149150

@@ -155,7 +156,7 @@ void ContextVK::Setup(Settings settings) {
155156
fml::RequestAffinity(fml::CpuAffinity::kNotPerformance);
156157
#ifdef FML_OS_ANDROID
157158
if (::setpriority(PRIO_PROCESS, gettid(), -5) != 0) {
158-
FML_LOG(ERROR) << "Failed to set Workers task runner priority";
159+
VALIDATION_LOG << "Failed to set Workers task runner priority";
159160
}
160161
#endif // FML_OS_ANDROID
161162
});

engine/src/flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_impl_vk.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,38 @@ const ISize& KHRSwapchainImplVK::GetSize() const {
279279
return size_;
280280
}
281281

282+
std::optional<ISize> KHRSwapchainImplVK::GetCurrentUnderlyingSurfaceSize()
283+
const {
284+
if (!IsValid()) {
285+
return std::nullopt;
286+
}
287+
288+
auto context = context_.lock();
289+
if (!context) {
290+
return std::nullopt;
291+
}
292+
293+
auto& vk_context = ContextVK::Cast(*context);
294+
const auto [result, surface_caps] =
295+
vk_context.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface_.get());
296+
if (result != vk::Result::eSuccess) {
297+
return std::nullopt;
298+
}
299+
300+
// From the spec: `currentExtent` is the current width and height of the
301+
// surface, or the special value (0xFFFFFFFF, 0xFFFFFFFF) indicating that the
302+
// surface size will be determined by the extent of a swapchain targeting the
303+
// surface.
304+
constexpr uint32_t kCurrentExtentsPlaceholder = 0xFFFFFFFF;
305+
if (surface_caps.currentExtent.width == kCurrentExtentsPlaceholder ||
306+
surface_caps.currentExtent.height == kCurrentExtentsPlaceholder) {
307+
return std::nullopt;
308+
}
309+
310+
return ISize::MakeWH(surface_caps.currentExtent.width,
311+
surface_caps.currentExtent.height);
312+
}
313+
282314
bool KHRSwapchainImplVK::IsValid() const {
283315
return is_valid_;
284316
}

engine/src/flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_impl_vk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class KHRSwapchainImplVK final
6464

6565
void AddFinalCommandBuffer(std::shared_ptr<CommandBuffer> cmd_buffer);
6666

67+
std::optional<ISize> GetCurrentUnderlyingSurfaceSize() const;
68+
6769
private:
6870
std::weak_ptr<Context> context_;
6971
vk::UniqueSurfaceKHR surface_;

0 commit comments

Comments
 (0)