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/modern_shaders_vk.h"
17 #include "impeller/fixtures/vk/fixtures_shaders_vk.h"
18 #include "impeller/playground/imgui/vk/imgui_shaders_vk.h"
24 #include "impeller/renderer/vk/compute_shaders_vk.h"
25 #include "impeller/scene/shaders/vk/scene_shaders_vk.h"
29 static std::vector<std::shared_ptr<fml::Mapping>>
32 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
33 impeller_entity_shaders_vk_length),
34 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
35 impeller_modern_shaders_vk_length),
36 std::make_shared<fml::NonOwnedMapping>(
37 impeller_fixtures_shaders_vk_data,
38 impeller_fixtures_shaders_vk_length),
39 std::make_shared<fml::NonOwnedMapping>(impeller_imgui_shaders_vk_data,
40 impeller_imgui_shaders_vk_length),
41 std::make_shared<fml::NonOwnedMapping>(impeller_scene_shaders_vk_data,
42 impeller_scene_shaders_vk_length),
43 std::make_shared<fml::NonOwnedMapping>(
44 impeller_compute_shaders_vk_data, impeller_compute_shaders_vk_length),
48 void PlaygroundImplVK::DestroyWindowHandle(WindowHandle handle) {
52 ::glfwDestroyWindow(
reinterpret_cast<GLFWwindow*
>(handle));
56 :
PlaygroundImpl(switches), handle_(nullptr, &DestroyWindowHandle) {
57 if (!::glfwVulkanSupported()) {
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.";
64 VALIDATION_LOG <<
"Attempted to initialize a Vulkan playground on a system "
65 "that does not support Vulkan.";
70 ::glfwDefaultWindowHints();
71 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
72 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
74 auto window = ::glfwCreateWindow(1, 1,
"Test",
nullptr,
nullptr);
80 handle_.reset(window);
84 reinterpret_cast<PFN_vkGetInstanceProcAddr
>(
85 &::glfwGetInstanceProcAddress);
91 if (!context_vk || !context_vk->IsValid()) {
92 VALIDATION_LOG <<
"Could not create Vulkan context in the playground.";
103 context_vk->SetSyncPresentation(
true);
105 VkSurfaceKHR vk_surface;
106 auto res = vk::Result{::glfwCreateWindowSurface(
107 context_vk->GetInstance(),
112 if (res != vk::Result::eSuccess) {
114 << vk::to_string(res);
118 vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
119 auto context = context_vk->CreateSurfaceContext();
120 if (!context->SetWindowSurface(std::move(surface))) {
125 context_ = std::move(context);
131 std::shared_ptr<Context> PlaygroundImplVK::GetContext()
const {
137 return handle_.get();
141 std::unique_ptr<Surface> PlaygroundImplVK::AcquireSurfaceFrame(
142 std::shared_ptr<Context> context) {
143 SurfaceContextVK* surface_context_vk =
144 reinterpret_cast<SurfaceContextVK*
>(context_.get());
145 return surface_context_vk->AcquireNextSurface();