Flutter Engine
 
Loading...
Searching...
No Matches
context_vk.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include "flutter/fml/paths.h"
8#include "impeller/entity/vk/entity_shaders_vk.h"
9#include "impeller/entity/vk/framebuffer_blend_shaders_vk.h"
10#include "impeller/entity/vk/modern_shaders_vk.h"
12#include "impeller/renderer/vk/compute_shaders_vk.h"
13
14namespace impeller::interop {
15
16static std::vector<std::shared_ptr<fml::Mapping>>
18 return {
19 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
20 impeller_entity_shaders_vk_length),
21 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
22 impeller_modern_shaders_vk_length),
23 std::make_shared<fml::NonOwnedMapping>(
24 impeller_framebuffer_blend_shaders_vk_data,
25 impeller_framebuffer_blend_shaders_vk_length),
26 std::make_shared<fml::NonOwnedMapping>(
27 impeller_compute_shaders_vk_data, impeller_compute_shaders_vk_length),
28 };
29}
30// This bit is complicated by the fact that impeller::ContextVK::Settings takes
31// a raw function pointer to the callback.
32thread_local std::function<PFN_vkVoidFunction(VkInstance instance,
33 const char* proc_name)>
35
36VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
37ContextVKGetInstanceProcAddress(VkInstance instance, const char* proc_name) {
39 return sContextVKProcAddressCallback(instance, proc_name);
40 }
41 return nullptr;
42}
43
45 if (!settings.IsValid()) {
46 VALIDATION_LOG << "Invalid settings for Vulkan context creation.";
47 return {};
48 }
49 impeller::ContextVK::Settings impeller_settings;
52 impeller_settings.enable_validation = true;
55 impeller_settings.flags = impeller::Flags{};
56 auto impeller_context =
57 impeller::ContextVK::Create(std::move(impeller_settings));
59 if (!impeller_context) {
60 VALIDATION_LOG << "Could not create Impeller context.";
61 return {};
62 }
63 return Create(std::move(impeller_context));
64}
65
67 std::shared_ptr<impeller::Context> impeller_context) {
68 // Can't call Create because of private constructor. Adopt the raw pointer
69 // instead.
70 auto context = Adopt<Context>(new ContextVK(std::move(impeller_context)));
71 if (!context->IsValid()) {
72 VALIDATION_LOG << " Could not create valid context.";
73 return {};
74 }
75 return context;
76}
77
78ContextVK::ContextVK(std::shared_ptr<impeller::Context> context)
79 : Context(std::move(context)) {}
80
81ContextVK::~ContextVK() = default;
82
84 : enable_validation(settings.enable_vulkan_validation) {
86 [&settings](VkInstance instance,
87 const char* proc_name) -> PFN_vkVoidFunction {
88 if (settings.proc_address_callback) {
89 return reinterpret_cast<PFN_vkVoidFunction>(
90 settings.proc_address_callback(instance, proc_name,
91 settings.user_data));
92 }
93 return nullptr;
94 };
95}
96
98 if (!IsValid()) {
99 return false;
100 }
101 const auto& context = impeller::ContextVK::Cast(*GetContext());
102 // NOLINTBEGIN(google-readability-casting)
103 info.vk_instance = reinterpret_cast<void*>(VkInstance(context.GetInstance()));
104 info.vk_physical_device =
105 reinterpret_cast<void*>(VkPhysicalDevice(context.GetPhysicalDevice()));
106 info.vk_logical_device =
107 reinterpret_cast<void*>(VkDevice(context.GetDevice()));
108 // NOLINTEND(google-readability-casting)
110 context.GetGraphicsQueue()->GetIndex().family;
111 info.graphics_queue_index = context.GetGraphicsQueue()->GetIndex().index;
112 return true;
113}
114
116 return !!instance_proc_address_callback;
117}
118
119} // namespace impeller::interop
static ContextVK & Cast(Context &base)
static std::shared_ptr< ContextVK > Create(Settings settings)
std::shared_ptr< impeller::Context > GetContext() const
Definition context.cc:20
ContextVK(const ContextVK &)=delete
bool GetInfo(ImpellerContextVulkanInfo &info) const
Definition context_vk.cc:97
static ScopedObject< Context > Create(const Settings &settings)
Definition context_vk.cc:44
VkInstance instance
Definition main.cc:64
fml::UniqueFD GetCachesDirectory()
thread_local std::function< PFN_vkVoidFunction(VkInstance instance, const char *proc_name)> sContextVKProcAddressCallback
Definition context_vk.cc:34
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL ContextVKGetInstanceProcAddress(VkInstance instance, const char *proc_name)
Definition context_vk.cc:37
static std::vector< std::shared_ptr< fml::Mapping > > CreateShaderLibraryMappings()
Definition ref_ptr.h:261
uint32_t graphics_queue_family_index
Definition impeller.h:642
void *IMPELLER_NULLABLE vk_instance
Definition impeller.h:639
void *IMPELLER_NULLABLE vk_logical_device
Definition impeller.h:641
void *IMPELLER_NULLABLE vk_physical_device
Definition impeller.h:640
ImpellerVulkanProcAddressCallback IMPELLER_NONNULL proc_address_callback
Definition impeller.h:634
void *IMPELLER_NULLABLE user_data
Definition impeller.h:633
std::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
Definition context_vk.h:81
PFN_vkGetInstanceProcAddr proc_address_callback
Definition context_vk.h:80
std::function< PFN_vkVoidFunction(VkInstance instance, const char *proc_name)> instance_proc_address_callback
Definition context_vk.h:19
#define VALIDATION_LOG
Definition validation.h:91