diff --git a/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc b/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc index 11d9018d95..006cef0394 100644 --- a/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc +++ b/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc @@ -15,6 +15,7 @@ #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" #include "third_party/skia/include/gpu/ganesh/vk/GrVkDirectContext.h" +#include "third_party/skia/include/gpu/vk/VulkanExtensions.h" #if OS_FUCHSIA #define VULKAN_SO_PATH "libvulkan.so" @@ -128,8 +129,15 @@ ShellTestPlatformViewVulkan::OffScreenSurface::OffScreenSurface( bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() { GrVkBackendContext backend_context; + skgpu::VulkanExtensions no_extensions; + // For now, Skia crashes if fDeviceFeatures is set but fVkExtensions is not. + backend_context.fVkExtensions = &no_extensions; + VkPhysicalDeviceFeatures features; + // It may be tempting to put features into backend_context here + // and pass just backend_context into the below function, however the pointers + // for features are const, so we won't be able to update them. - if (!CreateSkiaBackendContext(&backend_context)) { + if (!this->CreateSkiaBackendContext(&backend_context, &features)) { FML_DLOG(ERROR) << "Could not create Skia backend context."; return false; } @@ -153,7 +161,10 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() { } bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext( - GrVkBackendContext* context) { + GrVkBackendContext* context, + VkPhysicalDeviceFeatures* features) { + FML_CHECK(context); + FML_CHECK(features); auto getProc = CreateSkiaGetProc(vk_); if (getProc == nullptr) { @@ -161,8 +172,7 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext( return false; } - uint32_t skia_features = 0; - if (!logical_device_->GetPhysicalDeviceFeaturesSkia(&skia_features)) { + if (!logical_device_->GetPhysicalDeviceFeatures(features)) { FML_DLOG(ERROR) << "Failed to get Physical Device features"; return false; } @@ -172,11 +182,9 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext( context->fDevice = logical_device_->GetHandle(); context->fQueue = logical_device_->GetQueueHandle(); context->fGraphicsQueueIndex = logical_device_->GetGraphicsQueueIndex(); - context->fMinAPIVersion = application_->GetAPIVersion(); context->fMaxAPIVersion = application_->GetAPIVersion(); - context->fFeatures = skia_features; + context->fDeviceFeatures = features; context->fGetProc = std::move(getProc); - context->fOwnsInstanceAndDevice = false; context->fMemoryAllocator = memory_allocator_; return true; diff --git a/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.h b/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.h index 6631b10b64..02ef50d36d 100644 --- a/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.h +++ b/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.h @@ -60,7 +60,8 @@ class ShellTestPlatformViewVulkan : public ShellTestPlatformView { sk_sp context_; bool CreateSkiaGrContext(); - bool CreateSkiaBackendContext(GrVkBackendContext* context); + bool CreateSkiaBackendContext(GrVkBackendContext*, + VkPhysicalDeviceFeatures*); FML_DISALLOW_COPY_AND_ASSIGN(OffScreenSurface); }; diff --git a/engine/src/flutter/shell/platform/embedder/embedder_surface_vulkan.cc b/engine/src/flutter/shell/platform/embedder/embedder_surface_vulkan.cc index 1ab4ca9294..39ef90a83c 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder_surface_vulkan.cc @@ -13,7 +13,7 @@ #include "flutter/vulkan/vulkan_skia_proc_table.h" #include "include/gpu/GrDirectContext.h" #include "include/gpu/vk/GrVkBackendContext.h" -#include "include/gpu/vk/GrVkExtensions.h" +#include "include/gpu/vk/VulkanExtensions.h" #include "third_party/skia/include/gpu/ganesh/vk/GrVkDirectContext.h" namespace flutter { @@ -128,8 +128,8 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( size_t device_extension_count, const char** device_extensions, ContextType context_type) const { - uint32_t skia_features = 0; - if (!device_.GetPhysicalDeviceFeaturesSkia(&skia_features)) { + VkPhysicalDeviceFeatures features; + if (!device_.GetPhysicalDeviceFeatures(&features)) { FML_LOG(ERROR) << "Failed to get physical device features."; return nullptr; @@ -141,7 +141,7 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( return nullptr; } - GrVkExtensions extensions; + skgpu::VulkanExtensions extensions; GrVkBackendContext backend_context = {}; backend_context.fInstance = instance; @@ -149,12 +149,10 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( backend_context.fDevice = device_.GetHandle(); backend_context.fQueue = device_.GetQueueHandle(); backend_context.fGraphicsQueueIndex = device_.GetGraphicsQueueIndex(); - backend_context.fMinAPIVersion = version; backend_context.fMaxAPIVersion = version; - backend_context.fFeatures = skia_features; + backend_context.fDeviceFeatures = &features; backend_context.fVkExtensions = &extensions; backend_context.fGetProc = get_proc; - backend_context.fOwnsInstanceAndDevice = false; uint32_t vulkan_api_version = version; sk_sp allocator = diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc index 66e925f605..8cda71c15b 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc @@ -20,6 +20,7 @@ #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" #include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSurface.h" +#include "third_party/skia/include/gpu/vk/VulkanTypes.h" #include "vulkan/vulkan_core.h" #include "vulkan/vulkan_fuchsia.h" @@ -394,7 +395,7 @@ bool VulkanSurface::SetupSkiaSurface(sk_sp context, const VkMemoryRequirements& memory_reqs) { FML_CHECK(context != nullptr); - GrVkAlloc alloc; + skgpu::VulkanAlloc alloc; alloc.fMemory = vk_memory_; alloc.fOffset = 0; alloc.fSize = memory_reqs.size; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc index 538827ef76..17cc7e0adf 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc @@ -22,8 +22,8 @@ #include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSurface.h" #include "third_party/skia/include/gpu/ganesh/vk/GrVkDirectContext.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" -#include "third_party/skia/include/gpu/vk/GrVkExtensions.h" #include "third_party/skia/include/gpu/vk/GrVkTypes.h" +#include "third_party/skia/include/gpu/vk/VulkanExtensions.h" namespace flutter_runner { @@ -112,8 +112,8 @@ bool VulkanSurfaceProducer::Initialize() { return false; } - uint32_t skia_features = 0; - if (!logical_device_->GetPhysicalDeviceFeaturesSkia(&skia_features)) { + VkPhysicalDeviceFeatures features; + if (!logical_device_->GetPhysicalDeviceFeatures(&features)) { FML_LOG(ERROR) << "VulkanSurfaceProducer: Failed to get physical device features."; @@ -132,11 +132,9 @@ bool VulkanSurfaceProducer::Initialize() { backend_context.fQueue = logical_device_->GetQueueHandle(); backend_context.fGraphicsQueueIndex = logical_device_->GetGraphicsQueueIndex(); - backend_context.fMinAPIVersion = application_->GetAPIVersion(); backend_context.fMaxAPIVersion = application_->GetAPIVersion(); - backend_context.fFeatures = skia_features; + backend_context.fDeviceFeatures = &features; backend_context.fGetProc = std::move(getProc); - backend_context.fOwnsInstanceAndDevice = false; backend_context.fMemoryAllocator = memory_allocator_; // The memory_requirements_2 extension is required on Fuchsia as the AMD @@ -146,7 +144,7 @@ bool VulkanSurfaceProducer::Initialize() { }; const int device_extensions_count = sizeof(device_extensions) / sizeof(device_extensions[0]); - GrVkExtensions vk_extensions; + skgpu::VulkanExtensions vk_extensions; vk_extensions.init(backend_context.fGetProc, backend_context.fInstance, backend_context.fPhysicalDevice, 0, nullptr, device_extensions_count, device_extensions); diff --git a/engine/src/flutter/testing/test_vulkan_context.cc b/engine/src/flutter/testing/test_vulkan_context.cc index d7472303f1..726e550f95 100644 --- a/engine/src/flutter/testing/test_vulkan_context.cc +++ b/engine/src/flutter/testing/test_vulkan_context.cc @@ -18,7 +18,7 @@ #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/vk/GrVkDirectContext.h" -#include "third_party/skia/include/gpu/vk/GrVkExtensions.h" +#include "third_party/skia/include/gpu/vk/VulkanExtensions.h" #include "vulkan/vulkan_core.h" namespace flutter { @@ -70,8 +70,8 @@ TestVulkanContext::TestVulkanContext() { // For creating SkSurfaces from VkImages and snapshotting them, etc. // --------------------------------------------------------------------------- - uint32_t skia_features = 0; - if (!device_->GetPhysicalDeviceFeaturesSkia(&skia_features)) { + VkPhysicalDeviceFeatures features; + if (!device_->GetPhysicalDeviceFeatures(&features)) { FML_LOG(ERROR) << "Failed to get physical device features."; return; @@ -88,7 +88,7 @@ TestVulkanContext::TestVulkanContext() { VK_MAKE_VERSION(1, 0, 0), application_->GetInstance(), device_->GetPhysicalDeviceHandle(), device_->GetHandle(), vk_, true); - GrVkExtensions extensions; + skgpu::VulkanExtensions extensions; GrVkBackendContext backend_context = {}; backend_context.fInstance = application_->GetInstance(); @@ -96,12 +96,10 @@ TestVulkanContext::TestVulkanContext() { backend_context.fDevice = device_->GetHandle(); backend_context.fQueue = device_->GetQueueHandle(); backend_context.fGraphicsQueueIndex = device_->GetGraphicsQueueIndex(); - backend_context.fMinAPIVersion = VK_MAKE_VERSION(1, 0, 0); backend_context.fMaxAPIVersion = VK_MAKE_VERSION(1, 0, 0); - backend_context.fFeatures = skia_features; + backend_context.fDeviceFeatures = &features; backend_context.fVkExtensions = &extensions; backend_context.fGetProc = get_proc; - backend_context.fOwnsInstanceAndDevice = false; backend_context.fMemoryAllocator = allocator; GrContextOptions options = diff --git a/engine/src/flutter/vulkan/vulkan_device.cc b/engine/src/flutter/vulkan/vulkan_device.cc index e5b0fea59e..6a92071e32 100644 --- a/engine/src/flutter/vulkan/vulkan_device.cc +++ b/engine/src/flutter/vulkan/vulkan_device.cc @@ -258,33 +258,6 @@ bool VulkanDevice::GetPhysicalDeviceFeatures( return true; } -bool VulkanDevice::GetPhysicalDeviceFeaturesSkia(uint32_t* sk_features) const { - if (sk_features == nullptr) { - return false; - } - - VkPhysicalDeviceFeatures features; - - if (!GetPhysicalDeviceFeatures(&features)) { - return false; - } - - uint32_t flags = 0; - - if (features.geometryShader) { - flags |= kGeometryShader_GrVkFeatureFlag; - } - if (features.dualSrcBlend) { - flags |= kDualSrcBlend_GrVkFeatureFlag; - } - if (features.sampleRateShading) { - flags |= kSampleRateShading_GrVkFeatureFlag; - } - - *sk_features = flags; - return true; -} - std::vector VulkanDevice::GetQueueFamilyProperties() const { uint32_t count = 0; diff --git a/engine/src/flutter/vulkan/vulkan_device.h b/engine/src/flutter/vulkan/vulkan_device.h index 275a462e33..18065a05bc 100644 --- a/engine/src/flutter/vulkan/vulkan_device.h +++ b/engine/src/flutter/vulkan/vulkan_device.h @@ -55,9 +55,6 @@ class VulkanDevice { [[nodiscard]] bool GetPhysicalDeviceFeatures( VkPhysicalDeviceFeatures* features) const; - [[nodiscard]] bool GetPhysicalDeviceFeaturesSkia( - uint32_t* /* mask of GrVkFeatureFlags */ features) const; - [[nodiscard]] int ChooseSurfaceFormat( const VulkanSurface& surface, const std::vector& desired_formats, diff --git a/engine/src/flutter/vulkan/vulkan_native_surface.h b/engine/src/flutter/vulkan/vulkan_native_surface.h index 33884c6112..9701a0c083 100644 --- a/engine/src/flutter/vulkan/vulkan_native_surface.h +++ b/engine/src/flutter/vulkan/vulkan_native_surface.h @@ -18,8 +18,6 @@ class VulkanNativeSurface { virtual const char* GetExtensionName() const = 0; - virtual uint32_t GetSkiaExtensionName() const = 0; - virtual VkSurfaceKHR CreateSurfaceHandle( VulkanProcTable& vk, const VulkanHandle& instance) const = 0; diff --git a/engine/src/flutter/vulkan/vulkan_native_surface_android.cc b/engine/src/flutter/vulkan/vulkan_native_surface_android.cc index 3fa534da5c..6f27b6eb19 100644 --- a/engine/src/flutter/vulkan/vulkan_native_surface_android.cc +++ b/engine/src/flutter/vulkan/vulkan_native_surface_android.cc @@ -27,13 +27,10 @@ VulkanNativeSurfaceAndroid::~VulkanNativeSurfaceAndroid() { } const char* VulkanNativeSurfaceAndroid::GetExtensionName() const { + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_android_surface.html return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME; } -uint32_t VulkanNativeSurfaceAndroid::GetSkiaExtensionName() const { - return kKHR_android_surface_GrVkExtensionFlag; -} - VkSurfaceKHR VulkanNativeSurfaceAndroid::CreateSurfaceHandle( VulkanProcTable& vk, const VulkanHandle& instance) const { diff --git a/engine/src/flutter/vulkan/vulkan_native_surface_android.h b/engine/src/flutter/vulkan/vulkan_native_surface_android.h index 2a4eec03f6..1ac00f0c9f 100644 --- a/engine/src/flutter/vulkan/vulkan_native_surface_android.h +++ b/engine/src/flutter/vulkan/vulkan_native_surface_android.h @@ -23,8 +23,6 @@ class VulkanNativeSurfaceAndroid : public VulkanNativeSurface { const char* GetExtensionName() const override; - uint32_t GetSkiaExtensionName() const override; - VkSurfaceKHR CreateSurfaceHandle( VulkanProcTable& vk, const VulkanHandle& instance) const override; diff --git a/engine/src/flutter/vulkan/vulkan_window.cc b/engine/src/flutter/vulkan/vulkan_window.cc index c0ab63eb00..1227b1d5f8 100644 --- a/engine/src/flutter/vulkan/vulkan_window.cc +++ b/engine/src/flutter/vulkan/vulkan_window.cc @@ -21,6 +21,7 @@ #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/vk/GrVkDirectContext.h" +#include "third_party/skia/include/gpu/vk/VulkanExtensions.h" namespace vulkan { @@ -120,10 +121,13 @@ GrDirectContext* VulkanWindow::GetSkiaGrContext() { } bool VulkanWindow::CreateSkiaGrContext() { -#ifdef SK_VUKLAN +#ifdef SK_VULKAN GrVkBackendContext backend_context; + VkPhysicalDeviceFeatures features; + skgpu::VulkanExtensions extensions; - if (!CreateSkiaBackendContext(&backend_context)) { + if (!this->CreateSkiaBackendContext(&backend_context, &features, + &extensions)) { return false; } @@ -146,15 +150,21 @@ bool VulkanWindow::CreateSkiaGrContext() { #endif // SK_VULKAN } -bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) { +bool VulkanWindow::CreateSkiaBackendContext( + GrVkBackendContext* context, + VkPhysicalDeviceFeatures* features, + skgpu::VulkanExtensions* extensions) { +#ifdef SK_VULKAN + FML_CHECK(context); + FML_CHECK(features); + FML_CHECK(extensions); auto getProc = CreateSkiaGetProc(vk_); if (getProc == nullptr) { return false; } - uint32_t skia_features = 0; - if (!logical_device_->GetPhysicalDeviceFeaturesSkia(&skia_features)) { + if (!logical_device_->GetPhysicalDeviceFeatures(features)) { return false; } @@ -163,15 +173,31 @@ bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) { context->fDevice = logical_device_->GetHandle(); context->fQueue = logical_device_->GetQueueHandle(); context->fGraphicsQueueIndex = logical_device_->GetGraphicsQueueIndex(); - context->fMinAPIVersion = application_->GetAPIVersion(); - context->fExtensions = kKHR_surface_GrVkExtensionFlag | - kKHR_swapchain_GrVkExtensionFlag | - surface_->GetNativeSurface().GetSkiaExtensionName(); - context->fFeatures = skia_features; + context->fMaxAPIVersion = application_->GetAPIVersion(); + context->fDeviceFeatures = features; context->fGetProc = std::move(getProc); - context->fOwnsInstanceAndDevice = false; context->fMemoryAllocator = memory_allocator_; + + constexpr uint32_t instance_extension_count = 2; + const char* instance_extensions[instance_extension_count] = { + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html + VK_KHR_SURFACE_EXTENSION_NAME, + surface_->GetNativeSurface().GetExtensionName(), + }; + constexpr uint32_t device_extension_count = 1; + const char* device_extensions[device_extension_count] = { + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_swapchain.html + VK_KHR_SWAPCHAIN_EXTENSION_NAME, + }; + extensions->init(context->fGetProc, context->fInstance, + context->fPhysicalDevice, instance_extension_count, + instance_extensions, device_extension_count, + device_extensions); + context->fVkExtensions = extensions; return true; +#else + return false; +#endif } sk_sp VulkanWindow::AcquireSurface() { diff --git a/engine/src/flutter/vulkan/vulkan_window.h b/engine/src/flutter/vulkan/vulkan_window.h index 55d885d15d..22bf1ccc54 100644 --- a/engine/src/flutter/vulkan/vulkan_window.h +++ b/engine/src/flutter/vulkan/vulkan_window.h @@ -68,7 +68,9 @@ class VulkanWindow { bool CreateSkiaGrContext(); - bool CreateSkiaBackendContext(GrVkBackendContext* context); + bool CreateSkiaBackendContext(GrVkBackendContext*, + VkPhysicalDeviceFeatures*, + skgpu::VulkanExtensions*); [[nodiscard]] bool RecreateSwapchain();