Moved vulkan files

This commit is contained in:
Pasha Bibko
2025-11-16 21:20:43 +00:00
parent 5dc0974d50
commit edcf13d62a
5 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,154 @@
#pragma once
#include "../../VulkanRenderer.h"
namespace PB::Renderer
{
struct QueueFamilyIndices
{
static constexpr uint32_t UNDEFINED_UINT32_VALUE = 0xFFFFFFFF;
uint32_t graphicsFamily = UNDEFINED_UINT32_VALUE;
uint32_t presentFamily = UNDEFINED_UINT32_VALUE;
[[nodiscard]] bool Complete() const
{
return
graphicsFamily != UNDEFINED_UINT32_VALUE &&
presentFamily != UNDEFINED_UINT32_VALUE;
}
};
struct SwapChainSupportDetails
{
VkSurfaceCapabilitiesKHR capabilities;
std::vector<VkSurfaceFormatKHR> formats;
std::vector<VkPresentModeKHR> presentModes;
};
class VulkanManager
{
public:
/* Static class so (de)constructors have been deleted to stop accidental creation */
VulkanManager() = delete;
~VulkanManager() = delete;
/* Shorthand for calling all the initialisation functions, returns false if any fail */
static bool Init(GLFWwindow* window);
/* Frees ALL allocated Vulkan resources */
static bool Cleanup();
/*
Creates the global Vulkan instance, which connects the application to Vulkan.
Defines the application info and imports the needed (GLFW) extensions.
*/
static bool CreateInstance();
/*
Ties a surface to the window to present images. Abstracts platform specific code.
Required for creating a swap chain.
*/
static bool CreateSurface(GLFWwindow* window);
/*
Scans for all available GPUs and picks the first one that supports the necessary capabilities.
Only looks for discrete (non-integrated) GPUs and uses that for all rendering.
*/
static bool PickPhysicalDevice();
/*
Creates a logical device which handles the commands from Vulkan to hardware instructions.
Also requests the queues needed.
*/
static bool CreateLogicalDevice();
/*
Creates a swap chain with suitable image formats, present modes and image dimensions.
The swap chain is the series of images that are displayed to the screen.
*/
static bool CreateSwapChain(GLFWwindow* window);
/*
Each swap chain image requires a view, which describes how shaders and
the pipeline interact with the image data.
*/
static bool CreateImageViews();
/*
Defines the attachments (such as color and depth) and defines how they are rendered.
Also defines the subpasses and dependencies between them.
*/
static bool CreateRenderPass();
/*
Creates a framebuffer for each swap chain image, pairing the render pass with the relevant image.
Each framebuffer is a specific set of attachments used drawing a render pass instance.
*/
static bool CreateFramebuffer();
/*
Assembles shaders, fixed function state and creates the render pipeline.
Also checks that the render pass is compatiable.
*/
static bool CreateGraphicsPipeline();
/*
Allocates a command pool and command buffers.
The buffers represent the exact instructions the GPU will execute.
*/
static bool CreateCommandBuffers();
/*
Creates sync between coordinate operations between different parts of the rendering.
Required to stop race conditions between frames.
*/
static bool CreateSemaphores();
/*
Draws a frame to the screen using the command buffers and sync objects.
*/
static bool RenderPass();
private:
static bool IsDeviceSuitable(const VkPhysicalDevice& device);
static QueueFamilyIndices FindQueueFamilies(const VkPhysicalDevice& device);
static bool CheckDeviceExtensionSupport(const VkPhysicalDevice& device);
static SwapChainSupportDetails QuerySwapChainSupport();
static VkSurfaceFormatKHR ChooseSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
static VkPresentModeKHR ChoosePresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
static VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window);
static VkShaderModule CreateShaderModule(const std::string& filename);
static VkInstance s_Instance;
static VkSurfaceKHR s_Surface;
static VkPhysicalDevice s_PhysicalDevice;
static QueueFamilyIndices s_QueueIndices;
static VkDevice s_Device;
static VkQueue s_GraphicsQueue;
static VkQueue s_PresentQueue;
static VkSwapchainKHR s_SwapChain;
static std::vector<VkImage> s_SwapChainImages;
static std::vector<VkImageView> s_SwapChainImageViews;
static VkFormat s_SwapChainImageFormat;
static VkExtent2D s_SwapChainExtent;
static VkRenderPass s_RenderPass;
static std::vector<VkFramebuffer> s_Framebuffers;
static VkPipelineLayout s_PipelineLayout;
static VkPipeline s_RenderPipeline;
static VkCommandPool s_CommandPool;
static std::vector<VkCommandBuffer> s_CommandBuffers;
static VkSemaphore s_ImageAvailableSemaphore;
static VkSemaphore s_RenderFinishedSemaphore;
};
}