Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
VKRenderer.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include "Renderer.h"
7#include "VKDevice.h"
8#include "VKInstance.h"
9#include "VKPhysicalDevice.h"
10#include "VKSwapchain.h"
11#include <vulkan/vulkan.h>
12
13class VKRenderer : public Renderer
14{
15public:
16 std::string get_device_name() const override;
17 std::string get_renderer_name() const override;
18 std::string get_vendor_name() const override;
19
23 const VKInstance& get_instance() const;
24
29
33 const VKDevice& get_device() const;
34
38 const VKSwapchain& get_swapchain() const;
39
43 const VkCommandPool& get_command_pool() const;
44
45 static void init(const Window& win);
46 static void deinit();
47
48private:
49 static void create_instance();
50 static void create_surface(const Window& win);
51 static void select_physical_device();
52 static void create_device();
53 static void create_swapchain();
54 static void create_command_pool();
55};
56
57inline std::string_view ToString(VkResult res)
58{
59 switch(res)
60 {
61 case VK_SUCCESS:
62 return "VK_SUCCESS";
63
64 case VK_NOT_READY:
65 return "VK_NOT_READY";
66
67 case VK_TIMEOUT:
68 return "VK_TIMEOUT";
69
70 case VK_EVENT_SET:
71 return "VK_EVENT_SET";
72
73 case VK_EVENT_RESET:
74 return "VK_EVENT_RESET";
75
76 case VK_INCOMPLETE:
77 return "VK_INCOMPLETE";
78
79 case VK_ERROR_OUT_OF_HOST_MEMORY:
80 return "VK_ERROR_OUT_OF_HOST_MEMORY";
81
82 case VK_ERROR_OUT_OF_DEVICE_MEMORY:
83 return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
84
85 case VK_ERROR_INITIALIZATION_FAILED:
86 return "VK_ERROR_INITIALIZATION_FAILED";
87
88 case VK_ERROR_DEVICE_LOST:
89 return "VK_ERROR_DEVICE_LOST";
90
91 case VK_ERROR_MEMORY_MAP_FAILED:
92 return "VK_ERROR_MEMORY_MAP_FAILED";
93
94 case VK_ERROR_LAYER_NOT_PRESENT:
95 return "VK_ERROR_LAYER_NOT_PRESENT";
96
97 case VK_ERROR_FEATURE_NOT_PRESENT:
98 return "VK_ERROR_FEATURE_NOT_PRESENT";
99
100 case VK_ERROR_INCOMPATIBLE_DRIVER:
101 return "VK_ERROR_INCOMPATIBLE_DRIVER";
102
103 case VK_ERROR_TOO_MANY_OBJECTS:
104 return "VK_ERROR_TOO_MANY_OBJECTS";
105
106 case VK_ERROR_FORMAT_NOT_SUPPORTED:
107 return "VK_ERROR_FORMAT_NOT_SUPPORTED";
108
109 case VK_ERROR_SURFACE_LOST_KHR:
110 return "VK_ERROR_SURFACE_LOST_KHR";
111
112 case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
113 return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
114
115 case VK_SUBOPTIMAL_KHR:
116 return "VK_SUBOPTIMAL_KHR";
117
118 case VK_ERROR_OUT_OF_DATE_KHR:
119 return "VK_ERROR_OUT_OF_DATE_KHR";
120
121 case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
122 return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
123
124 case VK_ERROR_VALIDATION_FAILED_EXT:
125 return "VK_ERROR_VALIDATION_FAILED_EXT";
126
127 case VK_ERROR_INVALID_SHADER_NV:
128 return "VK_ERROR_INVALID_SHADER_NV";
129
130 default:
131 return "Unknown";
132 }
133}
134
135inline VkResult VKCheck(VkResult res)
136{
137 if(res != VK_SUCCESS)
138 throw std::runtime_error("Vulkan:" + std::string(ToString(res)));
139 return res;
140}
Definition: Renderer.h:10
Vulkan 逻辑设备.
Definition: VKDevice.h:14
Vulkan 实例.
Definition: VKInstance.h:12
Vulkan 物理设备.
Definition: VKPhysicalDevice.h:15
Definition: VKRenderer.h:14
const VKDevice & get_device() const
获取 VKDevice.
Definition: VKRenderer.cpp:50
const VKSwapchain & get_swapchain() const
获取 VKSwapchain.
Definition: VKRenderer.cpp:55
const VKPhysicalDevice & get_physical_device() const
获取 VKPhysicalDevice.
Definition: VKRenderer.cpp:45
const VKInstance & get_instance() const
获取 VKInstance.
Definition: VKRenderer.cpp:40
const VkCommandPool & get_command_pool() const
获取命令缓冲区池.
Definition: VKRenderer.cpp:60
Definition: VKSwapchain.h:11
窗体.
Definition: Window.h:24