26 {
27
28
29
30
32
33
34
36 FML_LOG(ERROR) <<
"Couldn't find Vulkan ICD \"" << vulkan_icd
37 << "\", trying \"libvulkan.so\" instead.";
38 vulkan_icd = "libvulkan.so";
39 }
40
41 FML_LOG(INFO) <<
"Using Vulkan ICD: " << vulkan_icd;
42
43 vk_ = fml::MakeRefCounted<vulkan::VulkanProcTable>(vulkan_icd);
45 FML_LOG(ERROR) <<
"Proc table has not acquired mandatory proc addresses.";
46 return;
47 }
48
49 application_ = std::make_unique<vulkan::VulkanApplication>(
50 *vk_, "Flutter Unittests", std::vector<std::string>{},
51 VK_MAKE_VERSION(1, 0, 0), VK_MAKE_VERSION(1, 1, 0), true);
52 if (!application_->IsValid()) {
53 FML_LOG(ERROR) <<
"Failed to initialize basic Vulkan state.";
54 return;
55 }
57 FML_LOG(ERROR) <<
"Failed to acquire full proc table.";
58 return;
59 }
60
61 device_ = application_->AcquireFirstCompatibleLogicalDevice();
62 if (!device_ || !device_->IsValid()) {
63 FML_LOG(ERROR) <<
"Failed to create compatible logical device.";
64 return;
65 }
66
67
68
69
70
71
72 VkPhysicalDeviceFeatures features;
73 if (!device_->GetPhysicalDeviceFeatures(&features)) {
74 FML_LOG(ERROR) <<
"Failed to get physical device features.";
75
76 return;
77 }
78
80 if (get_proc == nullptr) {
81 FML_LOG(ERROR) <<
"Failed to create Vulkan getProc for Skia.";
82 return;
83 }
84
85 sk_sp<skgpu::VulkanMemoryAllocator>
allocator =
87 VK_MAKE_VERSION(1, 1, 0), application_->GetInstance(),
88 device_->GetPhysicalDeviceHandle(), device_->GetHandle(), vk_, true);
89
90 skgpu::VulkanExtensions extensions;
91
92 skgpu::VulkanBackendContext backend_context = {};
93 backend_context.fInstance = application_->GetInstance();
94 backend_context.fPhysicalDevice = device_->GetPhysicalDeviceHandle();
95 backend_context.fDevice = device_->GetHandle();
96 backend_context.fQueue = device_->GetQueueHandle();
97 backend_context.fGraphicsQueueIndex = device_->GetGraphicsQueueIndex();
98 backend_context.fMaxAPIVersion = VK_MAKE_VERSION(1, 1, 0);
99 backend_context.fDeviceFeatures = &features;
100 backend_context.fVkExtensions = &extensions;
101 backend_context.fGetProc = get_proc;
102 backend_context.fMemoryAllocator =
allocator;
103
104 GrContextOptions options =
106 options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
107 context_ = GrDirectContexts::MakeVulkan(backend_context, options);
108}
static sk_sp< VulkanMemoryAllocator > Make(uint32_t vulkan_api_version, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, const fml::RefPtr< vulkan::VulkanProcTable > &vk, bool mustUseCoherentHostVisibleMemory)
static fml::RefPtr< NativeLibrary > Create(const char *path)
bool HasAcquiredMandatoryProcAddresses() const
bool AreInstanceProcsSetup() const
#define FML_LOG(severity)
std::shared_ptr< ImpellerAllocator > allocator
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
@ kRender
The context is used to render to a texture or renderbuffer.
skgpu::VulkanGetProc CreateSkiaGetProc(const fml::RefPtr< vulkan::VulkanProcTable > &vk)