2025-05-07 19:21:51 +02:00
|
|
|
/*
|
|
|
|
|
Crafter®.Graphics
|
|
|
|
|
Copyright (C) 2025 Catcrafts®
|
|
|
|
|
Catcrafts.net
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 3.0 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-19 15:46:26 +02:00
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include <vulkan/vulkan_wayland.h>
|
|
|
|
|
|
|
|
|
|
export module Crafter.Graphics:VulkanDevice;
|
2025-11-16 15:32:11 +01:00
|
|
|
import std;
|
2025-04-19 15:46:26 +02:00
|
|
|
|
|
|
|
|
export namespace Crafter {
|
2025-11-16 15:32:03 +01:00
|
|
|
/**
|
|
|
|
|
* @brief Static class for initizializing and holding various vulkan handles.
|
|
|
|
|
*/
|
2025-04-19 15:46:26 +02:00
|
|
|
class VulkanDevice {
|
|
|
|
|
public:
|
|
|
|
|
inline static VkInstance instance = VK_NULL_HANDLE;
|
|
|
|
|
inline static VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;
|
|
|
|
|
inline static VkPhysicalDevice physDevice = VK_NULL_HANDLE;
|
|
|
|
|
inline static VkDevice device = VK_NULL_HANDLE;
|
|
|
|
|
inline static std::uint32_t queueFamilyIndex = 0;
|
|
|
|
|
inline static VkQueue queue = VK_NULL_HANDLE;
|
|
|
|
|
inline static VkCommandPool commandPool = VK_NULL_HANDLE;
|
|
|
|
|
inline static VkSwapchainKHR swapchain = VK_NULL_HANDLE;
|
2025-04-19 23:59:27 +02:00
|
|
|
inline static PFN_vkCmdDrawMeshTasksEXT vkCmdDrawMeshTasksEXTProc;
|
|
|
|
|
inline static PFN_vkCmdBeginRenderingKHR vkCmdBeginRenderingKHRProc;
|
|
|
|
|
inline static PFN_vkCmdEndRenderingKHR vkCmdEndRenderingKHRProc;
|
|
|
|
|
inline static VkPhysicalDeviceMemoryProperties memoryProperties;
|
|
|
|
|
inline static VkFormat depthFormat = VK_FORMAT_UNDEFINED;
|
2025-06-14 01:45:33 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Creates the vulkan device, this must be called before any use of vulkan.
|
|
|
|
|
*/
|
2025-04-19 23:59:27 +02:00
|
|
|
static void CreateDevice();
|
2025-06-14 14:58:02 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Checks if result is VK_SUCCESS.
|
|
|
|
|
* @param result The VkResult to check.
|
|
|
|
|
* @throws std::runtime_error If result != VK_SUCCESS.
|
|
|
|
|
*/
|
2025-04-19 23:59:27 +02:00
|
|
|
static void CHECK_VK_RESULT(VkResult result);
|
2025-06-14 14:58:02 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Finds a suitable memory type index for the device based on required properties.
|
|
|
|
|
*
|
|
|
|
|
* This function searches through the memory types supported by the physical device to find
|
|
|
|
|
* a memory type index that matches the specified bitmask and has the requested property flags.
|
|
|
|
|
*
|
|
|
|
|
* @param typeBits A bitmask representing the memory types that are suitable. Each bit corresponds
|
|
|
|
|
* to a memory type index; if the bit is set, that memory type is considered.
|
|
|
|
|
* @param properties A bitmask of VkMemoryPropertyFlags specifying the desired memory properties,
|
|
|
|
|
* such as device local, host visible, etc.
|
|
|
|
|
*
|
|
|
|
|
* @return The index of a suitable memory type that fulfills the requirements.
|
|
|
|
|
*
|
|
|
|
|
* @throws std::runtime_error If no suitable memory type is found matching the criteria.
|
|
|
|
|
*/
|
2025-04-19 23:59:27 +02:00
|
|
|
static std::uint32_t GetMemoryType(std::uint32_t typeBits, VkMemoryPropertyFlags properties);
|
2025-04-19 15:46:26 +02:00
|
|
|
};
|
|
|
|
|
}
|