7 #include "flutter/fml/paths.h"
10 #define GLFW_INCLUDE_VULKAN
11 #include <GLFW/glfw3.h>
13 #include "flutter/fml/logging.h"
14 #include "flutter/fml/mapping.h"
15 #include "impeller/entity/vk/entity_shaders_vk.h"
16 #include "impeller/entity/vk/framebuffer_blend_shaders_vk.h"
17 #include "impeller/entity/vk/modern_shaders_vk.h"
18 #include "impeller/fixtures/vk/fixtures_shaders_vk.h"
19 #include "impeller/playground/imgui/vk/imgui_shaders_vk.h"
25 #include "impeller/renderer/vk/compute_shaders_vk.h"
26 #include "impeller/scene/shaders/vk/scene_shaders_vk.h"
30 static std::vector<std::shared_ptr<fml::Mapping>>
33 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
34 impeller_entity_shaders_vk_length),
35 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
36 impeller_modern_shaders_vk_length),
37 std::make_shared<fml::NonOwnedMapping>(
38 impeller_framebuffer_blend_shaders_vk_data,
39 impeller_framebuffer_blend_shaders_vk_length),
40 std::make_shared<fml::NonOwnedMapping>(
41 impeller_fixtures_shaders_vk_data,
42 impeller_fixtures_shaders_vk_length),
43 std::make_shared<fml::NonOwnedMapping>(impeller_imgui_shaders_vk_data,
44 impeller_imgui_shaders_vk_length),
45 std::make_shared<fml::NonOwnedMapping>(impeller_scene_shaders_vk_data,
46 impeller_scene_shaders_vk_length),
47 std::make_shared<fml::NonOwnedMapping>(
48 impeller_compute_shaders_vk_data, impeller_compute_shaders_vk_length),
52 vk::UniqueInstance PlaygroundImplVK::global_instance_;
54 void PlaygroundImplVK::DestroyWindowHandle(WindowHandle handle) {
58 ::glfwDestroyWindow(
reinterpret_cast<GLFWwindow*
>(handle));
62 :
PlaygroundImpl(switches), handle_(nullptr, &DestroyWindowHandle) {
63 if (!::glfwVulkanSupported()) {
65 VALIDATION_LOG <<
"Attempted to initialize a Vulkan playground on macOS "
66 "where Vulkan cannot be found. It can be installed via "
67 "MoltenVK and make sure to install it globally so "
68 "dlopen can find it.";
70 VALIDATION_LOG <<
"Attempted to initialize a Vulkan playground on a system "
71 "that does not support Vulkan.";
76 InitGlobalVulkanInstance();
78 ::glfwDefaultWindowHints();
79 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
80 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
82 auto window = ::glfwCreateWindow(1, 1,
"Test",
nullptr,
nullptr);
88 handle_.reset(window);
92 reinterpret_cast<PFN_vkGetInstanceProcAddr
>(
93 &::glfwGetInstanceProcAddress);
99 if (!context_vk || !context_vk->IsValid()) {
100 VALIDATION_LOG <<
"Could not create Vulkan context in the playground.";
111 context_vk->SetSyncPresentation(
true);
113 VkSurfaceKHR vk_surface;
114 auto res = vk::Result{::glfwCreateWindowSurface(
115 context_vk->GetInstance(),
120 if (res != vk::Result::eSuccess) {
122 << vk::to_string(res);
126 vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
127 auto context = context_vk->CreateSurfaceContext();
128 if (!context->SetWindowSurface(std::move(surface))) {
133 context_ = std::move(context);
139 std::shared_ptr<Context> PlaygroundImplVK::GetContext()
const {
145 return handle_.get();
149 std::unique_ptr<Surface> PlaygroundImplVK::AcquireSurfaceFrame(
150 std::shared_ptr<Context> context) {
151 SurfaceContextVK* surface_context_vk =
152 reinterpret_cast<SurfaceContextVK*
>(context_.get());
153 return surface_context_vk->AcquireNextSurface();
164 void PlaygroundImplVK::InitGlobalVulkanInstance() {
165 if (global_instance_) {
169 VULKAN_HPP_DEFAULT_DISPATCHER.init(::glfwGetInstanceProcAddress);
171 vk::ApplicationInfo application_info;
172 application_info.setApplicationVersion(VK_API_VERSION_1_0);
173 application_info.setApiVersion(VK_API_VERSION_1_1);
174 application_info.setEngineVersion(VK_API_VERSION_1_0);
175 application_info.setPEngineName(
"PlaygroundImplVK");
176 application_info.setPApplicationName(
"PlaygroundImplVK");
178 auto instance_result =
179 vk::createInstanceUnique(vk::InstanceCreateInfo({}, &application_info));
180 FML_CHECK(instance_result.result == vk::Result::eSuccess)
181 <<
"Unable to initialize global Vulkan instance";
182 global_instance_ = std::move(instance_result.value);
186 const std::shared_ptr<Capabilities>& capabilities) {
188 fml::StatusCode::kUnimplemented,
189 "PlaygroundImplVK doesn't support setting the capabilities.");