Change Buffer struct to hold AllocationInfo
Added allocationInfo field to struct Buffer. Also, modified createBuffer to use this field. This might be useful, when accessing allocation information later. Already used for uniform buffers.
This commit is contained in:
1 parent
cce4875329
commit
a175045518
1 file changed
+16
-21
+16
-21
@@ -150,6 +150,7 @@ struct Buffer
|
||||
{
|
||||
VkBuffer buffer;
|
||||
VmaAllocation allocation;
|
||||
VmaAllocationInfo allocationInfo;
|
||||
};
|
||||
|
||||
// FIXME: Temporary array of vertices, for testing purposes
|
||||
@@ -233,8 +234,6 @@ Buffer gVertexStagingBuffer = {};
|
||||
Buffer gIndexBuffer = {};
|
||||
Buffer gIndexStagingBuffer = {};
|
||||
std::vector<Buffer> gUniformBuffers = {};
|
||||
std::vector<void*> gUniformBuffersMappedMemory = {};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Helper function. Creates a buffer object
|
||||
@@ -247,8 +246,9 @@ std::vector<void*> gUniformBuffersMappedMemory = {};
|
||||
* @return uint8_t VULKAN_ERROR_NO_ERROR on success. Possible errors:
|
||||
* VULKAN_ERROR_COMMAND_BUFFER_ALLOCATION_FAILED
|
||||
*/
|
||||
static uint8_t createBuffer(const VkDeviceSize size, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage,
|
||||
const VmaAllocationCreateFlags allocationFlags, Buffer& buffer);
|
||||
static uint8_t createBuffer(const VkDeviceSize size, VkBufferUsageFlags bufferUsage,
|
||||
VmaMemoryUsage memoryUsage, const VmaAllocationCreateFlags allocationFlags,
|
||||
Buffer& buffer);
|
||||
|
||||
/**
|
||||
* @brief Copy one buffer's data to another
|
||||
@@ -475,7 +475,7 @@ static uint8_t createBuffer(const VkDeviceSize size, VkBufferUsageFlags bufferUs
|
||||
const VmaAllocationCreateFlags allocationFlags, Buffer& buffer)
|
||||
{
|
||||
VkBufferCreateInfo vertexBufferInfo;
|
||||
VmaAllocationCreateInfo allocInfo;
|
||||
VmaAllocationCreateInfo createInfo;
|
||||
|
||||
vertexBufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
vertexBufferInfo.pNext = nullptr;
|
||||
@@ -487,21 +487,21 @@ static uint8_t createBuffer(const VkDeviceSize size, VkBufferUsageFlags bufferUs
|
||||
vertexBufferInfo.pQueueFamilyIndices = nullptr;
|
||||
|
||||
/* Disalows random access to memory. TODO: Consider changing to VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT? */
|
||||
allocInfo.flags = allocationFlags;
|
||||
allocInfo.usage = memoryUsage;
|
||||
allocInfo.memoryTypeBits = 0U;
|
||||
allocInfo.requiredFlags = 0U;
|
||||
allocInfo.preferredFlags = 0U;
|
||||
allocInfo.pool = VK_NULL_HANDLE;
|
||||
allocInfo.pUserData = VK_NULL_HANDLE;
|
||||
allocInfo.priority = 0.0f;
|
||||
createInfo.flags = allocationFlags;
|
||||
createInfo.usage = memoryUsage;
|
||||
createInfo.memoryTypeBits = 0U;
|
||||
createInfo.requiredFlags = 0U;
|
||||
createInfo.preferredFlags = 0U;
|
||||
createInfo.pool = VK_NULL_HANDLE;
|
||||
createInfo.pUserData = VK_NULL_HANDLE;
|
||||
createInfo.priority = 0.0f;
|
||||
|
||||
if (VK_SUCCESS != vmaCreateBuffer(gAllocator,
|
||||
&vertexBufferInfo,
|
||||
&allocInfo,
|
||||
&createInfo,
|
||||
&buffer.buffer,
|
||||
&buffer.allocation,
|
||||
nullptr)) {
|
||||
&buffer.allocationInfo)) {
|
||||
LOGF << vulkanErrorMesssages[VULKAN_BUFFER_CREATION_FAILED];
|
||||
return VULKAN_ERROR_BUFFER_CREATION_FAILED;
|
||||
}
|
||||
@@ -977,7 +977,6 @@ static uint8_t createUniformBuffers()
|
||||
VkDeviceSize bufferSize = sizeof(UniformBufferObject);
|
||||
|
||||
gUniformBuffers.resize(SWAP_BUFFER_COUNT);
|
||||
gUniformBuffersMappedMemory.resize(SWAP_BUFFER_COUNT);
|
||||
|
||||
for (size_t i = 0; i < SWAP_BUFFER_COUNT; i++) {
|
||||
createBuffer(bufferSize,
|
||||
@@ -985,10 +984,6 @@ static uint8_t createUniformBuffers()
|
||||
VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
|
||||
VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||
gUniformBuffers[i]);
|
||||
|
||||
VmaAllocationInfo allocInfo;
|
||||
vmaGetAllocationInfo(gAllocator, gUniformBuffers[i].allocation, &allocInfo);
|
||||
gUniformBuffersMappedMemory[i] = allocInfo.pMappedData;
|
||||
}
|
||||
|
||||
return VULKAN_ERROR_NO_ERROR;
|
||||
@@ -1656,7 +1651,7 @@ static void updateUniformBuffer(uint32_t currentImage)
|
||||
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
ubo.proj = glm::perspective(glm::radians(45.0f), gSwapchainExtent.width / (float) gSwapchainExtent.height, 0.1f, 10.0f);
|
||||
ubo.proj[1][1] *= -1;
|
||||
memcpy(gUniformBuffersMappedMemory[currentImage], &ubo, sizeof(ubo));
|
||||
memcpy(gUniformBuffers[currentImage].allocationInfo.pMappedData, &ubo, sizeof(ubo));
|
||||
}
|
||||
|
||||
static void cleanupSwapchain()
|
||||
|
||||
Reference in new issue
Block a user