Moved queue family iteration code shared by KRDevice::createImage and KRDevice::createBuffer into a utility function.

Added imageCreateFlags argument to KRDevice::createImage
This commit is contained in:
2022-07-16 00:45:17 -07:00
parent 22b871ad2f
commit 83ea50384f
3 changed files with 19 additions and 18 deletions

View File

@@ -430,17 +430,18 @@ VmaAllocator KRDevice::getAllocator()
return m_allocator; return m_allocator;
} }
bool KRDevice::createImage(Vector2i dimensions, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation) void KRDevice::getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount)
{ {
// TODO - Break block into own function to be shared with createBuffer *familyCount = 1;
int familyCount = 1;
uint32_t queueFamilyIndices[2] = {};
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++;
} }
}
bool KRDevice::createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation)
{
VkImageCreateInfo imageInfo{}; VkImageCreateInfo imageInfo{};
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_2D; imageInfo.imageType = VK_IMAGE_TYPE_2D;
@@ -454,10 +455,13 @@ bool KRDevice::createImage(Vector2i dimensions, VkMemoryPropertyFlags properties
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
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 = 0; imageInfo.flags = imageCreateFlags;
imageInfo.sharingMode = VK_SHARING_MODE_CONCURRENT; imageInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
uint32_t queueFamilyIndices[2] = {};
imageInfo.pQueueFamilyIndices = queueFamilyIndices; imageInfo.pQueueFamilyIndices = queueFamilyIndices;
imageInfo.queueFamilyIndexCount = familyCount; imageInfo.queueFamilyIndexCount = 0;
getQueueFamiliesForSharing(queueFamilyIndices, &imageInfo.queueFamilyIndexCount);
VmaAllocationCreateInfo allocInfo = {}; VmaAllocationCreateInfo allocInfo = {};
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
@@ -476,20 +480,15 @@ bool KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemor
#endif #endif
) )
{ {
int familyCount = 1;
uint32_t queueFamilyIndices[2] = {};
queueFamilyIndices[0] = m_graphicsFamilyQueueIndex;
if (m_graphicsFamilyQueueIndex != m_transferFamilyQueueIndex) {
queueFamilyIndices[1] = m_transferFamilyQueueIndex;
familyCount++;
}
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; bufferInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
bufferInfo.queueFamilyIndexCount = familyCount;
uint32_t queueFamilyIndices[2] = {};
bufferInfo.pQueueFamilyIndices = queueFamilyIndices; bufferInfo.pQueueFamilyIndices = queueFamilyIndices;
bufferInfo.queueFamilyIndexCount = 0;
getQueueFamiliesForSharing(queueFamilyIndices, &bufferInfo.queueFamilyIndexCount);
VmaAllocationCreateInfo allocInfo = {}; VmaAllocationCreateInfo allocInfo = {};
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;

View File

@@ -55,7 +55,7 @@ public:
#endif #endif
); );
bool createImage(Vector2i dimensions, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation); bool createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation);
KrResult selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& surfaceFormat); KrResult selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& surfaceFormat);
KrResult selectDepthFormat(VkFormat& selectedDepthFormat); KrResult selectDepthFormat(VkFormat& selectedDepthFormat);
@@ -103,4 +103,6 @@ public:
size_t m_graphicsStagingBufferUsage; size_t m_graphicsStagingBufferUsage;
void* m_graphicsStagingBufferData; void* m_graphicsStagingBufferData;
private: private:
void getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount);
}; };

View File

@@ -61,7 +61,7 @@ bool KRTexture2D::createGPUTexture(int lod_max_dim) {
texture.allocation = VK_NULL_HANDLE; texture.allocation = VK_NULL_HANDLE;
texture.image = VK_NULL_HANDLE; texture.image = VK_NULL_HANDLE;
if (!device.createImage(getDimensions(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation)) { if (!device.createImage(getDimensions(), 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation)) {
success = false; success = false;
break; break;
} }