|
13 | 13 |
|
14 | 14 | VULKAN_ENGINE_NAMESPACE_BEGIN |
15 | 15 |
|
16 | | -namespace Graphics |
17 | | -{ |
| 16 | +namespace Graphics { |
18 | 17 |
|
19 | | -namespace Booter |
20 | | -{ |
| 18 | +namespace Booter { |
| 19 | +#pragma region Instance |
21 | 20 | // Instance |
22 | | -VkInstance create_instance(const char *appName, const char *engineName, bool validation, |
23 | | - std::vector<const char *> validationLayers); |
24 | | -std::vector<const char *> get_required_extensions(bool validation); |
25 | | -// Logger |
| 21 | +VkInstance create_instance(const char* appName, |
| 22 | + const char* engineName, |
| 23 | + bool validation, |
| 24 | + std::vector<const char*> validationLayers); |
| 25 | + |
| 26 | +#pragma region Validation |
| 27 | +// Validation Logger |
26 | 28 | VkDebugUtilsMessengerEXT create_debug_messenger(VkInstance instance); |
| 29 | +void populate_debug_messenger_create_info(VkDebugUtilsMessengerCreateInfoEXT& createInfo); |
| 30 | +inline static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, |
| 31 | + VkDebugUtilsMessageTypeFlagsEXT messageType, |
| 32 | + const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, |
| 33 | + void* pUserData) { |
| 34 | + |
| 35 | + DEBUG_LOG("(Validation Layer) " << pCallbackData->pMessage); |
| 36 | + |
| 37 | + return VK_FALSE; |
| 38 | +} |
| 39 | +VkResult create_debug_utils_messenger_EXT(VkInstance instance, |
| 40 | + const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, |
| 41 | + const VkAllocationCallbacks* pAllocator, |
| 42 | + VkDebugUtilsMessengerEXT* pDebugMessenger); |
| 43 | +void destroy_debug_utils_messenger_EXT(VkInstance instance, |
| 44 | + VkDebugUtilsMessengerEXT debugMessenger, |
| 45 | + const VkAllocationCallbacks* pAllocator); |
| 46 | +#pragma region GPU |
27 | 47 | // GPU |
28 | | -VkPhysicalDevice pick_graphics_card_device(VkInstance instance, VkSurfaceKHR surface, |
29 | | - std::vector<const char *> extensions); |
| 48 | +VkPhysicalDevice |
| 49 | + pick_graphics_card_device(VkInstance instance, VkSurfaceKHR surface, std::vector<const char*> extensions); |
| 50 | +int rate_device_suitability(VkPhysicalDevice device, VkSurfaceKHR surface, std::vector<const char*> extensions); |
| 51 | +bool check_device_extension_support(VkPhysicalDevice device, std::vector<const char*> extensions); |
| 52 | +struct SwapChainSupportDetails { |
| 53 | + VkSurfaceCapabilitiesKHR capabilities; |
| 54 | + std::vector<VkSurfaceFormatKHR> formats; |
| 55 | + std::vector<VkPresentModeKHR> presentModes; |
| 56 | +}; |
| 57 | +SwapChainSupportDetails query_swapchain_support(VkPhysicalDevice device, VkSurfaceKHR surface); |
| 58 | +struct QueueFamilyIndices { |
| 59 | + std::optional<uint32_t> graphicsFamily; |
| 60 | + std::optional<uint32_t> presentFamily; |
| 61 | + std::optional<uint32_t> computeFamily; |
| 62 | + std::optional<uint32_t> transferFamily; |
| 63 | + std::optional<uint32_t> sparseBindingFamily; |
30 | 64 |
|
31 | | -int rate_device_suitability(VkPhysicalDevice device, VkSurfaceKHR surface, std::vector<const char *> extensions); |
32 | | -bool check_device_extension_support(VkPhysicalDevice device, std::vector<const char *> extensions); |
| 65 | + inline bool isComplete() const { |
| 66 | + return graphicsFamily.has_value() && presentFamily.has_value() && computeFamily.has_value(); |
| 67 | + } |
| 68 | +}; |
| 69 | +QueueFamilyIndices find_queue_families(VkPhysicalDevice device, VkSurfaceKHR surface); |
33 | 70 |
|
| 71 | +#pragma region Device |
34 | 72 | // Logical Device |
35 | | -VkDevice create_logical_device(std::unordered_map<QueueType, VkQueue> &queues, VkPhysicalDevice gpu, |
36 | | - VkPhysicalDeviceFeatures features, VkSurfaceKHR surface, bool validation, |
37 | | - std::vector<const char *> validationLayers); |
| 73 | +VkDevice create_logical_device(std::unordered_map<QueueType, VkQueue>& queues, |
| 74 | + VkPhysicalDevice gpu, |
| 75 | + VkPhysicalDeviceFeatures features, |
| 76 | + VkSurfaceKHR surface, |
| 77 | + bool validation, |
| 78 | + std::vector<const char*> validationLayers); |
| 79 | +#pragma region VMA |
38 | 80 | // VMA |
39 | 81 | VmaAllocator setup_memory(VkInstance instance, VkDevice device, VkPhysicalDevice gpu); |
40 | 82 |
|
| 83 | +#pragma region Utils |
| 84 | +// Utilities |
| 85 | +std::vector<const char*> get_required_extensions(bool validation); |
| 86 | +bool check_validation_layer_suport(std::vector<const char*> validationLayers); |
| 87 | +bool is_instance_extension_supported(const char* extensionName); |
| 88 | +bool is_device_extension_supported(VkPhysicalDevice physicalDevice, const char* extensionName); |
| 89 | +void log_available_extensions(std::vector<VkExtensionProperties> ext); |
| 90 | +void log_available_gpus(std::multimap<int, VkPhysicalDevice> candidates); |
41 | 91 |
|
42 | 92 | }; // namespace Booter |
43 | 93 |
|
|
0 commit comments