9 #include <shared_mutex>
10 #include <unordered_map>
30 GraphicsObjectManager(VkInstance instance, VkPhysicalDevice gpu, VkDevice logDevice, VkQueue graphicsQueue, std::shared_mutex& graphicsMutex, uint32_t graphicsQueueFamily,
const uint32_t frameCount);
77 bool addTestObject(
int id,
const std::vector<SimpleVertex>& vertices,
const std::vector<uint32_t>& indices, glm::mat4 transformation);
86 bool addArea(
const std::vector<Vertex>& vertices,
const std::vector<uint32_t>& indices, std::array<ImageData, 6> textures, VkSampler texSampler);
178 VkImageView
createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT);
232 bool endCommandBuffer(VkDevice logDevice, VkCommandBuffer commandBuffer, VkFence fence = VK_NULL_HANDLE);
246 AllocatedBuffer createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VmaAllocationInfo& info, VmaMemoryUsage memUsage = VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags = 0, VkMemoryPropertyFlags requiredFlags = 0, VkMemoryPropertyFlags preferredFlags = 0);
247 AllocatedBuffer createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VmaMemoryUsage memUsage = VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags = 0, VkMemoryPropertyFlags requiredFlags = 0, VkMemoryPropertyFlags preferredFlags = 0);
264 AllocatedImage createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL, VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VmaMemoryUsage memUsage = VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags = 0, VkMemoryPropertyFlags requiredFlags = 0, VkMemoryPropertyFlags preferredFlags = 0);
298 bool endCommandBuffer(VkCommandBuffer commandBuffer, VkFence fence = VK_NULL_HANDLE);
309 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, VkCommandBuffer commandBuffer, VkImageAspectFlags aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT, std::pair<uint32_t, uint32_t> srcAndDstQueueFamilies = {VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED});
325 bool getPipelineAndAccessFlags(VkImageLayout srcLayout, VkImageLayout dstLayout, std::pair<VkAccessFlags, VkAccessFlags>& srcAndDstAccessMasks, std::pair<VkPipelineStageFlags, VkPipelineStageFlags>& srcAndDstStages);
ObjectType
Definition: BasicTypes.hpp:29
constexpr uint32_t MAX_BONES
Definition: BasicTypes.hpp:18
Graphics object manager manages different types of objects that have memory and can be drawn.
Definition: GraphicsObjectManager.hpp:18
AllocatedImage createDepthImage(uint32_t width, uint32_t height, VkFormat depthFormat)
Creates a depth image.
Definition: GraphicsObjectManager.cpp:807
void updateCameraDescriptor(const void *srcData, uint32_t frame)
Updates the camera descriptor with the given data.
Definition: GraphicsObjectManager.cpp:798
bool cleanResources(int id, ObjectType type)
Cleans resources of the given id, if they exists.
Definition: GraphicsObjectManager.cpp:683
VkDescriptorSetLayout sunLayoutM
Definition: GraphicsObjectManager.hpp:358
std::vector< AreaObject > areaObjectsM
Definition: GraphicsObjectManager.hpp:356
AllocatedBuffer createStagingBuffer(VkDeviceSize size, VmaAllocationInfo &allocInfo)
Helper for creating a staging buffer.
Definition: GraphicsObjectManager.cpp:551
~GraphicsObjectManager()
Destructor.
Definition: GraphicsObjectManager.cpp:53
bool getPipelineAndAccessFlags(VkImageLayout srcLayout, VkImageLayout dstLayout, std::pair< VkAccessFlags, VkAccessFlags > &srcAndDstAccessMasks, std::pair< VkPipelineStageFlags, VkPipelineStageFlags > &srcAndDstStages)
Fills access masks and pipeline stages when given source and destination layouts for an image.
Definition: GraphicsObjectManager.cpp:504
void copyBuffer(AllocatedBuffer allocBuffer, const void *srcData)
Copies the given data to the given buffer.
Definition: GraphicsObjectManager.cpp:856
std::vector< DrawableObject > getDrawableObjects(ObjectType type, uint32_t frame) const
Returns drawable objects of the given type.
Definition: GraphicsObjectManager.cpp:991
uint32_t getLayoutCount(ObjectType type) const
Returns the number of descriptor layouts of the given type. Currently not a very useful function....
Definition: GraphicsObjectManager.cpp:979
VkSharingMode getSharingMode()
Returns the sharing mode of created resources.
Definition: GraphicsObjectManager.cpp:419
bool addArea(const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices, std::array< ImageData, 6 > textures, VkSampler texSampler)
Adds an area object to the buffer manager.
Definition: GraphicsObjectManager.cpp:651
uint32_t frameCountM
Definition: GraphicsObjectManager.hpp:363
void updateSunDescriptor(const void *srcData, uint32_t frame)
Updates the sun descriptor with the given data.
Definition: GraphicsObjectManager.cpp:792
std::shared_mutex & graphicsQueueMutexM
Definition: GraphicsObjectManager.hpp:345
std::unordered_map< int, GameObject > gameObjectsM
Definition: GraphicsObjectManager.hpp:354
std::pair< uint32_t, uint32_t > getQueueTransitionFamilies()
Queue families should be transferred, if the resources are using multiple queues, and the sharingmode...
Definition: GraphicsObjectManager.cpp:495
LightObject sunM
Definition: GraphicsObjectManager.hpp:357
uint32_t getQueueFamilyCount()
Returns number of queue families.
Definition: GraphicsObjectManager.cpp:409
std::optional< CommandUnit > transferCommandUnitM
Definition: GraphicsObjectManager.hpp:347
void createSun()
Creates necessary memory allocations and mappings for a sun.
Definition: GraphicsObjectManager.cpp:564
VkDevice logDeviceM
Definition: GraphicsObjectManager.hpp:341
void createDescriptorBuilder()
Initializes the descriptorBuilder member.
Definition: GraphicsObjectManager.cpp:402
VmaAllocator allocatorM
Definition: GraphicsObjectManager.hpp:342
std::vector< CombinedImage > allocatedImagesM
Definition: GraphicsObjectManager.hpp:360
VkCommandBuffer startCommandBuffer(bool preferTransfer)
Allocates and begins a command buffer.
Definition: GraphicsObjectManager.cpp:433
AllocatedImage createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling=VK_IMAGE_TILING_OPTIMAL, VkImageUsageFlags usage=VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, VmaMemoryUsage memUsage=VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags=0, VkMemoryPropertyFlags requiredFlags=0, VkMemoryPropertyFlags preferredFlags=0)
Creates an allocated image. The standard parameters make it easy to create a texture image on the GPU...
Definition: GraphicsObjectManager.cpp:360
VkDeviceSize minOffsetM
Minimum offset alignment for uniform buffers.
Definition: GraphicsObjectManager.hpp:343
void addTransferQueueFamilyAccess(const uint32_t transferQueueFamily, VkQueue transferQueue)
Adds the given transfer queue to the manager.
Definition: GraphicsObjectManager.cpp:118
VkDescriptorSetLayout getSunLayout() const
Returns the descriptor set layout of the sun.
Definition: GraphicsObjectManager.cpp:787
VkDescriptorSetLayout getLayout(ObjectType type) const
Returns the descriptor set layout for the given object type.
Definition: GraphicsObjectManager.cpp:967
std::optional< CommandUnit > activeCommandUnitM
Definition: GraphicsObjectManager.hpp:349
void destroyImage(AllocatedImage image)
Interface for destroying an image That is owned by the user of this class.
Definition: GraphicsObjectManager.cpp:814
void updateObjectDescriptor(int id, const void *srcData, uint32_t frame)
Updates the object descriptor with the given data.
Definition: GraphicsObjectManager.cpp:762
bool endCommandBuffer(VkCommandBuffer commandBuffer, VkFence fence=VK_NULL_HANDLE)
Submits the given command buffer to be executed on the gpu.
Definition: GraphicsObjectManager.cpp:450
bool addTestObject(int id, const std::vector< SimpleVertex > &vertices, const std::vector< uint32_t > &indices, glm::mat4 transformation)
Adds a test object to the buffer manager.
Definition: GraphicsObjectManager.cpp:601
CombinedImage createCombinedImage(uint32_t width, uint32_t height, VkFormat format)
Creates an image for the given data and stores the memory to this class.
Definition: GraphicsObjectManager.cpp:847
void updateCharacterDescriptor(int id, const void *transformSrcData, const void *boneSrcData, uint32_t frame)
Definition: GraphicsObjectManager.cpp:769
std::unordered_map< int, TestObject > testObjectsM
Definition: GraphicsObjectManager.hpp:355
VkDescriptorSet getSunDescriptorSet(uint32_t frame) const
Returns the descriptor set of the sun for the given frame.
Definition: GraphicsObjectManager.cpp:778
void transitionDepthImageLayout(AllocatedImage depthImage, VkFormat depthFormat, VkImageLayout srcLayout, VkImageLayout dstLayout)
Transitions the given image to the given layout using graphics queue.
Definition: GraphicsObjectManager.cpp:819
void copyImage(AllocatedImage allocImage, const ImageData &srcData)
Copies the given data to the given image.
Definition: GraphicsObjectManager.cpp:898
VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags=VK_IMAGE_ASPECT_COLOR_BIT)
Creates an image view for the given image and format.
Definition: GraphicsObjectManager.cpp:826
std::unique_ptr< DescriptorBuilder > pBuilderM
Definition: GraphicsObjectManager.hpp:351
std::unordered_map< int, CharacterObject > characterObjectsM
Definition: GraphicsObjectManager.hpp:353
AllocatedBuffer createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VmaAllocationInfo &info, VmaMemoryUsage memUsage=VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags=0, VkMemoryPropertyFlags requiredFlags=0, VkMemoryPropertyFlags preferredFlags=0)
Creates a buffer with the given parameters.
Definition: GraphicsObjectManager.cpp:288
bool addGameObject(int objectId, const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices, ImageData &texture, glm::mat4 transformation, VkSampler imgSampler, PhongMaterial material=PhongMaterial::getDefaultMaterial())
Adds a game object to the buffer manager.
Definition: GraphicsObjectManager.cpp:217
GraphicsObjectManager(VkInstance instance, VkPhysicalDevice gpu, VkDevice logDevice, VkQueue graphicsQueue, std::shared_mutex &graphicsMutex, uint32_t graphicsQueueFamily, const uint32_t frameCount)
Creates a graphics object manager.
Definition: GraphicsObjectManager.cpp:11
std::array< VkDescriptorSetLayout, OBJECT_TYPE_COUNT > descriptorSetLayoutsM
Definition: GraphicsObjectManager.hpp:365
bool addCharacter(int characterID, const std::vector< CharacterVertex > &vertices, const std::vector< uint32_t > &indices, ImageData &texture, glm::mat4 transformation, glm::mat4 bindPose[MAX_BONES], VkSampler imgSampler, PhongMaterial material=PhongMaterial::getDefaultMaterial())
Adds a character to the buffer manager with the given parameters.
Definition: GraphicsObjectManager.cpp:140
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, VkCommandBuffer commandBuffer, VkImageAspectFlags aspectFlags=VK_IMAGE_ASPECT_COLOR_BIT, std::pair< uint32_t, uint32_t > srcAndDstQueueFamilies={VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED})
Records image layout transition barrier to the given command buffer.
Definition: GraphicsObjectManager.cpp:461
void updateTestObject(int id, const void *srcData, uint32_t frame)
Updates test object data.
Definition: GraphicsObjectManager.cpp:755
CommandUnit graphicsCommandUnitM
Definition: GraphicsObjectManager.hpp:346
Definition: GraphicsTypes.hpp:28
Definition: GraphicsTypes.hpp:15
Definition: GraphicsTypes.hpp:22
Command unit represents everything needed to allocate, submit, record and execute commands.
Definition: GraphicsObjectManager.hpp:227
VkCommandBuffer startCommandBuffer(VkDevice logDevice)
Definition: GraphicsObjectManager.cpp:1061
VkCommandPool commandPool
Command pool for the command unit.
Definition: GraphicsObjectManager.hpp:229
uint32_t queueFamilyIndex
Queue family index of the command unit.
Definition: GraphicsObjectManager.hpp:230
bool endCommandBuffer(VkDevice logDevice, VkCommandBuffer commandBuffer, VkFence fence=VK_NULL_HANDLE)
Definition: GraphicsObjectManager.cpp:1087
VkQueue queue
Queue for the command unit.
Definition: GraphicsObjectManager.hpp:228
Definition: BasicTypes.hpp:161
Simple light object that contains a list of uniform buffers.
Definition: GraphicsTypes.hpp:109
Definition: BasicTypes.hpp:135
static PhongMaterial getDefaultMaterial()
Definition: GraphicsTypes.cpp:346