Flutter Engine
 
Loading...
Searching...
No Matches
impeller::PlaygroundImplVK Class Referencefinal

#include <playground_impl_vk.h>

Inheritance diagram for impeller::PlaygroundImplVK:
impeller::PlaygroundImpl

Public Member Functions

 PlaygroundImplVK (PlaygroundSwitches switches)
 
 ~PlaygroundImplVK ()
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities) override
 
- Public Member Functions inherited from impeller::PlaygroundImpl
virtual ~PlaygroundImpl ()
 
Vector2 GetContentScale () const
 
virtual Playground::GLProcAddressResolver CreateGLProcAddressResolver () const
 
virtual void SetGPUDisabled (bool disabled) const
 

Static Public Member Functions

static bool IsVulkanDriverPresent ()
 
- Static Public Member Functions inherited from impeller::PlaygroundImpl
static std::unique_ptr< PlaygroundImplCreate (PlaygroundBackend backend, PlaygroundSwitches switches)
 

Additional Inherited Members

- Public Types inherited from impeller::PlaygroundImpl
using WindowHandle = void *
 
- Protected Member Functions inherited from impeller::PlaygroundImpl
 PlaygroundImpl (PlaygroundSwitches switches)
 
- Protected Attributes inherited from impeller::PlaygroundImpl
const PlaygroundSwitches switches_
 

Detailed Description

Definition at line 13 of file playground_impl_vk.h.

Constructor & Destructor Documentation

◆ PlaygroundImplVK()

impeller::PlaygroundImplVK::PlaygroundImplVK ( PlaygroundSwitches  switches)
explicit

Definition at line 66 of file playground_impl_vk.cc.

67 : PlaygroundImpl(switches), handle_(nullptr, &DestroyWindowHandle) {
69
70 InitGlobalVulkanInstance();
71
72 ::glfwDefaultWindowHints();
73 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
74 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
75
76 auto window = ::glfwCreateWindow(1, 1, "Test", nullptr, nullptr);
77 if (!window) {
78 VALIDATION_LOG << "Unable to create glfw window";
79 return;
80 }
81
82 int width = 0;
83 int height = 0;
84 ::glfwGetWindowSize(window, &width, &height);
85 size_ = ISize{width, height};
86
87 handle_.reset(window);
88
89 ContextVK::Settings context_settings;
90 context_settings.proc_address_callback =
91 reinterpret_cast<PFN_vkGetInstanceProcAddr>(
92 &::glfwGetInstanceProcAddress);
93 context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground();
94 context_settings.cache_directory = fml::paths::GetCachesDirectory();
95 context_settings.enable_validation = switches_.enable_vulkan_validation;
96 context_settings.fatal_missing_validations =
98 context_settings.flags = switches_.flags;
99
100 auto context_vk = ContextVK::Create(std::move(context_settings));
101 if (!context_vk || !context_vk->IsValid()) {
102 VALIDATION_LOG << "Could not create Vulkan context in the playground.";
103 return;
104 }
105
106 VkSurfaceKHR vk_surface;
107 auto res = vk::Result{::glfwCreateWindowSurface(
108 context_vk->GetInstance(), // instance
109 window, // window
110 nullptr, // allocator
111 &vk_surface // surface
112 )};
113 if (res != vk::Result::eSuccess) {
114 VALIDATION_LOG << "Could not create surface for GLFW window: "
115 << vk::to_string(res);
116 return;
117 }
118
119 vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
120 auto context = context_vk->CreateSurfaceContext();
121 if (!context->SetWindowSurface(std::move(surface), size_)) {
122 VALIDATION_LOG << "Could not set up surface for context.";
123 return;
124 }
125
126 context_ = std::move(context);
127}
static std::shared_ptr< ContextVK > Create(Settings settings)
PlaygroundImpl(PlaygroundSwitches switches)
const PlaygroundSwitches switches_
GLFWwindow * window
Definition main.cc:60
VkSurfaceKHR surface
Definition main.cc:65
#define GLFW_FALSE
#define FML_CHECK(condition)
Definition logging.h:104
fml::UniqueFD GetCachesDirectory()
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
ISize64 ISize
Definition size.h:162
int32_t height
int32_t width
#define VALIDATION_LOG
Definition validation.h:91

References impeller::ContextVK::Settings::cache_directory, impeller::ContextVK::Create(), impeller::ContextVK::Settings::enable_validation, impeller::PlaygroundSwitches::enable_vulkan_validation, impeller::ContextVK::Settings::fatal_missing_validations, impeller::PlaygroundSwitches::flags, impeller::ContextVK::Settings::flags, FML_CHECK, fml::paths::GetCachesDirectory(), GLFW_FALSE, height, IsVulkanDriverPresent(), impeller::ContextVK::Settings::proc_address_callback, impeller::ContextVK::Settings::shader_libraries_data, impeller::ShaderLibraryMappingsForPlayground(), surface, impeller::PlaygroundImpl::switches_, VALIDATION_LOG, width, and window.

◆ ~PlaygroundImplVK()

impeller::PlaygroundImplVK::~PlaygroundImplVK ( )
default

Member Function Documentation

◆ IsVulkanDriverPresent()

bool impeller::PlaygroundImplVK::IsVulkanDriverPresent ( )
static

Definition at line 224 of file playground_impl_vk.cc.

224 {
225 if (::glfwVulkanSupported()) {
226 return true;
227 }
228#ifdef TARGET_OS_MAC
229 FML_LOG(ERROR) << "Attempting to initialize a Vulkan playground on macOS "
230 "where Vulkan cannot be found. It can be installed via "
231 "MoltenVK and make sure to install it globally so "
232 "dlopen can find it.";
233#else // TARGET_OS_MAC
234 FML_LOG(ERROR) << "Attempting to initialize a Vulkan playground on a system "
235 "that does not support Vulkan.";
236#endif // TARGET_OS_MAC
237 return false;
238}
#define FML_LOG(severity)
Definition logging.h:101

References FML_LOG.

Referenced by impeller::PlaygroundImpl::Create(), PlaygroundImplVK(), and impeller::Playground::SupportsBackend().

◆ SetCapabilities()

fml::Status impeller::PlaygroundImplVK::SetCapabilities ( const std::shared_ptr< Capabilities > &  capabilities)
overridevirtual

Implements impeller::PlaygroundImpl.

Definition at line 217 of file playground_impl_vk.cc.

218 {
219 return fml::Status(
221 "PlaygroundImplVK doesn't support setting the capabilities.");
222}

References fml::kUnimplemented.


The documentation for this class was generated from the following files: