17#ifndef AEONGAMES_VULKANRENDERER_HPP
18#define AEONGAMES_VULKANRENDERER_HPP
20#include <vulkan/vulkan.h>
21#include <unordered_map>
25#include "aeongames/Renderer.hpp"
28#include "VulkanWindow.hpp"
29#include "VulkanBuffer.hpp"
30#include "VulkanMesh.hpp"
31#include "VulkanPipeline.hpp"
32#include "VulkanMaterial.hpp"
33#include "VulkanTexture.hpp"
34#include "VulkanMemoryPoolBuffer.hpp"
60 const VkDescriptorSetLayout&
GetDescriptorSetLayout (
const VkDescriptorSetLayoutCreateInfo& aDescriptorSetLayoutCreateInfo )
const;
67 uint32_t
FindMemoryTypeIndex ( uint32_t typeFilter, VkMemoryPropertyFlags properties )
const;
85 void SetClearColor (
void* aWindowId,
float R,
float G,
float B,
float A )
final;
88 void ResizeViewport (
void* aWindowId, int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight )
final;
91 void Render (
void* aWindowId,
98 uint32_t aVertexStart = 0,
99 uint32_t aVertexCount = 0xffffffff,
100 uint32_t aInstanceCount = 1,
101 uint32_t aFirstInstance = 0 )
const final;
112#if defined (VK_USE_PLATFORM_XLIB_KHR)
113 Display* GetDisplay()
const;
116 void InitializeInstance();
117 void InitializeDevice();
118 void InitializeCommandPools();
119 void InitializeDebug();
120 void SetupLayersAndExtensions();
122 void LoadFunctions();
123 void FinalizeInstance();
124 void FinalizeDevice();
125 void FinalizeCommandPools();
126 void FinalizeDebug();
127 void InitializeDescriptorSetLayout ( VkDescriptorSetLayout& aVkDescriptorSetLayout, VkDescriptorType aVkDescriptorType );
128 void FinalizeDescriptorSetLayout ( VkDescriptorSetLayout& aVkDescriptorSetLayout );
129#if defined (VK_USE_PLATFORM_XLIB_KHR)
130 Display* mDisplay {XOpenDisplay (
nullptr ) };
132 bool mValidate {
true };
133 VkInstance mVkInstance{ VK_NULL_HANDLE };
134 VkDevice mVkDevice { VK_NULL_HANDLE};
135 VkPhysicalDevice mVkPhysicalDevice{ VK_NULL_HANDLE };
136 VkPhysicalDeviceProperties mVkPhysicalDeviceProperties{};
137 VkPhysicalDeviceMemoryProperties mVkPhysicalDeviceMemoryProperties{};
138 PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT{
nullptr};
139 PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT{
nullptr};
140 VkDebugUtilsMessengerEXT mVkDebugUtilsMessengerEXT{VK_NULL_HANDLE};
141 VkCommandPool mVkSingleTimeCommandPool{ VK_NULL_HANDLE };
142 VkQueue mVkQueue{ VK_NULL_HANDLE };
143 mutable std::vector<std::tuple<size_t, VkDescriptorSetLayout >> mVkDescriptorSetLayouts{};
145 uint32_t mQueueFamilyIndex{};
146 std::vector<const char*> mInstanceLayerNames{};
147 std::vector<const char*> mInstanceExtensionNames{};
148 std::vector<const char*> mDeviceLayerNames{};
149 std::vector<const char*> mDeviceExtensionNames{};
151 bool mFunctionsLoaded =
false;
152 std::unordered_map<size_t, VulkanMesh> mMeshStore{};
153 std::unordered_map<size_t, VulkanPipeline> mPipelineStore{};
154 std::unordered_map<size_t, VulkanMaterial> mMaterialStore{};
155 std::unordered_map<size_t, VulkanTexture> mTextureStore{};
156 std::unordered_map<void*, VulkanWindow> mWindowStore{};
Header for 4x4 matrix class.
Provides access to a region within a memory pool buffer.
View frustum defined by six clipping planes, extracted from a projection (or view-projection) matrix.
Represents a surface material with uniform properties and texture samplers.
4 by 4 matrix in colum mayor order.
Represents a polygon mesh with vertex attributes and index data.
Rendering pipeline resource.
Abstract base class for rendering backends.
Represents a 2D texture image resource.
Vulkan material binding handler for descriptor sets and uniforms.
Vulkan mesh wrapper managing vertex and index buffer resources.
Vulkan graphics pipeline with descriptor set and push constant reflection.
uint32_t GetQueueFamilyIndex() const
Get the queue family index used for graphics operations.
void UnloadMesh(const Mesh &aMesh) final
Unloads mesh data from GPU memory.
const VkDescriptorSetLayout & GetDescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo &aDescriptorSetLayoutCreateInfo) const
Get or create a descriptor set layout matching the given create info.
void UnloadPipeline(const Pipeline &aPipeline) final
Unloads a rendering pipeline from the renderer.
const VkPhysicalDevice & GetPhysicalDevice() const
Get the physical device handle.
void LoadMesh(const Mesh &aMesh) final
Loads mesh data into GPU memory.
const VkInstance & GetInstance() const
Get the Vulkan instance handle.
void BeginRender(void *aWindowId) final
Begins a render pass for the given window surface.
const VulkanMesh * GetVulkanMesh(const Mesh &aMesh)
Get the cached VulkanMesh for a Mesh resource.
BufferAccessor AllocateSingleFrameUniformMemory(void *aWindowId, size_t aSize) final
Allocates uniform buffer memory that is valid for a single frame.
const VulkanMaterial * GetVulkanMaterial(const Material &aMaterial)
Get the cached VulkanMaterial for a Material resource.
const VkPhysicalDeviceMemoryProperties & GetPhysicalDeviceMemoryProperties() const
Get the physical device memory properties.
VkCommandBuffer BeginSingleTimeCommands() const
Begin recording a single-use command buffer.
VulkanRenderer(void *aWindow)
Construct from a native window handle.
void LoadPipeline(const Pipeline &aPipeline) final
Loads a rendering pipeline (shaders and state) into the renderer.
void SetClearColor(void *aWindowId, float R, float G, float B, float A) final
Sets the color to be used to clear the window background.
void AttachWindow(void *aWindowId) final
Attach a Window as a rendering surface.
const VkQueue & GetQueue() const
Get the graphics queue handle.
void ResizeViewport(void *aWindowId, int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight) final
Resizes the specific window surface's viewport.
void LoadTexture(const Texture &aTexture) final
Loads a texture into GPU memory.
void LoadMaterial(const Material &aMaterial) final
Loads material data into the renderer.
const VulkanPipeline * GetVulkanPipeline(const Pipeline &aPipeline)
Get the cached VulkanPipeline for a Pipeline resource.
uint32_t FindMemoryTypeIndex(uint32_t typeFilter, VkMemoryPropertyFlags properties) const
Find a memory type index matching both a type filter and property flags.
void SetViewMatrix(void *aWindowId, const Matrix4x4 &aMatrix) final
Sets the view matrix for a specific window surface.
void EndSingleTimeCommands(VkCommandBuffer commandBuffer) const
Submit and free a single-use command buffer.
void Render(void *aWindowId, const Matrix4x4 &aModelMatrix, const Mesh &aMesh, const Pipeline &aPipeline, const Material *aMaterial=nullptr, const BufferAccessor *aSkeleton=nullptr, Topology aTopology=Topology::TRIANGLE_LIST, uint32_t aVertexStart=0, uint32_t aVertexCount=0xffffffff, uint32_t aInstanceCount=1, uint32_t aFirstInstance=0) const final
Issues a draw call for a mesh with the given pipeline and optional material.
const VkPhysicalDeviceProperties & GetPhysicalDeviceProperties() const
Get the physical device properties.
const VkDescriptorImageInfo * GetTextureDescriptorImageInfo(const Texture &aTexture) const
Get the descriptor image info for a loaded texture.
void DetachWindow(void *aWindowId) final
Detach a Window as a rendering surface.
VkRenderPass GetRenderPass() const
Get the common Vulkan render pass.
void EndRender(void *aWindowId) final
Ends the current render pass for the given window surface.
const Frustum & GetFrustum(void *aWindowId) const final
Returns the view frustum for the given window surface.
void SetProjectionMatrix(void *aWindowId, const Matrix4x4 &aMatrix) final
Sets the projection matrix for a specific window surface.
uint32_t GetMemoryTypeIndex(VkMemoryPropertyFlags aVkMemoryPropertyFlags) const
Get a memory type index matching the requested property flags.
void UnloadTexture(const Texture &aTexture) final
Unloads a texture from GPU memory.
const VkDevice & GetDevice() const
Get the logical device handle.
void UnloadMaterial(const Material &aMaterial) final
Unloads material data from the renderer.
Vulkan texture resource wrapper with image and descriptor management.
Vulkan per-window swapchain, render pass, and rendering state.
<- This is here just for the literals
Topology
Primitive topology types for rendering.
@ TRIANGLE_LIST
Independent triangles.