Staging buffers are no longer host coherent; explicitly flushing the buffers instead.

Fixed getQueueFamiliesForSharing, so it now correctly returns more than one queue family.
This commit is contained in:
2022-07-20 22:37:22 -07:00
parent 0cc6c0d40b
commit 46f8af662e
2 changed files with 18 additions and 9 deletions

View File

@@ -405,7 +405,7 @@ bool KRDevice::initStagingBuffer(VkDeviceSize size, StagingBufferInfo* info
if (!createBuffer( if (!createBuffer(
size, size,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
&info->buffer, &info->buffer,
&info->allocation &info->allocation
#if KRENGINE_DEBUG_GPU_LABELS #if KRENGINE_DEBUG_GPU_LABELS
@@ -465,13 +465,18 @@ VmaAllocator KRDevice::getAllocator()
return m_allocator; return m_allocator;
} }
void KRDevice::getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount) void KRDevice::getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount, VkSharingMode* sharingMode)
{ {
*familyCount = 1; *familyCount = 1;
queueFamilyIndices[0] = m_graphicsFamilyQueueIndex; queueFamilyIndices[0] = m_graphicsFamilyQueueIndex;
if (m_graphicsFamilyQueueIndex != m_transferFamilyQueueIndex) { if (m_graphicsFamilyQueueIndex != m_transferFamilyQueueIndex) {
queueFamilyIndices[1] = m_transferFamilyQueueIndex; queueFamilyIndices[1] = m_transferFamilyQueueIndex;
*familyCount++; (*familyCount)++;
}
if (*familyCount > 1) {
*sharingMode = VK_SHARING_MODE_CONCURRENT;
} else {
*sharingMode = VK_SHARING_MODE_EXCLUSIVE;
} }
} }
@@ -495,12 +500,12 @@ bool KRDevice::createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFl
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageInfo.flags = imageCreateFlags; imageInfo.flags = imageCreateFlags;
imageInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
uint32_t queueFamilyIndices[2] = {}; uint32_t queueFamilyIndices[2] = {};
imageInfo.pQueueFamilyIndices = queueFamilyIndices; imageInfo.pQueueFamilyIndices = queueFamilyIndices;
imageInfo.queueFamilyIndexCount = 0; imageInfo.queueFamilyIndexCount = 0;
getQueueFamiliesForSharing(queueFamilyIndices, &imageInfo.queueFamilyIndexCount); getQueueFamiliesForSharing(queueFamilyIndices, &imageInfo.queueFamilyIndexCount, &imageInfo.sharingMode);
VmaAllocationCreateInfo allocInfo = {}; VmaAllocationCreateInfo allocInfo = {};
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
@@ -530,12 +535,11 @@ bool KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemor
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
bufferInfo.size = size; bufferInfo.size = size;
bufferInfo.usage = usage; bufferInfo.usage = usage;
bufferInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
uint32_t queueFamilyIndices[2] = {}; uint32_t queueFamilyIndices[2] = {};
bufferInfo.pQueueFamilyIndices = queueFamilyIndices; bufferInfo.pQueueFamilyIndices = queueFamilyIndices;
bufferInfo.queueFamilyIndexCount = 0; bufferInfo.queueFamilyIndexCount = 0;
getQueueFamiliesForSharing(queueFamilyIndices, &bufferInfo.queueFamilyIndexCount); getQueueFamiliesForSharing(queueFamilyIndices, &bufferInfo.queueFamilyIndexCount, &bufferInfo.sharingMode);
VmaAllocationCreateInfo allocInfo = {}; VmaAllocationCreateInfo allocInfo = {};
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
@@ -776,7 +780,12 @@ void KRDevice::streamUpload(void* data, size_t size, Vector2i dimensions, VkImag
void KRDevice::streamEnd() void KRDevice::streamEnd()
{ {
vkEndCommandBuffer(m_transferCommandBuffers[0]); vkEndCommandBuffer(m_transferCommandBuffers[0]);
if (m_streamingStagingBuffer.usage > 0) {
VkResult res = vmaFlushAllocation(m_allocator, m_streamingStagingBuffer.allocation, 0, m_streamingStagingBuffer.usage);
assert(res == VK_SUCCESS);
m_streamingStagingBuffer.usage = 0; m_streamingStagingBuffer.usage = 0;
}
// TODO - Should double buffer and use a fence rather than block the thread // TODO - Should double buffer and use a fence rather than block the thread
VkSubmitInfo submitInfo{}; VkSubmitInfo submitInfo{};

View File

@@ -112,7 +112,7 @@ public:
private: private:
void checkFlushStreamBuffer(size_t size); void checkFlushStreamBuffer(size_t size);
void getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount); void getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount, VkSharingMode* sharingMode);
// Initialization helper functions // Initialization helper functions
bool getAndCheckDeviceCapabilities(const std::vector<const char*>& deviceExtensions); bool getAndCheckDeviceCapabilities(const std::vector<const char*>& deviceExtensions);