Flutter Impeller
impeller::PlaygroundImplVK Class Referencefinal

#include <playground_impl_vk.h>

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

Public Member Functions

 PlaygroundImplVK (PlaygroundSwitches switches)
 
 ~PlaygroundImplVK ()
 
- Public Member Functions inherited from impeller::PlaygroundImpl
virtual ~PlaygroundImpl ()
 
Vector2 GetContentScale () const
 

Additional Inherited Members

- Public Types inherited from impeller::PlaygroundImpl
using WindowHandle = void *
 
- Static Public Member Functions inherited from impeller::PlaygroundImpl
static std::unique_ptr< PlaygroundImplCreate (PlaygroundBackend backend, PlaygroundSwitches switches)
 
- 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 55 of file playground_impl_vk.cc.

56  : PlaygroundImpl(switches), handle_(nullptr, &DestroyWindowHandle) {
57  if (!::glfwVulkanSupported()) {
58 #ifdef TARGET_OS_MAC
59  VALIDATION_LOG << "Attempted to initialize a Vulkan playground on macOS "
60  "where Vulkan cannot be found. It can be installed via "
61  "MoltenVK and make sure to install it globally so "
62  "dlopen can find it.";
63 #else
64  VALIDATION_LOG << "Attempted to initialize a Vulkan playground on a system "
65  "that does not support Vulkan.";
66 #endif
67  return;
68  }
69 
70  ::glfwDefaultWindowHints();
71  ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
72  ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
73 
74  auto window = ::glfwCreateWindow(1, 1, "Test", nullptr, nullptr);
75  if (!window) {
76  VALIDATION_LOG << "Unable to create glfw window";
77  return;
78  }
79 
80  handle_.reset(window);
81 
82  ContextVK::Settings context_settings;
83  context_settings.proc_address_callback =
84  reinterpret_cast<PFN_vkGetInstanceProcAddr>(
85  &::glfwGetInstanceProcAddress);
86  context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground();
87  context_settings.cache_directory = fml::paths::GetCachesDirectory();
88  context_settings.enable_validation = switches_.enable_vulkan_validation;
89 
90  auto context_vk = ContextVK::Create(std::move(context_settings));
91  if (!context_vk || !context_vk->IsValid()) {
92  VALIDATION_LOG << "Could not create Vulkan context in the playground.";
93  return;
94  }
95 
96  // Without this, the playground will timeout waiting for the presentation.
97  // It's better to have some Vulkan validation tests running on CI to catch
98  // regressions, but for now this is a workaround.
99  //
100  // TODO(matanlurey): https://github.com/flutter/flutter/issues/134852.
101  //
102  // (Note, if you're using MoltenVK, or Linux, you can comment out this line).
103  context_vk->SetSyncPresentation(true);
104 
105  VkSurfaceKHR vk_surface;
106  auto res = vk::Result{::glfwCreateWindowSurface(
107  context_vk->GetInstance(), // instance
108  window, // window
109  nullptr, // allocator
110  &vk_surface // surface
111  )};
112  if (res != vk::Result::eSuccess) {
113  VALIDATION_LOG << "Could not create surface for GLFW window: "
114  << vk::to_string(res);
115  return;
116  }
117 
118  vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
119  auto context = context_vk->CreateSurfaceContext();
120  if (!context->SetWindowSurface(std::move(surface))) {
121  VALIDATION_LOG << "Could not set up surface for context.";
122  return;
123  }
124 
125  context_ = std::move(context);
126 }

References impeller::ContextVK::Settings::cache_directory, impeller::ContextVK::Create(), impeller::ContextVK::Settings::enable_validation, impeller::PlaygroundSwitches::enable_vulkan_validation, impeller::ContextVK::Settings::proc_address_callback, impeller::ContextVK::Settings::shader_libraries_data, impeller::ShaderLibraryMappingsForPlayground(), impeller::PlaygroundImpl::switches_, and VALIDATION_LOG.

◆ ~PlaygroundImplVK()

impeller::PlaygroundImplVK::~PlaygroundImplVK ( )
default

The documentation for this class was generated from the following files:
impeller::ShaderLibraryMappingsForPlayground
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
Definition: playground_impl_gles.cc:89
impeller::ContextVK::Create
static std::shared_ptr< ContextVK > Create(Settings settings)
Definition: context_vk.cc:92
impeller::PlaygroundImpl::switches_
const PlaygroundSwitches switches_
Definition: playground_impl.h:36
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::PlaygroundSwitches::enable_vulkan_validation
bool enable_vulkan_validation
Definition: switches.h:21
impeller::PlaygroundImpl::PlaygroundImpl
PlaygroundImpl(PlaygroundSwitches switches)
Definition: playground_impl.cc:48