forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_vk.h
More file actions
136 lines (106 loc) · 4.5 KB
/
context_vk.h
File metadata and controls
136 lines (106 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <memory>
#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "impeller/base/backend_cast.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
#include "impeller/renderer/backend/vulkan/descriptor_pool_vk.h"
#include "impeller/renderer/backend/vulkan/pipeline_library_vk.h"
#include "impeller/renderer/backend/vulkan/sampler_library_vk.h"
#include "impeller/renderer/backend/vulkan/shader_library_vk.h"
#include "impeller/renderer/backend/vulkan/surface_producer_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "impeller/renderer/context.h"
#include "impeller/renderer/formats.h"
namespace impeller {
class ContextVK final : public Context, public BackendCast<ContextVK, Context> {
public:
static std::shared_ptr<ContextVK> Create(
PFN_vkGetInstanceProcAddr proc_address_callback,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
const std::shared_ptr<const fml::Mapping>& pipeline_cache_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
const std::string& label);
// |Context|
~ContextVK() override;
// |Context|
bool IsValid() const override;
template <typename T>
bool SetDebugName(T handle, std::string_view label) const {
return SetDebugName(*device_, handle, label);
}
template <typename T>
static bool SetDebugName(vk::Device dev, T handle, std::string_view label) {
uint64_t handle_ptr =
reinterpret_cast<uint64_t>(static_cast<typename T::NativeType>(handle));
std::string label_str = std::string(label);
auto ret =
dev.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT()
.setObjectType(T::objectType)
.setObjectHandle(handle_ptr)
.setPObjectName(label_str.c_str()));
if (ret != vk::Result::eSuccess) {
VALIDATION_LOG << "unable to set debug name";
return false;
}
return true;
}
vk::Instance GetInstance() const;
void SetupSwapchain(vk::UniqueSurfaceKHR surface);
std::unique_ptr<Surface> AcquireSurface(size_t current_frame);
std::shared_ptr<DescriptorPoolVK> GetDescriptorPool() const;
#ifdef FML_OS_ANDROID
vk::UniqueSurfaceKHR CreateAndroidSurface(ANativeWindow* window) const;
#endif // FML_OS_ANDROID
private:
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner_;
vk::UniqueInstance instance_;
vk::UniqueDebugUtilsMessengerEXT debug_messenger_;
vk::PhysicalDevice physical_device_;
vk::UniqueDevice device_;
std::shared_ptr<Allocator> allocator_;
std::shared_ptr<ShaderLibraryVK> shader_library_;
std::shared_ptr<SamplerLibraryVK> sampler_library_;
std::shared_ptr<PipelineLibraryVK> pipeline_library_;
vk::Queue graphics_queue_;
vk::Queue compute_queue_;
vk::Queue transfer_queue_;
vk::Queue present_queue_;
vk::UniqueSurfaceKHR surface_;
vk::Format surface_format_;
std::unique_ptr<SwapchainVK> swapchain_;
std::unique_ptr<CommandPoolVK> graphics_command_pool_;
std::unique_ptr<SurfaceProducerVK> surface_producer_;
std::shared_ptr<WorkQueue> work_queue_;
std::shared_ptr<DescriptorPoolVK> descriptor_pool_;
bool is_valid_ = false;
ContextVK(
PFN_vkGetInstanceProcAddr proc_address_callback,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
const std::shared_ptr<const fml::Mapping>& pipeline_cache_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
const std::string& label);
// |Context|
std::shared_ptr<Allocator> GetResourceAllocator() const override;
// |Context|
std::shared_ptr<ShaderLibrary> GetShaderLibrary() const override;
// |Context|
std::shared_ptr<SamplerLibrary> GetSamplerLibrary() const override;
// |Context|
std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const override;
// |Context|
std::shared_ptr<CommandBuffer> CreateCommandBuffer() const override;
// |Context|
PixelFormat GetColorAttachmentPixelFormat() const override;
// |Context|
std::shared_ptr<WorkQueue> GetWorkQueue() const override;
// |Context|
bool SupportsOffscreenMSAA() const override;
FML_DISALLOW_COPY_AND_ASSIGN(ContextVK);
};
} // namespace impeller