summaryrefslogtreecommitdiffstats
path: root/chromium/gpu/vulkan/vulkan_instance.h
blob: 0299140c580b23244a41f8b05774f733dadf8994 (plain)
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
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_VULKAN_VULKAN_INSTANCE_H_
#define GPU_VULKAN_VULKAN_INSTANCE_H_

#include <vulkan/vulkan_core.h>
#include <memory>

#include "base/check_op.h"
#include "base/component_export.h"
#include "base/files/file_path.h"
#include "base/native_library.h"
#include "gpu/config/vulkan_info.h"
#include "ui/gfx/extension_set.h"

namespace gpu {

class COMPONENT_EXPORT(VULKAN) VulkanInstance {
 public:
  VulkanInstance();

  VulkanInstance(const VulkanInstance&) = delete;
  VulkanInstance& operator=(const VulkanInstance&) = delete;

  ~VulkanInstance();

  // Creates the vulkan instance.
  //
  // The extensions in |required_extensions| and the layers in |required_layers|
  // will be enabled in the created instance. See the "Extended Functionality"
  // section of vulkan specification for more information.
  bool Initialize(const base::FilePath& vulkan_loader_library_path,
                  const std::vector<const char*>& required_extensions,
                  const std::vector<const char*>& required_layers);

  // These are the steps of `Initialize`. Most caller can use Initialize
  // directly. These are useful if unassigned functions are needed to compute
  // `required_extensions` or `required_layers`.
  bool BindUnassignedFunctionPointers(
      const base::FilePath& vulkan_loader_library_path);
  bool InitializeInstace(const std::vector<const char*>& required_extensions,
                         const std::vector<const char*>& required_layers);

  const VulkanInfo& vulkan_info() const { return vulkan_info_; }

  VkInstance vk_instance() { return vk_instance_; }

  bool is_from_angle() const { return is_from_angle_; }

 private:
  bool CreateInstance(const std::vector<const char*>& required_extensions,
                      const std::vector<const char*>& required_layers);
  bool InitializeFromANGLE(const std::vector<const char*>& required_extensions,
                           const std::vector<const char*>& required_layers);

  bool CollectBasicInfo(const std::vector<const char*>& required_layers);
  bool CollectDeviceInfo(VkPhysicalDevice physical_device = VK_NULL_HANDLE);
  void Destroy();

  const bool is_from_angle_;

  VulkanInfo vulkan_info_;

  base::NativeLibrary loader_library_ = nullptr;

  VkInstance owned_vk_instance_ = VK_NULL_HANDLE;
  VkInstance vk_instance_ = VK_NULL_HANDLE;
  bool debug_report_enabled_ = false;
#if DCHECK_IS_ON()
  VkDebugReportCallbackEXT error_callback_ = VK_NULL_HANDLE;
  VkDebugReportCallbackEXT warning_callback_ = VK_NULL_HANDLE;
#endif
};

}  // namespace gpu

#endif  // GPU_VULKAN_VULKAN_INSTANCE_H_